@@ -3,7 +3,8 @@ import { getCompInit, copyMerge, type RxComponent } from '#rx'
33import { sayerror } from '#dom'
44import { dofetch3 } from '#common/dofetch'
55import { 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'
78import { getDefaultDMRSettings } from './settings/defaults.ts'
89
910class 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).*/
116118function 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' )
0 commit comments