From f3f3d5fea9504353b9816d6c7a84c8c8e1507fde Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Wed, 12 Jun 2024 15:01:53 +0100 Subject: [PATCH 01/14] Remove experiment design field from Experiment Temporary leave experimentDesign field on Experiment entity to pass the test. I am going to remove it in the last commit --- .../rest/DASFeaturesController.java | 3 +-- .../DifferentialExperimentContrastLines.java | 20 ++++++++++++++----- ...xperimentsConditionsDetailsController.java | 4 ++-- .../atlas/trader/GxaExperimentRepository.java | 8 +++++++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/controllers/rest/DASFeaturesController.java b/app/src/main/java/uk/ac/ebi/atlas/controllers/rest/DASFeaturesController.java index fc3b081b..8b6b2c25 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/controllers/rest/DASFeaturesController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/controllers/rest/DASFeaturesController.java @@ -60,10 +60,9 @@ public String getDifferentialJsonResults( SetMultimap factorValuesByType = HashMultimap.create(); for (DiffAnalytics dbe : diffAnalyticsList) { AssayGroup testAssayGroup = dbe.getContrastTestAssayGroup(); - Experiment experiment = experimentTrader.getPublicExperiment(dbe.getExperimentAccession()); FactorSet factorsForAssayGroup = - FactorSet.create(experiment.getExperimentDesign() + FactorSet.create(experimentTrader.getExperimentDesign(dbe.getExperimentAccession()) .getFactorValues(testAssayGroup.getFirstAssayId())); for (Factor factor : factorsForAssayGroup) { factorValuesByType.put(factor.getType(), factor.getValue()); diff --git a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/DifferentialExperimentContrastLines.java b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/DifferentialExperimentContrastLines.java index c3f7ffc9..223b393a 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/DifferentialExperimentContrastLines.java +++ b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/DifferentialExperimentContrastLines.java @@ -3,11 +3,13 @@ import com.google.common.collect.ImmutableList; import org.jetbrains.annotations.NotNull; import uk.ac.ebi.atlas.model.OntologyTerm; +import uk.ac.ebi.atlas.model.experiment.ExperimentDesign; import uk.ac.ebi.atlas.model.experiment.sdrf.FactorSet; import uk.ac.ebi.atlas.model.experiment.sdrf.SampleCharacteristic; import uk.ac.ebi.atlas.model.experiment.sdrf.Factor; import uk.ac.ebi.atlas.model.experiment.sample.Contrast; import uk.ac.ebi.atlas.model.experiment.differential.DifferentialExperiment; +import uk.ac.ebi.atlas.trader.ExperimentTrader; import java.util.Iterator; import java.util.LinkedHashSet; @@ -18,9 +20,11 @@ public class DifferentialExperimentContrastLines implements Iterable { private final LinkedHashSet> contrastDetails; private final LinkedHashSet> result = new LinkedHashSet<>(); + private final ExperimentTrader experimentTrader; - public DifferentialExperimentContrastLines(DifferentialExperiment experiment) { + public DifferentialExperimentContrastLines(ExperimentTrader experimentTrader, DifferentialExperiment experiment) { this.contrastDetails = buildContrastDetails(experiment); + this.experimentTrader = experimentTrader; } private LinkedHashSet> buildContrastDetails(DifferentialExperiment experiment) { @@ -43,10 +47,11 @@ private void populateSamples(DifferentialExperiment experiment, String assayAccession, Contrast contrast, String value) { - for (SampleCharacteristic sample : experiment.getExperimentDesign().getSampleCharacteristics(assayAccession)) { + final String experimentAccession = experiment.getAccession(); + for (SampleCharacteristic sample : getExperimentDesign(experimentAccession).getSampleCharacteristics(assayAccession)) { ImmutableList line = ImmutableList.of( - experiment.getAccession(), + experimentAccession, contrast.getId(), value, "characteristic", @@ -61,12 +66,13 @@ private void populateFactors(DifferentialExperiment experiment, String assayAccession, Contrast contrast, String value) { - FactorSet factorSet = experiment.getExperimentDesign().getFactors(assayAccession); + final String experimentAccession = experiment.getAccession(); + FactorSet factorSet = getExperimentDesign(experimentAccession).getFactors(assayAccession); if (factorSet != null) { for (Factor factor : factorSet) { ImmutableList line = ImmutableList.of( - experiment.getAccession(), + experimentAccession, contrast.getId(), value, "factor", @@ -78,6 +84,10 @@ private void populateFactors(DifferentialExperiment experiment, } } + private ExperimentDesign getExperimentDesign(String experimentAccession) { + return experimentTrader.getExperimentDesign(experimentAccession); + } + private static String joinURIs(Set ontologyTerms) { return ontologyTerms.stream().map(OntologyTerm::uri).collect(joining(" ")); } diff --git a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java index eb84a89a..0622b283 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java @@ -26,7 +26,7 @@ @Controller @Scope("request") public class ExperimentsConditionsDetailsController { - private ExperimentTrader experimentTrader; + private final ExperimentTrader experimentTrader; public ExperimentsConditionsDetailsController(ExperimentTrader experimentTrader) { this.experimentTrader = experimentTrader; @@ -46,7 +46,7 @@ public void generateTsvFormatBaseline(HttpServletResponse response) { public void generateTsvFormatDifferential(HttpServletResponse response) { writeTsvLinesToResponse( response, - experiment -> new DifferentialExperimentContrastLines((DifferentialExperiment) experiment), + experiment -> new DifferentialExperimentContrastLines(experimentTrader, (DifferentialExperiment) experiment), MICROARRAY_1COLOUR_MICRORNA_DIFFERENTIAL, MICROARRAY_1COLOUR_MRNA_DIFFERENTIAL, MICROARRAY_2COLOUR_MRNA_DIFFERENTIAL, diff --git a/app/src/main/java/uk/ac/ebi/atlas/trader/GxaExperimentRepository.java b/app/src/main/java/uk/ac/ebi/atlas/trader/GxaExperimentRepository.java index 75396899..e40d3d12 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/trader/GxaExperimentRepository.java +++ b/app/src/main/java/uk/ac/ebi/atlas/trader/GxaExperimentRepository.java @@ -9,6 +9,7 @@ import uk.ac.ebi.atlas.experimentimport.ExperimentCrudDao; import uk.ac.ebi.atlas.experimentimport.idf.IdfParser; import uk.ac.ebi.atlas.model.experiment.Experiment; +import uk.ac.ebi.atlas.model.experiment.ExperimentDesign; import uk.ac.ebi.atlas.trader.factory.BaselineExperimentFactory; import uk.ac.ebi.atlas.trader.factory.MicroarrayExperimentFactory; import uk.ac.ebi.atlas.trader.factory.ProteomicsDifferentialExperimentFactory; @@ -54,7 +55,7 @@ public Experiment getExperiment(String experimentAccession) { LOGGER.info("Building experiment {}...", experimentAccession); - var experimentDesign = experimentDesignParser.parse(experimentDto.getExperimentAccession()); + var experimentDesign = getExperimentDesign(experimentAccession); var idfParserOutput = idfParser.parse(experimentDto.getExperimentAccession()); switch (experimentDto.getExperimentType()) { case PROTEOMICS_BASELINE: @@ -111,4 +112,9 @@ public Experiment getExperiment(String experimentAccession) { public String getExperimentType(String experimentAccession) { return experimentCrudDao.getExperimentType(experimentAccession); } + + @Override + public ExperimentDesign getExperimentDesign(String experimentAccession) { + return experimentDesignParser.parse(experimentAccession); + } } From 0b13c403c1c2e9457ca8cdc23dc2a72e8e0755ae Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Wed, 12 Jun 2024 16:21:51 +0100 Subject: [PATCH 02/14] Refactor ExperimentsConditionsDetailsController --- .../atlas/ebeyedump/ExperimentsConditionsDetailsController.java | 2 +- atlas-web-core | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java index 0622b283..349d5c5d 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java @@ -36,7 +36,7 @@ public ExperimentsConditionsDetailsController(ExperimentTrader experimentTrader) public void generateTsvFormatBaseline(HttpServletResponse response) { writeTsvLinesToResponse( response, - experiment -> new BaselineExperimentAssayGroupsLines((BaselineExperiment) experiment), + experiment -> new BaselineExperimentAssayGroupsLines(experimentTrader, (BaselineExperiment) experiment), RNASEQ_MRNA_BASELINE, PROTEOMICS_BASELINE, PROTEOMICS_BASELINE_DIA); diff --git a/atlas-web-core b/atlas-web-core index 2281e3fb..650099c4 160000 --- a/atlas-web-core +++ b/atlas-web-core @@ -1 +1 @@ -Subproject commit 2281e3fb14a455e6ead882883b345e84d2d0aa72 +Subproject commit 650099c4ecbbc9bcba9398cf78cff9e2f9cff6ed From 3163f038961f954b8ff97b1b3d03a37d33f4569d Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Wed, 12 Jun 2024 16:22:09 +0100 Subject: [PATCH 03/14] Refactor BaselineExperimentAssayGroupsLines --- .../BaselineExperimentAssayGroupsLines.java | 31 ++++++++++++++++--- ...aselineExperimentAssayGroupsLinesTest.java | 18 ++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLines.java b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLines.java index 7c5b68e1..3fe29d96 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLines.java +++ b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLines.java @@ -2,13 +2,17 @@ import com.google.common.collect.ImmutableList; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import uk.ac.ebi.atlas.model.experiment.ExperimentDesign; import uk.ac.ebi.atlas.model.experiment.sample.AssayGroup; import uk.ac.ebi.atlas.model.OntologyTerm; import uk.ac.ebi.atlas.model.experiment.sdrf.FactorSet; import uk.ac.ebi.atlas.model.experiment.sdrf.SampleCharacteristic; import uk.ac.ebi.atlas.model.experiment.baseline.BaselineExperiment; import uk.ac.ebi.atlas.model.experiment.sdrf.Factor; +import uk.ac.ebi.atlas.trader.ExperimentTrader; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; @@ -18,9 +22,12 @@ public class BaselineExperimentAssayGroupsLines implements Iterable { private final LinkedHashSet> result = new LinkedHashSet<>(); private final LinkedHashSet> assayGroupsDetails; + private final ExperimentTrader experimentTrader; - public BaselineExperimentAssayGroupsLines(BaselineExperiment experiment) { - assayGroupsDetails = buildAssayGroupsDetails(experiment); + public BaselineExperimentAssayGroupsLines(ExperimentTrader experimentTrader, + BaselineExperiment experiment) { + this.experimentTrader = experimentTrader; + this.assayGroupsDetails = buildAssayGroupsDetails(experiment); } private LinkedHashSet> buildAssayGroupsDetails(BaselineExperiment experiment) { @@ -35,7 +42,9 @@ private LinkedHashSet> buildAssayGroupsDetails(BaselineExp } private void populateSamples(BaselineExperiment experiment, String assayAccession, AssayGroup assayGroup) { - for (SampleCharacteristic sample : experiment.getExperimentDesign().getSampleCharacteristics(assayAccession)) { + final String experimentAccession = experiment.getAccession(); + + for (SampleCharacteristic sample : getSampleCharacteristics(assayAccession, experimentAccession)) { ImmutableList line = ImmutableList.of( experiment.getAccession(), @@ -49,7 +58,9 @@ private void populateSamples(BaselineExperiment experiment, String assayAccessio } private void populateFactors(BaselineExperiment experiment, String assayAccession, AssayGroup assayGroup) { - FactorSet factorSet = experiment.getExperimentDesign().getFactors(assayAccession); + final String experimentAccession = experiment.getAccession(); + + FactorSet factorSet = getFactors(assayAccession, experimentAccession); if (factorSet != null) { for (Factor factor : factorSet) { ImmutableList line = ImmutableList.of(experiment.getAccession(), assayGroup.getId(), "factor", @@ -59,6 +70,18 @@ private void populateFactors(BaselineExperiment experiment, String assayAccessio } } + private ExperimentDesign getExperimentDesign(String experimentAccession) { + return experimentTrader.getExperimentDesign(experimentAccession); + } + + private Collection getSampleCharacteristics(String assayAccession, String experimentAccession) { + return getExperimentDesign(experimentAccession).getSampleCharacteristics(assayAccession); + } + + private @Nullable FactorSet getFactors(String assayAccession, String experimentAccession) { + return getExperimentDesign(experimentAccession).getFactors(assayAccession); + } + private static String joinURIs(Set ontologyTerms) { return ontologyTerms.stream().map(OntologyTerm::uri).collect(joining(" ")); } diff --git a/app/src/test/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLinesTest.java b/app/src/test/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLinesTest.java index 77265f61..d412d081 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLinesTest.java +++ b/app/src/test/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLinesTest.java @@ -14,6 +14,7 @@ import uk.ac.ebi.atlas.model.experiment.sdrf.SampleCharacteristic; import uk.ac.ebi.atlas.model.experiment.ExperimentDesign; import uk.ac.ebi.atlas.model.experiment.baseline.BaselineExperiment; +import uk.ac.ebi.atlas.trader.ExperimentTrader; import java.util.Arrays; import java.util.Iterator; @@ -23,6 +24,7 @@ import static org.apache.commons.lang3.StringUtils.wrap; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -70,6 +72,9 @@ public class BaselineExperimentAssayGroupsLinesTest { @Mock private BaselineExperiment baselineExperiment; + @Mock + private ExperimentTrader experimentTraderMock; + @Test public void lines() { ExperimentDesign experimentDesign = new ExperimentDesign(); @@ -79,23 +84,20 @@ public void lines() { SampleCharacteristic sampleCharacteristic2 = SampleCharacteristic.create(SAMPLE_HEADER, SAMPLE_VALUE2, SAMPLE_ONTOLOGY_TERM2); - experimentDesign.putSampleCharacteristic(ASSAY1, SAMPLE_HEADER, sampleCharacteristic1); - experimentDesign.putFactor(ASSAY1, FACTOR_HEADER, FACTOR_VALUE1, FACTOR_ONTOLOGY_TERM1); - experimentDesign.putSampleCharacteristic(ASSAY2, SAMPLE_HEADER, sampleCharacteristic2); - experimentDesign.putFactor(ASSAY2, FACTOR_HEADER, FACTOR_VALUE2, FACTOR_ONTOLOGY_TERM2); - experimentDesign.putSampleCharacteristic(ASSAY3, SAMPLE_HEADER, SAMPLE_VALUE3); + experimentDesign.putFactor(ASSAY1, FACTOR_HEADER, FACTOR_VALUE1, FACTOR_ONTOLOGY_TERM1); + experimentDesign.putFactor(ASSAY2, FACTOR_HEADER, FACTOR_VALUE2, FACTOR_ONTOLOGY_TERM2); experimentDesign.putFactor(ASSAY3, FACTOR_HEADER, FACTOR_VALUE3); - when(baselineExperiment.getAccession()).thenReturn(EXPERIMENT_ACCESSION); when(baselineExperiment.getDataColumnDescriptors()).thenReturn(ImmutableList.of(ASSAY_GROUP1, ASSAY_GROUP2, ASSAY_GROUP3)); - when(baselineExperiment.getExperimentDesign()).thenReturn(experimentDesign); + when(experimentTraderMock.getExperimentDesign(any())).thenReturn(experimentDesign); - BaselineExperimentAssayGroupsLines subject = new BaselineExperimentAssayGroupsLines(baselineExperiment); + BaselineExperimentAssayGroupsLines subject = + new BaselineExperimentAssayGroupsLines(experimentTraderMock, baselineExperiment); Iterator lines = subject.iterator(); From 9da1546047455f77181445b85c0783d0f9f35734 Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Wed, 12 Jun 2024 17:00:14 +0100 Subject: [PATCH 04/14] Refactor BaselineExperimentPageService --- .../baseline/BaselineExperimentPageService.java | 8 ++++++-- .../json/JsonBaselineExperimentController.java | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/baseline/BaselineExperimentPageService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/baseline/BaselineExperimentPageService.java index 6a07d183..4d738f01 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/baseline/BaselineExperimentPageService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/baseline/BaselineExperimentPageService.java @@ -17,6 +17,7 @@ import uk.ac.ebi.atlas.model.experiment.baseline.BaselineProfile; import uk.ac.ebi.atlas.model.experiment.sdrf.RichFactorGroup; import uk.ac.ebi.atlas.model.experiment.summary.AssayGroupSummaryBuilder; +import uk.ac.ebi.atlas.trader.ExperimentTrader; import uk.ac.ebi.atlas.web.BaselineRequestPreferences; import java.util.List; @@ -28,13 +29,16 @@ public class BaselineExperimentPageService extends ExperimentPageService { private final BaselineExperimentProfilesService baselineExperimentProfilesService; private final CoexpressedGenesService coexpressedGenesService; private final AnatomogramFactory anatomogramFactory; + private final ExperimentTrader experimentTrader; public BaselineExperimentPageService(BaselineExperimentProfilesService baselineExperimentProfilesService, - CoexpressedGenesService coexpressedGenesService) { + CoexpressedGenesService coexpressedGenesService, + ExperimentTrader experimentTrader) { super(); this.anatomogramFactory = new AnatomogramFactory(); this.baselineExperimentProfilesService = baselineExperimentProfilesService; this.coexpressedGenesService = coexpressedGenesService; + this.experimentTrader = experimentTrader; } public JsonObject getResultsForExperiment( @@ -101,7 +105,7 @@ private JsonArray constructColumnHeaders(BaselineRequestContext requestContex o.add("assayGroupSummary", new AssayGroupSummaryBuilder() .forAssayGroup(experiment.getDataColumnDescriptor(dataColumnDescriptor.getId())) - .withExperimentDesign(experiment.getExperimentDesign()) + .withExperimentDesign(experimentTrader.getExperimentDesign(experiment.getAccession())) .build().toJson()); result.add(o); } diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonBaselineExperimentController.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonBaselineExperimentController.java index 10678c95..5e23947a 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonBaselineExperimentController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonBaselineExperimentController.java @@ -49,7 +49,8 @@ public class JsonBaselineExperimentController extends JsonExperimentController { super(experimentTrader); this.baselineExperimentPageService = - new BaselineExperimentPageService(baselineExperimentProfilesService, coexpressedGenesService); + new BaselineExperimentPageService( + baselineExperimentProfilesService, coexpressedGenesService,experimentTrader); this.rnaSeqHistograms = new HistogramService.RnaSeq(rnaSeqBaselineProfileStreamFactory, experimentTrader); From 7aada2ba072a9c48b4635096686f1e06566ae3ca Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Wed, 12 Jun 2024 17:57:25 +0100 Subject: [PATCH 05/14] Refactor HeatmapGroupingsService --- .../content/ExperimentPageContentService.java | 9 ++++- .../content/HeatmapGroupingsService.java | 38 +++++++++++++------ .../ExperimentGroupingsForHeatmapIT.java | 3 +- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java index af158800..395d07c6 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java @@ -22,6 +22,7 @@ import uk.ac.ebi.atlas.model.experiment.ExperimentType; import uk.ac.ebi.atlas.model.experiment.sample.ReportsGeneExpression; import uk.ac.ebi.atlas.resource.DataFileHub; +import uk.ac.ebi.atlas.trader.ExperimentTrader; import uk.ac.ebi.atlas.utils.GsonProvider; import java.util.List; @@ -39,10 +40,14 @@ public class ExperimentPageContentService { private final DataFileHub dataFileHub; private final ExpressionAtlasContentService expressionAtlasContentService; + private final ExperimentTrader experimentTrader; - public ExperimentPageContentService(DataFileHub dataFileHub, ExpressionAtlasContentService expressionAtlasContentService) { + public ExperimentPageContentService(DataFileHub dataFileHub, + ExpressionAtlasContentService expressionAtlasContentService, + ExperimentTrader experimentTrader) { this.dataFileHub = dataFileHub; this.expressionAtlasContentService = expressionAtlasContentService; + this.experimentTrader = experimentTrader; } @Cacheable(cacheNames = "experimentContent", key = "#experiment.getAccession()") @@ -66,7 +71,7 @@ private JsonObject experimentPageContentForExperiment(final Experiment getExperimentVariablesAsHeatmapFilterGroups(Experiment experiment) { + public static ImmutableList getExperimentVariablesAsHeatmapFilterGroups( + ExperimentTrader experimentTrader, + Experiment experiment) { + final String experimentAccession = experiment.getAccession(); if (!(experiment instanceof BaselineExperiment) && !(experiment instanceof DifferentialExperiment)) { throw new IllegalArgumentException( - "Experiment " + experiment.getAccession() + " of type " + experiment.getType() + " is not " + + "Experiment " + experimentAccession + " of type " + experiment.getType() + " is not " + "supported for heatmap display"); } @@ -84,7 +89,7 @@ public static ImmutableList getExperimentVariablesAsHeatmapF Streams.concat( Stream.of(experiment.getDisplayDefaults().getDefaultQueryFactorType()), experiment.getDisplayDefaults().getFactorTypes().stream(), - experiment.getExperimentDesign().getFactorHeaders().stream()) + getExperimentDesign(experimentTrader, experimentAccession).getFactorHeaders().stream()) .filter(StringUtils::isNotBlank) // defaultQueryFactorType in diff experiments is "" .map(Factor::normalize) .collect(toImmutableSet()); @@ -101,17 +106,19 @@ public static ImmutableList getExperimentVariablesAsHeatmapF experiment.getDisplayDefaults() .defaultFilterValuesForFactor(factorHeader) .orElse(ALL_VALUES_KEYWORD), - mapAssayGroupsToFactors(assayId2AssayGroup, factorHeader, experiment))); + mapAssayGroupsToFactors(experimentTrader, assayId2AssayGroup, factorHeader, + experiment))); Stream sampleCharacteristicGroups = - experiment.getExperimentDesign().getSampleCharacteristicHeaders().stream() + getExperimentDesign(experimentTrader, experimentAccession).getSampleCharacteristicHeaders().stream() .filter(sampleCharacteristicHeader -> !orderedFactors.contains(Factor.normalize(sampleCharacteristicHeader))) .map(sampleCharacteristicHeader -> HeatmapFilterGroup.create( sampleCharacteristicHeader, primaryVariables.contains(sampleCharacteristicHeader), ALL_VALUES_KEYWORD, - mapAssayGroupsToSampleCharacteristics(assayId2AssayGroup, sampleCharacteristicHeader, experiment))); + mapAssayGroupsToSampleCharacteristics(experimentTrader, assayId2AssayGroup, + sampleCharacteristicHeader, experiment))); return Streams.concat( mainFilterGroup.map(Stream::of).orElseGet(Stream::empty), @@ -120,32 +127,39 @@ public static ImmutableList getExperimentVariablesAsHeatmapF .collect(toImmutableList()); } + private static ExperimentDesign getExperimentDesign(ExperimentTrader experimentTrader, + String experimentAccession) { + return experimentTrader.getExperimentDesign(experimentAccession); + } + @NotNull private static ImmutableSetMultimap mapAssayGroupsToFactors( + ExperimentTrader experimentTrader, @NotNull ImmutableMultimap assayId2AssayGroup, @NotNull String factorHeader, @NotNull Experiment<@NotNull ?> experiment) { return assayId2AssayGroup.keySet().stream() - .filter(assayId -> experiment.getExperimentDesign().getFactor(assayId, factorHeader) != null) + .filter(assayId -> getExperimentDesign(experimentTrader, experiment.getAccession()) + .getFactor(assayId, factorHeader) != null) .collect(flatteningToImmutableSetMultimap( - assayId -> experiment.getExperimentDesign().getFactor(assayId, factorHeader).getValue(), + assayId -> getExperimentDesign(experimentTrader, experiment.getAccession()) + .getFactor(assayId, factorHeader).getValue(), assayId -> assayId2AssayGroup.get(assayId).stream())); } @NotNull private static ImmutableSetMultimap mapAssayGroupsToSampleCharacteristics( + ExperimentTrader experimentTrader, @NotNull ImmutableMultimap assayId2AssayGroup, @NotNull String sampleCharacteristicHeader, @NotNull Experiment<@NotNull?> experiment) { return assayId2AssayGroup.keySet().stream() .filter(assayId -> - experiment - .getExperimentDesign() + getExperimentDesign(experimentTrader, experiment.getAccession()) .getSampleCharacteristic(assayId, sampleCharacteristicHeader) != null) .collect(flatteningToImmutableSetMultimap( assayId -> - experiment - .getExperimentDesign() + getExperimentDesign(experimentTrader, experiment.getAccession()) .getSampleCharacteristic(assayId, sampleCharacteristicHeader).getValue(), assayId -> assayId2AssayGroup.get(assayId).stream())); } diff --git a/app/src/test/java/uk/ac/ebi/atlas/model/experiment/ExperimentGroupingsForHeatmapIT.java b/app/src/test/java/uk/ac/ebi/atlas/model/experiment/ExperimentGroupingsForHeatmapIT.java index dc28b4c6..8bb4b82c 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/model/experiment/ExperimentGroupingsForHeatmapIT.java +++ b/app/src/test/java/uk/ac/ebi/atlas/model/experiment/ExperimentGroupingsForHeatmapIT.java @@ -84,7 +84,8 @@ void outputInFineFormatForExperiment(String accession) { .collect(Collectors.toList()); JsonArray result = - GSON.toJsonTree(HeatmapGroupingsService.getExperimentVariablesAsHeatmapFilterGroups(experiment)) + GSON.toJsonTree(HeatmapGroupingsService.getExperimentVariablesAsHeatmapFilterGroups( + experimentTrader, experiment)) .getAsJsonArray(); assertThat(result.size(), greaterThan(0)); From afc6517a429413e0730215145ed282d692e5ae58 Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Thu, 13 Jun 2024 10:37:22 +0100 Subject: [PATCH 06/14] Refactor DifferentialExperimentPageService --- .../DifferentialExperimentPageService.java | 13 ++++++++----- .../json/JsonDifferentialExperimentController.java | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/differential/DifferentialExperimentPageService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/differential/DifferentialExperimentPageService.java index 44b0f4d6..2a2e39a8 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/differential/DifferentialExperimentPageService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/differential/DifferentialExperimentPageService.java @@ -17,6 +17,7 @@ import uk.ac.ebi.atlas.model.experiment.summary.ContrastSummaryBuilder; import uk.ac.ebi.atlas.profiles.json.ExternallyViewableProfilesList; import uk.ac.ebi.atlas.resource.ContrastImageTrader; +import uk.ac.ebi.atlas.trader.ExperimentTrader; import uk.ac.ebi.atlas.web.DifferentialRequestPreferences; import java.util.List; @@ -35,15 +36,17 @@ private final ContrastImageTrader contrastImageTrader; private final DifferentialRequestContextFactory differentialRequestContextFactory; private final DifferentialProfilesHeatMap profilesHeatMap; + private final ExperimentTrader experimentTrader; public DifferentialExperimentPageService( DifferentialRequestContextFactory differentialRequestContextFactory, DifferentialProfilesHeatMap profilesHeatMap, - ContrastImageTrader contrastImageTrader) { + ContrastImageTrader contrastImageTrader, + ExperimentTrader experimentTrader) { this.differentialRequestContextFactory = differentialRequestContextFactory; this.profilesHeatMap = profilesHeatMap; this.contrastImageTrader = contrastImageTrader; - + this.experimentTrader = experimentTrader; } public JsonObject getResultsForExperiment(E experiment, String accessKey, K preferences) { @@ -68,15 +71,15 @@ public JsonObject getResultsForExperiment(E experiment, String accessKey, K pref return result; } - private JsonArray constructColumnHeaders(Iterable contrasts, DifferentialExperiment - differentialExperiment) { + private JsonArray constructColumnHeaders(Iterable contrasts, + DifferentialExperiment differentialExperiment) { JsonArray result = new JsonArray(); Map contrastImages = contrastImageTrader.contrastImages(differentialExperiment); for (Contrast contrast : contrasts) { JsonObject o = contrast.toJson(); o.add("contrastSummary", new ContrastSummaryBuilder() .forContrast(contrast) - .withExperimentDesign(differentialExperiment.getExperimentDesign()) + .withExperimentDesign(experimentTrader.getExperimentDesign(differentialExperiment.getAccession())) .withExperimentDescription(differentialExperiment.getDescription()) .build().toJson()); o.add("resources", contrastImages.get(contrast.getId())); diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonDifferentialExperimentController.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonDifferentialExperimentController.java index eee5a0e7..39452198 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonDifferentialExperimentController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonDifferentialExperimentController.java @@ -65,12 +65,14 @@ public JsonDifferentialExperimentController(ExperimentTrader experimentTrader, differentialExperimentPageService = new DifferentialExperimentPageService<>(new DifferentialRequestContextFactory.RnaSeq(), new DifferentialProfilesHeatMap<>(bulkDifferentialProfileStreamFactory, solrQueryService), - atlasResourceHub); + atlasResourceHub, + experimentTrader); diffMicroarrayExperimentPageService = new DifferentialExperimentPageService<>(new DifferentialRequestContextFactory.Microarray(), new DifferentialProfilesHeatMap<>(microarrayProfileStreamFactory, solrQueryService), - atlasResourceHub); + atlasResourceHub, + experimentTrader); } private String differentialMicroarrayExperimentData(MicroarrayRequestPreferences preferences, From b0d4263a834ab756a169ee2b9732dadc8c8f95e8 Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Thu, 13 Jun 2024 16:08:56 +0100 Subject: [PATCH 07/14] Refactor EvidenceService --- .../experimentpage/json/opentargets/EvidenceService.java | 9 +++++++-- .../json/opentargets/OpenTargetsEvidenceController.java | 5 +++-- .../json/opentargets/EvidenceServiceIT.java | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java index 54217e4d..ab68b090 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java @@ -26,6 +26,7 @@ import uk.ac.ebi.atlas.profiles.differential.DifferentialProfileStreamOptions; import uk.ac.ebi.atlas.profiles.stream.ProfileStreamFactory; import uk.ac.ebi.atlas.resource.DataFileHub; +import uk.ac.ebi.atlas.trader.ExperimentTrader; import java.text.MessageFormat; import java.text.SimpleDateFormat; @@ -50,12 +51,15 @@ public class EvidenceService differentialProfileStreamFactory; private final DataFileHub dataFileHub; private final String expressionAtlasVersion; + private final ExperimentTrader experimentTrader; public EvidenceService(ProfileStreamFactory differentialProfileStreamFactory, DataFileHub dataFileHub, + ExperimentTrader experimentTrader, String expressionAtlasVersion) { this.differentialProfileStreamFactory = differentialProfileStreamFactory; this.dataFileHub = dataFileHub; + this.experimentTrader = experimentTrader; this.expressionAtlasVersion = expressionAtlasVersion; } @@ -67,7 +71,7 @@ public void evidenceForExperiment(E experiment, } var diseaseAssociations = getDiseaseAssociations(experiment); - if (diseaseAssociations.size() == 0) { + if (diseaseAssociations.isEmpty()) { return; } @@ -108,7 +112,8 @@ public void evidenceForExperiment(E experiment, private boolean shouldSkip(E experiment) { return !experiment.getSpecies().isUs() || experiment.getType().isMicroRna() || - cellLineAsSampleCharacteristicButNoDiseaseAsFactor(experiment.getExperimentDesign()); + cellLineAsSampleCharacteristicButNoDiseaseAsFactor( + experimentTrader.getExperimentDesign(experiment.getAccession())); } private void piecesOfEvidence(E experiment, diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/OpenTargetsEvidenceController.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/OpenTargetsEvidenceController.java index efc0d1fc..d8e0a4ae 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/OpenTargetsEvidenceController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/OpenTargetsEvidenceController.java @@ -53,9 +53,10 @@ public OpenTargetsEvidenceController(ExperimentTrader experimentTrader, String resourcesVersion = "prod.30"; bulkDifferentialEvidenceService = - new EvidenceService<>(bulkDifferentialProfileStreamFactory, dataFileHub, resourcesVersion); + new EvidenceService<>( + bulkDifferentialProfileStreamFactory, dataFileHub, experimentTrader, resourcesVersion); diffMicroarrayEvidenceService = - new EvidenceService<>(microarrayProfileStreamFactory, dataFileHub, resourcesVersion); + new EvidenceService<>(microarrayProfileStreamFactory, dataFileHub, experimentTrader, resourcesVersion); } @InitBinder("preferences") diff --git a/app/src/test/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceServiceIT.java b/app/src/test/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceServiceIT.java index 582fa8b9..23a857e2 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceServiceIT.java +++ b/app/src/test/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceServiceIT.java @@ -66,7 +66,8 @@ void cleanDatabaseTables() { @BeforeEach void setUp() { - subject = new EvidenceService<>(microarrayProfileStreamFactory, dataFileHub, "test"); + subject = new EvidenceService<>( + microarrayProfileStreamFactory, dataFileHub, experimentTrader, "test"); } @Test From 8fcd20ac784674ac95a6c7bc086f35eb40af5537 Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Thu, 13 Jun 2024 16:28:22 +0100 Subject: [PATCH 08/14] Refactor EvidenceService - left over --- .../json/opentargets/EvidenceService.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java index ab68b090..87408f36 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java @@ -113,7 +113,7 @@ private boolean shouldSkip(E experiment) { return !experiment.getSpecies().isUs() || experiment.getType().isMicroRna() || cellLineAsSampleCharacteristicButNoDiseaseAsFactor( - experimentTrader.getExperimentDesign(experiment.getAccession())); + getExperimentDesign(experiment.getAccession())); } private void piecesOfEvidence(E experiment, @@ -408,12 +408,18 @@ private JsonObject associationRecord(JsonObject uniqueAssociationFields, private ImmutableMap getDiseaseAssociations(DifferentialExperiment experiment) { var contrastToDiseaseBuilder = ImmutableMap.builder(); for (var contrast: experiment.getDataColumnDescriptors()) { - DiseaseAssociation.tryCreate(experiment, contrast) + DiseaseAssociation.tryCreate(getExperimentDesign(experiment.getAccession()), experiment, contrast) .ifPresent(diseaseAssociation -> contrastToDiseaseBuilder.put(contrast, diseaseAssociation)); } return contrastToDiseaseBuilder.build(); } + private ExperimentDesign getExperimentDesign(String experimentAccession) { + return experimentTrader.getExperimentDesign(experimentAccession); + } + + + @AutoValue abstract static class DiseaseAssociation { enum CONFIDENCE { @@ -428,15 +434,17 @@ enum CONFIDENCE { public abstract boolean isCttvPrimary(); public abstract SampleCharacteristic organismPart(); - public static Optional tryCreate(DifferentialExperiment experiment, Contrast contrast) { - var biosampleInfo = getBiosampleInfo(experiment.getExperimentDesign(), contrast.getTestAssayGroup()); - var diseaseInfo = getDiseaseInfo(experiment.getExperimentDesign(), contrast.getTestAssayGroup()); + public static Optional tryCreate(ExperimentDesign experimentDesign, + DifferentialExperiment experiment, Contrast contrast) { + + var biosampleInfo = getBiosampleInfo(experimentDesign, contrast.getTestAssayGroup()); + var diseaseInfo = getDiseaseInfo(experimentDesign, contrast.getTestAssayGroup()); if (biosampleInfo.isPresent() && diseaseInfo.isPresent()) { return Optional.of( DiseaseAssociation.create( biosampleInfo.get(), - experiment.getExperimentDesign(), + experimentDesign, contrast, experiment.doesContrastHaveCttvPrimaryAnnotation(contrast), diseaseInfo.get())); From 481e14b860e3b5bbb34b41da60c9b0dce7f480c9 Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Thu, 13 Jun 2024 16:29:04 +0100 Subject: [PATCH 09/14] Refactor ContrastSummaryController --- .../experimentpage/tooltip/ContrastSummaryController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/tooltip/ContrastSummaryController.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/tooltip/ContrastSummaryController.java index 6ded26ad..b4a23e08 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/tooltip/ContrastSummaryController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/tooltip/ContrastSummaryController.java @@ -22,7 +22,7 @@ @Scope("request") public class ContrastSummaryController { - private ExperimentTrader experimentTrader; + private final ExperimentTrader experimentTrader; @Inject public ContrastSummaryController(ExperimentTrader experimentTrader) { @@ -44,7 +44,7 @@ public String getTooltipContrastContent(@RequestParam(value = "experimentAccessi throw new IllegalArgumentException("No contrast with ID " + contrastId + " found."); } - ExperimentDesign experimentDesign = differentialExperiment.getExperimentDesign(); + ExperimentDesign experimentDesign = experimentTrader.getExperimentDesign(experimentAccession); ContrastSummary contrastSummary = new ContrastSummaryBuilder() .withExperimentDesign(experimentDesign) From 7849d9322015964d85505c16a81186c36a51d6c9 Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Thu, 13 Jun 2024 17:03:14 +0100 Subject: [PATCH 10/14] Refactor ExperimentPageContentService --- .../experimentpage/content/ExperimentPageContentService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java index 395d07c6..c927902c 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java @@ -95,7 +95,7 @@ private JsonObject experimentPageContentForExperiment(final Experiment Date: Thu, 13 Jun 2024 17:20:13 +0100 Subject: [PATCH 11/14] update with the latest atlas-web-core module changes --- atlas-web-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas-web-core b/atlas-web-core index 650099c4..ee2ff7f5 160000 --- a/atlas-web-core +++ b/atlas-web-core @@ -1 +1 @@ -Subproject commit 650099c4ecbbc9bcba9398cf78cff9e2f9cff6ed +Subproject commit ee2ff7f507e440ad2fc8981e2b820bb449f13486 From aa534d8d82f9f60b18834549c31d818c728d400b Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Fri, 14 Jun 2024 11:12:35 +0100 Subject: [PATCH 12/14] Remove experimentDesign field from Experiment entity (latest core changes) --- atlas-web-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas-web-core b/atlas-web-core index ee2ff7f5..a9ec17ac 160000 --- a/atlas-web-core +++ b/atlas-web-core @@ -1 +1 @@ -Subproject commit ee2ff7f507e440ad2fc8981e2b820bb449f13486 +Subproject commit a9ec17acbcc0868a1ca790e382555c5114f58f74 From 65b0415f445ab17133544151f111d434caa79807 Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Tue, 18 Jun 2024 15:37:14 +0100 Subject: [PATCH 13/14] Update to the latest atlas-web-core module changes --- atlas-web-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas-web-core b/atlas-web-core index a9ec17ac..e12a8b92 160000 --- a/atlas-web-core +++ b/atlas-web-core @@ -1 +1 @@ -Subproject commit a9ec17acbcc0868a1ca790e382555c5114f58f74 +Subproject commit e12a8b928c78c16f0bdd6d6d3f580a5656a54253 From b2cd31b8403769a1326134e292f09bc039e29a8c Mon Sep 17 00:00:00 2001 From: Karoly Erdos Date: Thu, 20 Jun 2024 16:32:53 +0100 Subject: [PATCH 14/14] Refactor getExperimentDesign method usage --- .../BaselineExperimentAssayGroupsLines.java | 23 +++++-------- .../DifferentialExperimentContrastLines.java | 15 +++----- ...xperimentsConditionsDetailsController.java | 11 ++++-- .../BaselineExperimentPageService.java | 17 +++++----- .../content/ExperimentPageContentService.java | 3 +- .../content/HeatmapGroupingsService.java | 34 +++++++------------ .../DifferentialExperimentPageService.java | 17 +++++----- .../JsonBaselineExperimentController.java | 3 +- .../JsonDifferentialExperimentController.java | 9 ++--- .../json/opentargets/EvidenceService.java | 25 +++++--------- .../OpenTargetsEvidenceController.java | 6 ++-- ...aselineExperimentAssayGroupsLinesTest.java | 7 +--- .../json/opentargets/EvidenceServiceIT.java | 10 ++++-- .../ExperimentGroupingsForHeatmapIT.java | 2 +- 14 files changed, 81 insertions(+), 101 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLines.java b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLines.java index 3fe29d96..d67f1e1f 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLines.java +++ b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLines.java @@ -10,7 +10,6 @@ import uk.ac.ebi.atlas.model.experiment.sdrf.SampleCharacteristic; import uk.ac.ebi.atlas.model.experiment.baseline.BaselineExperiment; import uk.ac.ebi.atlas.model.experiment.sdrf.Factor; -import uk.ac.ebi.atlas.trader.ExperimentTrader; import java.util.Collection; import java.util.Iterator; @@ -22,11 +21,11 @@ public class BaselineExperimentAssayGroupsLines implements Iterable { private final LinkedHashSet> result = new LinkedHashSet<>(); private final LinkedHashSet> assayGroupsDetails; - private final ExperimentTrader experimentTrader; + private final ExperimentDesign experimentDesign; - public BaselineExperimentAssayGroupsLines(ExperimentTrader experimentTrader, - BaselineExperiment experiment) { - this.experimentTrader = experimentTrader; + public BaselineExperimentAssayGroupsLines(BaselineExperiment experiment, + ExperimentDesign experimentDesign) { + this.experimentDesign = experimentDesign; this.assayGroupsDetails = buildAssayGroupsDetails(experiment); } @@ -60,26 +59,22 @@ private void populateSamples(BaselineExperiment experiment, String assayAccessio private void populateFactors(BaselineExperiment experiment, String assayAccession, AssayGroup assayGroup) { final String experimentAccession = experiment.getAccession(); - FactorSet factorSet = getFactors(assayAccession, experimentAccession); + FactorSet factorSet = getFactors(assayAccession); if (factorSet != null) { for (Factor factor : factorSet) { - ImmutableList line = ImmutableList.of(experiment.getAccession(), assayGroup.getId(), "factor", + ImmutableList line = ImmutableList.of(experimentAccession, assayGroup.getId(), "factor", factor.getHeader(), factor.getValue(), joinURIs(factor.getValueOntologyTerms())); result.add(line); } } } - private ExperimentDesign getExperimentDesign(String experimentAccession) { - return experimentTrader.getExperimentDesign(experimentAccession); - } - private Collection getSampleCharacteristics(String assayAccession, String experimentAccession) { - return getExperimentDesign(experimentAccession).getSampleCharacteristics(assayAccession); + return experimentDesign.getSampleCharacteristics(assayAccession); } - private @Nullable FactorSet getFactors(String assayAccession, String experimentAccession) { - return getExperimentDesign(experimentAccession).getFactors(assayAccession); + private @Nullable FactorSet getFactors(String assayAccession) { + return experimentDesign.getFactors(assayAccession); } private static String joinURIs(Set ontologyTerms) { diff --git a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/DifferentialExperimentContrastLines.java b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/DifferentialExperimentContrastLines.java index 223b393a..0219c094 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/DifferentialExperimentContrastLines.java +++ b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/DifferentialExperimentContrastLines.java @@ -9,7 +9,6 @@ import uk.ac.ebi.atlas.model.experiment.sdrf.Factor; import uk.ac.ebi.atlas.model.experiment.sample.Contrast; import uk.ac.ebi.atlas.model.experiment.differential.DifferentialExperiment; -import uk.ac.ebi.atlas.trader.ExperimentTrader; import java.util.Iterator; import java.util.LinkedHashSet; @@ -20,11 +19,11 @@ public class DifferentialExperimentContrastLines implements Iterable { private final LinkedHashSet> contrastDetails; private final LinkedHashSet> result = new LinkedHashSet<>(); - private final ExperimentTrader experimentTrader; + private final ExperimentDesign experimentDesign; - public DifferentialExperimentContrastLines(ExperimentTrader experimentTrader, DifferentialExperiment experiment) { + public DifferentialExperimentContrastLines(DifferentialExperiment experiment, ExperimentDesign experimentDesign) { this.contrastDetails = buildContrastDetails(experiment); - this.experimentTrader = experimentTrader; + this.experimentDesign = experimentDesign; } private LinkedHashSet> buildContrastDetails(DifferentialExperiment experiment) { @@ -48,7 +47,7 @@ private void populateSamples(DifferentialExperiment experiment, Contrast contrast, String value) { final String experimentAccession = experiment.getAccession(); - for (SampleCharacteristic sample : getExperimentDesign(experimentAccession).getSampleCharacteristics(assayAccession)) { + for (SampleCharacteristic sample : experimentDesign.getSampleCharacteristics(assayAccession)) { ImmutableList line = ImmutableList.of( experimentAccession, @@ -67,7 +66,7 @@ private void populateFactors(DifferentialExperiment experiment, Contrast contrast, String value) { final String experimentAccession = experiment.getAccession(); - FactorSet factorSet = getExperimentDesign(experimentAccession).getFactors(assayAccession); + FactorSet factorSet = experimentDesign.getFactors(assayAccession); if (factorSet != null) { for (Factor factor : factorSet) { ImmutableList line = @@ -84,10 +83,6 @@ private void populateFactors(DifferentialExperiment experiment, } } - private ExperimentDesign getExperimentDesign(String experimentAccession) { - return experimentTrader.getExperimentDesign(experimentAccession); - } - private static String joinURIs(Set ontologyTerms) { return ontologyTerms.stream().map(OntologyTerm::uri).collect(joining(" ")); } diff --git a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java index 349d5c5d..f62715a1 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/ebeyedump/ExperimentsConditionsDetailsController.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import uk.ac.ebi.atlas.model.experiment.Experiment; +import uk.ac.ebi.atlas.model.experiment.ExperimentDesign; import uk.ac.ebi.atlas.model.experiment.ExperimentType; import uk.ac.ebi.atlas.model.experiment.baseline.BaselineExperiment; import uk.ac.ebi.atlas.model.experiment.differential.DifferentialExperiment; @@ -36,7 +37,8 @@ public ExperimentsConditionsDetailsController(ExperimentTrader experimentTrader) public void generateTsvFormatBaseline(HttpServletResponse response) { writeTsvLinesToResponse( response, - experiment -> new BaselineExperimentAssayGroupsLines(experimentTrader, (BaselineExperiment) experiment), + experiment -> new BaselineExperimentAssayGroupsLines( + (BaselineExperiment) experiment, getExperimentDesign(experiment.getAccession())), RNASEQ_MRNA_BASELINE, PROTEOMICS_BASELINE, PROTEOMICS_BASELINE_DIA); @@ -46,13 +48,18 @@ public void generateTsvFormatBaseline(HttpServletResponse response) { public void generateTsvFormatDifferential(HttpServletResponse response) { writeTsvLinesToResponse( response, - experiment -> new DifferentialExperimentContrastLines(experimentTrader, (DifferentialExperiment) experiment), + experiment -> new DifferentialExperimentContrastLines( + (DifferentialExperiment) experiment, getExperimentDesign(experiment.getAccession())), MICROARRAY_1COLOUR_MICRORNA_DIFFERENTIAL, MICROARRAY_1COLOUR_MRNA_DIFFERENTIAL, MICROARRAY_2COLOUR_MRNA_DIFFERENTIAL, RNASEQ_MRNA_DIFFERENTIAL); } + private ExperimentDesign getExperimentDesign(String experimentAccession) { + return experimentTrader.getExperimentDesign(experimentAccession); + } + private void writeTsvLinesToResponse(HttpServletResponse response, Function> linesIteratorProducer, ExperimentType... experimentTypes) { diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/baseline/BaselineExperimentPageService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/baseline/BaselineExperimentPageService.java index 4d738f01..d8e01510 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/baseline/BaselineExperimentPageService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/baseline/BaselineExperimentPageService.java @@ -9,6 +9,7 @@ import uk.ac.ebi.atlas.experimentpage.baseline.profiles.BaselineExperimentProfilesListSerializer; import uk.ac.ebi.atlas.experimentpage.baseline.profiles.BaselineExperimentProfilesService; import uk.ac.ebi.atlas.experimentpage.context.BaselineRequestContext; +import uk.ac.ebi.atlas.model.experiment.ExperimentDesign; import uk.ac.ebi.atlas.model.experiment.sample.AssayGroup; import uk.ac.ebi.atlas.model.ExpressionUnit; import uk.ac.ebi.atlas.model.GeneProfilesList; @@ -17,7 +18,6 @@ import uk.ac.ebi.atlas.model.experiment.baseline.BaselineProfile; import uk.ac.ebi.atlas.model.experiment.sdrf.RichFactorGroup; import uk.ac.ebi.atlas.model.experiment.summary.AssayGroupSummaryBuilder; -import uk.ac.ebi.atlas.trader.ExperimentTrader; import uk.ac.ebi.atlas.web.BaselineRequestPreferences; import java.util.List; @@ -29,25 +29,23 @@ public class BaselineExperimentPageService extends ExperimentPageService { private final BaselineExperimentProfilesService baselineExperimentProfilesService; private final CoexpressedGenesService coexpressedGenesService; private final AnatomogramFactory anatomogramFactory; - private final ExperimentTrader experimentTrader; public BaselineExperimentPageService(BaselineExperimentProfilesService baselineExperimentProfilesService, - CoexpressedGenesService coexpressedGenesService, - ExperimentTrader experimentTrader) { + CoexpressedGenesService coexpressedGenesService) { super(); this.anatomogramFactory = new AnatomogramFactory(); this.baselineExperimentProfilesService = baselineExperimentProfilesService; this.coexpressedGenesService = coexpressedGenesService; - this.experimentTrader = experimentTrader; } public JsonObject getResultsForExperiment( - BaselineExperiment experiment, String accessKey, BaselineRequestPreferences preferences) { + BaselineExperiment experiment, ExperimentDesign experimentDesign, String accessKey, + BaselineRequestPreferences preferences) { BaselineRequestContext requestContext = new BaselineRequestContext<>(preferences, experiment); JsonObject result = new JsonObject(); - result.add("columnHeaders", constructColumnHeaders(requestContext, experiment)); + result.add("columnHeaders", constructColumnHeaders(requestContext, experiment, experimentDesign)); result.add("columnGroupings", new JsonArray()); GeneProfilesList baselineProfilesList = fetchProfiles(experiment, preferences); @@ -92,7 +90,8 @@ private GeneProfilesList fetchProfiles(BaselineExperiment exper return baselineProfilesList; } - private JsonArray constructColumnHeaders(BaselineRequestContext requestContext, BaselineExperiment experiment) { + private JsonArray constructColumnHeaders(BaselineRequestContext requestContext, BaselineExperiment experiment, + ExperimentDesign experimentDesign) { JsonArray result = new JsonArray(); for (AssayGroup dataColumnDescriptor : requestContext.getDataColumnsToReturn()) { @@ -105,7 +104,7 @@ private JsonArray constructColumnHeaders(BaselineRequestContext requestContex o.add("assayGroupSummary", new AssayGroupSummaryBuilder() .forAssayGroup(experiment.getDataColumnDescriptor(dataColumnDescriptor.getId())) - .withExperimentDesign(experimentTrader.getExperimentDesign(experiment.getAccession())) + .withExperimentDesign(experimentDesign) .build().toJson()); result.add(o); } diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java index c927902c..ab5ba197 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/content/ExperimentPageContentService.java @@ -71,7 +71,8 @@ private JsonObject experimentPageContentForExperiment(final Experiment getExperimentVariablesAsHeatmapFilterGroups( - ExperimentTrader experimentTrader, - Experiment experiment) { + Experiment experiment, + ExperimentDesign experimentDesign) { final String experimentAccession = experiment.getAccession(); if (!(experiment instanceof BaselineExperiment) && !(experiment instanceof DifferentialExperiment)) { throw new IllegalArgumentException( @@ -89,7 +88,7 @@ public static ImmutableList getExperimentVariablesAsHeatmapF Streams.concat( Stream.of(experiment.getDisplayDefaults().getDefaultQueryFactorType()), experiment.getDisplayDefaults().getFactorTypes().stream(), - getExperimentDesign(experimentTrader, experimentAccession).getFactorHeaders().stream()) + experimentDesign.getFactorHeaders().stream()) .filter(StringUtils::isNotBlank) // defaultQueryFactorType in diff experiments is "" .map(Factor::normalize) .collect(toImmutableSet()); @@ -106,18 +105,18 @@ public static ImmutableList getExperimentVariablesAsHeatmapF experiment.getDisplayDefaults() .defaultFilterValuesForFactor(factorHeader) .orElse(ALL_VALUES_KEYWORD), - mapAssayGroupsToFactors(experimentTrader, assayId2AssayGroup, factorHeader, + mapAssayGroupsToFactors(experimentDesign, assayId2AssayGroup, factorHeader, experiment))); Stream sampleCharacteristicGroups = - getExperimentDesign(experimentTrader, experimentAccession).getSampleCharacteristicHeaders().stream() + experimentDesign.getSampleCharacteristicHeaders().stream() .filter(sampleCharacteristicHeader -> !orderedFactors.contains(Factor.normalize(sampleCharacteristicHeader))) .map(sampleCharacteristicHeader -> HeatmapFilterGroup.create( sampleCharacteristicHeader, primaryVariables.contains(sampleCharacteristicHeader), ALL_VALUES_KEYWORD, - mapAssayGroupsToSampleCharacteristics(experimentTrader, assayId2AssayGroup, + mapAssayGroupsToSampleCharacteristics(experimentDesign, assayId2AssayGroup, sampleCharacteristicHeader, experiment))); return Streams.concat( @@ -127,40 +126,31 @@ public static ImmutableList getExperimentVariablesAsHeatmapF .collect(toImmutableList()); } - private static ExperimentDesign getExperimentDesign(ExperimentTrader experimentTrader, - String experimentAccession) { - return experimentTrader.getExperimentDesign(experimentAccession); - } - @NotNull private static ImmutableSetMultimap mapAssayGroupsToFactors( - ExperimentTrader experimentTrader, + ExperimentDesign experimentDesign, @NotNull ImmutableMultimap assayId2AssayGroup, @NotNull String factorHeader, @NotNull Experiment<@NotNull ?> experiment) { return assayId2AssayGroup.keySet().stream() - .filter(assayId -> getExperimentDesign(experimentTrader, experiment.getAccession()) - .getFactor(assayId, factorHeader) != null) + .filter(assayId -> experimentDesign.getFactor(assayId, factorHeader) != null) .collect(flatteningToImmutableSetMultimap( - assayId -> getExperimentDesign(experimentTrader, experiment.getAccession()) - .getFactor(assayId, factorHeader).getValue(), + assayId -> experimentDesign.getFactor(assayId, factorHeader).getValue(), assayId -> assayId2AssayGroup.get(assayId).stream())); } @NotNull private static ImmutableSetMultimap mapAssayGroupsToSampleCharacteristics( - ExperimentTrader experimentTrader, + ExperimentDesign experimentDesign, @NotNull ImmutableMultimap assayId2AssayGroup, @NotNull String sampleCharacteristicHeader, @NotNull Experiment<@NotNull?> experiment) { return assayId2AssayGroup.keySet().stream() .filter(assayId -> - getExperimentDesign(experimentTrader, experiment.getAccession()) - .getSampleCharacteristic(assayId, sampleCharacteristicHeader) != null) + experimentDesign.getSampleCharacteristic(assayId, sampleCharacteristicHeader) != null) .collect(flatteningToImmutableSetMultimap( assayId -> - getExperimentDesign(experimentTrader, experiment.getAccession()) - .getSampleCharacteristic(assayId, sampleCharacteristicHeader).getValue(), + experimentDesign.getSampleCharacteristic(assayId, sampleCharacteristicHeader).getValue(), assayId -> assayId2AssayGroup.get(assayId).stream())); } } diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/differential/DifferentialExperimentPageService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/differential/DifferentialExperimentPageService.java index 2a2e39a8..c350b556 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/differential/DifferentialExperimentPageService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/differential/DifferentialExperimentPageService.java @@ -9,6 +9,7 @@ import uk.ac.ebi.atlas.experimentpage.context.DifferentialRequestContext; import uk.ac.ebi.atlas.experimentpage.context.DifferentialRequestContextFactory; import uk.ac.ebi.atlas.model.ExpressionUnit; +import uk.ac.ebi.atlas.model.experiment.ExperimentDesign; import uk.ac.ebi.atlas.model.experiment.sample.Contrast; import uk.ac.ebi.atlas.model.experiment.differential.DifferentialExperiment; import uk.ac.ebi.atlas.model.experiment.differential.DifferentialExpression; @@ -17,7 +18,6 @@ import uk.ac.ebi.atlas.model.experiment.summary.ContrastSummaryBuilder; import uk.ac.ebi.atlas.profiles.json.ExternallyViewableProfilesList; import uk.ac.ebi.atlas.resource.ContrastImageTrader; -import uk.ac.ebi.atlas.trader.ExperimentTrader; import uk.ac.ebi.atlas.web.DifferentialRequestPreferences; import java.util.List; @@ -36,20 +36,18 @@ private final ContrastImageTrader contrastImageTrader; private final DifferentialRequestContextFactory differentialRequestContextFactory; private final DifferentialProfilesHeatMap profilesHeatMap; - private final ExperimentTrader experimentTrader; public DifferentialExperimentPageService( DifferentialRequestContextFactory differentialRequestContextFactory, DifferentialProfilesHeatMap profilesHeatMap, - ContrastImageTrader contrastImageTrader, - ExperimentTrader experimentTrader) { + ContrastImageTrader contrastImageTrader) { this.differentialRequestContextFactory = differentialRequestContextFactory; this.profilesHeatMap = profilesHeatMap; this.contrastImageTrader = contrastImageTrader; - this.experimentTrader = experimentTrader; } - public JsonObject getResultsForExperiment(E experiment, String accessKey, K preferences) { + public JsonObject getResultsForExperiment(E experiment, ExperimentDesign experimentDesign, + String accessKey, K preferences) { JsonObject result = new JsonObject(); R requestContext = differentialRequestContextFactory.create(experiment, preferences); @@ -63,7 +61,7 @@ public JsonObject getResultsForExperiment(E experiment, String accessKey, K pref } result.add("columnGroupings", new JsonArray()); - result.add("columnHeaders", constructColumnHeaders(contrasts, experiment)); + result.add("columnHeaders", constructColumnHeaders(contrasts, experiment, experimentDesign)); result.add("profiles", new ExternallyViewableProfilesList<>( profiles, new LinkToGene<>(), requestContext.getDataColumnsToReturn(), p -> ExpressionUnit.Relative.FOLD_CHANGE).asJson()); @@ -72,14 +70,15 @@ public JsonObject getResultsForExperiment(E experiment, String accessKey, K pref } private JsonArray constructColumnHeaders(Iterable contrasts, - DifferentialExperiment differentialExperiment) { + DifferentialExperiment differentialExperiment, + ExperimentDesign experimentDesign) { JsonArray result = new JsonArray(); Map contrastImages = contrastImageTrader.contrastImages(differentialExperiment); for (Contrast contrast : contrasts) { JsonObject o = contrast.toJson(); o.add("contrastSummary", new ContrastSummaryBuilder() .forContrast(contrast) - .withExperimentDesign(experimentTrader.getExperimentDesign(differentialExperiment.getAccession())) + .withExperimentDesign(experimentDesign) .withExperimentDescription(differentialExperiment.getDescription()) .build().toJson()); o.add("resources", contrastImages.get(contrast.getId())); diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonBaselineExperimentController.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonBaselineExperimentController.java index 5e23947a..a038204e 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonBaselineExperimentController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/JsonBaselineExperimentController.java @@ -50,7 +50,7 @@ public class JsonBaselineExperimentController extends JsonExperimentController { this.baselineExperimentPageService = new BaselineExperimentPageService( - baselineExperimentProfilesService, coexpressedGenesService,experimentTrader); + baselineExperimentProfilesService, coexpressedGenesService); this.rnaSeqHistograms = new HistogramService.RnaSeq(rnaSeqBaselineProfileStreamFactory, experimentTrader); @@ -68,6 +68,7 @@ private String baselineExperimentData(BaselineRequestPreferences(new DifferentialRequestContextFactory.RnaSeq(), new DifferentialProfilesHeatMap<>(bulkDifferentialProfileStreamFactory, solrQueryService), - atlasResourceHub, - experimentTrader); + atlasResourceHub); diffMicroarrayExperimentPageService = new DifferentialExperimentPageService<>(new DifferentialRequestContextFactory.Microarray(), new DifferentialProfilesHeatMap<>(microarrayProfileStreamFactory, solrQueryService), - atlasResourceHub, - experimentTrader); + atlasResourceHub); } private String differentialMicroarrayExperimentData(MicroarrayRequestPreferences preferences, @@ -80,6 +78,7 @@ private String differentialMicroarrayExperimentData(MicroarrayRequestPreferences String accessKey) { return GSON.toJson(diffMicroarrayExperimentPageService.getResultsForExperiment( (MicroarrayExperiment) experimentTrader.getExperiment(experimentAccession, accessKey), + experimentTrader.getExperimentDesign(experimentAccession), accessKey, preferences)); } @@ -127,6 +126,7 @@ public String differentialRnaSeqExperimentData( @RequestParam(defaultValue = "") String accessKey) { return GSON.toJson(differentialExperimentPageService.getResultsForExperiment( (DifferentialExperiment) experimentTrader.getExperiment(experimentAccession, accessKey), + experimentTrader.getExperimentDesign(experimentAccession), accessKey, preferences)); } @@ -140,6 +140,7 @@ public String differentialProteomicsExperimentData( @RequestParam(defaultValue = "") String accessKey) { return GSON.toJson(differentialExperimentPageService.getResultsForExperiment( (DifferentialExperiment) experimentTrader.getExperiment(experimentAccession, accessKey), + experimentTrader.getExperimentDesign(experimentAccession), accessKey, preferences)); } } diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java index 87408f36..fd407931 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceService.java @@ -26,7 +26,6 @@ import uk.ac.ebi.atlas.profiles.differential.DifferentialProfileStreamOptions; import uk.ac.ebi.atlas.profiles.stream.ProfileStreamFactory; import uk.ac.ebi.atlas.resource.DataFileHub; -import uk.ac.ebi.atlas.trader.ExperimentTrader; import java.text.MessageFormat; import java.text.SimpleDateFormat; @@ -51,26 +50,24 @@ public class EvidenceService differentialProfileStreamFactory; private final DataFileHub dataFileHub; private final String expressionAtlasVersion; - private final ExperimentTrader experimentTrader; public EvidenceService(ProfileStreamFactory differentialProfileStreamFactory, DataFileHub dataFileHub, - ExperimentTrader experimentTrader, String expressionAtlasVersion) { this.differentialProfileStreamFactory = differentialProfileStreamFactory; this.dataFileHub = dataFileHub; - this.experimentTrader = experimentTrader; this.expressionAtlasVersion = expressionAtlasVersion; } public void evidenceForExperiment(E experiment, + ExperimentDesign experimentDesign, Function queryForOneContrast, Consumer yield) { - if (shouldSkip(experiment)) { + if (shouldSkip(experiment, experimentDesign)) { return; } - var diseaseAssociations = getDiseaseAssociations(experiment); + var diseaseAssociations = getDiseaseAssociations(experiment, experimentDesign); if (diseaseAssociations.isEmpty()) { return; } @@ -109,11 +106,10 @@ public void evidenceForExperiment(E experiment, } } - private boolean shouldSkip(E experiment) { + private boolean shouldSkip(E experiment, ExperimentDesign experimentDesign) { return !experiment.getSpecies().isUs() || experiment.getType().isMicroRna() || - cellLineAsSampleCharacteristicButNoDiseaseAsFactor( - getExperimentDesign(experiment.getAccession())); + cellLineAsSampleCharacteristicButNoDiseaseAsFactor(experimentDesign); } private void piecesOfEvidence(E experiment, @@ -405,21 +401,16 @@ private JsonObject associationRecord(JsonObject uniqueAssociationFields, return associationRecord; } - private ImmutableMap getDiseaseAssociations(DifferentialExperiment experiment) { + private ImmutableMap getDiseaseAssociations(DifferentialExperiment experiment, + ExperimentDesign experimentDesign) { var contrastToDiseaseBuilder = ImmutableMap.builder(); for (var contrast: experiment.getDataColumnDescriptors()) { - DiseaseAssociation.tryCreate(getExperimentDesign(experiment.getAccession()), experiment, contrast) + DiseaseAssociation.tryCreate(experimentDesign, experiment, contrast) .ifPresent(diseaseAssociation -> contrastToDiseaseBuilder.put(contrast, diseaseAssociation)); } return contrastToDiseaseBuilder.build(); } - private ExperimentDesign getExperimentDesign(String experimentAccession) { - return experimentTrader.getExperimentDesign(experimentAccession); - } - - - @AutoValue abstract static class DiseaseAssociation { enum CONFIDENCE { diff --git a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/OpenTargetsEvidenceController.java b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/OpenTargetsEvidenceController.java index d8e0a4ae..d07f4724 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/OpenTargetsEvidenceController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/OpenTargetsEvidenceController.java @@ -54,9 +54,9 @@ public OpenTargetsEvidenceController(ExperimentTrader experimentTrader, bulkDifferentialEvidenceService = new EvidenceService<>( - bulkDifferentialProfileStreamFactory, dataFileHub, experimentTrader, resourcesVersion); + bulkDifferentialProfileStreamFactory, dataFileHub, resourcesVersion); diffMicroarrayEvidenceService = - new EvidenceService<>(microarrayProfileStreamFactory, dataFileHub, experimentTrader, resourcesVersion); + new EvidenceService<>(microarrayProfileStreamFactory, dataFileHub, resourcesVersion); } @InitBinder("preferences") @@ -78,6 +78,7 @@ private void differentialMicroarrayExperimentEvidence(double logFoldChangeCutoff PrintWriter responseWriter = response.getWriter(); diffMicroarrayEvidenceService.evidenceForExperiment( experiment, + experimentTrader.getExperimentDesign(experimentAccession), contrast -> { MicroarrayRequestPreferences requestPreferences = new MicroarrayRequestPreferences(); requestPreferences.setFoldChangeCutoff(logFoldChangeCutoff); @@ -159,6 +160,7 @@ public void differentialRnaSeqExperimentEvidence( PrintWriter printWriter = response.getWriter(); bulkDifferentialEvidenceService.evidenceForExperiment( experiment, + experimentTrader.getExperimentDesign(experimentAccession), contrast -> { DifferentialRequestPreferences requestPreferences = new DifferentialRequestPreferences(); requestPreferences.setFoldChangeCutoff(logFoldChangeCutoff); diff --git a/app/src/test/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLinesTest.java b/app/src/test/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLinesTest.java index d412d081..8bc774d6 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLinesTest.java +++ b/app/src/test/java/uk/ac/ebi/atlas/ebeyedump/BaselineExperimentAssayGroupsLinesTest.java @@ -24,7 +24,6 @@ import static org.apache.commons.lang3.StringUtils.wrap; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -72,9 +71,6 @@ public class BaselineExperimentAssayGroupsLinesTest { @Mock private BaselineExperiment baselineExperiment; - @Mock - private ExperimentTrader experimentTraderMock; - @Test public void lines() { ExperimentDesign experimentDesign = new ExperimentDesign(); @@ -94,10 +90,9 @@ public void lines() { when(baselineExperiment.getAccession()).thenReturn(EXPERIMENT_ACCESSION); when(baselineExperiment.getDataColumnDescriptors()).thenReturn(ImmutableList.of(ASSAY_GROUP1, ASSAY_GROUP2, ASSAY_GROUP3)); - when(experimentTraderMock.getExperimentDesign(any())).thenReturn(experimentDesign); BaselineExperimentAssayGroupsLines subject = - new BaselineExperimentAssayGroupsLines(experimentTraderMock, baselineExperiment); + new BaselineExperimentAssayGroupsLines(baselineExperiment, experimentDesign); Iterator lines = subject.iterator(); diff --git a/app/src/test/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceServiceIT.java b/app/src/test/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceServiceIT.java index 23a857e2..c304be85 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceServiceIT.java +++ b/app/src/test/java/uk/ac/ebi/atlas/experimentpage/json/opentargets/EvidenceServiceIT.java @@ -67,7 +67,7 @@ void cleanDatabaseTables() { @BeforeEach void setUp() { subject = new EvidenceService<>( - microarrayProfileStreamFactory, dataFileHub, experimentTrader, "test"); + microarrayProfileStreamFactory, dataFileHub, "test"); } @Test @@ -75,7 +75,9 @@ void organismPartIsIncludedIfAvailable() { var listBuilder = ImmutableList.builder(); var experiment = (MicroarrayExperiment) experimentTrader.getPublicExperiment("E-GEOD-40611"); subject.evidenceForExperiment( - experiment, contrast -> { + experiment, + experimentTrader.getExperimentDesign(experiment.getAccession()), + contrast -> { var requestPreferences = new MicroarrayRequestPreferences(); requestPreferences.setHeatmapMatrixSize(1000); requestPreferences.setSelectedColumnIds(ImmutableSet.of(contrast.getId())); @@ -95,7 +97,9 @@ void diseaseIdIsIncludedAsUniqueAssociation() { var listBuilder = ImmutableList.builder(); var experiment = (MicroarrayExperiment) experimentTrader.getPublicExperiment("E-GEOD-40611"); subject.evidenceForExperiment( - experiment, contrast -> { + experiment, + experimentTrader.getExperimentDesign(experiment.getAccession()), + contrast -> { var requestPreferences = new MicroarrayRequestPreferences(); requestPreferences.setHeatmapMatrixSize(1000); requestPreferences.setSelectedColumnIds(ImmutableSet.of(contrast.getId())); diff --git a/app/src/test/java/uk/ac/ebi/atlas/model/experiment/ExperimentGroupingsForHeatmapIT.java b/app/src/test/java/uk/ac/ebi/atlas/model/experiment/ExperimentGroupingsForHeatmapIT.java index 8bb4b82c..c225ed11 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/model/experiment/ExperimentGroupingsForHeatmapIT.java +++ b/app/src/test/java/uk/ac/ebi/atlas/model/experiment/ExperimentGroupingsForHeatmapIT.java @@ -85,7 +85,7 @@ void outputInFineFormatForExperiment(String accession) { JsonArray result = GSON.toJsonTree(HeatmapGroupingsService.getExperimentVariablesAsHeatmapFilterGroups( - experimentTrader, experiment)) + experiment, experimentTrader.getExperimentDesign(accession))) .getAsJsonArray(); assertThat(result.size(), greaterThan(0));