Search in sources :

Example 1 with ExecutionResult

use of org.neo4j.cypher.javacompat.ExecutionResult in project eol-globi-data by jhpoelen.

the class ExporterTaxaDistinct method exportAllDistinctTaxa.

private void exportAllDistinctTaxa(Writer writer, GraphDatabaseService graphDatabase) throws IOException {
    ExecutionEngine engine = new ExecutionEngine(graphDatabase);
    ExecutionResult results = engine.execute("START taxon = node:taxons('*:*') " + "MATCH taxon<-[:CLASSIFIED_AS]-specimen " + "WHERE has(taxon.externalId) AND taxon.externalId <> '" + PropertyAndValueDictionary.NO_MATCH + "' " + "AND has(taxon.name) AND taxon.name <> '" + PropertyAndValueDictionary.NO_MATCH + "' " + "RETURN distinct(taxon)" + ", taxon.name as scientificName" + ", taxon.path? as path" + ", taxon.pathNames? as pathNames" + ", taxon.rank? as rank" + ", taxon.externalId as taxonId");
    Map<String, String> row = new HashMap<String, String>();
    for (Map<String, Object> result : results) {
        resultsToRow(row, result);
        writeProperties(writer, row);
        row.clear();
    }
}
Also used : ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) HashMap(java.util.HashMap) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult)

Example 2 with ExecutionResult

use of org.neo4j.cypher.javacompat.ExecutionResult 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 3 with ExecutionResult

use of org.neo4j.cypher.javacompat.ExecutionResult in project eol-globi-data by jhpoelen.

the class ImageLinker method link.

@Override
public void link() {
    ExecutionEngine engine = new ExecutionEngine(graphDb);
    ExecutionResult executionResult = engine.execute("START taxon = node:taxons('*:*')\n" + "WHERE not(has(taxon.thumbnailUrl)) AND has(taxon.externalId) AND taxon.externalId <> 'no:match'\n" + "RETURN id(taxon) as `id`, taxon.externalId as `externalId`");
    for (Map<String, Object> externalIdMap : executionResult) {
        final String externalId = (String) externalIdMap.get("externalId");
        final Long nodeId = (Long) externalIdMap.get("id");
        TaxonImage taxonImage = null;
        try {
            taxonImage = new EOLTaxonImageService().lookupImageForExternalId(externalId);
        } catch (IOException e) {
            LOG.warn("failed to lookup externalId [" + externalId + "]", e);
        }
        if (taxonImage == null) {
            if (out != null) {
                out.println(StringUtils.join(Arrays.asList("EOL:12345", "", "", ""), "\t"));
            }
        } else {
            final String infoURL = taxonImage.getInfoURL() == null ? "" : taxonImage.getInfoURL();
            final String thumbnailURL = taxonImage.getThumbnailURL() == null ? "" : taxonImage.getThumbnailURL();
            final String imageURL = taxonImage.getImageURL() == null ? "" : taxonImage.getImageURL();
            ExecutionResult execute = engine.execute("START taxon = node({nodeId})\n" + "SET taxon.externalUrl={infoUrl}, taxon.imageUrl={imageUrl}, taxon.thumbnailUrl={thumbnailUrl}\n" + "RETURN taxon.externalId, taxon.externalUrl, taxon.thumbnailUrl, taxon.imageUrl", new HashMap<String, Object>() {

                {
                    put("nodeId", nodeId);
                    put("infoUrl", infoURL);
                    put("imageUrl", imageURL);
                    put("thumbnailUrl", thumbnailURL);
                }
            });
            if (out != null) {
                for (Map<String, Object> stringObjectMap : execute) {
                    out.println(StringUtils.join(CSVTSVUtil.escapeValues(stringObjectMap.values()), "\t"));
                }
            }
            if (execute != null && execute.iterator() != null) {
                execute.iterator().close();
            }
        }
    }
}
Also used : ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) TaxonImage(org.eol.globi.domain.TaxonImage) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult) IOException(java.io.IOException) EOLTaxonImageService(org.eol.globi.service.EOLTaxonImageService)

Example 4 with ExecutionResult

use of org.neo4j.cypher.javacompat.ExecutionResult in project eol-globi-data by jhpoelen.

the class IndexInteractions method link.

