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

Allow adding pre built numberic dicterm cluster #2580

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
36 changes: 1 addition & 35 deletions client/mass/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,41 +290,7 @@ function getChartTypeList(self, state) {
//use the app name defined in dataset file
label: state.termdbConfig.numericDictTermCluster?.appName || 'Numeric Dictionary Term cluster',
chartType: 'numericDictTermCluster',
clickTo: self.showTree_selectlst,
usecase: {
target: 'numericDictTermCluster',
detail: { exclude: state.termdbConfig.numericDictTermCluster?.exclude }
},
updateActionBySelectedTerms: (action, termlst) => {
const twlst = termlst.map(term => ({
term: structuredClone(term),
q: { mode: NumericModes.continuous }
}))
if (twlst.length == 1) {
// violin
action.config.chartType = 'summary'
action.config.term = twlst[0]
return
}
if (twlst.length == 2) {
// scatter
action.config.chartType = 'summary'
action.config.term = twlst[0]
action.config.term2 = twlst[1]
return
}
// 3 or more terms, launch clustering
action.config.chartType = 'hierCluster'
action.config.dataType = 'numericDictTerm'
action.config.termgroups = [
{
name:
state.termdbConfig.numericDictTermCluster?.settings?.termGroupName || 'Numercic Dictionary Term Cluster',
lst: twlst,
type: 'hierCluster'
}
]
}
clickTo: self.loadChartSpecificMenu
}
]

Expand Down
76 changes: 76 additions & 0 deletions client/plots/numericDictTermCluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { NumericModes } from '#shared/terms.js'

export function makeChartBtnMenu(holder, chartsInstance) {
/*
holder: the holder in the tooltip
chartsInstance: MassCharts instance
termdbConfig is accessible at chartsInstance.state.termdbConfig{}
mass option is accessible at chartsInstance.app.opts{}
*/
chartsInstance.dom.tip.clear()
const menuDiv = holder.append('div')
if (chartsInstance.state.termdbConfig.numericDictTermClusterPlots) {
for (const plot of chartsInstance.state.termdbConfig.numericDictTermClusterPlots) {
/* plot:
{
name=str
}
*/
menuDiv
.append('div')
.attr('class', 'sja_menuoption sja_sharp_border')
.text(plot.name)
.on('click', async () => {
chartsInstance.dom.tip.hide()
const config = await chartsInstance.app.vocabApi.getNumericDictTermClusterByName(plot.name)
chartsInstance.app.dispatch({
type: 'plot_create',
config
})
})
}
}

const chart = {
//use the app name defined in dataset file
label: chartsInstance.state.termdbConfig.numericDictTermCluster?.appName || 'Numeric Dictionary Term cluster',
chartType: 'numericDictTermCluster',
clickTo: self.showTree_selectlst,
usecase: {
target: 'numericDictTermCluster',
detail: { exclude: chartsInstance.state.termdbConfig.numericDictTermCluster?.exclude }
},
updateActionBySelectedTerms: (action, termlst) => {
const twlst = termlst.map(term => ({
term: structuredClone(term),
q: { mode: NumericModes.continuous }
}))
if (twlst.length == 1) {
// violin
action.config.chartType = 'summary'
action.config.term = twlst[0]
return
}
if (twlst.length == 2) {
// scatter
action.config.chartType = 'summary'
action.config.term = twlst[0]
action.config.term2 = twlst[1]
return
}
// 3 or more terms, launch clustering
action.config.chartType = 'hierCluster'
action.config.dataType = 'numericDictTerm'
action.config.termgroups = [
{
name:
chartsInstance.state.termdbConfig.numericDictTermCluster?.settings?.termGroupName ||
'Numercic Dictionary Term Cluster',
lst: twlst,
type: 'hierCluster'
}
]
}
}
chartsInstance.showTree_selectlst(chart)
}
12 changes: 12 additions & 0 deletions client/termdb/TermdbVocab.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,18 @@ export class TermdbVocab extends Vocab {
})
}

async getNumericDictTermClusterByName(name) {
// find a pre-built numericDictTermCluster by name from this dataset
return await dofetch3('termdb', {
body: {
for: 'numericDictTermCluster',
getPlotDataByName: name,
genome: this.state.vocab.genome,
dslabel: this.state.vocab.dslabel
}
})
}

// following two methods are hardcoded at /gdc/*. TODO change to generic method to work for all datasets
async getTopMutatedGenes(arg) {
return await dofetch3('gdc/topMutatedGenes', { method: 'GET', body: arg })
Expand Down
3 changes: 2 additions & 1 deletion release.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Features:
- numericDictTermCluster: allows adding pre-built numericDictTermCluster plots
9 changes: 9 additions & 0 deletions server/routes/termdb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function make(q, res, ds: Mds3WithCohort, genome) {
addRestrictAncestries(c, tdb)
addScatterplots(c, ds)
addMatrixplots(c, ds)
addNumericDictTermClusterPlots(c, ds)
addNonDictionaryQueries(c, ds, genome)

res.send({ termdbConfig: c })
Expand Down Expand Up @@ -157,6 +158,14 @@ function addMatrixplots(c, ds) {
})
}

function addNumericDictTermClusterPlots(c, ds) {
if (!ds.cohort.numericDictTermClusterPlots) return
// this dataset has premade numericDictTermClusterPlots. reveal numericDictTermCluster plot names to client
c.numericDictTermClusterPlots = ds.cohort.numericDictTermClusterPlots.plots.map(p => {
return { name: p.name }
})
}

