Skip to content

Commit 929754a

Browse files
authored
Misc refactors and improvements (#5415)
1 parent 49a482e commit 929754a

File tree

55 files changed

+1518
-1246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1518
-1246
lines changed

packages/core/src/pluggableElementTypes/models/BaseDisplayModel.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ function stateModelFactory() {
7878
return getContainingTrack(self)
7979
},
8080

81+
/**
82+
* #getter
83+
* Returns true if the parent track is minimized. Used to skip
84+
* expensive operations like autoruns when track is not visible.
85+
*/
86+
get isMinimized() {
87+
return this.parentTrack.minimized
88+
},
89+
8190
/**
8291
* #getter
8392
* Returns the parent display if this display is nested within another display
@@ -132,7 +141,7 @@ function stateModelFactory() {
132141
renderProps() {
133142
return {
134143
...getParentRenderProps(self),
135-
notReady: getContainingView(self).minimized,
144+
notReady: self.isMinimized || getContainingView(self).minimized,
136145
rpcDriverName: self.effectiveRpcDriverName,
137146
}
138147
},

packages/core/src/util/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ export interface AbstractTrackModel {
319319
id: string
320320
displays: AbstractDisplayModel[]
321321
configuration: AnyConfigurationModel & { displays: Display[] }
322+
minimized: boolean
322323
}
323324

324325
export function isTrackModel(thing: unknown): thing is AbstractTrackModel {

plugins/alignments/src/LinearPileupDisplay/SharedLinearPileupDisplayMixin.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export function SharedLinearPileupDisplayMixin(
151151
* #getter
152152
*/
153153
get autorunReady() {
154+
if (self.isMinimized) {
155+
return false
156+
}
154157
const view = getContainingView(self) as LGV
155158
return (
156159
view.initialized && self.featureDensityStatsReadyAndRegionNotTooLarge
@@ -334,23 +337,26 @@ export function SharedLinearPileupDisplayMixin(
334337
*/
335338
get rendererConfig() {
336339
const {
337-
featureHeight: height,
340+
featureHeight,
338341
noSpacing,
339342
hideSmallIndels,
340343
hideMismatches,
341344
hideLargeIndels,
342-
trackMaxHeight: maxHeight,
345+
trackMaxHeight,
343346
rendererTypeName,
344347
} = self
345-
const configBlob = getConf(self, ['renderers', rendererTypeName]) || {}
348+
// @ts-ignore
349+
const conf = self.configuration.renderers?.[rendererTypeName]
346350
return {
347-
...configBlob,
348-
...(hideSmallIndels !== undefined ? { hideSmallIndels } : {}),
349-
...(hideMismatches !== undefined ? { hideMismatches } : {}),
350-
...(hideLargeIndels !== undefined ? { hideLargeIndels } : {}),
351-
...(height !== undefined ? { height } : {}),
352-
...(noSpacing !== undefined ? { noSpacing } : {}),
353-
...(maxHeight !== undefined ? { maxHeight } : {}),
351+
height: featureHeight ?? readConfObject(conf, 'height'),
352+
noSpacing: noSpacing ?? readConfObject(conf, 'noSpacing'),
353+
maxHeight: trackMaxHeight ?? readConfObject(conf, 'maxHeight'),
354+
hideSmallIndels:
355+
hideSmallIndels ?? readConfObject(conf, 'hideSmallIndels'),
356+
hideMismatches:
357+
hideMismatches ?? readConfObject(conf, 'hideMismatches'),
358+
hideLargeIndels:
359+
hideLargeIndels ?? readConfObject(conf, 'hideLargeIndels'),
354360
}
355361
},
356362
}))
@@ -359,14 +365,20 @@ export function SharedLinearPileupDisplayMixin(
359365
* #getter
360366
*/
361367
get maxHeight() {
362-
return readConfObject(self.rendererConfig, 'maxHeight')
368+
return self.rendererConfig.maxHeight
363369
},
364370

365371
/**
366372
* #getter
367373
*/
368374
get featureHeightSetting() {
369-
return readConfObject(self.rendererConfig, 'height')
375+
return self.rendererConfig.height
376+
},
377+
/**
378+
* #getter
379+
*/
380+
get noSpacingSetting() {
381+
return self.rendererConfig.noSpacing
370382
},
371383
/**
372384
* #getter
@@ -644,7 +656,9 @@ export function SharedLinearPileupDisplayMixin(
644656
{
645657
label: 'Normal',
646658
type: 'radio',
647-
checked: self.featureHeight === 7 && self.noSpacing === false,
659+
checked:
660+
self.featureHeightSetting === 7 &&
661+
self.noSpacingSetting === false,
648662
onClick: () => {
649663
self.setFeatureHeight(7)
650664
self.setNoSpacing(false)
@@ -653,7 +667,9 @@ export function SharedLinearPileupDisplayMixin(
653667
{
654668
label: 'Compact',
655669
type: 'radio',
656-
checked: self.featureHeight === 2 && self.noSpacing === true,
670+
checked:
671+
self.featureHeightSetting === 2 &&
672+
self.noSpacingSetting === true,
657673
onClick: () => {
658674
self.setFeatureHeight(2)
659675
self.setNoSpacing(true)
@@ -662,7 +678,9 @@ export function SharedLinearPileupDisplayMixin(
662678
{
663679
label: 'Super-compact',
664680
type: 'radio',
665-
checked: self.featureHeight === 1 && self.noSpacing === true,
681+
checked:
682+
self.featureHeightSetting === 1 &&
683+
self.noSpacingSetting === true,
666684
onClick: () => {
667685
self.setFeatureHeight(1)
668686
self.setNoSpacing(true)

plugins/alignments/src/LinearPileupDisplay/doAfterAttach.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ export function doAfterAttach(model: {
3636
createAutorun(
3737
model,
3838
async () => {
39-
const view = getContainingView(model) as LGV
4039
if (!model.autorunReady) {
4140
return
4241
}
43-
42+
const view = getContainingView(model) as LGV
4443
model.setCurrSortBpPerPx(view.bpPerPx)
4544
},
4645
{
@@ -51,12 +50,11 @@ export function doAfterAttach(model: {
5150
createAutorun(
5251
model,
5352
async () => {
54-
const { rpcManager } = getSession(model)
55-
const view = getContainingView(model) as LGV
5653
if (!model.autorunReady) {
5754
return
5855
}
59-
56+
const { rpcManager } = getSession(model)
57+
const view = getContainingView(model) as LGV
6058
const { sortedBy, adapterConfig, rendererType, sortReady } = model
6159
const { bpPerPx } = view
6260

plugins/alignments/src/LinearPileupDisplay/model.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { lazy } from 'react'
22

33
import {
44
ConfigurationReference,
5-
getConf,
65
readConfObject,
76
} from '@jbrowse/core/configuration'
87
import { getContainingView, getSession } from '@jbrowse/core/util'
@@ -186,21 +185,23 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
186185
noSpacing,
187186
trackMaxHeight,
188187
mismatchAlpha,
189-
rendererTypeName,
190188
hideSmallIndels,
191189
hideMismatches,
190+
hideLargeIndels,
192191
} = self
193-
const configBlob = getConf(self, ['renderers', rendererTypeName]) || {}
192+
// @ts-ignore
193+
const conf = self.configuration.renderers?.PileupRenderer
194194
return {
195-
...configBlob,
196-
...(featureHeight !== undefined ? { height: featureHeight } : {}),
197-
...(hideSmallIndels !== undefined ? { hideSmallIndels } : {}),
198-
...(hideMismatches !== undefined ? { hideMismatches } : {}),
199-
...(noSpacing !== undefined ? { noSpacing } : {}),
200-
...(mismatchAlpha !== undefined ? { mismatchAlpha } : {}),
201-
...(trackMaxHeight !== undefined
202-
? { maxHeight: trackMaxHeight }
203-
: {}),
195+
height: featureHeight ?? readConfObject(conf, 'height'),
196+
noSpacing: noSpacing ?? readConfObject(conf, 'noSpacing'),
197+
maxHeight: trackMaxHeight ?? readConfObject(conf, 'maxHeight'),
198+
mismatchAlpha: mismatchAlpha ?? readConfObject(conf, 'mismatchAlpha'),
199+
hideSmallIndels:
200+
hideSmallIndels ?? readConfObject(conf, 'hideSmallIndels'),
201+
hideMismatches:
202+
hideMismatches ?? readConfObject(conf, 'hideMismatches'),
203+
hideLargeIndels:
204+
hideLargeIndels ?? readConfObject(conf, 'hideLargeIndels'),
204205
}
205206
},
206207
}))
@@ -211,7 +212,7 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
211212
* #getter
212213
*/
213214
get mismatchAlphaSetting() {
214-
return readConfObject(self.rendererConfig, 'mismatchAlpha')
215+
return self.rendererConfig.mismatchAlpha
215216
},
216217
/**
217218
* #method

plugins/alignments/src/LinearPileupDisplay/sharedDoAfterAttach.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ export function sharedDoAfterAttach(self: {
2121
createAutorun(
2222
self,
2323
async () => {
24-
const view = getContainingView(self) as LGV
2524
if (!self.autorunReady) {
2625
return
2726
}
28-
27+
const view = getContainingView(self) as LGV
2928
const { colorBy, tagsReady } = self
3029
const { staticBlocks } = view
3130
if (colorBy?.tag && !tagsReady) {

plugins/alignments/src/LinearSNPCoverageDisplay/model.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,27 +149,25 @@ function stateModelFactory(
149149
* #getter
150150
*/
151151
get rendererConfig() {
152-
const configBlob =
153-
getConf(self, ['renderers', self.rendererTypeName]) || {}
154-
155152
const { showArcs, showInterbaseCounts, showInterbaseIndicators } =
156153
self
154+
// @ts-ignore
155+
const conf = self.configuration.renderers?.[self.rendererTypeName]
157156
return {
158-
...configBlob,
159157
showInterbaseCounts:
160-
showInterbaseCounts ?? configBlob.showInterbaseCounts,
158+
showInterbaseCounts ??
159+
readConfObject(conf, 'showInterbaseCounts'),
161160
showInterbaseIndicators:
162-
showInterbaseIndicators ?? configBlob.showInterbaseIndicators,
163-
showArcs: showArcs ?? configBlob.showArcs,
161+
showInterbaseIndicators ??
162+
readConfObject(conf, 'showInterbaseIndicators'),
163+
showArcs: showArcs ?? readConfObject(conf, 'showArcs'),
164164
}
165165
},
166166
/**
167167
* #getter
168168
*/
169169
get showArcsSetting() {
170-
return (
171-
self.showArcs ?? readConfObject(this.rendererConfig, 'showArcs')
172-
)
170+
return this.rendererConfig.showArcs
173171
},
174172
/**
175173
* #getter
@@ -202,19 +200,13 @@ function stateModelFactory(
202200
* #getter
203201
*/
204202
get showInterbaseCountsSetting() {
205-
return (
206-
self.showInterbaseCounts ??
207-
readConfObject(this.rendererConfig, 'showInterbaseCounts')
208-
)
203+
return this.rendererConfig.showInterbaseCounts
209204
},
210205
/**
211206
* #getter
212207
*/
213208
get showInterbaseIndicatorsSetting() {
214-
return (
215-
self.showInterbaseIndicators ??
216-
readConfObject(this.rendererConfig, 'showInterbaseIndicators')
217-
)
209+
return this.rendererConfig.showInterbaseIndicators
218210
},
219211

220212
/**

plugins/alignments/src/SNPCoverageAdapter/SNPCoverageAdapter.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,17 @@ export default class SNPCoverageAdapter extends BaseFeatureDataAdapter {
236236
const { bpPerPx, statsEstimationMode } = opts
237237

238238
// Clear cache when bpPerPx changes (zoom level changed)
239-
if (this.lastBpPerPx !== undefined && this.lastBpPerPx !== bpPerPx) {
240-
// console.log(
241-
// `[SNPCoverageAdapter] bpPerPx changed (${this.lastBpPerPx} -> ${bpPerPx}), clearing cache`,
242-
// )
239+
// Only compare when both values are defined to avoid clearing on stats calls
240+
if (
241+
bpPerPx !== undefined &&
242+
this.lastBpPerPx !== undefined &&
243+
this.lastBpPerPx !== bpPerPx
244+
) {
243245
this.cache.clear()
244246
}
245-
this.lastBpPerPx = bpPerPx
247+
if (bpPerPx !== undefined) {
248+
this.lastBpPerPx = bpPerPx
249+
}
246250

247251
// For statsEstimationMode, check for any cached result with same region+filterBy
248252
if (statsEstimationMode) {

plugins/alignments/src/SNPCoverageAdapter/generateCoverageBinsPrefixSum.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ export async function generateCoverageBinsPrefixSum({
166166
for (let i = 0, l = features.length; i < l; i++) {
167167
processFeature(region, features[i]!, skipmap, noncovEvents, snpEvents)
168168
}
169+
// Clear feature reference to avoid retaining last feature in memory
170+
featureCtx.feature = undefined
169171

170172
// Compute deletion depth prefix sums
171173
const deletionDepth = new Int32Array(regionSize)
@@ -491,7 +493,6 @@ function mismatchHandler(
491493
const hash = `${mstart}_${mend}_${effectiveStrand}`
492494
if (skipmap![hash] === undefined) {
493495
skipmap![hash] = {
494-
feature: feature!,
495496
start: mstart,
496497
end: mend,
497498
strand: fstrand,

plugins/alignments/src/shared/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export type SkipMap = Record<
55
string,
66
{
77
score: number
8-
feature: unknown
98
start: number
109
end: number
1110
strand: number

0 commit comments

Comments
 (0)