IdfParser { public IdfParserOutput parse(String experimentAccession) { try (TsvStreamer idfStreamer = dataFileHub.getExperimentFiles(experimentAccession).idf.get()) { parsedIdf = idfStreamer.get() .filter(line -> line.length > 1) .filter(line -> LINE_IDS.contains(convertIdfFieldNameToKey(line[0]))) .collect(Collectors.toMap( line -> convertIdfFieldNameToKey(line[0]), line -> Arrays.stream(line) .skip(1) .filter(item -> !item.isEmpty()) .collect(Collectors.toList()), (accumulatedValues, newValue) -> accumulatedValues)); String title = getParsedOutputByKey( AE_EXPERIMENT_DISPLAY_NAME_ID, getParsedOutputByKey(INVESTIGATION_TITLE_ID, emptyList())) .stream() .findFirst() .orElse(""); String secondaryAccession = getParsedOutputByKey(SECONDARY_ACCESSION_ID, emptyList()) .stream() .findFirst() .orElse(""); String experimentDescription = getParsedOutputByKey(EXPERIMENT_DESCRIPTION_ID, emptyList()) .stream() .findFirst() .orElse(""); List<Publication> publications = createListOfPublications( getParsedOutputByKey(PUBMED_ID, emptyList()), getParsedOutputByKey(PUBLICATION_TITLE_ID, emptyList()), getParsedOutputByKey(PUBLICATION_DOI_ID, emptyList())); int expectedClusters = NumberUtils.toInt(getParsedOutputByKey(EXPECTED_CLUSTERS_ID, emptyList()) .stream() .findFirst() .orElse(""), 0); List<String> metadataFieldsOfInterest = getParsedOutputByKey(ADDITIONAL_ATTRIBUTES_ID, emptyList()); return new IdfParserOutput( title, secondaryAccession, experimentDescription, publications, expectedClusters, metadataFieldsOfInterest ); } } @Inject  IdfParser(DataFileHub dataFileHub); IdfParserOutput parse(String experimentAccession);  }
@Test void parse() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT)); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEqualTo(AE_DISPLAY_NAME); assertThat(idfParserOutput.getPubmedIds()).containsOnlyElementsOf(PUBMED_IDS); assertThat(idfParserOutput.getExpectedClusters()).isEqualTo(NumberUtils.toInt(EXPECTED_CLUSTERS)); assertThat(idfParserOutput.getMetadataFieldsOfInterest()) .containsOnlyElementsOf(ImmutableSet.copyOf(ADDITIONAL_ATTRIBUTES)); }
@Test void parseMixedCaseKeys() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT_MIXED_CASE)); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEqualTo(AE_DISPLAY_NAME); assertThat(idfParserOutput.getPubmedIds()).containsOnlyElementsOf(PUBMED_IDS); assertThat(idfParserOutput.getExpectedClusters()).isEqualTo(NumberUtils.toInt(EXPECTED_CLUSTERS)); }
@Test void parseNoPubmedIds() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT[0], IDF_TXT[1])); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEqualTo(AE_DISPLAY_NAME); assertThat(idfParserOutput.getPublications()).isEmpty(); }
@Test void parseNoAeDisplayName() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT[0], IDF_TXT[2], IDF_TXT[3])); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEqualTo(INVESTIGATION_TITLE); assertThat(idfParserOutput.getPubmedIds()).containsOnlyElementsOf(PUBMED_IDS); }
@Test void parseNoAeDisplayNameNoTitle() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT[2], IDF_TXT[3])); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEmpty(); assertThat(idfParserOutput.getPubmedIds()).containsOnlyElementsOf(PUBMED_IDS); }
@Test void parseNothing() { dataFileHub.addIdfFile(E_MTAB_513, Collections.emptyList()); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEmpty(); assertThat(idfParserOutput.getPublications()).isEmpty(); assertThat(idfParserOutput.getExpectedClusters()).isEqualTo(0); }
@Test void keepsOnlyFirstValueOfDuplicateFields() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT_DUPLICATE_FIELDS)); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEqualTo(AE_DISPLAY_NAME); }
@Test void skipsEmptyDisplayName() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT_EMPTY_DISPLAY_NAME)); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEqualTo(INVESTIGATION_TITLE); }
@Test void parsesCommentsWithWhitespaces() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT_WHITESPACES_IN_COMMENTS)); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEqualTo(AE_DISPLAY_NAME); assertThat(idfParserOutput.getExpectedClusters()).isEqualTo(NumberUtils.toInt(EXPECTED_CLUSTERS)); }
@Test void ignoresFieldsWithEmptyValuesMadeUpOfWhitespaces() { dataFileHub.addIdfFile(E_MTAB_513, Arrays.asList(IDF_TXT_SPACES_IN_FIELD_VALUES)); IdfParserOutput idfParserOutput = subject.parse(E_MTAB_513); assertThat(idfParserOutput.getTitle()).isEqualTo(INVESTIGATION_TITLE); }