Skip to content

Commit

Permalink
Change populations to ancestry_groups in variant page
Browse files Browse the repository at this point in the history
  • Loading branch information
phildarnowsky-broad committed Apr 2, 2024
1 parent 1c390b2 commit 12869f6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
6 changes: 3 additions & 3 deletions browser/src/VariantList/ExportVariantsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const getValueGivenProperty = (
variant: VariantTableVariant,
property: Property
) => {
return variant.populations.filter((v) => v.id === popId)[0]
? JSON.stringify(variant.populations.filter((v) => v.id === popId)[0][property])
return variant.ancestry_groups.filter((v) => v.id === popId)[0]
? JSON.stringify(variant.ancestry_groups.filter((v) => v.id === popId)[0][property])
: ''
}

Expand Down Expand Up @@ -342,7 +342,7 @@ export type VariantTableVariant = {
hgvs?: string
hgvsc?: string
hgvsp?: string
populations: Population[]
ancestry_groups: Population[]
pos: number
rsids?: string[]
transcript_id: string
Expand Down
24 changes: 12 additions & 12 deletions browser/src/VariantList/mergeExomeAndGenomeData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const createAncestryGroupObjects = (shorthands: AncestryGroupShorthand[]) => {
}

describe('mergeExomeAndGenomePopulationData', () => {
it('returns expected values when exomes and genomes have the same populations', () => {
it('returns expected values when exomes and genomes have the same ancestry_groups', () => {
const geneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
Expand All @@ -35,8 +35,8 @@ describe('mergeExomeAndGenomePopulationData', () => {

const testVariant = variantFactory.build({
variant_id: 'test_variant',
exome: { populations: geneticAncestryGroupObjects },
genome: { populations: geneticAncestryGroupObjects },
exome: { ancestry_groups: geneticAncestryGroupObjects },
genome: { ancestry_groups: geneticAncestryGroupObjects },
})

const result = mergeExomeAndGenomePopulationData(testVariant.exome!, testVariant.genome!)
Expand All @@ -50,7 +50,7 @@ describe('mergeExomeAndGenomePopulationData', () => {
expect(result).toStrictEqual(expected)
})

it('returns expected values when exomes have less populations than genomes', () => {
it('returns expected values when exomes have less ancestry_groups than genomes', () => {
const exomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
Expand All @@ -66,8 +66,8 @@ describe('mergeExomeAndGenomePopulationData', () => {

const testVariant = variantFactory.build({
variant_id: 'test_variant',
exome: { populations: exomeGeneticAncestryGroupObjects },
genome: { populations: genomeGeneticAncestryGroupObjects },
exome: { ancestry_groups: exomeGeneticAncestryGroupObjects },
genome: { ancestry_groups: genomeGeneticAncestryGroupObjects },
})

const result = mergeExomeAndGenomePopulationData(testVariant.exome!, testVariant.genome!)
Expand All @@ -82,7 +82,7 @@ describe('mergeExomeAndGenomePopulationData', () => {
expect(result).toStrictEqual(expected)
})

it('returns expected values exomes have more populations than genomes', () => {
it('returns expected values exomes have more ancestry_groups than genomes', () => {
const exomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
Expand All @@ -98,8 +98,8 @@ describe('mergeExomeAndGenomePopulationData', () => {

const testVariant = variantFactory.build({
variant_id: 'test_variant',
exome: { populations: exomeGeneticAncestryGroupObjects },
genome: { populations: genomeGeneticAncestryGroupObjects },
exome: { ancestry_groups: exomeGeneticAncestryGroupObjects },
genome: { ancestry_groups: genomeGeneticAncestryGroupObjects },
})

const result = mergeExomeAndGenomePopulationData(testVariant.exome!, testVariant.genome!)
Expand All @@ -114,7 +114,7 @@ describe('mergeExomeAndGenomePopulationData', () => {
expect(result).toStrictEqual(expected)
})

it('returns expected values when exome and genome populations are in a different order', () => {
it('returns expected values when exome and genome ancestry_groups are in a different order', () => {
const exomeGeneticAncestryGroupObjects = createAncestryGroupObjects([
{ id: 'eur', value: 1 },
{ id: 'afr', value: 2 },
Expand All @@ -129,8 +129,8 @@ describe('mergeExomeAndGenomePopulationData', () => {

const testVariant = variantFactory.build({
variant_id: 'test_variant',
exome: { populations: exomeGeneticAncestryGroupObjects },
genome: { populations: genomeGeneticAncestryGroupObjects },
exome: { ancestry_groups: exomeGeneticAncestryGroupObjects },
genome: { ancestry_groups: genomeGeneticAncestryGroupObjects },
})

const result = mergeExomeAndGenomePopulationData(testVariant.exome!, testVariant.genome!)
Expand Down
20 changes: 10 additions & 10 deletions browser/src/VariantList/mergeExomeAndGenomeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export const mergeExomeAndGenomePopulationData = (
exome: SequencingType,
genome: SequencingType
) => {
const populations: { [key: string]: Population } = {}
const ancestry_groups: { [key: string]: Population } = {}

exome.populations.forEach((exomePopulation: Population) => {
populations[exomePopulation.id] = {
exome.ancestry_groups.forEach((exomePopulation: Population) => {
ancestry_groups[exomePopulation.id] = {
id: exomePopulation.id,
ac: exomePopulation.ac,
an: exomePopulation.an,
Expand All @@ -19,18 +19,18 @@ export const mergeExomeAndGenomePopulationData = (
}
})

genome.populations.forEach((genomePopulation: Population) => {
if (genomePopulation.id in populations) {
const entry = populations[genomePopulation.id]
populations[genomePopulation.id] = {
genome.ancestry_groups.forEach((genomePopulation: Population) => {
if (genomePopulation.id in ancestry_groups) {
const entry = ancestry_groups[genomePopulation.id]
ancestry_groups[genomePopulation.id] = {
id: genomePopulation.id,
ac: add(entry.ac, genomePopulation.ac),
an: add(entry.an, genomePopulation.an),
ac_hemi: add(entry.ac_hemi, genomePopulation.ac_hemi),
ac_hom: add(entry.ac_hom, genomePopulation.ac_hom),
}
} else {
populations[genomePopulation.id] = {
ancestry_groups[genomePopulation.id] = {
id: genomePopulation.id,
ac: genomePopulation.ac,
an: genomePopulation.an,
Expand All @@ -40,7 +40,7 @@ export const mergeExomeAndGenomePopulationData = (
}
})

return Object.values(populations)
return Object.values(ancestry_groups)
}

const mergeExomeAndGenomeData = (variants: any) =>
Expand Down Expand Up @@ -74,7 +74,7 @@ const mergeExomeAndGenomeData = (variants: any) =>
ac_hemi: add(exome.ac_hemi, genome.ac_hemi),
ac_hom: add(exome.ac_hom, genome.ac_hom),
filters: exome.filters.concat(genome.filters),
populations: mergeExomeAndGenomePopulationData(exome!, genome!),
ancestry_groups: mergeExomeAndGenomePopulationData(exome!, genome!),
}
})

Expand Down
14 changes: 7 additions & 7 deletions browser/src/VariantPage/VariantPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export type SequencingType = {
hemizygote_count: number | null
faf95: Faf95
filters: string[]
populations: Population[]
local_ancestry_populations: LocalAncestryPopulation[]
ancestry_groups: Population[]
local_ancestry_groups: LocalAncestryPopulation[]
age_distribution: AgeDistribution | null
quality_metrics: VariantQualityMetrics
}
Expand Down Expand Up @@ -348,7 +348,7 @@ export const VariantPageContent = ({ datasetId, variant }: VariantPageContentPro
Genetic Ancestry Group Frequencies <InfoButton topic="ancestry" />
</h2>
{hasLocalAncestryPopulations(datasetId) &&
((variant.genome && variant.genome.local_ancestry_populations) || []).length > 0 && (
((variant.genome && variant.genome.local_ancestry_groups) || []).length > 0 && (
<div
style={{
padding: '0 1em',
Expand Down Expand Up @@ -495,14 +495,14 @@ query ${operationName}($variantId: String!, $datasetId: DatasetId!, $referenceGe
popmax_population
}
filters
populations {
ancestry_groups {
id
ac
an
ac_hemi
ac_hom
}
local_ancestry_populations @include(if: $includeLocalAncestry) {
local_ancestry_groups @include(if: $includeLocalAncestry) {
id
ac
an
Expand Down Expand Up @@ -574,14 +574,14 @@ query ${operationName}($variantId: String!, $datasetId: DatasetId!, $referenceGe
popmax_population
}
filters
populations {
ancestry_groups {
id
ac
an
ac_hemi
ac_hom
}
local_ancestry_populations @include(if: $includeLocalAncestry) {
local_ancestry_groups @include(if: $includeLocalAncestry) {
id
ac
an
Expand Down
14 changes: 7 additions & 7 deletions browser/src/VariantPage/VariantPopulationFrequencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ type Props = {
const VariantPopulationFrequencies = ({ datasetId, variant }: Props) => {
if (hasLocalAncestryPopulations(datasetId) && variant.genome) {
const genome = variant.genome!
const genomePopulations = genome.populations.filter(
const genomePopulations = genome.ancestry_groups.filter(
(pop) => !(pop.id.startsWith('hgdp:') || pop.id.startsWith('1kg:'))
)
const exomePopulations = variant.exome
? variant.exome.populations.filter(
? variant.exome.ancestry_groups.filter(
(pop) => !(pop.id.startsWith('hgdp:') || pop.id.startsWith('1kg:'))
)
: []
const hgdpPopulations = genome.populations
const hgdpPopulations = genome.ancestry_groups
.filter((pop) => pop.id.startsWith('hgdp:'))
.map((pop) => ({ ...pop, id: pop.id.slice(5) })) // Remove hgdp: prefix
const tgpPopulations = genome.populations
const tgpPopulations = genome.ancestry_groups
.filter((pop) => pop.id.startsWith('1kg:'))
.map((pop) => ({ ...pop, id: pop.id.slice(4) })) // Remove 1kg: prefix

const localAncestryPopulations = genome.local_ancestry_populations || []
const localAncestryPopulations = genome.local_ancestry_groups || []

return (
// @ts-expect-error TS(2741) FIXME: Property 'onChange' is missing in type '{ tabs: { ... Remove this comment to see the full error message
Expand Down Expand Up @@ -141,8 +141,8 @@ const VariantPopulationFrequencies = ({ datasetId, variant }: Props) => {
<TableWrapper>
<GnomadPopulationsTable
datasetId={datasetId}
exomePopulations={variant.exome ? variant.exome.populations : []}
genomePopulations={variant.genome ? variant.genome.populations : []}
exomePopulations={variant.exome ? variant.exome.ancestry_groups : []}
genomePopulations={variant.genome ? variant.genome.ancestry_groups : []}
showHemizygotes={variant.chrom === 'X' || variant.chrom === 'Y'}
/>
</TableWrapper>
Expand Down
12 changes: 6 additions & 6 deletions browser/src/__factories__/Variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const variantTableVariantFactory = Factory.define<VariantTableVariant>(
hgvs = 'string',
hgvsc = 'string',
hgvsp = 'string',
populations = [],
ancestry_groups = [],
pos = 1,
rsids = [],
variant_id = '',
Expand Down Expand Up @@ -177,7 +177,7 @@ export const variantTableVariantFactory = Factory.define<VariantTableVariant>(
hgvs,
hgvsc,
hgvsp,
populations,
ancestry_groups,
pos,
rsids,
variant_id,
Expand All @@ -198,8 +198,8 @@ export const sequencingFactory = Factory.define<SequencingType>(({ params, assoc
homozygote_count = null,
hemizygote_count = null,
filters = [],
populations = [],
local_ancestry_populations = [],
ancestry_groups = [],
local_ancestry_groups = [],
ac_hemi = 1,
ac_hom = 1,
} = params
Expand All @@ -226,8 +226,8 @@ export const sequencingFactory = Factory.define<SequencingType>(({ params, assoc
homozygote_count,
hemizygote_count,
filters,
populations,
local_ancestry_populations,
ancestry_groups,
local_ancestry_groups,
age_distribution,
quality_metrics,
faf95,
Expand Down

0 comments on commit 12869f6

Please sign in to comment.