use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class SparqlClientCachingFactory method create.
@Override
public SparqlClient create(ResourceService resourceService) {
DB db = getDb();
final Map<String, String> queryCache = db.createTreeMap("queryCache").make();
final ResourceService resourceServiceCaching = new ResourceServiceCaching(queryCache, resourceService);
return new OpenBiodivClientImpl(resourceServiceCaching) {
@Override
public void close() throws IOException {
db.close();
}
};
}
use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class DatasetImporterForZOVERTest method parseVirusHostRecord.
@Test
public void parseVirusHostRecord() throws IOException, StudyImporterException {
String hostLabel = "tick";
long virusId = 35237L;
String virusData = DatasetImporterForZOVER.getVirusData(hostLabel, virusId, new ResourceService() {
@Override
public InputStream retrieve(URI resourceName) throws IOException {
return getClass().getResourceAsStream("zover/tick_viruses_35237.json");
}
}, "http://www.mgc.ac.cn");
List<Map<String, String>> interactions = new ArrayList<>();
InteractionListener listener = new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
interactions.add(interaction);
}
};
JsonNode jsonNode = new ObjectMapper().readTree(virusData);
DatasetImporterForZOVER.parseData(hostLabel, listener, jsonNode, virusId);
assertThat(interactions.size(), is(281));
Map<String, String> first = interactions.get(0);
assertThat(first.get(SOURCE_TAXON_NAME), is("African swine fever virus"));
assertThat(first.get(SOURCE_TAXON_ID), is("NCBI:10497"));
assertThat(first.get(SOURCE_TAXON_PATH), is("Asfarviridae | African swine fever virus"));
assertThat(first.get(INTERACTION_TYPE_NAME), is("pathogenOf"));
assertThat(first.get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002556"));
assertThat(first.get(TARGET_TAXON_NAME), is("Ornithodoros porcinus"));
assertThat(first.get(TARGET_TAXON_ID), is("NCBI:34594"));
assertThat(first.get(TARGET_TAXON_PATH), is("Ornithodoros | Ornithodoros porcinus"));
assertThat(first.get(LOCALITY_NAME), is("South Africa"));
assertThat(first.get(REFERENCE_URL), is("https://www.ncbi.nlm.nih.gov/nuccore/GQ867183"));
assertThat(first.get(REFERENCE_ID), is("urn:lsid:cn.ac.mgc:tick:35237"));
}
use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class InteractTypeMapperFactoryImplTest method createBlankMapping.
@Test
public void createBlankMapping() throws TermLookupServiceException, IOException {
ResourceService resourceService = Mockito.mock(ResourceService.class);
when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("interaction_type_ignored\nshouldBeIgnored", StandardCharsets.UTF_8));
String mapping = "provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id" + "\n,,interactsWith, http://purl.obolibrary.org/obo/RO_0002437";
when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream(mapping, StandardCharsets.UTF_8));
InteractTypeMapperFactory interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
assertThat(interactTypeMapperFactory.create().getInteractType(""), is(InteractType.INTERACTS_WITH));
}
use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class InteractTypeMapperFactoryImplTest method createAndNoMappingResource.
@Test
public void createAndNoMappingResource() throws TermLookupServiceException, IOException {
ResourceService resourceService = Mockito.mock(ResourceService.class);
when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("interaction_type_ignored\nshouldBeIgnored", StandardCharsets.UTF_8)).thenReturn(IOUtils.toInputStream("interaction_type_ignored\nshouldBeIgnored", StandardCharsets.UTF_8));
when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenThrow(new IOException("kaboom!"));
InteractTypeMapperFactory interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
InteractTypeMapper interactTypeMapper = interactTypeMapperFactory.create();
assertNull(interactTypeMapper.getInteractType("shouldBeIgnored"));
assertTrue(interactTypeMapper.shouldIgnoreInteractionType("shouldBeIgnored"));
}
use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.
the class InteractTypeMapperFactoryImplTest method throwOnDuplicateMapping.
@Test(expected = TermLookupServiceException.class)
public void throwOnDuplicateMapping() 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_0002470\n" + "drinking,http://purl.obolibrary.org/obo/OMIT_0005582,eats,http://purl.obolibrary.org/obo/RO_0002470\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("multiple mappings for [id]: [http://purl.obolibrary.org/obo/OMIT_0005582] were found, but only one unambiguous mapping is allowed"));
throw ex;
}
}
Aggregations