Search in sources :

Example 81 with Study

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

the class StudyImporterForSimonsTest method createAndPopulateStudy.

@Test
public void createAndPopulateStudy() throws StudyImporterException {
    String csvString = "\"Obs\",\"spcode\", \"sizecl\", \"cruise\", \"stcode\", \"numstom\", \"numfood\", \"pctfull\", \"predator famcode\", \"prey\", \"number\", \"season\", \"depth\", \"transect\", \"alphcode\", \"taxord\", \"station\", \"long\", \"lat\", \"time\", \"sizeclass\", \"predator\"\n";
    csvString += "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
    csvString += "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca agassizi\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
    csvString += "2, 11, 2, 1, 1, 20, 15, 592.5, 6, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 20, \"Chandeleur Islands\", \"aabd\", 47.11, \"C1\", 344445.31, 3323087.25, 144, \"26-50\", \"Halieutichthys aculeatus\"\n";
    StudyImporterForSimons importer = new StudyImporterForSimons(new TestParserFactory(csvString), nodeFactory);
    importStudy(importer);
    assertNotNull(taxonIndex.findTaxonByName("Rhynchoconger flavus"));
    assertNotNull(taxonIndex.findTaxonByName("Halieutichthys aculeatus"));
    assertNotNull(taxonIndex.findTaxonByName("Ampelisca sp. (abdita complex)"));
    assertNotNull(nodeFactory.findStudy("Simons 1997"));
    assertNotNull(nodeFactory.findLocation(new LocationImpl(LAT_1, LONG_1, -60.0d, null)));
    assertNotNull(nodeFactory.findLocation(new LocationImpl(LAT_2, LONG_2, -20.0d, null)));
    assertNotNull(nodeFactory.findSeason("summer"));
    Study foundStudy = nodeFactory.findStudy("Simons 1997");
    assertNotNull(foundStudy);
    for (Relationship rel : NodeUtil.getSpecimens(foundStudy)) {
        Node specimen = rel.getEndNode();
        Node speciesNode = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
        String scientificName = (String) speciesNode.getProperty("name");
        if ("Rhynchoconger flavus".equals(scientificName)) {
            String seasonName = "summer";
            String genusName = "Ampelisca sp. (abdita complex)";
            double length = (201.0d + 300.0d) / 2.0d;
            assertSpecimen(specimen, LONG_1, LAT_1, -60.0, seasonName, genusName, length);
            Iterable<Relationship> ateRelationships = specimen.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
            List<String> preyNames = new ArrayList<String>();
            for (Relationship ateRel : ateRelationships) {
                Node preyTaxonNode = ateRel.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS)).iterator().next().getEndNode();
                preyNames.add(preyTaxonNode.getProperty(PropertyAndValueDictionary.NAME).toString());
            }
            assertThat(preyNames, hasItem("Ampelisca sp. (abdita complex)"));
            assertThat(preyNames.contains("Ampelisca agassizi"), Is.is(true));
            assertThat(preyNames.size(), Is.is(2));
        } else if ("Halieutichthys aculeatus".equals(scientificName)) {
            String genusName = "Ampelisca sp. (abdita complex)";
            String seasonName = "summer";
            double length = (26.0d + 50.0d) / 2.0d;
            assertSpecimen(specimen, LONG_2, LAT_2, -20.0, seasonName, genusName, length);
        } else if ("Ampelisca sp. (abdita complex)".equals(scientificName)) {
            Node locationNode = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING).getEndNode();
            assertNotNull(locationNode);
            assertTrue(locationNode.hasProperty(LocationConstant.LONGITUDE));
            assertTrue(locationNode.hasProperty(LocationConstant.ALTITUDE));
            assertTrue(locationNode.hasProperty(LocationConstant.LATITUDE));
        } else if ("Ampelisca agassizi".equals(scientificName)) {
            assertPreySpecimen(specimen, LONG_1, LAT_1, -60.0);
        } else {
            fail("found predator with unexpected scientificName [" + scientificName + "]");
        }
    }
}
Also used : Study(org.eol.globi.domain.Study) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) LocationImpl(org.eol.globi.domain.LocationImpl) Test(org.junit.Test)

Example 82 with Study

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

the class StudyImporterForTSVTest method assertStudyTitles.

