Search in sources :

Example 36 with Study

use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.

the class StudyImporterForBioInfoTest method importAbout600Records.

@Test
public void importAbout600Records() throws StudyImporterException {
    StudyImporter importer = new StudyImporterTestFactory(nodeFactory).instantiateImporter((Class) StudyImporterForBioInfo.class);
    final List<String> msgs = new ArrayList<String>();
    importer.setLogger(new ImportLogger() {

        @Override
        public void warn(LogContext study, String message) {
            msgs.add(message);
        }

        @Override
        public void info(LogContext study, String message) {
            msgs.add(message);
        }

        @Override
        public void severe(LogContext study, String message) {
            msgs.add(message);
        }
    });
    // limit the number of line to be imported to make test runs reasonably fast
    importer.setFilter(recordNumber -> recordNumber < 1000 || recordNumber == 4585 || (recordNumber > 47310 && recordNumber < 47320) || (recordNumber > 24220 && recordNumber < 24340));
    importStudy(importer);
    Study vectorStudy = nodeFactory.findStudy(TaxonomyProvider.BIO_INFO + "ref:153303");
    assertThat(vectorStudy, is(notNullValue()));
    Study study = nodeFactory.findStudy(TaxonomyProvider.BIO_INFO + "ref:60527");
    for (Relationship collectedRel : NodeUtil.getSpecimens(study)) {
        SpecimenNode specimen = new SpecimenNode(collectedRel.getEndNode());
        String externalId = specimen.getExternalId();
        assertThat(externalId, is(notNullValue()));
        assertThat(externalId, containsString(TaxonomyProvider.BIO_INFO + "rel:"));
    }
    ExecutionEngine engine = new ExecutionEngine(getGraphDb());
    ExecutionResult result = engine.execute("START taxon = node:taxons('*:*') MATCH taxon<-[:CLASSIFIED_AS]-specimen-[r]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon RETURN taxon.externalId + ' ' + lower(type(r)) + ' ' + targetTaxon.externalId as interaction");
    ResourceIterator<Map<String, Object>> iterator = result.iterator();
    List<String> interactions = new ArrayList<String>();
    while (iterator.hasNext()) {
        Map<String, Object> next = iterator.next();
        interactions.add((String) next.get("interaction"));
    }
    assertThat(interactions, hasItem("NBN:NHMSYS0000455771 interacts_with NBN:NBNSYS0000024890"));
    assertThat(interactions, hasItem("NBN:NBNSYS0000030148 endoparasitoid_of NBN:NHMSYS0000502366"));
    assertThat(interactions, hasItem("NBN:NHMSYS0000500943 has_endoparasitoid NBN:NBNSYS0000030148"));
    assertThat(interactions, hasItem("bioinfo:taxon:160260 has_vector bioinfo:taxon:162065"));
    assertThat(study.getTitle(), is("bioinfo:ref:60527"));
    assertThat(study.getSource(), is("Food Webs and Species Interactions in the Biodiversity of UK and Ireland (Online). 2015. Data provided by Malcolm Storey. Also available from http://bioinfo.org.uk."));
    assertThat("found unexpected log messages: [" + StringUtils.join(msgs, "\n") + "]", msgs.size(), is(1));
    assertThat(msgs.get(0), is("empty/no taxon name for bioinfo taxon id [149359] on line [4171]"));
}
Also used : Study(org.eol.globi.domain.Study) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) SpecimenNode(org.eol.globi.domain.SpecimenNode) ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) Relationship(org.neo4j.graphdb.Relationship) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 37 with Study

use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.

the class StudyImporterForBlewettTest method importAll.

@Test
public void importAll() throws StudyImporterException {
    StudyImporter importer = new StudyImporterTestFactory(nodeFactory).instantiateImporter((Class) StudyImporterForBlewett.class);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
    int count = 0;
    for (Relationship specimen : specimens) {
        count++;
    }
    assertThat(count, is(1824));
    assertNotNull(taxonIndex.findTaxonByName("Centropomus undecimalis"));
    Taxon taxonOfType = taxonIndex.findTaxonByName("Cal sapidus");
    assertThat(taxonOfType.getName(), is("Cal sapidus"));
    assertNotNull(taxonIndex.findTaxonByName("Ort chrysoptera"));
}
Also used : Study(org.eol.globi.domain.Study) Relationship(org.neo4j.graphdb.Relationship) Taxon(org.eol.globi.domain.Taxon) Test(org.junit.Test)

Example 38 with Study

use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.

the class StudyImporterForCruaudTest method importAll.

