mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-24 06:58:12 +08:00
46 lines
839 B
JavaScript
46 lines
839 B
JavaScript
import * as globals from "../../globals.js"
|
|
|
|
/*
|
|
end result:
|
|
|
|
counts: {
|
|
Sample.type: {
|
|
glioblastoma: 3452
|
|
},
|
|
Selection: {
|
|
foo: 234,
|
|
bar: 21
|
|
}
|
|
}
|
|
|
|
*/
|
|
|
|
const categories = globals.categories;
|
|
|
|
const createCategoryCounts = (cells) => {
|
|
|
|
/* instantiate counts obj */
|
|
const counts = {};
|
|
|
|
categories.forEach((category) => {
|
|
counts[category] = {};
|
|
})
|
|
|
|
cells.forEach((cell) => {
|
|
categories.forEach((category) => {
|
|
|
|
/* if, for the given category (ie., categories.Location), we do not have ie., glioblastoma already, create it. Otherwise increment it. */
|
|
if (!counts[category][cell[category]]) {
|
|
counts[category][cell[category]] = 1;
|
|
} else {
|
|
counts[category][cell[category]]++
|
|
}
|
|
|
|
})
|
|
});
|
|
|
|
return counts;
|
|
}
|
|
|
|
export default createCategoryCounts;
|