Search in sources :

Example 56 with Study

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

the class StudyImporterForBioInfo method createRelations.

protected void createRelations(LabeledCSVParser parser, Map<String, String> refMap, Map<String, Taxon> taxonMap) throws StudyImporterException {
    try {
        long count = 1;
        while (parser.getLine() != null) {
            if (importFilter.shouldImportRecord(count)) {
                String refIds = parser.getValueByLabel("list of reference ids");
                if (StringUtils.isNotBlank(refIds)) {
                    String[] ids = StringUtils.split(refIds, ";");
                    for (String id : ids) {
                        String trimmedId = StringUtils.trim(id);
                        Study study = createStudy(trimmedId, refMap.get(trimmedId));
                        String relationship = parser.getValueByLabel("relationship");
                        if (StringUtils.isBlank(relationship)) {
                            getLogger().warn(study, "no relationship for record on line [" + (parser.lastLineNumber() + 1) + "]");
                        }
                        InteractType interactType = INTERACTION_MAPPING.get(relationship);
                        if (null == interactType) {
                            getLogger().warn(study, "no mapping found for relationship [" + relationship + "] for record on line [" + (parser.lastLineNumber() + 1) + "]");
                        } else {
                            importInteraction(parser, study, interactType, taxonMap);
                        }
                    }
                }
            }
            count++;
        }
    } catch (IOException e1) {
        throw new StudyImporterException("problem reading trophic relations data", e1);
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) IOException(java.io.IOException)

Example 57 with Study

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

the class StudyImporterForBrose method importLine.

private void importLine(LabeledCSVParser parser, Map<String, String> refMap) throws StudyImporterException {
    Study localStudy = null;
    try {
        String shortReference = StringUtils.trim(parser.getValueByLabel("Link reference"));
        if (!refMap.containsKey(shortReference)) {
            throw new StudyImporterException("failed to find ref [" + shortReference + "] on line [" + parser.lastLineNumber() + "]");
        }
        String longReference = refMap.get(shortReference);
        localStudy = nodeFactory.getOrCreateStudy(new StudyImpl("BROSE-" + StringUtils.abbreviate(longReference, 20), SOURCE, null, ExternalIdUtil.toCitation(null, longReference, null)));
        String name = getName(parser, "Taxonomy consumer", "Common name(s) consumer");
        if (StringUtils.isBlank(name)) {
            getLogger().warn(localStudy, "found empty name on line [" + parser.lastLineNumber() + "]");
        } else {
            addInteractionForConsumer(parser, localStudy, name);
        }
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("problem creating nodes at line [" + parser.lastLineNumber() + "]", e);
    } catch (NumberFormatException e) {
        String message = "skipping record, found malformed field at line [" + parser.lastLineNumber() + "]: ";
        if (localStudy != null) {
            getLogger().warn(localStudy, message + e.getMessage());
        }
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl)

Example 58 with Study

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

the class StudyImporterForByrnes method importLine.

private void importLine(LabeledCSVParser parser, Map<String, String> refMap) throws StudyImporterException {
    Study localStudy = null;
    try {
        String refList = StringUtils.trim(parser.getValueByLabel("Reference"));
        String[] refs;
        if (StringUtils.isBlank(refList)) {
            refs = new String[] { "Byrnes, J.E. et al., 2011. Climate-driven increases in storm frequency simplify kelp forest food webs. Global Change Biology, 17(8), pp.2513–2524. Available at: http://dx.doi.org/10.1111/j.1365-2486.2011.02409.x." };
        } else {
            refs = StringUtils.split(refList, ",");
        }
        for (String ref : refs) {
            String singleShortRef = StringUtils.trim(ref);
            String longRef = refMap.get(singleShortRef);
            String citation = StringUtils.isBlank(longRef) ? singleShortRef : longRef;
            localStudy = nodeFactory.getOrCreateStudy(new StudyImpl("BYRNES-" + StringUtils.abbreviate(citation, 32), SOURCE, null, citation));
            String predatorName = parser.getValueByLabel("Predator");
            if (StringUtils.isBlank(predatorName)) {
                getLogger().warn(localStudy, "found empty predator name on line [" + parser.lastLineNumber() + "]");
            } else {
                addInteractionForPredator(parser, localStudy, predatorName);
            }
        }
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("problem creating nodes at line [" + parser.lastLineNumber() + "]", e);
    } catch (NumberFormatException e) {
        String message = "skipping record, found malformed field at line [" + parser.lastLineNumber() + "]: ";
        if (localStudy != null) {
            getLogger().warn(localStudy, message + e.getMessage());
        }
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl)

Example 59 with Study

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

the class StudyImporterForBarnes method importLine.

private void importLine(LabeledCSVParser parser, Map<String, String> refMap) throws StudyImporterException {
    Study localStudy = null;
    try {
        String shortReference = StringUtils.trim(parser.getValueByLabel("Reference"));
        if (!refMap.containsKey(shortReference)) {
            throw new StudyImporterException("failed to find ref [" + shortReference + "] on line [" + parser.lastLineNumber() + "]");
        }
        String longReference = refMap.get(shortReference);
        localStudy = nodeFactory.getOrCreateStudy(new StudyImpl("BARNES-" + shortReference, SOURCE, null, ExternalIdUtil.toCitation(null, longReference, null)));
        String predatorName = parser.getValueByLabel("Predator");
        if (StringUtils.isBlank(predatorName)) {
            getLogger().warn(localStudy, "found empty predator name on line [" + parser.lastLineNumber() + "]");
        } else {
            addInteractionForPredator(parser, localStudy, predatorName);
        }
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("problem creating nodes at line [" + parser.lastLineNumber() + "]", e);
    } catch (NumberFormatException e) {
        String message = "skipping record, found malformed field at line [" + parser.lastLineNumber() + "]: ";
        if (localStudy != null) {
            getLogger().warn(localStudy, message + e.getMessage());
        }
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl)

Example 60 with Study

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

the class StudyImporterForBlewett method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    String citation = "Blewett DA, Hensley RA, and Stevens PW, Feeding Habits of Common Snook, Centropomus Undecimalis, in Charlotte Harbor, Florida, Gulf and Caribbean Research Vol 18, 1–13, 2006. doi:10.18785/gcr.1801.01 ";
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Blewett 2006", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, null, citation));
    try {
        Map<String, Location> collectionLocationMap = new HashMap<>();
        Map<String, Date> collectionTimeMap = new HashMap<String, Date>();
        buildLocationTimeMaps(collectionLocationMap, collectionTimeMap, study);
        parsePredatorPreyInteraction(study, collectionLocationMap, collectionTimeMap);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource", e);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create taxon", e);
    } catch (TermLookupServiceException e) {
        throw new StudyImporterException("failed to map terms", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) IOException(java.io.IOException) Date(java.util.Date) 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