mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-05 07:18:12 +08:00
Deduplicate merged gene list in subsetAndResetGeneLists (#1490)
Fixes https://github.com/chanzuckerberg/cellxgene/issues/1486
This commit is contained in:
@@ -4,11 +4,21 @@ test controls helpers
|
|||||||
import { subsetAndResetGeneLists } from "../../../src/util/stateManager/controlsHelpers";
|
import { subsetAndResetGeneLists } from "../../../src/util/stateManager/controlsHelpers";
|
||||||
import * as globals from "../../../src/globals";
|
import * as globals from "../../../src/globals";
|
||||||
|
|
||||||
|
|
||||||
describe("controls helpers", () => {
|
describe("controls helpers", () => {
|
||||||
test("subsetAndResetGeneLists", () => {
|
test("subsetAndResetGeneLists", () => {
|
||||||
const geneList = [...Array(150).keys()].map(
|
const geneList = [];
|
||||||
() => Math.random().toString(36).substring(2, 6) // random string of 4 characters
|
const genRandGene = () => Math.random().toString(36).substring(2, 6);
|
||||||
);
|
|
||||||
|
// build a unique set of genes
|
||||||
|
for (let i = 0; i < 150; i += 1) {
|
||||||
|
let randGene = genRandGene();
|
||||||
|
while (geneList.includes(randGene)) randGene = genRandGene();
|
||||||
|
geneList.push(randGene);
|
||||||
|
}
|
||||||
|
// insert duplicates
|
||||||
|
geneList[0] = "dupl";
|
||||||
|
geneList[20] = "dupl";
|
||||||
const state = {
|
const state = {
|
||||||
userDefinedGenes: geneList.slice(0, 20),
|
userDefinedGenes: geneList.slice(0, 20),
|
||||||
diffexpGenes: geneList.slice(20),
|
diffexpGenes: geneList.slice(20),
|
||||||
@@ -16,12 +26,14 @@ describe("controls helpers", () => {
|
|||||||
const [newUserDefinedGenes, newDiffExpGenes] = subsetAndResetGeneLists(
|
const [newUserDefinedGenes, newDiffExpGenes] = subsetAndResetGeneLists(
|
||||||
state
|
state
|
||||||
);
|
);
|
||||||
|
const expectedNewUserDefinedGenes = [
|
||||||
|
...geneList.slice(0, 20),
|
||||||
|
...geneList.slice(21)
|
||||||
|
].slice(0, globals.maxGenes);
|
||||||
expect(globals.maxUserDefinedGenes).toBeLessThan(globals.maxGenes);
|
expect(globals.maxUserDefinedGenes).toBeLessThan(globals.maxGenes);
|
||||||
expect(geneList.length).toBeGreaterThan(globals.maxGenes);
|
expect(geneList.length).toBeGreaterThan(globals.maxGenes);
|
||||||
expect(newUserDefinedGenes).toHaveLength(globals.maxGenes);
|
expect(newUserDefinedGenes).toHaveLength(globals.maxGenes);
|
||||||
expect(newUserDefinedGenes).toStrictEqual(
|
expect(newUserDefinedGenes).toStrictEqual(expectedNewUserDefinedGenes);
|
||||||
geneList.slice(0, globals.maxGenes)
|
|
||||||
);
|
|
||||||
expect(newDiffExpGenes).toStrictEqual([]);
|
expect(newDiffExpGenes).toStrictEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -203,8 +203,7 @@ export function pruneVarDataCache(varData, needed) {
|
|||||||
|
|
||||||
export function subsetAndResetGeneLists(state) {
|
export function subsetAndResetGeneLists(state) {
|
||||||
const { userDefinedGenes, diffexpGenes } = state;
|
const { userDefinedGenes, diffexpGenes } = state;
|
||||||
const newUserDefinedGenes = []
|
const newUserDefinedGenes = _.uniq([].concat(userDefinedGenes, diffexpGenes))
|
||||||
.concat(userDefinedGenes, diffexpGenes)
|
|
||||||
.slice(0, globals.maxGenes);
|
.slice(0, globals.maxGenes);
|
||||||
const newDiffExpGenes = [];
|
const newDiffExpGenes = [];
|
||||||
return [newUserDefinedGenes, newDiffExpGenes];
|
return [newUserDefinedGenes, newDiffExpGenes];
|
||||||
|
|||||||
Reference in New Issue
Block a user