public void assertStudyTitles(String element) {
    final List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    final List<String> titles = new ArrayList<String>();
    for (Study study : allStudies) {
        titles.add(study.getTitle());
    }
    assertThat(titles, hasItem(element));
}
Also used : Study(org.eol.globi.domain.Study) ArrayList(java.util.ArrayList)

Example 83 with Study

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

the class StudyImporterForStronaIT method importFirst200.

@Test
public void importFirst200() throws NodeFactoryException, StudyImporterException {
    StudyImporter importer = new StudyImporterForStrona(new ParserFactoryLocal(), nodeFactory);
    importer.setFilter(new ImportFilter() {

        @Override
        public boolean shouldImportRecord(Long recordNumber) {
            return recordNumber < 200;
        }
    });
    importStudy(importer);
    List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(allStudies.size(), is(1));
    assertThat(taxonIndex.findTaxonByName("Aidablennius sphynx"), is(notNullValue()));
    assertThat(taxonIndex.findTaxonByName("Acanthocephaloides incrassatus"), is(notNullValue()));
    Study study = allStudies.get(0);
    assertThat(study.getSource(), containsString(" Accessed at"));
    assertThat(study.getCitation(), containsString("http://dx.doi.org/10.1890/12-1419.1"));
    assertThat(study.getCitation(), containsString("Strona"));
}
Also used : Study(org.eol.globi.domain.Study) Test(org.junit.Test)

Example 84 with Study

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

the class NormalizerTest method doSingleImport.

@Test
public void doSingleImport() throws IOException, StudyImporterException {
    importData(StudyImporterForSimons.class, new NodeFactoryNeo4j(getGraphDb()));
    GraphDatabaseService graphService = getGraphDb();
    Study study = getStudySingleton(graphService);
    assertThat(study.getTitle(), is("Simons 1997"));
    assertNotNull(graphService.getNodeById(1));
    assertNotNull(graphService.getNodeById(200));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Study(org.eol.globi.domain.Study) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) Test(org.junit.Test)

Example 85 with Study

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

the class StudyImporterForCruaud method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    LabeledCSVParser dataParser;
    try {
        dataParser = parserFactory.createParser(RESOURCE_PATH, CharsetConstant.UTF8);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource [" + RESOURCE_PATH + "]", e);
    }
    try {
        Study study = nodeFactory.getOrCreateStudy(new StudyImpl("cruaud", SOURCE, "http://dx.doi.org/10.1093/sysbio/sys068", null));
        while (dataParser.getLine() != null) {
            if (importFilter.shouldImportRecord((long) dataParser.getLastLineNumber())) {
                try {
                    String parasiteName = StringUtils.trim(dataParser.getValueByLabel("Family and Species"));
                    String hostName = StringUtils.trim(dataParser.getValueByLabel("Natural host Ficus species"));
                    hostName = StringUtils.replace(hostName, "F.", "Ficus");
                    if (areNamesAvailable(parasiteName, hostName)) {
                        Specimen parasite = nodeFactory.createSpecimen(study, new TaxonImpl(parasiteName, null));
                        Specimen host = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
                        parasite.interactsWith(host, InteractType.PARASITE_OF);
                        String samplingLocation = StringUtils.trim(dataParser.getValueByLabel("Sampling location"));
                        if (getGeoNamesService().hasTermForLocale(samplingLocation)) {
                            LatLng pointForLocality = getGeoNamesService().findLatLng(samplingLocation);
                            if (pointForLocality == null) {
                                LOG.warn("no location associated with locality [" + samplingLocation + "]");
                            } else {
                                Location location = nodeFactory.getOrCreateLocation(new LocationImpl(pointForLocality.getLat(), pointForLocality.getLng(), null, null));
                                parasite.caughtIn(location);
                                host.caughtIn(location);
                            }
                        } else {
                            LOG.warn("no location associated with locality [" + samplingLocation + "]");
                        }
                    }
                } catch (NodeFactoryException | NumberFormatException e) {
                    throw new StudyImporterException("failed to import line [" + (dataParser.lastLineNumber() + 1) + "]", e);
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("problem importing [" + RESOURCE_PATH + "]", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Specimen(org.eol.globi.domain.Specimen) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) Location(org.eol.globi.domain.Location)

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