-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add insertion tab for mutations component
- Loading branch information
1 parent
0797bf4
commit 7259feb
Showing
38 changed files
with
845 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { type Dataset } from './Dataset'; | ||
import { type Operator } from './Operator'; | ||
import { type InsertionEntry, type LapisFilter, type SequenceType } from '../types'; | ||
import { MutationCache } from '../utils/mutations'; | ||
import { mapLapisFilterToUrlParams } from '../utils/utils'; | ||
|
||
export class FetchInsertionsOperator implements Operator<InsertionEntry> { | ||
constructor( | ||
private filter: LapisFilter, | ||
private sequenceType: SequenceType, | ||
) {} | ||
|
||
private async fetchInsertions( | ||
lapis: string, | ||
signal?: AbortSignal, | ||
): Promise<{ insertion: string; count: number }[]> { | ||
const endpoint = `${this.sequenceType === 'nucleotide' ? 'nuc' : 'aa'}-insertions`; | ||
const params = mapLapisFilterToUrlParams(this.filter); | ||
return (await (await fetch(`${lapis}/${endpoint}?${params.toString()}`, { signal })).json()).data; | ||
} | ||
|
||
async evaluate(lapis: string, signal?: AbortSignal): Promise<Dataset<InsertionEntry>> { | ||
const [insertions] = await Promise.all([this.fetchInsertions(lapis, signal)]); | ||
|
||
const mutationCache = MutationCache.getInstance(); | ||
const content: InsertionEntry[] = insertions.map(({ insertion, count }) => ({ | ||
type: 'insertion', | ||
mutation: mutationCache.getInsertion(insertion), | ||
count, | ||
})); | ||
|
||
return { content }; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
components/src/operator/FetchSubstitutionsOrDeletionsOperator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { type Dataset } from './Dataset'; | ||
import { type Operator } from './Operator'; | ||
import { type LapisFilter, type SequenceType, type SubstitutionOrDeletionEntry } from '../types'; | ||
import { MutationCache, Substitution } from '../utils/mutations'; | ||
import { mapLapisFilterToUrlParams } from '../utils/utils'; | ||
|
||
export class FetchSubstitutionsOrDeletionsOperator implements Operator<SubstitutionOrDeletionEntry> { | ||
constructor( | ||
private filter: LapisFilter, | ||
private sequenceType: SequenceType, | ||
private minProportion?: number, | ||
) {} | ||
|
||
async evaluate(lapis: string, signal?: AbortSignal): Promise<Dataset<SubstitutionOrDeletionEntry>> { | ||
const [mutations] = await Promise.all([this.fetchMutations(lapis, signal)]); | ||
|
||
const instance = MutationCache.getInstance(); | ||
const content: SubstitutionOrDeletionEntry[] = mutations.map(({ mutation, count, proportion }) => { | ||
const parsed = instance.getSubstitutionOrDeletion(mutation); | ||
return parsed instanceof Substitution | ||
? { type: 'substitution', mutation: parsed, count, proportion } | ||
: { type: 'deletion', mutation: parsed, count, proportion }; | ||
}); | ||
|
||
return { content }; | ||
} | ||
|
||
private async fetchMutations( | ||
lapis: string, | ||
signal?: AbortSignal, | ||
): Promise<{ mutation: string; count: number; proportion: number }[]> { | ||
const endpoint = `${this.sequenceType === 'nucleotide' ? 'nuc' : 'aa'}-mutations`; | ||
const params = mapLapisFilterToUrlParams(this.filter); | ||
if (this.minProportion !== undefined) { | ||
params.set('minProportion', this.minProportion.toString()); | ||
} | ||
return (await (await fetch(`${lapis}/${endpoint}?${params.toString()}`, { signal })).json()).data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
components/src/preact/mutations/getInsertionsTableData.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { getInsertionsTableData } from './getInsertionsTableData'; | ||
import { Insertion } from '../../utils/mutations'; | ||
|
||
describe('getInsertionsTableData', () => { | ||
test('should return the correct data', () => { | ||
const data = [ | ||
{ | ||
type: 'insertion' as const, | ||
mutation: new Insertion('segment1', 123, 'T'), | ||
count: 1, | ||
proportion: 0.1, | ||
}, | ||
{ | ||
type: 'insertion' as const, | ||
mutation: new Insertion('segment2', 234, 'AAA'), | ||
count: 2, | ||
proportion: 0.2, | ||
}, | ||
]; | ||
|
||
const result = getInsertionsTableData(data); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
insertion: 'ins_segment1:123:T', | ||
count: 1, | ||
}, | ||
{ | ||
insertion: 'ins_segment2:234:AAA', | ||
count: 2, | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { type InsertionEntry } from '../../types'; | ||
|
||
export function getInsertionsTableData(data: InsertionEntry[]) { | ||
return data.map((mutationEntry) => { | ||
return { | ||
insertion: mutationEntry.mutation.toString(), | ||
count: mutationEntry.count, | ||
}; | ||
}); | ||
} |
40 changes: 40 additions & 0 deletions
40
components/src/preact/mutations/getMutationsTableData.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { getMutationsTableData } from './getMutationsTableData'; | ||
import { Deletion, Substitution } from '../../utils/mutations'; | ||
|
||
describe('getMutationsTableData', () => { | ||
test('should return the correct data', () => { | ||
const data = [ | ||
{ | ||
type: 'substitution' as const, | ||
mutation: new Substitution('segment1', 'A', 'T', 123), | ||
count: 1, | ||
proportion: 0.1, | ||
}, | ||
{ | ||
type: 'deletion' as const, | ||
mutation: new Deletion('segment2', 'C', 123), | ||
count: 2, | ||
proportion: 0.2, | ||
}, | ||
]; | ||
|
||
const result = getMutationsTableData(data); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
mutation: 'segment1:A123T', | ||
type: 'substitution', | ||
count: 1, | ||
proportion: 0.1, | ||
}, | ||
{ | ||
mutation: 'segment2:C123-', | ||
type: 'deletion', | ||
count: 2, | ||
proportion: 0.2, | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type SubstitutionOrDeletionEntry } from '../../types'; | ||
|
||
export function getMutationsTableData(data: SubstitutionOrDeletionEntry[]) { | ||
return data.map((mutationEntry) => { | ||
return { | ||
mutation: mutationEntry.mutation.toString(), | ||
type: mutationEntry.type, | ||
count: mutationEntry.count, | ||
proportion: mutationEntry.proportion, | ||
}; | ||
}); | ||
} |
Oops, something went wrong.