TsnePlotSettingsService { public Optional<Integer> getExpectedClusters(String experimentAccession) { IdfParserOutput idfParserOutput = idfParser.parse(experimentAccession); if (idfParserOutput.getExpectedClusters() != 0 && getAvailableKs(experimentAccession).contains(idfParserOutput.getExpectedClusters())) { return Optional.of(idfParserOutput.getExpectedClusters()); } else { try (TsvStreamer clustersTsvStreamer = dataFileHub.getSingleCellExperimentFiles(experimentAccession).clustersTsv.get()) { return clustersTsvStreamer.get() .skip(1) .filter(line -> line[0].equalsIgnoreCase("true")) .map(line -> Integer.parseInt(line[1])) .findFirst(); } } } TsnePlotSettingsService(DataFileHub dataFileHub,
                                   IdfParser idfParser,
                                   TSnePlotDao tSnePlotDao,
                                   MarkerGenesDao markerGenesDao); Optional<Integer> getExpectedClusters(String experimentAccession);  }
@Test @DisplayName("Expected clusters value in idf is a valid cluster") void expectedClustersOnlyInIdf() { dataFileHubMock.addClustersFile( EXPERIMENT_ACCESSION, Arrays.asList(CLUSTERS_TSV_WITHOUT_PREFFERED_K_WITH_IDF_K)); when(idfParserMock.parse(EXPERIMENT_ACCESSION)) .thenReturn( new IdfParserOutput( "Title", "", "Description", Collections.emptyList(), Integer.parseInt(IDF_PREFERRED_K), Collections.emptyList())); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION)) .isPresent(); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION).get()) .isEqualTo(Integer.parseInt(IDF_PREFERRED_K)); }
@Test @DisplayName("Valid expected clusters in idf and clusters.tsv") void expectedClustersInIdfAndClustersTsv() { dataFileHubMock.addClustersFile(EXPERIMENT_ACCESSION, Arrays.asList(CLUSTERS_TSV_WITH_PREFFERED_K_WITH_IDF_K)); when(idfParserMock.parse(EXPERIMENT_ACCESSION)) .thenReturn( new IdfParserOutput( "Title", "", "Description", Collections.emptyList(), Integer.parseInt(IDF_PREFERRED_K), Collections.emptyList())); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION)) .isPresent(); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION).get()) .isEqualTo(Integer.parseInt(IDF_PREFERRED_K)); }
@Test @DisplayName("Expected clusters in idf is invalid and no value in clusters.tsv") void invalidExpectedClustersInIdf() { dataFileHubMock.addClustersFile( EXPERIMENT_ACCESSION, Arrays.asList(CLUSTERS_TSV_WITHOUT_PREFFERED_K_WITHOUT_IDF_K)); when(idfParserMock.parse(EXPERIMENT_ACCESSION)) .thenReturn( new IdfParserOutput( "Title", "", "Description", Collections.emptyList(), Integer.parseInt(IDF_PREFERRED_K), Collections.emptyList())); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION)).isNotPresent(); }
@Test @DisplayName("Expected clusters in idf is invalid and expected clusters in clusters.tsv") void invalidIdfValueValidClustersTsv() { dataFileHubMock.addClustersFile( EXPERIMENT_ACCESSION, Arrays.asList(CLUSTERS_TSV_WITH_PREFFERED_K_WITHOUT_IDF_K)); when(idfParserMock.parse(EXPERIMENT_ACCESSION)) .thenReturn( new IdfParserOutput( "Title", "", "Description", Collections.emptyList(), Integer.parseInt(IDF_PREFERRED_K), Collections.emptyList())); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION)) .isPresent(); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION).get()) .isEqualTo(Integer.parseInt(CLUSTERS_TSV_PREFERRED_K)); }
@Test @DisplayName("No value in idf, expected clusters in clusters.tsv") void noIdfValueValidClustersTsv() { dataFileHubMock.addClustersFile( EXPERIMENT_ACCESSION, Arrays.asList(CLUSTERS_TSV_WITH_PREFFERED_K_WITHOUT_IDF_K)); when(idfParserMock.parse(EXPERIMENT_ACCESSION)) .thenReturn( new IdfParserOutput( "Title", "", "Description", Collections.emptyList(), 0, Collections.emptyList())); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION)) .isPresent(); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION).get()) .isEqualTo(Integer.parseInt(CLUSTERS_TSV_PREFERRED_K)); }
@Test @DisplayName("No value in idf or clusters.tsv") void noExpectedClusters() { dataFileHubMock.addClustersFile( EXPERIMENT_ACCESSION, Arrays.asList(CLUSTERS_TSV_WITHOUT_PREFFERED_K_WITHOUT_IDF_K)); when(idfParserMock.parse(EXPERIMENT_ACCESSION)) .thenReturn( new IdfParserOutput( "Title", "", "Description", Collections.emptyList(), 0, Collections.emptyList())); assertThat(subject.getExpectedClusters(EXPERIMENT_ACCESSION)).isNotPresent(); }