Skip to content

Commit

Permalink
fix(frontend): always prefer joint freq data when merging
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyhgrant committed May 7, 2024
1 parent a392b10 commit b3830a6
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 7 deletions.
328 changes: 327 additions & 1 deletion browser/src/VariantList/mergeExomeAndGenomeData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { describe, it, expect } from '@jest/globals'
import { populationFactory, variantFactory } from '../__factories__/Variant'
import { Population } from '../VariantPage/VariantPage'

import { mergeExomeAndGenomePopulationData } from './mergeExomeAndGenomeData'
import {
mergeExomeAndGenomePopulationData,
mergeExomeAndGenomeData,
} from './mergeExomeAndGenomeData'
import { PopulationId } from '@gnomad/dataset-metadata/gnomadPopulations'

type AncestryGroupShorthand = {
Expand Down Expand Up @@ -144,3 +147,326 @@ describe('mergeExomeAndGenomePopulationData', () => {
expect(result).toStrictEqual(expected)
})
})

describe('mergeExomeAndGenomeData', () => {
it('returns expected values with just exome data', () => {
const exomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
])
const testExomeOnlyVariant = variantFactory.build({
variant_id: 'test_variant',
exome: {
ac: 1,
ac_hemi: 2,
ac_hom: 3,
an: 4,
af: 5,
faf95: undefined,
filters: ['RF'],
populations: exomeGeneticAncestryGroupObjects,
},
})

const result = mergeExomeAndGenomeData([testExomeOnlyVariant])

const expected = [
{
...testExomeOnlyVariant,
ac: 1,
ac_hemi: 2,
ac_hom: 3,
an: 4,
af: 5,
allele_freq: 5,
faf95: undefined,
filters: ['RF'],
populations: exomeGeneticAncestryGroupObjects,
},
]

expect(result).toStrictEqual(expected)
})
it('returns expected values with just genome data', () => {
const genomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 8 },
{ id: 'remaining', value: 16 },
{ id: 'eur', value: 32 },
{ id: 'mid', value: 64 },
])
const testGenomeOnlyVariant = variantFactory.build({
variant_id: 'test_variant',
genome: {
ac: 2,
ac_hemi: 3,
ac_hom: 4,
an: 5,
af: 6,
faf95: undefined,
filters: ['AC0'],
populations: genomeGeneticAncestryGroupObjects,
},
})

const result = mergeExomeAndGenomeData([testGenomeOnlyVariant])

const expected = [
{
...testGenomeOnlyVariant,
ac: 2,
ac_hemi: 3,
ac_hom: 4,
an: 5,
af: 6,
allele_freq: 6,
faf95: undefined,
filters: ['AC0'],
populations: genomeGeneticAncestryGroupObjects,
},
]

expect(result).toStrictEqual(expected)
})

it('returns expected values with exome and genome data', () => {
const exomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
])

const genomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 8 },
{ id: 'remaining', value: 16 },
{ id: 'eur', value: 32 },
{ id: 'mid', value: 64 },
])

const testExomeAndGenomeVariant = variantFactory.build({
variant_id: 'test_variant',
exome: {
ac: 1,
ac_hemi: 2,
ac_hom: 3,
an: 4,
faf95: undefined,
filters: ['RF'],
populations: exomeGeneticAncestryGroupObjects,
},
genome: {
ac: 2,
ac_hemi: 3,
ac_hom: 4,
an: 6,
faf95: undefined,
filters: ['AC0'],
populations: genomeGeneticAncestryGroupObjects,
},
})

const result = mergeExomeAndGenomeData([testExomeAndGenomeVariant])

const expected = [
{
...testExomeAndGenomeVariant,
ac: 3,
ac_hemi: 5,
ac_hom: 7,
an: 10,
af: 0.3,
allele_freq: 0.3,
filters: ['RF', 'AC0'],
populations: [
{ ac: 9, ac_hemi: 11, ac_hom: 13, an: 90, id: 'afr' },
{ ac: 18, ac_hemi: 20, ac_hom: 22, an: 180, id: 'remaining' },
{ ac: 36, ac_hemi: 38, ac_hom: 40, an: 360, id: 'eur' },
{ ac: 64, ac_hemi: 65, ac_hom: 66, an: 640, id: 'mid' },
],
},
]

expect(result).toStrictEqual(expected)
})
it('returns expected values with exome and joint data', () => {
const exomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
])
const jointGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 8 },
{ id: 'remaining', value: 16 },
{ id: 'eur', value: 32 },
{ id: 'mid', value: 64 },
])
const testExomeAndJointVariant = variantFactory.build({
variant_id: 'test_variant',
exome: {
ac: 1,
ac_hemi: 2,
ac_hom: 3,
an: 4,
af: 5,
faf95: undefined,
filters: ['RF'],
populations: exomeGeneticAncestryGroupObjects,
},
joint: {
ac: 10,
hemizygote_count: 20,
homozygote_count: 30,
an: 40,
faf95: undefined,
filters: ['RF'],
populations: jointGeneticAncestryGroupObjects,
},
})

const result = mergeExomeAndGenomeData([testExomeAndJointVariant])

