Skip to content

Commit

Permalink
add log label for value
Browse files Browse the repository at this point in the history
  • Loading branch information
elissa-alarmani committed Sep 6, 2024
1 parent 51e48c0 commit dbb240a
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions browser/src/VariantPage/VariantSiteQualityMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -874,7 +891,7 @@ const SiteQualityMetricsHistogram = ({
fontSize={12}
textAnchor={secondaryLabelOnLeft ? 'end' : 'start'}
>
{formatMetricValue(secondaryMetricValue, metric)}
{formatMetricValue(originalSecondaryMetricValue, metric, isLogMetrics)}
</text>
</>
)}
Expand Down Expand Up @@ -902,7 +919,8 @@ const SiteQualityMetricsHistogram = ({
fontSize={12}
textAnchor={primaryLabelOnLeft ? 'end' : 'start'}
>
{formatMetricValue(primaryMetricValue, metric)}
{/* {formattedLabel} */}
{formatMetricValue(originalPrimaryMetricValue, metric, logLabels.includes(xLabel))}
</text>
</>
)}
Expand Down Expand Up @@ -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)`
}

Expand Down

0 comments on commit dbb240a

Please sign in to comment.