-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Platform]: Insilico predictors chart (#594)
- Loading branch information
Showing
7 changed files
with
3,430 additions
and
1,652 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
159 changes: 159 additions & 0 deletions
159
packages/sections/src/variant/InSilicoPredictors/InSilicoPredictorsPlot.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,159 @@ | ||
import { useRef, useEffect } from "react"; | ||
import * as PlotLib from "@observablehq/plot"; | ||
import { rgb } from "d3"; | ||
import { useMeasure } from "@uidotdev/usehooks"; | ||
import { Box, Fade } from "@mui/material"; | ||
import { grey } from "@mui/material/colors"; | ||
import { DataDownloader } from "ui"; | ||
|
||
const PRIORITISATION_COLORS = [ | ||
rgb("#bc3a19"), | ||
rgb("#d65a1f"), | ||
rgb("#e08145"), | ||
rgb("#e3a772"), | ||
rgb("#e6ca9c"), | ||
rgb("#eceada"), | ||
rgb("#c5d2c1"), | ||
rgb("#9ebaa8"), | ||
rgb("#78a290"), | ||
rgb("#528b78"), | ||
rgb("#2f735f"), | ||
]; | ||
|
||
function InSilicoPredictorsPlot({ data, query, variables, columns }) { | ||
const [ref, { width }] = useMeasure(); | ||
return ( | ||
<div> | ||
<Box> | ||
<ChartControls data={data} query={query} variables={variables} columns={columns} /> | ||
</Box> | ||
<Box sx={{ width: "90%", margin: "0 auto", mb: 6 }} ref={ref}> | ||
<Fade in> | ||
<div> | ||
<Plot data={data} width={width} /> | ||
</div> | ||
</Fade> | ||
</Box> | ||
</div> | ||
); | ||
} | ||
|
||
function ChartControls({ data, query, variables, columns }) { | ||
return ( | ||
<Box | ||
sx={{ | ||
borderColor: grey[300], | ||
borderRadius: 1, | ||
display: "flex", | ||
justifyContent: "flex-end", | ||
gap: 1, | ||
}} | ||
> | ||
<DataDownloader | ||
btnLabel="Export" | ||
rows={data} | ||
query={query} | ||
variables={variables} | ||
columns={columns} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
const colorScale = PRIORITISATION_COLORS.reverse(); | ||
const getXLabel = (tick: number) => { | ||
if (tick === -1) return "Likely benign"; | ||
if (tick === 0) return "Uncertain"; | ||
if (tick === 1) return "Likely deleterious"; | ||
return ""; | ||
}; | ||
|
||
function Plot({ data, width }) { | ||
const headerRef = useRef(); | ||
|
||
useEffect(() => { | ||
if (data === undefined || width === null) return; | ||
const chart = PlotLib.plot({ | ||
width: width, | ||
height: 250, | ||
label: null, | ||
marginLeft: 120, | ||
marginRight: 100, | ||
x: { | ||
axis: "bottom", | ||
ticks: 2, | ||
labelAnchor: "center", | ||
tickFormat: d => getXLabel(d), | ||
tickSize: 0, | ||
domain: [-1, 1], | ||
}, | ||
|
||
color: { | ||
legend: false, | ||
type: "linear", | ||
range: colorScale, | ||
domain: [-1, 1], | ||
interpolate: "hsl", | ||
}, | ||
style: { | ||
fontSize: "15px", | ||
}, | ||
marks: [ | ||
PlotLib.ruleY(data, { | ||
x1: -0.99, | ||
x2: 0.99, | ||
y: "method", | ||
stroke: grey[400], | ||
strokeWidth: 1, | ||
strokeDasharray: 6, | ||
}), | ||
PlotLib.dot(data, { | ||
x: "normalisedScore", | ||
y: "method", | ||
r: 12, | ||
fill: "normalisedScore", | ||
stroke: grey[100], | ||
strokeWidth: 4, | ||
tip: { | ||
fontSize: 14, | ||
textPadding: 20, | ||
format: { | ||
x: false, | ||
y: false, | ||
fill: false, | ||
normalisedScore: false, | ||
}, | ||
}, | ||
channels: { | ||
method: { | ||
value: "method", | ||
label: "", | ||
}, | ||
assessment: { | ||
value: "assessment", | ||
label: "Assessment:", | ||
}, | ||
score: { | ||
value: "score", | ||
label: "Score:", | ||
}, | ||
assessmentFlag: { | ||
value: "assessmentFlag", | ||
label: "Assessment Flag:", | ||
}, | ||
normalisedScore: { | ||
value: "normalisedScore", | ||
label: "Normalised Score:", | ||
}, | ||
}, | ||
}), | ||
], | ||
}); | ||
headerRef.current.append(chart); | ||
return () => chart.remove(); | ||
}, [data, width]); | ||
|
||
return <Box ref={headerRef}></Box>; | ||
} | ||
|
||
export default InSilicoPredictorsPlot; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
import { faChartPie, faTableColumns } from "@fortawesome/free-solid-svg-icons"; | ||
import { FormControl, MenuItem, Select, SelectChangeEvent, Box } from "@mui/material"; | ||
import { ReactElement, useState } from "react"; | ||
import { faChartLine, faTableColumns } from "@fortawesome/free-solid-svg-icons"; | ||
import { ToggleButtonGroup, ToggleButton, styled } from "@mui/material"; | ||
import { ReactElement, useState, MouseEvent } from "react"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { VIEW } from "../../constants"; | ||
|
||
const menuItemStyles = { display: "flex", gap: 1 }; | ||
const menuActiveStyles = { display: "flex", gap: 1, alignItems: "center" }; | ||
|
||
type SectionViewToggleProps = { | ||
defaultValue: string; | ||
viewChange: (s: string) => void; | ||
}; | ||
|
||
const StyledToggleButtonGroup = styled(ToggleButtonGroup)` | ||
padding: 0; | ||
`; | ||
|
||
const StyledToggleButton = styled(ToggleButton)(({ theme }) => ({ | ||
paddingTop: theme.spacing(0.5), | ||
paddingBottom: theme.spacing(0.5), | ||
display: "flex", | ||
alignItems: "center", | ||
gap: theme.spacing(0.5), | ||
})); | ||
|
||
function SectionViewToggle({ | ||
defaultValue = VIEW.table, | ||
viewChange, | ||
}: SectionViewToggleProps): ReactElement { | ||
const [alignment, setAlignment] = useState(defaultValue); | ||
const [sectionView, setView] = useState(defaultValue); | ||
|
||
const handleAlignment = (event: SelectChangeEvent) => { | ||
const handleViewChange = (event: MouseEvent) => { | ||
event.preventDefault(); | ||
if (event.target.value) { | ||
setAlignment(event.target.value); | ||
viewChange(event.target.value); | ||
setView(event.target.value); | ||
if (viewChange) viewChange(event.target.value); | ||
} | ||
}; | ||
|
||
return ( | ||
<FormControl size="small"> | ||
<Select | ||
sx={{ typography: "body2" }} | ||
value={alignment} | ||
onChange={handleAlignment} | ||
renderValue={view => { | ||
const iconView = VIEW.table ? faTableColumns : faChartPie; | ||
return ( | ||
<Box sx={menuActiveStyles}> | ||
<FontAwesomeIcon icon={iconView} /> {view} view | ||
</Box> | ||
); | ||
}} | ||
> | ||
<MenuItem value={VIEW.table} sx={menuItemStyles}> | ||
<FontAwesomeIcon icon={faTableColumns} /> | ||
{VIEW.table} | ||
</MenuItem> | ||
<MenuItem value={VIEW.chart} sx={menuItemStyles}> | ||
<FontAwesomeIcon icon={faChartPie} /> {VIEW.chart} | ||
</MenuItem> | ||
</Select> | ||
</FormControl> | ||
<StyledToggleButtonGroup | ||
sx={{ typography: "body2" }} | ||
value={sectionView} | ||
onChange={handleViewChange} | ||
> | ||
<StyledToggleButton aria-label="Switch to table view" value={VIEW.table}> | ||
<FontAwesomeIcon icon={faTableColumns} /> | ||
{VIEW.table} view | ||
</StyledToggleButton> | ||
<StyledToggleButton aria-label="Switch to chartn view" value={VIEW.chart}> | ||
<FontAwesomeIcon icon={faChartLine} /> | ||
{VIEW.chart} | ||
</StyledToggleButton> | ||
</StyledToggleButtonGroup> | ||
); | ||
} | ||
export default SectionViewToggle; |
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
Oops, something went wrong.