Skip to content

Commit

Permalink
Update stats to be relevant to current region
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 14, 2024
1 parent 00a8c8f commit 67cb847
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 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 {
currStatsRegions: string
currStatsBpPerPx: number
featureDensity: number
scoreMean: number
Expand Down
16 changes: 11 additions & 5 deletions plugins/wiggle/src/LinearWiggleDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ function stateModelFactory(
* #getter
* unused currently
*/
get quantitativeStatsRelevantToCurrentZoom() {
get quantitativeStatsUpToDate() {
const view = getContainingView(self) as LinearGenomeViewModel
return self.stats?.currStatsBpPerPx === view.bpPerPx
const statsRegions = JSON.stringify(view.dynamicBlocks)
return (
self.stats?.currStatsBpPerPx === view.bpPerPx ||
self.stats?.currStatsRegions === statsRegions
)
},
}))

Expand Down Expand Up @@ -140,7 +144,7 @@ function stateModelFactory(
const superProps = self.adapterProps()
return {
...self.adapterProps(),
notReady: superProps.notReady || !self.stats,
notReady: superProps.notReady || !self.quantitativeStatsUpToDate,
height,
ticks,
}
Expand All @@ -150,8 +154,10 @@ function stateModelFactory(
* #getter
*/
get needsScalebar() {
const { rendererTypeName: type } = self
return type === 'XYPlotRenderer' || type === 'LinePlotRenderer'
return (
self.rendererTypeName === 'XYPlotRenderer' ||
self.rendererTypeName === 'LinePlotRenderer'
)
},
/**
* #getter
Expand Down
11 changes: 8 additions & 3 deletions plugins/wiggle/src/getQuantitativeStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ export async function getQuantitativeStats(
signal?: AbortSignal
filters: string[]
currStatsBpPerPx: number
currStatsRegions: string
},
): Promise<QuantitativeStats> {
const { rpcManager } = getSession(self)
const numStdDev = getConf(self, 'numStdDev') || 3
const { adapterConfig, autoscaleType } = self
const sessionId = getRpcSessionId(self)
const { currStatsBpPerPx } = opts
const { rpcManager } = getSession(self)
const { adapterConfig, autoscaleType } = self
const { currStatsRegions, currStatsBpPerPx } = opts
const params = {
sessionId,
adapterConfig,
Expand Down Expand Up @@ -55,10 +56,12 @@ export async function getQuantitativeStats(
scoreMin: scoreMin >= 0 ? 0 : scoreMean - numStdDev * scoreStdDev,
scoreMax: scoreMean + numStdDev * scoreStdDev,
currStatsBpPerPx,
currStatsRegions,
}
: {
...results,
currStatsBpPerPx,
currStatsRegions,
}
}
if (autoscaleType === 'local' || autoscaleType === 'localsd') {
Expand Down Expand Up @@ -90,10 +93,12 @@ export async function getQuantitativeStats(
scoreMin: scoreMin >= 0 ? 0 : scoreMean - numStdDev * scoreStdDev,
scoreMax: scoreMean + numStdDev * scoreStdDev,
currStatsBpPerPx,
currStatsRegions,
}
: {
...results,
currStatsBpPerPx,
currStatsRegions,
}
}
if (autoscaleType === 'zscale') {
Expand Down
10 changes: 7 additions & 3 deletions plugins/wiggle/src/getQuantitativeStatsAutorun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type LGV = LinearGenomeViewModel

export function getQuantitativeStatsAutorun(self: {
quantitativeStatsReady: boolean
quantitativeStatsUpToDate: boolean
configuration: AnyConfigurationModel
adapterConfig: AnyConfigurationModel
autoscaleType: string
Expand All @@ -29,21 +30,24 @@ export function getQuantitativeStatsAutorun(self: {
const view = getContainingView(self) as LGV
const aborter = new AbortController()
self.setStatsLoading(aborter)

if (!self.quantitativeStatsReady) {
return
}
if (self.quantitativeStatsUpToDate) {
return
}

const statsRegion = JSON.stringify(view.dynamicBlocks)
const statsRegions = JSON.stringify(view.dynamicBlocks)
const wiggleStats = await getQuantitativeStats(self, {
signal: aborter.signal,
filters: [],
currStatsBpPerPx: view.bpPerPx,
currStatsRegions: statsRegions,
...self.adapterProps(),
})

if (isAlive(self)) {
self.updateQuantitativeStats(wiggleStats, statsRegion)
self.updateQuantitativeStats(wiggleStats, statsRegions)
}
} catch (e) {
console.error(e)
Expand Down
25 changes: 15 additions & 10 deletions plugins/wiggle/src/shared/SharedWiggleMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import { lazy } from 'react'
// lazies
const SetMinMaxDialog = lazy(() => import('./SetMinMaxDialog'))

export interface QuantitativeStats {
currStatsRegions: string
currStatsBpPerPx: number
scoreMin: number
scoreMax: number
}

/**
* #stateModel SharedWiggleMixin
*/
Expand Down Expand Up @@ -102,9 +109,7 @@ export default function SharedWiggleMixin(
/**
* #volatile
*/
stats: undefined as
| { currStatsBpPerPx: number; scoreMin: number; scoreMax: number }
| undefined,
stats: undefined as QuantitativeStats | undefined,
/**
* #volatile
*/
Expand All @@ -114,19 +119,16 @@ export default function SharedWiggleMixin(
/**
* #action
*/
updateQuantitativeStats(stats: {
currStatsBpPerPx: number
scoreMin: number
scoreMax: number
}) {
const { currStatsBpPerPx, scoreMin, scoreMax } = stats
updateQuantitativeStats(stats: QuantitativeStats) {
const { currStatsRegions, currStatsBpPerPx, scoreMin, scoreMax } = stats
const EPSILON = 0.000001
if (
!self.stats ||
Math.abs(self.stats.scoreMax - scoreMax) > EPSILON ||
Math.abs(self.stats.scoreMin - scoreMin) > EPSILON
) {
self.stats = {
currStatsRegions,
currStatsBpPerPx,
scoreMin,
scoreMax,
Expand Down Expand Up @@ -518,7 +520,10 @@ export default function SharedWiggleMixin(
onClick: () => {
getSession(self).queueDialog(handleClose => [
SetMinMaxDialog,
{ model: self, handleClose },
{
model: self,
handleClose,
},
])
},
},
Expand Down

0 comments on commit 67cb847

Please sign in to comment.