Search in sources :

Example 1 with LogContext

use of org.eol.globi.domain.LogContext 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 2 with LogContext

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

the class InteractionListenerImplTest method importAssociatedTaxa.

@Test
public void importAssociatedTaxa() throws StudyImporterException {
    final InteractionListenerImpl listener = new InteractionListenerImpl(nodeFactory, null, new ImportLogger() {

        @Override
        public void warn(LogContext study, String message) {
            fail("got message: " + message);
        }

        @Override
        public void info(LogContext study, String message) {
        }

        @Override
        public void severe(LogContext study, String message) {
            fail("got message: " + message);
        }
    });
    final HashMap<String, String> link = new HashMap<>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(SOURCE_TAXON_ID, "duck");
    link.put(SOURCE_BODY_PART_ID, "bla:123");
    link.put(SOURCE_BODY_PART_NAME, "snout");
    link.put("associatedTaxa", "parasite of: Mini mouse");
    link.put(StudyImporterForMetaTable.EVENT_DATE, "20160404T21:31:40Z");
    link.put(StudyImporterForMetaTable.LATITUDE, "12.1");
    link.put(StudyImporterForMetaTable.LONGITUDE, "13.2");
    link.put(REFERENCE_ID, "123");
    link.put(STUDY_SOURCE_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    link.put(REFERENCE_DOI, "doi:1234");
    listener.newLink(link);
    final List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(allStudies.size(), is(1));
    final Study study = allStudies.get(0);
    assertThat(study.getCitation(), is(""));
    boolean foundPair = false;
    for (Relationship specimenRel : NodeUtil.getSpecimens(study)) {
        final SpecimenNode predator = new SpecimenNode(specimenRel.getEndNode());
        for (Relationship hosts : ((NodeBacked) predator).getUnderlyingNode().getRelationships(NodeUtil.asNeo4j(InteractType.PARASITE_OF), Direction.OUTGOING)) {
            final SpecimenNode host = new SpecimenNode(hosts.getEndNode());
            final TaxonNode hostTaxon = getOrigTaxon(host);
            final TaxonNode predTaxon = getOrigTaxon(predator);
            assertThat(hostTaxon.getName(), is("Mini mouse"));
            assertThat(predTaxon.getName(), is("donald"));
            assertThat(predTaxon.getExternalId(), is("duck"));
            foundPair = true;
        }
    }
    assertThat(foundPair, is(true));
}
Also used : Study(org.eol.globi.domain.Study) TaxonNode(org.eol.globi.domain.TaxonNode) HashMap(java.util.HashMap) LogContext(org.eol.globi.domain.LogContext) SpecimenNode(org.eol.globi.domain.SpecimenNode) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 3 with LogContext

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

the class StudyImporterForHechingerTest method importStudy.

@Test
public void importStudy() throws StudyImporterException, IOException {
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Ryan F. Hechinger, Kevin D. Lafferty, John P. McLaughlin, Brian L. Fredensborg, Todd C. Huspeni, Julio Lorda, Parwant K. Sandhu, Jenny C. Shaw, Mark E. Torchin, Kathleen L. Whitney, and Armand M. Kuris 2011. Food webs including parasites, biomass, body sizes, and life stages for three California/Baja California estuaries. Ecology 92:791–791. http://dx.doi.org/10.1890/10-1383.1 .\",\n" + "  \"doi\": \"http://dx.doi.org/10.1890/10-1383.1\",\n" + "  \"format\": \"hechinger\",\n" + "  \"delimiter\": \"\\t\",\n" + "  \"resources\": {\n" + "    \"nodes\": \"hechinger/Metaweb_Nodes.txt\",\n" + "    \"links\": \"hechinger/Metaweb_Links.txt\"\n" + "  }\n" + "}");
    DatasetImpl dataset = new DatasetLocal();
    dataset.setConfig(config);
    ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
    StudyImporterForHechinger importer = new StudyImporterForHechinger(parserFactory, nodeFactory);
    importer.setDataset(dataset);
    importer.setLogger(new ImportLogger() {

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

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

        @Override
        public void severe(LogContext study, String message) {
            LOG.error(message);
        }
    });
    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(27932));
    ExecutionEngine engine = new ExecutionEngine(getGraphDb());
    String query = "START resourceTaxon = node:taxons(name='Suaeda spp.')" + " MATCH taxon<-[:CLASSIFIED_AS]-specimen-[r]->resourceSpecimen-[:CLASSIFIED_AS]-resourceTaxon, specimen-[:COLLECTED_AT]->location" + " RETURN taxon.name, specimen.lifeStage?, type(r), resourceTaxon.name, resourceSpecimen.lifeStage?, location.latitude as lat, location.longitude as lng";
    ExecutionResult result = engine.execute(query);
    assertThat(result.dumpToString(), containsString("Branta bernicla"));
    assertThat(result.dumpToString(), containsString("Athya affinis"));
    assertThat(result.dumpToString(), containsString("Anas acuta"));
    assertThat(result.dumpToString(), containsString("30.378207 | -115.938835 |"));
    query = "START taxon = node:taxons('*:*')" + " MATCH taxon<-[:CLASSIFIED_AS]-specimen-[:PARASITE_OF]->resourceSpecimen-[:CLASSIFIED_AS]-resourceTaxon" + " RETURN taxon.name";
    result = engine.execute(query);
    Set<String> actualParasites = new HashSet<String>();
    for (Map<String, Object> row : result) {
        actualParasites.add((String) row.get("taxon.name"));
    }
    assertThat(actualParasites.size() > 0, is(true));
    for (String unlikelyParasite : unlikelyParasites()) {
        assertThat(actualParasites, not(hasItem(unlikelyParasite)));
    }
    // Trypanorhyncha (kind of tapeworms) are typically parasites, not prey
    query = "START resourceTaxon = node:taxons(name='Trypanorhyncha')" + " MATCH taxon<-[:CLASSIFIED_AS]-specimen-[r:PREYS_UPON]->resourceSpecimen-[:CLASSIFIED_AS]-resourceTaxon" + " RETURN specimen.externalId + type(r) + resourceSpecimen.externalId as `resourceExternalId`";
    result = engine.execute(query);
    Set<String> actualPrey = new HashSet<String>();
    for (Map<String, Object> row : result) {
        actualPrey.add((String) row.get("resourceExternalId"));
    }
    assertThat(actualPrey.size(), is(0));
}
Also used : Study(org.eol.globi.domain.Study) LogContext(org.eol.globi.domain.LogContext) JsonNode(org.codehaus.jackson.JsonNode) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult) DatasetImpl(org.eol.globi.service.DatasetImpl) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DatasetLocal(org.eol.globi.service.DatasetLocal) ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) Relationship(org.neo4j.graphdb.Relationship) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with LogContext

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

