Search in sources :

Example 66 with Study

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

the class StudyImporterForSeltmannIT method importArchive.

protected void importArchive(String archiveName) throws StudyImporterException {
    StudyImporterForSeltmann importer = new StudyImporterForSeltmann(null, nodeFactory);
    importer.setDataset(new DatasetImpl(null, URI.create(ARCHIVE_URI_PREFIX + archiveName)));
    importStudy(importer);
    List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    for (Study allStudy : allStudies) {
        assertThat(allStudy.getSource(), startsWith("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        assertThat(allStudy.getCitation(), is("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        Iterable<Relationship> specimens = NodeUtil.getSpecimens(allStudy);
        for (Relationship specimen : specimens) {
            Specimen spec = new SpecimenNode(specimen.getEndNode());
            Term basisOfRecord = spec.getBasisOfRecord();
            assertThat(basisOfRecord.getId(), either(is("TEST:PreservedSpecimen")).or(is("TEST:LabelObservation")));
            assertThat(basisOfRecord.getName(), either(is("PreservedSpecimen")).or(is("LabelObservation")));
        }
    }
    assertThat(taxonIndex.findTaxonByName("Megandrena mentzeliae"), is(notNullValue()));
    assertThat(taxonIndex.findTaxonByName("Mentzelia tricuspis"), is(notNullValue()));
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) DatasetImpl(org.eol.globi.service.DatasetImpl) Term(org.eol.globi.domain.Term) SpecimenNode(org.eol.globi.domain.SpecimenNode)

Example 67 with Study

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

the class StudyImporterForSeltmannTest method importSome.

@Test
public void importSome() throws StudyImporterException, IOException {
    StudyImporterForSeltmann importer = new StudyImporterForSeltmann(null, nodeFactory);
    Dataset dataset = new DatasetLocal();
    JsonNode config = new ObjectMapper().readTree("{\"citation\": \"some citation\", \"resources\": {\"archive\": \"seltmann/testArchive.zip\"}}");
    dataset.setConfig(config);
    importer.setDataset(dataset);
    importStudy(importer);
    List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    for (Study allStudy : allStudies) {
        assertThat(allStudy.getSource(), startsWith("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        assertThat(allStudy.getCitation(), is("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        Iterable<Relationship> specimens = NodeUtil.getSpecimens(allStudy);
        for (Relationship specimen : specimens) {
            SpecimenNode spec = new SpecimenNode(specimen.getEndNode());
            final String recordId = (String) spec.getUnderlyingNode().getProperty("idigbio:recordID");
            assertThat(recordId, is(notNullValue()));
            assertThat(spec.getExternalId(), is(recordId));
            Term basisOfRecord = spec.getBasisOfRecord();
            assertThat(basisOfRecord.getId(), either(is("TEST:PreservedSpecimen")).or(is("TEST:LabelObservation")));
            assertThat(basisOfRecord.getName(), either(is("PreservedSpecimen")).or(is("LabelObservation")));
        }
    }
    assertThat(taxonIndex.findTaxonByName("Megandrena mentzeliae"), is(notNullValue()));
    assertThat(taxonIndex.findTaxonByName("Mentzelia tricuspis"), is(notNullValue()));
}
Also used : Study(org.eol.globi.domain.Study) Dataset(org.eol.globi.service.Dataset) Relationship(org.neo4j.graphdb.Relationship) JsonNode(org.codehaus.jackson.JsonNode) Term(org.eol.globi.domain.Term) SpecimenNode(org.eol.globi.domain.SpecimenNode) DatasetLocal(org.eol.globi.service.DatasetLocal) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 68 with Study

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

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

use of org.eol.globi.domain.Study 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)

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