BioEntityPropertyService { Map<String, String> mapToLinkText(BioentityPropertyName propertyName, Collection<String> propertyValues, boolean isPlantSpecies) { switch (propertyName) { case ORTHOLOG: return propertyValues.stream() .collect(toMap(identity(), this::fetchSymbolAndSpeciesForOrtholog)); case PATHWAYID: return isPlantSpecies ? reactomeClient.getPlantPathwayNames(propertyValues) : reactomeClient.getPathwayNames(propertyValues); case GO: case PO: return propertyValues.stream() .collect(toMap(identity(), p -> goPoTermTrader.get(p).map(OntologyTerm::name).orElse(p))); case INTERPRO: return propertyValues.stream() .collect(toMap(identity(), p -> interProTermTrader.get(p).map(OntologyTerm::name).orElse(p))); default: return propertyValues.stream().collect(toMap(identity(), identity())); } } @Inject  BioEntityPropertyService(SpeciesInferrer speciesInferrer,
                                    BioEntityPropertyDao bioEntityPropertyDao,
                                    ReactomeClient reactomeClient,
                                    GoPoTrader goPoTermTrader,
                                    InterProTrader interProTermTrader);   }
@Test public void unmappedPropertiesAreReturnedUnchanged() { for (BioentityPropertyName bioentityPropertyName : BioentityPropertyName.values()) { if (!UNMAPPED_PROPERTY_NAMES.contains(bioentityPropertyName)) { assertThat( subject.mapToLinkText(bioentityPropertyName, ImmutableSet.of("foobar"), false), hasEntry(is("foobar"), is("foobar"))); } } }
@Test public void reactomeTermsAreMapped() { when(reactomeClientMock.getPathwayNames(any())).thenReturn(ImmutableMap.of("R-HSA-31337", "foobar")); subject.mapToLinkText(BioentityPropertyName.PATHWAYID, ImmutableSet.of("R-HSA-31337"), false); verify(reactomeClientMock, times(1)).getPathwayNames(eq(ImmutableSet.of("R-HSA-31337"))); }
@Test public void goTermsAreMapped() { when(goPoTermTraderMock.get(anyString())).thenReturn(Optional.of(OntologyTerm.create("foobar"))); subject.mapToLinkText(BioentityPropertyName.GO, ImmutableSet.of("foobar"), false); verify(goPoTermTraderMock, times(1)).get(eq("foobar")); }
@Test public void poTermsAreMapped() { when(goPoTermTraderMock.get(anyString())).thenReturn(Optional.of(OntologyTerm.create("foobar"))); subject.mapToLinkText(BioentityPropertyName.PO, ImmutableSet.of("foobar"), false); verify(goPoTermTraderMock, times(1)).get(eq("foobar")); }
@Test public void interproTermsAreMapped() { when(interProTermTraderMock.get(anyString())).thenReturn(Optional.of(OntologyTerm.create("foobar"))); subject.mapToLinkText(BioentityPropertyName.INTERPRO, ImmutableSet.of("foobar"), false); verify(interProTermTraderMock, times(1)).get(eq("foobar")); }
@Test public void unknownSpeciesAreOmittedFromOrthologs() { when(speciesInferrerMock.inferSpeciesForGeneQuery( argThat(semanticQuery -> semanticQuery.iterator().next().value().startsWith("ENSCING")))) .thenReturn(new Species("Ciona intestinalis", SpeciesProperties.UNKNOWN)); assertThat( subject.mapToLinkText(BioentityPropertyName.ORTHOLOG, ImmutableSet.of("ENSCING00000014543"), false), hasEntry("ENSCING00000014543", "ENSCING00000014543")); verifyZeroInteractions(bioEntityPropertyDaoMock); }
@Test public void useGeneIdIfNoGeneNameAvailable() { when(speciesInferrerMock.inferSpeciesForGeneQuery( argThat(semanticQuery -> semanticQuery.iterator().next().value().startsWith("VIT")))) .thenReturn(new Species("Vitis vinifera", SpeciesProperties.create( "vitis_vinifera", "DEVELOPMENTAL_STAGE", "plants", ImmutableSet.of()))); when(bioEntityPropertyDaoMock.fetchPropertyValuesForGeneId( eq("VIT_01s0026g00140"), eq(BioentityPropertyName.SYMBOL))) .thenReturn(ImmutableSet.of()); assertThat( subject.mapToLinkText(BioentityPropertyName.ORTHOLOG, ImmutableSet.of("VIT_01s0026g00140"), false), hasEntry("VIT_01s0026g00140", "VIT_01s0026g00140 (Vitis vinifera)")); }