use of org.eol.globi.domain.Study 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);
}
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class StudyImporterForHurlbert method importRecords.
private void importRecords(Set<String> regions, Set<String> locales, Set<String> habitats, Record record, String sourceCitation) throws StudyImporterException {
String namespace = getDataset() == null ? "" : getDataset().getNamespace();
StudyImpl study1 = new StudyImpl(namespace + sourceCitation, "Allen Hurlbert. Avian Diet Database (https://github.com/hurlbertlab/dietdatabase/). " + CitationUtil.createLastAccessedString(RESOURCE), null, sourceCitation);
study1.setOriginatingDataset(getDataset());
Study study = nodeFactory.getOrCreateStudy(study1);
// ID,Common_Name,Scientific_Name,,,,Prey_Common_Name,Fraction_Diet_By_Wt_or_Vol,Fraction_Diet_By_Items,Fraction_Occurrence,Fraction_Diet_Unspecified,Item Sample Size,Bird Sample size,Sites,StudyNode Type,Notes,Source
String[] preyLabels = { "Prey_Kingdom", "Prey_Phylum", "Prey_Class", "Prey_Order", "Prey_Suborder", "Prey_Family", "Prey_Genus", "Prey_Scientific_Name" };
ArrayUtils.reverse(preyLabels);
String preyTaxonName = null;
for (String preyLabel : preyLabels) {
preyTaxonName = columnValueOrNull(record, preyLabel);
if (StringUtils.isNotBlank(preyTaxonName) && !"NA".equalsIgnoreCase(preyTaxonName)) {
break;
}
}
String predatorTaxonName = StringUtils.trim(columnValueOrNull(record, "Scientific_Name"));
if (StringUtils.isNotBlank(StringUtils.trim(predatorTaxonName)) && StringUtils.isNotBlank(StringUtils.trim(preyTaxonName))) {
importInteraction(regions, locales, habitats, record, study, preyTaxonName, predatorTaxonName);
}
}
use of org.eol.globi.domain.Study 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);
}
}
use of org.eol.globi.domain.Study 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);
}
}
use of org.eol.globi.domain.Study 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);
}
}
Aggregations