From cfe123977117f51b9d312cb77c09045e2563fa67 Mon Sep 17 00:00:00 2001 From: EliotRagueneau Date: Tue, 14 Nov 2023 15:43:47 +0000 Subject: [PATCH] :sparkles::bug: Introduce importableOnly filter to fix gsa analysis issues when matching PUBCHEM entities --- pom.xml | 4 +- .../reactome/server/analysis/core/Main.java | 3 +- .../core/methods/IdentifiersMapping.java | 15 +- .../analysis/core/model/HierarchiesData.java | 39 ++- .../analysis/core/model/PathwayNodeData.java | 253 ++++++++++++++---- .../core/result/AnalysisStoredResult.java | 143 ++++++---- .../core/result/model/EntityStatistics.java | 14 +- .../core/result/model/PathwaySummary.java | 16 +- .../core/result/model/ReactionStatistics.java | 4 +- .../utils/ExternalAnalysisResultCheck.java | 2 +- .../server/analysis/core/util/MapSet.java | 5 + 11 files changed, 355 insertions(+), 143 deletions(-) diff --git a/pom.xml b/pom.xml index 90ed1a6f..6c67448c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ org.reactome.maven reactome-parent - 1.0.3 + 1.0.5-SNAPSHOT org.reactome.server.tools analysis-core - 3.4.7 + 3.4.8-SNAPSHOT jar The Reactome analysis-core extracts data from the graph-database to create the intermediate data format diff --git a/src/main/java/org/reactome/server/analysis/core/Main.java b/src/main/java/org/reactome/server/analysis/core/Main.java index 7a4a0b1f..a3c720a1 100644 --- a/src/main/java/org/reactome/server/analysis/core/Main.java +++ b/src/main/java/org/reactome/server/analysis/core/Main.java @@ -34,6 +34,7 @@ public static void main(String[] args) throws JSAPException { SimpleJSAP jsap = new SimpleJSAP(Main.class.getName(), "Connect to Reactome Graph Database", new Parameter[]{ new FlaggedOption("host", JSAP.STRING_PARSER, "bolt://localhost:7687", JSAP.NOT_REQUIRED, 'h', "host", "The neo4j host") + , new FlaggedOption("db", JSAP.STRING_PARSER, "graph.db", JSAP.NOT_REQUIRED, 'd', "db", "The neo4j database name") , new FlaggedOption("user", JSAP.STRING_PARSER, "neo4j", JSAP.NOT_REQUIRED, 'u', "user", "The neo4j user") , new FlaggedOption("password", JSAP.STRING_PARSER, "neo4jj", JSAP.REQUIRED, 'k', "password", "The neo4j password") , new FlaggedOption("output", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'o', "output", "The file where the results are written to") @@ -46,7 +47,7 @@ public static void main(String[] args) throws JSAPException { if (jsap.messagePrinted()) System.exit(1); //Initialising ReactomeCore Neo4j configuration - ReactomeGraphCore.initialise(config.getString("host"), config.getString("user"), config.getString("password"), AnalysisCoreNeo4jConfig.class); + ReactomeGraphCore.initialise(config.getString("host"), config.getString("user"), config.getString("password"), config.getString("db"), AnalysisCoreNeo4jConfig.class); TEST_MAIN_SPECIES = config.getBoolean("test"); VERBOSE = config.getBoolean("verbose"); diff --git a/src/main/java/org/reactome/server/analysis/core/methods/IdentifiersMapping.java b/src/main/java/org/reactome/server/analysis/core/methods/IdentifiersMapping.java index 7e30e924..b96822e3 100644 --- a/src/main/java/org/reactome/server/analysis/core/methods/IdentifiersMapping.java +++ b/src/main/java/org/reactome/server/analysis/core/methods/IdentifiersMapping.java @@ -10,6 +10,7 @@ import org.reactome.server.analysis.core.model.resource.Resource; import org.reactome.server.analysis.core.result.model.MappedEntity; import org.reactome.server.analysis.core.result.model.MappedIdentifier; +import org.reactome.server.analysis.core.result.utils.ExternalAnalysisResultCheck; import org.reactome.server.analysis.core.util.MapSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,9 +40,9 @@ public IdentifiersMapping(AnalysisData analysisData) { this.analysisData = analysisData; } - public List run(Set identifiers, SpeciesNode speciesNode, boolean includeInteractors) { + public List run(Set identifiers, SpeciesNode speciesNode, boolean includeInteractors, boolean importableOnly) { this.increaseCounter(); - MapSet mapping = getMapping(identifiers, speciesNode, includeInteractors); + MapSet mapping = getMapping(identifiers, speciesNode, includeInteractors, importableOnly); this.decreaseCounter(); List rtn = new ArrayList<>(); for (String identifier : mapping.keySet()) { @@ -54,7 +55,7 @@ public static long getMappingCount() { return MAPPING_COUNT; } - private MapSet getMapping(Set identifiers, SpeciesNode speciesNode, boolean includeInteractors) { + private MapSet getMapping(Set identifiers, SpeciesNode speciesNode, boolean includeInteractors, boolean importableOnly) { MapSet rtn = new MapSet<>(); final int originalSampleSize = identifiers.size(); @@ -67,9 +68,11 @@ private MapSet getMapping(Set identifiers, Spe MapSet resourceEntities = entitiesMap.get(identifier); for (Resource resource : resourceEntities.keySet()) { - for (EntityNode node : resourceEntities.getElements(resource)) { - if (speciesNode != null) node = node.getProjection(speciesNode); - if (node != null) rtn.add(identifier, new MappedIdentifier(node.getIdentifier())); + if (!importableOnly || ExternalAnalysisResultCheck.isValidResource(resource.getName())) { + for (EntityNode node : resourceEntities.getElements(resource)) { + if (speciesNode != null) node = node.getProjection(speciesNode); + if (node != null) rtn.add(identifier, new MappedIdentifier(node.getIdentifier())); + } } } diff --git a/src/main/java/org/reactome/server/analysis/core/model/HierarchiesData.java b/src/main/java/org/reactome/server/analysis/core/model/HierarchiesData.java index d80ea603..3881f28b 100644 --- a/src/main/java/org/reactome/server/analysis/core/model/HierarchiesData.java +++ b/src/main/java/org/reactome/server/analysis/core/model/HierarchiesData.java @@ -21,17 +21,17 @@ public HierarchiesData(Map pathwayHierarchies, Ma this.pathwayLocation = pathwayLocation; } - public void addNotFound(AnalysisIdentifier identifier){ + public void addNotFound(AnalysisIdentifier identifier) { this.notFound.add(identifier); } - public List getUniqueHitPathways(SpeciesNode species){ + public List getUniqueHitPathways(SpeciesNode species) { Set found = new HashSet<>(); List rtn = new LinkedList<>(); for (PathwayNode pathwayNode : this.getHitPathways()) { - if(species==null || pathwayNode.getSpecies().equals(species)){ + if (species == null || pathwayNode.getSpecies().equals(species)) { SpeciesPathway sp = new SpeciesPathway(pathwayNode); - if(!found.contains(sp)){ + if (!found.contains(sp)) { rtn.add(pathwayNode); found.add(sp); } @@ -45,7 +45,7 @@ public Map getPathwayHierarchies() { return pathwayHierarchies; } - private Set getHitPathways(){ + private Set getHitPathways() { Set rtn = new HashSet<>(); for (SpeciesNode species : pathwayHierarchies.keySet()) { rtn.addAll(pathwayHierarchies.get(species).getHitPathways()); @@ -62,7 +62,7 @@ public MapSet getPathwayLocation() { } @SuppressWarnings("ConstantConditions") - public void setResultStatistics(Map sampleSizePerResource, Integer notFound, boolean includeInteractors){ + public void setResultStatistics(Map sampleSizePerResource, Integer notFound, boolean includeInteractors) { for (SpeciesNode species : this.pathwayHierarchies.keySet()) { PathwayHierarchy hierarchy = this.pathwayHierarchies.get(species); for (PathwayRoot node : hierarchy.getChildren()) { @@ -79,21 +79,32 @@ public void setResultStatistics(Map sampleSizePerResource //Contains several sets of PathwayStatistic objects depending on the main resource (this one is used to calculate //the entities FDR result based on the entities pValues MapSet pathwayResourceEntityPValue = new MapSet(); + MapSet pathwayResourceEntityPValueImportable = new MapSet<>(); //This one does not depend on main resource because is for the combined result of the entities FDR based in their pValues - List pathwayEntityPValue = new LinkedList(); + List pathwayEntityPValue = new LinkedList<>(); + List pathwayEntityPValueImportable = new LinkedList<>(); //First thing we have to do, is iterate over the hit pathways and populate the lists (and MapSet) defined above for (PathwayNode node : hierarchy.getHitPathways()) { PathwayNodeData nodeData = node.getPathwayNodeData(); + boolean hasImportable = false; + for (MainResource resource : nodeData.getResources()) { Double pValue = nodeData.getEntitiesPValue(resource); - if(pValue!=null) + if (pValue != null) { pathwayResourceEntityPValue.add(resource, new PathwayStatistic(node, pValue)); + if (!resource.isAuxMainResource()) { + hasImportable = true; + pathwayResourceEntityPValueImportable.add(resource, new PathwayStatistic(node, pValue)); + } + } } Double pValue = nodeData.getEntitiesPValue(); pathwayEntityPValue.add(new PathwayStatistic(node, pValue)); + if (hasImportable) + pathwayEntityPValueImportable.add(new PathwayStatistic(node, nodeData.getEntitiesPValue(true))); } /* Here we have to iterate over the different resources where the "individual" results have been found @@ -116,8 +127,15 @@ public void setResultStatistics(Map sampleSizePerResource this.setFDRWithBenjaminiHochberg(pathwayEntityPValue); for (PathwayStatistic pathwayStatistic : pathwayEntityPValue) { PathwayNodeData nodeData = pathwayStatistic.getPathwayNode().getPathwayNodeData(); - nodeData.setEntitiesFDR(pathwayStatistic.getFDR()); + nodeData.setEntitiesFDR(false, pathwayStatistic.getFDR()); } + + this.setFDRWithBenjaminiHochberg(pathwayEntityPValueImportable); + for (PathwayStatistic pathwayStatistic : pathwayEntityPValueImportable) { + PathwayNodeData nodeData = pathwayStatistic.getPathwayNode().getPathwayNodeData(); + nodeData.setEntitiesFDR(true, pathwayStatistic.getFDR()); + } + } } @@ -125,6 +143,7 @@ public void setResultStatistics(Map sampleSizePerResource * Use this method to calculate FDR from a list of pvalues using Benjamini-Hochberg * method. The implementation of this method is based on the source code for MEMo * (http://cbio.mskcc.org/tools/memo/). + * * @param list a list of PathwayStatic objects representing the hit pathways and their pValue */ private void setFDRWithBenjaminiHochberg(List list) { @@ -141,7 +160,7 @@ private void setFDRWithBenjaminiHochberg(List list) { } } - private class PathwayStatistic implements Comparable{ + private class PathwayStatistic implements Comparable { private PathwayNode pathwayNode; private Double pValue; private Double fdr; diff --git a/src/main/java/org/reactome/server/analysis/core/model/PathwayNodeData.java b/src/main/java/org/reactome/server/analysis/core/model/PathwayNodeData.java index 66134132..548c3faf 100644 --- a/src/main/java/org/reactome/server/analysis/core/model/PathwayNodeData.java +++ b/src/main/java/org/reactome/server/analysis/core/model/PathwayNodeData.java @@ -11,6 +11,9 @@ import org.reactome.server.analysis.core.util.MathUtilities; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * For each pathway, this class contains the result of the analysis. There are three main parts in @@ -24,9 +27,10 @@ public class PathwayNodeData { //Please note that counter is used for each main identifier and for the combinedResult class Counter { - Counter() { } + Counter() { + } - Counter(ExternalStatistics counter){ + Counter(ExternalStatistics counter) { this.totalEntities = counter.getEntitiesCount(); this.foundEntities = counter.getEntitiesFound(); this.entitiesRatio = counter.getEntitiesRatio(); @@ -94,6 +98,7 @@ class Counter { //Analysis result containers private Map entitiesResult = new HashMap<>(); private Counter combinedResult = new Counter(); //All main identifiers combined in one result + private Counter importableResult = new Counter(); //All importable identifiers combined in one result public PathwayNodeData() { } @@ -103,6 +108,7 @@ public PathwayNodeData(ExternalPathwayNodeData data) { for (ExternalStatistics statistics : data.getStatistics()) { if ("TOTAL".equals(statistics.getResource())) { this.combinedResult = new Counter(statistics); + this.importableResult = new Counter(statistics); } else { MainResource mr = ResourceFactory.getMainResource(statistics.getResource()); this.entitiesResult.put(mr, new Counter(statistics)); @@ -157,11 +163,15 @@ public void addReactions(MainResource mainResource, Set reacti } - public Integer getEntitiesAndInteractorsCount(){ - return combinedResult.totalFound; + public Integer getEntitiesAndInteractorsCount() { + return this.getEntitiesAndInteractorsCount(false); + } + + public Integer getEntitiesAndInteractorsCount(boolean importableOnly) { + return !importableOnly ? combinedResult.totalFound : importableResult.totalFound; } - public Integer getEntitiesAndInteractorsCount(MainResource resource){ + public Integer getEntitiesAndInteractorsCount(MainResource resource) { Counter counter = this.entitiesResult.get(resource); if (counter != null) { return counter.totalFound; @@ -170,11 +180,14 @@ public Integer getEntitiesAndInteractorsCount(MainResource resource){ } public Integer getEntitiesAndInteractorsFound() { - int total = 0; - for (MainResource resource : foundTotal.keySet()) { - total += foundTotal.getElements(resource).size(); - } - return total; + return foundTotal.stream().mapToInt(entry -> entry.getValue().size()).sum(); + } + + public Integer getEntitiesAndInteractorsFound(boolean importableOnly) { + var stream = !importableOnly ? + foundTotal.stream() : + foundTotal.stream().filter(entry -> !entry.getKey().isAuxMainResource()); + return stream.mapToInt(entry -> entry.getValue().size()).sum(); } public Integer getEntitiesAndInteractorsFound(MainResource resource) { @@ -194,11 +207,11 @@ public Set getFoundEntities() { return rtn; } - public List getExternalEntities(){ + public List getExternalEntities() { List rtn = new ArrayList<>(); for (Identifier identifier : entities.keySet()) { - ExternalIdentifier ei = new ExternalIdentifier(identifier.getValue()); + ExternalIdentifier ei = new ExternalIdentifier(identifier.getValue()); for (MainIdentifier mainIdentifier : entities.getElements(identifier)) { ExternalMainIdentifier emi = new ExternalMainIdentifier(mainIdentifier); ei.addMapsTo(emi); @@ -208,6 +221,13 @@ public List getExternalEntities(){ return rtn; } + public Set getFoundEntities(boolean importableOnly) { + Stream identifiers = importableOnly ? + entities.values().stream().filter(id -> !id.getResource().isAuxMainResource()) : + entities.values().stream(); + return identifiers.map(Identifier::getValue).collect(Collectors.toSet()); + } + public Set getFoundEntities(MainResource resource) { Set rtn = new HashSet<>(); for (Identifier identifier : entities.keySet()) { @@ -273,6 +293,19 @@ private List getEntitiesDuplication() { return rtn; } + private List getEntitiesDuplication(boolean importableOnly) { + return !importableOnly ? + entities.stream() + .flatMap(entry -> entry.getValue().stream().map(MainIdentifier::getValue)) + .collect(Collectors.toCollection(LinkedList::new)) : + + entities.stream() + .flatMap(entry -> entry.getValue().stream()) + .filter(id -> !id.getResource().isAuxMainResource()) + .map(MainIdentifier::getValue) + .collect(Collectors.toCollection(LinkedList::new)); + } + private List getEntitiesDuplication(MainResource resource) { List rtn = new LinkedList<>(); for (Identifier identifier : entities.keySet()) { @@ -293,6 +326,18 @@ private List getInteractorsDuplication() { return rtn; } + private List getInteractorsDuplication(boolean importableOnly) { + return !importableOnly ? + interactors.stream() + .flatMap(entry -> entry.getValue().stream()) + .collect(Collectors.toCollection(LinkedList::new)) : + + interactors.stream() + .filter(entry -> !entry.getKey().getResource().isAuxMainResource()) + .flatMap(entry -> entry.getValue().stream()) + .collect(Collectors.toCollection(LinkedList::new)); + } + private List getInteractorsDuplication(MainResource resource) { List rtn = new LinkedList<>(); for (MainIdentifier mainIdentifier : interactors.keySet()) { @@ -308,9 +353,15 @@ public List getExpressionValuesAvg() { return calculateAverage(groupEntitiesExpressionValues(getEntitiesDuplication(), getInteractorsDuplication())); } + public List getExpressionValuesAvg(boolean importableOnly) { + if (!importableOnly) return this.getExpressionValuesAvg(); + if (importableResult.exp != null && !importableResult.exp.isEmpty()) return importableResult.exp; + return calculateAverage(groupEntitiesExpressionValues(getEntitiesDuplication(true), getInteractorsDuplication(true))); + } + public List getExpressionValuesAvg(MainResource resource) { final Counter counter = entitiesResult.get(resource); - if(counter!=null && counter.exp!=null && !counter.exp.isEmpty()) return counter.exp; + if (counter != null && counter.exp != null && !counter.exp.isEmpty()) return counter.exp; return calculateAverage(groupEntitiesExpressionValues(getEntitiesDuplication(resource), getInteractorsDuplication(resource))); } @@ -318,6 +369,10 @@ public Integer getEntitiesCount() { return this.combinedResult.totalEntities; } + public Integer getEntitiesCount(boolean importableOnly) { + return !importableOnly ? this.combinedResult.totalEntities : this.importableResult.totalEntities; + } + public Integer getEntitiesCount(MainResource resource) { Counter counter = this.entitiesResult.get(resource); if (counter != null) { @@ -330,6 +385,10 @@ public Integer getEntitiesFound() { return getFoundEntities().size(); } + public Integer getEntitiesFound(boolean importableOnly) { + return getFoundEntities(importableOnly).size(); + } + public Integer getEntitiesFound(MainResource resource) { return getFoundEntities(resource).size(); } @@ -338,6 +397,10 @@ public Double getEntitiesPValue() { return this.combinedResult.entitiesPValue; } + public Double getEntitiesPValue(boolean importableOnly) { + return !importableOnly ? this.combinedResult.entitiesPValue : this.importableResult.entitiesPValue; + } + public Double getEntitiesPValue(MainResource resource) { Counter counter = this.entitiesResult.get(resource); if (counter != null) { @@ -350,6 +413,10 @@ public Double getEntitiesFDR() { return this.combinedResult.entitiesFDR; } + public Double getEntitiesFDR(boolean importableOnly) { + return !importableOnly ? this.combinedResult.entitiesFDR : this.importableResult.entitiesFDR; + } + public Double getEntitiesFDR(MainResource resource) { Counter counter = this.entitiesResult.get(resource); if (counter != null) { @@ -362,6 +429,11 @@ public Double getEntitiesRatio() { return this.combinedResult.entitiesRatio; } + public Double getEntitiesRatio(boolean importableOnly) { + return !importableOnly ? this.combinedResult.entitiesRatio : this.importableResult.entitiesRatio; + } + + public Double getEntitiesRatio(MainResource resource) { Counter counter = this.entitiesResult.get(resource); if (counter != null) { @@ -374,6 +446,10 @@ public Double getInteractorsRatio() { return this.combinedResult.interactorsRatio; } + public Double getInteractorsRatio(boolean importableOnly) { + return !importableOnly ? this.combinedResult.interactorsRatio : this.importableResult.interactorsRatio; + } + public Double getInteractorsRatio(MainResource resource) { Counter counter = this.entitiesResult.get(resource); if (counter != null) { @@ -394,11 +470,20 @@ public MapSet getInteractorMap() { // INTERACTORS Result - public Set getFoundInteractors(){ + public Set getFoundInteractors() { return interactors.values(); } - public Set getFoundInteractors(MainResource resource){ + public Set getFoundInteractors(boolean importableOnly) { + return !importableOnly ? + interactors.values() : + interactors.stream() + .filter(entry -> !entry.getKey().getResource().isAuxMainResource()) + .flatMap(entry -> entry.getValue().stream()) + .collect(Collectors.toSet()); + } + + public Set getFoundInteractors(MainResource resource) { Set rtn = new HashSet<>(); for (MainIdentifier mainIdentifier : interactors.keySet()) { if (mainIdentifier.getResource().equals(resource)) { @@ -408,11 +493,15 @@ public Set getFoundInteractors(MainResource resource){ return rtn; } - public Integer getInteractorsCount(){ + public Integer getInteractorsCount() { return this.combinedResult.totalInteractors; } - public Integer getInteractorsCount(MainResource resource){ + public Integer getInteractorsCount(boolean importableOnly) { + return !importableOnly ? this.combinedResult.totalInteractors : this.importableResult.totalInteractors; + } + + public Integer getInteractorsCount(MainResource resource) { Counter counter = this.entitiesResult.get(resource); if (counter != null) { return counter.totalInteractors; @@ -420,7 +509,7 @@ public Integer getInteractorsCount(MainResource resource){ return 0; } - public Integer getInteractorsFound(){ + public Integer getInteractorsFound() { Set mapsTo = new HashSet<>(); for (InteractorIdentifier interactor : getFoundInteractors()) { mapsTo.add(interactor.getMapsTo()); @@ -428,7 +517,16 @@ public Integer getInteractorsFound(){ return mapsTo.size(); } - public Integer getInteractorsFound(MainResource resource){ + public Integer getInteractorsFound(boolean importableOnly) { + return Math.toIntExact( + getFoundInteractors(importableOnly).stream() + .map(InteractorIdentifier::getMapsTo) + .distinct() + .count() + ); + } + + public Integer getInteractorsFound(MainResource resource) { Set mapsTo = new HashSet<>(); for (InteractorIdentifier interactor : getFoundInteractors(resource)) { mapsTo.add(interactor.getMapsTo()); @@ -464,9 +562,18 @@ public Set getReactions() { return reactions.values(); } + public Set getReactions(boolean importableOnly) { + return !importableOnly ? + reactions.values() : + reactions.stream() + .filter(entry -> !entry.getKey().isAuxMainResource()) + .flatMap(entry -> entry.getValue().stream()) + .collect(Collectors.toSet()); + } + public Set getReactions(MainResource resource) { Set rtn = reactions.getElements(resource); - if(rtn==null){ + if (rtn == null) { rtn = new HashSet<>(); } return rtn; @@ -488,9 +595,13 @@ public Integer getReactionsCount() { return this.combinedResult.totalReactions; } + public Integer getReactionsCount(boolean importableOnly) { + return !importableOnly ? this.combinedResult.totalReactions : this.importableResult.totalReactions; + } + public Integer getReactionsCount(MainResource mainResource) { Counter counter = this.entitiesResult.get(mainResource); - if(counter!=null){ + if (counter != null) { return counter.totalReactions; } return 0; @@ -502,60 +613,81 @@ public Integer getInteractorsReactionsCount() { public Integer getInteractorsReactionsCount(MainResource mainResource) { Counter counter = this.entitiesResult.get(mainResource); - if(counter!=null){ + if (counter != null) { return counter.totalReactions; } return 0; } - public Integer getReactionsFound(){ + public Integer getReactionsFound() { return this.getReactions().size(); } - public Integer getReactionsFound(MainResource resource){ + public Integer getReactionsFound(boolean importableOnly) { + return this.getReactions(importableOnly).size(); + } + + public Integer getReactionsFound(MainResource resource) { return this.getReactions(resource).size(); } - public Double getReactionsRatio(){ + public Double getReactionsRatio() { return this.combinedResult.reactionsRatio; } - public Double getReactionsRatio(MainResource resource){ + public Double getReactionsRatio(boolean importableOnly) { + return !importableOnly ? this.combinedResult.reactionsRatio : this.importableResult.reactionsRatio; + } + + public Double getReactionsRatio(MainResource resource) { Counter counter = this.entitiesResult.get(resource); - if(counter !=null){ + if (counter != null) { return counter.reactionsRatio; } return null; } - public Set getResources(){ + public Set getResources() { return this.entitiesResult.keySet(); } - public boolean hasResult(){ + public boolean hasResult() { return !foundTotal.isEmpty(); // return !entities.isEmpty() || !interactors.isEmpty(); } - public void setEntitiesFDR(Double fdr){ + public void setEntitiesFDR(Double fdr) { this.combinedResult.entitiesFDR = fdr; } - public void setEntitiesFDR(MainResource resource, Double fdr){ + public void setEntitiesFDR(boolean importableOnly, Double fdr) { + if (!importableOnly) + this.combinedResult.entitiesFDR = fdr; + else + this.importableResult.entitiesFDR = fdr; + } + + public void setEntitiesFDR(MainResource resource, Double fdr) { this.entitiesResult.get(resource).entitiesFDR = fdr; } //This is only called in build time - void setCounters(PathwayNodeData speciesData){ + void setCounters(PathwayNodeData speciesData) { Set totalReactions = new HashSet<>(); + Set importableReactions = new HashSet<>(); for (MainResource mainResource : reactions.keySet()) { Counter counter = getOrCreateCounter(mainResource); counter.totalReactions = reactions.getElements(mainResource).size(); + counter.reactionsRatio = counter.totalReactions / speciesData.getReactionsCount(mainResource).doubleValue(); totalReactions.addAll(reactions.getElements(mainResource)); - counter.reactionsRatio = counter.totalReactions/speciesData.getReactionsCount(mainResource).doubleValue(); - } - combinedResult.totalReactions += totalReactions.size(); totalReactions.clear(); - combinedResult.reactionsRatio = combinedResult.totalReactions /speciesData.getReactionsCount().doubleValue(); + if (!mainResource.isAuxMainResource()) importableReactions.addAll(reactions.getElements(mainResource)); + } + combinedResult.totalReactions += totalReactions.size(); + importableResult.totalReactions += importableReactions.size(); + totalReactions.clear(); + importableReactions.clear(); + combinedResult.reactionsRatio = combinedResult.totalReactions / speciesData.getReactionsCount().doubleValue(); + importableResult.reactionsRatio = importableResult.totalReactions / speciesData.getReactionsCount().doubleValue(); reactions = new MapSet<>(); MapSet aux = new MapSet<>(); @@ -567,12 +699,16 @@ void setCounters(PathwayNodeData speciesData){ for (MainResource mainResource : aux.keySet()) { Counter counter = this.getOrCreateCounter(mainResource); counter.totalEntities = aux.getElements(mainResource).size(); - counter.entitiesRatio = counter.totalEntities/speciesData.getEntitiesCount(mainResource).doubleValue(); + counter.entitiesRatio = counter.totalEntities / speciesData.getEntitiesCount(mainResource).doubleValue(); counter.totalFound = getEntitiesAndInteractorsFound(mainResource); combinedResult.totalEntities += counter.totalEntities; + if (!mainResource.isAuxMainResource()) + importableResult.totalEntities += counter.totalEntities; } combinedResult.entitiesRatio = this.combinedResult.totalEntities / speciesData.getEntitiesCount().doubleValue(); - combinedResult.totalFound = getEntitiesAndInteractorsFound(); + importableResult.entitiesRatio = this.importableResult.totalEntities / speciesData.getEntitiesCount().doubleValue(); + combinedResult.totalFound = getEntitiesAndInteractorsFound(false); + importableResult.totalFound = getEntitiesAndInteractorsFound(true); entities = new MapSet<>(); @@ -591,16 +727,18 @@ void setCounters(PathwayNodeData speciesData){ Set interactors = temp.getElements(mainResource); counter.totalInteractors = interactors == null ? 0 : interactors.size(); counter.interactorsRatio = counter.totalFound / speciesData.getEntitiesAndInteractorsCount(mainResource).doubleValue(); - if(counter.interactorsRatio.isNaN() || counter.interactorsRatio.isInfinite() ){ + if (counter.interactorsRatio.isNaN() || counter.interactorsRatio.isInfinite()) { counter.interactorsRatio = 0.0; } combinedResult.totalInteractors += counter.totalInteractors; + if (!mainResource.isAuxMainResource()) importableResult.totalInteractors += counter.totalInteractors; } combinedResult.interactorsRatio = this.combinedResult.totalFound / speciesData.getEntitiesAndInteractorsCount().doubleValue(); + importableResult.interactorsRatio = this.importableResult.totalFound / speciesData.getEntitiesAndInteractorsCount().doubleValue(); foundTotal = new MapSet<>(); } - public void setResultStatistics(Map sampleSizePerResource, Integer notFound, boolean includeInteractors){ + public void setResultStatistics(Map sampleSizePerResource, Integer notFound, boolean includeInteractors) { for (MainResource mainResource : this.getResources()) { Counter counter = this.entitiesResult.get(mainResource); counter.foundEntities = getEntitiesFound(mainResource); @@ -620,41 +758,52 @@ public void setResultStatistics(Map sampleSizePerResource } } - Counter counter = combinedResult; - counter.foundEntities = getEntitiesFound(); + setAggregatingCounterStatistics(combinedResult, sampleSizePerResource, notFound, includeInteractors, false); + setAggregatingCounterStatistics(importableResult, sampleSizePerResource, notFound, includeInteractors, true); + } + + private void setAggregatingCounterStatistics(Counter counter, Map sampleSizePerResource, Integer notFound, boolean includeInteractors, boolean importableOnly) { + counter.foundEntities = getEntitiesFound(importableOnly); int found; - if(includeInteractors) { - counter.foundInteractors = getInteractorsFound(); - found = getEntitiesAndInteractorsFound(); + if (includeInteractors) { + counter.foundInteractors = getInteractorsFound(importableOnly); + found = getEntitiesAndInteractorsFound(importableOnly); } else { found = counter.foundEntities; } - if( found > 0 ){ + if (found > 0) { Integer sampleSize = notFound; for (MainResource mainResource : sampleSizePerResource.keySet()) { - sampleSize += sampleSizePerResource.get(mainResource); + if (!importableOnly || !mainResource.isAuxMainResource()) { + sampleSize += sampleSizePerResource.get(mainResource); + } } double ratio = includeInteractors ? counter.interactorsRatio : counter.entitiesRatio; counter.entitiesPValue = MathUtilities.calculatePValue(ratio, sampleSize, counter.foundEntities); } - counter.foundReactions = getReactionsFound(); + counter.foundReactions = getReactionsFound(importableOnly); } - protected Double getScore(){ + + protected Double getScore() { return getScore(this.combinedResult); } - protected Double getScore(MainResource mainResource){ + protected Double getScore(boolean importableOnly) { + return getScore(this.importableResult); + } + + protected Double getScore(MainResource mainResource) { return getScore(this.entitiesResult.get(mainResource)); } - private Double getScore(Counter counter){ + private Double getScore(Counter counter) { double entitiesPercentage = counter.foundEntities / counter.totalEntities.doubleValue(); double reactionsPercentage = counter.foundReactions / counter.totalReactions.doubleValue(); return (0.75 * (reactionsPercentage)) + (0.25 * (entitiesPercentage)); } - private Counter getOrCreateCounter(MainResource mainResource){ + private Counter getOrCreateCounter(MainResource mainResource) { Counter counter = this.entitiesResult.get(mainResource); if (counter == null) { counter = new Counter(); diff --git a/src/main/java/org/reactome/server/analysis/core/result/AnalysisStoredResult.java b/src/main/java/org/reactome/server/analysis/core/result/AnalysisStoredResult.java index 9431c523..0c9fa3fb 100644 --- a/src/main/java/org/reactome/server/analysis/core/result/AnalysisStoredResult.java +++ b/src/main/java/org/reactome/server/analysis/core/result/AnalysisStoredResult.java @@ -38,7 +38,7 @@ public AnalysisStoredResult(UserData userData, HierarchiesData data) { } public AnalysisStoredResult(String token, ExternalAnalysisResult result) { - this.summary = new AnalysisSummary(token, result.getSummary()); + this.summary = new AnalysisSummary(token, result.getSummary()); this.expressionSummary = new ExpressionSummary(result.getExpressionSummary()); this.pathways = new ArrayList<>(); this.warnings = result.getWarnings(); @@ -77,7 +77,7 @@ public void setHitPathways(List pathwayNodes) { Integer total = 0; for (PathwayNode pathwayNode : pathwayNodes) { PathwayNodeData data = pathwayNode.getPathwayNodeData(); - if(data.getEntitiesPValue() == null) continue; + if (data.getEntitiesPValue() == null) continue; total++; for (MainResource mr : pathwayNode.getPathwayNodeData().getResources()) { @@ -198,38 +198,16 @@ public MapSet getFoundEntitiesMap(MainResource mainR return rtn; } - public Set getFoundReactions(String pathwayId, String resource) { - Set rtn = new HashSet<>(); - if (resource.toUpperCase().equals("TOTAL")) { - for (PathwayNodeSummary pathway : this.pathways) { - if (pathway.is(pathwayId)) { - for (AnalysisReaction reaction : pathway.getData().getReactions()) { - rtn.add(reaction.getDbId()); - } - } - } - } else { - Resource r = ResourceFactory.getResource(resource); - if (r instanceof MainResource) { - MainResource mainResource = (MainResource) r; - for (PathwayNodeSummary pathway : this.pathways) { - if (pathway.is(pathwayId)) { - for (AnalysisReaction reaction : pathway.getData().getReactions(mainResource)) { - rtn.add(reaction.getDbId()); - } - } - } - } - } - return rtn; + public Set getFoundReactions(String pathwayId, String resource, boolean importableOnly) { + return this.getFoundReactions(List.of(pathwayId), resource, importableOnly); } - public Set getFoundReactions(List pathwayIds, String resource) { + public Set getFoundReactions(List pathwayIds, String resource, boolean importableOnly) { Set rtn = new HashSet<>(); if (resource.toUpperCase().equals("TOTAL")) { for (PathwayNodeSummary pathway : this.pathways) { if (pathway.in(pathwayIds)) { - for (AnalysisReaction reaction : pathway.getData().getReactions()) { + for (AnalysisReaction reaction : pathway.getData().getReactions(importableOnly)) { rtn.add(reaction.getDbId()); } } @@ -250,6 +228,36 @@ public Set getFoundReactions(List pathwayIds, String resource) { return rtn; } +// public Set getFoundReactions(String pathwayId, String resource, boolean importableOnly) { +// return this.getFoundReactions(List.of(pathwayId), resource, importableOnly); +// } + +// public Set getFoundReactions(List pathwayIds, String resource, boolean importableOnly) { +// Set rtn = new HashSet<>(); +// if (resource.toUpperCase().equals("TOTAL")) { +// for (PathwayNodeSummary pathway : this.pathways) { +// if (pathway.in(pathwayIds)) { +// for (AnalysisReaction reaction : pathway.getData().getReactions(importableOnly)) { +// rtn.add(reaction.getDbId()); +// } +// } +// } +// } else { +// Resource r = ResourceFactory.getResource(resource); +// if (r instanceof MainResource) { +// MainResource mainResource = (MainResource) r; +// for (PathwayNodeSummary pathway : this.pathways) { +// if (pathway.in(pathwayIds)) { +// for (AnalysisReaction reaction : pathway.getData().getReactions(mainResource)) { +// rtn.add(reaction.getDbId()); +// } +// } +// } +// } +// } +// return rtn; +// } + public Set getNotFound() { return notFound; } @@ -275,7 +283,7 @@ public List getPathways() { return pathways; } - public int getPage(String pathwayId, String sortBy, String order, String resource, Integer pageSize){ + public int getPage(String pathwayId, String sortBy, String order, String resource, Integer pageSize) { Collections.sort(this.pathways, getComparator(sortBy, order, resource)); if (pageSize == null) pageSize = PAGE_SIZE; for (int i = 0; i < this.pathways.size(); i++) { @@ -295,19 +303,19 @@ public List getSpeciesSummary() { return speciesSummary; } - public AnalysisResult getResultSummary(String resource) { - return getResultSummary(null, "ASC", resource, null, null); + public AnalysisResult getResultSummary(String resource, boolean importableOnly) { + return getResultSummary(null, "ASC", resource, null, null, importableOnly); } - public AnalysisStoredResult filterPathways(String resource) { - return filterPathways(resource, null, true, null, null); + public AnalysisStoredResult filterPathways(String resource, boolean importableOnly) { + return filterPathways(resource, null, true, null, null, importableOnly); } - public AnalysisStoredResult filterPathways(String resource, Double pValue, boolean includeDisease, Integer min, Integer max) { - return filterPathways(null, resource, pValue, includeDisease, min, max); + public AnalysisStoredResult filterPathways(String resource, Double pValue, boolean includeDisease, Integer min, Integer max, boolean importableOnly) { + return filterPathways(null, resource, pValue, includeDisease, min, max, importableOnly); } - public AnalysisStoredResult filterPathways(List species, String resource, Double pValue, boolean includeDisease, Integer min, Integer max) { + public AnalysisStoredResult filterPathways(List species, String resource, Double pValue, boolean includeDisease, Integer min, Integer max, boolean importableOnly) { final boolean includeInteractors = summary.isInteractors(); MainResource mr = ResourceFactory.getMainResource(resource); List pathways = new LinkedList<>(); @@ -322,27 +330,27 @@ public AnalysisStoredResult filterPathways(List species, String resourc this.getSpeciesSummary().forEach(s -> speciesHits.put(s.getSpeciesNode(), 0)); for (PathwayNodeSummary pathway : this.pathways) { - if(!includeDisease && pathway.isInDisease()) continue; + if (!includeDisease && pathway.isInDisease()) continue; PathwayNodeData data = pathway.getData(); - Double pwypValue = (mr == null) ? data.getEntitiesPValue() : data.getEntitiesPValue(mr); + Double pwypValue = (mr == null) ? data.getEntitiesPValue(importableOnly) : data.getEntitiesPValue(mr); if (pwypValue == null) continue; boolean toAdd = pValue == null || pwypValue <= pValue; final int found = (mr == null) ? - data.getEntitiesFound() + data.getInteractorsFound() : + data.getEntitiesFound(importableOnly) + data.getInteractorsFound(importableOnly) : data.getEntitiesFound(mr) + data.getInteractorsFound(mr); toAdd &= found > 0; final int size = (mr == null) ? - data.getEntitiesCount() + (includeInteractors ? data.getInteractorsCount() : 0) : + data.getEntitiesCount(importableOnly) + (includeInteractors ? data.getInteractorsCount(importableOnly) : 0) : data.getEntitiesCount(mr) + (includeInteractors ? data.getInteractorsCount(mr) : 0); toAdd &= (min == null || max == null) ? size > 0 : min <= size && max >= size; toAdd &= species == null || species.isEmpty() || pathway.getSpecies().isIn(species); - if (toAdd){ + if (toAdd) { pathways.add(pathway); resourceTotal += 1; for (MainResource r : data.getResources()) { - if (data.getEntitiesPValue(r) != null) { + if ((!importableOnly || !r.isAuxMainResource()) && data.getEntitiesPValue(r) != null) { resourceHits.put(r.getName(), resourceHits.getOrDefault(r.getName(), 0) + 1); } } @@ -356,6 +364,33 @@ public AnalysisStoredResult filterPathways(List species, String resourc return this; } + public AnalysisStoredResult filterPathwaysImportableOnly(boolean importableOnly) { + List pathways = new LinkedList<>(); + + int resourceTotal = 0; + Map resourceHits = new HashMap<>(); + this.resourceSummary.stream() + .filter(rs -> rs.getPathways() > 0 && !rs.getResource().equals("TOTAL")) + .forEach(rs -> resourceHits.put(rs.getResource(), 0)); + + for (PathwayNodeSummary pathway : this.pathways) { + PathwayNodeData data = pathway.getData(); + + if (data.getResources().stream().allMatch(MainResource::isAuxMainResource)) continue; + + pathways.add(pathway); + resourceTotal += 1; + for (MainResource r : data.getResources()) { + if (!r.isAuxMainResource() && data.getEntitiesPValue(r) != null) { + resourceHits.put(r.getName(), resourceHits.getOrDefault(r.getName(), 0) + 1); + } + } + } + this.pathways = pathways; + setResourceSummaryFiltered(resourceHits, resourceTotal); + return this; + } + private void setSpeciesSummaryFiltered(Map speciesHits) { for (SpeciesSummary ss : speciesSummary) { ss.setFiltered(speciesHits.get(ss.getSpeciesNode())); @@ -370,7 +405,7 @@ private void setResourceSummaryFiltered(Map resourceHits, Integ } } - public AnalysisResult getResultSummary(String sortBy, String order, String resource, Integer pageSize, Integer page) { + public AnalysisResult getResultSummary(String sortBy, String order, String resource, Integer pageSize, Integer page, boolean importableOnly) { // this.filterPathways(species, resource, pValue, includeDisease, min, max); Collections.sort(this.pathways, getComparator(sortBy, order, resource)); if (pageSize == null) pageSize = PAGE_SIZE; @@ -379,11 +414,11 @@ public AnalysisResult getResultSummary(String sortBy, String order, String resou int end = (pageSize * page) > this.pathways.size() ? this.pathways.size() : (pageSize * page); for (int i = pageSize * (page - 1); i < end; ++i) { PathwayNodeSummary pathwayNodeSummary = this.pathways.get(i); - rtn.add(new PathwaySummary(pathwayNodeSummary, resource.toUpperCase(), summary.isInteractors())); + rtn.add(new PathwaySummary(pathwayNodeSummary, resource.toUpperCase(), summary.isInteractors(), importableOnly)); } } else { for (PathwayNodeSummary pathway : this.pathways) { - rtn.add(new PathwaySummary(pathway, resource.toUpperCase(), summary.isInteractors())); + rtn.add(new PathwaySummary(pathway, resource.toUpperCase(), summary.isInteractors(), importableOnly)); } } return new AnalysisResult(this, rtn); @@ -397,33 +432,33 @@ public List getWarnings() { return warnings; } - public List filterByPathways(List pathwayIds, String resource) { - this.filterPathways(resource); + public List filterByPathways(List pathwayIds, String resource, boolean importableOnly) { + this.filterPathways(resource, importableOnly); List rtn = new LinkedList<>(); for (PathwayNodeSummary pathway : this.pathways) { if (pathway.in(pathwayIds)) { - rtn.add(new PathwaySummary(pathway, resource.toUpperCase(), summary.isInteractors())); + rtn.add(new PathwaySummary(pathway, resource.toUpperCase(), summary.isInteractors(), importableOnly)); } } return rtn; } - public SpeciesFilteredResult filterBySpecies(Long speciesId, String resource) { - return filterBySpecies(speciesId, resource, null, "ASC"); + public SpeciesFilteredResult filterBySpecies(Long speciesId, String resource, boolean importableOnly) { + return filterBySpecies(speciesId, resource, null, "ASC", importableOnly); } - public SpeciesFilteredResult filterBySpecies(Long speciesId, String resource, String sortBy, String order) { + public SpeciesFilteredResult filterBySpecies(Long speciesId, String resource, String sortBy, String order, boolean importableOnly) { if (resource != null) { Resource r = ResourceFactory.getResource(resource); - this.filterPathways(resource); + this.filterPathways(resource, importableOnly); Collections.sort(this.pathways, getComparator(sortBy, order, resource)); List rtn = new LinkedList<>(); Double min = null, max = null; for (PathwayNodeSummary pathway : this.pathways) { if (pathway.getSpecies().getSpeciesID().equals(speciesId)) { - PathwaySummary aux = new PathwaySummary(pathway, resource.toUpperCase(), summary.isInteractors()); + PathwaySummary aux = new PathwaySummary(pathway, resource.toUpperCase(), summary.isInteractors(), importableOnly); rtn.add(new PathwayBase(aux)); List exps = new LinkedList<>(); @@ -460,7 +495,7 @@ public List getBinnedPathwaySize(int binSize, String resource, List() : speciesList; for (PathwayNodeSummary pathway : pathways) { - if(!includeDisease && pathway.isInDisease()) continue; + if (!includeDisease && pathway.isInDisease()) continue; if (speciesList.isEmpty() || pathway.getSpecies().isIn(speciesList)) { final PathwayNodeData data = pathway.getData(); final Double pv = (mr == null) ? data.getEntitiesPValue() : data.getEntitiesPValue(mr); diff --git a/src/main/java/org/reactome/server/analysis/core/result/model/EntityStatistics.java b/src/main/java/org/reactome/server/analysis/core/result/model/EntityStatistics.java index aa1d9b0d..c2b0ade4 100644 --- a/src/main/java/org/reactome/server/analysis/core/result/model/EntityStatistics.java +++ b/src/main/java/org/reactome/server/analysis/core/result/model/EntityStatistics.java @@ -21,14 +21,14 @@ public class EntityStatistics extends Statistics { private List exp = null; - public EntityStatistics(PathwayNodeData d, boolean interactors) { + public EntityStatistics(PathwayNodeData d, boolean interactors, boolean importableOnly) { super("TOTAL", - interactors ? d.getEntitiesAndInteractorsCount() : d.getEntitiesCount(), - interactors ? d.getEntitiesAndInteractorsFound() : d.getEntitiesFound(), - interactors ? d.getInteractorsRatio() : d.getEntitiesRatio()); - this.fdr = d.getEntitiesFDR(); - this.pValue = d.getEntitiesPValue(); - this.exp = d.getExpressionValuesAvg(); + interactors ? d.getEntitiesAndInteractorsCount(importableOnly) : d.getEntitiesCount(importableOnly), + interactors ? d.getEntitiesAndInteractorsFound(importableOnly) : d.getEntitiesFound(importableOnly), + interactors ? d.getInteractorsRatio(importableOnly) : d.getEntitiesRatio(importableOnly)); + this.fdr = d.getEntitiesFDR(importableOnly); + this.pValue = d.getEntitiesPValue(importableOnly); + this.exp = d.getExpressionValuesAvg(importableOnly); if (interactors) { this.curatedFound = d.getEntitiesFound(); this.curatedTotal = d.getEntitiesCount(); diff --git a/src/main/java/org/reactome/server/analysis/core/result/model/PathwaySummary.java b/src/main/java/org/reactome/server/analysis/core/result/model/PathwaySummary.java index 2c52d2fc..20a9ccf0 100644 --- a/src/main/java/org/reactome/server/analysis/core/result/model/PathwaySummary.java +++ b/src/main/java/org/reactome/server/analysis/core/result/model/PathwaySummary.java @@ -19,7 +19,7 @@ public class PathwaySummary { private EntityStatistics entities; private ReactionStatistics reactions; - public PathwaySummary(PathwayNodeSummary node, String resource, boolean interactors) { + public PathwaySummary(PathwayNodeSummary node, String resource, boolean interactors, boolean importableOnly) { this.stId = node.getStId(); this.dbId = node.getPathwayId(); @@ -28,16 +28,16 @@ public PathwaySummary(PathwayNodeSummary node, String resource, boolean interact this.llp = node.isLlp(); this.isInDisease = node.isInDisease(); - initialize(node.getData(), resource, interactors); + initialize(node.getData(), resource, interactors, importableOnly); } - private void initialize(PathwayNodeData d, String resource, boolean interactors){ - if(resource.equals("TOTAL")){ - this.entities = new EntityStatistics(d, interactors); - this.reactions = new ReactionStatistics(d); - }else{ + private void initialize(PathwayNodeData d, String resource, boolean interactors, boolean importableOnly) { + if (resource.equals("TOTAL")) { + this.entities = new EntityStatistics(d, interactors, importableOnly); + this.reactions = new ReactionStatistics(d, importableOnly); + } else { for (MainResource mr : d.getResources()) { - if(mr.getName().equals(resource)){ + if (mr.getName().equals(resource)) { this.entities = new EntityStatistics(mr, d, interactors); this.reactions = new ReactionStatistics(mr, d); break; diff --git a/src/main/java/org/reactome/server/analysis/core/result/model/ReactionStatistics.java b/src/main/java/org/reactome/server/analysis/core/result/model/ReactionStatistics.java index 82ae4f82..b556ccbb 100644 --- a/src/main/java/org/reactome/server/analysis/core/result/model/ReactionStatistics.java +++ b/src/main/java/org/reactome/server/analysis/core/result/model/ReactionStatistics.java @@ -9,8 +9,8 @@ //@ApiModel(value = "ReactionStatistics", description = "Statistics for a reaction type") public class ReactionStatistics extends Statistics { - public ReactionStatistics(PathwayNodeData d) { - super("TOTAL", d.getReactionsCount(), d.getReactionsFound(), d.getReactionsRatio()); + public ReactionStatistics(PathwayNodeData d, boolean importableOnly) { + super("TOTAL", d.getReactionsCount(importableOnly), d.getReactionsFound(importableOnly), d.getReactionsRatio(importableOnly)); } public ReactionStatistics(MainResource mainResource, PathwayNodeData d) { diff --git a/src/main/java/org/reactome/server/analysis/core/result/utils/ExternalAnalysisResultCheck.java b/src/main/java/org/reactome/server/analysis/core/result/utils/ExternalAnalysisResultCheck.java index b64d7871..069088d3 100644 --- a/src/main/java/org/reactome/server/analysis/core/result/utils/ExternalAnalysisResultCheck.java +++ b/src/main/java/org/reactome/server/analysis/core/result/utils/ExternalAnalysisResultCheck.java @@ -372,7 +372,7 @@ private void checkNotFound(List notFound, ExternalExpression @SuppressWarnings("BooleanMethodIsAlwaysInverted") - private boolean isValidResource(String resource) { + public static boolean isValidResource(String resource) { if (resource.equals("TOTAL")) return true; return ResourceFactory.getMainResource(resource) != null; } diff --git a/src/main/java/org/reactome/server/analysis/core/util/MapSet.java b/src/main/java/org/reactome/server/analysis/core/util/MapSet.java index ee005f1e..3047b79c 100644 --- a/src/main/java/org/reactome/server/analysis/core/util/MapSet.java +++ b/src/main/java/org/reactome/server/analysis/core/util/MapSet.java @@ -2,6 +2,7 @@ import java.io.Serializable; import java.util.*; +import java.util.stream.Stream; /** * @author Antonio Fabregat @@ -63,4 +64,8 @@ public Set values() { public int elementsCount() { return map.values().stream().mapToInt(Set::size).sum(); } + + public Stream>> stream() { + return map.entrySet().stream(); + } }