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

Reduce re-rendering on quantitative and snpcoverage track height adjustments #4652

Merged
merged 4 commits into from
Nov 13, 2024
Merged
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
32 changes: 0 additions & 32 deletions packages/core/util/stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
calcStdFromSums,
rectifyStats,
scoresToStats,
calcPerBaseStats,
UnrectifiedQuantitativeStats,
} from './stats'

Expand Down Expand Up @@ -55,34 +54,3 @@ test('scores to stats', async () => {
expect(ret.scoreMin).toEqual(1)
expect(ret.scoreStdDev).toEqual(1) // calculated from a webapp
})

// peter TODO: fix this test
test('calc per base stats', () => {
// one score at start
expect(
calcPerBaseStats({ refName: 'ctgA', start: 0, end: 9 }, [
new SimpleFeature({ id: 1, data: { start: 0, end: 1, score: 10 } }),
]),
).toEqual([10, 0, 0, 0, 0, 0, 0, 0, 0])
// multiple features
expect(
calcPerBaseStats({ refName: 'ctgA', start: 0, end: 9 }, [
new SimpleFeature({ id: 1, data: { start: 0, end: 1, score: 10 } }),
new SimpleFeature({ id: 2, data: { start: 8, end: 9, score: 10 } }),
]),
).toEqual([10, 0, 0, 0, 0, 0, 0, 0, 10])
// multiple features
expect(
calcPerBaseStats({ refName: 'ctgA', start: 15, end: 30 }, [
new SimpleFeature({ id: 1, data: { start: 10, end: 20, score: 10 } }),
new SimpleFeature({ id: 2, data: { start: 25, end: 26, score: 10 } }),
]),
).toEqual([10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0])
// feature starts before region
expect(
calcPerBaseStats({ refName: 'ctgA', start: 10, end: 19 }, [
new SimpleFeature({ id: 1, data: { start: 5, end: 15, score: 10 } }),
new SimpleFeature({ id: 1, data: { start: 18, end: 26, score: 10 } }),
]),
).toEqual([10, 10, 10, 10, 10, 0, 0, 0, 10])
})
40 changes: 1 addition & 39 deletions packages/core/util/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface UnrectifiedQuantitativeStats {
basesCovered: number
}
export interface QuantitativeStats extends UnrectifiedQuantitativeStats {
currStatsBpPerPx: number
featureDensity: number
scoreMean: number
scoreStdDev: number
Expand Down Expand Up @@ -71,45 +72,6 @@ export function rectifyStats(s: UnrectifiedQuantitativeStats) {
} as QuantitativeStats
}

/**
* calculates per-base scores for variable width features over a region
*
* @param region - object contains start, end
* @param features - list of features with start, end, score
* @returns array of numeric scores
*/
export function calcPerBaseStats(
region: NoAssemblyRegion,
features: Feature[],
): number[] {
const { start, end } = region
const scores = []
const feats = features.sort((a, b) => a.get('start') - b.get('start'))
let pos = start
let currentFeat = 0
let i = 0

while (pos < end) {
while (
currentFeat < feats.length &&
pos >= feats[currentFeat]!.get('end')
) {
currentFeat += 1
}
const f = feats[currentFeat]
if (!f) {
scores[i] = 0
} else if (pos >= f.get('start') && pos < f.get('end')) {
scores[i] = f.get('score')
} else {
scores[i] = 0
}
i += 1
pos += 1
}
return scores
}

/**
* transform a list of scores to summary statistics
*
Expand Down
1 change: 0 additions & 1 deletion plugins/alignments/src/BamAdapter/BamAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ export default class BamAdapter extends BaseFeatureDataAdapter {
if (tagFilter) {
const readVal = record.tags[tagFilter.tag]
const filterVal = tagFilter.value
console.log({ readVal, filterVal })
if (
filterVal === '*'
? readVal === undefined
Expand Down
61 changes: 36 additions & 25 deletions plugins/alignments/src/LinearSNPCoverageDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function stateModelFactory(
},
}))
.views(self => {
const { renderProps: superRenderProps } = self
const { adapterProps: superAdapterProps } = self
return {
/**
* #getter
Expand Down Expand Up @@ -196,36 +196,16 @@ function stateModelFactory(
)
},

/**
* #getter
*/
get renderReady() {
const superProps = superRenderProps()
return !superProps.notReady && self.modificationsReady
},

/**
* #getter
*/
get ready() {
return this.renderReady
},

/**
* #method
*/
renderProps() {
const superProps = superRenderProps()
const { filters, colorBy, filterBy, visibleModifications } = self
adapterProps() {
const superProps = superAdapterProps()
const { filters, filterBy } = self
return {
...superProps,
notReady: !this.ready,
filters,
colorBy,
filterBy,
visibleModifications: Object.fromEntries(
visibleModifications.toJSON(),
),
}
},
}
Expand Down Expand Up @@ -288,8 +268,39 @@ function stateModelFactory(
}))

.views(self => {
const { trackMenuItems: superTrackMenuItems } = self
const {
renderProps: superRenderProps,
trackMenuItems: superTrackMenuItems,
} = self
return {
/**
* #getter
*/
get renderReady() {
const superProps = superRenderProps()
return !superProps.notReady && self.modificationsReady
},

/**
* #getter
*/
get ready() {
return this.renderReady
},
/**
* #method
*/
renderProps() {
const { colorBy, visibleModifications } = self
return {
...superRenderProps(),
notReady: !this.ready,
colorBy,
visibleModifications: Object.fromEntries(
visibleModifications.toJSON(),
),
}
},
/**
* #getter
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function TrackHeightMixin() {
})
.volatile(() => ({
/**
* #property
* #volatile
*/
scrollTop: 0,
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@jbrowse/plugin-linear-genome-view'

// locals
import { WiggleDisplayModel } from '../models/model'
import { WiggleDisplayModel } from '../model'
import YScaleBar from '../../shared/YScaleBar'

type LGV = LinearGenomeViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { types } from 'mobx-state-tree'
import PluginManager from '@jbrowse/core/PluginManager'

// locals
import sharedWiggleConfigFactory from '../../shared/configShared'
import sharedWiggleConfigFactory from '../shared/SharedWiggleConfigSchema'

/**
* #config LinearWiggleDisplay
Expand Down
6 changes: 3 additions & 3 deletions plugins/wiggle/src/LinearWiggleDisplay/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import PluginManager from '@jbrowse/core/PluginManager'
import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType'

import configSchemaFactory from './models/configSchema'
import modelFactory from './models/model'
import configSchemaFactory from './configSchema'
import modelFactory from './model'
import { lazy } from 'react'

export default function LinearWiggleDisplayF(pluginManager: PluginManager) {
Expand All @@ -23,4 +23,4 @@ export default function LinearWiggleDisplayF(pluginManager: PluginManager) {

export { default as Tooltip } from './components/Tooltip'
export { default as ReactComponent } from './components/WiggleDisplayComponent'
export { default as modelFactory } from './models/model'
export { default as modelFactory } from './model'
Loading
Loading