diff --git a/build.gradle.kts b/build.gradle.kts index 87331ccb..dade24e8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -80,7 +80,7 @@ repositories { // versions val coreLib = "6.19.1" // Container core lib version val edaCompute = "2.4.4" // EDA Compute version (used to pull in compute plugin RAML) -val edaCommon = "11.6.6" // EDA Common version +val edaCommon = "11.6.7" // EDA Common version val fgputil = "2.12.9-jakarta" // FgpUtil version // use local EDA compute compiled schema if project exists, else use released version; diff --git a/src/main/java/org/veupathdb/service/eda/ds/core/AbstractPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/core/AbstractPlugin.java index fb6ba39c..72b36556 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/core/AbstractPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/core/AbstractPlugin.java @@ -17,7 +17,10 @@ import org.veupathdb.service.eda.common.client.*; import org.veupathdb.service.eda.common.client.EdaComputeClient.ComputeRequestBody; import org.veupathdb.service.eda.common.client.spec.StreamSpec; +import org.veupathdb.service.eda.common.model.CollectionDef; +import org.veupathdb.service.eda.common.model.EntityDef; import org.veupathdb.service.eda.common.model.ReferenceMetadata; +import org.veupathdb.service.eda.common.model.VariableDef; import org.veupathdb.service.eda.common.plugin.constraint.ConstraintSpec; import org.veupathdb.service.eda.common.plugin.constraint.DataElementSet; import org.veupathdb.service.eda.common.plugin.constraint.DataElementValidator; @@ -38,6 +41,7 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import java.util.stream.Collector; import java.util.stream.Collectors; import static org.veupathdb.service.eda.common.plugin.util.PluginUtil.singleQuote; @@ -336,7 +340,7 @@ protected Map getCategoricalProportionDistribution(VariableSpec return response.getHistogram().stream().collect(Collectors.toMap(HistogramBin::getBinLabel, bin -> Double.valueOf(bin.getValue().toString()))); } - protected Map getVocabByRootEntity(DynamicDataSpecImpl dataSpec, List subsetFilters) { + protected Map getVocabByRootEntity(DynamicDataSpec dataSpec, List subsetFilters) { PluginUtil util = getUtil(); ResponseFuture response = _subsettingClient.getVocabByRootEntity(_referenceMetadata, dataSpec, subsetFilters); @@ -352,20 +356,20 @@ protected Map getVocabByRootEntity(DynamicDataSpecImpl data return vocab; } - protected Map getVocabByRootEntity(DynamicDataSpecImpl dataSpec) { + protected Map getVocabByRootEntity(DynamicDataSpec dataSpec) { return getVocabByRootEntity(dataSpec, _subsetFilters); } - protected Map getVocabByRootEntity(List dataSpecs, List subsetFilters) { + protected Map getVocabByRootEntity(List dataSpecs, List subsetFilters) { Map studyVocabStreams = new HashMap(); - for (DynamicDataSpecImpl dataSpec : dataSpecs) { + for (DynamicDataSpec dataSpec : dataSpecs) { studyVocabStreams.putAll(getVocabByRootEntity(dataSpec)); } return studyVocabStreams; } - protected Map getVocabByRootEntity(List dataSpecs) { + protected Map getVocabByRootEntity(List dataSpecs) { return getVocabByRootEntity(dataSpecs, _subsetFilters); } @@ -578,11 +582,12 @@ public String getVariableMetadataRObjectAsString(CollectionSpec collection, Stri if (collection == null) return null; PluginUtil util = getUtil(); String membersList = getVariableSpecListRObjectAsString(util.getCollectionMembers(collection)); + plotReference = plotReference == null ? "" : "veupathUtils::PlotReference(value=" + singleQuote(plotReference) + "),"; return "veupathUtils::VariableMetadata(" + "variableClass=veupathUtils::VariableClass(value='native')," + "variableSpec=veupathUtils::VariableSpec(variableId=" + singleQuote(collection.getCollectionId()) + ",entityId=" + singleQuote(collection.getEntityId()) + ")," + - "plotReference=veupathUtils::PlotReference(value=" + singleQuote(plotReference) + ")," + + plotReference + "dataType=" + singleQuote(util.getCollectionType(collection)) + "," + "dataShape=" + singleQuote(util.getCollectionDataShape(collection)) + "," + "imputeZero=" + util.getCollectionImputeZero(collection).toUpperCase() + "," + @@ -594,11 +599,12 @@ public String getVariableMetadataRObjectAsString(VariableSpec var, String plotRe if (var == null) return null; PluginUtil util = getUtil(); String hasStudyDependentVocabulary = util.getHasStudyDependentVocabulary(var) ? "TRUE" : "FALSE"; + plotReference = plotReference == null ? "" : "plotReference=veupathUtils::PlotReference(value=" + singleQuote(plotReference) + "),"; return "veupathUtils::VariableMetadata(" + "variableClass=veupathUtils::VariableClass(value='native')," + "variableSpec=veupathUtils::VariableSpec(variableId=" + singleQuote(var.getVariableId()) + ",entityId=" + singleQuote(var.getEntityId()) + ")," + - "plotReference=veupathUtils::PlotReference(value=" + singleQuote(plotReference) + ")," + + plotReference + "dataType=veupathUtils::DataType(value=" + singleQuote(util.getVariableType(var)) + ")," + "dataShape=veupathUtils::DataShape(value=" + singleQuote(util.getVariableDataShape(var)) + ")," + "imputeZero=" + util.getVariableImputeZero(var).toUpperCase() + "," + @@ -606,7 +612,18 @@ public String getVariableMetadataRObjectAsString(VariableSpec var, String plotRe "hasStudyDependentVocabulary=" + hasStudyDependentVocabulary + ")"; } - public String getVoidEvalDynamicDataMetadataList(Map dataSpecs) { + public String getVoidEvalDynamicDataMetadataListWithStudyDependentVocabs(Map dataSpecs, String outputEntityId) { + List dataSpecsFromMap = dataSpecs.values().stream().collect(Collectors.toList()); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId, dataSpecsFromMap); + // for each new data spec with study dependent vocabs, add it to the map + for (DynamicDataSpec dataSpec : dataSpecsWithStudyDependentVocabs) { + dataSpecs.put("none" + getDynamicDataSpecId(dataSpec), dataSpec); + } + + return getVoidEvalDynamicDataMetadataList(dataSpecs); + } + + public String getVoidEvalDynamicDataMetadataList(Map dataSpecs) { return // special case if vars is null or all var values are null dataSpecs == null || dataSpecs.values().stream().allMatch(Objects::isNull) @@ -617,7 +634,8 @@ public String getVoidEvalDynamicDataMetadataList(Map { String plotReference = entry.getKey(); - DynamicDataSpecImpl dataSpec = entry.getValue(); + if (plotReference.contains("none") || plotReference.contains("null")) plotReference = null; + DynamicDataSpec dataSpec = entry.getValue(); if (dataSpec.isCollectionSpec()) { return getVariableMetadataRObjectAsString(dataSpec.getCollectionSpec(), plotReference); } else if (dataSpec.isVariableSpec()) { @@ -631,28 +649,51 @@ public String getVoidEvalDynamicDataMetadataList(Map varMapToDynamicDataMap(Map varSpecs) { - Map dataSpecs = varSpecs.entrySet().stream() + public Map varMapToDynamicDataMap(Map varSpecs) { + Map dataSpecs = varSpecs.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> new DynamicDataSpecImpl(e.getValue()))); return(dataSpecs); } +public String getVoidEvalVariableMetadataListWithStudyDependentVocabs(Map varSpecs, String outputEntityId) { + List varSpecsFromMap = varSpecs.values().stream().collect(Collectors.toList()); + List varSpecsWithStudyDependentVocabs = getVariableSpecsWithStudyDependentVocabs(outputEntityId, varSpecsFromMap); + // for each new varSpec with studyDependentVocabs, add it to varSpecs + for (VariableSpec varSpec : varSpecsWithStudyDependentVocabs) { + //ok this is a bit hacky i guess.. + // maybe someday make the varMap like Map>, could help facets too + varSpecs.put("none" + varSpec.getVariableId(), varSpec); + } + return getVoidEvalVariableMetadataList(varSpecs); +} + public String getVoidEvalVariableMetadataList(Map varSpecs) { - Map dataSpecs = varMapToDynamicDataMap(varSpecs); + Map dataSpecs = varMapToDynamicDataMap(varSpecs); return getVoidEvalDynamicDataMetadataList(dataSpecs); } - public Map collectionMapToDynamicDataMap(Map collectionSpecs) { - Map dataSpecs = collectionSpecs.entrySet().stream() + public Map collectionMapToDynamicDataMap(Map collectionSpecs) { + Map dataSpecs = collectionSpecs.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> new DynamicDataSpecImpl(e.getValue()))); return(dataSpecs); } + public String getVoidEvalCollectionMetadataListWithStudyDependentVocabs(Map collectionSpecs, String outputEntityId) { + List collectionSpecsFromMap = collectionSpecs.values().stream().collect(Collectors.toList()); + List collectionSpecsWithStudyDependentVocabs = getCollectionSpecsWithStudyDependentVocabs(outputEntityId, collectionSpecsFromMap); + + for (CollectionSpec collectionSpec : collectionSpecsWithStudyDependentVocabs) { + collectionSpecs.put("none" + collectionSpec.getCollectionId(), collectionSpec); + } + + return getVoidEvalCollectionMetadataList(collectionSpecs); + } + public String getVoidEvalCollectionMetadataList(Map collectionSpecs) { - Map dataSpecs = collectionMapToDynamicDataMap(collectionSpecs); + Map dataSpecs = collectionMapToDynamicDataMap(collectionSpecs); return getVoidEvalDynamicDataMetadataList(dataSpecs); } @@ -678,10 +719,10 @@ public String getRBinListAsString(List labels) { return rBinList + "))"; } - public boolean validateImputeZeroesRequest(Map dataSpecs) { + public boolean validateImputeZeroesRequest(Map dataSpecs) { // TODO keep adding checks as i think of them - List dataSpecsWithStudyDependentVocabs = findDataSpecsWithStudyDependentVocabs(dataSpecs); + List dataSpecsWithStudyDependentVocabs = dataSpecs.entrySet().stream().filter(entry -> hasStudyDependentVocabulary(entry.getValue())).map(Map.Entry::getValue).toList(); List entities = dataSpecsWithStudyDependentVocabs.stream().map(data -> getDynamicDataSpecEntityId(data)).toList(); if (entities.size() == 0) { return false; @@ -695,7 +736,7 @@ public boolean validateImputeZeroesRequest(Map data return true; } - public String getRStudyVocabsAsString(DynamicDataSpecImpl dataSpec) { + public String getRStudyVocabsAsString(DynamicDataSpec dataSpec) { PluginUtil util = getUtil(); // this assuming the first ancestor is the root one is a bit hacky, but i did the same in R so... @@ -713,7 +754,7 @@ public String getRStudyVocabsAsString(DynamicDataSpecImpl dataSpec) { return studyVocabsListAsRString; } - public String getRStudyVocabsAsString(List dataSpecs) { + public String getRStudyVocabsAsString(List dataSpecs) { String studyVocabListRString = "veupathUtils::StudySpecificVocabulariesByVariableList(S4Vectors::SimpleList("; boolean first = true; @@ -730,7 +771,7 @@ public String getRStudyVocabsAsString(List dataSpecs) { return studyVocabListRString + "))"; } - public boolean hasStudyDependentVocabulary(DynamicDataSpecImpl dataSpec) { + public boolean hasStudyDependentVocabulary(DynamicDataSpec dataSpec) { PluginUtil util = getUtil(); if (dataSpec.isCollectionSpec()) { @@ -742,31 +783,8 @@ public boolean hasStudyDependentVocabulary(DynamicDataSpecImpl dataSpec) { } } - public List findDataSpecsWithStudyDependentVocabs(Map dataSpecs) { - List dataSpecsWithStudyDependentVocabs = new ArrayList<>(); - - for (DynamicDataSpecImpl dataSpec : dataSpecs.values()) { - if (hasStudyDependentVocabulary(dataSpec)) { - dataSpecsWithStudyDependentVocabs.add(dataSpec); - } - } - - return dataSpecsWithStudyDependentVocabs; - } - - public List findVariableSpecsWithStudyDependentVocabs(Map varSpecs) { - Map dataSpecs = varMapToDynamicDataMap(varSpecs); - - return findDataSpecsWithStudyDependentVocabs(dataSpecs); - } - - public List findCollectionSpecsWithStudyDependentVocabs(Map collectionSpecs) { - Map dataSpecs = collectionMapToDynamicDataMap(collectionSpecs); - - return findDataSpecsWithStudyDependentVocabs(dataSpecs); - } - - public String getDynamicDataSpecEntityId(DynamicDataSpecImpl dataSpec) { + // TODO consider moving these next two to utils in edacommon + public String getDynamicDataSpecEntityId(DynamicDataSpec dataSpec) { if (dataSpec.isCollectionSpec()) { return dataSpec.getCollectionSpec().getEntityId(); } else if (dataSpec.isVariableSpec()) { @@ -776,7 +794,7 @@ public String getDynamicDataSpecEntityId(DynamicDataSpecImpl dataSpec) { } } - public String getDynamicDataSpecId(DynamicDataSpecImpl dataSpec) { + public String getDynamicDataSpecId(DynamicDataSpec dataSpec) { if (dataSpec.isCollectionSpec()) { return dataSpec.getCollectionSpec().getCollectionId(); } else if (dataSpec.isVariableSpec()) { @@ -786,17 +804,14 @@ public String getDynamicDataSpecId(DynamicDataSpecImpl dataSpec) { } } - public String getRMegastudyAsString(String compressedDataHandle, Map dataSpecs) { + public String getRMegastudyAsString(String compressedDataHandle, String outputEntityId) { PluginUtil util = getUtil(); // find and validate variables w study specific vocabs - List dataSpecsWithStudyDependentVocabs = findDataSpecsWithStudyDependentVocabs(dataSpecs); - List entities = dataSpecsWithStudyDependentVocabs.stream().map(data -> getDynamicDataSpecEntityId(data)).toList(); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); String studyVocabsAsRString = getRStudyVocabsAsString(dataSpecsWithStudyDependentVocabs); - // get ancestor ids, can use first var bc we validate there is at least one and they all have the same entity - String entityId = entities.get(0); - String ancestorIdsAsRString = util.getEntityAncestorsAsRVectorString(entityId, _referenceMetadata, true); + String ancestorIdsAsRString = util.getEntityAncestorsAsRVectorString(outputEntityId, _referenceMetadata, true); String megastudyAsRString = "veupathUtils::Megastudy(" + "data = " + compressedDataHandle + "," + @@ -806,38 +821,178 @@ public String getRMegastudyAsString(String compressedDataHandle, Map dataSpecs) { - return getRInputDataWithImputedZeroesAsString(compressedDataHandle, dataSpecs, "variables"); + public String getRInputDataWithImputedZeroesAsString( + String compressedDataHandle, Map dataSpecs, + String outputEntityId + ) { + return getRInputDataWithImputedZeroesAsString(compressedDataHandle, dataSpecs, outputEntityId, "variables"); } - public String getRInputDataWithImputedZeroesAsString(String compressedDataHandle, Map dataSpecs, String variableMetadataListHandle) { + public String getRInputDataWithImputedZeroesAsString( + String compressedDataHandle, + Map dataSpecs, + String outputEntityId, + String variableMetadataListHandle + ) { boolean validRequest = validateImputeZeroesRequest(dataSpecs); if (validRequest) { - String megastudyData = getRMegastudyAsString(compressedDataHandle, dataSpecs); + String megastudyData = getRMegastudyAsString(compressedDataHandle, outputEntityId); return "veupathUtils::getDTWithImputedZeroes(" + megastudyData + ", " + variableMetadataListHandle + ")"; } return compressedDataHandle; } - public String getRCollectionInputDataWithImputedZeroesAsString(String compressedDataHandle, Map collectionSpecs) { - return getRCollectionInputDataWithImputedZeroesAsString(compressedDataHandle, collectionSpecs, "variables"); + public String getRCollectionInputDataWithImputedZeroesAsString( + String compressedDataHandle, + Map collectionSpecs, + String outputEntityId + ) { + return getRCollectionInputDataWithImputedZeroesAsString(compressedDataHandle, collectionSpecs, outputEntityId, "variables"); + } + + public String getRCollectionInputDataWithImputedZeroesAsString( + String compressedDataHandle, + Map collectionSpecs, + String outputEntityId, + String variableMetadataListHandle + ) { + Map dataSpecs = collectionMapToDynamicDataMap(collectionSpecs); + + return(getRInputDataWithImputedZeroesAsString(compressedDataHandle, dataSpecs, outputEntityId, variableMetadataListHandle)); + } + + public String getRVariableInputDataWithImputedZeroesAsString( + String compressedDataHandle, + Map varSpecs, + String outputEntityId + ) { + return getRVariableInputDataWithImputedZeroesAsString(compressedDataHandle, varSpecs, outputEntityId, "variables"); + } + + public String getRVariableInputDataWithImputedZeroesAsString( + String compressedDataHandle, + Map varSpecs, + String outputEntityId, + String variableMetadataListHandle + ) { + Map dataSpecs = varMapToDynamicDataMap(varSpecs); + + return(getRInputDataWithImputedZeroesAsString(compressedDataHandle, dataSpecs, outputEntityId, variableMetadataListHandle)); } - public String getRCollectionInputDataWithImputedZeroesAsString(String compressedDataHandle, Map collectionSpecs, String variableMetadataListHandle) { - Map dataSpecs = collectionMapToDynamicDataMap(collectionSpecs); + // TODO consider adding all that follows to util in edacommon + public List getVariableSpecsWithStudyDependentVocabs(String entityId) { + List varSpecsWithStudyDependentVocabs = new ArrayList<>(); + EntityDef entity = _referenceMetadata.getEntity(entityId).orElseThrow(); + + // get reference metadata and find variables w study specific vocabs + for (VariableDef var : entity.getVariables()) { + if (var.getHasStudyDependentVocabulary()) { + VariableSpecImpl varSpec = new VariableSpecImpl(); + varSpec.setVariableId(var.getVariableId()); + varSpec.setEntityId(entityId); + varSpecsWithStudyDependentVocabs.add(varSpec); + } + } - return(getRInputDataWithImputedZeroesAsString(compressedDataHandle, dataSpecs, variableMetadataListHandle)); + return varSpecsWithStudyDependentVocabs; } - public String getRVariableInputDataWithImputedZeroesAsString(String compressedDataHandle, Map varSpecs) { - return getRVariableInputDataWithImputedZeroesAsString(compressedDataHandle, varSpecs, "variables"); + public boolean areSameVariableSpec(VariableSpec varSpec1, VariableSpec varSpec2) { + return varSpec1.getVariableId().equals(varSpec2.getVariableId()) && + varSpec1.getEntityId().equals(varSpec2.getEntityId()); } - public String getRVariableInputDataWithImputedZeroesAsString(String compressedDataHandle, Map varSpecs, String variableMetadataListHandle) { - Map dataSpecs = varMapToDynamicDataMap(varSpecs); + public boolean containsVariableSpec(List varSpecs, VariableSpec varSpec) { + return varSpecs.stream().anyMatch(var -> areSameVariableSpec(var, varSpec)); + } + + public boolean areSameDynamicDataSpec(DynamicDataSpec dataSpec1, DynamicDataSpec dataSpec2) { + return getDynamicDataSpecId(dataSpec1).equals(getDynamicDataSpecId(dataSpec2)) && + getDynamicDataSpecEntityId(dataSpec1).equals(getDynamicDataSpecEntityId(dataSpec2)); + } + + public boolean containsDataSpec(List dataSpecs, DynamicDataSpec dataSpec) { + return dataSpecs.stream().anyMatch(data -> areSameDynamicDataSpec(data, dataSpec)); + } + + public boolean areSameCollectionSpec(CollectionSpec colSpec1, CollectionSpec colSpec2) { + return colSpec1.getCollectionId().equals(colSpec2.getCollectionId()) && + colSpec1.getEntityId().equals(colSpec2.getEntityId()); + } + + public boolean containsCollectionSpec(List colSpecs, CollectionSpec colSpec) { + return colSpecs.stream().anyMatch(col -> areSameCollectionSpec(col, colSpec)); + } + + public List getVariableSpecsWithStudyDependentVocabs(String entityId, List varSpecsToIgnore) { + List varSpecsWithStudyDependentVocabs = getVariableSpecsWithStudyDependentVocabs(entityId); + varSpecsWithStudyDependentVocabs = varSpecsWithStudyDependentVocabs.stream().filter(var -> !containsVariableSpec(varSpecsToIgnore, var)).collect(Collectors.toList()); + + return varSpecsWithStudyDependentVocabs; + } + + public List getCollectionSpecsWithStudyDependentVocabs(String entityId) { + List collectionSpecsWithStudyDependentVocabs = new ArrayList<>(); + EntityDef entity = _referenceMetadata.getEntity(entityId).orElseThrow(); + + // get reference metadata and find collections w study specific vocabs + for (CollectionDef collection : entity.getCollections()) { + if (collection.getHasStudyDependentVocabulary()) { + CollectionSpecImpl colSpec = new CollectionSpecImpl(); + colSpec.setCollectionId(collection.getCollectionId()); + colSpec.setEntityId(entityId); + collectionSpecsWithStudyDependentVocabs.add(colSpec); + } + } + + return collectionSpecsWithStudyDependentVocabs; + } + + public List getCollectionSpecsWithStudyDependentVocabs(String entityId, List collectionSpecsToIgnore) { + List collectionSpecsWithStudyDependentVocabs = getCollectionSpecsWithStudyDependentVocabs(entityId); + collectionSpecsWithStudyDependentVocabs.stream().filter(col -> !containsCollectionSpec(collectionSpecsToIgnore, col)).collect(Collectors.toList()); + + return collectionSpecsWithStudyDependentVocabs; + } + + // this seems the most common case for collections, so worth a helper + public List getCollectionSpecsWithStudyDependentVocabs(String entityId, CollectionSpec collectionSpecToIgnore) { + return getCollectionSpecsWithStudyDependentVocabs(entityId, List.of(collectionSpecToIgnore)); + } + + public List getDynamicDataSpecsWithStudyDependentVocabs(String entityId, List dataSpecsToIgnore) { + List dynamicDataSpecsWithStudyDependentVocabs = new ArrayList<>(); + + List varSpecsToIgnore = dataSpecsToIgnore.stream() + .filter(dataSpec -> dataSpec.isVariableSpec()) + .map(dataSpec -> dataSpec.getVariableSpec()) + .collect(Collectors.toList()); + List varSpecsWithStudyDependentVocabs = getVariableSpecsWithStudyDependentVocabs(entityId, varSpecsToIgnore); + + List collectionSpecsToIgnore = dataSpecsToIgnore.stream() + .filter(dataSpec -> dataSpec.isCollectionSpec()) + .map(dataSpec -> dataSpec.getCollectionSpec()) + .collect(Collectors.toList()); + List collectionSpecsWithStudyDependentVocabs = getCollectionSpecsWithStudyDependentVocabs(entityId, collectionSpecsToIgnore); + + for (VariableSpec varSpec : varSpecsWithStudyDependentVocabs) { + DynamicDataSpecImpl dataSpec = new DynamicDataSpecImpl(varSpec); + dynamicDataSpecsWithStudyDependentVocabs.add(dataSpec); + } + + for (CollectionSpec colSpec : collectionSpecsWithStudyDependentVocabs) { + DynamicDataSpecImpl dataSpec = new DynamicDataSpecImpl(colSpec); + dynamicDataSpecsWithStudyDependentVocabs.add(dataSpec); + } + + return dynamicDataSpecsWithStudyDependentVocabs; + } - return(getRInputDataWithImputedZeroesAsString(compressedDataHandle, dataSpecs, variableMetadataListHandle)); + public List getDynamicDataSpecsWithStudyDependentVocabs(String entityId) { + return getDynamicDataSpecsWithStudyDependentVocabs(entityId, new ArrayList<>()); } } diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingBarplotPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingBarplotPlugin.java index 9016eedb..fd4a0f4e 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingBarplotPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingBarplotPlugin.java @@ -67,32 +67,37 @@ protected void validateVisualizationSpec(CollectionFloatingBarplotSpec pluginSpe } @Override - protected List getRequestedStreams(CollectionFloatingBarplotSpec pluginSpec) { + protected List getRequestedStreams(CollectionFloatingBarplotSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.addAll(pluginSpec.getOverlayConfig().getSelectedMembers()); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVars(pluginSpec.getOverlayConfig().getSelectedMembers()) - ); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + // this will probably need revisited when/ if we introduce study-dependent vocabs for collections + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { CollectionFloatingBarplotSpec spec = getPluginSpec(); - PluginUtil util = getUtil(); + String outputEntityId = spec.getOutputEntityId(); String barMode = spec.getBarMode().getValue(); String overlayValues = getRBinListAsString(spec.getOverlayConfig().getSelectedValues()); - List inputVarSpecs = new ArrayList<>(spec.getOverlayConfig().getSelectedMembers()); Map varMap = new HashMap<>(); varMap.put("overlay", spec.getOverlayConfig().getCollection()); - List dataSpecsWithStudyDependentVocabs = findCollectionSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithRemoteFiles(Resources.RSERVE_URL, dataStreams, connection -> { connection.voidEval(DEFAULT_SINGLE_STREAM_NAME + " <- data.table::fread('" + DEFAULT_SINGLE_STREAM_NAME + "', na.strings=c(''))"); - String inputData = getRCollectionInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalCollectionMetadataList(varMap)); + String inputData = getRCollectionInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalCollectionMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String cmd = "plot.data::bar(data=" + inputData + ", " + "variables=variables, " + diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingBoxplotPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingBoxplotPlugin.java index d71d2bf5..18215a27 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingBoxplotPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingBoxplotPlugin.java @@ -73,21 +73,27 @@ protected void validateVisualizationSpec(CollectionFloatingBoxplotSpec pluginSpe @Override protected List getRequestedStreams(CollectionFloatingBoxplotSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.add(pluginSpec.getXAxisVariable()); + plotVariableSpecs.addAll(pluginSpec.getOverlayConfig().getSelectedMembers()); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVars(pluginSpec.getOverlayConfig().getSelectedMembers()) - .addVar(pluginSpec.getXAxisVariable()) - ); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { PluginUtil util = getUtil(); CollectionFloatingBoxplotSpec spec = getPluginSpec(); + String outputEntityId = spec.getOutputEntityId(); List inputVarSpecs = new ArrayList<>(spec.getOverlayConfig().getSelectedMembers()); inputVarSpecs.add(spec.getXAxisVariable()); CollectionSpec overlayVariable = spec.getOverlayConfig().getCollection(); - Map varMap = new HashMap<>(); + Map varMap = new HashMap<>(); varMap.put("xAxis", new DynamicDataSpecImpl(spec.getXAxisVariable())); varMap.put("overlay", new DynamicDataSpecImpl(overlayVariable)); @@ -106,13 +112,13 @@ protected void writeResults(OutputStream out, Map dataStrea conn.voidEval(name + " <- data.table::fread('" + name + "', na.strings=c(''))") ); - List dataSpecsWithStudyDependentVocabs = findDataSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithProcessedRemoteFiles(Resources.RSERVE_URL, filesProcessor, connection -> { - String inputData = getRInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalDynamicDataMetadataList(varMap)); + String inputData = getRInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalDynamicDataMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String cmd = "plot.data::box(data=" + inputData + ", " + "variables=variables, " + diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingContTablePlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingContTablePlugin.java index 0b157916..8e76c00e 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingContTablePlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingContTablePlugin.java @@ -58,30 +58,34 @@ protected void validateVisualizationSpec(CollectionFloatingContTableSpec pluginS } @Override - protected List getRequestedStreams(CollectionFloatingContTableSpec pluginSpec) { + protected List getRequestedStreams(CollectionFloatingContTableSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.addAll(pluginSpec.getXAxisVariable().getSelectedMembers()); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVars(pluginSpec.getXAxisVariable().getSelectedMembers()) - ); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { - PluginUtil util = getUtil(); CollectionFloatingContTableSpec spec = getPluginSpec(); + String outputEntityId = spec.getOutputEntityId(); String overlayValues = getRBinListAsString(spec.getXAxisVariable().getSelectedValues()); - List inputVarSpecs = new ArrayList<>(spec.getXAxisVariable().getSelectedMembers()); Map varMap = new HashMap<>(); varMap.put("xAxis", spec.getXAxisVariable().getCollection()); - List dataSpecsWithStudyDependentVocabs = findCollectionSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithRemoteFiles(Resources.RSERVE_URL, dataStreams, connection -> { connection.voidEval(DEFAULT_SINGLE_STREAM_NAME + " <- data.table::fread('" + DEFAULT_SINGLE_STREAM_NAME + "', na.strings=c(''))"); - String inputData = getRCollectionInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalCollectionMetadataList(varMap)); + String inputData = getRCollectionInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalCollectionMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String cmd = "plot.data::mosaic(data=" + inputData + ", " + "variables=variables, " + "statistic='chiSq', " + diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingHistogramPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingHistogramPlugin.java index c6feed0e..352d1f5c 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingHistogramPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingHistogramPlugin.java @@ -68,31 +68,36 @@ protected void validateVisualizationSpec(CollectionFloatingHistogramSpec pluginS @Override protected List getRequestedStreams(CollectionFloatingHistogramSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.addAll(pluginSpec.getOverlayConfig().getSelectedMembers()); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVars(pluginSpec.getOverlayConfig().getSelectedMembers()) - ); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { PluginUtil util = getUtil(); CollectionFloatingHistogramSpec spec = getPluginSpec(); - List inputVarSpecs = new ArrayList<>(spec.getOverlayConfig().getSelectedMembers()); + String outputEntityId = spec.getOutputEntityId(); CollectionSpec overlayVariable = spec.getOverlayConfig().getCollection(); Map varMap = new HashMap<>(); varMap.put("overlay", overlayVariable); String barMode = spec.getBarMode().getValue(); String collectionType = util.getCollectionType(overlayVariable); - List dataSpecsWithStudyDependentVocabs = findCollectionSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithRemoteFiles(Resources.RSERVE_URL, dataStreams, connection -> { connection.voidEval(DEFAULT_SINGLE_STREAM_NAME + " <- data.table::fread('" + DEFAULT_SINGLE_STREAM_NAME + "', na.strings=c(''))"); - String inputData = getRCollectionInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalCollectionMetadataList(varMap)); + String inputData = getRCollectionInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalCollectionMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String viewportRString = getViewportAsRString(spec.getViewport(), collectionType); connection.voidEval(viewportRString); diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingLineplotPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingLineplotPlugin.java index 3a113f30..38f579e4 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingLineplotPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/CollectionFloatingLineplotPlugin.java @@ -69,21 +69,27 @@ protected void validateVisualizationSpec(CollectionFloatingLineplotSpec pluginSp @Override protected List getRequestedStreams(CollectionFloatingLineplotSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.add(pluginSpec.getXAxisVariable()); + plotVariableSpecs.addAll(pluginSpec.getOverlayConfig().getSelectedMembers()); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVars(pluginSpec.getOverlayConfig().getSelectedMembers()) - .addVar(pluginSpec.getXAxisVariable()) - ); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { PluginUtil util = getUtil(); CollectionFloatingLineplotSpec spec = getPluginSpec(); + String outputEntityId = spec.getOutputEntityId(); List inputVarSpecs = new ArrayList<>(spec.getOverlayConfig().getSelectedMembers()); inputVarSpecs.add(spec.getXAxisVariable()); CollectionSpec overlayVariable = spec.getOverlayConfig().getCollection(); - Map varMap = new HashMap<>(); + Map varMap = new HashMap<>(); varMap.put("xAxis", new DynamicDataSpecImpl(spec.getXAxisVariable())); varMap.put("overlay", new DynamicDataSpecImpl(overlayVariable)); String errorBars = spec.getErrorBars() != null ? spec.getErrorBars().getValue() : "FALSE"; @@ -93,14 +99,14 @@ protected void writeResults(OutputStream out, Map dataStrea String denominatorValues = spec.getYAxisDenominatorValues() != null ? PluginUtil.listToRVector(spec.getYAxisDenominatorValues()) : "NULL"; String overlayValues = getRBinListAsString(spec.getOverlayConfig().getSelectedValues()); - List dataSpecsWithStudyDependentVocabs = findDataSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithRemoteFiles(Resources.RSERVE_URL, dataStreams, connection -> { connection.voidEval(DEFAULT_SINGLE_STREAM_NAME + " <- data.table::fread('" + DEFAULT_SINGLE_STREAM_NAME + "', na.strings=c(''))"); - String inputData = getRInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalDynamicDataMetadataList(varMap)); + String inputData = getRInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalDynamicDataMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String viewportRString = getViewportAsRString(spec.getViewport(), collectionType); connection.voidEval(viewportRString); BinWidthSpec binSpec = spec.getBinSpec(); diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingBarplotPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingBarplotPlugin.java index 56c6124a..ef671084 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingBarplotPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingBarplotPlugin.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -82,18 +83,23 @@ protected void validateVisualizationSpec(FloatingBarplotSpec pluginSpec) throws @Override protected List getRequestedStreams(FloatingBarplotSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.add(pluginSpec.getXAxisVariable()); + plotVariableSpecs.add(Optional.ofNullable(pluginSpec.getOverlayConfig()).map(OverlayConfig::getOverlayVariable).orElse(null)); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVar(pluginSpec.getXAxisVariable()) - .addVar(Optional.ofNullable(pluginSpec.getOverlayConfig()) - .map(OverlayConfig::getOverlayVariable) - .orElse(null))); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { FloatingBarplotSpec spec = getPluginSpec(); PluginUtil util = getUtil(); + String outputEntityId = spec.getOutputEntityId(); String barMode = spec.getBarMode().getValue(); VariableSpec overlayVariable = _overlaySpecification != null ? _overlaySpecification.getOverlayVariable() : null; String overlayValues = _overlaySpecification == null ? "NULL" : _overlaySpecification.getRBinListAsString(); @@ -103,15 +109,15 @@ protected void writeResults(OutputStream out, Map dataStrea varMap.put("overlay", overlayVariable); // TODO can we make this automagical? override useRConnectionWithRemoteFiles ? i wasnt clear how.. - List dataSpecsWithStudyDependentVocabs = findVariableSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithRemoteFiles(Resources.RSERVE_URL, dataStreams, connection -> { connection.voidEval(DEFAULT_SINGLE_STREAM_NAME + " <- data.table::fread('" + DEFAULT_SINGLE_STREAM_NAME + "', na.strings=c(''))"); - String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalVariableMetadataList(varMap)); + String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalVariableMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String cmd = "plot.data::bar(data=" + inputData + ", " + "variables=variables, " + diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingBoxplotPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingBoxplotPlugin.java index c0562bc7..d94b30d8 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingBoxplotPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingBoxplotPlugin.java @@ -84,19 +84,24 @@ protected void validateVisualizationSpec(FloatingBoxplotSpec pluginSpec) throws @Override protected List getRequestedStreams(FloatingBoxplotSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.add(pluginSpec.getXAxisVariable()); + plotVariableSpecs.add(pluginSpec.getYAxisVariable()); + plotVariableSpecs.add(Optional.ofNullable(pluginSpec.getOverlayConfig()).map(OverlayConfig::getOverlayVariable).orElse(null)); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVar(pluginSpec.getXAxisVariable()) - .addVar(pluginSpec.getYAxisVariable()) - .addVar(Optional.ofNullable(pluginSpec.getOverlayConfig()) - .map(OverlayConfig::getOverlayVariable) - .orElse(null))); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { PluginUtil util = getUtil(); FloatingBoxplotSpec spec = getPluginSpec(); + String outputEntityId = spec.getOutputEntityId(); VariableSpec overlayVariable = _overlaySpecification != null ? _overlaySpecification.getOverlayVariable() : null; Map varMap = new HashMap<>(); varMap.put("xAxis", spec.getXAxisVariable()); @@ -107,7 +112,7 @@ protected void writeResults(OutputStream out, Map dataStrea nonStrataVarColNames.add(util.toColNameOrEmpty(spec.getXAxisVariable())); nonStrataVarColNames.add(util.toColNameOrEmpty(spec.getYAxisVariable())); - List dataSpecsWithStudyDependentVocabs = findVariableSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); @@ -122,8 +127,8 @@ protected void writeResults(OutputStream out, Map dataStrea useRConnectionWithProcessedRemoteFiles(Resources.RSERVE_URL, filesProcessor, connection -> { String overlayValues = _overlaySpecification == null ? "NULL" : _overlaySpecification.getRBinListAsString(); - String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalVariableMetadataList(varMap)); + String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalVariableMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String cmd = "plot.data::box(data=" + inputData + ", " + "variables=variables, " + diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingContTablePlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingContTablePlugin.java index a1c9c9cd..00d7209e 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingContTablePlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingContTablePlugin.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -67,28 +68,35 @@ protected void validateVisualizationSpec(FloatingContTableSpec pluginSpec) throw @Override protected List getRequestedStreams(FloatingContTableSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.add(pluginSpec.getXAxisVariable()); + plotVariableSpecs.add(pluginSpec.getYAxisVariable()); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVar(pluginSpec.getXAxisVariable()) - .addVar(pluginSpec.getYAxisVariable())); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { PluginUtil util = getUtil(); FloatingContTableSpec spec = getPluginSpec(); + String outputEntityId = spec.getOutputEntityId(); Map varMap = new HashMap<>(); varMap.put("xAxis", spec.getXAxisVariable()); varMap.put("yAxis", spec.getYAxisVariable()); - List dataSpecsWithStudyDependentVocabs = findVariableSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithRemoteFiles(Resources.RSERVE_URL, dataStreams, connection -> { connection.voidEval(DEFAULT_SINGLE_STREAM_NAME + " <- data.table::fread('" + DEFAULT_SINGLE_STREAM_NAME + "', na.strings=c(''))"); - String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalVariableMetadataList(varMap)); + String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalVariableMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String cmd = "plot.data::mosaic(data=" + inputData + ", " + "variables=variables, " + "statistic='chiSq', " + diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingHistogramPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingHistogramPlugin.java index 4e9d3b2e..0eee4cff 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingHistogramPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingHistogramPlugin.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -84,18 +85,23 @@ protected void validateVisualizationSpec(FloatingHistogramSpec pluginSpec) throw @Override protected List getRequestedStreams(FloatingHistogramSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.add(pluginSpec.getXAxisVariable()); + plotVariableSpecs.add(Optional.ofNullable(pluginSpec.getOverlayConfig()).map(OverlayConfig::getOverlayVariable).orElse(null)); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVar(pluginSpec.getXAxisVariable()) - .addVar(Optional.ofNullable(pluginSpec.getOverlayConfig()) - .map(OverlayConfig::getOverlayVariable) - .orElse(null))); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { PluginUtil util = getUtil(); FloatingHistogramSpec spec = getPluginSpec(); + String outputEntityId = spec.getOutputEntityId(); VariableSpec overlayVariable = _overlaySpecification != null ? _overlaySpecification.getOverlayVariable() : null; Map varMap = new HashMap<>(); varMap.put("xAxis", spec.getXAxisVariable()); @@ -105,14 +111,14 @@ protected void writeResults(OutputStream out, Map dataStrea String xVarType = util.getVariableType(spec.getXAxisVariable()); String overlayValues = _overlaySpecification == null ? "NULL" : _overlaySpecification.getRBinListAsString(); - List dataSpecsWithStudyDependentVocabs = findVariableSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithRemoteFiles(Resources.RSERVE_URL, dataStreams, connection -> { connection.voidEval(DEFAULT_SINGLE_STREAM_NAME + " <- data.table::fread('" + DEFAULT_SINGLE_STREAM_NAME + "', na.strings=c(''))"); - String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalVariableMetadataList(varMap)); + String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalVariableMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String viewportRString = getViewportAsRString(spec.getViewport(), xVarType); connection.voidEval(viewportRString); diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingLineplotPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingLineplotPlugin.java index 01074d47..871dbf01 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingLineplotPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingLineplotPlugin.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -82,19 +83,24 @@ protected void validateVisualizationSpec(FloatingLineplotSpec pluginSpec) throws @Override protected List getRequestedStreams(FloatingLineplotSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.add(pluginSpec.getXAxisVariable()); + plotVariableSpecs.add(pluginSpec.getYAxisVariable()); + plotVariableSpecs.add(Optional.ofNullable(pluginSpec.getOverlayConfig()).map(OverlayConfig::getOverlayVariable).orElse(null)); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVar(pluginSpec.getXAxisVariable()) - .addVar(pluginSpec.getYAxisVariable()) - .addVar(Optional.ofNullable(pluginSpec.getOverlayConfig()) - .map(OverlayConfig::getOverlayVariable) - .orElse(null))); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { PluginUtil util = getUtil(); FloatingLineplotSpec spec = getPluginSpec(); + String outputEntityId = spec.getOutputEntityId(); VariableSpec overlayVariable = _overlaySpecification != null ? _overlaySpecification.getOverlayVariable() : null; Map varMap = new HashMap<>(); varMap.put("xAxis", spec.getXAxisVariable()); @@ -108,14 +114,14 @@ protected void writeResults(OutputStream out, Map dataStrea String denominatorValues = spec.getYAxisDenominatorValues() != null ? PluginUtil.listToRVector(spec.getYAxisDenominatorValues()) : "NULL"; String overlayValues = _overlaySpecification == null ? "NULL" : _overlaySpecification.getRBinListAsString(); - List dataSpecsWithStudyDependentVocabs = findVariableSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); useRConnectionWithRemoteFiles(Resources.RSERVE_URL, dataStreams, connection -> { connection.voidEval(DEFAULT_SINGLE_STREAM_NAME + " <- data.table::fread('" + DEFAULT_SINGLE_STREAM_NAME + "', na.strings=c(''))"); - String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalVariableMetadataList(varMap)); + String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalVariableMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String viewportRString = getViewportAsRString(spec.getViewport(), xVarType); connection.voidEval(viewportRString); diff --git a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingScatterplotPlugin.java b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingScatterplotPlugin.java index c7adcd7c..d2b4c841 100644 --- a/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingScatterplotPlugin.java +++ b/src/main/java/org/veupathdb/service/eda/ds/plugin/standalonemap/FloatingScatterplotPlugin.java @@ -91,19 +91,24 @@ protected void validateVisualizationSpec(FloatingScatterplotSpec pluginSpec) thr @Override protected List getRequestedStreams(FloatingScatterplotSpec pluginSpec) { + String outputEntityId = pluginSpec.getOutputEntityId(); + List plotVariableSpecs = new ArrayList(); + plotVariableSpecs.add(pluginSpec.getXAxisVariable()); + plotVariableSpecs.add(pluginSpec.getYAxisVariable()); + plotVariableSpecs.add(Optional.ofNullable(pluginSpec.getOverlayConfig()).map(OverlayConfig::getOverlayVariable).orElse(null)); + return ListBuilder.asList( - new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, pluginSpec.getOutputEntityId()) - .addVar(pluginSpec.getXAxisVariable()) - .addVar(pluginSpec.getYAxisVariable()) - .addVar(Optional.ofNullable(pluginSpec.getOverlayConfig()) - .map(OverlayConfig::getOverlayVariable) - .orElse(null))); + new StreamSpec(DEFAULT_SINGLE_STREAM_NAME, outputEntityId) + .addVars(plotVariableSpecs) + // TODO can we make this automagical? + .addVars(getVariableSpecsWithStudyDependentVocabs(pluginSpec.getOutputEntityId(), plotVariableSpecs))); } @Override protected void writeResults(OutputStream out, Map dataStreams) throws IOException { PluginUtil util = getUtil(); FloatingScatterplotSpec spec = getPluginSpec(); + String outputEntityId = spec.getOutputEntityId(); VariableSpec overlayVariable = _overlaySpecification != null ? _overlaySpecification.getOverlayVariable() : null; Map varMap = new HashMap<>(); varMap.put("xAxis", spec.getXAxisVariable()); @@ -121,7 +126,7 @@ protected void writeResults(OutputStream out, Map dataStrea nonStrataVarColNames.add(util.toColNameOrEmpty(spec.getXAxisVariable())); nonStrataVarColNames.add(util.toColNameOrEmpty(spec.getYAxisVariable())); - List dataSpecsWithStudyDependentVocabs = findVariableSpecsWithStudyDependentVocabs(varMap); + List dataSpecsWithStudyDependentVocabs = getDynamicDataSpecsWithStudyDependentVocabs(outputEntityId); Map studyVocabs = getVocabByRootEntity(dataSpecsWithStudyDependentVocabs); dataStreams.putAll(studyVocabs); @@ -135,8 +140,8 @@ protected void writeResults(OutputStream out, Map dataStrea ); useRConnectionWithProcessedRemoteFiles(Resources.RSERVE_URL, filesProcessor, connection -> { - String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, "variables"); - connection.voidEval(getVoidEvalVariableMetadataList(varMap)); + String inputData = getRVariableInputDataWithImputedZeroesAsString(DEFAULT_SINGLE_STREAM_NAME, varMap, outputEntityId, "variables"); + connection.voidEval(getVoidEvalVariableMetadataListWithStudyDependentVocabs(varMap, outputEntityId)); String cmd = "plot.data::scattergl(data=" + inputData + ", " +