Search in sources :

Example 1 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForDBatVirTest method parseInteractions.

@Test
public void parseInteractions() throws IOException, StudyImporterException {
    InputStream first2 = getClass().getResourceAsStream("/org/eol/globi/data/dbatvir/dbatvir-first2.json");
    List<Map<String, String>> links = new ArrayList<>();
    InteractionListener interactionListener = links::add;
    DatasetImporterForDBatVir.parseInteractions(first2, interactionListener);
    assertThat(links.size(), Is.is(2));
    assertThat(links.get(0).get(SOURCE_TAXON_NAME), Is.is("Hipposideros caffer"));
    assertThat(links.get(0).get(SOURCE_TAXON_RANK), Is.is("species"));
    assertThat(links.get(0).get(SOURCE_TAXON_ID), Is.is("NCBI:302402"));
    assertThat(links.get(0).get(SOURCE_TAXON_PATH), Is.is("Rhinolophidae | Hipposideros caffer"));
    assertThat(links.get(0).get(SOURCE_TAXON_PATH_IDS), Is.is(" | NCBI:302402"));
    assertThat(links.get(0).get(SOURCE_TAXON_PATH_NAMES), Is.is("family | species"));
    assertThat(links.get(0).get(INTERACTION_TYPE_ID), Is.is("http://purl.obolibrary.org/obo/RO_0002453"));
    assertThat(links.get(0).get(INTERACTION_TYPE_NAME), Is.is("hostOf"));
    assertThat(links.get(0).get(TARGET_TAXON_NAME), Is.is("BatCoV5743/KEN/Kwale"));
    assertThat(links.get(0).get(TARGET_TAXON_RANK), Is.is("strain"));
    assertThat(links.get(0).get(TARGET_TAXON_ID), Is.is("NCBI:1739614"));
    assertThat(links.get(0).get(TARGET_TAXON_PATH), Is.is("Coronaviridae | 229E-related bat coronavirus | BatCoV5743/KEN/Kwale"));
    assertThat(links.get(0).get(TARGET_TAXON_PATH_IDS), Is.is(" | NCBI:1739614 | "));
    assertThat(links.get(0).get(TARGET_TAXON_PATH_NAMES), Is.is("family | species | strain"));
    assertThat(links.get(0).get(DatasetImporterForMetaTable.EVENT_DATE), Is.is("2016-03"));
    assertThat(links.get(0).get(LOCALITY_NAME), Is.is("Kenya"));
    assertThat(links.get(0).get(REFERENCE_ID), Is.is("http://www.ncbi.nlm.nih.gov/pubmed/28393313"));
    assertThat(links.get(0).get(REFERENCE_URL), Is.is("http://www.ncbi.nlm.nih.gov/pubmed/28393313"));
    assertThat(links.get(0).get(REFERENCE_CITATION), Is.is("Waruhiu C, Ommeh S, Obanda V, Agwanda B, Gakuya F, Ge XY, Yang XL, Wu LJ, Zohaib A, Hu B, Shi ZL, Molecular detection of viruses in Kenyan bats and discovery of novel astroviruses, caliciviruses and rotaviruses. Virol Sin 2017, 32(2):101-114."));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Map(java.util.Map) Test(org.junit.Test)

Example 2 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForDBatVirTest method parseWithDateRange.

@Test
public void parseWithDateRange() throws IOException, StudyImporterException {
    InputStream first2 = getClass().getResourceAsStream("/org/eol/globi/data/dbatvir/dbatvir-daterange.json");
    List<Map<String, String>> links = new ArrayList<>();
    InteractionListener interactionListener = links::add;
    DatasetImporterForDBatVir.parseInteractions(first2, interactionListener);
    assertThat(links.size(), Is.is(2));
    assertThat(links.get(0).get(DatasetImporterForMetaTable.EVENT_DATE), Is.is("2012-03/2014-07"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Map(java.util.Map) Test(org.junit.Test)

Example 3 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForGlobalWebDbTest method parseMatrix.

@Test
public void parseMatrix() throws IOException, StudyImporterException {
    List<Map<String, String>> interactions = new TreeList<>();
    InteractionListener listener = interactions::add;
    DatasetImporterForGlobalWebDb.parseDietMatrix(listener, aDietMatrix, "some source citation");
    assertThat(interactions.size(), is(6));
    Map<String, String> first = interactions.get(0);
    assertThat(first.get(TaxonUtil.SOURCE_TAXON_NAME), is("Balanus balanoides"));
    assertThat(first.get(TaxonUtil.TARGET_TAXON_NAME), is("detritus"));
    assertThat(first.get(DatasetImporterForTSV.INTERACTION_TYPE_NAME), is("eats"));
    assertThat(first.get(DatasetImporterForTSV.INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(first.get(DatasetImporterForTSV.HABITAT_NAME), is("Exposed rocky shore"));
    assertThat(first.get(DatasetImporterForTSV.LOCALITY_NAME), is("New England, U.S.A."));
    assertThat(first.get(DatasetImporterForTSV.REFERENCE_ID), is("df06df18abafa63a6f0473d6d0e6ce68"));
    assertThat(first.get(DatasetImporterForTSV.REFERENCE_CITATION), is("B.A. Menge and J.P. Sutherland. Species Diversity Gradients: Synthesis of the Roles of Predation, Competition, and Temporal Heterogeneity. The American Naturalist, 110(973), pp. 351-369."));
    assertThat(first.get(DatasetImporterForTSV.DATASET_CITATION), is("some source citation"));
    Map<String, String> last = interactions.get(5);
    assertThat(last.get(TaxonUtil.SOURCE_TAXON_NAME), is("Thais lapillus"));
    assertThat(last.get(TaxonUtil.TARGET_TAXON_NAME), is("Mytilus edulis"));
    assertThat(last.get(DatasetImporterForTSV.INTERACTION_TYPE_NAME), is("eats"));
    assertThat(last.get(DatasetImporterForTSV.INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(last.get(DatasetImporterForTSV.HABITAT_NAME), is("Exposed rocky shore"));
    assertThat(last.get(DatasetImporterForTSV.LOCALITY_NAME), is("New England, U.S.A."));
    assertThat(last.get(DatasetImporterForTSV.REFERENCE_ID), is("df06df18abafa63a6f0473d6d0e6ce68"));
    assertThat(last.get(DatasetImporterForTSV.REFERENCE_CITATION), is("B.A. Menge and J.P. Sutherland. Species Diversity Gradients: Synthesis of the Roles of Predation, Competition, and Temporal Heterogeneity. The American Naturalist, 110(973), pp. 351-369."));
    assertThat(last.get(DatasetImporterForTSV.DATASET_CITATION), is("some source citation"));
}
Also used : InteractionListener(org.eol.globi.process.InteractionListener) TreeList(org.apache.commons.collections4.list.TreeList) Map(java.util.Map) Test(org.junit.Test)

Example 4 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForMetaTableIT method importREEMWithStaticCSV.

@Test
public void importREEMWithStaticCSV() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    final InteractionListener interactionListener = links::add;
    final DatasetImporterForMetaTable.TableParserFactory tableFactory = (config, dataset) -> {
        String firstFewLines = "Hauljoin,\" Pred_nodc\",\" Pred_specn\",\" Prey_nodc\",\" Pred_len\",\" Year\",\" Month\",\" day\",\" region\",\" Pred_name\",\" Prey_Name\",\" Vessel\",\" Cruise\",\" Haul\",\" Rlat\",\" Rlong\",\" Gear_depth\",\" Bottom_depth\",\" Start_hour\",\" Surface_temp\",\" Gear_temp\",\" INPFC_Area\",\" Stationid\",\" Start_date\",\" Prey_sz1\",\" Prey_sex\"\n" + "11012118.0,8791030401.0,5.0,9999999998.0,53.0,1994.0,7.0,11.0,AI,\"Pacific cod Gadus macrocephalus\",\"Rocks \",95.0,199401.0,148.0,51.43,178.81999999999999,222.0,228.0,11.0,0.63,0.41999999999999998,542.0,118-11,\"1994-07-11 00:00:00\",3.0,\n" + "11012118.0,8791030401.0,8.0,9999999998.0,53.0,1994.0,7.0,11.0,AI,\"Pacific cod Gadus macrocephalus\",\"Rocks \",95.0,199401.0,148.0,51.43,178.81999999999999,222.0,228.0,11.0,0.63,0.41999999999999998,542.0,118-11,\"1994-07-11 00:00:00\",3.0,\n" + "11012118.0,8791030401.0,9.0,9999999998.0,58.0,1994.0,7.0,11.0,AI,\"Pacific cod Gadus macrocephalus\",\"Rocks \",95.0,199401.0,148.0,51.43,178.81999999999999,222.0,228.0,11.0,0.63,0.41999999999999998,542.0,118-11,\"1994-07-11 00:00:00\",13.0,\n" + "11012118.0,8791030401.0,9.0,9999999998.0,58.0,1994.0,7.0,11.0,AI,\"Pacific cod Gadus macrocephalus\",\"Rocks \",95.0,199401.0,148.0,51.43,178.81999999999999,222.0,228.0,11.0,0.63,0.41999999999999998,542.0,118-11,\"1994-07-11 00:00:00\",3.0,\n";
        return CSVTSVUtil.createLabeledCSVParser(CSVTSVUtil.createExcelCSVParse(IOUtils.toInputStream(firstFewLines, StandardCharsets.UTF_8)));
    };
    final String baseUrl = "https://raw.githubusercontent.com/globalbioticinteractions/noaa-reem/main";
    final String resource = baseUrl + "/globi.json";
    importAll(interactionListener, tableFactory, baseUrl, resource);
    assertThat(links.size(), is(12));
    final Map<String, String> firstLine = links.get(0);
    assertThat(firstLine.get(DatasetImporterForTSV.INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
    assertThat(firstLine.get(DatasetImporterForTSV.INTERACTION_TYPE_NAME), is("eats"));
    assertThat(firstLine.get(TaxonUtil.TARGET_TAXON_ID), is(nullValue()));
    assertThat(firstLine.get(TaxonUtil.TARGET_TAXON_NAME), is("Rocks"));
    assertThat(firstLine.get(TaxonUtil.SOURCE_TAXON_ID), is("NODC:8791030401"));
    assertThat(firstLine.get(TaxonUtil.SOURCE_TAXON_NAME), is("Pacific cod Gadus macrocephalus"));
    assertThat(firstLine.get(DatasetImporterForMetaTable.EVENT_DATE), startsWith("1994-07-11"));
    assertThat(firstLine.get(DatasetImporterForMetaTable.LATITUDE), is("51.43"));
    assertThat(firstLine.get(DatasetImporterForMetaTable.LONGITUDE), is("178.81999999999999"));
}
Also used : TaxonUtil(org.eol.globi.service.TaxonUtil) CSVTSVUtil(org.eol.globi.util.CSVTSVUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URL(java.net.URL) InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) ResourceUtil(org.eol.globi.util.ResourceUtil) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) IsNot.not(org.hamcrest.core.IsNot.not) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Dataset(org.globalbioticinteractions.dataset.Dataset) Matchers.containsString(org.hamcrest.Matchers.containsString) InputStream(java.io.InputStream) InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 5 with InteractionListener

use of org.eol.globi.process.InteractionListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForMetaTableIT method importAll.

@Test
public void importAll() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    final InteractionListener interactionListener = links::add;
    final DatasetImporterForMetaTable.TableParserFactory tableFactory = (config, dataset) -> {
        String firstFewLines = "intertype,obstype,effunit,effort,obsunit,obsquant,germnotes,\"REPLACE(Interaction.notes, ',', ';')\",AnimalNumber,AnimalClass,AnimalOrder,AnimalFamily,AnimalGenus,AnimalSpecies,AnimalSubSpecies,AnimalType,AnimalCommonName,PlantNumber,PlantFamily,PlantGenus,PlantSpecies,PlantSubSpecies,country,region,ProvinceDistrictCity,ProtectedArea,HabitatWhite,HabitatAuthor,author,title,year,journal,volume,number,pages,USER,DEF_timestamp,,,\n" + "seed disperser,direct observation,months,4,dung density,,,Article focused on elephant density per habitat type based on seed/plant types identified in dung at the various research locations. All identified plant types are being assumed to be dispersed by the elephants,1441,Mammalia,Proboscidea,Elephantidae,Loxodonta,africana,,NULL,African Bush Elephant,4035,Poaceae,Cynodon,dactylon,NULL,Mozambique,NULL,NULL,yes,forest transitions and mosaics,mangroves dune grass plains forest woodland riverine,\"De Boer, W.F. and Ntumi, C.P. and Correia, A.U. and Mafuca, J.M.\",Diet and distribution of elephant in the Maputo Elephant Reserve; Mozambique,2000,African Journal of Ecology,38,3,188-201,Mary,0000-00-00 00:00:00,,,\n" + "seed disperser,direct observation,months,4,dung density,,,Article focused on elephant density per habitat type based on seed/plant types identified in dung at the various research locations. All identified plant types are being assumed to be dispersed by the elephants,1441,Mammalia,Proboscidea,Elephantidae,Loxodonta,africana,,NULL,African Bush Elephant,3639,Poaceae,Aristida,canescens,NULL,Mozambique,NULL,NULL,yes,forest transitions and mosaics,mangroves dune grass plains forest woodland riverine,\"De Boer, W.F. and Ntumi, C.P. and Correia, A.U. and Mafuca, J.M.\",Diet and distribution of elephant in the Maputo Elephant Reserve; Mozambique,2000,African Journal of Ecology,38,3,188-201,Mary,0000-00-00 00:00:00,,,\n" + "seed disperser,direct observation,months,4,dung density,,,Article focused on elephant density per habitat type based on seed/plant types identified in dung at the various research locations. All identified plant types are being assumed to be dispersed by the elephants,1441,Mammalia,Proboscidea,Elephantidae,Loxodonta,africana,,NULL,African Bush Elephant,3574,Poaceae,Andropogon,eucomus,NULL,Mozambique,NULL,NULL,yes,forest transitions and mosaics,mangroves dune grass plains forest woodland riverine,\"De Boer, W.F. and Ntumi, C.P. and Correia, A.U. and Mafuca, J.M.\",Diet and distribution of elephant in the Maputo Elephant Reserve; Mozambique,2000,African Journal of Ecology,38,3,188-201,Mary,0000-00-00 00:00:00,,,\n" + "seed disperser,direct observation,months,4,dung density,,,Article focused on elephant density per habitat type based on seed/plant types identified in dung at the various research locations. All identified plant types are being assumed to be dispersed by the elephants,1441,Mammalia,Proboscidea,Elephantidae,Loxodonta,africana,,NULL,African Bush Elephant,5125,Phyllanthaceae,Phyllanthus,reticulatus,NULL,Mozambique,NULL,NULL,yes,forest transitions and mosaics,mangroves dune grass plains forest woodland riverine,\"De Boer, W.F. and Ntumi, C.P. and Correia, A.U. and Mafuca, J.M.\",Diet and distribution of elephant in the Maputo Elephant Reserve; Mozambique,2000,African Journal of Ecology,38,3,188-201,Mary,0000-00-00 00:00:00,,,\n" + "seed disperser,direct observation,months,4,dung density,,,Article focused on elephant density per habitat type based on seed/plant types identified in dung at the various research locations. All identified plant types are being assumed to be dispersed by the elephants,1441,Mammalia,Proboscidea,Elephantidae,Loxodonta,africana,,NULL,African Bush Elephant,399,Myrtaceae,Syzygium,cordatum,,Mozambique,NULL,NULL,yes,forest transitions and mosaics,mangroves dune grass plains forest woodland riverine,\"De Boer, W.F. and Ntumi, C.P. and Correia, A.U. and Mafuca, J.M.\",Diet and distribution of elephant in the Maputo Elephant Reserve; Mozambique,2000,African Journal of Ecology,38,3,188-201,Mary,0000-00-00 00:00:00,,,\n" + "seed disperser,direct observation,months,4,dung density,,,Article focused on elephant density per habitat type based on seed/plant types identified in dung at the various research locations. All identified plant types are being assumed to be dispersed by the elephants,1441,Mammalia,Proboscidea,Elephantidae,Loxodonta,africana,,NULL,African Bush Elephant,374,Moraceae,Ficus,sycomorus,,Mozambique,NULL,NULL,yes,forest transitions and mosaics,mangroves dune grass plains forest woodland riverine,\"De Boer, W.F. and Ntumi, C.P. and Correia, A.U. and Mafuca, J.M.\",Diet and distribution of elephant in the Maputo Elephant Reserve; Mozambique,2000,African Journal of Ecology,38,3,188-201,Mary,0000-00-00 00:00:00,,,\n" + "seed disperser,direct observation,months,4,dung density,,,Article focused on elephant density per habitat type based on seed/plant types identified in dung at the various research locations. All identified plant types are being assumed to be dispersed by the elephants,1441,Mammalia,Proboscidea,Elephantidae,Loxodonta,africana,,NULL,African Bush Elephant,4398,Moraceae,Ficus,sp,NULL,Mozambique,NULL,NULL,yes,forest transitions and mosaics,mangroves dune grass plains forest woodland riverine,\"De Boer, W.F. and Ntumi, C.P. and Correia, A.U. and Mafuca, J.M.\",Diet and distribution of elephant in the Maputo Elephant Reserve; Mozambique,2000,African Journal of Ecology,38,3,188-201,Mary,0000-00-00 00:00:00,,,\n" + "seed disperser,direct observation,years,4,NULL,NULL,NULL,NULL,3051,Animal,Animal,Animal,Animal,animal,NULL,general animal,NULL,4176,Caesalpinioideae,Distemonanthus,benthamianus,NULL,Cameroon,NULL,NULL,yes,NULL,semideciduous tropical rain forest,\"Hardesty, B.D. and Parker, V.T.\",Community seed rain patterns and a comparison to adult community structure in a West African tropical forest,2003,Plant Ecology,164,1,49-64,Mary,8/15/12 9:35,,,\n" + "ingestion,direct observation,years,2,NULL,NULL,NULL,during both summer and winter season,1462,Mammalia,Artiodactyla,Bovidae,Madoqua,kirkii,,NULL,Kirk's Dikdik,6897,Moraceae,Ficus,petersii,NULL,Namibia,South West Africa,NULL,yes,NULL,riverine thicket,\"Tinley, K.\",Dikdik; Madoqua kirkii; in south-west Africa: notes on distribution; ecology; and behaviour,1969,Madoqua,1,NULL,Jul-33,Anna,2/24/14 18:40,,,\n";
        return CSVTSVUtil.createLabeledCSVParser(CSVTSVUtil.createExcelCSVParse(IOUtils.toInputStream(firstFewLines, StandardCharsets.UTF_8)));
    };
    final String baseUrl = "https://raw.githubusercontent.com/globalbioticinteractions/AfricaTreeDatabase/main";
    final String resource = baseUrl + "/globi.json";
    importAll(interactionListener, tableFactory, baseUrl, resource);
    assertThat(links.size(), is(9));
}
Also used : TaxonUtil(org.eol.globi.service.TaxonUtil) CSVTSVUtil(org.eol.globi.util.CSVTSVUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) URL(java.net.URL) InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) ResourceUtil(org.eol.globi.util.ResourceUtil) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) IsNot.not(org.hamcrest.core.IsNot.not) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Dataset(org.globalbioticinteractions.dataset.Dataset) Matchers.containsString(org.hamcrest.Matchers.containsString) InputStream(java.io.InputStream) InteractionListener(org.eol.globi.process.InteractionListener) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Aggregations

InteractionListener (org.eol.globi.process.InteractionListener)58 Test (org.junit.Test)51 Map (java.util.Map)46 ArrayList (java.util.ArrayList)36 TreeMap (java.util.TreeMap)26 URI (java.net.URI)24 IOException (java.io.IOException)22 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 URL (java.net.URL)15 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)14 InputStream (java.io.InputStream)13 List (java.util.List)13 TaxonUtil (org.eol.globi.service.TaxonUtil)13 Archive (org.gbif.dwc.Archive)13 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)13 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10