@Override
public void link() {
    LinkProgress progress = new LinkProgress(LOG::info, 10);
    progress.start();
    boolean done;
    ExecutionEngine engine = new ExecutionEngine(graphDb);
    do {
        ExecutionResult result = engine.execute("START dataset = node:datasets('*:*')\n" + "MATCH dataset<-[:IN_DATASET]-study-[:COLLECTED]->specimen\n" + "WHERE not(specimen<-[:HAS_PARTICIPANT]-())\n" + "WITH specimen, study, dataset LIMIT {batchSize}\n" + "MATCH specimen-[i:" + InteractUtil.allInteractionsCypherClause() + "]->otherSpecimen\n" + "WHERE not(has(i.inverted))\n" + "CREATE specimen<-[:HAS_PARTICIPANT]-interaction-[:DERIVED_FROM]->study" + ", interaction-[:HAS_PARTICIPANT]->otherSpecimen " + ", interaction-[:ACCESSED_AT]->dataset\n" + "RETURN id(interaction)", MapUtil.map("batchSize", this.batchSize));
        done = !result.iterator().hasNext();
        result.iterator().close();
        progress.progress();
    } while (!done);
}
Also used : ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult)

Example 5 with ExecutionResult

use of org.neo4j.cypher.javacompat.ExecutionResult in project eol-globi-data by jhpoelen.

the class StudyImporterForByrnesTest method importAll.

@Test
public void importAll() throws StudyImporterException {
    StudyImporterForByrnes studyImporterForByrnes = new StudyImporterForByrnes(new ParserFactoryLocal(), nodeFactory);
    studyImporterForByrnes.importStudy();
    resolveNames();
    List<String> citationList = new ArrayList<String>();
    Set<String> citations = new HashSet<String>();
    List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
    assertTrue(studies.size() > 0);
    for (Study study : studies) {
        assertThat(study.getTitle(), is(notNullValue()));
        assertThat(study.getSource(), is(notNullValue()));
        assertThat(study.getCitation(), is(notNullValue()));
        citations.add(study.getCitation());
        citationList.add(study.getCitation());
    }
    assertThat("found duplicates in citation list", citationList.size(), is(citations.size()));
    assertNotNull(taxonIndex.findTaxonByName("Anisotremus davidsonii"));
    assertThat(citations, hasItem("Pennings, S. C. 1990. Size-related shifts in herbivory: specialization in the sea hare Aplysia californica Cooper. Journal of Experimental Marine Biology and Ecology 142:43-61."));
    assertThat(citations, hasItem("Barry, J. and M. Ehret. 1993. Diet, food preference, and algal availability for fishes and crabs on intertidal reef communities in southern California. Environmental Biology of Fishes 37:75-95."));
    assertThat(citations, hasItem("Byrnes, J.E. et al., 2011. Climate-driven increases in storm frequency simplify kelp forest food webs. Global Change Biology, 17(8), pp.2513–2524. Available at: http://dx.doi.org/10.1111/j.1365-2486.2011.02409.x."));
    assertThat(citations, not(hasItem("17(8)")));
    ExecutionEngine executionEngine = new ExecutionEngine(getGraphDb());
    ExecutionResult result = executionEngine.execute("START taxon = node:taxons(name=\"Strongylocentrotus purpuratus\")" + " MATCH taxon<-[:CLASSIFIED_AS]-specimen-[:ATE]->prey-[:CLASSIFIED_AS]->preyTaxon " + " RETURN collect(distinct(preyTaxon.name))");
    assertThat(result.dumpToString(), containsString("Bossiella orbigiana"));
}
Also used : Study(org.eol.globi.domain.Study) ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) ArrayList(java.util.ArrayList) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ExecutionEngine (org.neo4j.cypher.javacompat.ExecutionEngine)9 ExecutionResult (org.neo4j.cypher.javacompat.ExecutionResult)9 Study (org.eol.globi.domain.Study)4 Test (org.junit.Test)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LogContext (org.eol.globi.domain.LogContext)2 Relationship (org.neo4j.graphdb.Relationship)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Map (java.util.Map)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 StudyImporterException (org.eol.globi.data.StudyImporterException)1 SpecimenNode (org.eol.globi.domain.SpecimenNode)1 TaxonImage (org.eol.globi.domain.TaxonImage)1 DatasetImpl (org.eol.globi.service.DatasetImpl)1