BaselineAnalyticsSearchDao { public Map<String, Map<String, Double>> fetchExpressionLevels(SemanticQuery geneQuery, SemanticQuery conditionQuery, String species, String defaultQueryFactorType) { return aggregateExpressionLevelByDataColumnAndExperiment( fetchExpressionLevelsPayload(geneQuery, conditionQuery, species, defaultQueryFactorType)); } BaselineAnalyticsSearchDao(AnalyticsQueryClient analyticsQueryClient); List<Map<String, Object>> fetchFacetsThatHaveExpression(SemanticQuery geneQuery,
                                                                   SemanticQuery conditionQuery,
                                                                   String species); List<Map<String, Object>> fetchExpressionLevelsPayload(SemanticQuery geneQuery,
                                                           SemanticQuery conditionQuery,
                                                           String species,
                                                           String defaultQueryFactorType); Map<String, Map<String, Double>> fetchExpressionLevels(SemanticQuery geneQuery,
                                                                  SemanticQuery conditionQuery,
                                                                  String species,
                                                                  String defaultQueryFactorType);  }
@Test void sumOfExpressionLevelsIsAveragedByGenesExpressedInAssayGroup() { List<Pair<Long, Double>> aggregatedExpression = ImmutableList.of( Pair.of(RNG.nextLong(1, MAX_EXPRESSED_GENES), RNG.nextDouble(0.1, MAX_AGGREGATE_EXPRESSION)), Pair.of(RNG.nextLong(1, MAX_EXPRESSED_GENES), RNG.nextDouble(0.1, MAX_AGGREGATE_EXPRESSION)), Pair.of(RNG.nextLong(1, MAX_EXPRESSED_GENES), RNG.nextDouble(0.1, MAX_AGGREGATE_EXPRESSION))); String randomizedPayload = String.format( JSON_PAYLOAD_SAMPLE_FROM_LUNG_SEARCH_IN_CCLE, aggregatedExpression.stream().mapToLong(Pair::getLeft).sum(), aggregatedExpression.get(0).getLeft(), aggregatedExpression.get(0).getRight(), aggregatedExpression.get(1).getLeft(), aggregatedExpression.get(1).getRight(), aggregatedExpression.get(2).getLeft(), aggregatedExpression.get(2).getRight()); when(analyticsQueryClientBuilderMock.baselineFacets()).thenReturn(analyticsQueryClientBuilderMock); when(analyticsQueryClientBuilderMock.queryIdentifierSearch(any())).thenReturn(analyticsQueryClientBuilderMock); when(analyticsQueryClientBuilderMock.queryConditionsSearch(any())).thenReturn(analyticsQueryClientBuilderMock); when(analyticsQueryClientBuilderMock.ofSpecies(anyString())).thenReturn(analyticsQueryClientBuilderMock); when(analyticsQueryClientBuilderMock.withFactorType(anyString())).thenReturn(analyticsQueryClientBuilderMock); when(analyticsQueryClientBuilderMock.fetch()).thenReturn(randomizedPayload); when(analyticsQueryClientMock.queryBuilder()).thenReturn(analyticsQueryClientBuilderMock); assertThat( subject.fetchExpressionLevels( SemanticQuery.create(), SemanticQuery.create("lung"), "homo sapiens", "CELL_LINE") .get("E-MTAB-2770")) .containsAllEntriesOf( ImmutableMap.of( "g571", BASELINE_EXPRESSION_ROUNDER.applyAsDouble( aggregatedExpression.get(0).getRight() / aggregatedExpression.get(0).getLeft()), "g520", BASELINE_EXPRESSION_ROUNDER.applyAsDouble( aggregatedExpression.get(1).getRight() / aggregatedExpression.get(1).getLeft()), "g519", BASELINE_EXPRESSION_ROUNDER.applyAsDouble( aggregatedExpression.get(2).getRight() / aggregatedExpression.get(2).getLeft()))); }