Skip to content

Commit

Permalink
[Platform]: Phewas and Manhattan plot fixes (#601)
Browse files Browse the repository at this point in the history
* use linear scales

* spacing and therapeutic areas labels
  • Loading branch information
gjmcn authored Dec 9, 2024
1 parent 93e8657 commit 7e2cebf
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 218 deletions.
48 changes: 23 additions & 25 deletions packages/sections/src/study/GWASCredibleSets/ManhattanPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
HTMLTooltipTable,
HTMLTooltipRow,
} from "ui";
import { scaleLinear, scaleLog, min } from "d3";
import { scaleLinear, min } from "d3";
import { ScientificNotation } from "ui";
import { naLabel } from "../../constants";

Expand All @@ -42,15 +42,24 @@ export default function ManhattanPlot({ loading, data }) {
d.variant != null;
});
if (data.length === 0) return null;
// eslint-disable-next-line
data = structuredClone(data);
data.forEach(d => {
d._y = Math.log10(d.pValueMantissa) + d.pValueExponent;
});

const pValueMin = min(data, pValue);
const pValueMax = 1;
const yMin = min(data, d => d._y);
const yMax = 0;

const genomePositions = {};
data.forEach(({ variant }) => {
genomePositions[variant.id] = cumulativePosition(variant);
});

const xScale = scaleLinear().domain([0, genomeLength]);
const yScale = scaleLinear().domain([yMin, yMax]).nice(); // ensure min scale value <= yMin
yScale.domain([yScale.domain()[0], yMax]); // ensure max scale value is yMax - in case nice changed it

return (
<Vis>

Expand All @@ -63,13 +72,9 @@ export default function ManhattanPlot({ loading, data }) {
fontFamily={fontFamily}
data={data}
yReverse
scales={{
x: scaleLinear().domain([0, genomeLength]),
y: scaleLog().domain([pValueMin, pValueMax]),
}}
scales={{ x: xScale, y: yScale }}
xTick={chromosomeInfo}
>

<XTick
values={tickData => [0, ...tickData.map(chromo => chromo.end)]}
tickLength={15}
Expand All @@ -91,21 +96,21 @@ export default function ManhattanPlot({ loading, data }) {
</tspan>
</XTitle>
<YTick />
<YLabel format={v => -Math.log10(v)} />
<YLabel format={v => Math.abs(v)} />

<Segment
x={d => genomePositions[d.variant.id]}
xx={d => genomePositions[d.variant.id]}
y={pValue}
yy={pValueMax}
y={d => d._y}
yy={yMax}
stroke={markColor}
strokeWidth={1}
strokeOpacity={0.7}
hover="stay"
/>
<Circle
x={d => genomePositions[d.variant.id]}
y={pValue}
y={d => d._y}
fill={background}
stroke={markColor}
strokeWidth={1.2}
Expand All @@ -119,8 +124,8 @@ export default function ManhattanPlot({ loading, data }) {
x={0}
xx={genomeLength}
dxx={8}
y={pValueMin}
yy={pValueMax}
y={yMin}
yy={yMax}
dy={-8}
dyy={0}
fill={background}
Expand All @@ -130,22 +135,22 @@ export default function ManhattanPlot({ loading, data }) {
dataFrom="hover"
x={d => genomePositions[d.variant.id]}
xx={d => genomePositions[d.variant.id]}
y={pValue}
yy={pValueMax}
y={d => d._y}
yy={yMax}
stroke={markColor}
strokeWidth={1.7}
strokeOpacity={1}
/>
<Circle
dataFrom="hover"
x={d => genomePositions[d.variant.id]}
y={pValue}
y={d => d._y}
fill={markColor}
area={circleArea}
/>
<HTMLTooltip
x={d => genomePositions[d.variant.id]}
y={pValue}
y={d => d._y}
pxWidth={290}
pxHeight={200}
content={tooltipContent}
Expand Down Expand Up @@ -209,13 +214,6 @@ function tooltipContent(data) {
);
}

function pValue(row) {
return Math.max(
row.pValueMantissa * 10 ** row.pValueExponent,
Number.MIN_VALUE
);
}

// from: https://www.ncbi.nlm.nih.gov/grc/human/data
// (first tab: "Chromosome lengths")
const chromosomeInfo = [
Expand Down
2 changes: 2 additions & 0 deletions packages/sections/src/variant/GWASCredibleSets/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ function Body({ id, entity }: BodyProps) {
loading={request.loading}
data={request.data?.variant.gwasCredibleSets.rows}
id={id}
referenceAllele={request.data?.variant.referenceAllele}
alternateAllele={request.data?.variant.alternateAllele}
/>
);
}}
Expand Down
Loading

0 comments on commit 7e2cebf

Please sign in to comment.