Skip to content

Commit

Permalink
Merge pull request #1601 from GMOD/color_by_base
Browse files Browse the repository at this point in the history
Add ability to color by per-base quality in alignment tracks
  • Loading branch information
rbuels authored Feb 19, 2021
2 parents 7186f1b + ff463e6 commit 9a8d75a
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 215 deletions.
10 changes: 8 additions & 2 deletions packages/core/util/offscreenCanvasPonyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ class PonyfillOffscreenContext {

// setters (no getters working)
set strokeStyle(style) {
this.commands.push({ type: 'strokeStyle', style })
if (style !== this.currentStrokeStyle) {
this.commands.push({ type: 'strokeStyle', style })
this.currentStrokeStyle = style
}
}

set fillStyle(style) {
this.commands.push({ type: 'fillStyle', style })
if (style !== this.currentFillStyle) {
this.commands.push({ type: 'fillStyle', style })
this.currentFillStyle = style
}
}

set font(style) {
Expand Down
6 changes: 6 additions & 0 deletions plugins/alignments/src/LinearPileupDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ const stateModelFactory = (
self.setColorScheme({ type: 'pairOrientation' })
},
},
{
label: 'Per-base quality',
onClick: () => {
self.setColorScheme({ type: 'perBaseQuality' })
},
},
{
label: 'Insert size',
onClick: () => {
Expand Down
59 changes: 59 additions & 0 deletions plugins/alignments/src/PileupRenderer/PileupLayoutSession.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import deepEqual from 'deep-equal'
import { LayoutSession } from '@jbrowse/core/pluggableElementTypes/renderers/BoxRendererType'
import { AnyConfigurationModel } from '@jbrowse/core/configuration/configurationSchema'
import SerializableFilterChain from '@jbrowse/core/pluggableElementTypes/renderers/util/serializableFilterChain'
import GranularRectLayout from '@jbrowse/core/util/layouts/GranularRectLayout'
import MultiLayout from '@jbrowse/core/util/layouts/MultiLayout'
import { readConfObject } from '@jbrowse/core/configuration'

export interface PileupLayoutSessionProps {
config: AnyConfigurationModel
bpPerPx: number
filters: SerializableFilterChain
sortedBy: unknown
showSoftClip: unknown
}

type MyMultiLayout = MultiLayout<GranularRectLayout<unknown>, unknown>
interface CachedPileupLayout {
layout: MyMultiLayout
config: AnyConfigurationModel
filters: SerializableFilterChain
sortedBy: unknown
showSoftClip: boolean
}
// Sorting and revealing soft clip changes the layout of Pileup renderer
// Adds extra conditions to see if cached layout is valid
export class PileupLayoutSession extends LayoutSession {
sortedBy: unknown

showSoftClip = false

constructor(args: PileupLayoutSessionProps) {
super(args)
this.config = args.config
}

cachedLayoutIsValid(cachedLayout: CachedPileupLayout) {
return (
super.cachedLayoutIsValid(cachedLayout) &&
this.showSoftClip === cachedLayout.showSoftClip &&
deepEqual(this.sortedBy, cachedLayout.sortedBy)
)
}

cachedLayout: CachedPileupLayout | undefined

get layout(): MyMultiLayout {
if (!this.cachedLayout || !this.cachedLayoutIsValid(this.cachedLayout)) {
this.cachedLayout = {
layout: this.makeLayout(),
config: readConfObject(this.config),
filters: this.filters,
sortedBy: this.sortedBy,
showSoftClip: this.showSoftClip,
}
}
return this.cachedLayout.layout
}
}
Loading

0 comments on commit 9a8d75a

Please sign in to comment.