Color by gene set mean expression (#2157)

* colorby histo

* color graph by mean expression

* move var index after returns

* add genesets as an argument

* varindex

* undo redo for mean expression

* destructure

* ternary

* Revert "destructure"

This reverts commit 2d9432c1c7.

* color by mean for diffexp
This commit is contained in:
Colin Megill
2021-04-22 13:58:30 -04:00
committed by GitHub
parent 860547ced1
commit fd2a7a53ab
10 changed files with 170 additions and 27 deletions
+46 -2
View File
@@ -12,8 +12,15 @@ import { range } from "../range";
given a color mode & accessor, generate an annoMatrix query that will
fulfill it
*/
export function createColorQuery(colorMode, colorByAccessor, schema) {
if (!colorMode || !colorByAccessor || !schema) return null;
export function createColorQuery(
colorMode,
colorByAccessor,
schema,
genesets,
diffExp
) {
if (!colorMode || !colorByAccessor || !schema || !genesets) return null;
switch (colorMode) {
case "color by categorical metadata":
case "color by continuous metadata": {
@@ -33,6 +40,38 @@ export function createColorQuery(colorMode, colorByAccessor, schema) {
},
];
}
case "color by geneset mean expression": {
const varIndex = schema?.annotations?.var?.index;
if (!varIndex) return null;
if (!genesets) return null;
let _geneset;
let _setGenes;
if (colorByAccessor === "Temp DiffExp Set") {
_geneset = diffExp;
_setGenes = _geneset.map((diffexpResultItem) => {
const geneName = diffexpResultItem[0];
return geneName;
});
} else {
_geneset = genesets.get(colorByAccessor);
_setGenes = [..._geneset.genes.keys()];
}
return [
"X",
{
summarize: {
method: "mean",
field: "var",
column: varIndex,
values: _setGenes,
},
},
];
}
default: {
return null;
}
@@ -86,6 +125,11 @@ function _createColorTable(
const { min, max } = col.summarize();
return createColorsByContinuousMetadata(col.asArray(), min, max);
}
case "color by geneset mean expression": {
const col = colorByData.icol(0);
const { min, max } = col.summarize();
return createColorsByContinuousMetadata(col.asArray(), min, max);
}
default: {
return defaultColors(schema.dataframe.nObs);
}