Skip to content

Commit

Permalink
fix(browser): allow viewing single source grp freqs on variant page
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyhgrant committed Nov 1, 2024
1 parent f89a77b commit 504450c
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 1,373 deletions.
25 changes: 14 additions & 11 deletions browser/src/VariantPage/GnomadPopulationsTable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 { allDatasetIds, getTopLevelDataset } from '@gnomad/dataset-metadata/metadata'
import { createAncestryGroupObjects } from '../__factories__/Variant'

describe('GnomadPopulationsTable', () => {
Expand Down Expand Up @@ -44,16 +44,19 @@ describe('GnomadPopulationsTable', () => {
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 jointGeneticAncestryGroupObjects =
getTopLevelDataset(dataset) === 'v4'
? createAncestryGroupObjects(
[
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
{ id: 'XX', value: 8 },
{ id: 'XY', value: 16 },
],
true
)
: null

const tree = renderer.create(
<GnomadPopulationsTable
Expand Down
24 changes: 13 additions & 11 deletions browser/src/VariantPage/GnomadPopulationsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export class GnomadPopulationsTable extends Component<
super(props)

this.state = {
includeExomes: props.exomePopulations.length !== 0,
includeGenomes: props.genomePopulations.length !== 0,
includeExomes: props.exomePopulations.length !== 0 || !!props.jointPopulations,
includeGenomes: props.genomePopulations.length !== 0 || !!props.jointPopulations,
}
}

Expand All @@ -118,13 +118,7 @@ export class GnomadPopulationsTable extends Component<
exomePopulations: includeExomes ? exomePopulations : [],
genomePopulations: includeGenomes ? genomePopulations : [],
jointPopulations:
// if theres joint data, but no variant present in genomes, still use joint
(includeExomes || exomePopulations.length === 0) &&
// if theres joint data, but no variant present in exomes, still use joint
(includeGenomes || genomePopulations.length === 0) &&
jointPopulations
? jointPopulations
: null,
includeExomes && includeGenomes && jointPopulations ? jointPopulations : null,
}).filter((mergedAncestry) => (mergedAncestry.id as string) !== '')

const mergedPopulationsWithNames = addPopulationNames(mergedPopulations)
Expand Down Expand Up @@ -159,6 +153,14 @@ export class GnomadPopulationsTable extends Component<
})
}

const disableExomesCheckbox =
(jointPopulations && exomePopulations.length !== 0 && genomePopulations.length === 0) ||
(!jointPopulations && (exomePopulations.length === 0 || (includeExomes && !includeGenomes)))

const disableGenomesCheckbox =
(jointPopulations && exomePopulations.length === 0 && genomePopulations.length !== 0) ||
(!jointPopulations && (genomePopulations.length === 0 || (!includeExomes && includeGenomes)))

return (
<>
<PopulationsTable
Expand All @@ -177,7 +179,7 @@ export class GnomadPopulationsTable extends Component<
Include:
<Checkbox
checked={includeExomes}
disabled={exomePopulations.length === 0 || (includeExomes && !includeGenomes)}
disabled={disableExomesCheckbox}
id="includeExomePopulations"
label="Exomes"
onChange={(value) => {
Expand All @@ -186,7 +188,7 @@ export class GnomadPopulationsTable extends Component<
/>
<Checkbox
checked={includeGenomes}
disabled={genomePopulations.length === 0 || (!includeExomes && includeGenomes)}
disabled={disableGenomesCheckbox}
id="includeGenomePopulations"
label="Genomes"
onChange={(value) => {
Expand Down
Loading

0 comments on commit 504450c

Please sign in to comment.