@Test
public void importAll() throws NodeFactoryException, StudyImporterException {
    StudyImporterForCruaud importer = new StudyImporterForCruaud(new ParserFactoryLocal(), nodeFactory);
    importer.setGeoNamesService(new GeoNamesService() {

        @Override
        public boolean hasTermForLocale(String locality) {
            return true;
        }

        @Override
        public LatLng findLatLng(String locality) throws IOException {
            return new LatLng(0, 0);
        }
    });
    importStudy(importer);
    List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(allStudies.size(), is(1));
    assertThat(taxonIndex.findTaxonByName("Agaon sp."), is(notNullValue()));
    assertThat(taxonIndex.findTaxonByName("Ficus chapaensis"), is(notNullValue()));
    assertThat(allStudies.get(0).getSource(), is(notNullValue()));
}
Also used : Study(org.eol.globi.domain.Study) GeoNamesService(org.eol.globi.service.GeoNamesService) IOException(java.io.IOException) LatLng(org.eol.globi.geo.LatLng) Test(org.junit.Test)

Example 39 with Study

use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.

the class StudyImporterForDunneTest method importStudy.

@Test
public void importStudy() throws StudyImporterException, IOException {
    String configJson = "{ \"citation\": \"blabla\",\n" + "  \"format\": \"dunne\",\n" + "  \"resources\": {\n" + "    \"nodes\": \"https://raw.githubusercontent.com/globalbioticinteractions/dunne2016SanakIntertidal/master/nodes.tsv\",\n" + "    \"links\": \"https://raw.githubusercontent.com/globalbioticinteractions/dunne2016SanakIntertidal/master/links.tsv\"\n" + "  },\n" + "  \"location\": {\n" + "    \"locality\": {\n" + "      \"id\": \"GEONAMES:5873327\",\n" + "      \"name\": \"Sanak Island, Alaska, USA\"\n" + "    },\n" + "    \"latitude\": 60,\n" + "    \"longitude\": 60\n" + "  }\n" + "}";
    JsonNode jsonNode = new ObjectMapper().readTree(configJson);
    DatasetImpl dunne2016 = new DatasetImpl("dunne2016", URI.create("http://example.com"));
    dunne2016.setConfig(jsonNode);
    ParserFactory parserFactory = new ParserFactoryForDataset(dunne2016);
    StudyImporterForDunne importer = new StudyImporterForDunne(parserFactory, nodeFactory);
    importer.setDataset(dunne2016);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    assertThat(study, is(notNullValue()));
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
    int count = 0;
    for (Relationship specimen : specimens) {
        count++;
    }
    assertThat(count, is(1804 * 2));
}
Also used : Study(org.eol.globi.domain.Study) Relationship(org.neo4j.graphdb.Relationship) JsonNode(org.codehaus.jackson.JsonNode) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 40 with Study

use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.

the class StudyImporterForDunneTest method importStudy2.

@Test
public void importStudy2() throws StudyImporterException, IOException {
    String configJson = "{ \"citation\": \"blabla\",\n" + "  \"format\": \"dunne\",\n" + "  \"resources\": {\n" + "    \"nodes\": \"https://raw.githubusercontent.com/globalbioticinteractions/dunne2016SanakNearshore/master/nodes.tsv\",\n" + "    \"links\": \"https://raw.githubusercontent.com/globalbioticinteractions/dunne2016SanakNearshore/master/links.tsv\"\n" + "  },\n" + "  \"location\": {\n" + "    \"locality\": {\n" + "      \"id\": \"GEONAMES:5873327\",\n" + "      \"name\": \"Sanak Island, Alaska, USA\"\n" + "    },\n" + "    \"latitude\": 60,\n" + "    \"longitude\": 60\n" + "  }\n" + "}";
    DatasetImpl dunne2016 = new DatasetImpl("dunne2016", URI.create("http://example.com"));
    dunne2016.setConfig(new ObjectMapper().readTree(configJson));
    ParserFactory parserFactory = new ParserFactoryForDataset(dunne2016);
    StudyImporterForDunne importer = new StudyImporterForDunne(parserFactory, nodeFactory);
    importer.setDataset(dunne2016);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    assertThat(study, is(notNullValue()));
    assertThat(study.getSource(), containsString("Accessed at "));
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
    int count = 0;
    for (Relationship specimen : specimens) {
        count++;
    }
    assertThat(count, is(6774 * 2));
}
Also used : Study(org.eol.globi.domain.Study) Relationship(org.neo4j.graphdb.Relationship) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

Study (org.eol.globi.domain.Study)141 Test (org.junit.Test)84 StudyImpl (org.eol.globi.domain.StudyImpl)61 Specimen (org.eol.globi.domain.Specimen)38 Relationship (org.neo4j.graphdb.Relationship)33 TaxonImpl (org.eol.globi.domain.TaxonImpl)32 IOException (java.io.IOException)30 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)24 Location (org.eol.globi.domain.Location)24 StringWriter (java.io.StringWriter)21 LocationImpl (org.eol.globi.domain.LocationImpl)20 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)16 Taxon (org.eol.globi.domain.Taxon)16 SpecimenNode (org.eol.globi.domain.SpecimenNode)14 Date (java.util.Date)13 DatasetImpl (org.eol.globi.service.DatasetImpl)13 Node (org.neo4j.graphdb.Node)12 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)10 InteractType (org.eol.globi.domain.InteractType)9