Search in sources :

Example 71 with Study

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

the class LinkerDOITest method createStudyDOIlookupCitationDisabled.

@Test
public void createStudyDOIlookupCitationDisabled() throws NodeFactoryException {
    StudyImpl study1 = new StudyImpl("title", "some source", null, "some citation");
    study1.setExternalId("some:id");
    DatasetImpl originatingDataset = new DatasetImpl("some/namespace", URI.create("some:uri"));
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, false);
    originatingDataset.setConfig(objectNode);
    study1.setOriginatingDataset(originatingDataset);
    Study study = getNodeFactory().getOrCreateStudy(study1);
    assertThat(study.getSource(), is("some source"));
    assertThat(study.getDOI(), is(nullValue()));
    assertThat(study.getCitation(), is("some citation"));
    assertThat(study.getTitle(), is("title"));
    assertThat(study.getExternalId(), is("some:id"));
}
Also used : Study(org.eol.globi.domain.Study) ObjectNode(org.codehaus.jackson.node.ObjectNode) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 72 with Study

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

the class LinkerDOITest method doLink.

@Test
public void doLink() throws NodeFactoryException, PropertyEnricherException {
    StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", "some source", null, "some citation"));
    new LinkerDOI(getGraphDb()).link();
    Study studyResolved = nodeFactory.getOrCreateStudy(study);
    assertThat(studyResolved.getDOI(), is(nullValue()));
    assertThat(study.getDOI(), is(nullValue()));
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 73 with Study

use of org.eol.globi.domain.Study 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 74 with Study

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

the class StudyImporterForAkin method importStudy.

private Study importStudy(String studyResource) throws StudyImporterException {
    Study study;
    try {
        String doi = "http://dx.doi.org/10.1007/bf02784282";
        StudyImpl study1 = new StudyImpl("Akin et al 2006", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, doi, ExternalIdUtil.toCitation("Senol Akin", "S. Akin, K. O. Winemiller, Seasonal variation in food web composition and structure in a temperate tidal estuary, Estuaries and Coasts" + "; August 2006, Volume 29, Issue 4, pp 552-567", "2006"));
        study = nodeFactory.getOrCreateStudy(study1);
        String[][] siteInfo = loadSampleSiteLocations();
        importAkinStudyFile(siteInfo, studyResource, study);
    } catch (IOException e) {
        throw new StudyImporterException("failed to find resource [" + studyResource + "]", e);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to parse resource [" + studyResource + "]", e);
    }
    return study;
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) IOException(java.io.IOException)

Example 75 with Study

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

the class StudyImporterForSeltmann method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    final String archiveURL = DatasetUtil.getNamedResourceURI(getDataset(), "archive");
    if (org.apache.commons.lang.StringUtils.isBlank(archiveURL)) {
        throw new StudyImporterException("failed to import [" + getDataset().getNamespace() + "]: no [archiveURL] specified");
    }
    DB db = DBMaker.newMemoryDirectDB().compressionEnable().transactionDisable().make();
    final HTreeMap<String, Map<String, String>> assocMap = db.createHashMap("assocMap").make();
    try {
        InputStream inputStream = DatasetUtil.getNamedResourceStream(getDataset(), "archive");
        ZipInputStream zipInputStream = new ZipInputStream(inputStream);
        ZipEntry entry;
        File assocTempFile = null;
        File occTempFile = null;
        while ((entry = zipInputStream.getNextEntry()) != null) {
            if (entry.getName().matches("(^|(.*/))associatedTaxa.tsv$")) {
                assocTempFile = FileUtils.saveToTmpFile(zipInputStream, entry);
            } else if (entry.getName().matches("(^|(.*/))occurrences.tsv$")) {
                occTempFile = FileUtils.saveToTmpFile(zipInputStream, entry);
            } else {
                IOUtils.copy(zipInputStream, new NullOutputStream());
            }
        }
        IOUtils.closeQuietly(zipInputStream);
        if (assocTempFile == null) {
            throw new StudyImporterException("failed to find expected [associatedTaxa.tsv] resource");
        }
        if (occTempFile == null) {
            throw new StudyImporterException("failed to find expected [occurrences.tsv] resource");
        }
        BufferedReader assocReader = FileUtils.getUncompressedBufferedReader(new FileInputStream(assocTempFile), CharsetConstant.UTF8);
        LabeledCSVParser parser = CSVTSVUtil.createLabeledCSVParser(assocReader);
        parser.changeDelimiter('\t');
        while (parser.getLine() != null) {
            Map<String, String> prop = new HashMap<String, String>();
            addKeyValue(parser, prop, "dwc:coreid");
            addKeyValue(parser, prop, "dwc:basisOfRecord");
            addKeyValue(parser, prop, FIELD_IDIGBIO_RECORD_ID);
            addKeyValue(parser, prop, FIELD_ASSOCIATED_GENUS);
            addKeyValue(parser, prop, FIELD_ASSOCIATED_SPECIFIC_EPITHET);
            addKeyValue(parser, prop, FIELD_ASSOCIATED_SCIENTIFIC_NAME);
            addKeyValue(parser, prop, "dwc:basisOfRecord");
            addKeyValue(parser, prop, "aec:associatedRelationshipTerm");
            addKeyValue(parser, prop, "aec:associatedRelationshipURI");
            addKeyValue(parser, prop, "aec:associatedLocationOnHost");
            addKeyValue(parser, prop, "aec:associatedEmergenceVerbatimDate");
            String coreId = parser.getValueByLabel("dwc:coreid");
            if (StringUtils.isBlank(coreId)) {
                LOG.warn("no coreid for line [" + parser.getLastLineNumber() + 1 + "]");
            } else {
                assocMap.put(coreId, prop);
            }
        }
        LabeledCSVParser occurrence = CSVTSVUtil.createLabeledCSVParser(new FileInputStream(occTempFile));
        occurrence.changeDelimiter('\t');
        while (occurrence.getLine() != null) {
            String references = occurrence.getValueByLabel("dcterms:references");
            Study study = nodeFactory.getOrCreateStudy(new StudyImpl("seltmann" + references, CitationUtil.sourceCitationLastAccessed(this.getDataset(), references), null, references));
            String recordId = occurrence.getValueByLabel(FIELD_IDIGBIO_RECORD_ID);
            Map<String, String> assoc = assocMap.get(recordId);
            if (assoc != null) {
                String targetName = getTargetNameFromAssocMap(assoc);
                String sourceName = occurrence.getValueByLabel("scientificName");
                String eventDate = occurrence.getValueByLabel("eventDate");
                Date date = null;
                if (StringUtils.equals(eventDate, "0000-00-00")) {
                    getLogger().warn(study, "found suspicious event date [" + eventDate + "]" + getLineMsg(occurrence));
                } else if (StringUtils.isBlank(eventDate)) {
                    getLogger().warn(study, "found suspicious event date [" + eventDate + "]" + getLineMsg(occurrence));
                } else {
                    DateTimeFormatter fmtDateTime1 = DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC();
                    String dateString = eventDate.split("/")[0];
                    try {
                        date = fmtDateTime1.parseDateTime(dateString).toDate();
                    } catch (IllegalArgumentException e) {
                        getLogger().warn(study, "invalid date [" + dateString + "] " + getLineMsg(occurrence));
                    }
                }
                if (StringUtils.isBlank(sourceName)) {
                    getLogger().warn(study, "found blank source taxon name" + getLineMsg(occurrence));
                }
                if (StringUtils.isBlank(targetName)) {
                    getLogger().warn(study, "found blank associated target taxon name" + getLineMsg(occurrence));
                }
                InteractType interactType = parseInteractType(occurrence, assoc);
                if (interactType != null && StringUtils.isNotBlank(sourceName) && StringUtils.isNotBlank(targetName)) {
                    try {
                        createInteraction(occurrence, study, assoc, targetName, sourceName, date, interactType);
                    } catch (NodeFactoryException ex) {
                        String message = "failed to import interaction because of [" + ex.getMessage() + "]" + getLineMsg(occurrence);
                        LOG.warn(message);
                        getLogger().warn(study, message);
                    }
                }
            }
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException(e);
    }
    db.close();
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Date(java.util.Date) ZipInputStream(java.util.zip.ZipInputStream) BufferedReader(java.io.BufferedReader) HashMap(java.util.HashMap) Map(java.util.Map) HTreeMap(org.mapdb.HTreeMap) File(java.io.File) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DB(org.mapdb.DB) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

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