use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForAkin method importAkinStudyFile.
private Study importAkinStudyFile(String[][] siteInfos, String studyResource, Study study) throws IOException, StudyImporterException, NodeFactoryException {
LabeledCSVParser parser = parserFactory.createParser(studyResource, CharsetConstant.UTF8);
String[] header = parser.getLabels();
String[] line;
while ((line = parser.getLine()) != null) {
if (isValid(line, header, parser, siteInfos)) {
parseLine(siteInfos, studyResource, study, parser, header, line);
} else {
getLogger().warn(study, "[" + studyResource + "," + parser.lastLineNumber() + "]: skipping line, missing mandatory date or site field in line [" + StringUtils.join(line, ",") + "]");
}
}
return study;
}
use of com.Ostermiller.util.LabeledCSVParser 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 com.Ostermiller.util.LabeledCSVParser 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 com.Ostermiller.util.LabeledCSVParser 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 com.Ostermiller.util.LabeledCSVParser 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);
}
}
Aggregations