Skip to content

Commit

Permalink
feat(browser): sort ClinVar by consequence in table
Browse files Browse the repository at this point in the history
Sort ClinVar terms by their submitted classification, rather than lexicographically
  • Loading branch information
rileyhgrant committed Nov 21, 2024
1 parent 9503aaf commit 0f70e09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
18 changes: 17 additions & 1 deletion browser/src/ClinvarVariantsTrack/clinvarVariantCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CLINICAL_SIGNIFICANCE_GROUPS = {
'Conflicting classifications of pathogenicity',
'conflicting data from submitters',
]),
benign: new Set(['Benign', 'Likely benign', 'Benign/Likely benign']),
benign: new Set(['Likely benign', 'Benign/Likely benign', 'Benign']),
other: new Set([
'other',
'drug response',
Expand All @@ -29,6 +29,22 @@ const CLINICAL_SIGNIFICANCE_GROUPS = {
]),
} as const

const buildPriorityMapping = () => {
const mapping: { [key: string]: number } = {}
let priority = 1

for (const category of CLINICAL_SIGNIFICANCE_CATEGORIES) {

Check failure on line 36 in browser/src/ClinvarVariantsTrack/clinvarVariantCategories.ts

View workflow job for this annotation

GitHub Actions / Checks

iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations
const group = CLINICAL_SIGNIFICANCE_GROUPS[category as ClinicalSignificance]
for (const significance of group) {

Check failure on line 38 in browser/src/ClinvarVariantsTrack/clinvarVariantCategories.ts

View workflow job for this annotation

GitHub Actions / Checks

iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations
mapping[significance] = priority++

Check failure on line 39 in browser/src/ClinvarVariantsTrack/clinvarVariantCategories.ts

View workflow job for this annotation

GitHub Actions / Checks

Unary operator '++' used
}
}

return mapping
}

export const CLINICAL_SIGNIFICANCE_SORT_PRIORITY = buildPriorityMapping()

export type ClinicalSignificance = keyof typeof CLINICAL_SIGNIFICANCE_GROUPS

export const clinvarVariantClinicalSignificanceCategory = (variant: any) => {
Expand Down
10 changes: 10 additions & 0 deletions browser/src/VariantList/sortUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CLINICAL_SIGNIFICANCE_SORT_PRIORITY } from '../ClinvarVariantsTrack/clinvarVariantCategories'

export const isEmpty = (val: any) => val === undefined || val === null || val === ''

export const makeCompareFunction =
Expand Down Expand Up @@ -29,3 +31,11 @@ export const makeStringCompareFunction = (key: any) =>

export const makeNumericCompareFunction = (key: any) =>
makeCompareFunction(key, (v1: any, v2: any) => v1 - v2)

export const makeClinvarCompareFunction = (key: any) =>
makeCompareFunction(key, (v1: string, v2: string) => {
return (
(CLINICAL_SIGNIFICANCE_SORT_PRIORITY[v1] ?? 999) -
(CLINICAL_SIGNIFICANCE_SORT_PRIORITY[v2] ?? 999)
)
})
3 changes: 2 additions & 1 deletion browser/src/VariantList/variantTableColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Cell, NumericCell, renderAlleleCountCell, renderAlleleFrequencyCell } f
import { getCategoryFromConsequence, getLabelForConsequenceTerm } from '../vepConsequences'
import SampleSourceIcon from './SampleSourceIcon'
import {
makeClinvarCompareFunction,
makeCompareFunction,
makeNumericCompareFunction,
makeStringCompareFunction,
Expand Down Expand Up @@ -126,7 +127,7 @@ const variantTableColumns: VariantTableColumn[] = [
description: 'ClinVar clinical significance',
grow: 1,
minWidth: 150,
compareFunction: makeStringCompareFunction('clinical_significance'),
compareFunction: makeClinvarCompareFunction('clinical_significance'),
getSearchTerms: (variant: any) => variant.clinical_significance,
render: (variant: any, _: any, { highlightWords }: any) => (
<Cell>
Expand Down

0 comments on commit 0f70e09

Please sign in to comment.