Skip to content

Commit

Permalink
fix(components): gs-mutation-filter: allow for reference genome with …
Browse files Browse the repository at this point in the history
…no genes
  • Loading branch information
Jonas Zarzalis (TNG) authored and JonasKellerer committed Jan 28, 2025
1 parent db5abc3 commit af26d8b
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 118 deletions.
68 changes: 68 additions & 0 deletions components/src/preact/mutationFilter/ExampleMutation.tsx
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`;
}
}
}
}
}
}
Loading

0 comments on commit af26d8b

Please sign in to comment.