PhivePriority implements Prioritiser<PhivePriorityResult> { @Override public Stream<PhivePriorityResult> prioritise(List<String> hpoIds, List<Gene> genes) { logger.info("Starting {}", PRIORITY_TYPE); List<PhenotypeTerm> hpoPhenotypeTerms = priorityService.makePhenotypeTermsFromHpoIds(hpoIds); PhenotypeMatcher humanMousePhenotypeMatcher = priorityService.getPhenotypeMatcherForOrganism(hpoPhenotypeTerms, Organism.MOUSE); Set<Integer> wantedGeneIds = genes.stream().map(Gene::getEntrezGeneID).collect(ImmutableSet.toImmutableSet()); Set<GeneModel> modelsToScore = priorityService.getModelsForOrganism(Organism.MOUSE).stream() .filter(model -> wantedGeneIds.contains(model.getEntrezGeneId())) .collect(ImmutableSet.toImmutableSet()); List<GeneModelPhenotypeMatch> scoredModels = scoreModels(humanMousePhenotypeMatcher, modelsToScore); Map<Integer, Optional<GeneModelPhenotypeMatch>> geneModelPhenotypeMatches = scoredModels.parallelStream() .collect(groupingByConcurrent(GeneModelPhenotypeMatch::getEntrezGeneId, maxBy(comparingDouble(GeneModelPhenotypeMatch::getScore)))); return genes.stream().map(getPhivePriorityResult(geneModelPhenotypeMatches)); } PhivePriority(PriorityService priorityService); @Override PriorityType getPriorityType(); @Override Stream<PhivePriorityResult> prioritise(List<String> hpoIds, List<Gene> genes); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testPrioritise() { List<Gene> genes = getGenes(); List<String> hpoIds= Lists.newArrayList("HP:0010055", "HP:0001363", "HP:0001156", "HP:0011304"); PhivePriority phivePriority = new PhivePriority(TestPriorityServiceFactory.TEST_SERVICE); List<PhivePriorityResult> results = phivePriority.prioritise(hpoIds, genes) .sorted() .collect(toList()); results.forEach(System.out::println); assertThat(results.size(), equalTo(genes.size())); Map<String, Double> actualScores = results.stream().collect(toMap(PhivePriorityResult::getGeneSymbol, PhivePriorityResult::getScore)); checkScores(actualScores, expectedMouseScores()); }