Skip to content

Commit

Permalink
fix: OMIM id extraction for link-out (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Dec 10, 2023
1 parent 374377a commit f362311
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
21 changes: 4 additions & 17 deletions frontend/src/components/GeneDetails/ConditionsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { computed, ref } from 'vue'
import type { HpoTerm } from '@/api/viguno'
import CadaRanking from '@/components/GeneDetails/ConditionsCard/CadaRanking.vue'
import { extractDbnsfpMimDiseaseId, transformDbnsfpMimDiseaseId } from '@/lib/utils'
export interface Props {
geneInfo: any
Expand All @@ -23,20 +24,6 @@ const showTermIds = ref<boolean>(false)
/** Whether to show terms as hyperlinks. */
const showTermLinks = ref<boolean>(true)
/** Extract MIM disease ID from dbSNFP string */
const extractMimDiseaseId = (id: string) => {
return id.split('[')[1].split(']')[0]
}
/** Transforms MIM disease ID from dbNSFP depending on `showTermIds.value` */
const transformMimDiseaseId = (id: string) => {
if (showTermIds.value) {
return id.replace(']', '] ')
} else {
return id.split(']')[1].trim()
}
}
// -- code for expanded / collapsed card --------------------------------------
/** Whether the card is expanded. */
Expand Down Expand Up @@ -153,15 +140,15 @@ const hpoTermsToShow = computed<HpoTerm[]>(() => {
<template v-if="idx > 0"> , </template>
<template v-if="showTermLinks">
<a
:href="`https://www.omim.org/entry/${extractMimDiseaseId(disease)}`"
:href="`https://www.omim.org/entry/${extractDbnsfpMimDiseaseId(disease)}`"
target="_blank"
>
<v-icon>mdi-launch</v-icon>
{{ transformMimDiseaseId(disease) }}
{{ transformDbnsfpMimDiseaseId(disease, showTermIds) }}
</a>
</template>
<template v-else>
{{ transformMimDiseaseId(disease) }}
{{ transformDbnsfpMimDiseaseId(disease, showTermIds) }}
</template>
</template>
</div>
Expand Down
42 changes: 40 additions & 2 deletions frontend/src/lib/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { describe, expect, it } from 'vitest'
import { describe, expect, it, test } from 'vitest'

import { type GenomeBuild } from '@/lib/genomeBuilds'
import { type Seqvar } from '@/lib/genomicVars'

import {
copy,
extractDbnsfpMimDiseaseId,
infoFromQuery,
isVariantMt,
isVariantMtHomopolymer,
removeCommasFromNumbers,
roundIt,
separateIt
separateIt,
transformDbnsfpMimDiseaseId
} from '../utils'

/** Example Sequence variant. */
Expand Down Expand Up @@ -185,3 +187,39 @@ describe.concurrent('copy method', () => {
expect(result).toEqual({ foo: 'bar' })
})
})

describe.concurrent('extractDbnsfpMimDiseaseId', () => {
test.each([
['[MIM:616921] Dyskinesia, limb and orofacial, infantile-onset', '616921'],
['[MIM:616921] Dyskinesia, limb and orofacial, infantile-onset [recessive?]', '616921']
])('%s => %s', (lhs, rhs) => {
expect(extractDbnsfpMimDiseaseId(lhs)).toEqual(rhs)
})
})

describe.concurrent('transformDbnsfpMimDiseaseId', () => {
test.each([
[
'[MIM:616921]Dyskinesia, limb and orofacial, infantile-onset',
'[MIM:616921] Dyskinesia, limb and orofacial, infantile-onset',
true
],
[
'[MIM:616921]Dyskinesia, limb and orofacial, infantile-onset [recessive?]',
'[MIM:616921] Dyskinesia, limb and orofacial, infantile-onset [recessive?]',
true
],
[
'[MIM:616921]Dyskinesia, limb and orofacial, infantile-onset',
'Dyskinesia, limb and orofacial, infantile-onset',
false
],
[
'[MIM:616921]Dyskinesia, limb and orofacial, infantile-onset [recessive?]',
'Dyskinesia, limb and orofacial, infantile-onset [recessive?]',
false
]
])('should work correctly', (lhs, rhs, showTermIds) => {
expect(transformDbnsfpMimDiseaseId(lhs, showTermIds)).toEqual(rhs)
})
})
18 changes: 18 additions & 0 deletions frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,21 @@ export const bookmarkTo = (bookmark: BookmarkData): RouteLocationRaw => {
}
}
}

/**
* Extract MIM disease ID from dbSNFP string
*/
export const extractDbnsfpMimDiseaseId = (id: string) => {
return id.split('[')[1].split(']', 1)[0].replace('MIM:', '')
}

/**
* Transforms MIM disease ID from dbNSFP depending on `showTermIds.value`
*/
export const transformDbnsfpMimDiseaseId = (id: string, showTermIds: boolean) => {
if (showTermIds) {
return id.replace(']', '] ')
} else {
return id.split(']').splice(1).join(']').trim()
}
}

0 comments on commit f362311

Please sign in to comment.