Search in sources :

Example 16 with Specimen

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

the class InteractionListenerImpl method importValidLink.

private void importValidLink(Map<String, String> link) throws StudyImporterException, IOException {
    Study study = nodeFactory.getOrCreateStudy(studyFromLink(link));
    Specimen source = createSpecimen(link, study, SOURCE_TAXON_NAME, SOURCE_TAXON_ID, SOURCE_BODY_PART_NAME, SOURCE_BODY_PART_ID);
    Specimen target = createSpecimen(link, study, TARGET_TAXON_NAME, TARGET_TAXON_ID, TARGET_BODY_PART_NAME, TARGET_BODY_PART_ID);
    String interactionTypeId = link.get(INTERACTION_TYPE_ID);
    InteractType type = InteractType.typeOf(interactionTypeId);
    source.interactsWith(target, type, getOrCreateLocation(study, link));
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen)

Example 17 with Specimen

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

the class StudyImporterForHurlbert method importInteraction.

protected void importInteraction(Set<String> regions, Set<String> locales, Set<String> habitats, Record record, Study study, String preyTaxonName, String predatorName) throws StudyImporterException {
    try {
        Taxon predatorTaxon = new TaxonImpl(predatorName);
        Specimen predatorSpecimen = nodeFactory.createSpecimen(study, predatorTaxon);
        setBasisOfRecordAsLiterature(predatorSpecimen);
        Taxon preyTaxon = new TaxonImpl(preyTaxonName);
        String preyNameId = StringUtils.trim(columnValueOrNull(record, "Prey_Name_ITIS_ID"));
        if (NumberUtils.isDigits(preyNameId)) {
            preyTaxon.setExternalId(TaxonomyProvider.ITIS.getIdPrefix() + preyNameId);
        }
        Specimen preySpecimen = nodeFactory.createSpecimen(study, preyTaxon);
        setBasisOfRecordAsLiterature(preySpecimen);
        String preyStage = StringUtils.trim(columnValueOrNull(record, "Prey_Stage"));
        if (StringUtils.isNotBlank(preyStage)) {
            Term lifeStage = nodeFactory.getOrCreateLifeStage("HULBERT:" + StringUtils.replace(preyStage, " ", "_"), preyStage);
            preySpecimen.setLifeStage(lifeStage);
        }
        String preyPart = StringUtils.trim(columnValueOrNull(record, "Prey_Part"));
        if (StringUtils.isNotBlank(preyPart)) {
            Term term = nodeFactory.getOrCreateBodyPart("HULBERT:" + StringUtils.replace(preyPart, " ", "_"), preyPart);
            preySpecimen.setBodyPart(term);
        }
        Date date = addCollectionDate(record, study);
        nodeFactory.setUnixEpochProperty(predatorSpecimen, date);
        nodeFactory.setUnixEpochProperty(preySpecimen, date);
        LocationImpl location = new LocationImpl(null, null, null, null);
        String longitude = columnValueOrNull(record, "Longitude_dd");
        String latitude = columnValueOrNull(record, "Latitude_dd");
        if (NumberUtils.isNumber(latitude) && NumberUtils.isNumber(longitude)) {
            try {
                LatLng latLng = LocationUtil.parseLatLng(latitude, longitude);
                String altitude = columnValueOrNull(record, "Altitude_mean_m");
                Double altitudeD = NumberUtils.isNumber(altitude) ? Double.parseDouble(altitude) : null;
                location = new LocationImpl(latLng.getLat(), latLng.getLng(), altitudeD, null);
            } catch (InvalidLocationException e) {
                getLogger().warn(study, "found invalid (lat,lng) pair: (" + latitude + "," + longitude + ")");
            }
        }
        String locationRegion = columnValueOrNull(record, "Location_Region");
        String locationSpecific = columnValueOrNull(record, "Location_Specific");
        location.setLocality(StringUtils.join(Arrays.asList(locationRegion, locationSpecific), ":"));
        Location locationNode = nodeFactory.getOrCreateLocation(location);
        String habitat_type = columnValueOrNull(record, "Habitat_type");
        List<Term> habitatList = Arrays.stream(StringUtils.split(StringUtils.defaultIfBlank(habitat_type, ""), ";")).map(StringUtils::trim).map(habitat -> new TermImpl(idForHabitat(habitat), habitat)).collect(Collectors.toList());
        nodeFactory.addEnvironmentToLocation(locationNode, habitatList);
        preySpecimen.caughtIn(locationNode);
        predatorSpecimen.caughtIn(locationNode);
        predatorSpecimen.ate(preySpecimen);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create interaction between [" + predatorName + "] and [" + preyTaxonName + "]", e);
    }
}
Also used : TsvParser(com.univocity.parsers.tsv.TsvParser) DateUtil(org.eol.globi.util.DateUtil) StringUtils(org.apache.commons.lang.StringUtils) CitationUtil(org.globalbioticinteractions.dataset.CitationUtil) Arrays(java.util.Arrays) Record(com.univocity.parsers.common.record.Record) Term(org.eol.globi.domain.Term) Specimen(org.eol.globi.domain.Specimen) Location(org.eol.globi.domain.Location) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) LocationImpl(org.eol.globi.domain.LocationImpl) HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) Map(java.util.Map) LatLng(org.eol.globi.geo.LatLng) TaxonomyProvider(org.eol.globi.domain.TaxonomyProvider) Taxon(org.eol.globi.domain.Taxon) InvalidLocationException(org.eol.globi.util.InvalidLocationException) DateTime(org.joda.time.DateTime) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TsvParserSettings(com.univocity.parsers.tsv.TsvParserSettings) List(java.util.List) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Study(org.eol.globi.domain.Study) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ArrayUtils(org.apache.commons.lang.ArrayUtils) InputStream(java.io.InputStream) InvalidLocationException(org.eol.globi.util.InvalidLocationException) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.eol.globi.domain.Term) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) Specimen(org.eol.globi.domain.Specimen) StringUtils(org.apache.commons.lang.StringUtils) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) Location(org.eol.globi.domain.Location)

