ExperimentAttributesService { public Map<String, Object> getAttributes(Experiment<?> experiment) { Map<String, Object> result = new HashMap<>(); result.put("experimentAccession", experiment.getAccession()); result.put("experimentDescription", experiment.getDescription()); result.put("type", experiment.getType().getHumanDescription()); result.putAll(experiment.getSpecies().getAttributes()); result.put("pubMedIds", experiment.getPubMedIds()); result.put("dois", experiment.getDois()); result.put("disclaimer", experiment.getDisclaimer()); result.put("lastUpdated", new SimpleDateFormat("dd-MM-yyyy").format(experiment.getLastUpdate())); result.put("numberOfAssays", experiment.getAnalysedAssays().size()); result.put("factors", experiment.getExperimentDesign().getFactorHeaders()); if (!experiment.getDois().isEmpty()) { result.put("publications", getPublications(experiment.getDois())); } else if (!experiment.getPubMedIds().isEmpty()) { result.put("publications", getPublications(experiment.getPubMedIds())); } result.put("longDescription", idfParser.parse(experiment.getAccession()).getExperimentDescription()); List<String> keywords = ImmutableList.<String>builder() .add("experiment") .add(experiment.getAccession()) .addAll(experiment.getDataProviderDescription()) .addAll(Arrays.asList(experiment.getType().getDescription().split("_"))) .addAll(experiment.getExperimentDesign().getAssayHeaders()) .build(); result.put("pageKeywords", Joiner.on(',').join(keywords)); result.put("pageDescription", experiment.getDescription()); result.put("dataProviderURL", experiment.getDataProviderURL()); result.put("dataProviderDescription", experiment.getDataProviderDescription()); result.put("alternativeViews", experiment.getAlternativeViews()); result.put("alternativeViewDescriptions", experiment.getAlternativeViewDescriptions()); if (experiment instanceof MicroarrayExperiment) { MicroarrayExperiment microarrayExperiment = (MicroarrayExperiment) experiment; result.put("arrayDesignAccessions", microarrayExperiment.getArrayDesignAccessions()); result.put("arrayDesignNames", microarrayExperiment.getArrayDesignNames()); } else if (experiment instanceof DifferentialExperiment) { result.put("regulationValues", Regulation.values()); result.put("contrasts", experiment.getDataColumnDescriptors()); } return result; } ExperimentAttributesService(EuropePmcClient europePmcClient, IdfParser idfParser); Map<String, Object> getAttributes(Experiment<?> experiment);  }
@Test public void getAttributesForBaselineExperimentWithNoPublications() { when(europePmcClientMock.getPublicationByIdentifier(anyString())).thenReturn(Optional.empty()); when(idfParser.parse(any())) .thenReturn(new IdfParserOutput("title", "12345","description", Lists.emptyList(), 0, Lists.emptyList())); BaselineExperiment experiment = MockExperiment.createBaselineExperiment("FOOBAR"); Map<String, Object> result = subject.getAttributes(experiment); assertThat(result) .containsKeys(BASELINE_EXPERIMENT_ATTRIBUTES) .doesNotContainKeys(DIFFERENTIAL_EXPERIMENT_ATTRIBUTES) .doesNotContainKeys(MICROARRAY_EXPERIMENT_ATTRIBUTES) .extracting("experimentAccession", "type", "publications") .contains("FOOBAR", ExperimentType.RNASEQ_MRNA_BASELINE.getHumanDescription(), Lists.emptyList()); }
@Test public void getAttributesForBaselineExperimentWithPublicationsFromDois() { List<String> dois = Arrays.asList("100.100/doi", "999.100/another-doi"); when(europePmcClientMock.getPublicationByIdentifier("100.100/doi")) .thenReturn(Optional.of(new Publication("", "100.100/doi", "Publication 1"))); when(europePmcClientMock.getPublicationByIdentifier("999.100/another-doi")) .thenReturn(Optional.of(new Publication("", "999.100/another-doi", "Publication 2"))); when(idfParser.parse(any())) .thenReturn(new IdfParserOutput("title", "12345","description", Lists.emptyList(), 0, Lists.emptyList())); BaselineExperiment experiment = MockExperiment.createBaselineExperiment(Lists.emptyList(), dois); Map<String, Object> result = subject.getAttributes(experiment); assertThat(result).extracting("publications").isNotEmpty(); }
@Test public void getAttributesForBaselineExperimentWithPublicationsFromPubmedIds() { List<String> pubmedIds = Arrays.asList("1123", "1235"); when(europePmcClientMock.getPublicationByIdentifier("1123")) .thenReturn(Optional.of(new Publication("1123", "100.100/doi", "Publication 1"))); when(europePmcClientMock.getPublicationByIdentifier("1235")) .thenReturn(Optional.of(new Publication("1235", "999.100/another-doi", "Publication 2"))); when(idfParser.parse(any())) .thenReturn(new IdfParserOutput("title", "12345","description", Lists.emptyList(), 0, Lists.emptyList())); BaselineExperiment experiment = MockExperiment.createBaselineExperiment(pubmedIds, Lists.emptyList()); Map<String, Object> result = subject.getAttributes(experiment); assertThat(result).extracting("publications").isNotEmpty(); }
@Test public void getAttributesForDifferentialExperiment() { DifferentialExperiment experiment = MockExperiment.createDifferentialExperiment(); when(idfParser.parse(any())) .thenReturn(new IdfParserOutput("title", "12345","description", Lists.emptyList(), 0, Lists.emptyList())); Map<String, Object> result = subject.getAttributes(experiment); assertThat(result) .containsKeys(BASELINE_EXPERIMENT_ATTRIBUTES) .containsKeys(DIFFERENTIAL_EXPERIMENT_ATTRIBUTES) .doesNotContainKeys(MICROARRAY_EXPERIMENT_ATTRIBUTES); }
@Test public void getAttributesForMicroarrayExperiment() { MicroarrayExperiment experiment = MockExperiment.createMicroarrayExperiment(); when(idfParser.parse(any())) .thenReturn(new IdfParserOutput("title", "12345","description", Lists.emptyList(), 0, Lists.emptyList())); Map<String, Object> result = subject.getAttributes(experiment); assertThat(result) .containsKeys(BASELINE_EXPERIMENT_ATTRIBUTES) .containsKeys(MICROARRAY_EXPERIMENT_ATTRIBUTES) .doesNotContainKeys(DIFFERENTIAL_EXPERIMENT_ATTRIBUTES); }