Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions plugins/alignments/src/LinearSNPCoverageDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,15 @@ function stateModelFactory(
createAutorun(
self,
async () => {
self.setModificationsReady(false)
if (!self.autorunReady) {
return
}
const view = getContainingView(self) as LGV
const singleRegion = view.dynamicBlocks.contentBlocks.length === 1
const { staticBlocks } = view
const { colorBy } = self
if (colorBy?.type === 'modifications') {
if (colorBy?.type === 'modifications' && !singleRegion) {
self.setModificationsReady(false)
const { modifications, simplexModifications } =
await getUniqueModifications({
model: self,
Expand All @@ -293,9 +294,8 @@ function stateModelFactory(
self.setSimplexModifications(simplexModifications)
self.setModificationsReady(true)
}
} else {
self.setModificationsReady(true)
}
self.setModificationsReady(true)
},
{ delay: 1000 },
)
Expand Down
37 changes: 36 additions & 1 deletion plugins/alignments/src/SNPCoverageRenderer/makeImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@jbrowse/plugin-wiggle'

import { alphaColor } from '../shared/util'
import { getColorForModification } from '../util'

import type { RenderArgsDeserializedWithFeatures } from './types'
import type { BaseCoverageBin } from '../shared/types'
Expand Down Expand Up @@ -115,7 +116,7 @@ export async function makeImage(
bpPerPx,
colorBy,
displayCrossHatches,
visibleModifications = {},
visibleModifications: initialVisibleModifications = {},
simplexModifications = [],
scaleOpts,
height: unadjustedHeight,
Expand All @@ -124,6 +125,37 @@ export async function makeImage(
ticks,
stopToken,
} = props

const singleRegion = regions.length === 1
let visibleModifications = initialVisibleModifications
if (singleRegion && colorBy.type === 'modifications') {
const newVisibleModifications = { ...initialVisibleModifications }
const foundModifications = new Set<string>()
for (const feature of features.values()) {
const snpinfo = feature.get('snpinfo')
if (snpinfo) {
const { mods, nonmods } = snpinfo
for (const mod of Object.keys(mods)) {
foundModifications.add(mod.replace('mod_', ''))
}
for (const nonmod of Object.keys(nonmods)) {
foundModifications.add(nonmod.replace('nonmod_', ''))
}
}
}

for (const type of foundModifications) {
if (!newVisibleModifications[type]) {
newVisibleModifications[type] = {
type,
base: 'N',
strand: '.',
color: getColorForModification(type),
}
}
}
visibleModifications = newVisibleModifications
}
const theme = createJBrowseTheme(configTheme)
const region = regions[0]!
const width = (region.end - region.start) / bpPerPx
Expand All @@ -143,6 +175,9 @@ export async function makeImage(
range: [0, height / 2],
scaleType: 'linear',
})
if (!viewScale || !indicatorViewScale) {
return
}
const originY = getOrigin(scaleOpts.scaleType)
const originLinear = getOrigin('linear')

Expand Down
12 changes: 6 additions & 6 deletions plugins/linear-genome-view/src/BaseLinearDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
*/
contextMenuFeature: undefined as undefined | Feature,
}))
.views(self => ({

Check failure on line 109 in plugins/linear-genome-view/src/BaseLinearDisplay/model.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

'self' is defined but never used. Allowed unused args must match /^_/u
/**
* #getter
* if a display-level message should be displayed instead of the blocks,
Expand All @@ -119,8 +119,10 @@
* #getter
*/
get blockType(): 'staticBlocks' | 'dynamicBlocks' {
return 'staticBlocks'
return 'dynamicBlocks'
},
}))
.views(self => ({
/**
* #getter
*/
Expand All @@ -129,14 +131,12 @@
if (!view.initialized) {
throw new Error('view not initialized yet')
}
return view[this.blockType]
return view.dynamicBlocks
},
}))
.views(self => ({
/**
* #getter
* how many milliseconds to wait for the display to
* "settle" before re-rendering a block
* how many milliseconds to wait for the display to "settle" before
* re-rendering a block
*/
get renderDelay() {
return 50
Expand Down
30 changes: 17 additions & 13 deletions plugins/wiggle/src/LinearWiggleDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,16 @@ function stateModelFactory(
const { inverted, scaleType, domain, height } = self
const minimalTicks = getConf(self, 'minimalTicks')
if (domain) {
const ticks = axisPropsFromTickScale(
getScale({
scaleType,
domain,
range: [
height - YSCALEBAR_LABEL_OFFSET,
YSCALEBAR_LABEL_OFFSET,
],
inverted,
}),
4,
)
const scale = getScale({
scaleType,
domain,
range: [height - YSCALEBAR_LABEL_OFFSET, YSCALEBAR_LABEL_OFFSET],
inverted,
})
if (!scale) {
return undefined
}
const ticks = axisPropsFromTickScale(scale, 4)
return height < 100 || minimalTicks
? { ...ticks, values: domain }
: ticks
Expand All @@ -165,9 +163,15 @@ function stateModelFactory(
renderProps() {
const { inverted, ticks, height } = self
const superProps = self.adapterProps()
const view = getContainingView(self) as LinearGenomeViewModel
const statsRegion = JSON.stringify(view.dynamicBlocks)
const singleRegion = view.dynamicBlocks.contentBlocks.length === 1
return {
...self.adapterProps(),
notReady: superProps.notReady || !self.stats,
notReady:
superProps.notReady ||
(!singleRegion &&
(!self.stats || self.statsRegion !== statsRegion)),
height,
ticks,
inverted,
Expand Down
19 changes: 10 additions & 9 deletions plugins/wiggle/src/MultiLinearWiggleDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,16 @@ export function stateModelFactory(
}

const offset = isMultiRow ? 0 : YSCALEBAR_LABEL_OFFSET
const ticks = axisPropsFromTickScale(
getScale({
scaleType,
domain,
range: [rowHeight - offset, offset],
inverted: getConf(self, 'inverted') as boolean,
}),
4,
)
const scale = getScale({
scaleType,
domain,
range: [rowHeight - offset, offset],
inverted: getConf(self, 'inverted') as boolean,
})
if (!scale) {
return undefined
}
const ticks = axisPropsFromTickScale(scale, 4)
return useMinimalTicks ? { ...ticks, values: domain } : ticks
},

Expand Down
36 changes: 28 additions & 8 deletions plugins/wiggle/src/WiggleBaseRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import FeatureRendererType from '@jbrowse/core/pluggableElementTypes/renderers/FeatureRendererType'
import { renderToAbstractCanvas, updateStatus } from '@jbrowse/core/util'

import { getNiceDomain } from './util'

import type { ScaleOpts, Source } from './util'
import type {
RenderArgs as FeatureRenderArgs,
Expand Down Expand Up @@ -41,20 +43,37 @@ export default abstract class WiggleBaseRenderer extends FeatureRendererType {

async render(renderProps: RenderArgsDeserialized) {
const features = await this.getFeatures(renderProps)
const {
inverted,
height,
regions,
bpPerPx,
statusCallback = () => {},
} = renderProps
const { inverted, height, regions, bpPerPx, scaleOpts, statusCallback } =
renderProps

const region = regions[0]!
const width = (region.end - region.start) / bpPerPx

// calculate new domain for single region views
let newDomain: number[] | undefined
if (regions.length === 1) {
let scoreMin = Infinity
let scoreMax = -Infinity
for (const feature of features.values()) {
const score = feature.get('score') as number
scoreMin = Math.min(scoreMin, score)
scoreMax = Math.max(scoreMax, score)
}
if (scoreMin !== Infinity) {
const { scaleType, minScore, maxScore } = scaleOpts
newDomain = getNiceDomain({
domain: [scoreMin, scoreMax],
bounds: [minScore, maxScore],
scaleType: scaleType,
})
}
}

const newScaleOpts = { ...scaleOpts, domain: newDomain || scaleOpts.domain }

const { reducedFeatures, ...rest } = await updateStatus(
'Rendering plot',
statusCallback,
statusCallback || (() => {}),
() =>
renderToAbstractCanvas(
width,
Expand All @@ -63,6 +82,7 @@ export default abstract class WiggleBaseRenderer extends FeatureRendererType {
ctx =>
this.draw(ctx, {
...renderProps,
scaleOpts: newScaleOpts,
features,
inverted,
}) as Promise<{ reducedFeatures: Feature[] | undefined }>,
Expand Down
8 changes: 8 additions & 0 deletions plugins/wiggle/src/drawDensity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export function drawDensity(
})

const scale2 = getScale({ ...scaleOpts, range: [0, height] })

if (!scale || !scale2) {
return { reducedFeatures: [] }
}

const cb =
color === '#f0f'
? (_: Feature, score: number) => scale(score)
Expand Down Expand Up @@ -70,6 +75,9 @@ export function drawDensity(
const score = feature.get('score')
hasClipping = hasClipping || score > niceMax || score < niceMin
const w = rightPx - leftPx + fudgeFactor
if (!scaleOpts.domain) {
return { reducedFeatures: [] }
}
if (score >= scaleOpts.domain[0]!) {
ctx.fillStyle = cb(feature, score)
ctx.fillRect(leftPx, 0, w, height)
Expand Down
3 changes: 3 additions & 0 deletions plugins/wiggle/src/drawLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export function drawLine(
const height = unadjustedHeight - offset * 2
const clipColor = readConfObject(config, 'clipColor')
const scale = getScale({ ...scaleOpts, range: [0, height] })
if (!scale) {
return { reducedFeatures: [] }
}
const domain = scale.domain()
const niceMin = domain[0]!
const niceMax = domain[1]!
Expand Down
3 changes: 3 additions & 0 deletions plugins/wiggle/src/drawXY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export function drawXY(
const minSize = readConfObject(config, 'minSize')

const scale = getScale({ ...scaleOpts, range: [0, height], inverted })
if (!scale) {
return { reducedFeatures: [] }
}
const originY = getOrigin(scaleOpts.scaleType)
const domain = scale.domain()
const niceMin = domain[0]!
Expand Down
10 changes: 8 additions & 2 deletions plugins/wiggle/src/getQuantitativeStatsAutorun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@
setError: (error: unknown) => void
setMessage: (str: string) => void
updateQuantitativeStats: (stats: QuantitativeStats, region: string) => void
setStatsRegion: (region: string) => void
}) {
addDisposer(
self,
autorun(
async () => {
try {
if (self.quantitativeStatsReady) {
const view = getContainingView(self) as LGV
const view = getContainingView(self) as LGV
if (
self.quantitativeStatsReady &&
view.dynamicBlocks.contentBlocks.length > 1
) {
console.log('wtf')

Check failure on line 36 in plugins/wiggle/src/getQuantitativeStatsAutorun.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

Unexpected console statement. Only these console methods are allowed: error, warn
const stopToken = createStopToken()
self.setStatsLoading(stopToken)
const statsRegion = JSON.stringify(view.dynamicBlocks)
self.setStatsRegion(statsRegion)
const wiggleStats = await getQuantitativeStats(self, {
stopToken,
filters: [],
Expand Down
Loading
Loading