Search in sources :

Example 11 with DatasetLocal

use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.

the class ExporterRDFTest method exportSPIRE.

@Test
public void exportSPIRE() throws IOException, StudyImporterException {
    StudyImporterForSPIRE importer = new StudyImporterForSPIRE(null, nodeFactory);
    importer.setFilter(recordNumber -> recordNumber < 5);
    importer.setDataset(new DatasetLocal());
    importStudy(importer);
    List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
    Taxon taxon = taxonIndex.getOrCreateTaxon(new TaxonImpl("some taxon", null));
    Taxon sameAsTaxon = taxonIndex.getOrCreateTaxon(new TaxonImpl("bugus same as taxon", "EOL:123"));
    Transaction tx = getGraphDb().beginTx();
    try {
        assertThat(taxon, is(notNullValue()));
        ((NodeBacked) taxon).getUnderlyingNode().createRelationshipTo(((NodeBacked) sameAsTaxon).getUnderlyingNode(), NodeUtil.asNeo4j(RelTypes.SAME_AS));
        tx.success();
    } finally {
        tx.finish();
    }
    File file = File.createTempFile("spire-as-light-globi", ".nq");
    try {
        Writer writer = new FileWriter(file);
        ExporterRDF turtleExporter = new ExporterRDF();
        for (Study study : studies) {
            turtleExporter.exportStudy(study, writer, true);
        }
        writer.flush();
        writer.close();
        assertTrue(file.exists());
        String content = IOUtils.toString(new FileInputStream(file));
        assertThat(content, not(containsString("no:match")));
        assertThat(content, containsString("http://purl.obolibrary.org/obo/ENVO_"));
    } finally {
        FileUtils.deleteQuietly(file);
    }
}
Also used : Study(org.eol.globi.domain.Study) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) FileWriter(java.io.FileWriter) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DatasetLocal(org.eol.globi.service.DatasetLocal) FileInputStream(java.io.FileInputStream) StudyImporterForSPIRE(org.eol.globi.data.StudyImporterForSPIRE) Transaction(org.neo4j.graphdb.Transaction) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 12 with DatasetLocal

use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.

the class StudyImporterForGlobalWebDbTest method dietMatrix.

@Test
public void dietMatrix() throws StudyImporterException {
    List<String> matrices = new ArrayList<>();
    StudyImporterForGlobalWebDb importer = new StudyImporterForGlobalWebDb(null, null);
    importer.setDataset(new DatasetLocal());
    importer.importDietMatrices("classpath:/org/eol/globi/data/globalwebdb-test.zip", matrices::add);
    assertThat(matrices.size(), is(10));
    assertThat(matrices.get(0), is(aDietMatrix));
}
Also used : ArrayList(java.util.ArrayList) DatasetLocal(org.eol.globi.service.DatasetLocal) Test(org.junit.Test)

Example 13 with DatasetLocal

use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.

the class StudyImporterForGlobalWebDbTest method dietMatrices.

@Test
public void dietMatrices() throws StudyImporterException {
    final AtomicInteger count = new AtomicInteger();
    StudyImporterForGlobalWebDb importer = new StudyImporterForGlobalWebDb(null, null);
    importer.setDataset(new DatasetLocal());
    importer.importDietMatrices("classpath:/org/eol/globi/data/globalwebdb-test.zip", matrixString -> {
        try {
            StudyImporterForGlobalWebDb.parseDietMatrix(new InteractionListener() {

                @Override
                public void newLink(Map<String, String> properties) throws StudyImporterException {
                    count.incrementAndGet();
                }
            }, matrixString, "a source citation");
        } catch (IOException e) {
            throw new StudyImporterException(e);
        }
    });
    assertThat(count.get(), is(207));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) DatasetLocal(org.eol.globi.service.DatasetLocal) Test(org.junit.Test)

Example 14 with DatasetLocal

use of org.eol.globi.service.DatasetLocal 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 15 with DatasetLocal

use of org.eol.globi.service.DatasetLocal in project eol-globi-data by jhpoelen.

the class StudyImporterForLifeWatchGreeceTest method importCoupleOfLines.

