From a296398ccefa52ff698382ecec077bdd0c2e3747 Mon Sep 17 00:00:00 2001 From: Jayaram Kancherla Date: Wed, 24 Apr 2024 08:04:31 -0700 Subject: [PATCH] Choose `counts` as the default assay if available for new analysis (#259) --- src/components/NewAnalysis/H5ADCard.js | 7 ++- src/components/NewAnalysis/RDSSECard.js | 55 +++++++++++++-------- src/components/NewAnalysis/TenxHDF5Card.js | 4 ++ src/components/NewAnalysis/ZippedADBCard.js | 55 ++++++++++++--------- src/components/NewAnalysis/utils.js | 11 +++++ 5 files changed, 87 insertions(+), 45 deletions(-) diff --git a/src/components/NewAnalysis/H5ADCard.js b/src/components/NewAnalysis/H5ADCard.js index 04bfc3f8..7a5e5f45 100644 --- a/src/components/NewAnalysis/H5ADCard.js +++ b/src/components/NewAnalysis/H5ADCard.js @@ -16,7 +16,7 @@ import { import "./index.css"; import { MODALITIES } from "../../utils/utils"; -import { getDefaultFeature } from "./utils"; +import { getDefaultFeature, getDefaultAssayName } from "./utils"; export function H5AD({ resource, @@ -50,7 +50,10 @@ export function H5AD({ preflight.all_features ); - tmpOptions["countMatrixName"] = preflight.all_assay_names[0]; + // Default assignment to + tmpOptions["countMatrixName"] = getDefaultAssayName( + preflight.all_assay_names + ); setOptions(tmpOptions); setInit2(false); diff --git a/src/components/NewAnalysis/RDSSECard.js b/src/components/NewAnalysis/RDSSECard.js index fb63aa91..76a38ccd 100644 --- a/src/components/NewAnalysis/RDSSECard.js +++ b/src/components/NewAnalysis/RDSSECard.js @@ -17,7 +17,11 @@ import "./index.css"; import { MODALITIES } from "../../utils/utils"; -import { getDefaultFeature, reportFeatureTypes } from "./utils"; +import { + getDefaultFeature, + reportFeatureTypes, + getDefaultAssayName, +} from "./utils"; export function RDSSE({ resource, @@ -66,8 +70,9 @@ export function RDSSE({ options["adtExperiment"] !== null && options["adtExperiment"] !== undefined ) { - tmpOptions["adtCountAssay"] = - preflight.modality_assay_names[options?.["adtExperiment"]][0]; + tmpOptions["adtCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[options?.["adtExperiment"]] + ); tmpOptions["primaryAdtFeatureIdColumn"] = getDefaultFeature( preflight.modality_features[options?.["adtExperiment"]] @@ -88,8 +93,9 @@ export function RDSSE({ options["crisprExperiment"] !== null && options["crisprExperiment"] !== undefined ) { - tmpOptions["crisprCountAssay"] = - preflight.modality_assay_names[options?.["crisprExperiment"]][0]; + tmpOptions["crisprCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[options?.["crisprExperiment"]] + ); tmpOptions["primaryCrisprFeatureIdColumn"] = getDefaultFeature( preflight.modality_features[options?.["crisprExperiment"]] @@ -110,8 +116,9 @@ export function RDSSE({ options["rnaExperiment"] !== null && options["rnaExperiment"] !== undefined ) { - tmpOptions["rnaCountAssay"] = - preflight.modality_assay_names[options?.["rnaExperiment"]][0]; + tmpOptions["rnaCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[options?.["rnaExperiment"]] + ); tmpOptions["primaryRnaFeatureIdColumn"] = getDefaultFeature( preflight.modality_features[options?.["rnaExperiment"]] @@ -141,6 +148,10 @@ export function RDSSE({ return `${mod.toLowerCase()}Experiment`; }; + const getAssayNameKey = (mod) => { + return `${mod.toLowerCase()}CountAssay`; + }; + const resetModality = (mod, val) => { let tmpOptions = { ...options }; @@ -164,7 +175,9 @@ export function RDSSE({ for (const [k, v] of Object.entries(preflight.modality_features)) { if (k === "" || k.toLowerCase().indexOf("gene") > -1) { tmpOptions["rnaExperiment"] = k; - tmpOptions["rnaCountAssay"] = preflight.modality_assay_names[k][0]; + tmpOptions["rnaCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[k] + ); tmpOptions["primaryRnaFeatureIdColumn"] = getDefaultFeature(v); } else if ( @@ -172,11 +185,15 @@ export function RDSSE({ k.toLowerCase().indexOf("adt") > -1 ) { tmpOptions["adtExperiment"] = k; - tmpOptions["adtCountAssay"] = preflight.modality_assay_names[k][0]; + tmpOptions["adtCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[k] + ); tmpOptions["primaryAdtFeatureIdColumn"] = getDefaultFeature(v); } else if (k.toLowerCase().indexOf("crispr") > -1) { tmpOptions["crisprExperiment"] = k; - tmpOptions["crisprCountAssay"] = preflight.modality_assay_names[k][0]; + tmpOptions["crisprCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[k] + ); tmpOptions["primaryCrisprFeatureIdColumn"] = getDefaultFeature(v); } } @@ -275,13 +292,6 @@ export function RDSSE({ {mod} count assay { if ( e.target.value !== undefined && @@ -289,10 +299,9 @@ export function RDSSE({ ) { let tmpOptions = { ...options }; if (e.target.value === "none") { - tmpOptions[`${mod.toLowerCase()}CountAssay`] = - null; + tmpOptions[getAssayNameKey(mod)] = null; } else { - tmpOptions[`${mod.toLowerCase()}CountAssay`] = + tmpOptions[getAssayNameKey(mod)] = e.target.value; } setOptions(tmpOptions); @@ -305,7 +314,11 @@ export function RDSSE({ dsMeta.modality_assay_names[ options[getFTypeKey(mod)] ].map((x, i) => ( - ))} diff --git a/src/components/NewAnalysis/TenxHDF5Card.js b/src/components/NewAnalysis/TenxHDF5Card.js index e0846675..b3a7d16f 100644 --- a/src/components/NewAnalysis/TenxHDF5Card.js +++ b/src/components/NewAnalysis/TenxHDF5Card.js @@ -71,6 +71,10 @@ export function TenxHDF5({ return `featureType${getCamelCaseKey(mod)}Name`; }; + const getAssayNameKey = (mod) => { + return `${mod.toLowerCase()}CountAssay`; + }; + const resetModality = (mod, val) => { let tmpOptions = { ...options }; diff --git a/src/components/NewAnalysis/ZippedADBCard.js b/src/components/NewAnalysis/ZippedADBCard.js index 648fe23a..3667d645 100644 --- a/src/components/NewAnalysis/ZippedADBCard.js +++ b/src/components/NewAnalysis/ZippedADBCard.js @@ -17,7 +17,7 @@ import "./index.css"; import { MODALITIES } from "../../utils/utils"; -import { reportFeatureTypes } from "./utils"; +import { reportFeatureTypes, getDefaultAssayName } from "./utils"; export function ZippedADB({ resource, @@ -66,8 +66,10 @@ export function ZippedADB({ options["adtExperiment"] !== null && options["adtExperiment"] !== undefined ) { - tmpOptions["adtCountAssay"] = - preflight.modality_assay_names[options?.["adtExperiment"]][0]; + tmpOptions["adtCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[options?.["adtExperiment"]] + ); + tmpOptions["primaryAdtFeatureIdColumn"] = Object.keys( preflight.modality_features[options?.["adtExperiment"]].columns )[0]; @@ -87,8 +89,10 @@ export function ZippedADB({ options["crisprExperiment"] !== null && options["crisprExperiment"] !== undefined ) { - tmpOptions["crisprCountAssay"] = - preflight.modality_assay_names[options?.["crisprExperiment"]][0]; + tmpOptions["crisprCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[options?.["crisprExperiment"]] + ); + tmpOptions["primaryCrisprFeatureIdColumn"] = Object.keys( preflight.modality_features[options?.["crisprExperiment"]].columns )[0]; @@ -108,8 +112,10 @@ export function ZippedADB({ options["rnaExperiment"] !== null && options["rnaExperiment"] !== undefined ) { - tmpOptions["rnaCountAssay"] = - preflight.modality_assay_names[options?.["rnaExperiment"]][0]; + tmpOptions["rnaCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[options?.["rnaExperiment"]] + ); + tmpOptions["primaryRnaFeatureIdColumn"] = Object.keys( preflight.modality_features[options?.["rnaExperiment"]].columns )[0]; @@ -138,6 +144,10 @@ export function ZippedADB({ return `${mod.toLowerCase()}Experiment`; }; + const getAssayNameKey = (mod) => { + return `${mod.toLowerCase()}CountAssay`; + }; + const resetModality = (mod, val) => { let tmpOptions = { ...options }; @@ -161,18 +171,24 @@ export function ZippedADB({ for (const [k, v] of Object.entries(preflight.modality_features)) { if (k === "" || k.toLowerCase().indexOf("gene") > -1) { tmpOptions["rnaExperiment"] = k; - tmpOptions["rnaCountAssay"] = preflight.modality_assay_names[k][0]; + tmpOptions["rnaCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[k] + ); tmpOptions["primaryRnaFeatureIdColumn"] = Object.keys(v.columns)[0]; } else if ( k.toLowerCase().indexOf("antibody") > -1 || k.toLowerCase().indexOf("adt") > -1 ) { tmpOptions["adtExperiment"] = k; - tmpOptions["adtCountAssay"] = preflight.modality_assay_names[k][0]; + tmpOptions["adtCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[k] + ); tmpOptions["primaryAdtFeatureIdColumn"] = Object.keys(v.columns)[0]; } else if (k.toLowerCase().indexOf("crispr") > -1) { tmpOptions["crisprExperiment"] = k; - tmpOptions["crisprCountAssay"] = preflight.modality_assay_names[k][0]; + tmpOptions["crisprCountAssay"] = getDefaultAssayName( + preflight.modality_assay_names[k] + ); tmpOptions["primaryCrisprFeatureIdColumn"] = Object.keys(v.columns)[0]; } } @@ -271,13 +287,6 @@ export function ZippedADB({ {mod} count assay { if ( e.target.value !== undefined && @@ -285,11 +294,9 @@ export function ZippedADB({ ) { let tmpOptions = { ...options }; if (e.target.value === "none") { - tmpOptions[`${mod.toLowerCase()}CountAssay`] = - null; + tmpOptions[getAssayNameKey] = null; } else { - tmpOptions[`${mod.toLowerCase()}CountAssay`] = - e.target.value; + tmpOptions[getAssayNameKey] = e.target.value; } setOptions(tmpOptions); } @@ -301,7 +308,11 @@ export function ZippedADB({ dsMeta.modality_assay_names[ options[getFTypeKey(mod)] ].map((x, i) => ( - ))} diff --git a/src/components/NewAnalysis/utils.js b/src/components/NewAnalysis/utils.js index 0a3e903e..9a4298c8 100644 --- a/src/components/NewAnalysis/utils.js +++ b/src/components/NewAnalysis/utils.js @@ -48,3 +48,14 @@ export function getDefaultFeature(obj) { return Object.keys(obj.columns)[0]; } + +export function getDefaultAssayName(assaynames) { + let _defname = assaynames[0]; + for (let _aname of assaynames) { + if (_aname.toLowerCase() == "counts") { + _defname = _aname; + } + } + + return _defname; +}