Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser): render XX and XY sums in variant table #1581

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 18 additions & 32 deletions browser/src/VariantList/mergeExomeAndGenomeData.spec.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,22 @@
import { describe, it, expect } from '@jest/globals'

import { populationFactory, variantFactory } from '../__factories__/Variant'
import { createAncestryGroupObjects, variantFactory } from '../__factories__/Variant'
import { Population } from '../VariantPage/VariantPage'

import {
mergeExomeGenomeAndJointPopulationData,
mergeExomeAndGenomeData,
} from './mergeExomeAndGenomeData'

type AncestryGroupShorthand = {
id: string
value: number
}

const createAncestryGroupObjects = (
shorthands: AncestryGroupShorthand[],
includeJointFields: boolean
) => {
const geneticAncestryGroupObjects: Population[] = shorthands.map((shorthand) => {
const populationFields: any = {
id: shorthand.id,
ac: shorthand.value,
an: shorthand.value * 10,
ac_hemi: shorthand.value + 1,
ac_hom: shorthand.value + 2,
}

if (includeJointFields) {
populationFields.hemizygote_count = shorthand.value + 1
populationFields.homozygote_count = shorthand.value + 2
}
return populationFactory.build(populationFields)
})

return geneticAncestryGroupObjects
}

describe('mergeExomeGenomeAndJointPopulationData', () => {
it('returns expected values when exomes and genomes have the same populations', () => {
const geneticAncestryGroupObjects = createAncestryGroupObjects(
[
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
{ id: 'XX', value: 8 },
{ id: 'XY', value: 16 },
],
false
)
Expand All @@ -62,6 +36,8 @@ describe('mergeExomeGenomeAndJointPopulationData', () => {
{ ac: 2, ac_hemi: 4, ac_hom: 6, an: 20, id: 'afr' },
{ ac: 4, ac_hemi: 6, ac_hom: 8, an: 40, id: 'remaining' },
{ ac: 8, ac_hemi: 10, ac_hom: 12, an: 80, id: 'eur' },
{ ac: 16, ac_hemi: 18, ac_hom: 20, an: 160, id: 'XX' },
{ ac: 32, ac_hemi: 34, ac_hom: 36, an: 320, id: 'XY' },
]

expect(result).toStrictEqual(expected)
Expand Down Expand Up @@ -250,15 +226,19 @@ describe('mergeExomeGenomeAndJointPopulationData', () => {
{ id: 'eur', value: 1 },
{ id: 'afr', value: 2 },
{ id: 'remaining', value: 4 },
{ id: 'XX', value: 8 },
{ id: 'XY', value: 16 },
],
false
)

const genomeGeneticAncestryGroupObjects = createAncestryGroupObjects(
[
{ id: 'afr', value: 8 },
{ id: 'remaining', value: 16 },
{ id: 'eur', value: 32 },
{ id: 'afr', value: 32 },
{ id: 'remaining', value: 64 },
{ id: 'eur', value: 128 },
{ id: 'XX', value: 256 },
{ id: 'XY', value: 512 },
],
false
)
Expand All @@ -270,6 +250,8 @@ describe('mergeExomeGenomeAndJointPopulationData', () => {
{ ac: 32, hemizygote_count: 33, homozygote_count: 34, an: 320, id: 'remaining' },
{ ac: 64, hemizygote_count: 65, homozygote_count: 66, an: 640, id: 'eur' },
{ ac: 128, hemizygote_count: 129, homozygote_count: 130, an: 1280, id: 'mid' },
{ ac: 256, hemizygote_count: 257, homozygote_count: 258, an: 2560, id: 'XX' },
{ ac: 512, hemizygote_count: 513, homozygote_count: 514, an: 5120, id: 'XY' },
]

const testVariant = variantFactory.build({
Expand All @@ -294,6 +276,8 @@ describe('mergeExomeGenomeAndJointPopulationData', () => {
{ id: 'remaining', value: 32 },
{ id: 'eur', value: 64 },
{ id: 'mid', value: 128 },
{ id: 'XX', value: 256 },
{ id: 'XY', value: 512 },
],
true
)
Expand Down Expand Up @@ -346,6 +330,8 @@ describe('mergeExomeAndGenomeData', () => {
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
{ id: 'XX', value: 8 },
{ id: 'XY', value: 16 },
],
false
)
Expand Down
7 changes: 6 additions & 1 deletion browser/src/VariantList/mergeExomeAndGenomeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ const addMissingAncestries = (
findAncestries(versionAncestry, currentAncestries) || emptyAncestries(versionAncestry)
)

return fullAncestries
const totalXX = currentAncestries.filter((ancestry) => ancestry.id === 'XX')
const totalXY = currentAncestries.filter((ancestry) => ancestry.id === 'XY')

const fullAncestriesWithTotalKaryotypes = fullAncestries.concat(totalXX, totalXY)

return fullAncestriesWithTotalKaryotypes
}

export const mergeExomeGenomeAndJointPopulationData = ({
Expand Down
71 changes: 71 additions & 0 deletions browser/src/VariantPage/GnomadPopulationsTable.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react'
import { describe, expect, test } from '@jest/globals'
import renderer from 'react-test-renderer'

import { GnomadPopulationsTable } from './GnomadPopulationsTable'
import { allDatasetIds } from '@gnomad/dataset-metadata/metadata'
import { createAncestryGroupObjects } from '../__factories__/Variant'

describe('GnomadPopulationsTable', () => {
describe.each(allDatasetIds)('with a dataset of %s', (dataset: any) => {
test('has no unexpected changes', () => {
const exomeGeneticAncestryGroupObjexts = createAncestryGroupObjects(
[
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
{ id: 'XX', value: 8 },
{ id: 'XY', value: 16 },
],
false
)

const genomeGeneticAncestryGroupObjexts = createAncestryGroupObjects(
[
{ id: 'afr', value: 32 },
{ id: 'remaining', value: 64 },
{ id: 'eur', value: 128 },
{ id: 'XX', value: 256 },
{ id: 'XY', value: 512 },
],
false
)

const tree = renderer.create(
<GnomadPopulationsTable
datasetId={dataset}
exomePopulations={exomeGeneticAncestryGroupObjexts}
genomePopulations={genomeGeneticAncestryGroupObjexts}
jointPopulations={null}
showHemizygotes={false}
/>
)

expect(tree).toMatchSnapshot()
})
test('has no unexpected changes when missing genetic ancestry groups are filled in', () => {
const jointGeneticAncestryGroupObjects = createAncestryGroupObjects(
[
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
{ id: 'XX', value: 8 },
{ id: 'XY', value: 16 },
],
true
)

const tree = renderer.create(
<GnomadPopulationsTable
datasetId={dataset}
exomePopulations={[]}
genomePopulations={[]}
jointPopulations={jointGeneticAncestryGroupObjects}
showHemizygotes={false}
/>
)

expect(tree).toMatchSnapshot()
})
})
})
Loading
Loading