-
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.
fix(components): gs-mutation-filter: allow for reference genome with …
…no genes
- Loading branch information
1 parent
db5abc3
commit af26d8b
Showing
4 changed files
with
258 additions
and
118 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,68 @@ | ||
import { useContext } from 'preact/hooks'; | ||
import type { FC } from 'react'; | ||
|
||
import { type ReferenceGenome } from '../../lapisApi/ReferenceGenome'; | ||
import type { SequenceType } from '../../types'; | ||
import { ReferenceGenomeContext } from '../ReferenceGenomeContext'; | ||
|
||
type ExampleMutationProps = { | ||
sequenceType: SequenceType; | ||
mutationType: 'substitution' | 'insertion'; | ||
}; | ||
|
||
export const ExampleMutation: FC<ExampleMutationProps> = ({ sequenceType, mutationType }) => { | ||
const referenceGenome = useContext(ReferenceGenomeContext); | ||
|
||
return <b>{getExampleMutation(referenceGenome, sequenceType, mutationType)}</b>; | ||
}; | ||
|
||
export function getExampleMutation( | ||
referenceGenome: ReferenceGenome, | ||
sequenceType: SequenceType, | ||
mutationType: 'substitution' | 'insertion', | ||
) { | ||
switch (sequenceType) { | ||
case 'amino acid': { | ||
if (referenceGenome.genes.length === 0) { | ||
return ''; | ||
} | ||
|
||
const firstGene = referenceGenome.genes[0].name; | ||
|
||
switch (mutationType) { | ||
case 'substitution': | ||
return `${firstGene}:57Q`; | ||
case 'insertion': | ||
return `ins_${firstGene}:31:N`; | ||
} | ||
} | ||
// Issue of linter https://github.com/typescript-eslint/typescript-eslint/issues/3455 | ||
// eslint-disable-next-line no-fallthrough | ||
case 'nucleotide': { | ||
switch (referenceGenome.nucleotideSequences.length) { | ||
case 0: { | ||
return ''; | ||
} | ||
case 1: { | ||
switch (mutationType) { | ||
case 'substitution': | ||
return '23T'; | ||
case 'insertion': | ||
return 'ins_1046:A'; | ||
} | ||
} | ||
// Issue of linter https://github.com/typescript-eslint/typescript-eslint/issues/3455 | ||
// eslint-disable-next-line no-fallthrough | ||
default: { | ||
const firstSegment = referenceGenome.nucleotideSequences[0].name; | ||
switch (mutationType) { | ||
case 'substitution': | ||
return `${firstSegment}:23T`; | ||
case 'insertion': | ||
return `ins_${firstSegment}:10462:A`; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.