Search in sources :

Example 71 with TaxonImpl

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

the class StudyImporterForBioInfo method createSpecimen.

private Specimen createSpecimen(LabeledCSVParser parser, Study study, Map<String, Taxon> taxonMap, String nbnId, String bioTaxonId) throws StudyImporterException {
    Specimen specimen = null;
    if (StringUtils.isBlank(nbnId)) {
        try {
            Taxon taxon = taxonMap.get(bioTaxonId);
            if (taxon == null) {
                getLogger().warn(study, "empty/no taxon name for bioinfo taxon id [" + bioTaxonId + "] on line [" + parser.lastLineNumber() + 1 + "]");
            } else {
                specimen = nodeFactory.createSpecimen(study, new TaxonImpl(taxon.getName(), TaxonomyProvider.BIO_INFO + "taxon:" + bioTaxonId));
                setSpecimenExternalId(parser, specimen);
            }
        } catch (NodeFactoryException e) {
            throw new StudyImporterException("failed to create taxon with scientific name [" + bioTaxonId + "]", e);
        }
    } else {
        specimen = createSpecimen(study, parser, nbnId);
    }
    return specimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 72 with TaxonImpl

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

the class StudyImporterForSeltmann method createInteraction.

protected void createInteraction(LabeledCSVParser occurrence, Study study, Map<String, String> assoc, String targetName, String sourceName, Date date, InteractType interactType) throws StudyImporterException {
    Specimen source = nodeFactory.createSpecimen(study, new TaxonImpl(sourceName, null));
    Specimen target = nodeFactory.createSpecimen(study, new TaxonImpl(targetName, null));
    source.interactsWith(target, interactType);
    String sourceBasisOfRecord = occurrence.getValueByLabel("basisOfRecord");
    source.setBasisOfRecord(nodeFactory.getOrCreateBasisOfRecord(sourceBasisOfRecord, sourceBasisOfRecord));
    final String recordId = occurrence.getValueByLabel(FIELD_IDIGBIO_RECORD_ID);
    source.setProperty(FIELD_IDIGBIO_RECORD_ID, recordId);
    source.setExternalId(recordId);
    source.setProperty(FIELD_OCCURRENCE_ID, occurrence.getValueByLabel(FIELD_OCCURRENCE_ID));
    source.setProperty(FIELD_CATALOG_NUMBER, occurrence.getValueByLabel(FIELD_CATALOG_NUMBER));
    String targetBasisOfRecord = assoc.get("dwc:basisOfRecord");
    target.setBasisOfRecord(nodeFactory.getOrCreateBasisOfRecord(targetBasisOfRecord, targetBasisOfRecord));
    final String assocRecordId = assoc.get(FIELD_IDIGBIO_RECORD_ID);
    target.setProperty(FIELD_IDIGBIO_RECORD_ID, assocRecordId);
    target.setExternalId(assocRecordId);
    nodeFactory.setUnixEpochProperty(source, date);
    nodeFactory.setUnixEpochProperty(target, date);
    String latitude = occurrence.getValueByLabel("decimalLatitude");
    String longitude = occurrence.getValueByLabel("decimalLongitude");
    if (StringUtils.isNotBlank(latitude) && StringUtils.isNotBlank(longitude)) {
        Location loc = nodeFactory.getOrCreateLocation(new LocationImpl(Double.parseDouble(latitude), Double.parseDouble(longitude), null, null));
        source.caughtIn(loc);
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 73 with TaxonImpl

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

the class StudyImporterForRoopnarine method importPredatorSpecimen.

private List<Specimen> importPredatorSpecimen(String trophicGuildLookup, Map<Integer, List<String>> trophicGuildNumberToSpeciesMap, LabeledCSVParser parser, List<String> preyTaxonList, Study study, Location location) throws StudyImporterException {
    Integer predatorGuildNumber = parseGuildNumber(trophicGuildLookup, parser);
    List<Specimen> predatorSpecimenList = new ArrayList<Specimen>();
    List<String> predatorTaxaList = trophicGuildNumberToSpeciesMap.get(predatorGuildNumber);
    if (predatorTaxaList == null) {
        throw new StudyImporterException("no species available for guild number [" + predatorGuildNumber + "]");
    }
    for (String predatorTaxa : predatorTaxaList) {
        // TODO - here's where the specimen model doesn't fit nicely - need a way to distinguish inferred relationships from direct observations
        if (StringUtils.isBlank(predatorTaxa)) {
            getLogger().info(study, "found blank predator name on line [" + parser.lastLineNumber() + "]");
        } else {
            Specimen predatorSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(predatorTaxa, null));
            predatorSpecimen.caughtIn(location);
            predatorSpecimenList.add(predatorSpecimen);
            for (String preyTaxonName : preyTaxonList) {
                if (StringUtils.isBlank(preyTaxonName)) {
                    getLogger().info(study, "found blank prey name for predator [" + predatorTaxa + "] on line [" + parser.lastLineNumber() + "]");
                } else {
                    Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(preyTaxonName, null));
                    preySpecimen.caughtIn(location);
                    predatorSpecimen.ate(preySpecimen);
                }
            }
        }
    }
    return predatorSpecimenList;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) ArrayList(java.util.ArrayList)

Example 74 with TaxonImpl

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

the class StudyImporterForStrona method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    LabeledCSVParser dataParser;
    try {
        dataParser = parserFactory.createParser(RESOURCE_PATH, CharsetConstant.UTF8);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource [" + RESOURCE_PATH + "]", e);
    }
    try {
        Study study = nodeFactory.getOrCreateStudy(new StudyImpl("strona2013", SOURCE + " . " + CitationUtil.createLastAccessedString(RESOURCE_PATH), "http://dx.doi.org/10.1890/12-1419.1", SOURCE));
        while (dataParser.getLine() != null) {
            if (importFilter.shouldImportRecord((long) dataParser.getLastLineNumber())) {
                try {
                    String parasiteName = StringUtils.trim(dataParser.getValueByLabel("P_SP"));
                    String hostName = StringUtils.trim(dataParser.getValueByLabel("H_SP"));
                    if (areNamesAvailable(parasiteName, hostName)) {
                        Specimen parasite = nodeFactory.createSpecimen(study, new TaxonImpl(parasiteName, null));
                        Specimen host = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
                        parasite.interactsWith(host, InteractType.PARASITE_OF);
                    }
                } catch (NodeFactoryException | NumberFormatException e) {
                    throw new StudyImporterException("failed to import line [" + (dataParser.lastLineNumber() + 1) + "]", e);
                }
            }
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("problem importing [" + RESOURCE_PATH + "]", 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)

Example 75 with TaxonImpl

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

the class StudyImporterForWebOfLife method importNetwork.

public void importNetwork(InteractType interactType1, Location networkLocation, Study study, File file) throws IOException, NodeFactoryException {
    LabeledCSVParser interactions = CSVTSVUtil.createLabeledCSVParser(new FileInputStream(file));
    final String[] targetLabels = interactions.getLabels();
    List<String> targetTaxonNames = new ArrayList<String>();
    List<String> ignoredLabels = Arrays.asList("number of hosts sampled", "");
    for (String targetLabel : targetLabels) {
        String trimmedLabel = StringUtils.trim(targetLabel);
        if (StringUtils.isNotBlank(targetLabel) || !ignoredLabels.contains(trimmedLabel)) {
            targetTaxonNames.add(targetLabel);
        }
    }
    String[] line;
    while ((line = interactions.getLine()) != null) {
        String sourceTaxonName = line[0];
        final Specimen sourceSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(sourceTaxonName, null));
        sourceSpecimen.caughtIn(networkLocation);
        for (String targetTaxonName : targetTaxonNames) {
            final String valueByLabel = StringUtils.trim(interactions.getValueByLabel(targetTaxonName));
            if (StringUtils.isNotBlank(valueByLabel) && !StringUtils.equals("0", valueByLabel)) {
                final Specimen targetSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(targetTaxonName, null));
                targetSpecimen.caughtIn(networkLocation);
                sourceSpecimen.interactsWith(targetSpecimen, interactType1);
            }
        }
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) ArrayList(java.util.ArrayList) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) FileInputStream(java.io.FileInputStream)

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