Skip to content

Commit

Permalink
Modify coocurrence table to only render on v2 data
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyhgrant committed Jul 28, 2023
1 parent b970c98 commit 41a3833
Show file tree
Hide file tree
Showing 5 changed files with 3,475 additions and 0 deletions.
1 change: 1 addition & 0 deletions browser/src/GenePage/GenePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ const GenePage = ({ datasetId, gene, geneId }: Props) => {
<ConstraintTable datasetId={datasetId} geneOrTranscript={gene} />
) : (
<VariantCooccurrenceCountsTable
datasetId={datasetId}
heterozygous_variant_cooccurrence_counts={
gene.heterozygous_variant_cooccurrence_counts!
}
Expand Down
46 changes: 46 additions & 0 deletions browser/src/GenePage/VariantCooccurrenceCountsTable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,58 @@ import {
} from '../__factories__/VariantCooccurrenceCountsPerSeverityAndAf'

import VariantCooccurrenceCountsTable from './VariantCooccurrenceCountsTable'
import { forDatasetsMatching, forDatasetsNotMatching } from '../../../tests/__helpers__/datasets'

const v2Regexp = /_r2/

forDatasetsNotMatching(
v2Regexp,
'VariantCoocurrenceCountsTable with non v2 dataset "%s"',
(datasetId) => {
test('has no unexpected changes and renders as placeholder text', () => {
const heterozygousCounts =
HeterozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const homozygousCounts = HomozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const tableContent = render(
<VariantCooccurrenceCountsTable
datasetId={datasetId}
heterozygous_variant_cooccurrence_counts={heterozygousCounts}
homozygous_variant_cooccurrence_counts={homozygousCounts}
/>
)
const normalContentFragment = tableContent.asFragment()
expect(normalContentFragment.querySelectorAll('p').length).toEqual(1)
expect(normalContentFragment.querySelectorAll('table').length).toEqual(0)
expect(normalContentFragment).toMatchSnapshot()
})
}
)

forDatasetsMatching(v2Regexp, 'VariantCoocurrenceCountsTable with v2 dataset "%s"', (datasetId) => {
test('has no unexpected changes and renders as a table', () => {
const heterozygousCounts = HeterozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const homozygousCounts = HomozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const tableContent = render(
<VariantCooccurrenceCountsTable
datasetId={datasetId}
heterozygous_variant_cooccurrence_counts={heterozygousCounts}
homozygous_variant_cooccurrence_counts={homozygousCounts}
/>
)
const normalContentFragment = tableContent.asFragment()
expect(normalContentFragment.querySelectorAll('p').length).toEqual(0)
expect(normalContentFragment.querySelectorAll('table').length).toEqual(2)
expect(normalContentFragment).toMatchSnapshot()
})
})

describe('VariantCooccurrenceCountsTable', () => {
test('renders correct data into correct table cells in both regular and extended mode', () => {
const heterozygousCounts = HeterozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const homozygousCounts = HomozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const tableContent = render(
<VariantCooccurrenceCountsTable
datasetId="gnomad_r2_1"
heterozygous_variant_cooccurrence_counts={heterozygousCounts}
homozygous_variant_cooccurrence_counts={homozygousCounts}
/>
Expand Down Expand Up @@ -42,6 +87,7 @@ describe('VariantCooccurrenceCountsTable', () => {
test('fills in missing data with zeroes', () => {
const tableContent = render(
<VariantCooccurrenceCountsTable
datasetId="gnomad_r2_1"
heterozygous_variant_cooccurrence_counts={{}}
homozygous_variant_cooccurrence_counts={{}}
/>
Expand Down
7 changes: 7 additions & 0 deletions browser/src/GenePage/VariantCooccurrenceCountsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, Dispatch, SetStateAction, ReactNode } from 'react'
import styled from 'styled-components'

import { BaseTable, TooltipAnchor, TooltipHint, Button } from '@gnomad/ui'
import { DatasetId, hasVariantCoocurrence } from '@gnomad/dataset-metadata/metadata'

export const heterozygousVariantCooccurrenceSeverities = [
'lof_lof',
Expand Down Expand Up @@ -505,14 +506,20 @@ const HomozygousCaption = () => (
)

const VariantCooccurrenceCountsTable = ({
datasetId,
heterozygous_variant_cooccurrence_counts,
homozygous_variant_cooccurrence_counts,
}: {
datasetId: DatasetId
heterozygous_variant_cooccurrence_counts: HeterozygousVariantCooccurrenceCountsPerSeverityAndAf
homozygous_variant_cooccurrence_counts: HomozygousVariantCooccurrenceCountsPerSeverityAndAf
}) => {
const [tableMode, setTableMode] = useState<TableMode>('normal')

if (!hasVariantCoocurrence(datasetId)) {
return <p>Variant co-occurrence is only available for gnomAD v2.</p>
}

const buttonLabel = tableMode === 'normal' ? 'expand' : 'collapse'
const clickCallback = () => toggleTableMode(tableMode, setTableMode)
const toggleButton = <ModeToggle onClick={clickCallback}>{buttonLabel}</ModeToggle>
Expand Down
Loading

0 comments on commit 41a3833

Please sign in to comment.