Skip to content

Commit 0a2f3b5

Browse files
committed
Simplifying client code
1 parent df3ea38 commit 0a2f3b5

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

client/plots/dmr/DmrPlot.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { getCompInit, copyMerge, type RxComponent } from '#rx'
33
import { sayerror } from '#dom'
44
import { dofetch3 } from '#common/dofetch'
55
import { first_genetrack_tolist } from '#common/1stGenetk'
6-
import type { DmrConfig, DmrDom, DmrResult, BedItem } from './DmrTypes.ts'
6+
import type { TermdbDmrResponse } from '#types'
7+
import type { DmrConfig, DmrDom, BedItem } from './DmrTypes.ts'
78
import { getDefaultDMRSettings } from './settings/defaults.ts'
89

910
class DmrPlot extends PlotBase implements RxComponent {
@@ -41,7 +42,8 @@ class DmrPlot extends PlotBase implements RxComponent {
4142
this.dom.loading.style('display', 'block')
4243

4344
try {
44-
const { genome, dslabel, geneName, group1, group2, settings } = config
45+
const { geneName, group1, group2, settings } = config
46+
const { genome, dslabel } = this.app.vocabApi.vocab
4547

4648
// Resolve gene name to genomic coordinates
4749
const geneResult = await dofetch3('genelookup', {
@@ -55,12 +57,12 @@ class DmrPlot extends PlotBase implements RxComponent {
5557
const start = Math.max(0, gm.start - settings.dmr.pad)
5658
const stop = gm.stop + settings.dmr.pad
5759

58-
const dmrResult: DmrResult = await dofetch3('termdb/dmr', {
60+
const dmrResult: TermdbDmrResponse = await dofetch3('termdb/dmr', {
5961
body: { genome, dslabel, chr, start, stop, group1, group2 }
6062
})
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')
63+
if ('error' in dmrResult) {
64+
sayerror(this.dom.error, dmrResult.error)
65+
throw new Error(dmrResult.error)
6466
}
6567

6668
const genomeObj = this.app.opts.genome
@@ -70,7 +72,7 @@ class DmrPlot extends PlotBase implements RxComponent {
7072
tklst.push({
7173
type: 'bedj',
7274
name: 'DMRs',
73-
bedItems: (dmrResult.dmrs ?? []).map(dmr => {
75+
bedItems: dmrResult.dmrs.map(dmr => {
7476
const alpha = Math.round(Math.min(255, (0.5 + dmr.probability * 0.5) * 255))
7577
const hex = alpha.toString(16).padStart(2, '0')
7678
const base = dmr.direction === 'hyper' ? '#e66101' : '#5e81f4'
@@ -114,8 +116,6 @@ export function getPlotConfig(opts: Partial<DmrConfig>): DmrConfig {
114116
/** Runs in both getPlotConfig and main() because will only run in main()
115117
* when plot is loaded from a saved state (e.g. mass session file).*/
116118
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')
119119
if (!opts.geneName) throw new Error('geneName is required for DMR plot')
120120
if (!opts.group1) throw new Error('group1 is required for DMR plot')
121121
if (!opts.group2) throw new Error('group2 is required for DMR plot')

client/plots/dmr/DmrTypes.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export type DmrConfig = {
66
chartType: 'dmr'
77
id: string
88
headerText: string
9-
genome: string
10-
dslabel: string
119
geneName: string
1210
promoterId?: string
1311
group1: { sample: string }[]
@@ -22,19 +20,6 @@ export type DmrDom = {
2220
loading: Elem
2321
}
2422

25-
export type Dmr = {
26-
chr: string
27-
start: number
28-
stop: number
29-
direction: 'hyper' | 'hypo'
30-
probability: number
31-
}
32-
33-
export type DmrResult = {
34-
error?: string
35-
dmrs?: Dmr[]
36-
}
37-
3823
export type BedItem = {
3924
chr: string
4025
start: number

client/plots/volcano/interactions/VolcanoInteractions.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ export class VolcanoInteractions {
198198
config: {
199199
chartType: 'dmr',
200200
headerText: promoterId ? `DMR: ${geneName} (${promoterId})` : `DMR: ${geneName}`,
201-
genome: this.app.vocabApi.vocab.genome,
202-
dslabel: this.app.vocabApi.vocab.dslabel,
203201
geneName,
204202
promoterId,
205203
group1: config.samplelst.groups[0].values || [],

0 commit comments

Comments
 (0)