Search in sources :

Example 21 with DatasetImpl

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

the class StudyImporterForSzoboszlaiIT method importAll.

@Test
public void importAll() throws StudyImporterException, IOException {
    JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Szoboszlai AI, Thayer JA, Wood SA, Sydeman WJ, Koehn LE (2015) Data from: Forage species in predator diets: synthesis of data from the California Current. Dryad Digital Repository. http://dx.doi.org/10.5061/dryad.nv5d2\",\n" + "  \"doi\": \"http://dx.doi.org/10.5061/dryad.nv5d2\",\n" + "  \"format\": \"szoboszlai\",\n" + "  \"resources\": {\n" + "    \"links\": \"http://datadryad.org/bitstream/handle/10255/dryad.94536/CCPDDlinkdata_v1.csv\",\n" + "    \"shapes\": \"http://datadryad.org/bitstream/handle/10255/dryad.94535/CCPDDlocationdata_v1.zip\"\n" + "  }\n" + "}");
    DatasetImpl dataset = new DatasetImpl("someRepo", URI.create("http://example.com"));
    dataset.setConfig(config);
    ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
    StudyImporterForSzoboszlai importer = new StudyImporterForSzoboszlai(parserFactory, nodeFactory);
    importer.setDataset(dataset);
    importStudy(importer);
    List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(allStudies.size(), is(not(0)));
    Study firstStudy = allStudies.get(0);
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(firstStudy);
    for (Relationship specimen : specimens) {
        Specimen specimenNode = new SpecimenNode(specimen.getEndNode());
        Location sampleLocation = specimenNode.getSampleLocation();
        assertThat(sampleLocation, is(notNullValue()));
        assertThat(sampleLocation.getLatitude(), is(notNullValue()));
        assertThat(sampleLocation.getLongitude(), is(notNullValue()));
    }
    assertThat(taxonIndex.findTaxonByName("Thunnus thynnus"), is(notNullValue()));
    assertThat(nodeFactory.findLocation(new LocationImpl(34.00824202376044, -120.72716166720323, null, null)), is(notNullValue()));
}
Also used : Study(org.eol.globi.domain.Study) JsonNode(org.codehaus.jackson.JsonNode) DatasetImpl(org.eol.globi.service.DatasetImpl) SpecimenNode(org.eol.globi.domain.SpecimenNode) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 22 with DatasetImpl

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

the class StudyImporterForTSVTest method wardeh.

@Test
public void wardeh() throws StudyImporterException {
    String firstFewLines = "sourceTaxonId\tsourceTaxonName\tinteractionTypeId\tinteractionTypeName\ttargetTaxonId\ttargetTaxonName\tlocalityId\tlocalityName\tdecimalLatitude\tdecimalLongitude\tobservationDateTime\treferenceUrl\tsourceDoi\tsourceCitation\n" + "EOL:2912748\tbacillus subtilis\tRO:0002454\thasHost\tEOL:594885\tmorus alba\t\t\t\t\t\thttp://www.ncbi.nlm.nih.gov/nuccore/100172732\tdoi: 10.1038/sdata.2015.49\tWardeh, M. et al. Database of host-pathogen and related species interactions, and their global distribution. Sci. Data 2:150049 doi: 10.1038/sdata.2015.49 (2015)\n" + "EOL:741039\tbovine adenovirus c\tRO:0002454\thasHost\tEOL:328699\tbos taurus\t\t\t\t\t\thttp://www.ncbi.nlm.nih.gov/nuccore/1002418\tdoi: 10.1038/sdata.2015.49\tWardeh, M. et al. Database of host-pathogen and related species interactions, and their global distribution. Sci. Data 2:150049 doi: 10.1038/sdata.2015.49 (2015)\n" + "EOL:12141292\tichthyophonus hoferi\tRO:0002454\thasHost\tEOL:205418\tlimanda ferruginea\t\t\t\t\t\thttp://www.ncbi.nlm.nih.gov/nuccore/1002422\tdoi: 10.1038/sdata.2015.49\tWardeh, M. et al. Database of host-pathogen and related species interactions, and their global distribution. Sci. Data 2:150049 doi: 10.1038/sdata.2015.49 (2015)\n";
    StudyImporterForTSV importer = new StudyImporterForTSV(new TestParserFactory(firstFewLines), nodeFactory);
    importer.setDataset(new DatasetImpl("someRepo", URI.create("http://example.com")));
    importStudy(importer);
    Taxon taxon = taxonIndex.findTaxonById("EOL:2912748");
    assertThat(taxon, is(notNullValue()));
    assertThat(taxon.getName(), is("bacillus subtilis"));
    assertThat(taxon.getExternalId(), is("EOL:2912748"));
    final List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    final List<String> titles = new ArrayList<String>();
    final List<String> ids = new ArrayList<String>();
    for (Study study : allStudies) {
        titles.add(study.getTitle());
        ids.add(study.getExternalId());
    }
    assertThat(titles, hasItem("someRepohttp://www.ncbi.nlm.nih.gov/nuccore/100172732"));
    assertThat(ids, hasItem("http://www.ncbi.nlm.nih.gov/nuccore/100172732"));
}
Also used : Study(org.eol.globi.domain.Study) Taxon(org.eol.globi.domain.Taxon) ArrayList(java.util.ArrayList) DatasetImpl(org.eol.globi.service.DatasetImpl) Test(org.junit.Test)

