Search in sources :

Example 1 with ResourceService

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();
        }
    };
}
Also used : ResourceService(org.eol.globi.service.ResourceService) OpenBiodivClientImpl(org.globalbioticinteractions.util.OpenBiodivClientImpl) DB(org.mapdb.DB)

Example 2 with ResourceService

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"));
}
Also used : InputStream(java.io.InputStream) ResourceService(org.eol.globi.service.ResourceService) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with ResourceService

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));
}
Also used : ResourceService(org.eol.globi.service.ResourceService) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with ResourceService

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"));
}
Also used : ResourceService(org.eol.globi.service.ResourceService) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with ResourceService

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;
    }
}
Also used : TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) TermLookupServiceConfigurationException(org.eol.globi.service.TermLookupServiceConfigurationException) ResourceService(org.eol.globi.service.ResourceService) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ResourceService (org.eol.globi.service.ResourceService)34 Test (org.junit.Test)31 IOException (java.io.IOException)9 Matchers.anyString (org.mockito.Matchers.anyString)9 URI (java.net.URI)7 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 InteractType (org.eol.globi.domain.InteractType)3 InteractionListener (org.eol.globi.process.InteractionListener)3 TermLookupService (org.eol.globi.service.TermLookupService)3 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 HashMap (java.util.HashMap)2 Term (org.eol.globi.domain.Term)2 TermLookupServiceConfigurationException (org.eol.globi.service.TermLookupServiceConfigurationException)2 TermLookupServiceException (org.eol.globi.service.TermLookupServiceException)2 Dataset (org.globalbioticinteractions.dataset.Dataset)2 OpenBiodivClientImpl (org.globalbioticinteractions.util.OpenBiodivClientImpl)2 SparqlClient (org.globalbioticinteractions.util.SparqlClient)2