Search in sources :

Example 1 with TaxonImpl

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

the class StudyImporterForINaturalist method parseTaxon.

static Taxon parseTaxon(JsonNode taxonNode) {
    String name = null;
    String externalId = null;
    JsonNode nameNode = taxonNode.get("name");
    if (nameNode != null && !nameNode.isNull()) {
        name = nameNode.asText();
    }
    JsonNode idNode = taxonNode.get("id");
    if (null != idNode) {
        externalId = TaxonomyProvider.INATURALIST_TAXON.getIdPrefix() + idNode.asText();
    }
    return (name == null && externalId == null) ? null : new TaxonImpl(name, externalId);
}
Also used : TaxonImpl(org.eol.globi.domain.TaxonImpl) JsonNode(org.codehaus.jackson.JsonNode)

Example 2 with TaxonImpl

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

the class StudyImporterForKelpForest method createSpecimen.

protected Specimen createSpecimen(LabeledCSVParser parser, Map<String, Long> nameToId, String nameLabel, String stageLabel, Study study) throws NodeFactoryException {
    String sourceName = parser.getValueByLabel(nameLabel);
    Long id = nameToId.get(sourceName);
    String taxonExternalId = id == null ? null : TaxonomyProvider.ID_PREFIX_ITIS + id;
    Specimen sourceSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(sourceName, taxonExternalId));
    String sourceLifeStage = parser.getValueByLabel(stageLabel);
    Term orCreateLifeStage = nodeFactory.getOrCreateLifeStage("KELP:" + sourceLifeStage, sourceLifeStage);
    sourceSpecimen.setLifeStage(orCreateLifeStage);
    return sourceSpecimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.eol.globi.domain.Term)

Example 3 with TaxonImpl

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

the class StudyImporterForRobledo method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    String description = "García-Robledo C, Erickson DL, Staines CL, Erwin TL, Kress WJ. Tropical Plant–Herbivore Networks: Reconstructing Species Interactions Using DNA Barcodes Heil M, editor. PLoS ONE [Internet]. 2013 January 8;8(1):e52967. Available from: http://dx.doi.org/10.1371/journal.pone.0052967";
    String doi = "http://dx.doi.org/10.1371/journal.pone.0052967";
    Study study1 = new StudyImpl("García-Robledo et al 2013", description, doi, description);
    Study study = nodeFactory.getOrCreateStudy(study1);
    Map<String, String> abrLookup = buildPlantLookup();
    // spatial location from: http://www.ots.ac.cr/index.php?option=com_content&task=view&id=163&Itemid=348
    Double latitude = LocationUtil.parseDegrees("10°26'N");
    Double longitude = LocationUtil.parseDegrees("83°59'W");
    Location location;
    try {
        location = nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, 35.0, null));
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create location", e);
    }
    // TODO: need to map date range of collections
    String studyResource = "robledo/table_s1_extract.csv";
    try {
        LabeledCSVParser parser = parserFactory.createParser(studyResource, CharsetConstant.UTF8);
        while (parser.getLine() != null) {
            String beetleName = parser.getValueByLabel("Herbivore species");
            String beetleScientificName = completeBeetleName(beetleName);
            Specimen predator = nodeFactory.createSpecimen(study, new TaxonImpl(beetleScientificName, null));
            predator.caughtIn(location);
            for (String plantAbbreviation : abrLookup.keySet()) {
                String plantScientificName = abrLookup.get(plantAbbreviation);
                String valueByLabel = parser.getValueByLabel(plantAbbreviation);
                try {
                    int interactionCode = Integer.parseInt(valueByLabel);
                    if (interactionCode > 0) {
                        Specimen plant = nodeFactory.createSpecimen(study, new TaxonImpl(plantScientificName, null));
                        plant.caughtIn(location);
                        predator.ate(plant);
                    }
                } catch (NumberFormatException ex) {
                    getLogger().warn(study, "malformed or no value [" + valueByLabel + "] found for [" + plantScientificName + "(" + plantAbbreviation + ")" + "] and beetle [" + beetleScientificName + "] could be found in [" + studyResource + ":" + parser.lastLineNumber() + "]");
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("problem reading [" + studyResource + "]", e);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("cannot create specimens from [" + studyResource + "]", 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) Location(org.eol.globi.domain.Location)

Example 4 with TaxonImpl

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

the class StudyImporterForRaymond method getSpecimen.

private Specimen getSpecimen(LabeledCSVParser dietParser, String nameLabel, String lifeStageLabel, Study study) throws NodeFactoryException {
    String predatorName = dietParser.getValueByLabel(nameLabel);
    Specimen predator = nodeFactory.createSpecimen(study, new TaxonImpl(predatorName, null));
    String predatorLifeStage = dietParser.getValueByLabel(lifeStageLabel);
    predator.setLifeStage(nodeFactory.getOrCreateLifeStage("RAYMOND:" + predatorLifeStage, predatorLifeStage));
    return predator;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 5 with TaxonImpl

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

the class StudyImporterForSPIRE method createSpecimen.

private Specimen createSpecimen(String taxonName, Study study) throws NodeFactoryException {
    taxonName = taxonName.replaceAll("_", " ");
    Specimen specimen = nodeFactory.createSpecimen(study, new TaxonImpl(taxonName, null));
    if (taxonName.contains("adult")) {
        addLifeStage(specimen, "adult");
    } else if (taxonName.contains("juvenile")) {
        addLifeStage(specimen, "juvenile");
    } else if (taxonName.contains(" egg")) {
        addLifeStage(specimen, "egg");
    } else if (taxonName.contains("larvae")) {
        addLifeStage(specimen, "larvae");
    } else if (taxonName.contains("immature")) {
        addLifeStage(specimen, "immature");
    } else if (taxonName.contains("nymphs")) {
        addLifeStage(specimen, "nymphs");
    }
    return specimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Aggregations

TaxonImpl (org.eol.globi.domain.TaxonImpl)123 Specimen (org.eol.globi.domain.Specimen)59 Test (org.junit.Test)54 Taxon (org.eol.globi.domain.Taxon)42 StudyImpl (org.eol.globi.domain.StudyImpl)34 Study (org.eol.globi.domain.Study)32 Location (org.eol.globi.domain.Location)16 LocationImpl (org.eol.globi.domain.LocationImpl)15 TaxonNode (org.eol.globi.domain.TaxonNode)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 IOException (java.io.IOException)11 TermImpl (org.eol.globi.domain.TermImpl)11 StringWriter (java.io.StringWriter)9 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)7 Map (java.util.Map)5 Node (org.neo4j.graphdb.Node)5 File (java.io.File)4