Search in sources :

Example 11 with Location

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

the class StudyImporterForHechinger method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    Study study = createStudy();
    try {
        LabeledCSVParser nodes = parserFactory.createParser(getNodesResourceName(), CharsetConstant.UTF8);
        nodes.changeDelimiter(getDelimiter());
        Map<Integer, Term> stageForNode = new HashMap<>();
        Map<Integer, String> taxonForNode = new HashMap<Integer, String>();
        while (nodes.getLine() != null) {
            Integer nodeId = getNodeId(nodes);
            if (nodeId != null) {
                String name = parseMostGranularTaxonName(nodes);
                if (StringUtils.isBlank(name)) {
                    name = nodes.getValueByLabel("WorkingName");
                    if (StringUtils.isBlank(name)) {
                        getLogger().warn(study, "failed to find name for node on line [" + nodes.lastLineNumber() + "]");
                    }
                }
                if (StringUtils.isNotBlank(name)) {
                    try {
                        taxonForNode.put(nodeId, name);
                        String stage = nodes.getValueByLabel("Stage");
                        stageForNode.put(nodeId, nodeFactory.getOrCreateLifeStage(getNamespace() + ":" + stage, stage));
                    } catch (NodeFactoryException e) {
                        throw new StudyImporterException("failed to reader line [" + nodes.lastLineNumber() + "]", e);
                    }
                }
            }
        }
        LabeledCSVParser links = parserFactory.createParser(getLinksResourceName(), CharsetConstant.UTF8);
        links.changeDelimiter(getDelimiter());
        while (links.getLine() != null) {
            List<Location> locations = new ArrayList<>();
            if (getLocation() != null) {
                Location loc = nodeFactory.getOrCreateLocation(new LocationImpl(getLocation().getLat(), getLocation().getLng(), null, null));
                if (loc != null) {
                    locations.add(loc);
                }
            }
            if (StringUtils.equals("1", links.getValueByLabel("PresentAtCSM"))) {
                locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(34.403511, -119.537873, null, null)));
            }
            if (StringUtils.equals("1", links.getValueByLabel("PresentAtEPB"))) {
                locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(31.748606, -116.626854, null, null)));
            }
            if (StringUtils.equals("1", links.getValueByLabel("PresentAtBSQ"))) {
                locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(30.378207, -115.938835, null, null)));
            }
            for (Location location : locations) {
                addLink(study, stageForNode, taxonForNode, links, location);
            }
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("failed import study", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Term(org.eol.globi.domain.Term) IOException(java.io.IOException) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 12 with Location

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

the class StudyImporterForGoMexSI2 method addObservations.

private void addObservations(Map<String, Map<String, String>> predatorIdToPredatorSpecimen, Map<String, Study> refIdToStudyMap, Map<String, List<Map<String, String>>> predatorUIToPreyLists, Study metaStudy) throws StudyImporterException {
    String locationResource = getLocationsResourcePath();
    try {
        TermLookupService cmecsService = new CMECSService();
        LabeledCSVParser parser = parserFactory.createParser(locationResource, CharsetConstant.UTF8);
        while (parser.getLine() != null) {
            String refId = getMandatoryValue(locationResource, parser, "DATA_ID");
            if (!refIdToStudyMap.containsKey(refId)) {
                getLogger().warn(metaStudy, "failed to find study for ref id [" + refId + "] on related to observation location in [" + locationResource + ":" + parser.getLastLineNumber() + "]");
            } else {
                Study study = refIdToStudyMap.get(refId);
                String specimenId = getMandatoryValue(locationResource, parser, "PRED_ID");
                Location location = parseLocation(locationResource, parser);
                Location locationNode = nodeFactory.getOrCreateLocation(location);
                enrichLocation(metaStudy, locationResource, cmecsService, parser, locationNode);
                String predatorId = refId + specimenId;
                Map<String, String> predatorProperties = predatorIdToPredatorSpecimen.get(predatorId);
                if (predatorProperties == null) {
                    getLogger().warn(study, "failed to lookup predator [" + refId + ":" + specimenId + "] for location at [" + locationResource + ":" + (parser.getLastLineNumber() + 1) + "]");
                } else {
                    addObservation(predatorUIToPreyLists, parser, study, locationNode, predatorId, predatorProperties);
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to open resource [" + locationResource + "]", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TermLookupService(org.eol.globi.service.TermLookupService) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Location(org.eol.globi.domain.Location)

Example 13 with Location

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

the class StudyImporterForINaturalist method createAssociation.

private Specimen createAssociation(long observationId, String interactionDataType, InteractType interactType, JsonNode observation, Taxon targetTaxon, Taxon sourceTaxonName, Study study, Date observationDate) throws StudyImporterException, NodeFactoryException {
    Specimen sourceSpecimen = getSourceSpecimen(observationId, interactionDataType, sourceTaxonName, study);
    setBasisOfRecord(sourceSpecimen);
    Specimen targetSpecimen = nodeFactory.createSpecimen(study, targetTaxon);
    setBasisOfRecord(targetSpecimen);
    sourceSpecimen.interactsWith(targetSpecimen, interactType);
    setCollectionDate(sourceSpecimen, targetSpecimen, observationDate);
    setCollectionDate(sourceSpecimen, sourceSpecimen, observationDate);
    Location location = parseLocation(observation);
    sourceSpecimen.caughtIn(location);
    targetSpecimen.caughtIn(location);
    return sourceSpecimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen) Location(org.eol.globi.domain.Location)

Example 14 with Location

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

the class ExporterOccurrencesTest method createTestData.

private void createTestData(Double length) throws NodeFactoryException, ParseException {
    Study myStudy = nodeFactory.createStudy(new StudyImpl("myStudy", null, null, null));
    Specimen specimen = nodeFactory.createSpecimen(myStudy, new TaxonImpl("Homo sapiens", "EOL:327955"));
    specimen.setStomachVolumeInMilliLiter(666.0);
    specimen.setLifeStage(new TermImpl("GLOBI:JUVENILE", "JUVENILE"));
    specimen.setPhysiologicalState(new TermImpl("GLOBI:DIGESTATE", "DIGESTATE"));
    specimen.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
    nodeFactory.setUnixEpochProperty(specimen, ExportTestUtil.utcTestDate());
    if (null != length) {
        specimen.setLengthInMm(length);
    }
    Location location = nodeFactory.getOrCreateLocation(new LocationImpl(12.0, -1.0, -60.0, null));
    specimen.caughtIn(location);
    Specimen wolf1 = eatWolf(specimen, myStudy);
    wolf1.caughtIn(location);
    Specimen wolf2 = eatWolf(specimen, myStudy);
    wolf2.caughtIn(location);
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LocationImpl(org.eol.globi.domain.LocationImpl) TermImpl(org.eol.globi.domain.TermImpl) Location(org.eol.globi.domain.Location)

Example 15 with Location

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

the class StudyImporterForCook method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    LabeledCSVParser parser;
    try {
        parser = parserFactory.createParser(DATASET_RESOURCE_NAME, CharsetConstant.UTF8);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource", e);
    }
    String citation = "Cook CW. The Early Life History and Reproductive Biology of Cymothoa excisa, a Marine Isopod Parasitizing Atlantic Croaker, (Micropogonias undulatus), along the Texas Coast. 2012. Master Thesis. Available from http://repositories.lib.utexas.edu/handle/2152/ETD-UT-2012-08-6285.";
    StudyImpl study1 = new StudyImpl("Cook 2012", "Data provided by Colt W. Cook. Also available from  http://repositories.lib.utexas.edu/handle/2152/ETD-UT-2012-08-6285.", null, citation);
    study1.setExternalId("http://repositories.lib.utexas.edu/handle/2152/ETD-UT-2012-08-6285");
    Study study = nodeFactory.getOrCreateStudy(study1);
    try {
        Double latitude = LocationUtil.parseDegrees("27º51'N");
        Double longitude = LocationUtil.parseDegrees("97º8'W");
        Location sampleLocation = nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, -3.0, null));
        try {
            while (parser.getLine() != null) {
                Specimen host = nodeFactory.createSpecimen(study, new TaxonImpl("Micropogonias undulatus", null));
                host.setLengthInMm(Double.parseDouble(parser.getValueByLabel("Fish Length")) * 10.0);
                String dateString = parser.getValueByLabel("Date");
                Date collectionDate = DateUtil.parsePatternUTC(dateString, "MM/dd/yyyy").toDate();
                nodeFactory.setUnixEpochProperty(host, collectionDate);
                host.caughtIn(sampleLocation);
                String[] isoCols = { "Iso 1", "Iso 2", "Iso 3", "Iso 4 ", "Iso 5" };
                for (String isoCol : isoCols) {
                    addParasites(parser, study, sampleLocation, host, collectionDate, isoCol);
                }
            }
        } catch (IOException e) {
            throw new StudyImporterException("failed to parse [" + DATASET_RESOURCE_NAME + "]", e);
        } catch (IllegalArgumentException e) {
            throw new StudyImporterException("failed to parse date", e);
        }
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create host and parasite taxons", 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) Date(java.util.Date) Specimen(org.eol.globi.domain.Specimen) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Aggregations

Location (org.eol.globi.domain.Location)44 LocationImpl (org.eol.globi.domain.LocationImpl)32 Specimen (org.eol.globi.domain.Specimen)31 Study (org.eol.globi.domain.Study)24 StudyImpl (org.eol.globi.domain.StudyImpl)16 TaxonImpl (org.eol.globi.domain.TaxonImpl)16 Date (java.util.Date)14 IOException (java.io.IOException)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 HashMap (java.util.HashMap)8 LatLng (org.eol.globi.geo.LatLng)8 TermImpl (org.eol.globi.domain.TermImpl)6 Test (org.junit.Test)6 Relationship (org.neo4j.graphdb.Relationship)6 SpecimenNode (org.eol.globi.domain.SpecimenNode)5 ArrayList (java.util.ArrayList)4 Taxon (org.eol.globi.domain.Taxon)4 Node (org.neo4j.graphdb.Node)3 List (java.util.List)2 Map (java.util.Map)2