From dbb240a52f291e98b468b7183e5436ebe191218e Mon Sep 17 00:00:00 2001 From: Elissa Alarmani Date: Fri, 6 Sep 2024 15:04:33 -0400 Subject: [PATCH] add log label for value --- .../VariantPage/VariantSiteQualityMetrics.tsx | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/browser/src/VariantPage/VariantSiteQualityMetrics.tsx b/browser/src/VariantPage/VariantSiteQualityMetrics.tsx index c11cf2df2..01da30005 100644 --- a/browser/src/VariantPage/VariantSiteQualityMetrics.tsx +++ b/browser/src/VariantPage/VariantSiteQualityMetrics.tsx @@ -571,7 +571,10 @@ const yTickFormat = (n: any) => { return `${n}` } -const formatMetricValue = (value: any, metric: any) => { +const formatMetricValue = (value: any, metric: any, isLog?: boolean) => { + if (isLog) { + return `log(${value})` + } if (value === 0) { return '0' } @@ -627,13 +630,27 @@ const SiteQualityMetricsHistogram = ({ const logLabels = ['AS_VarDP', 'QUALapprox', 'AS_QUALapprox'] - const xLabelRenamed = logLabels.includes(xLabel) ? `log(${xLabel})` : xLabel + const isLogMetrics = logLabels.includes(xLabel) + + const xLabelRenamed = isLogMetrics ? `log(${xLabel})` : xLabel const primaryValues = exomeBinValues || genomeBinValues const secondaryValues = exomeBinValues ? genomeBinValues : null - const primaryMetricValue = exomeMetricValue !== null ? exomeMetricValue : genomeMetricValue - const secondaryMetricValue = exomeMetricValue !== null ? genomeMetricValue : null + const originalPrimaryMetricValue = + exomeMetricValue !== null ? exomeMetricValue : genomeMetricValue + + const primaryMetricValue = + isLogMetrics && originalPrimaryMetricValue > 0 + ? Math.log(originalPrimaryMetricValue) + : originalPrimaryMetricValue + + const originalSecondaryMetricValue = exomeMetricValue !== null ? genomeMetricValue : null + + const secondaryMetricValue = + isLogMetrics && originalSecondaryMetricValue > 0 + ? Math.log(originalSecondaryMetricValue) + : originalSecondaryMetricValue const primaryYLabel = exomeBinValues ? 'Exome variants' : 'Genome variants' const secondaryYLabel = 'Genome variants' @@ -874,7 +891,7 @@ const SiteQualityMetricsHistogram = ({ fontSize={12} textAnchor={secondaryLabelOnLeft ? 'end' : 'start'} > - {formatMetricValue(secondaryMetricValue, metric)} + {formatMetricValue(originalSecondaryMetricValue, metric, isLogMetrics)} )} @@ -902,7 +919,8 @@ const SiteQualityMetricsHistogram = ({ fontSize={12} textAnchor={primaryLabelOnLeft ? 'end' : 'start'} > - {formatMetricValue(primaryMetricValue, metric)} + {/* {formattedLabel} */} + {formatMetricValue(originalPrimaryMetricValue, metric, logLabels.includes(xLabel))} )} @@ -1020,20 +1038,32 @@ const VariantSiteQualityMetricsDistribution = ({ const includeExomes = selectedSequencingType.includes('e') const includeGenomes = selectedSequencingType.includes('g') + const logLabels = ['AS_VarDP', 'QUALapprox', 'AS_QUALapprox'] + + const isLogMetrics = logLabels.includes(selectedMetric) + let values if (variant.exome && variant.genome) { values = `${ - exomeMetricValue === null ? '–' : formatMetricValue(exomeMetricValue, selectedMetric) + exomeMetricValue === null + ? '–' + : formatMetricValue(exomeMetricValue, selectedMetric, isLogMetrics) } (exome samples), ${ - genomeMetricValue === null ? '–' : formatMetricValue(genomeMetricValue, selectedMetric) + genomeMetricValue === null + ? '–' + : formatMetricValue(genomeMetricValue, selectedMetric, isLogMetrics) } (genome samples)` } else if (variant.exome) { values = `${ - exomeMetricValue === null ? '–' : formatMetricValue(exomeMetricValue, selectedMetric) + exomeMetricValue === null + ? '–' + : formatMetricValue(exomeMetricValue, selectedMetric, isLogMetrics) } (exome samples)` } else { values = `${ - genomeMetricValue === null ? '–' : formatMetricValue(genomeMetricValue, selectedMetric) + genomeMetricValue === null + ? '–' + : formatMetricValue(genomeMetricValue, selectedMetric, isLogMetrics) } (genome samples)` }