const expected = [
{
...testExomeAndJointVariant,
ac: 10,
hemizygote_count: 20,
homozygote_count: 30,
an: 40,
allele_freq: 0.25,
faf95: undefined,
filters: ['RF'],
populations: jointGeneticAncestryGroupObjects,
},
]

expect(result).toStrictEqual(expected)
})
it('returns expected values with genome and joint data', () => {
const genomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 8 },
{ id: 'remaining', value: 16 },
{ id: 'eur', value: 32 },
{ id: 'mid', value: 64 },
])
const jointGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
])
const testGenomeAndJointVariant = variantFactory.build({
variant_id: 'test_variant',
genome: {
ac: 1,
ac_hemi: 2,
ac_hom: 3,
an: 4,
af: 5,
faf95: undefined,
filters: ['RF'],
populations: genomeGeneticAncestryGroupObjects,
},
joint: {
ac: 10,
hemizygote_count: 20,
homozygote_count: 30,
an: 40,
faf95: undefined,
filters: ['RF'],
populations: jointGeneticAncestryGroupObjects,
},
})

const result = mergeExomeAndGenomeData([testGenomeAndJointVariant])

const expected = [
{
...testGenomeAndJointVariant,
ac: 10,
hemizygote_count: 20,
homozygote_count: 30,
an: 40,
allele_freq: 0.25,
faf95: undefined,
filters: ['RF'],
populations: jointGeneticAncestryGroupObjects,
},
]

expect(result).toStrictEqual(expected)
})
it('returns expected values with exome, genome, and joint data', () => {
const exomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
])
const genomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 8 },
{ id: 'remaining', value: 16 },
{ id: 'eur', value: 32 },
{ id: 'mid', value: 64 },
])
const jointGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 10 },
{ id: 'remaining', value: 20 },
{ id: 'eur', value: 40 },
{ id: 'mid', value: 80 },
{ id: 'sas', value: 160 },
])
const testExomeGenomeAndJointVariant = variantFactory.build({
variant_id: 'test_variant',
exome: {
ac: 1,
ac_hemi: 2,
ac_hom: 3,
an: 4,
af: 5,
faf95: undefined,
filters: ['RF'],
populations: exomeGeneticAncestryGroupObjects,
},
genome: {
ac: 2,
ac_hemi: 4,
ac_hom: 5,
an: 6,
af: 5,
faf95: undefined,
filters: ['AC0'],
populations: genomeGeneticAncestryGroupObjects,
},
joint: {
ac: 10,
hemizygote_count: 20,
homozygote_count: 30,
an: 40,
faf95: undefined,
filters: ['discrepant_frequencies'],
populations: jointGeneticAncestryGroupObjects,
},
})

const result = mergeExomeAndGenomeData([testExomeGenomeAndJointVariant])

const expected = [
{
...testExomeGenomeAndJointVariant,
ac: 10,
ac_hemi: 20,
ac_hom: 30,
an: 40,
af: 0.25,
allele_freq: 0.25,
filters: ['RF', 'AC0', 'discrepant_frequencies'],
populations: [
{ ac: 9, ac_hemi: 11, ac_hom: 13, an: 90, id: 'afr' },
{ ac: 18, ac_hemi: 20, ac_hom: 22, an: 180, id: 'remaining' },
{ ac: 36, ac_hemi: 38, ac_hom: 40, an: 360, id: 'eur' },
{ ac: 64, ac_hemi: 65, ac_hom: 66, an: 640, id: 'mid' },
],
},
]

expect(result).toStrictEqual(expected)
})
})
28 changes: 22 additions & 6 deletions browser/src/VariantList/mergeExomeAndGenomeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,37 @@ export const mergeExomeAndGenomePopulationData = (
return Object.values(populations)
}

const mergeExomeAndGenomeData = (variants: any) =>
export const mergeExomeAndGenomeData = (variants: any) =>
variants.map((variant: any) => {
const { exome, genome } = variant
const { exome, genome, joint } = variant
if (!exome) {
if (!joint) {
return {
...variant,
...variant.genome,
allele_freq: variant.genome.af, // hack for variant track which expects allele_freq field
}
}
return {
...variant,
...variant.genome,
allele_freq: variant.genome.af, // hack for variant track which expects allele_freq field
...variant.joint,
filters: variant.genome.filters,
allele_freq: variant.joint.ac / variant.joint.an,
}
}
if (!genome) {
if (!joint) {
return {
...variant,
...variant.exome,
allele_freq: variant.exome.af, // hack for variant track which expects allele_freq field
}
}
return {
...variant,
...variant.exome,
allele_freq: variant.exome.af, // hack for variant track which expects allele_freq field
...variant.joint,
filters: variant.exome.filters,
allele_freq: variant.joint.ac / variant.joint.an, // hack for variant track which expects allele_freq field
}
}

Expand Down
1 change: 1 addition & 0 deletions browser/src/VariantPage/VariantPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export type SequencingType = BaseSequencingType & {
local_ancestry_populations: LocalAncestryPopulation[]
ac_hom: number
ac_hemi: number
af?: number
}

export type JointSequencingType = BaseSequencingType & {
Expand Down

0 comments on commit b3830a6

Please sign in to comment.