Skip to content

Commit

Permalink
fixup! pref(components): use web worker for mutations over time calcu…
Browse files Browse the repository at this point in the history
…lation
  • Loading branch information
JonasKellerer committed Nov 5, 2024
1 parent 74bc144 commit a6b4817
Showing 1 changed file with 68 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import { yearMonthDay } from '../../utils/temporalTestHelpers';

describe('getFilteredMutationOverTimeData', () => {
it('should filter by displayed segments', () => {
const data = prepareMutationOverTimeData();
const { data, overallMutationData } = prepareMutationOverTimeData([
someSubstitutionEntry,
anotherSubstitutionEntry,
someDeletionEntry,
]);

const result = getFilteredMutationOverTimeData(
data,
[someSubstitutionEntry, anotherSubstitutionEntry, someDeletionEntry],
overallMutationData,
[
{ segment: 'someSegment', checked: false, label: 'Some Segment' },
{ segment: 'someOtherSegment', checked: true, label: 'Some Other Segment' },
Expand All @@ -27,11 +31,15 @@ describe('getFilteredMutationOverTimeData', () => {
});

it('should filter by mutation types', () => {
const data = prepareMutationOverTimeData();
const { data, overallMutationData } = prepareMutationOverTimeData([
someSubstitutionEntry,
anotherSubstitutionEntry,
someDeletionEntry,
]);

const result = getFilteredMutationOverTimeData(
data,
[someSubstitutionEntry, anotherSubstitutionEntry, someDeletionEntry],
overallMutationData,
[],
[
{
Expand All @@ -52,109 +60,74 @@ describe('getFilteredMutationOverTimeData', () => {
});

it('should remove mutations where overall proportion is below filter', () => {
const data = prepareMutationOverTimeData();
const { data, overallMutationData } = prepareMutationOverTimeData([
{ ...someSubstitutionEntry, proportion: belowFilter },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
]);

const result = getFilteredMutationOverTimeData(
data,
[
{ ...someSubstitutionEntry, proportion: belowFilter },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
],
[],
[],
proportionInterval,
);
const result = getFilteredMutationOverTimeData(data, overallMutationData, [], [], proportionInterval);

expect(result.getFirstAxisKeys()).to.deep.equal([anotherSubstitution, someDeletion]);
});

it('should remove mutations where overall proportion is above filter', () => {
const data = prepareMutationOverTimeData();
const { data, overallMutationData } = prepareMutationOverTimeData([
{ ...someSubstitutionEntry, proportion: aboveFilter },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
]);

const result = getFilteredMutationOverTimeData(
data,
[
{ ...someSubstitutionEntry, proportion: aboveFilter },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
],
[],
[],
proportionInterval,
);
const result = getFilteredMutationOverTimeData(data, overallMutationData, [], [], proportionInterval);

expect(result.getFirstAxisKeys()).to.deep.equal([anotherSubstitution, someDeletion]);
});

it('should not remove mutations where overall proportion is above filter but single proportion is below filter', () => {
const data = prepareMutationOverTimeDataWithOneMutationWithProportion(belowFilter);
const { data, overallMutationData } = prepareMutationOverTimeData([
someSubstitutionEntry,
anotherSubstitutionEntry,
someDeletionEntry,
]);
data.set(someSubstitution, someTemporal, { ...someMutationOverTimeValue, proportion: belowFilter });

const result = getFilteredMutationOverTimeData(
data,
[
{ ...someSubstitutionEntry, proportion: inFilter },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
],
[],
[],
proportionInterval,
);
const result = getFilteredMutationOverTimeData(data, overallMutationData, [], [], proportionInterval);

expect(result.getFirstAxisKeys()).to.deep.equal([someSubstitution, anotherSubstitution, someDeletion]);
});

it('should not remove mutations where overall proportion is below max but single proportion is above max', () => {
const data = prepareMutationOverTimeDataWithOneMutationWithProportion(aboveFilter);
const { data, overallMutationData } = prepareMutationOverTimeData([
someSubstitutionEntry,
anotherSubstitutionEntry,
someDeletionEntry,
]);
data.set(someSubstitution, someTemporal, { ...someMutationOverTimeValue, proportion: aboveFilter });

const result = getFilteredMutationOverTimeData(
data,
[
{ ...someSubstitutionEntry, proportion: inFilter },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
],
[],
[],
proportionInterval,
);
const result = getFilteredMutationOverTimeData(data, overallMutationData, [], [], proportionInterval);

expect(result.getFirstAxisKeys()).to.deep.equal([someSubstitution, anotherSubstitution, someDeletion]);
});

it('should not remove mutations where overall proportion is at lower bound of filter', () => {
const data = prepareMutationOverTimeData();

const result = getFilteredMutationOverTimeData(
data,
[
{ ...someSubstitutionEntry, proportion: atFilterMin },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
],
[],
[],
proportionInterval,
);
const { data, overallMutationData } = prepareMutationOverTimeData([
{ ...someSubstitutionEntry, proportion: atFilterMin },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
]);
const result = getFilteredMutationOverTimeData(data, overallMutationData, [], [], proportionInterval);

expect(result.getFirstAxisKeys()).to.deep.equal([someSubstitution, anotherSubstitution, someDeletion]);
});

it('should not remove mutations where overall proportion is at upper bound of filter', () => {
const data = prepareMutationOverTimeData();
const { data, overallMutationData } = prepareMutationOverTimeData([
{ ...someSubstitutionEntry, proportion: atFilterMax },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
]);

const result = getFilteredMutationOverTimeData(
data,
[
{ ...someSubstitutionEntry, proportion: atFilterMax },
{ ...anotherSubstitutionEntry, proportion: inFilter },
{ ...someDeletionEntry, proportion: inFilter },
],
[],
[],
proportionInterval,
);
const result = getFilteredMutationOverTimeData(data, overallMutationData, [], [], proportionInterval);

expect(result.getFirstAxisKeys()).to.deep.equal([someSubstitution, anotherSubstitution, someDeletion]);
});
Expand All @@ -177,36 +150,36 @@ describe('getFilteredMutationOverTimeData', () => {
const someSubstitutionEntry: SubstitutionEntry<Substitution> = {
type: 'substitution',
mutation: someSubstitution,
count: 123,
count: 234,
proportion: inFilter,
};

const anotherSubstitution: Substitution = {
type: 'substitution',
valueAtReference: 'A',
substitutionValue: 'T',
code: 'A123T',
valueAtReference: 'G',
substitutionValue: 'C',
code: 'G345C',
segment: 'someOtherSegment',
position: 123,
position: 345,
};
const anotherSubstitutionEntry: SubstitutionEntry<Substitution> = {
type: 'substitution',
mutation: anotherSubstitution,
count: 123,
count: 456,
proportion: inFilter,
};

const someDeletion: Deletion = {
type: 'deletion',
valueAtReference: 'A',
segment: 'someSegment',
position: 123,
position: 567,
code: 'A123-',
};
const someDeletionEntry: DeletionEntry<Deletion> = {
type: 'deletion',
mutation: someDeletion,
count: 123,
count: 789,
proportion: inFilter,
};
const someTemporal = yearMonthDay('2021-01-01');
Expand All @@ -217,33 +190,18 @@ describe('getFilteredMutationOverTimeData', () => {
totalCount: 10,
};

function prepareMutationOverTimeData() {
function prepareMutationOverTimeData(
mutationEntries: (SubstitutionEntry<Substitution> | DeletionEntry<Deletion>)[],
temporals: TemporalClass[] = [someTemporal, anotherTemporal],
) {
const data = new Map2dBase<Substitution | Deletion, TemporalClass, MutationOverTimeMutationValue>();

data.set(someSubstitution, someTemporal, someMutationOverTimeValue);
data.set(someSubstitution, anotherTemporal, someMutationOverTimeValue);

data.set(anotherSubstitution, someTemporal, someMutationOverTimeValue);
data.set(anotherSubstitution, anotherTemporal, someMutationOverTimeValue);

data.set(someDeletion, someTemporal, someMutationOverTimeValue);
data.set(someDeletion, anotherTemporal, someMutationOverTimeValue);

return data;
}

function prepareMutationOverTimeDataWithOneMutationWithProportion(proportion: number) {
const data = new Map2dBase<Substitution | Deletion, TemporalClass, MutationOverTimeMutationValue>();

data.set(someSubstitution, someTemporal, { ...someMutationOverTimeValue, proportion });
data.set(someSubstitution, anotherTemporal, someMutationOverTimeValue);

data.set(anotherSubstitution, someTemporal, someMutationOverTimeValue);
data.set(anotherSubstitution, anotherTemporal, someMutationOverTimeValue);

data.set(someDeletion, someTemporal, someMutationOverTimeValue);
data.set(someDeletion, anotherTemporal, someMutationOverTimeValue);
temporals.forEach((temporal) => {
mutationEntries.forEach((entry) => {
data.set(entry.mutation, temporal, someMutationOverTimeValue);
});
});

return data;
return { data, overallMutationData: mutationEntries };
}
});

0 comments on commit a6b4817

Please sign in to comment.