Deduplicate merged gene list in subsetAndResetGeneLists (#1490)

Fixes https://github.com/chanzuckerberg/cellxgene/issues/1486
This commit is contained in:
Matt Weiden
2020-05-20 15:35:27 -07:00
committed by GitHub
parent efdae22fbe
commit 8d762e59ca
2 changed files with 19 additions and 8 deletions

View File

@@ -4,11 +4,21 @@ test controls helpers
import { subsetAndResetGeneLists } from "../../../src/util/stateManager/controlsHelpers";
import * as globals from "../../../src/globals";
describe("controls helpers", () => {
test("subsetAndResetGeneLists", () => {
const geneList = [...Array(150).keys()].map(
() => Math.random().toString(36).substring(2, 6) // random string of 4 characters
);
const geneList = [];
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 = {
userDefinedGenes: geneList.slice(0, 20),
diffexpGenes: geneList.slice(20),
@@ -16,12 +26,14 @@ describe("controls helpers", () => {
const [newUserDefinedGenes, newDiffExpGenes] = subsetAndResetGeneLists(
state
);
const expectedNewUserDefinedGenes = [
...geneList.slice(0, 20),
...geneList.slice(21)
].slice(0, globals.maxGenes);
expect(globals.maxUserDefinedGenes).toBeLessThan(globals.maxGenes);
expect(geneList.length).toBeGreaterThan(globals.maxGenes);
expect(newUserDefinedGenes).toHaveLength(globals.maxGenes);
expect(newUserDefinedGenes).toStrictEqual(
geneList.slice(0, globals.maxGenes)
);
expect(newUserDefinedGenes).toStrictEqual(expectedNewUserDefinedGenes);
expect(newDiffExpGenes).toStrictEqual([]);
});
});

View File

@@ -203,8 +203,7 @@ export function pruneVarDataCache(varData, needed) {
export function subsetAndResetGeneLists(state) {
const { userDefinedGenes, diffexpGenes } = state;
const newUserDefinedGenes = []
.concat(userDefinedGenes, diffexpGenes)
const newUserDefinedGenes = _.uniq([].concat(userDefinedGenes, diffexpGenes))
.slice(0, globals.maxGenes);
const newDiffExpGenes = [];
return [newUserDefinedGenes, newDiffExpGenes];