Example 23 with DatasetImpl

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

the class IndexInteractionsTest method indexInteractions.

@Test
public void indexInteractions() throws NodeFactoryException {
    TaxonIndex taxonIndex = getOrCreateTaxonIndex();
    // see https://github.com/jhpoelen/eol-globi-data/wiki/Nanopubs
    StudyImpl study = new StudyImpl("some study", "some source", "http://doi.org/123.23/222", "some study citation");
    NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri")));
    Study interaction = factory.getOrCreateStudy(study);
    TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
    Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
    donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
    TaxonImpl mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
    Taxon mickeyTaxonNCBI = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
    NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonNCBI, getGraphDb(), RelTypes.SAME_AS);
    Specimen mickey = factory.createSpecimen(interaction, mickeyTaxon);
    mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxon));
    donald.ate(mickey);
    new IndexInteractions(getGraphDb()).link();
    NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j(getGraphDb());
    StudyImpl study1 = new StudyImpl("some study", "some source", null, "come citation");
    study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri")));
    StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
    assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
    assertThat(interaction.getTitle(), is(someStudy.getTitle()));
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(someStudy);
    RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
    Set<Long> ids = new HashSet<>();
    List<Long> idList = new ArrayList<>();
    for (Relationship specimen : specimens) {
        assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
        Relationship singleRelationship = specimen.getEndNode().getSingleRelationship(hasParticipant, Direction.INCOMING);
        long id = singleRelationship.getStartNode().getId();
        ids.add(id);
        idList.add(id);
    }
    assertThat(ids.size(), Is.is(1));
    assertThat(idList.size(), Is.is(2));
    Node interactionNode = getGraphDb().getNodeById(idList.get(0));
    assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.DERIVED_FROM)));
    assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.ACCESSED_AT)));
}
Also used : Study(org.eol.globi.domain.Study) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) DatasetImpl(org.eol.globi.service.DatasetImpl) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) StudyNode(org.eol.globi.domain.StudyNode) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) TaxonIndex(org.eol.globi.data.TaxonIndex) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with DatasetImpl

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

the class LinkerDOITest method createStudyDOIlookupCitationDisabled.

@Test
public void createStudyDOIlookupCitationDisabled() throws NodeFactoryException {
    StudyImpl study1 = new StudyImpl("title", "some source", null, "some citation");
    study1.setExternalId("some:id");
    DatasetImpl originatingDataset = new DatasetImpl("some/namespace", URI.create("some:uri"));
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, false);
    originatingDataset.setConfig(objectNode);
    study1.setOriginatingDataset(originatingDataset);
    Study study = getNodeFactory().getOrCreateStudy(study1);
    assertThat(study.getSource(), is("some source"));
    assertThat(study.getDOI(), is(nullValue()));
    assertThat(study.getCitation(), is("some citation"));
    assertThat(study.getTitle(), is("title"));
    assertThat(study.getExternalId(), is("some:id"));
}
Also used : Study(org.eol.globi.domain.Study) ObjectNode(org.codehaus.jackson.node.ObjectNode) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 25 with DatasetImpl

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

