Skip to content

Commit

Permalink
fix(components): gs-mutations-over-time: show 0 instead of "no data" …
Browse files Browse the repository at this point in the history
…when there are sequences but no mutation

resolves #635 case 2
  • Loading branch information
fengelniederhammer committed Jan 9, 2025
1 parent 3d943a1 commit 666709a
Show file tree
Hide file tree
Showing 10 changed files with 32,762 additions and 11,893 deletions.
14,139 changes: 11,077 additions & 3,062 deletions components/src/preact/mutationsOverTime/__mockData__/aminoAcidMutationsByDay.ts

Large diffs are not rendered by default.

10,489 changes: 3,883 additions & 6,606 deletions components/src/preact/mutationsOverTime/__mockData__/byWeek.ts

Large diffs are not rendered by default.

19,827 changes: 17,624 additions & 2,203 deletions components/src/preact/mutationsOverTime/__mockData__/defaultMockData.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const MutationsOverTimeGrid: FunctionComponent<MutationsOverTimeGridProps> = ({
};

function getTooltipPosition(rowIndex: number, rows: number, columnIndex: number, columns: number) {
const tooltipX = rowIndex < rows / 2 ? 'bottom' : 'top';
const tooltipX = rowIndex < rows / 2 || rowIndex < 5 ? 'bottom' : 'top';
const tooltipY = columnIndex < columns / 2 ? 'start' : 'end';
return `${tooltipX}-${tooltipY}` as const;
}
Expand Down
148 changes: 144 additions & 4 deletions components/src/query/queryMutationsOverTime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ describe('queryMutationsOverTime', () => {
});

expect(mutationOverTimeData.getAsArray()).to.deep.equal([
[{ proportion: 0.4, count: 4, totalCount: 11 }, null, null],
[
{ proportion: 0.4, count: 4, totalCount: 11 },
{ proportion: 0, count: 0, totalCount: 12 },
{ proportion: 0, count: 0, totalCount: 13 },
],
[
{ proportion: 0.1, count: 1, totalCount: 11 },
{ proportion: 0.2, count: 2, totalCount: 12 },
Expand Down Expand Up @@ -177,7 +181,7 @@ describe('queryMutationsOverTime', () => {
dateFieldTo: '2023-01-02',
fields: [],
},
response: { data: [{ count: 12 }] },
response: { data: [{ count: 0 }] },
},
{
body: {
Expand Down Expand Up @@ -247,7 +251,7 @@ describe('queryMutationsOverTime', () => {
});

expect(mutationOverTimeData.getAsArray()).to.deep.equal([
[{ proportion: 0.4, count: 4, totalCount: 11 }, null, null],
[{ proportion: 0.4, count: 4, totalCount: 11 }, null, { proportion: 0, count: 0, totalCount: 13 }],
[{ proportion: 0.1, count: 1, totalCount: 11 }, null, { proportion: 0.3, count: 3, totalCount: 13 }],
]);

Expand Down Expand Up @@ -688,7 +692,10 @@ describe('queryMutationsOverTime', () => {
});

expect(mutationOverTimeData.getAsArray()).to.deep.equal([
[{ proportion: 0.4, count: 4, totalCount: 11 }, null],
[
{ proportion: 0.4, count: 4, totalCount: 11 },
{ proportion: 0, count: 0, totalCount: 12 },
],
[
{ proportion: 0.1, count: 1, totalCount: 11 },
{ proportion: 0.2, count: 2, totalCount: 12 },
Expand Down Expand Up @@ -734,6 +741,139 @@ describe('queryMutationsOverTime', () => {
expect(dates.length).toBe(0);
});

it('should fill with 0 if the mutation does not exist in a date range but count > 0', async () => {
const lapisFilter = { field1: 'value1', field2: 'value2' };
const dateField = 'dateField';

lapisRequestMocks.multipleAggregated([
{
body: { ...lapisFilter, fields: [dateField] },
response: {
data: [
{ count: 1, [dateField]: '2023-01-01' },
{ count: 1, [dateField]: '2023-01-02' },
],
},
},
{
body: {
...lapisFilter,
dateFieldFrom: '2023-01-01',
dateFieldTo: '2023-01-01',
fields: [],
},
response: { data: [{ count: 11 }] },
},
{
body: {
...lapisFilter,
dateFieldFrom: '2023-01-02',
dateFieldTo: '2023-01-02',
fields: [],
},
response: { data: [{ count: 11 }] },
},
]);

lapisRequestMocks.multipleMutations(
[
{
body: {
...lapisFilter,
dateFieldFrom: '2023-01-01',
dateFieldTo: '2023-01-01',
minProportion: 0.001,
},
response: { data: [getSomeTestMutation(0.1, 1)] },
},
{
body: {
...lapisFilter,
dateFieldFrom: '2023-01-02',
dateFieldTo: '2023-01-02',
minProportion: 0.001,
},
response: { data: [] },
},
{
body: {
...lapisFilter,
dateFieldFrom: '2023-01-01',
dateFieldTo: '2023-01-02',
minProportion: 0.001,
},
response: {
data: [getSomeTestMutation(0.21, 6)],
},
},
],
'nucleotide',
);

const { mutationOverTimeData } = await queryMutationsOverTimeData({
lapisFilter,
sequenceType: 'nucleotide',
lapis: DUMMY_LAPIS_URL,
lapisDateField: dateField,
granularity: 'day',
});

expect(mutationOverTimeData.getAsArray()).to.deep.equal([
[
{ proportion: 0.1, count: 1, totalCount: 11 },
{ proportion: 0, count: 0, totalCount: 11 },
],
]);
});

it('should return null if count in a date range is 0', async () => {
const lapisFilter = { field1: 'value1', field2: 'value2' };
const dateField = 'dateField';

lapisRequestMocks.multipleAggregated([
{
body: { ...lapisFilter, fields: [dateField] },
response: {
data: [{ count: 0, [dateField]: '2023-01-01' }],
},
},
{
body: {
...lapisFilter,
dateFieldFrom: '2023-01-01',
dateFieldTo: '2023-01-01',
fields: [],
},
response: { data: [{ count: 0 }] },
},
]);

lapisRequestMocks.multipleMutations(
[
{
body: {
...lapisFilter,
dateFieldFrom: '2023-01-01',
dateFieldTo: '2023-01-01',
minProportion: 0.001,
},
response: { data: [getSomeTestMutation(0.1, 1)] },
},
],
'nucleotide',
);

const { mutationOverTimeData } = await queryMutationsOverTimeData({
lapisFilter,
sequenceType: 'nucleotide',
lapis: DUMMY_LAPIS_URL,
lapisDateField: dateField,
granularity: 'day',
});

expect(mutationOverTimeData.getAsArray()).to.deep.equal([[null]]);
});

function getSomeTestMutation(proportion: number, count: number) {
return {
mutation: 'sequenceName:A123T',
Expand Down
18 changes: 17 additions & 1 deletion components/src/query/queryMutationsOverTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export async function queryMutationsOverTimeData({

const data = await fetchAndPrepareSubstitutionsOrDeletions(filter, sequenceType).evaluate(lapis, signal);
const totalCountQuery = await getTotalNumberOfSequencesInDateRange(filter).evaluate(lapis, signal);

return {
date,
mutations: data.content,
Expand Down Expand Up @@ -244,9 +245,14 @@ export function groupByMutation(
});

data.forEach((mutationData) => {
if (mutationData.totalCount == 0) {
return;
}

const date = toTemporal(mutationData.date);

mutationData.mutations.forEach((mutationEntry) => {
const mutation = toSubstitutionOrDeletion(mutationEntry.mutation);
const date = toTemporal(mutationData.date);

if (dataArray.get(mutation, date) !== undefined) {
dataArray.set(mutation, date, {
Expand All @@ -256,6 +262,16 @@ export function groupByMutation(
});
}
});

for (const firstAxisKey of dataArray.getFirstAxisKeys()) {
if (dataArray.get(firstAxisKey, date) === null) {
dataArray.set(firstAxisKey, date, {
count: 0,
proportion: 0,
totalCount: mutationData.totalCount,
});
}
}
});

return dataArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mutation,2024-W03,2024-W04,2024-W05,2024-W06
C44T,0.5851938895417156,0.5614583333333333,0.6298472385428907,0.5540540540540541
C774T,0.26635694928377857,0.2508050767190756,0.27291549030679463,0.2662041625371655
C1762A,0.06473724295506474,0.06412605349945034,0.04853105243584976,0.041330446762448333
C11747T,0.0638990638990639,0.062058130400628436,0.04801873902010541,0.03954564577198149
G17562T,0.0710909434675742,0.07296607077708865,0.06433721575152523,0.05823724838772718
T18453C,0.21926151503616292,0.19885629957572404,0.21122050900984582,0.21082565208864484
G21641T,0.06280500742626777,0.10792580101180438,0.06527690040008423,0.028808481216870248
C23277T,0.06267698697375873,0.0770213542617266,0.10395856455789863,0.127443315089914
C44T,0.5851938895417156,0,0.6298472385428907,0.5540540540540541
C774T,0.26635694928377857,0,0.27291549030679463,0.2662041625371655
C1762A,0.06473724295506474,0,0.04853105243584976,0.041330446762448333
C11747T,0.0638990638990639,0,0.04801873902010541,0.03954564577198149
G17562T,0.0710909434675742,0,0.06433721575152523,0.05823724838772718
T18453C,0.21926151503616292,0,0.21122050900984582,0.21082565208864484
G21641T,0.06280500742626777,0,0.06527690040008423,0.028808481216870248
C23277T,0.06267698697375873,0,0.10395856455789863,0.127443315089914
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mutation,2024-W03,2024-W04,2024-W05,2024-W06
C44T,0.5851938895417156,0.5614583333333333,0.6298472385428907,0.5540540540540541
C774T,0.26635694928377857,0.2508050767190756,0.27291549030679463,0.2662041625371655
C1762A,0.06473724295506474,0.06412605349945034,0.04853105243584976,0.041330446762448333
C11747T,0.0638990638990639,0.062058130400628436,0.04801873902010541,0.03954564577198149
G17562T,0.0710909434675742,0.07296607077708865,0.06433721575152523,0.05823724838772718
T18453C,0.21926151503616292,0.19885629957572404,0.21122050900984582,0.21082565208864484
G21641T,0.06280500742626777,0.10792580101180438,0.06527690040008423,0.028808481216870248
C23277T,0.06267698697375873,0.0770213542617266,0.10395856455789863,0.127443315089914
C44T,0.5851938895417156,0,0.6298472385428907,0.5540540540540541
C774T,0.26635694928377857,0,0.27291549030679463,0.2662041625371655
C1762A,0.06473724295506474,0,0.04853105243584976,0.041330446762448333
C11747T,0.0638990638990639,0,0.04801873902010541,0.03954564577198149
G17562T,0.0710909434675742,0,0.06433721575152523,0.05823724838772718
T18453C,0.21926151503616292,0,0.21122050900984582,0.21082565208864484
G21641T,0.06280500742626777,0,0.06527690040008423,0.028808481216870248
C23277T,0.06267698697375873,0,0.10395856455789863,0.127443315089914
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 666709a

Please sign in to comment.