Skip to content

Commit

Permalink
fixup: avoid "as any"
Browse files Browse the repository at this point in the history
  • Loading branch information
phildarnowsky-broad committed Feb 24, 2025
1 parent 69d9539 commit f2d8a64
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
67 changes: 29 additions & 38 deletions browser/src/ShortTandemRepeatPage/ShortTandemRepeatAttributes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,59 @@ import AttributeList, { AttributeListItem } from '../AttributeList'
import InlineList from '../InlineList'
import Link from '../Link'

import { ShortTandemRepeat } from './ShortTandemRepeatPage'
import { ShortTandemRepeat, RepeatUnitClassification } from './ShortTandemRepeatPage'

type ShortTandemRepeatRepeatUnitsProps = {
shortTandemRepeat: ShortTandemRepeat
}

const ShortTandemRepeatRepeatUnits = ({ shortTandemRepeat }: ShortTandemRepeatRepeatUnitsProps) => {
const repeatUnitsByClassification: Record<string, string[]> = {}
const repeatUnitsByClassification: Partial<Record<RepeatUnitClassification, string[]>> = {}
shortTandemRepeat.repeat_units.forEach((repeatUnit) => {
if (repeatUnitsByClassification[repeatUnit.classification] === undefined) {
repeatUnitsByClassification[repeatUnit.classification] = []
}
repeatUnitsByClassification[repeatUnit.classification].push(repeatUnit.repeat_unit)
repeatUnitsByClassification[repeatUnit.classification]!.push(repeatUnit.repeat_unit)
})

if (
!(repeatUnitsByClassification as any).pathogenic &&
!(repeatUnitsByClassification as any).benign
!repeatUnitsByClassification.pathogenic &&
!repeatUnitsByClassification.benign &&
repeatUnitsByClassification.unknown
) {
return (
<AttributeListItem
label={`Repeat unit${(repeatUnitsByClassification as any).unknown.length > 1 ? 's' : ''}`}
label={`Repeat unit${repeatUnitsByClassification.unknown.length > 1 ? 's' : ''}`}
>
<InlineList
items={(repeatUnitsByClassification as any).unknown.map((repeatUnit: string) => (
items={repeatUnitsByClassification.unknown.map((repeatUnit: string) => (
<span>
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
shortTandemRepeat.repeat_units.length > 1
? `${repeatUnit} (reference)`
: repeatUnit}
</span>
))}
label={`Repeat unit${(repeatUnitsByClassification as any).unknown.length > 1 ? 's' : ''}`}
label={`Repeat unit${repeatUnitsByClassification.unknown.length > 1 ? 's' : ''}`}
/>
</AttributeListItem>
)
}

if (
(repeatUnitsByClassification as any).pathogenic &&
(repeatUnitsByClassification as any).pathogenic.length === 1 &&
!(repeatUnitsByClassification as any).benign &&
!(repeatUnitsByClassification as any).unknown
repeatUnitsByClassification.pathogenic &&
repeatUnitsByClassification.pathogenic.length === 1 &&
repeatUnitsByClassification.benign &&
repeatUnitsByClassification.unknown
) {
return (
<>
{(repeatUnitsByClassification as any).pathogenic && (
{repeatUnitsByClassification.pathogenic && (
<AttributeListItem
label={`Repeat unit${
(repeatUnitsByClassification as any).pathogenic.length > 1 ? 's' : ''
}`}
label={`Repeat unit${repeatUnitsByClassification.pathogenic.length > 1 ? 's' : ''}`}
>
<InlineList
items={(repeatUnitsByClassification as any).pathogenic.map((repeatUnit: string) => (
items={repeatUnitsByClassification.pathogenic.map((repeatUnit: string) => (
<span>
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
shortTandemRepeat.repeat_units.length > 1
Expand All @@ -66,7 +65,7 @@ const ShortTandemRepeatRepeatUnits = ({ shortTandemRepeat }: ShortTandemRepeatRe
</span>
))}
label={`Pathogenic repeat unit${
(repeatUnitsByClassification as any).pathogenic.length > 1 ? 's' : ''
repeatUnitsByClassification.pathogenic.length > 1 ? 's' : ''
}`}
/>
</AttributeListItem>
Expand All @@ -77,15 +76,15 @@ const ShortTandemRepeatRepeatUnits = ({ shortTandemRepeat }: ShortTandemRepeatRe

return (
<>
{(repeatUnitsByClassification as any).pathogenic && (
{repeatUnitsByClassification.pathogenic && (
<AttributeListItem
label={`Pathogenic repeat unit${
(repeatUnitsByClassification as any).pathogenic.length > 1 ? 's' : ''
repeatUnitsByClassification.pathogenic.length > 1 ? 's' : ''
}`}
tooltip="These repeat units have been reported in the literature as pathogenic when they expand beyond a certain threshold."
>
<InlineList
items={(repeatUnitsByClassification as any).pathogenic.map((repeatUnit: string) => (
items={repeatUnitsByClassification.pathogenic.map((repeatUnit: string) => (
<span>
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
shortTandemRepeat.repeat_units.length > 1
Expand All @@ -94,52 +93,44 @@ const ShortTandemRepeatRepeatUnits = ({ shortTandemRepeat }: ShortTandemRepeatRe
</span>
))}
label={`Pathogenic repeat unit${
(repeatUnitsByClassification as any).pathogenic.length > 1 ? 's' : ''
repeatUnitsByClassification.pathogenic.length > 1 ? 's' : ''
}`}
/>
</AttributeListItem>
)}
{(repeatUnitsByClassification as any).benign && (
{repeatUnitsByClassification.benign && (
<AttributeListItem
label={`Benign repeat unit${
(repeatUnitsByClassification as any).benign.length > 1 ? 's' : ''
}`}
label={`Benign repeat unit${repeatUnitsByClassification.benign.length > 1 ? 's' : ''}`}
tooltip="These repeat units are regarded in the literature as benign, even when expanded."
>
<InlineList
items={(repeatUnitsByClassification as any).benign.map((repeatUnit: string) => (
items={repeatUnitsByClassification.benign.map((repeatUnit: string) => (
<span>
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
shortTandemRepeat.repeat_units.length > 1
? `${repeatUnit} (reference)`
: repeatUnit}
</span>
))}
label={`Benign repeat unit${
(repeatUnitsByClassification as any).benign.length > 1 ? 's' : ''
}`}
label={`Benign repeat unit${repeatUnitsByClassification.benign.length > 1 ? 's' : ''}`}
/>
</AttributeListItem>
)}
{(repeatUnitsByClassification as any).unknown && (
{repeatUnitsByClassification.unknown && (
<AttributeListItem
label={`Other repeat unit${
(repeatUnitsByClassification as any).unknown.length > 1 ? 's' : ''
}`}
label={`Other repeat unit${repeatUnitsByClassification.unknown.length > 1 ? 's' : ''}`}
tooltip="These are the other repeat units detected at this locus within gnomAD samples by the call_non_ref_pathogenic_motifs.py script."
>
<InlineList
items={(repeatUnitsByClassification as any).unknown.map((repeatUnit: string) => (
items={repeatUnitsByClassification.unknown.map((repeatUnit: string) => (
<span>
{repeatUnit === shortTandemRepeat.reference_repeat_unit &&
shortTandemRepeat.repeat_units.length > 1
? `${repeatUnit} (reference)`
: repeatUnit}
</span>
))}
label={`Other repeat unit${
(repeatUnitsByClassification as any).unknown.length > 1 ? 's' : ''
}`}
label={`Other repeat unit${repeatUnitsByClassification.unknown.length > 1 ? 's' : ''}`}
/>
</AttributeListItem>
)}
Expand Down
4 changes: 3 additions & 1 deletion browser/src/ShortTandemRepeatPage/ShortTandemRepeatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export type PlotRange = {
stop: number
}

export type RepeatUnitClassification = 'benign' | 'pathogenic' | 'unknown'

export type ShortTandemRepeat = {
id: string
gene: {
Expand All @@ -115,7 +117,7 @@ export type ShortTandemRepeat = {
reference_repeat_unit: string
repeat_units: {
repeat_unit: string
classification: string
classification: RepeatUnitClassification
}[]
allele_size_distribution: AlleleSizeDistributionCohort[]
genotype_distribution: GenotypeDistributionCohort[]
Expand Down

0 comments on commit f2d8a64

Please sign in to comment.