the class StudyImporterForTSVTest method importMinimal.

@Test
public void importMinimal() throws StudyImporterException {
    String minimalLines = "sourceTaxonId\tsourceTaxonName\tinteractionTypeId\tinteractionTypeName\ttargetTaxonId\ttargetTaxonName\tlocalityId\tlocalityName\tdecimalLatitude\tdecimalLongitude\tobservationDateTime\treferenceDoi\treferenceCitation\n" + "EOL:123\t\tRO:0002444\t\tEOL:111\t\t\t\t\t\t\t\tGittenberger, A., Gittenberger, E. (2011). Cryptic, adaptive radiation of endoparasitic snails: sibling species of Leptoconchus (Gastropoda: Coralliophilidae) in corals. Org Divers Evol, 11(1), 21–41. doi:10.1007/s13127-011-0039-1\n" + "EOL:456\t\tRO:0002444\t\tEOL:222\t\t\t\t\t\t\t\tGittenberger, A., Gittenberger, E. (2011). Cryptic, adaptive radiation of endoparasitic snails: sibling species of Leptoconchus (Gastropoda: Coralliophilidae) in corals. Org Divers Evol, 11(1), 21–41. doi:10.1007/s13127-011-0039-1\n" + "EOL:678\t\tRO:0002444\t\tEOL:333\t\t\t\t\t\t\t\tGittenberger, A., Gittenberger, E. (2011). Cryptic, adaptive radiation of endoparasitic snails: sibling species of Leptoconchus (Gastropoda: Coralliophilidae) in corals. Org Divers Evol, 11(1), 21–41. doi:10.1007/s13127-011-0039-1\n" + "EOL:912\t\tRO:0002444\t\tEOL:444\t\t\t\t\t\t\t\tGittenberger, A., Gittenberger, E. (2011). Cryptic, adaptive radiation of endoparasitic snails: sibling species of Leptoconchus (Gastropoda: Coralliophilidae) in corals. Org Divers Evol, 11(1), 21–41. doi:10.1007/s13127-011-0039-1\n";
    StudyImporterForTSV importer = new StudyImporterForTSV(new TestParserFactory(minimalLines), nodeFactory);
    importer.setDataset(new DatasetImpl("someRepo", URI.create("http://example.com")));
    importStudy(importer);
    Taxon taxon = taxonIndex.findTaxonById("EOL:123");
    assertThat(taxon, is(notNullValue()));
    assertThat(taxon.getName(), is("no name"));
    assertThat(taxon.getExternalId(), is("EOL:123"));
    assertStudyTitles("someRepoGittenberger, A., Gittenberger, E. (2011). Cryptic, adaptive radiation of endoparasitic snails: sibling species of Leptoconchus (Gastropoda: Coralliophilidae) in corals. Org Divers Evol, 11(1), 21–41. doi:10.1007/s13127-011-0039-1");
}
Also used : Taxon(org.eol.globi.domain.Taxon) DatasetImpl(org.eol.globi.service.DatasetImpl) Test(org.junit.Test)

Aggregations

DatasetImpl (org.eol.globi.service.DatasetImpl)45 Test (org.junit.Test)31 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)24 JsonNode (org.codehaus.jackson.JsonNode)16 Study (org.eol.globi.domain.Study)13 Relationship (org.neo4j.graphdb.Relationship)9 ArrayList (java.util.ArrayList)6 ObjectNode (org.codehaus.jackson.node.ObjectNode)6 StudyImpl (org.eol.globi.domain.StudyImpl)6 Dataset (org.eol.globi.service.Dataset)6 Node (org.neo4j.graphdb.Node)5 InputStream (java.io.InputStream)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)4 NodeFactoryWithDatasetContext (org.eol.globi.data.NodeFactoryWithDatasetContext)3 LogContext (org.eol.globi.domain.LogContext)3 Specimen (org.eol.globi.domain.Specimen)3 Taxon (org.eol.globi.domain.Taxon)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2