GeneSearchService { public Map<String, Map<String, Map<Integer, List<Integer>>>> getMarkerGeneProfile(String... geneIds) { return fetchInParallel( ImmutableSet.copyOf(geneIds), geneId -> fetchClusterIDWithPreferredKAndMinPForGeneID( geneSearchDao.fetchExperimentAccessionsWhereGeneIsMarker(geneId), geneId)); } GeneSearchService(GeneSearchDao geneSearchDao, TsnePlotSettingsService tsnePlotSettingsService); Map<String, Map<String, List<String>>> getCellIdsInExperiments(String... geneIds); Map<String, Map<String, List<String>>> getFacets(List<String> cellIds); Map<String, Map<String, Map<Integer, List<Integer>>>> getMarkerGeneProfile(String... geneIds);  }
@Test void markerGeneProfilesForOneGeneId() { String experimentAccession1 = generateRandomExperimentAccession(); String experimentAccession2 = generateRandomExperimentAccession(); String geneId = generateRandomEnsemblGeneId(); when(tsnePlotSettingsServiceMock.getExpectedClusters(experimentAccession1)).thenReturn(Optional.of(5)); when(tsnePlotSettingsServiceMock.getExpectedClusters(experimentAccession2)).thenReturn(Optional.of(10)); when(geneSearchDaoMock .fetchClusterIdsWithPreferredKAndMinPForExperimentAccession(geneId, experimentAccession1, 5)) .thenReturn(ImmutableMap.of(5, ImmutableList.of(1))); when(geneSearchDaoMock .fetchClusterIdsWithPreferredKAndMinPForExperimentAccession(geneId, experimentAccession2, 10)) .thenReturn(ImmutableMap.of(10, ImmutableList.of(1))); when(geneSearchDaoMock .fetchExperimentAccessionsWhereGeneIsMarker(geneId)) .thenReturn(ImmutableList.of(experimentAccession1, experimentAccession2)); Map<String, Map<String, Map<Integer, List<Integer>>>> result = subject.getMarkerGeneProfile(geneId); assertThat(result) .isNotEmpty() .containsOnlyKeys(geneId) .containsAllEntriesOf(ImmutableMap.of(geneId, ImmutableMap.of( experimentAccession1, ImmutableMap.of(5, ImmutableList.of(1)), experimentAccession2, ImmutableMap.of(10, ImmutableList.of(1))))); }
@Test void markerGeneProfilesForMultipleGeneIds() { String experimentAccession1 = generateRandomExperimentAccession(); String experimentAccession2 = generateRandomExperimentAccession(); String experimentAccession3 = generateRandomExperimentAccession(); String experimentAccession4 = generateRandomExperimentAccession(); String geneId1 = generateRandomEnsemblGeneId(); String geneId2 = generateRandomEnsemblGeneId(); when(tsnePlotSettingsServiceMock.getExpectedClusters(experimentAccession1)).thenReturn(Optional.of(5)); when(tsnePlotSettingsServiceMock.getExpectedClusters(experimentAccession2)).thenReturn(Optional.of(10)); when(geneSearchDaoMock .fetchClusterIdsWithPreferredKAndMinPForExperimentAccession(geneId1, experimentAccession1, 5)) .thenReturn(ImmutableMap.of(5, ImmutableList.of(1))); when(geneSearchDaoMock .fetchClusterIdsWithPreferredKAndMinPForExperimentAccession(geneId1, experimentAccession2, 10)) .thenReturn(ImmutableMap.of(10, ImmutableList.of(1))); when(tsnePlotSettingsServiceMock.getExpectedClusters(experimentAccession3)).thenReturn(Optional.of(2)); when(tsnePlotSettingsServiceMock.getExpectedClusters(experimentAccession4)).thenReturn(Optional.of(4)); when(geneSearchDaoMock .fetchClusterIdsWithPreferredKAndMinPForExperimentAccession(geneId2, experimentAccession3, 2)) .thenReturn(ImmutableMap.of(2, ImmutableList.of(1))); when(geneSearchDaoMock .fetchClusterIdsWithPreferredKAndMinPForExperimentAccession(geneId2, experimentAccession4, 4)) .thenReturn(ImmutableMap.of(4, ImmutableList.of(1))); when(geneSearchDaoMock.fetchExperimentAccessionsWhereGeneIsMarker(geneId1)) .thenReturn(ImmutableList.of(experimentAccession1, experimentAccession2)); when(geneSearchDaoMock.fetchExperimentAccessionsWhereGeneIsMarker(geneId2)) .thenReturn(ImmutableList.of(experimentAccession3, experimentAccession4)); assertThat(subject.getMarkerGeneProfile(geneId1, geneId2)) .containsAllEntriesOf( ImmutableMap.of( geneId1, ImmutableMap.of( experimentAccession1, ImmutableMap.of(5, ImmutableList.of(1)), experimentAccession2, ImmutableMap.of(10, ImmutableList.of(1))), geneId2, ImmutableMap.of( experimentAccession3, ImmutableMap.of(2, ImmutableList.of(1)), experimentAccession4, ImmutableMap.of(4, ImmutableList.of(1))))); }