use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class DatasetImporterForZOVERTest method importDataset.
@Test
public void importDataset() throws StudyImporterException {
List<Map<String, String>> interactions = new ArrayList<>();
DatasetImporterForZOVER importer = new DatasetImporterForZOVER(null, null);
importer.setDatabases(Collections.singletonList(DatasetImporterForZOVER.ZOVER_CHIROPTERA));
importer.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
interactions.add(interaction);
}
});
DatasetImpl dataset = new DatasetImpl("some/namespace", new ResourceService() {
@Override
public InputStream retrieve(URI resourceName) throws IOException {
InputStream is = null;
if (StringUtils.equals("http://www.mgc.ac.cn/cgi-bin/ZOVER/lineage2json1.pl?type=viruses&host=chiroptera", resourceName.toString())) {
is = getClass().getResourceAsStream("zover/chiroptera_chopped.json");
} else if (StringUtils.equals("http://www.mgc.ac.cn/ZOVER/json/chiroptera_viruses_363628.json", resourceName.toString())) {
is = getClass().getResourceAsStream("zover/chiroptera_viruses_363628.json");
}
return is;
}
}, URI.create("some:uri")) {
};
importer.setDataset(dataset);
importer.importStudy();
assertThat(interactions.size(), is(1));
Map<String, String> interaction = interactions.get(0);
assertThat(interaction.get(SOURCE_TAXON_NAME), is("Torque teno Tadarida brasiliensis virus"));
assertThat(interaction.get(SOURCE_TAXON_ID), is("NCBI:1543419"));
assertThat(interaction.get(TARGET_TAXON_NAME), is("Tadarida brasiliensis"));
assertThat(interaction.get(TARGET_TAXON_ID), is("NCBI:9438"));
assertThat(interaction.get(INTERACTION_TYPE_NAME), is("pathogenOf"));
assertThat(interaction.get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002556"));
assertThat(interaction.get(REFERENCE_CITATION), is(nullValue()));
assertThat(interaction.get(REFERENCE_URL), is("https://www.ncbi.nlm.nih.gov/nuccore/KM434181"));
assertThat(interaction.get(REFERENCE_DOI), is(nullValue()));
assertThat(interaction.get(REFERENCE_ID), is("urn:lsid:cn.ac.mgc:tick:363628"));
}
use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class InteractTypeMapperFactoryWithFallbackTest method createAndIgnoreTermNoMapper.
@Test(expected = TermLookupServiceException.class)
public void createAndIgnoreTermNoMapper() throws TermLookupServiceException, IOException {
ResourceService resourceService = Mockito.mock(ResourceService.class);
when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("observation_field_id\nshouldBeIgnored", StandardCharsets.UTF_8)).thenReturn(IOUtils.toInputStream("observation_field_id\nshouldBeIgnored", StandardCharsets.UTF_8));
when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream("", StandardCharsets.UTF_8));
InteractTypeMapper interactTypeMapper = new InteractTypeMapperFactoryWithFallback().create();
assertNull(interactTypeMapper);
}
use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class InteractUtilTest method createInteractionTermMapperUnknownResolvedId.
@Test(expected = TermLookupServiceException.class)
public void createInteractionTermMapperUnknownResolvedId() throws StudyImporterException, TermLookupServiceException {
TermLookupService ignoredTermService = new TermLookupService() {
@Override
public List<Term> lookupTermByName(String name) throws TermLookupServiceException {
return null;
}
};
ResourceService resourceService = new ResourceService() {
@Override
public InputStream retrieve(URI resourceName) throws IOException {
return IOUtils.toInputStream("observation_field_id,providedName,interaction_type_id,resolvedName\n" + "someProvidedId,someProvidedName,someResolvedId,someResolvedName", StandardCharsets.UTF_8);
}
};
TermLookupService termLookupService = InteractTypeMapperFactoryImpl.getTermLookupService(ignoredTermService, resourceService, "observation_field_id", "observation_field_name", "interaction_type_id", InteractTypeMapperFactoryImpl.TYPE_MAP_URI_DEFAULT);
List<Term> someProvidedId = termLookupService.lookupTermByName("someProvidedId");
assertThat(someProvidedId.size(), is(1));
assertThat(someProvidedId.get(0).getId(), is("someResolvedId"));
assertThat(someProvidedId.get(0).getName(), is("someResolvedName"));
}
use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class InteractUtilTest method createInteractionTermMapperValidTerm.
@Test
public void createInteractionTermMapperValidTerm() throws StudyImporterException, TermLookupServiceException {
ResourceService testResourceService = new ResourceService() {
@Override
public InputStream retrieve(URI resourceName) throws IOException {
return IOUtils.toInputStream("provided_interaction_type_id,provided_interaction_type_label,mapped_to_interaction_type_id,mapped_to_interaction_type_label\n" + "someProvidedId,someProvidedName,http://purl.obolibrary.org/obo/RO_0002440,someResolvedName", StandardCharsets.UTF_8);
}
};
ResourceService ignoredResourceService = new ResourceService() {
@Override
public InputStream retrieve(URI resourceName) throws IOException {
return IOUtils.toInputStream("interaction_type_ignored\n" + "someIgnoredId", StandardCharsets.UTF_8);
}
};
TermLookupService ignoredTermService = InteractTypeMapperFactoryImpl.getIgnoredTermService(ignoredResourceService, "interaction_type_ignored", InteractTypeMapperFactoryImpl.TYPE_IGNORED_URI_DEFAULT);
TermLookupService termLookupService = InteractTypeMapperFactoryImpl.getTermLookupService(ignoredTermService, testResourceService, "provided_interaction_type_id", "provided_interaction_type_label", "mapped_to_interaction_type_id", InteractTypeMapperFactoryImpl.TYPE_MAP_URI_DEFAULT);
List<Term> someProvidedId = termLookupService.lookupTermByName("someProvidedId");
assertThat(someProvidedId.size(), is(1));
assertThat(someProvidedId.get(0).getId(), is("http://purl.obolibrary.org/obo/RO_0002440"));
assertThat(someProvidedId.get(0).getName(), is("symbiontOf"));
}
use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class InteractTypeMapperFactoryImplTest method throwOnMappingToUnsupportedInteractionType.
@Test(expected = TermLookupServiceException.class)
public void throwOnMappingToUnsupportedInteractionType() throws TermLookupServiceException, IOException {
ResourceService resourceService = Mockito.mock(ResourceService.class);
when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(null);
String mapping = "provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id\n" + "drinking,http://purl.obolibrary.org/obo/OMIT_0005582,eats,http://purl.obolibrary.org/obo/RO_000XXXX\n";
when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream(mapping, StandardCharsets.UTF_8));
InteractTypeMapperFactory interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
try {
interactTypeMapperFactory.create();
} catch (TermLookupServiceException ex) {
assertThat(ex, is(instanceOf(TermLookupServiceConfigurationException.class)));
assertThat(ex.getMessage(), is("failed to map interaction type to [http://purl.obolibrary.org/obo/RO_000XXXX] on line [1]: interaction type unknown to GloBI"));
throw ex;
}
}
Aggregations