/* ds.queries{} contains query methods for non-dictionary data types
including genomic, molecular, imaging etc
*/
Expand Down
4 changes: 3 additions & 1 deletion server/src/mds3.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { get_samples, get_active_groupset } from './termdb.sql.js'
import { server_init_db_queries } from './termdb.server.init.ts'
import { barchart_data } from './termdb.barchart.js'
import { mayInitiateScatterplots } from './termdb.scatter.js'
import { mayInitiateMatrixplots } from './termdb.matrix.js'
import { mayInitiateMatrixplots, mayInitiateNumericDictionaryTermplots } from './termdb.matrix.js'
import { add_bcf_variant_filter } from './termdb.snp.js'
import { validate_query_NIdata } from '#routes/brainImagingSamples.ts'
import { validate_query_singleCell } from '#routes/termdb.singlecellSamples.ts'
Expand Down Expand Up @@ -301,6 +301,8 @@ export async function validate_termdb(ds) {

await mayInitiateMatrixplots(ds)

await mayInitiateNumericDictionaryTermplots(ds)

if ('minTimeSinceDx' in tdb) {
if (!Number.isFinite(tdb.minTimeSinceDx)) throw 'termdb.minTimeSinceDx not number'
if (tdb.minTimeSinceDx <= 0) throw 'termdb.minTimeSinceDx<=0'
Expand Down
13 changes: 13 additions & 0 deletions server/src/termdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function handle_request_closure(genomes) {
if (q.for == 'mds3queryDetails') return get_mds3queryDetails(res, ds)
if (q.for == 'termTypes') return res.send(await ds.getTermTypes(q))
if (q.for == 'matrix') return await get_matrix(q, req, res, ds, genome)
if (q.for == 'numericDictTermCluster') return await get_numericDictTermCluster(q, req, res, ds, genome)
if (q.for == 'getSamplesPerFilter') return await getSamplesPerFilter(q, ds, res)
if (q.for == 'mds3variantData') return await get_mds3variantData(q, res, ds, genome)
if (q.for == 'validateToken') {
Expand Down Expand Up @@ -328,6 +329,18 @@ async function get_matrix(q, req, res, ds, genome) {
res.send(data)
}

async function get_numericDictTermCluster(q, req, res, ds, genome) {
if (q.getPlotDataByName) {
// send back the config for premade numericDictTermCluster plot
if (!ds.cohort?.numericDictTermClusterPlots?.plots)
throw 'ds.cohort.get_numericDictTermClusterPlots.plots missing for the dataset'
const plot = ds.cohort.numericDictTermClusterPlots.plots.find(p => p.name === q.getPlotDataByName)
if (!plot) throw 'invalid name of premade numericDictTermCluster plot' // invalid name could be attack string, avoid returning it so it won't be printed in html
res.send(plot.numericDictTermClusterConfig)
return
}
}

async function get_ProfileFacilities(q, req, res, ds, tdb) {
const canDisplay = authApi.canDisplaySampleIds(req, ds)
let result = []
Expand Down
20 changes: 20 additions & 0 deletions server/src/termdb.matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,26 @@ export async function mayInitiateMatrixplots(ds) {
}
}

/*
works with "canned" NumericDictionaryTerm plot in a dataset, e.g. data from a text file
called in mds3.init
*/
export async function mayInitiateNumericDictionaryTermplots(ds) {
if (!ds.cohort.numericDictTermClusterPlots) return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please define type def for ds.cohort.numericDictTermClusterPlots

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks just added

if (!Array.isArray(ds.cohort.numericDictTermClusterPlots.plots))
throw 'cohort.numericDictTermClusterPlots.plots is not array'
for (const p of ds.cohort.numericDictTermClusterPlots.plots) {
if (!p.name) throw '.name missing from one of numericDictTermClusterPlots.plots[]'
if (p.file) {
const numericDictTermClusterConfig = await read_file(path.join(serverconfig.tpmasterdir, p.file))
p.numericDictTermClusterConfig = JSON.parse(numericDictTermClusterConfig)
if (p.getConfig) p.numericDictTermClusterConfig = p.getConfig(p.numericDictTermClusterConfig)
} else {
throw 'unknown data source of one of numericDictTermClusterConfig.plots[]'
}
}
}

async function findListOfBins(q, tw, ds) {
// for non-dict terms which may lack tw.term.bins
if (tw.q.type == 'custom-bin') {
Expand Down
14 changes: 14 additions & 0 deletions shared/types/src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,23 @@ type MatrixPlotsEntry = {
getConfig?: (f: any) => void
}

type NumericDictTermClusterPlotsEntry = {
name: string
file: string
settings?: {
[key: string]: any
}
getConfig?: (f: any) => void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's purpose of getConfig()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just added comment

}

type MatrixPlots = {
plots: MatrixPlotsEntry[]
}

type NumericDictTermClusterPlots = {
plots: NumericDictTermClusterPlotsEntry[]
}

type AllowCaseDetails = {
sample_id_key: string
terms: string[]
Expand Down Expand Up @@ -1271,6 +1284,7 @@ export type Cohort = {
defaultChartType?: string
massNav?: MassNav
matrixplots?: MatrixPlots
numericDictTermClusterPlots?: NumericDictTermClusterPlots
mutationset?: MutationSet[]
renamedChartTypes?: { singleCellPlot?: string; sampleScatter?: string }
scatterplots?: Scatterplots
Expand Down
Loading