Files
cellxgene/src/components/categorical/createCategoryCounts.js
T
2017-08-23 16:28:01 -07:00

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;