Skip to content

Commit

Permalink
Hide small indels
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 19, 2024
1 parent 818b059 commit 3b35cd5
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export function SharedLinearPileupDisplayMixin(
* #property
*/
jexlFilters: types.optional(types.array(types.string), []),
/**
* #property
*/
hideSmallIndelsSetting: types.maybe(types.boolean),
}),
)
.volatile(() => ({
Expand Down Expand Up @@ -130,10 +134,20 @@ export function SharedLinearPileupDisplayMixin(
},
}))
.views(self => ({
/**
* #getter
*/
get autorunReady() {
const view = getContainingView(self) as LGV
return view.initialized && self.statsReadyAndRegionNotTooLarge
},

/**
* #getter
*/
get hideSmallIndels() {
return self.hideSmallIndelsSetting
},
}))
.actions(self => ({
/**
Expand Down Expand Up @@ -265,24 +279,35 @@ export function SharedLinearPileupDisplayMixin(
setJexlFilters(filters: string[]) {
self.jexlFilters = cast(filters)
},

/**
* #action
*/
setHideSmallIndels(arg: boolean) {
self.hideSmallIndelsSetting = arg
},
}))

.views(self => ({
/**
* #getter
*/
get rendererConfig() {
const { featureHeight, noSpacing, trackMaxHeight, rendererTypeName } =
self
const {
featureHeight: height,
noSpacing,
hideSmallIndels,
trackMaxHeight: maxHeight,
rendererTypeName,
} = self
const configBlob = getConf(self, ['renderers', rendererTypeName]) || {}
return self.rendererType.configSchema.create(
{
...configBlob,
...(featureHeight !== undefined ? { height: featureHeight } : {}),
...(hideSmallIndels !== undefined ? { hideSmallIndels } : {}),
...(height !== undefined ? { height } : {}),
...(noSpacing !== undefined ? { noSpacing } : {}),
...(trackMaxHeight !== undefined
? { maxHeight: trackMaxHeight }
: {}),
...(maxHeight !== undefined ? { maxHeight } : {}),
},
getEnv(self),
)
Expand Down Expand Up @@ -561,6 +586,15 @@ export function SharedLinearPileupDisplayMixin(
},
],
},
{
label: 'Hide small indels (<10bp)',
priority: -1,
type: 'checkbox',
checked: self.hideSmallIndels,
onClick: () => {
self.setHideSmallIndels(!self.hideSmallIndels)
},
},
{
label: 'Set max height...',
priority: -1,
Expand Down
2 changes: 2 additions & 0 deletions plugins/alignments/src/LinearPileupDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,14 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
trackMaxHeight,
mismatchAlpha,
rendererTypeName,
hideSmallIndels,
} = self
const configBlob = getConf(self, ['renderers', rendererTypeName]) || {}
return self.rendererType.configSchema.create(
{
...configBlob,
...(featureHeight !== undefined ? { height: featureHeight } : {}),
...(hideSmallIndels !== undefined ? { hideSmallIndels } : {}),
...(noSpacing !== undefined ? { noSpacing } : {}),
...(mismatchAlpha !== undefined ? { mismatchAlpha } : {}),
...(trackMaxHeight !== undefined
Expand Down
9 changes: 9 additions & 0 deletions plugins/alignments/src/PileupRenderer/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ const PileupRenderer = ConfigurationSchema(
'the minimum width in px for a pileup mismatch feature. use for increasing/decreasing mismatch marker widths when zoomed out, e.g. 0 or 1',
defaultValue: 1,
},
/**
* #slot
*/
hideSmallIndels: {
type: 'boolean',
description:
'Hides small indels, sometimes occurring in long read sequencing',
defaultValue: false,
},
/**
* #slot
*/
Expand Down
2 changes: 2 additions & 0 deletions plugins/alignments/src/PileupRenderer/makeImageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function makeImageData({
config,
'largeInsertionIndicatorScale',
)
const hideSmallIndels = readConfObject(config, 'hideSmallIndels') as boolean
const defaultColor = readConfObject(config, 'color') === '#f0f'
const theme = createJBrowseTheme(configTheme)
const colorForBase = getColorBaseMap(theme)
Expand Down Expand Up @@ -76,6 +77,7 @@ export function makeImageData({
ctx,
feat,
renderArgs,
hideSmallIndels,
mismatchAlpha,
drawSNPsMuted,
drawIndels,
Expand Down
51 changes: 31 additions & 20 deletions plugins/alignments/src/PileupRenderer/renderMismatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function renderMismatches({
charHeight,
colorForBase,
contrastForBase,
hideSmallIndels,
canvasWidth,
drawSNPsMuted,
drawIndels = true,
Expand All @@ -32,6 +33,7 @@ export function renderMismatches({
drawSNPsMuted?: boolean
minSubfeatureWidth: number
largeInsertionIndicatorScale: number
hideSmallIndels: boolean
charWidth: number
charHeight: number
canvasWidth: number
Expand Down Expand Up @@ -100,32 +102,41 @@ export function renderMismatches({
)
}
} else if (mismatch.type === 'deletion' && drawIndels) {
fillRect(
ctx,
leftPx,
topPx,
Math.abs(leftPx - rightPx),
heightPx,
canvasWidth,
colorForBase.deletion,
)
const txt = `${mismatch.length}`
const rwidth = measureText(txt, 10)
if (widthPx >= rwidth && heightPx >= heightLim) {
ctx.fillStyle = contrastForBase.deletion!
ctx.fillText(txt, (leftPx + rightPx) / 2 - rwidth / 2, topPx + heightPx)
const len = mismatch.length
if (!hideSmallIndels || len >= 10) {
fillRect(
ctx,
leftPx,
topPx,
Math.abs(leftPx - rightPx),
heightPx,
canvasWidth,
colorForBase.deletion,
)
const txt = `${mismatch.length}`
const rwidth = measureText(txt, 10)
if (widthPx >= rwidth && heightPx >= heightLim) {
ctx.fillStyle = contrastForBase.deletion!
ctx.fillText(
txt,
(leftPx + rightPx) / 2 - rwidth / 2,
topPx + heightPx,
)
}
}
} else if (mismatch.type === 'insertion' && drawIndels) {
const pos = leftPx + extraHorizontallyFlippedOffset
const len = +mismatch.base || mismatch.length
const insW = Math.max(minSubfeatureWidth, Math.min(1.2, 1 / bpPerPx))
if (len < 10) {
fillRect(ctx, pos, topPx, insW, heightPx, canvasWidth, 'purple')
if (1 / bpPerPx >= charWidth && heightPx >= heightLim) {
const l = Math.round(pos - insW)
fillRect(ctx, l, topPx, insW * 3, 1, canvasWidth)
fillRect(ctx, l, topPx + heightPx - 1, insW * 3, 1, canvasWidth)
ctx.fillText(`(${mismatch.base})`, pos + 3, topPx + heightPx)
if (!hideSmallIndels) {
fillRect(ctx, pos, topPx, insW, heightPx, canvasWidth, 'purple')
if (1 / bpPerPx >= charWidth && heightPx >= heightLim) {
const l = Math.round(pos - insW)
fillRect(ctx, l, topPx, insW * 3, 1, canvasWidth)
fillRect(ctx, l, topPx + heightPx - 1, insW * 3, 1, canvasWidth)
ctx.fillText(`(${mismatch.base})`, pos + 3, topPx + heightPx)
}
}
}
} else if (mismatch.type === 'hardclip' || mismatch.type === 'softclip') {
Expand Down

0 comments on commit 3b35cd5

Please sign in to comment.