use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForHechinger method importStudy.
@Override
public void importStudy() throws StudyImporterException {
Study study = createStudy();
try {
LabeledCSVParser nodes = parserFactory.createParser(getNodesResourceName(), CharsetConstant.UTF8);
nodes.changeDelimiter(getDelimiter());
Map<Integer, Term> stageForNode = new HashMap<>();
Map<Integer, String> taxonForNode = new HashMap<Integer, String>();
while (nodes.getLine() != null) {
Integer nodeId = getNodeId(nodes);
if (nodeId != null) {
String name = parseMostGranularTaxonName(nodes);
if (StringUtils.isBlank(name)) {
name = nodes.getValueByLabel("WorkingName");
if (StringUtils.isBlank(name)) {
getLogger().warn(study, "failed to find name for node on line [" + nodes.lastLineNumber() + "]");
}
}
if (StringUtils.isNotBlank(name)) {
try {
taxonForNode.put(nodeId, name);
String stage = nodes.getValueByLabel("Stage");
stageForNode.put(nodeId, nodeFactory.getOrCreateLifeStage(getNamespace() + ":" + stage, stage));
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to reader line [" + nodes.lastLineNumber() + "]", e);
}
}
}
}
LabeledCSVParser links = parserFactory.createParser(getLinksResourceName(), CharsetConstant.UTF8);
links.changeDelimiter(getDelimiter());
while (links.getLine() != null) {
List<Location> locations = new ArrayList<>();
if (getLocation() != null) {
Location loc = nodeFactory.getOrCreateLocation(new LocationImpl(getLocation().getLat(), getLocation().getLng(), null, null));
if (loc != null) {
locations.add(loc);
}
}
if (StringUtils.equals("1", links.getValueByLabel("PresentAtCSM"))) {
locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(34.403511, -119.537873, null, null)));
}
if (StringUtils.equals("1", links.getValueByLabel("PresentAtEPB"))) {
locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(31.748606, -116.626854, null, null)));
}
if (StringUtils.equals("1", links.getValueByLabel("PresentAtBSQ"))) {
locations.add(nodeFactory.getOrCreateLocation(new LocationImpl(30.378207, -115.938835, null, null)));
}
for (Location location : locations) {
addLink(study, stageForNode, taxonForNode, links, location);
}
}
} catch (IOException | NodeFactoryException e) {
throw new StudyImporterException("failed import study", e);
}
}
use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForGoMexSI2 method addObservations.
private void addObservations(Map<String, Map<String, String>> predatorIdToPredatorSpecimen, Map<String, Study> refIdToStudyMap, Map<String, List<Map<String, String>>> predatorUIToPreyLists, Study metaStudy) throws StudyImporterException {
String locationResource = getLocationsResourcePath();
try {
TermLookupService cmecsService = new CMECSService();
LabeledCSVParser parser = parserFactory.createParser(locationResource, CharsetConstant.UTF8);
while (parser.getLine() != null) {
String refId = getMandatoryValue(locationResource, parser, "DATA_ID");
if (!refIdToStudyMap.containsKey(refId)) {
getLogger().warn(metaStudy, "failed to find study for ref id [" + refId + "] on related to observation location in [" + locationResource + ":" + parser.getLastLineNumber() + "]");
} else {
Study study = refIdToStudyMap.get(refId);
String specimenId = getMandatoryValue(locationResource, parser, "PRED_ID");
Location location = parseLocation(locationResource, parser);
Location locationNode = nodeFactory.getOrCreateLocation(location);
enrichLocation(metaStudy, locationResource, cmecsService, parser, locationNode);
String predatorId = refId + specimenId;
Map<String, String> predatorProperties = predatorIdToPredatorSpecimen.get(predatorId);
if (predatorProperties == null) {
getLogger().warn(study, "failed to lookup predator [" + refId + ":" + specimenId + "] for location at [" + locationResource + ":" + (parser.getLastLineNumber() + 1) + "]");
} else {
addObservation(predatorUIToPreyLists, parser, study, locationNode, predatorId, predatorProperties);
}
}
}
} catch (IOException e) {
throw new StudyImporterException("failed to open resource [" + locationResource + "]", e);
}
}
use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForINaturalist method createAssociation.
private Specimen createAssociation(long observationId, String interactionDataType, InteractType interactType, JsonNode observation, Taxon targetTaxon, Taxon sourceTaxonName, Study study, Date observationDate) throws StudyImporterException, NodeFactoryException {
Specimen sourceSpecimen = getSourceSpecimen(observationId, interactionDataType, sourceTaxonName, study);
setBasisOfRecord(sourceSpecimen);
Specimen targetSpecimen = nodeFactory.createSpecimen(study, targetTaxon);
setBasisOfRecord(targetSpecimen);
sourceSpecimen.interactsWith(targetSpecimen, interactType);
setCollectionDate(sourceSpecimen, targetSpecimen, observationDate);
setCollectionDate(sourceSpecimen, sourceSpecimen, observationDate);
Location location = parseLocation(observation);
sourceSpecimen.caughtIn(location);
targetSpecimen.caughtIn(location);
return sourceSpecimen;
}
use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class ExporterOccurrencesTest method createTestData.
private void createTestData(Double length) throws NodeFactoryException, ParseException {
Study myStudy = nodeFactory.createStudy(new StudyImpl("myStudy", null, null, null));
Specimen specimen = nodeFactory.createSpecimen(myStudy, new TaxonImpl("Homo sapiens", "EOL:327955"));
specimen.setStomachVolumeInMilliLiter(666.0);
specimen.setLifeStage(new TermImpl("GLOBI:JUVENILE", "JUVENILE"));
specimen.setPhysiologicalState(new TermImpl("GLOBI:DIGESTATE", "DIGESTATE"));
specimen.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
nodeFactory.setUnixEpochProperty(specimen, ExportTestUtil.utcTestDate());
if (null != length) {
specimen.setLengthInMm(length);
}
Location location = nodeFactory.getOrCreateLocation(new LocationImpl(12.0, -1.0, -60.0, null));
specimen.caughtIn(location);
Specimen wolf1 = eatWolf(specimen, myStudy);
wolf1.caughtIn(location);
Specimen wolf2 = eatWolf(specimen, myStudy);
wolf2.caughtIn(location);
}
use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForCook method importStudy.
@Override
public void importStudy() throws StudyImporterException {
LabeledCSVParser parser;
try {
parser = parserFactory.createParser(DATASET_RESOURCE_NAME, CharsetConstant.UTF8);
} catch (IOException e) {
throw new StudyImporterException("failed to read resource", e);
}
String citation = "Cook CW. The Early Life History and Reproductive Biology of Cymothoa excisa, a Marine Isopod Parasitizing Atlantic Croaker, (Micropogonias undulatus), along the Texas Coast. 2012. Master Thesis. Available from http://repositories.lib.utexas.edu/handle/2152/ETD-UT-2012-08-6285.";
StudyImpl study1 = new StudyImpl("Cook 2012", "Data provided by Colt W. Cook. Also available from http://repositories.lib.utexas.edu/handle/2152/ETD-UT-2012-08-6285.", null, citation);
study1.setExternalId("http://repositories.lib.utexas.edu/handle/2152/ETD-UT-2012-08-6285");
Study study = nodeFactory.getOrCreateStudy(study1);
try {
Double latitude = LocationUtil.parseDegrees("27º51'N");
Double longitude = LocationUtil.parseDegrees("97º8'W");
Location sampleLocation = nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, -3.0, null));
try {
while (parser.getLine() != null) {
Specimen host = nodeFactory.createSpecimen(study, new TaxonImpl("Micropogonias undulatus", null));
host.setLengthInMm(Double.parseDouble(parser.getValueByLabel("Fish Length")) * 10.0);
String dateString = parser.getValueByLabel("Date");
Date collectionDate = DateUtil.parsePatternUTC(dateString, "MM/dd/yyyy").toDate();
nodeFactory.setUnixEpochProperty(host, collectionDate);
host.caughtIn(sampleLocation);
String[] isoCols = { "Iso 1", "Iso 2", "Iso 3", "Iso 4 ", "Iso 5" };
for (String isoCol : isoCols) {
addParasites(parser, study, sampleLocation, host, collectionDate, isoCol);
}
}
} catch (IOException e) {
throw new StudyImporterException("failed to parse [" + DATASET_RESOURCE_NAME + "]", e);
} catch (IllegalArgumentException e) {
throw new StudyImporterException("failed to parse date", e);
}
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to create host and parasite taxons", e);
}
}
Aggregations