Skip to content

Commit

Permalink
bug fix to return Map but not Set on empty filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhou82 committed Feb 20, 2025
1 parent 88da674 commit 2e93e35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion server/routes/termdb.cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ async function validateNative(q: GeneExpressionQueryNative, ds: any, genome: any
const limitSamples = await mayLimitSamples(param, q.samples, ds)
if (limitSamples?.size == 0) {
// got 0 sample after filtering, must still return expected structure with no data
return { term2sample2value: new Set(), byTermId: {}, bySampleId: {} }
return { term2sample2value: new Map(), byTermId: {}, bySampleId: {} }
}

// has at least 1 sample passing filter and with exp data
Expand Down
27 changes: 13 additions & 14 deletions server/src/termdb.matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,20 @@ async function getSampleData(q, ds, onlyChildren = false) {
filter0: q.filter0
}
const data = await q.ds.queries[tw.term.type].get(args)
if (data.term2sample2value.size > 0)
for (const sampleId in data.term2sample2value.get(tw.term.name)) {
if (!(sampleId in samples)) {
samples[sampleId] = { sample: sampleId }
}
const values = data.term2sample2value.get(tw.term.name)
const value = Number(values[sampleId])
let key = value
if (lstOfBins) {
// term is in binning mode. key should be changed into the label of the bin to which value belongs
const bin = getBin(lstOfBins, value)
key = get_bin_label(lstOfBins[bin], tw.q)
}
samples[sampleId][tw.$id] = { key, value }
for (const sampleId in data.term2sample2value.get(tw.term.name)) {
if (!(sampleId in samples)) {
samples[sampleId] = { sample: sampleId }
}
const values = data.term2sample2value.get(tw.term.name)
const value = Number(values[sampleId])
let key = value
if (lstOfBins) {
// term is in binning mode. key should be changed into the label of the bin to which value belongs
const bin = getBin(lstOfBins, value)
key = get_bin_label(lstOfBins[bin], tw.q)
}
samples[sampleId][tw.$id] = { key, value }
}
} else if (tw.term.type == TermTypes.SINGLECELL_GENE_EXPRESSION) {
if (!q.ds.queries?.singleCell?.geneExpression) throw 'not supported by dataset: singleCell.geneExpression'
let lst // list of bins based on tw config
Expand Down

0 comments on commit 2e93e35

Please sign in to comment.