Search in sources :

Example 21 with ResourceService

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"));
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ResourceService(org.eol.globi.service.ResourceService) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) IOException(java.io.IOException) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) Map(java.util.Map) Test(org.junit.Test)

Example 22 with ResourceService

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

Example 23 with ResourceService

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"));
}
Also used : TermLookupService(org.eol.globi.service.TermLookupService) ResourceService(org.eol.globi.service.ResourceService) Term(org.eol.globi.domain.Term) URI(java.net.URI) Test(org.junit.Test)

Example 24 with ResourceService

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"));
}
Also used : TermLookupService(org.eol.globi.service.TermLookupService) ResourceService(org.eol.globi.service.ResourceService) Term(org.eol.globi.domain.Term) URI(java.net.URI) Test(org.junit.Test)

Example 25 with ResourceService

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;
    }
}
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