From 999c8b4971a3659ba558e6423671c3fe1e5c6946 Mon Sep 17 00:00:00 2001 From: Graham McNeill Date: Mon, 9 Dec 2024 22:01:22 +0000 Subject: [PATCH] [Platform]: Numeric precision (#611) * use toPrecision instead toFixed * format insilico predictors scores --- packages/sections/src/credibleSet/Variants/Body.tsx | 4 ++-- packages/sections/src/study/GWASCredibleSets/Body.tsx | 2 +- .../sections/src/variant/GWASCredibleSets/Body.tsx | 2 +- .../sections/src/variant/InSilicoPredictors/Body.tsx | 10 ++++++---- packages/sections/src/variant/QTLCredibleSets/Body.tsx | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/sections/src/credibleSet/Variants/Body.tsx b/packages/sections/src/credibleSet/Variants/Body.tsx index 78c4439a3..dff9808dd 100644 --- a/packages/sections/src/credibleSet/Variants/Body.tsx +++ b/packages/sections/src/credibleSet/Variants/Body.tsx @@ -91,7 +91,7 @@ function getColumns({ leadVariantId, leadReferenceAllele, leadAlternateAllele }: tooltip: "Beta with respect to the ALT allele", renderCell: ({ beta }) => { if (typeof beta !== "number") return naLabel; - return beta.toFixed(3); + return beta.toPrecision(3); }, }, { @@ -138,7 +138,7 @@ function getColumns({ leadVariantId, leadReferenceAllele, leadAlternateAllele }: sortable: true, renderCell: ({ posteriorProbability }) => { if (typeof posteriorProbability !== "number") return naLabel; - return posteriorProbability.toFixed(3); + return posteriorProbability.toPrecision(3); }, }, { diff --git a/packages/sections/src/study/GWASCredibleSets/Body.tsx b/packages/sections/src/study/GWASCredibleSets/Body.tsx index 88c48ccdb..b94fce994 100644 --- a/packages/sections/src/study/GWASCredibleSets/Body.tsx +++ b/packages/sections/src/study/GWASCredibleSets/Body.tsx @@ -79,7 +79,7 @@ const columns = [ tooltip: "Beta with respect to the ALT allele", renderCell: ({ beta }) => { if (typeof beta !== "number") return naLabel; - return beta.toFixed(3); + return beta.toPrecision(3); }, }, { diff --git a/packages/sections/src/variant/GWASCredibleSets/Body.tsx b/packages/sections/src/variant/GWASCredibleSets/Body.tsx index 21b6a363b..5cd9da27b 100644 --- a/packages/sections/src/variant/GWASCredibleSets/Body.tsx +++ b/packages/sections/src/variant/GWASCredibleSets/Body.tsx @@ -134,7 +134,7 @@ function getColumns({ id, referenceAllele, alternateAllele }: getColumnsType) { sortable: true, renderCell: ({ beta }) => { if (typeof beta !== "number") return naLabel; - return beta.toFixed(3); + return beta.toPrecision(3); }, }, { diff --git a/packages/sections/src/variant/InSilicoPredictors/Body.tsx b/packages/sections/src/variant/InSilicoPredictors/Body.tsx index a6cbc0544..c00d0e4d2 100644 --- a/packages/sections/src/variant/InSilicoPredictors/Body.tsx +++ b/packages/sections/src/variant/InSilicoPredictors/Body.tsx @@ -38,12 +38,14 @@ const columns = [ { id: "score", label: "Score", - renderCell: ({ score }) => score ?? naLabel, + numeric: true, + renderCell: ({ score }) => score?.toPrecision(3) ?? naLabel, }, { id: "normalisedScore", label: "Normalised score", - renderCell: ({ normalisedScore }) => normalisedScore ?? naLabel, + numeric: true, + renderCell: ({ normalisedScore }) => normalisedScore?.toFixed(3) ?? naLabel, }, ]; @@ -55,8 +57,8 @@ type BodyProps = { function getSortedRows(request) { return request.data?.variant?.inSilicoPredictors ? [...request.data.variant.inSilicoPredictors] - .filter(e => e.method !== null) - .sort((row1, row2) => row1.method.localeCompare(row2.method)) + .filter(e => e.method !== null) + .sort((row1, row2) => row1.method.localeCompare(row2.method)) : []; } diff --git a/packages/sections/src/variant/QTLCredibleSets/Body.tsx b/packages/sections/src/variant/QTLCredibleSets/Body.tsx index c1a0006e2..510f4f104 100644 --- a/packages/sections/src/variant/QTLCredibleSets/Body.tsx +++ b/packages/sections/src/variant/QTLCredibleSets/Body.tsx @@ -103,7 +103,7 @@ function getColumns({ id, referenceAllele, alternateAllele }: getColumnsType) { ); }, - exportValue: ({ study }) => { return `[${study?.biosample?.biosampleId}]:${study?.biosample?.biosampleName}`}, + exportValue: ({ study }) => { return `[${study?.biosample?.biosampleId}]:${study?.biosample?.biosampleName}` }, }, { id: "study.condition", @@ -142,7 +142,7 @@ function getColumns({ id, referenceAllele, alternateAllele }: getColumnsType) { sortable: true, renderCell: ({ beta }) => { if (typeof beta !== "number") return naLabel; - return beta.toFixed(3); + return beta.toPrecision(3); }, }, {