@Test
public void importCoupleOfLines() throws StudyImporterException {
    StudyImporterForLifeWatchGreece importer = new StudyImporterForLifeWatchGreece(new TestParserFactory("122,\"Fauchald, K., Jumars, P.A. (1979) The Diet of Worms: A StudyNode of Polychaete Feeding Guilds. <i>Oceanography and Marine Biology: Annual Review</i>, 17:193-284.\",\"Schistomeringos rudolphii\",\"http://www.owl-ontologies.com/unnamed.owl#Algae\",\"Algae as food source.\",\"http://eol.org/schema/terms/preysUpon\",\"The type of food an organism prefers.\",1,1\n" + "429,\"Simpson, M. (1962) Reproduction of the Polychaete Glycera Dibranchiata at Solomons, Maryland. <i>The Biological Bulletin</i>, 123:396-411.\",\"Glycera alba\",\"http://polytraits.lifewatchgreece.eu/terms/EPKY_YES\",\"The organism undergoes epitokous metamorphosis.\",\"http://polytraits.lifewatchgreece.eu/terms/EPKY\",\"Form of reproduction of marine polychates in which the new individual arises by modification and separation from the posterior end of the worm in order to leave the bottom and reproduce [1292].\",2,1\n" + "543,\"Rouse, G.W., Pleijel, F. (2001) Polychaetes. Oxford University Press,Oxford.354pp.\",\"Glycera alba\",\"http://polytraits.lifewatchgreece.eu/terms/EPKY_YES\",\"The organism undergoes epitokous metamorphosis.\",\"http://polytraits.lifewatchgreece.eu/terms/EPKY\",\"Form of reproduction of marine polychates in which the new individual arises by modification and separation from the posterior end of the worm in order to leave the bottom and reproduce [1292].\",2,1\n" + "429,\"Simpson, M. (1962) Reproduction of the Polychaete Glycera Dibranchiata at Solomons, Maryland. <i>The Biological Bulletin</i>, 123:396-411.\",\"Glycera rouxi\",\"http://polytraits.lifewatchgreece.eu/terms/SM_YES\",\"Organisms that undergo sexual metamorphosis\",\"http://polytraits.lifewatchgreece.eu/terms/SM\",\"Conspicuous change in the organism's body structure prior to reproduction.\",2,1\n" + "778,\"Hartmann-Schröder, G. (1996) Annelida, Borstenwürmer, Polychaeta. Gustav Fischer Verlag, Jena. 648pp.\",\"Glycera rouxi\",\"http://polytraits.lifewatchgreece.eu/terms/SM_YES\",\"Organisms that undergo sexual metamorphosis\",\"http://polytraits.lifewatchgreece.eu/terms/SM\",\"Conspicuous change in the organism's body structure prior to reproduction.\",2,1\n" + "429,\"Simpson, M. (1962) Reproduction of the Polychaete Glycera Dibranchiata at Solomons, Maryland. <i>The Biological Bulletin</i>, 123:396-411.\",\"Glycera tesselata\",\"http://polytraits.lifewatchgreece.eu/terms/SM_YES\",\"Organisms that undergo sexual metamorphosis\",\"http://polytraits.lifewatchgreece.eu/terms/SM\",\"Conspicuous change in the organism's body structure prior to reproduction.\",2,1\n"), nodeFactory);
    importer.setDataset(new DatasetLocal());
    importStudy(importer);
}
Also used : DatasetLocal(org.eol.globi.service.DatasetLocal) Test(org.junit.Test)

Aggregations

DatasetLocal (org.eol.globi.service.DatasetLocal)16 Test (org.junit.Test)11 Study (org.eol.globi.domain.Study)7 IOException (java.io.IOException)4 JsonNode (org.codehaus.jackson.JsonNode)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Relationship (org.neo4j.graphdb.Relationship)3 Specimen (org.eol.globi.domain.Specimen)2 Taxon (org.eol.globi.domain.Taxon)2 LatLng (org.eol.globi.geo.LatLng)2 GeoNamesService (org.eol.globi.service.GeoNamesService)2 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)2 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)1 Query (com.hp.hpl.jena.query.Query)1 QueryExecution (com.hp.hpl.jena.query.QueryExecution)1 QuerySolution (com.hp.hpl.jena.query.QuerySolution)1 ResultSet (com.hp.hpl.jena.query.ResultSet)1 Model (com.hp.hpl.jena.rdf.model.Model)1