Skip to content

Commit

Permalink
Highlight high LOF OEs in mitochondrial constraint table
Browse files Browse the repository at this point in the history
  • Loading branch information
phildarnowsky-broad committed Feb 26, 2025
1 parent 583ecc8 commit 5c52b3c
Show file tree
Hide file tree
Showing 4 changed files with 2,657 additions and 80 deletions.
32 changes: 32 additions & 0 deletions browser/src/ConstraintTable/ConstraintTable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ forAllDatasets('ConstraintTable with "%s" dataset selected', (datasetId) => {
)
expect(tree).toMatchSnapshot()
})

test('highlights upper LOF OE CI if below 0.058', () => {
const constraint = proteinMitochondrialConstraintFactory.build({ oe_lof_upper: 0.057999999 })
const tree = renderer.create(
<BrowserRouter>
<ConstraintTable
datasetId={datasetId}
geneOrTranscript={geneFactory.build({
chrom: 'M',
mitochondrial_constraint: constraint,
})}
/>
</BrowserRouter>
)
expect(tree).toMatchSnapshot()
})
})

describe('with a mitochondrial RNA gene', () => {
Expand All @@ -136,6 +152,22 @@ forAllDatasets('ConstraintTable with "%s" dataset selected', (datasetId) => {
)
expect(tree).toMatchSnapshot()
})

test('highlights upper LOF OE CI if below 0.27', () => {
const constraint = rnaMitochondrialConstraintFactory.build({ oe_upper: 0.2699999 })
const tree = renderer.create(
<BrowserRouter>
<ConstraintTable
datasetId={datasetId}
geneOrTranscript={geneFactory.build({
chrom: 'M',
mitochondrial_constraint: constraint,
})}
/>
</BrowserRouter>
)
expect(tree).toMatchSnapshot()
})
})

describe('with a mitochondrial gene missing constraint data', () => {
Expand Down
66 changes: 49 additions & 17 deletions browser/src/ConstraintTable/MitochondrialConstraintTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,66 @@ import {
RNAMitochondrialGeneConstraint,
} from '../GenePage/GenePage'
import { BaseTable, TooltipAnchor } from '@gnomad/ui'
import { ConstraintHighlight } from './constraintMetrics'

const isProteinMitochondrialGeneConstraint = (
constraint: MitochondrialGeneConstraint
): constraint is ProteinMitochondrialGeneConstraint =>
Object.prototype.hasOwnProperty.call(constraint, 'exp_lof')

type Highlight = {
threshold: number
color: string
}

type ConstraintRowProps = {
category: string
expected: number
observed: number
oe: number
oeLower: number
oeUpper: number
highlight?: Highlight
}

const PROTEIN_GENE_HIGHLIGHT: Highlight = {
threshold: 0.058,
color: '#ff2600',
}

const RNA_GENE_HIGHLIGHT: Highlight = {
threshold: 0.27,
color: PROTEIN_GENE_HIGHLIGHT.color,
}

const ConstraintRow = ({
category,
expected,
observed,
oe,
oeLower,
oeUpper,
}: {
category: string
expected: number
observed: number
oe: number
oeLower: number
oeUpper: number
}) => (
<tr>
<th scope="row">{category}</th>
<td>{expected < 10 ? expected.toFixed(2) : expected.toFixed(1)}</td>
<td>{observed < 10 ? observed.toFixed(2) : observed.toFixed(1)}</td>
<td>
o/e = {oe.toFixed(2)} ({oeLower.toFixed(2)} - {oeUpper.toFixed(2)})
</td>
</tr>
)
highlight,
}: ConstraintRowProps) => {
const oeUpperFixed = oeUpper.toFixed(2)
const oeUpperContent =
highlight && oeUpper < highlight.threshold ? (
<ConstraintHighlight highlightColor={highlight.color}>{oeUpperFixed}</ConstraintHighlight>
) : (
oeUpperFixed
)

return (
<tr>
<th scope="row">{category}</th>
<td>{expected < 10 ? expected.toFixed(2) : expected.toFixed(1)}</td>
<td>{observed < 10 ? observed.toFixed(2) : observed.toFixed(1)}</td>
<td>
o/e = {oe.toFixed(2)} ({oeLower.toFixed(2)} - {oeUpperContent})
</td>
</tr>
)
}

const ProteinConstraintMetrics = ({
constraint,
Expand Down Expand Up @@ -83,6 +113,7 @@ const ProteinConstraintMetrics = ({
oe={oe_lof}
oeLower={oe_lof_lower}
oeUpper={oe_lof_upper}
highlight={PROTEIN_GENE_HIGHLIGHT}
/>
</tbody>
)
Expand All @@ -99,6 +130,7 @@ const RNAConstraintMetrics = ({ constraint }: { constraint: RNAMitochondrialGene
oe={oe}
oeLower={oe_lower}
oeUpper={oe_upper}
highlight={RNA_GENE_HIGHLIGHT}
/>
</tbody>
)
Expand Down
Loading

0 comments on commit 5c52b3c

Please sign in to comment.