HighchartsHeatmapAdapter { List<Map<String, Object>> getMarkerGeneHeatmapData(List<MarkerGene> markerGenes) { List<MarkerGene> sortedMarkerGenes = markerGenes.stream() .parallel() .sorted(Comparator.comparing(MarkerGene::clusterIdWhereMarker) .thenComparing(MarkerGene::pValue) ) .collect(Collectors.toList()); List<String> uniqueGeneIds = sortedMarkerGenes .stream() .map(MarkerGene::geneId) .distinct() .collect(Collectors.toList()); Map<String, String> symbolsForGeneIds = markerGenesDao.getSymbolsForGeneIds(uniqueGeneIds); Map<String, Integer> geneIdIndices = uniqueGeneIds .stream() .collect(Collectors.toMap(x -> x, uniqueGeneIds::indexOf)); return sortedMarkerGenes .stream() .map(markerGene -> { Map<String, Object> heatmapCell = new HashMap<>(); heatmapCell.put("x", markerGene.clusterId() - 1); heatmapCell.put("y", geneIdIndices.get(markerGene.geneId())); heatmapCell.put("name", symbolsForGeneIds.getOrDefault(markerGene.geneId(), markerGene.geneId())); heatmapCell.put("value", markerGene.medianExpression()); heatmapCell.put("clusterIdWhereMarker", markerGene.clusterIdWhereMarker()); heatmapCell.put("pValue", markerGene.pValue()); return heatmapCell; }) .collect(Collectors.toList()); } @Inject  HighchartsHeatmapAdapter(MarkerGenesDao markerGenesDao);   }
@Test void markerGeneWithoutSymbolHasGeneIDAsName() { String gene1 = generateRandomEnsemblGeneId(); String gene2 = generateRandomEnsemblGeneId(); String gene3 = generateRandomEnsemblGeneId(); String geneSymbol1 = generateRandomGeneSymbol(); String geneSymbol2 = generateRandomGeneSymbol(); List<String> randomGeneIds = Arrays.asList(gene1, gene2, gene3); when(markerGenesDaoMock.getSymbolsForGeneIds(randomGeneIds)).thenReturn(ImmutableMap.of( gene1, geneSymbol1, gene2, geneSymbol2 )); List<MarkerGene> markerGenes = Arrays.asList( MarkerGene.create(gene1, 1, 1, 0.004, 1, 199, 185), MarkerGene.create(gene2, 1, 3, 0.0006, 2, 12, 1.11), MarkerGene.create(gene3, 1, 5, 0.001, 6, 1000, 10000)); List<Map<String, Object>> result = subject.getMarkerGeneHeatmapData(markerGenes); assertThat(result).hasSize(3); assertThat(result).element(0).extracting("name").containsOnly(geneSymbol1); assertThat(result).element(1).extracting("name").containsOnly(geneSymbol2); assertThat(result).element(2).extracting("name").containsOnly(gene3); }