mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 16:58:13 +08:00
@@ -5,7 +5,6 @@ import Async from "react-async";
|
|||||||
import memoize from "memoize-one";
|
import memoize from "memoize-one";
|
||||||
import * as globals from "../../globals";
|
import * as globals from "../../globals";
|
||||||
import actions from "../../actions";
|
import actions from "../../actions";
|
||||||
import { histogramContinuous } from "../../util/dataframe/histogram";
|
|
||||||
import { makeContinuousDimensionName } from "../../util/nameCreators";
|
import { makeContinuousDimensionName } from "../../util/nameCreators";
|
||||||
import HistogramHeader from "./header";
|
import HistogramHeader from "./header";
|
||||||
import Histogram from "./histogram";
|
import Histogram from "./histogram";
|
||||||
@@ -285,10 +284,11 @@ class HistogramBrush extends React.PureComponent {
|
|||||||
.domain([domainMin, domainMax])
|
.domain([domainMin, domainMax])
|
||||||
.range([leftMargin, leftMargin + newWidth]);
|
.range([leftMargin, leftMargin + newWidth]);
|
||||||
|
|
||||||
histogramCache.bins = histogramContinuous(col, numBins, [
|
histogramCache.bins = col.histogram(numBins, [
|
||||||
domainMin,
|
domainMin,
|
||||||
domainMax,
|
domainMax,
|
||||||
]); /* memoized */
|
]); /* memoized */
|
||||||
|
|
||||||
histogramCache.binWidth = (domainMax - domainMin) / numBins;
|
histogramCache.binWidth = (domainMax - domainMin) / numBins;
|
||||||
|
|
||||||
histogramCache.binStart = (i) => domainMin + i * histogramCache.binWidth;
|
histogramCache.binStart = (i) => domainMin + i * histogramCache.binWidth;
|
||||||
@@ -306,7 +306,13 @@ class HistogramBrush extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createQuery() {
|
createQuery() {
|
||||||
const { isObs, isGeneSetSummary, field, setGenes, annoMatrix } = this.props;
|
const {
|
||||||
|
isObs,
|
||||||
|
isGeneSetSummary,
|
||||||
|
field,
|
||||||
|
setGenes,
|
||||||
|
annoMatrix,
|
||||||
|
} = this.props;
|
||||||
const { schema } = annoMatrix;
|
const { schema } = annoMatrix;
|
||||||
if (isObs) {
|
if (isObs) {
|
||||||
return ["obs", field];
|
return ["obs", field];
|
||||||
@@ -322,7 +328,7 @@ class HistogramBrush extends React.PureComponent {
|
|||||||
method: "mean",
|
method: "mean",
|
||||||
field: "var",
|
field: "var",
|
||||||
column: varIndex,
|
column: varIndex,
|
||||||
values: setGenes,
|
values: [...setGenes.keys()],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { FaChevronRight, FaChevronDown } from "react-icons/fa";
|
import { FaChevronRight, FaChevronDown } from "react-icons/fa";
|
||||||
import actions from "../../actions";
|
|
||||||
import Gene from "./gene";
|
import Gene from "./gene";
|
||||||
import { memoize } from "../../util/dataframe/util";
|
|
||||||
import Truncate from "../util/truncate";
|
import Truncate from "../util/truncate";
|
||||||
import * as globals from "../../globals";
|
import * as globals from "../../globals";
|
||||||
import GenesetMenus from "./menus/genesetMenus";
|
import GenesetMenus from "./menus/genesetMenus";
|
||||||
@@ -12,17 +9,7 @@ import HistogramBrush from "../brushableHistogram";
|
|||||||
|
|
||||||
import { diffexpPopNamePrefix1, diffexpPopNamePrefix2 } from "../../globals";
|
import { diffexpPopNamePrefix1, diffexpPopNamePrefix2 } from "../../globals";
|
||||||
|
|
||||||
@connect((state, ownProps) => {
|
|
||||||
return {
|
|
||||||
world: state.world,
|
|
||||||
userDefinedGenes: state.controls.userDefinedGenes,
|
|
||||||
userDefinedGenesLoading: state.controls.userDefinedGenesLoading,
|
|
||||||
isColorAccessor: state.colors.colorAccessor === ownProps.setName,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
class GeneSet extends React.Component {
|
class GeneSet extends React.Component {
|
||||||
_memoGenesToUpper = memoize(this._genesToUpper, (arr) => arr);
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -30,64 +17,18 @@ class GeneSet extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_genesToUpper = (listGenes) => {
|
|
||||||
// Has to be a Map to preserve index
|
|
||||||
const upperGenes = new Map();
|
|
||||||
for (let i = 0, { length } = listGenes; i < length; i += 1) {
|
|
||||||
upperGenes.set(listGenes[i].toUpperCase(), i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return upperGenes;
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchGenes = () => {
|
|
||||||
const { world, dispatch, setGenes } = this.props;
|
|
||||||
const varIndexName = world.schema.annotations.var.index;
|
|
||||||
|
|
||||||
const worldGenes = world.varAnnotations.col(varIndexName).asArray();
|
|
||||||
|
|
||||||
const upperGenes = this._genesToUpper(setGenes);
|
|
||||||
const upperWorldGenes = this._memoGenesToUpper(worldGenes);
|
|
||||||
|
|
||||||
dispatch({ type: "bulk user defined gene start" });
|
|
||||||
|
|
||||||
Promise.all(
|
|
||||||
[...upperGenes.keys()].map((upperGene) => {
|
|
||||||
const indexOfGene = upperWorldGenes.get(upperGene);
|
|
||||||
|
|
||||||
return dispatch(
|
|
||||||
actions.requestUserDefinedGene(worldGenes[indexOfGene])
|
|
||||||
);
|
|
||||||
})
|
|
||||||
).then(
|
|
||||||
() => dispatch({ type: "bulk user defined gene complete" }),
|
|
||||||
() => dispatch({ type: "bulk user defined gene error" })
|
|
||||||
);
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
onGenesetMenuClick = () => {
|
onGenesetMenuClick = () => {
|
||||||
const { isOpen } = this.state;
|
const { isOpen } = this.state;
|
||||||
this.setState({ isOpen: !isOpen });
|
this.setState({ isOpen: !isOpen });
|
||||||
};
|
};
|
||||||
|
|
||||||
onColorChangeClick = () => {
|
|
||||||
// const { dispatch, setName } = this.props;
|
|
||||||
// dispatch({
|
|
||||||
// type: "color by gene set",
|
|
||||||
// colorAccessor: setName,
|
|
||||||
// });
|
|
||||||
};
|
|
||||||
|
|
||||||
renderGenes() {
|
renderGenes() {
|
||||||
const { setName, setGenes, setGenesWithDescriptions } = this.props;
|
const { setName, setGenes } = this.props;
|
||||||
|
const setGenesNames = [...setGenes.keys()];
|
||||||
return (
|
return (
|
||||||
<div data-testclass="gene-set-genes">
|
<div data-testclass="gene-set-genes">
|
||||||
{setGenes.map((gene) => {
|
{setGenesNames.map((gene) => {
|
||||||
const { geneDescription } = setGenesWithDescriptions.get(gene);
|
const { geneDescription } = setGenes.get(gene);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Gene
|
<Gene
|
||||||
key={gene}
|
key={gene}
|
||||||
@@ -102,10 +43,10 @@ class GeneSet extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { setName, setGenes, genesetDescription } = this.props;
|
const { setName, genesetDescription, setGenes } = this.props;
|
||||||
const { isOpen } = this.state;
|
const { isOpen } = this.state;
|
||||||
const genesetNameLengthVisible = 150; /* this magic number determines how much of a long geneset name we see */
|
const genesetNameLengthVisible = 150; /* this magic number determines how much of a long geneset name we see */
|
||||||
const genesetIsEmpty = setGenes.length === 0;
|
const genesetIsEmpty = setGenes.size === 0;
|
||||||
let testClass = "geneset-expand";
|
let testClass = "geneset-expand";
|
||||||
|
|
||||||
if (setName.includes(diffexpPopNamePrefix1))
|
if (setName.includes(diffexpPopNamePrefix1))
|
||||||
@@ -174,7 +115,7 @@ class GeneSet extends React.Component {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{isOpen && !genesetIsEmpty && setGenes.length > 0 && (
|
{isOpen && !genesetIsEmpty && (
|
||||||
<HistogramBrush
|
<HistogramBrush
|
||||||
isGeneSetSummary
|
isGeneSetSummary
|
||||||
field={setName}
|
field={setName}
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ class GeneExpression extends React.Component {
|
|||||||
sets.push(
|
sets.push(
|
||||||
<GeneSet
|
<GeneSet
|
||||||
key={name}
|
key={name}
|
||||||
setGenes={Array.from(geneset.genes.keys())}
|
setGenes={geneset.genes}
|
||||||
setGenesWithDescriptions={geneset.genes}
|
|
||||||
setName={name}
|
setName={name}
|
||||||
genesetDescription={geneset.genesetDescription}
|
genesetDescription={geneset.genesetDescription}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user