From 8e08534d4295011da612a9cf18e44265c0d9fefd Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Thu, 11 Oct 2018 21:19:13 -0700 Subject: [PATCH] user defined gene --- client/src/actions/index.js | 21 +++++++- client/src/components/geneExpression/index.js | 2 +- client/src/reducers/controls.js | 48 +++++++++++++------ 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/client/src/actions/index.js b/client/src/actions/index.js index f4f548e7..90b79601 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -204,6 +204,24 @@ const requestGeneExpressionCountsPOST = genes => async (dispatch, getState) => { } }; +const requestUserDefinedGene = gene => async dispatch => { + dispatch({ type: "request user defined gene started" }); + try { + const data = await dispatch(requestGeneExpressionCountsPOST([gene])); + + /* then send the success case action through */ + return dispatch({ + type: "request user defined gene success", + data + }); + } catch (error) { + return dispatch({ + type: "request user defined gene error", + error + }); + } +}; + const requestDifferentialExpression = (set1, set2, num_genes = 10) => async ( dispatch, getState @@ -244,7 +262,7 @@ const requestDifferentialExpression = (set1, set2, num_genes = 10) => async ( Kick off secondary action to fetch all of the expression data for the topN expressed genes. */ - dispatch(requestGeneExpressionCountsPOST(topNGenes)); + await dispatch(requestGeneExpressionCountsPOST(topNGenes)); /* then send the success case action through */ return dispatch({ @@ -265,5 +283,6 @@ export default { requestSingleGeneExpressionCountsForColoringPOST, requestGeneExpressionCountsPOST, requestDifferentialExpression, + requestUserDefinedGene, doInitialDataLoad }; diff --git a/client/src/components/geneExpression/index.js b/client/src/components/geneExpression/index.js index 864c5f2a..becaae87 100644 --- a/client/src/components/geneExpression/index.js +++ b/client/src/components/geneExpression/index.js @@ -54,7 +54,7 @@ class GeneExpression extends React.Component { } else if (!_.find(world.varAnnotations, { name: gene })) { console.log("That doesn't appear to be a valid gene name."); } else { - dispatch(actions.requestGeneExpressionCountsPOST([gene])); + dispatch(actions.requestUserDefinedGene(gene)); dispatch({ type: "user defined gene", data: gene diff --git a/client/src/reducers/controls.js b/client/src/reducers/controls.js index ee512fb1..f4acb535 100644 --- a/client/src/reducers/controls.js +++ b/client/src/reducers/controls.js @@ -203,8 +203,7 @@ const Controls = ( }; } case "expression load success": { - console.log("expression load success", action); - const { world, universe, crossfilter, dimensionMap } = state; + const { world, universe } = state; let universeVarDataCache = universe.varDataCache; let worldVarDataCache = world.varDataCache; _.forEach(action.expressionData, (val, key) => { @@ -218,16 +217,6 @@ const Controls = ( } }); - _.forEach(action.expressionData, (val, key) => { - dimensionMap[key] = World.createVarDimension( - /* "__var__" + */ - world, - worldVarDataCache, - crossfilter, - key - ); - }); - return { ...state, universe: { @@ -240,17 +229,48 @@ const Controls = ( } }; } + case "request user defined gene success": { + const { world, crossfilter, dimensionMap, userDefinedGenes } = state; + const worldVarDataCache = world.varDataCache; + const _userDefinedGenes = userDefinedGenes.slice(); + const gene = action.data.genes[0]; + + dimensionMap[userDefinedDimensionName(gene)] = World.createVarDimension( + /* "__var__" + */ + world, + worldVarDataCache, + crossfilter, + gene + ); + + return { + ...state, + dimensionMap, + userDefinedGenes: _userDefinedGenes + }; + } case "request differential expression success": { - console.log("request diff success", action); - const { world } = state; + const { world, crossfilter, dimensionMap } = state; + const worldVarDataCache = world.varDataCache; const _diffexpGenes = []; action.data.forEach(d => { _diffexpGenes.push(world.varAnnotations[d[0]].name); }); + _.forEach(_diffexpGenes, gene => { + dimensionMap[diffexpDimensionName(gene)] = World.createVarDimension( + /* "__var__" + */ + world, + worldVarDataCache, + crossfilter, + gene + ); + }); + return { ...state, + dimensionMap, diffexpGenes: _diffexpGenes }; }