Search in sources :

Example 46 with Specimen

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

the class StudyImporterForBaremore method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    Study study;
    try {
        LabeledCSVParser parser = parserFactory.createParser(DATA_SOURCE, CharsetConstant.UTF8);
        String[] line;
        study = nodeFactory.getOrCreateStudy(new StudyImpl("Baremore 2010", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, "doi:10.3354/ab00214", ExternalIdUtil.toCitation("Ivy E. Baremore", "Prey Selection By The Atlantic Angel Shark Squatina Dumeril In The Northeastern Gulf Of Mexico.", "2010")));
        Location collectionLocation = nodeFactory.getOrCreateLocation(new LocationImpl(29.219302, -87.06665, null, null));
        Map<Integer, Specimen> specimenMap = new HashMap<Integer, Specimen>();
        while ((line = parser.getLine()) != null) {
            Integer sharkId = Integer.parseInt(line[0]);
            String collectionDateString = line[1];
            if (isBlank(collectionDateString)) {
                getLogger().warn(study, "line [" + parser.getLastLineNumber() + "] in [" + DATA_SOURCE + "]: missing collection date");
            } else {
                Specimen predatorSpecimen = specimenMap.get(sharkId);
                if (predatorSpecimen == null) {
                    predatorSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Squatina dumeril", null));
                    predatorSpecimen.caughtIn(collectionLocation);
                    addLifeStage(parser, predatorSpecimen);
                    addCollectionDate(collectionDateString, predatorSpecimen);
                }
                specimenMap.put(sharkId, predatorSpecimen);
                String totalLengthInCm = line[3];
                try {
                    Double lengthInMm = Double.parseDouble(totalLengthInCm) * 10.0;
                    predatorSpecimen.setLengthInMm(lengthInMm);
                } catch (NumberFormatException ex) {
                    throw new StudyImporterException("failed to parse length [" + totalLengthInCm);
                }
                String preySpeciesDescription = line[7];
                if (StringUtils.isBlank(preySpeciesDescription)) {
                    getLogger().info(study, "found blank prey species description [" + preySpeciesDescription + "] on line [" + parser.lastLineNumber() + "]");
                } else {
                    Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(preySpeciesDescription, null));
                    preySpecimen.caughtIn(collectionLocation);
                    predatorSpecimen.ate(preySpecimen);
                    nodeFactory.setUnixEpochProperty(preySpecimen, nodeFactory.getUnixEpochProperty(predatorSpecimen));
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to parse labels", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) HashMap(java.util.HashMap) 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) Location(org.eol.globi.domain.Location)

Example 47 with Specimen

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

the class StudyImporterForAkin method addPrey.

private void addPrey(Study study, LabeledCSVParser parser, String[] header, String[] line, Specimen specimen, Location location) throws StudyImporterException {
    int firstPreyIndex = findIndexForColumnWithNameThrowOnMissing("Detritus", header);
    for (int i = firstPreyIndex; i < line.length; i++) {
        String preySpeciesName = header[i];
        if (StringUtils.isNotBlank(preySpeciesName)) {
            String preyVolumeString = line[i];
            try {
                if (StringUtils.isNotBlank(preyVolumeString)) {
                    double volume = Double.parseDouble(preyVolumeString);
                    if (volume > 0) {
                        Specimen prey = nodeFactory.createSpecimen(study, new TaxonImpl(preySpeciesName, null));
                        prey.setLifeStage(parseLifeStage(nodeFactory.getTermLookupService(), preySpeciesName));
                        prey.setVolumeInMilliLiter(volume);
                        prey.caughtIn(location);
                        specimen.ate(prey);
                    }
                }
            } catch (NumberFormatException ex) {
                throw new StudyImporterException("failed to parse volume of prey [" + preySpeciesName + "] in stomach [" + preyVolumeString + "] on line [" + parser.getLastLineNumber() + "]");
            } catch (TermLookupServiceException e) {
                throw new StudyImporterException("failed to parse life stage of prey [" + preySpeciesName + "] in stomach [" + preyVolumeString + "] on line [" + parser.getLastLineNumber() + "]");
            }
        }
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 48 with Specimen

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

the class StudyImporterForBlewett method parsePredatorPreyInteraction.

private void parsePredatorPreyInteraction(Study study, Map<String, Location> locationMap, Map<String, Date> collectionTimeMap) throws IOException, NodeFactoryException, TermLookupServiceException {
    LabeledCSVParser parser = parserFactory.createParser("blewett/SnookDietData2000_02_Charlotte_Harbor_FL_Blewett_numeric_abundance.csv", CharsetConstant.UTF8);
    String[] header = parser.getLabels();
    String[] line;
    while ((line = parser.getLine()) != null) {
        if (line.length < 2) {
            break;
        }
        Specimen predatorSpecimen = addPredator(study, parser, line);
        List<Specimen> specimen = addPreyForPredator(header, line, study);
        for (Specimen prey : specimen) {
            predatorSpecimen.ate(prey);
        }
        String collectionCode = parser.getValueByLabel(COLLECTION_NO);
        if (collectionCode != null) {
            specimen.add(predatorSpecimen);
            setLocationAndDate(locationMap, collectionTimeMap, specimen, collectionCode);
        }
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser)

Example 49 with Specimen

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

the class StudyImporterForBarnes method addInteractionForPredator.

private void addInteractionForPredator(LabeledCSVParser parser, Study localStudy, String predatorName) throws NodeFactoryException, StudyImporterException {
    Specimen predator = nodeFactory.createSpecimen(localStudy, new TaxonImpl(predatorName, null));
    addLifeStage(parser, predator);
    Double latitude = LocationUtil.parseDegrees(parser.getValueByLabel("Latitude"));
    Double longitude = LocationUtil.parseDegrees(parser.getValueByLabel("Longitude"));
    String depth = parser.getValueByLabel("Depth");
    Double altitudeInMeters = -1.0 * Double.parseDouble(depth);
    Location location = nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, altitudeInMeters, null));
    predator.caughtIn(location);
    String preyName = parser.getValueByLabel("Prey");
    if (StringUtils.isBlank(preyName)) {
        getLogger().warn(localStudy, "found empty prey name on line [" + parser.lastLineNumber() + "]");
    } else {
        Specimen prey = nodeFactory.createSpecimen(localStudy, new TaxonImpl(preyName, null));
        prey.caughtIn(location);
        predator.ate(prey);
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 50 with Specimen

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

the class StudyImporterForBioInfo method importInteraction.

private void importInteraction(LabeledCSVParser parser, Study study, InteractType interactType, Map<String, Taxon> taxonMap) throws StudyImporterException {
    String passiveId = parser.getValueByLabel("passive NBN Code");
    String activeId = parser.getValueByLabel("active NBN Code");
    Specimen donorSpecimen = createSpecimen(parser, study, taxonMap, passiveId, parser.getValueByLabel("my passive taxon id"));
    Specimen recipientSpecimen = createSpecimen(parser, study, taxonMap, activeId, parser.getValueByLabel("my active taxon id"));
    if (donorSpecimen != null && recipientSpecimen != null) {
        addLifeStage(parser, donorSpecimen, "stage of passive taxon", study);
        addBodyPart(parser, donorSpecimen, "part of passive taxon", study);
        addLifeStage(parser, recipientSpecimen, "stage of active taxon", study);
        addBodyPart(parser, donorSpecimen, "part of active taxon", study);
        recipientSpecimen.interactsWith(donorSpecimen, interactType);
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen)

Aggregations

Specimen (org.eol.globi.domain.Specimen)91 TaxonImpl (org.eol.globi.domain.TaxonImpl)59 Study (org.eol.globi.domain.Study)38 StudyImpl (org.eol.globi.domain.StudyImpl)34 Location (org.eol.globi.domain.Location)31 LocationImpl (org.eol.globi.domain.LocationImpl)22 Test (org.junit.Test)17 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)15 IOException (java.io.IOException)15 Date (java.util.Date)14 Relationship (org.neo4j.graphdb.Relationship)12 HashMap (java.util.HashMap)11 Taxon (org.eol.globi.domain.Taxon)11 SpecimenNode (org.eol.globi.domain.SpecimenNode)9 TermImpl (org.eol.globi.domain.TermImpl)9 ArrayList (java.util.ArrayList)8 InteractType (org.eol.globi.domain.InteractType)7 LatLng (org.eol.globi.geo.LatLng)6 Map (java.util.Map)5 TaxonNode (org.eol.globi.domain.TaxonNode)5