mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-03 22:18:12 +08:00
namespacing
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
|
||||
The original motivation for this file is name collision. It's possible
|
||||
to have two of the same gene, user defined and diffexpressed, on the client
|
||||
simultaneously, looking at the same data in the cache but with two
|
||||
dimensions and two crossfilters. It's also possible that someone could
|
||||
have a obsAnnotation named X, but we are using that for layout. So
|
||||
we namespace, and abstract to avoid proliferating strings throughout the
|
||||
codebase.
|
||||
|
||||
*/
|
||||
|
||||
const makeDimensionName = (namespace, key) => `${namespace}_${key}`;
|
||||
|
||||
export const layoutDimensionName = key => makeDimensionName("layout", key);
|
||||
export const obsAnnoDimensionName = key => makeDimensionName("obsAnno", key);
|
||||
export const diffexpDimensionName = key =>
|
||||
makeDimensionName("varData_diffexp", key);
|
||||
export const userDefinedDimensionName = key =>
|
||||
makeDimensionName("varData_userDefined", key);
|
||||
|
||||
/*
|
||||
continuousNamespace = {
|
||||
isObs: true,
|
||||
isDiffExp: false,
|
||||
isUserDefined: false
|
||||
}
|
||||
|
||||
ie., makeContinuousDimensionName(continuousNamespace = {isObs: true}, "total_reads")
|
||||
see: histogram brush, as it doesn't know what type of continuous it was with only field
|
||||
*/
|
||||
export const makeContinuousDimensionName = (continuousNamespace, key) => {
|
||||
let name;
|
||||
if (continuousNamespace.isObs) {
|
||||
name = obsAnnoDimensionName(key);
|
||||
} else if (continuousNamespace.isDiffExp) {
|
||||
name = diffexpDimensionName(key);
|
||||
} else if (continuousNamespace.isUserDefined) {
|
||||
name = userDefinedDimensionName(key);
|
||||
}
|
||||
|
||||
return name;
|
||||
};
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import _ from "lodash";
|
||||
import * as kvCache from "./keyvalcache";
|
||||
import { layoutDimensionName, obsAnnoDimensionName } from "../nameCreators";
|
||||
|
||||
/*
|
||||
World is a subset of universe. Most code should use world, and should
|
||||
@@ -296,13 +297,14 @@ export function createVarDimension(
|
||||
crossfilter,
|
||||
geneName
|
||||
) {
|
||||
const { varDataCache, worldObsIndex } = world;
|
||||
const { worldObsIndex } = world;
|
||||
const varData = _worldVarDataCache[geneName];
|
||||
const worldIndex = worldObsIndex ? idx => worldObsIndex[idx] : idx => idx;
|
||||
|
||||
return crossfilter.dimension(r => {
|
||||
return varData[worldIndex(r.__index__)];
|
||||
}, Float32Array);
|
||||
return crossfilter.dimension(
|
||||
r => varData[worldIndex(r.__index__)],
|
||||
Float32Array
|
||||
);
|
||||
}
|
||||
|
||||
export function createObsDimensionMap(crossfilter, world) {
|
||||
@@ -317,7 +319,10 @@ export function createObsDimensionMap(crossfilter, world) {
|
||||
(result, anno) => {
|
||||
const dimType = deduceDimensionType(anno, anno.name);
|
||||
if (dimType) {
|
||||
result[anno.name] = crossfilter.dimension(r => r[anno.name], dimType);
|
||||
result[obsAnnoDimensionName(anno.name)] = crossfilter.dimension(
|
||||
r => r[anno.name],
|
||||
dimType
|
||||
);
|
||||
} // else ignore the annotation
|
||||
},
|
||||
{}
|
||||
@@ -327,11 +332,11 @@ export function createObsDimensionMap(crossfilter, world) {
|
||||
Add crossfilter dimensions allowing filtering on layout
|
||||
*/
|
||||
const worldIndex = worldObsIndex ? idx => worldObsIndex[idx] : idx => idx;
|
||||
dimensionMap.x = crossfilter.dimension(
|
||||
dimensionMap[layoutDimensionName("X")] = crossfilter.dimension(
|
||||
r => obsLayout.X[worldIndex(r.__index__)],
|
||||
Float32Array
|
||||
);
|
||||
dimensionMap.y = crossfilter.dimension(
|
||||
dimensionMap[layoutDimensionName("Y")] = crossfilter.dimension(
|
||||
r => obsLayout.Y[worldIndex(r.__index__)],
|
||||
Float32Array
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user