Skip to content

Commit 85f64a7

Browse files
Highlight high LOF OEs in mitochondrial constraint table
1 parent b502899 commit 85f64a7

File tree

4 files changed

+2367
-102
lines changed

4 files changed

+2367
-102
lines changed

browser/src/ConstraintTable/ConstraintTable.spec.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ forAllDatasets('ConstraintTable with "%s" dataset selected', (datasetId) => {
118118
)
119119
expect(tree).toMatchSnapshot()
120120
})
121+
122+
test('highlights upper LOF OE CI if below 0.058', () => {
123+
const constraint = proteinMitochondrialConstraintFactory.build({ oe_lof_upper: 0.057999999 })
124+
const tree = renderer.create(
125+
<BrowserRouter>
126+
<ConstraintTable
127+
datasetId={datasetId}
128+
geneOrTranscript={geneFactory.build({
129+
chrom: 'M',
130+
mitochondrial_constraint: constraint,
131+
})}
132+
/>
133+
</BrowserRouter>
134+
)
135+
expect(tree).toMatchSnapshot()
136+
})
121137
})
122138

123139
describe('with a mitochondrial RNA gene', () => {
@@ -136,6 +152,22 @@ forAllDatasets('ConstraintTable with "%s" dataset selected', (datasetId) => {
136152
)
137153
expect(tree).toMatchSnapshot()
138154
})
155+
156+
test('highlights upper LOF OE CI if below 0.27', () => {
157+
const constraint = rnaMitochondrialConstraintFactory.build({ oe_upper: 0.2699999 })
158+
const tree = renderer.create(
159+
<BrowserRouter>
160+
<ConstraintTable
161+
datasetId={datasetId}
162+
geneOrTranscript={geneFactory.build({
163+
chrom: 'M',
164+
mitochondrial_constraint: constraint,
165+
})}
166+
/>
167+
</BrowserRouter>
168+
)
169+
expect(tree).toMatchSnapshot()
170+
})
139171
})
140172

141173
describe('with a mitochondrial gene missing constraint data', () => {

browser/src/ConstraintTable/MitochondrialConstraintTable.tsx

+49-17
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,66 @@ import {
55
RNAMitochondrialGeneConstraint,
66
} from '../GenePage/GenePage'
77
import { BaseTable } from '@gnomad/ui'
8+
import { ConstraintHighlight } from './constraintMetrics'
89

910
const isProteinMitochondrialGeneConstraint = (
1011
constraint: MitochondrialGeneConstraint
1112
): constraint is ProteinMitochondrialGeneConstraint =>
1213
Object.prototype.hasOwnProperty.call(constraint, 'exp_lof')
1314

15+
type Highlight = {
16+
threshold: number
17+
color: string
18+
}
19+
20+
type ConstraintRowProps = {
21+
category: string
22+
expected: number
23+
observed: number
24+
oe: number
25+
oeLower: number
26+
oeUpper: number
27+
highlight?: Highlight
28+
}
29+
30+
const PROTEIN_GENE_HIGHLIGHT: Highlight = {
31+
threshold: 0.058,
32+
color: '#ff2600',
33+
}
34+
35+
const RNA_GENE_HIGHLIGHT: Highlight = {
36+
threshold: 0.27,
37+
color: PROTEIN_GENE_HIGHLIGHT.color,
38+
}
39+
1440
const ConstraintRow = ({
1541
category,
1642
expected,
1743
observed,
1844
oe,
1945
oeLower,
2046
oeUpper,
21-
}: {
22-
category: string
23-
expected: number
24-
observed: number
25-
oe: number
26-
oeLower: number
27-
oeUpper: number
28-
}) => (
29-
<tr>
30-
<th scope="row">{category}</th>
31-
<td>{expected < 10 ? expected.toFixed(2) : expected.toFixed(1)}</td>
32-
<td>{observed < 10 ? observed.toFixed(2) : observed.toFixed(1)}</td>
33-
<td>
34-
o/e = {oe.toFixed(2)} ({oeLower.toFixed(2)} - {oeUpper.toFixed(2)})
35-
</td>
36-
</tr>
37-
)
47+
highlight,
48+
}: ConstraintRowProps) => {
49+
const oeUpperFixed = oeUpper.toFixed(2)
50+
const oeUpperContent =
51+
highlight && oeUpper < highlight.threshold ? (
52+
<ConstraintHighlight highlightColor={highlight.color}>{oeUpperFixed}</ConstraintHighlight>
53+
) : (
54+
oeUpperFixed
55+
)
56+
57+
return (
58+
<tr>
59+
<th scope="row">{category}</th>
60+
<td>{expected < 10 ? expected.toFixed(2) : expected.toFixed(1)}</td>
61+
<td>{observed < 10 ? observed.toFixed(2) : observed.toFixed(1)}</td>
62+
<td>
63+
o/e = {oe.toFixed(2)} ({oeLower.toFixed(2)} - {oeUpperContent})
64+
</td>
65+
</tr>
66+
)
67+
}
3868

3969
const ProteinConstraintMetrics = ({
4070
constraint,
@@ -83,6 +113,7 @@ const ProteinConstraintMetrics = ({
83113
oe={oe_lof}
84114
oeLower={oe_lof_lower}
85115
oeUpper={oe_lof_upper}
116+
highlight={PROTEIN_GENE_HIGHLIGHT}
86117
/>
87118
</tbody>
88119
)
@@ -99,6 +130,7 @@ const RNAConstraintMetrics = ({ constraint }: { constraint: RNAMitochondrialGene
99130
oe={oe}
100131
oeLower={oe_lower}
101132
oeUpper={oe_upper}
133+
highlight={RNA_GENE_HIGHLIGHT}
102134
/>
103135
</tbody>
104136
)

0 commit comments

Comments
 (0)