Skip to content

Commit 81010de

Browse files
committed
Removed cache file creation, NaiveGP model branch, improved client code based on feedback. Other cleanups
1 parent 8f59056 commit 81010de

File tree

9 files changed

+123
-738
lines changed

9 files changed

+123
-738
lines changed

client/plots/dmr/DmrPlot.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { sayerror } from '#dom'
44
import { dofetch3 } from '#common/dofetch'
55
import { first_genetrack_tolist } from '#common/1stGenetk'
66
import type { DmrConfig, DmrDom, DmrResult, BedItem } from './DmrTypes.ts'
7+
import { getDefaultDMRSettings } from './settings/defaults.ts'
78

89
class DmrPlot extends PlotBase implements RxComponent {
910
static type = 'dmr'
@@ -14,7 +15,7 @@ class DmrPlot extends PlotBase implements RxComponent {
1415
constructor(opts: any, api: any) {
1516
super(opts, api)
1617
this.dom = {
17-
header: opts.header,
18+
header: opts?.header,
1819
holder: opts.holder.append('div'),
1920
error: opts.holder.append('div'),
2021
loading: opts.holder.append('div').text('Running DMR analysis…')
@@ -33,16 +34,34 @@ class DmrPlot extends PlotBase implements RxComponent {
3334
const config = this.state.config as DmrConfig
3435
if (this.dom.header) this.dom.header.text(config.headerText || 'DMR Analysis')
3536

37+
validateConfig(config)
38+
3639
this.dom.holder.selectAll('*').remove()
3740
this.dom.error.selectAll('*').remove()
3841
this.dom.loading.style('display', 'block')
3942

4043
try {
41-
const { genome, dslabel, chr, start, stop, group1, group2 } = config
44+
const { genome, dslabel, geneName, group1, group2, settings } = config
45+
46+
// Resolve gene name to genomic coordinates
47+
const geneResult = await dofetch3('genelookup', {
48+
body: { deep: 1, input: geneName, genome }
49+
})
50+
if (geneResult.error || !geneResult.gmlst?.length) {
51+
throw new Error(`Could not find coordinates for gene "${geneName}"`)
52+
}
53+
const gm = geneResult.gmlst[0]
54+
const chr = gm.chr
55+
const start = Math.max(0, gm.start - settings.dmr.pad)
56+
const stop = gm.stop + settings.dmr.pad
57+
4258
const dmrResult: DmrResult = await dofetch3('termdb/dmr', {
4359
body: { genome, dslabel, chr, start, stop, group1, group2 }
4460
})
45-
if (dmrResult.error) throw new Error(dmrResult.error)
61+
if (!dmrResult || dmrResult.error) {
62+
sayerror(this.dom.error, dmrResult?.error || 'No result returned from server')
63+
throw new Error(dmrResult?.error || 'No result returned from server')
64+
}
4665

4766
const genomeObj = this.app.opts.genome
4867
const tklst: { type: string; name: string; bedItems?: BedItem[]; __isgene?: boolean }[] = []
@@ -68,7 +87,7 @@ class DmrPlot extends PlotBase implements RxComponent {
6887
stop,
6988
tklst,
7089
nobox: true,
71-
width: 800,
90+
width: settings.dmr.blockWidth,
7291
hidegenelegend: true
7392
})
7493
} catch (e: unknown) {
@@ -82,5 +101,22 @@ class DmrPlot extends PlotBase implements RxComponent {
82101
export const componentInit = getCompInit(DmrPlot)
83102

84103
export function getPlotConfig(opts: Partial<DmrConfig>): DmrConfig {
85-
return copyMerge({ chartType: 'dmr', headerText: 'DMR Analysis' }, opts)
104+
validateConfig(opts)
105+
106+
const config = {
107+
settings: {
108+
dmr: getDefaultDMRSettings(opts)
109+
}
110+
}
111+
return copyMerge(config, opts)
112+
}
113+
114+
/** Runs in both getPlotConfig and main() because will only run in main()
115+
* when plot is loaded from a saved state (e.g. mass session file).*/
116+
function validateConfig(opts) {
117+
if (!opts.genome) throw new Error('genome is required for DMR plot')
118+
if (!opts.dslabel) throw new Error('dslabel is required for DMR plot')
119+
if (!opts.geneName) throw new Error('geneName is required for DMR plot')
120+
if (!opts.group1) throw new Error('group1 is required for DMR plot')
121+
if (!opts.group2) throw new Error('group2 is required for DMR plot')
86122
}

client/plots/dmr/DmrTypes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Elem } from '../../types/d3'
2+
import type { DMRSettings } from './settings/Settings'
23

34
/** Config shape passed via plot_create from VolcanoInteractions */
45
export type DmrConfig = {
@@ -7,11 +8,11 @@ export type DmrConfig = {
78
headerText: string
89
genome: string
910
dslabel: string
10-
chr: string
11-
start: number
12-
stop: number
11+
geneName: string
12+
promoterId?: string
1313
group1: { sample: string }[]
1414
group2: { sample: string }[]
15+
settings: { dmr: DMRSettings }
1516
}
1617

1718
export type DmrDom = {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type DMRSettings = {
2+
/** Width argument for the block (default: 800) */
3+
blockWidth: number
4+
/** Base pairs to extend beyond the start and stop coordinates when querying for DMRs (default: 2000) */
5+
pad: number
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { DMRSettings } from './Settings.ts'
2+
3+
export function getDefaultDMRSettings(opts: any): DMRSettings {
4+
const overrides = opts.settings || {}
5+
const defaults = {
6+
blockWidth: 800,
7+
pad: 2000
8+
}
9+
10+
return Object.assign(defaults, overrides)
11+
}

client/plots/volcano/interactions/VolcanoInteractions.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { downloadTable, GeneSetEditUI, MultiTermWrapperEditUI } from '#dom'
33
import { to_svg } from '#src/client'
44
import type { VolcanoDom, VolcanoPlotConfig } from '../VolcanoTypes'
55
import { DNA_METHYLATION, GENE_EXPRESSION } from '#shared/terms.js'
6-
import { dofetch3 } from '#common/dofetch'
76

87
export class VolcanoInteractions {
98
app: MassAppApi
@@ -194,30 +193,15 @@ export class VolcanoInteractions {
194193
const config = this.app.getState().plots.find((p: VolcanoPlotConfig) => p.id === this.id)
195194
if (config.termType !== DNA_METHYLATION) return
196195

197-
const genome = this.app.vocabApi.vocab.genome
198-
const dslabel = this.app.vocabApi.vocab.dslabel
199-
200-
const geneResult = await dofetch3('genelookup', {
201-
body: { deep: 1, input: geneName, genome }
202-
})
203-
if (geneResult.error || !geneResult.gmlst?.length) {
204-
window.alert(`Could not find coordinates for gene "${geneName}"`)
205-
return
206-
}
207-
208-
const gm = geneResult.gmlst[0]
209-
const pad = 2000
210-
211196
this.app.dispatch({
212197
type: 'plot_create',
213198
config: {
214199
chartType: 'dmr',
215200
headerText: promoterId ? `DMR: ${geneName} (${promoterId})` : `DMR: ${geneName}`,
216-
genome,
217-
dslabel,
218-
chr: gm.chr,
219-
start: Math.max(0, gm.start - pad),
220-
stop: gm.stop + pad,
201+
genome: this.app.vocabApi.vocab.genome,
202+
dslabel: this.app.vocabApi.vocab.dslabel,
203+
geneName,
204+
promoterId,
221205
group1: config.samplelst.groups[0].values || [],
222206
group2: config.samplelst.groups[1].values || []
223207
}

python/src/gpdm/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Annotation,
99
DMR,
1010
GPDMResults,
11-
NaiveGP,
1211
DomainPartitionedGP,
1312
)
1413

@@ -18,6 +17,5 @@
1817
"Annotation",
1918
"DMR",
2019
"GPDMResults",
21-
"NaiveGP",
2220
"DomainPartitionedGP",
2321
]

0 commit comments

Comments
 (0)