the class StudyImporterForPlanqueIT method importAll.

@Test
public void importAll() throws StudyImporterException, NodeFactoryException, IOException {
    final List<String> errorMessages = new ArrayList<String>();
    BaseStudyImporter importer = new StudyImporterForPlanque(new ParserFactoryLocal(), nodeFactory);
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Benjamin Planque, Raul Primicerio, Kathrine Michalsen, Michaela Aschan, Grégoire Certain, Padmini Dalpadado, Harald Gjøsæater, Cecilie Hansen, Edda Johannesen, Lis Lindal Jørgensen, Ina Kolsum, Susanne Kortsch, Lise-Marie Leclerc, Lena Omli, Mette Skern-Mauritzen, and Magnus Wiedmann 2014. Who eats whom in the Barents Sea: a food web topology from plankton to whales. Ecology 95:1430–1430. http://dx.doi.org/10.1890/13-1062.1\",\n" + "  \"doi\": \"http://dx.doi.org/10.1890/13-1062.1\",\n" + "  \"format\": \"planque\",\n" + "  \"resources\": {\n" + "    \"links\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/PairwiseList.txt\",\n" + "    \"references\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/References.txt\",\n" + "    \"referencesForLinks\": \"http://www.esapubs.org/archive/ecol/E095/124/revised/PairWise2References.txt\"\n" + "  }\n" + "}");
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"));
    dataset.setConfig(config);
    importer.setDataset(dataset);
    importer.setLogger(new ImportLogger() {

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

        @Override
        public void info(LogContext study, String message) {
        }

        @Override
        public void severe(LogContext study, String message) {
        }
    });
    importStudy(importer);
    int interactionCount = 0;
    List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
    for (Study study : studies) {
        Iterable<Relationship> specimenRels = NodeUtil.getSpecimens(study);
        for (Relationship specimenRel : specimenRels) {
            interactionCount++;
        }
    }
    assertThat(interactionCount, is(4900));
    int uniqueReference = 236;
    // note that the +1 is for all links that had no reference associated to it
    assertThat(studies.size(), is(uniqueReference + 1));
    assertThat(taxonIndex.findTaxonByName("Trisopterus esmarkii"), is(notNullValue()));
    assertThat(errorMessages.size(), is(0));
}
Also used : Study(org.eol.globi.domain.Study) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) Relationship(org.neo4j.graphdb.Relationship) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 5 with LogContext

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

the class StudyImporterForHurlbertIT method importAll.

@Test
public void importAll() throws StudyImporterException, DatasetFinderException {
    Dataset dataset = datasetFor("hurlbertlab/dietdatabase");
    ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
    StudyImporter importer = new StudyImporterForHurlbert(parserFactory, nodeFactory);
    importer.setDataset(dataset);
    importer.setLogger(new ImportLogger() {

        @Override
        public void warn(LogContext study, String message) {
            fail("did not expect warning [" + message + "]");
        }

        @Override
        public void info(LogContext study, String message) {
        }

        @Override
        public void severe(LogContext study, String message) {
            fail("did not expect error [" + message + "]");
        }
    });
    importStudy(importer);
    List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(allStudies.size() > 10, is(true));
    assertThat(allStudies.get(0).getOriginatingDataset(), is(notNullValue()));
    Taxon formicidae = taxonIndex.findTaxonByName("Formicidae");
    assertThat(formicidae.getExternalId(), is(notNullValue()));
}
Also used : Study(org.eol.globi.domain.Study) Dataset(org.eol.globi.service.Dataset) Taxon(org.eol.globi.domain.Taxon) LogContext(org.eol.globi.domain.LogContext) Test(org.junit.Test)

Aggregations

LogContext (org.eol.globi.domain.LogContext)6 Study (org.eol.globi.domain.Study)5 Test (org.junit.Test)5 Relationship (org.neo4j.graphdb.Relationship)4 ArrayList (java.util.ArrayList)3 JsonNode (org.codehaus.jackson.JsonNode)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 DatasetImpl (org.eol.globi.service.DatasetImpl)3 HashMap (java.util.HashMap)2 SpecimenNode (org.eol.globi.domain.SpecimenNode)2 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)2 ExecutionEngine (org.neo4j.cypher.javacompat.ExecutionEngine)2 ExecutionResult (org.neo4j.cypher.javacompat.ExecutionResult)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Taxon (org.eol.globi.domain.Taxon)1 TaxonNode (org.eol.globi.domain.TaxonNode)1 Dataset (org.eol.globi.service.Dataset)1 DatasetLocal (org.eol.globi.service.DatasetLocal)1