Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw SNPs in modifications/methylation views #3001

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions plugins/alignments/src/PileupRenderer/PileupRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ interface LayoutFeature {
feature: Feature
}

function shouldDrawSNPs(type?: string) {
return !['methylation', 'modifications'].includes(type || '')
function shouldDrawSNPsMuted(type?: string) {
return ['methylation', 'modifications'].includes(type || '')
}

function shouldDrawIndels(type?: string) {
Expand Down Expand Up @@ -830,7 +830,7 @@ export default class PileupRenderer extends BoxRendererType {
colorForBase,
contrastForBase,
canvasWidth,
drawSNPs = true,
drawSNPsMuted,
drawIndels = true,
}: {
ctx: CanvasRenderingContext2D
Expand All @@ -839,8 +839,8 @@ export default class PileupRenderer extends BoxRendererType {
colorForBase: { [key: string]: string }
contrastForBase: { [key: string]: string }
mismatchAlpha?: boolean
drawSNPs?: boolean
drawIndels?: boolean
drawSNPsMuted?: boolean
minSubfeatureWidth: number
largeInsertionIndicatorScale: number
charWidth: number
Expand Down Expand Up @@ -872,30 +872,34 @@ export default class PileupRenderer extends BoxRendererType {
const mbase = mismatch.base
const [leftPx, rightPx] = bpSpanPx(mstart, mstart + mlen, region, bpPerPx)
const widthPx = Math.max(minSubfeatureWidth, Math.abs(leftPx - rightPx))
if (mismatch.type === 'mismatch' && drawSNPs) {
const baseColor = colorForBase[mismatch.base] || '#888'
if (mismatch.type === 'mismatch') {
if (!drawSNPsMuted) {
const baseColor = colorForBase[mismatch.base] || '#888'

fillRect(
ctx,
leftPx,
topPx,
widthPx,
heightPx,
canvasWidth,
!mismatchAlpha
? baseColor
: mismatch.qual !== undefined
? // @ts-ignore
Color(baseColor)
.alpha(Math.min(1, mismatch.qual / 50))
.hsl()
.string()
: baseColor,
)
fillRect(
ctx,
leftPx,
topPx,
widthPx,
heightPx,
canvasWidth,
!mismatchAlpha
? baseColor
: mismatch.qual !== undefined
? // @ts-ignore
Color(baseColor)
.alpha(Math.min(1, mismatch.qual / 50))
.hsl()
.string()
: baseColor,
)
}

if (widthPx >= charWidth && heightPx >= heightLim) {
// normal SNP coloring
const contrastColor = contrastForBase[mismatch.base] || 'black'
const contrastColor = drawSNPsMuted
? 'black'
: contrastForBase[mismatch.base] || 'black'
ctx.fillStyle = !mismatchAlpha
? contrastColor
: mismatch.qual !== undefined
Expand Down Expand Up @@ -1160,7 +1164,7 @@ export default class PileupRenderer extends BoxRendererType {
ctx.font = 'bold 10px Courier New,monospace'

const { charWidth, charHeight } = this.getCharWidthHeight(ctx)
const drawSNPs = shouldDrawSNPs(colorBy?.type)
const drawSNPsMuted = shouldDrawSNPsMuted(colorBy?.type)
const drawIndels = shouldDrawIndels(colorBy?.type)
for (let i = 0; i < layoutRecords.length; i++) {
const feat = layoutRecords[i]
Expand All @@ -1184,7 +1188,7 @@ export default class PileupRenderer extends BoxRendererType {
feat,
renderArgs,
mismatchAlpha,
drawSNPs,
drawSNPsMuted,
drawIndels,
largeInsertionIndicatorScale,
minSubfeatureWidth,
Expand Down