-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mitochondrial regional constraint visualizations
- Loading branch information
1 parent
89aec0a
commit c1ca289
Showing
11 changed files
with
378 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
browser/src/GenePage/MitochondrialRegionConstraintTrack.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import { expect, test } from '@jest/globals' | ||
import MitochondrialRegionConstraintTrack, { | ||
MitochondrialConstraintRegion, | ||
} from './MitochondrialRegionConstraintTrack' | ||
import { Exon } from '../TranscriptPage/TranscriptPage' | ||
// @ts-expect-error | ||
import { RegionViewerContext } from '@gnomad/region-viewer' | ||
|
||
const childProps = { | ||
centerPanelWidth: 3, | ||
isPositionDefined: true, | ||
leftPanelWidth: 4, | ||
regions: [], | ||
rightPanelWidth: 5, | ||
scalePosition: (i: number) => i, | ||
} | ||
|
||
const exons: Exon[] = [ | ||
{ feature_type: 'CDS', start: 123, stop: 234 }, | ||
{ feature_type: 'UTR', start: 235, stop: 999 }, | ||
{ feature_type: 'CDS', start: 1000, stop: 1999 }, | ||
] | ||
|
||
test('track has no unexpected changes when gene has constraint', () => { | ||
const constraintRegions: MitochondrialConstraintRegion[] = [ | ||
{ start: 555, stop: 666, oe: 0.45, oe_lower: 0.37, oe_upper: 0.47 }, | ||
{ start: 777, stop: 888, oe: 0.56, oe_lower: 0.52, oe_upper: 0.59 }, | ||
] | ||
const tree = renderer.create( | ||
<RegionViewerContext.Provider value={childProps}> | ||
<MitochondrialRegionConstraintTrack constraintRegions={constraintRegions} exons={exons} /> | ||
</RegionViewerContext.Provider> | ||
) | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
test('track has no unexpected changes when no constraint for gene', () => { | ||
const tree = renderer.create( | ||
<RegionViewerContext.Provider value={childProps}> | ||
<MitochondrialRegionConstraintTrack constraintRegions={null} exons={exons} /> | ||
</RegionViewerContext.Provider> | ||
) | ||
expect(tree).toMatchSnapshot() | ||
}) |
74 changes: 74 additions & 0 deletions
74
browser/src/GenePage/MitochondrialRegionConstraintTrack.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react' | ||
import { Exon } from '../TranscriptPage/TranscriptPage' | ||
import ConstraintTrack, { regionsInExons, RegionAttributeList } from '../ConstraintTrack' | ||
|
||
export type MitochondrialConstraintRegion = { | ||
start: number | ||
stop: number | ||
oe: number | ||
oe_upper: number | ||
oe_lower: number | ||
} | ||
|
||
type Props = { | ||
constraintRegions: MitochondrialConstraintRegion[] | null | ||
exons: Exon[] | ||
} | ||
|
||
const constraintColor = '#fd8d3c' | ||
|
||
const Legend = () => ( | ||
<> | ||
<span>Constrained region</span> | ||
<svg width={50} height={25}> | ||
<rect x={10} y={3} width={30} height={10} stroke="#000" fill={constraintColor} /> | ||
</svg> | ||
</> | ||
) | ||
|
||
type TooltipProps = { | ||
region: MitochondrialConstraintRegion | ||
} | ||
|
||
const Tooltip = ({ region }: TooltipProps) => { | ||
return ( | ||
<RegionAttributeList> | ||
<div> | ||
<dt>Coordinates:</dt> | ||
<dd>{`M:${region.start}-${region.stop}`}</dd> | ||
</div> | ||
<div> | ||
<dt>Missense observed/expected:</dt> | ||
<dd> | ||
{region.oe.toFixed(3)} ({region.oe_lower.toFixed(3)}-{region.oe_upper.toFixed(3)}) | ||
</dd> | ||
</div> | ||
</RegionAttributeList> | ||
) | ||
} | ||
|
||
const formattedOE = (region: MitochondrialConstraintRegion) => region.oe.toFixed(3) | ||
|
||
const MitochondrialConstraintRegionTrack = ({ constraintRegions, exons }: Props) => { | ||
if (constraintRegions === null) { | ||
return null | ||
} | ||
|
||
return ( | ||
<ConstraintTrack | ||
trackTitle="Regional constraint" | ||
infobuttonTopic="TK-mitochondrial-gene-constraint" | ||
legend={<Legend />} | ||
valueFn={formattedOE} | ||
colorFn={() => constraintColor} | ||
tooltipComponent={Tooltip} | ||
allRegions={null} | ||
constrainedRegions={regionsInExons( | ||
constraintRegions, | ||
exons.filter((exon) => exon.feature_type === 'CDS') | ||
)} | ||
/> | ||
) | ||
} | ||
|
||
export default MitochondrialConstraintRegionTrack |
Oops, something went wrong.