Example 18 with Specimen

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

the class StudyImporterForICES method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    LabeledCSVParser parser = createParser();
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("ICES", "International Council for the Exploration of the Sea. Available at http://www.ices.dk/products/cooperative.asp .", null, "Cooperative Research Report No. 164; Cooperative Research Report No. 219, ICES Stomach DatasetImpl, ICES"));
    study.setExternalId("http://ecosystemdata.ices.dk/stomachdata/");
    try {
        Specimen predator = null;
        String lastStomachId = null;
        while ((parser.getLine()) != null) {
            if (importFilter.shouldImportRecord((long) parser.getLastLineNumber())) {
                Date date = parseDate(parser);
                Location location = parseLocation(parser);
                String currentStomachId = parser.getValueByLabel("ICES StomachID");
                if (lastStomachId == null || !lastStomachId.equals(currentStomachId)) {
                    predator = addPredator(parser, study);
                    nodeFactory.setUnixEpochProperty(predator, date);
                    predator.caughtIn(location);
                }
                Specimen prey = addPrey(parser, predator, study);
                if (prey != null) {
                    nodeFactory.setUnixEpochProperty(prey, date);
                    prey.caughtIn(location);
                }
                lastStomachId = currentStomachId;
            }
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("problem parsing datasource", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Date(java.util.Date) Location(org.eol.globi.domain.Location)

Example 19 with Specimen

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

the class StudyImporterForICES method addPrey.

private Specimen addPrey(LabeledCSVParser parser, Specimen predatorSpecimen, Study study) throws NodeFactoryException {
    String preyName = parser.getValueByLabel("Prey Species Name");
    Specimen specimen = null;
    if (StringUtils.isNotBlank(preyName)) {
        specimen = atePrey(predatorSpecimen, preyName, study);
    }
    return specimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen)

Example 20 with Specimen

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

the class StudyImporterForHafner method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    try {
        LabeledCSVParser parser = parserFactory.createParser(RESOURCE, "UTF-8");
        while (parser.getLine() != null) {
            String sourceCitation = "Mark S. Hafner, Philip D. Sudman, Francis X. Villablanca, Theresa A. Spradling, James W. Demastes, Steven A. Nadler. (1994). Disparate Rates of Molecular Evolution in Cospeciating Hosts and Parasites. Science 265: 1087-1090. doi:10.1126/science.8066445";
            Study study = nodeFactory.getOrCreateStudy(new StudyImpl("hafner1994", "Shan Kothari, Pers. Comm. 2014.", "doi:10.1126/science.8066445", sourceCitation));
            String hostName = parser.getValueByLabel("Host");
            String parasiteName = parser.getValueByLabel("Parasite");
            Specimen host = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
            Specimen parasite = nodeFactory.createSpecimen(study, new TaxonImpl(parasiteName, null));
            parasite.interactsWith(host, InteractType.PARASITE_OF);
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("failed to import [" + RESOURCE + "]", e);
    }
}
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) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException)

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