Skip to content

Commit

Permalink
test: fix and reactivate nucleotide mutations tests
Browse files Browse the repository at this point in the history
issue: #283
  • Loading branch information
fengelniederhammer committed Jul 6, 2023
1 parent 2007c7f commit e433960
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data class MutationData(
example = "G29741T",
description = "(nucleotide symbol in reference genome)(position in genome)" +
"(mutation's target nucleotide symbol)",
) val mutation: String,
) val position: String,
@Schema(
example = "42",
description = "Total number of sequences with this mutation matching the given sequence filter criteria",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class LapisControllerTest(@Autowired val mockMvc: MockMvc) {

mockMvc.perform(get("/nucleotideMutations?country=Switzerland"))
.andExpect(status().isOk)
.andExpect(jsonPath("\$[0].mutation").value("the mutation"))
.andExpect(jsonPath("\$[0].position").value("the mutation"))
.andExpect(jsonPath("\$[0].proportion").value(0.5))
.andExpect(jsonPath("\$[0].count").value(42))
}
Expand All @@ -129,7 +129,7 @@ class LapisControllerTest(@Autowired val mockMvc: MockMvc) {

mockMvc.perform(get("/nucleotideMutations?country=Switzerland&minProportion=0.3"))
.andExpect(status().isOk)
.andExpect(jsonPath("\$[0].mutation").value("the mutation"))
.andExpect(jsonPath("\$[0].position").value("the mutation"))
.andExpect(jsonPath("\$[0].proportion").value(0.5))
.andExpect(jsonPath("\$[0].count").value(42))
}
Expand All @@ -149,7 +149,7 @@ class LapisControllerTest(@Autowired val mockMvc: MockMvc) {

mockMvc.perform(request)
.andExpect(status().isOk)
.andExpect(jsonPath("\$[0].mutation").value("the mutation"))
.andExpect(jsonPath("\$[0].position").value("the mutation"))
.andExpect(jsonPath("\$[0].proportion").value(0.5))
.andExpect(jsonPath("\$[0].count").value(42))
}
Expand All @@ -169,7 +169,7 @@ class LapisControllerTest(@Autowired val mockMvc: MockMvc) {

mockMvc.perform(request)
.andExpect(status().isOk)
.andExpect(jsonPath("\$[0].mutation").value("the mutation"))
.andExpect(jsonPath("\$[0].position").value("the mutation"))
.andExpect(jsonPath("\$[0].proportion").value(0.5))
.andExpect(jsonPath("\$[0].count").value(42))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ class SiloClientTest {
"queryResult": [
{
"count": 45,
"mutation": "first mutation",
"position": "first mutation",
"proportion": 0.9
},
{
"count": 44,
"mutation": "second mutation",
"position": "second mutation",
"proportion": 0.7
}
]
Expand Down
10 changes: 5 additions & 5 deletions siloLapisTests/test/aggregated.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect } from 'chai';
import { lapisClient } from './common';
import fs from 'fs';
import { AggregatedResponse, SequenceFiltersWithGroupByFields } from './lapisClient';
import {AggregatedResponse, SequenceFiltersWithFields} from './lapisClient';

const queriesPath = __dirname + '/aggregatedQueries';
const aggregatedQueryFiles = fs.readdirSync(queriesPath);

type TestCase = {
testCaseName: string;
lapisRequest: SequenceFiltersWithGroupByFields;
expected: AggregatedResponse[];
testCaseName: string;
lapisRequest: SequenceFiltersWithFields;
expected: AggregatedResponse[];
};

describe('The /aggregated endpoint', () => {
Expand All @@ -18,7 +18,7 @@ describe('The /aggregated endpoint', () => {
.forEach((testCase: TestCase) =>
it('should return data for the test case ' + testCase.testCaseName, async () => {
const result = await lapisClient.postAggregated({
sequenceFiltersWithGroupByFields: testCase.lapisRequest,
sequenceFiltersWithFields: testCase.lapisRequest,
});

const resultWithoutUndefined = result.map((aggregatedResponse: AggregatedResponse) => {
Expand Down
75 changes: 37 additions & 38 deletions siloLapisTests/test/nucleotideMutations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,41 @@ import fs from 'fs';
import { SequenceFilters } from './lapisClient';

describe('The /nucleotideMutationProportions endpoint', () => {
let mutationWithLessThan10PercentProportion = 'G29741T';
let mutationWithMoreThan50PercentProportion = 'G28880A';

// TODO: reenable this as soon as SILO supports nuc mutation queries again
// it('should return mutation proportions for Switzerland', async () => {
// const result = await lapisClient.postNucleotideMutations({
// sequenceFiltersWithMinProportion: { country: 'Switzerland' },
// });
//
// expect(result).to.have.length(362);
//
// const rareMutationProportion = result.find(
// mutationData => mutationData.mutation === mutationWithLessThan10PercentProportion
// );
// expect(rareMutationProportion?.count).to.equal(8);
// expect(rareMutationProportion?.proportion).to.be.approximately(0.0816326, 0.0001);
//
// const commonMutationProportion = result.find(
// mutationProportion => mutationProportion.mutation === mutationWithMoreThan50PercentProportion
// );
// expect(commonMutationProportion?.count).to.equal(61);
// expect(commonMutationProportion?.proportion).to.be.approximately(0.6288659793814433, 0.0001);
// });
//
// it('should return mutation proportions for Switzerland with minProportion 0.5', async () => {
// const result = await lapisClient.postNucleotideMutations({
// sequenceFiltersWithMinProportion: {
// country: 'Switzerland',
// minProportion: 0.5,
// },
// });
//
// expect(result).to.have.length(108);
//
// const mutationsAboveThreshold = result.map(mutationData => mutationData.mutation);
// expect(mutationsAboveThreshold).to.contain(mutationWithMoreThan50PercentProportion);
// expect(mutationsAboveThreshold).to.not.contain(mutationWithLessThan10PercentProportion);
// });
let mutationWithLessThan10PercentProportion = 'C19220T';
let mutationWithMoreThan50PercentProportion = 'G28280C';

it('should return mutation proportions for Switzerland', async () => {
const result = await lapisClient.postNucleotideMutations({
sequenceFiltersWithMinProportion: { country: 'Switzerland' },
});

expect(result).to.have.length(362);

const rareMutationProportion = result.find(
mutationData => mutationData.position === mutationWithLessThan10PercentProportion
);
expect(rareMutationProportion?.count).to.equal(8);
expect(rareMutationProportion?.proportion).to.be.approximately(0.0816, 0.0001);

const commonMutationProportion = result.find(
mutationProportion => mutationProportion.position === mutationWithMoreThan50PercentProportion
);
expect(commonMutationProportion?.count).to.equal(51);
expect(commonMutationProportion?.proportion).to.be.approximately(0.5204, 0.0001);
});

it('should return mutation proportions for Switzerland with minProportion 0.5', async () => {
const result = await lapisClient.postNucleotideMutations({
sequenceFiltersWithMinProportion: {
country: 'Switzerland',
minProportion: 0.5,
},
});

expect(result).to.have.length(108);

const mutationsAboveThreshold = result.map(mutationData => mutationData.position);
expect(mutationsAboveThreshold).to.contain(mutationWithMoreThan50PercentProportion);
expect(mutationsAboveThreshold).to.not.contain(mutationWithLessThan10PercentProportion);
});
});

0 comments on commit e433960

Please sign in to comment.