use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class OpenTreeUtil method readTaxonomy.
public static void readTaxonomy(OpenTreeListener listener, InputStream inputStream) throws IOException {
LabeledCSVParser parser = CSVTSVUtil.createLabeledCSVParser(new CSVParser(IOUtils.toBufferedInputStream(inputStream), '\t'));
while (parser.getLine() != null) {
String taxonId = parser.getValueByLabel("uid");
String[] externalIds = StringUtils.split(parser.getValueByLabel("sourceinfo"), ",");
for (String otherTaxonId : externalIds) {
listener.taxonSameAs(taxonId, otherTaxonId);
}
}
}
use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class TaxonCacheParserTest method parse.
public static void parse(BufferedReader reader, TaxonCacheListener listener) throws IOException {
LabeledCSVParser labeledCSVParser = CSVTSVUtil.createLabeledCSVParser(reader);
listener.start();
while (labeledCSVParser.getLine() != null) {
Taxon taxa = TaxonCacheParser.parseLine(labeledCSVParser);
listener.addTaxon(taxa);
}
listener.finish();
}
use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForRaymond method importData.
private void importData(InputStream inputStream) throws IOException, StudyImporterException {
File dietFile = null;
File sourcesFile = null;
LabeledCSVParser sourcesParser = null;
LabeledCSVParser dietParser = null;
try {
ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (DIET_CSV.equals(entry.getName())) {
dietFile = File.createTempFile("raymondDiet", ".csv");
dietParser = CSVTSVUtil.createParser(dietFile, zis);
} else if (SOURCES_CSV.equals(entry.getName())) {
sourcesFile = File.createTempFile("raymondSources", ".csv");
sourcesParser = CSVTSVUtil.createParser(sourcesFile, zis);
} else {
IOUtils.copy(zis, new NullOutputStream());
}
}
if (sourcesParser == null) {
throw new StudyImporterException("failed to find [" + SOURCES_CSV + "] in [" + RESOURCE_URL + "]");
}
if (dietParser == null) {
throw new StudyImporterException("failed to find [" + DIET_CSV + "] in [" + RESOURCE_URL + "]");
}
importData(sourcesParser, dietParser);
} finally {
org.apache.commons.io.FileUtils.deleteQuietly(dietFile);
org.apache.commons.io.FileUtils.deleteQuietly(sourcesFile);
}
}
use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForKelpForest method importStudy.
@Override
public void importStudy() throws StudyImporterException {
try {
String source = "Beas-Luna, R., Novak, M., Carr, M. H., Tinker, M. T., Black, A., Caselle, J. E., … Iles, A. (2014). An Online Database for Informing Ecological Network Models: http://kelpforest.ucsc.edu. PLoS ONE, 9(10), e109356. doi:10.1371/journal.pone.0109356";
Study study = nodeFactory.getOrCreateStudy(new StudyImpl(source, source, "doi:10.1371/journal.pone.0109356", source));
LabeledCSVParser parser = parserFactory.createParser(NODES, "UTF-8");
String[] line;
Map<String, Long> nameToId = new HashMap<String, Long>();
while ((line = parser.getLine()) != null) {
if (line.length > 2) {
String name = parser.getValueByLabel("working_name");
String itisId = parser.getValueByLabel("itis_id");
Long id = StringUtils.isBlank(itisId) ? null : Long.parseLong(itisId);
id = (id != null && id > 0L) ? id : null;
nameToId.put(name, id);
}
}
Map<String, InteractType> typeToType = new HashMap<String, InteractType>() {
{
put("trophic", InteractType.ATE);
put("parasitic", InteractType.PARASITE_OF);
}
};
parser = parserFactory.createParser(LINKS, "UTF-8");
while ((line = parser.getLine()) != null) {
if (line.length > 2) {
String interactionType = parser.getValueByLabel("type");
InteractType interactType = typeToType.get(interactionType);
if (null == interactType) {
LOG.warn("ignoring type [" + interactionType + "] on line: [" + (parser.getLastLineNumber() + 1) + "]");
} else {
Specimen sourceSpecimen = createSpecimen(parser, nameToId, "node_1_working_name", "node1_stage", study);
Specimen targetSpecimen = createSpecimen(parser, nameToId, "node_2_working_name", "node2_stage", study);
sourceSpecimen.interactsWith(targetSpecimen, interactType);
}
}
}
} catch (IOException | NodeFactoryException e) {
throw new StudyImporterException("failed to import", e);
}
}
use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.
the class StudyImporterForJRFerrerParis method importStudy.
@Override
public void importStudy() throws StudyImporterException {
String citation = "Ferrer-Paris, José R.; Sánchez-Mercado, Ada Y.; Lozano, Cecilia; Zambrano, Liset; Soto, José; Baettig, Jessica; Leal, María (2014): A compilation of larval host-plant records for six families of butterflies (Lepidoptera: Papilionoidea) from available electronic resources. figshare. http://dx.doi.org/10.6084/m9.figshare.1168861 . " + CitationUtil.createLastAccessedString(RESOURCE);
Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Ferrer-Paris 2014", citation, "http://dx.doi.org/10.6084/m9.figshare.1168861", citation));
try {
LabeledCSVParser parser = parserFactory.createParser(RESOURCE, CharsetConstant.UTF8);
while (parser.getLine() != null) {
String butterflyName = createTaxon(parser, "Lepidoptera Name");
String plantName = createTaxon(parser, "Hostplant Name");
if (validNames(butterflyName, plantName, study, parser.lastLineNumber())) {
addAssociation(study, parser, butterflyName, plantName);
}
}
} catch (IOException e) {
throw new StudyImporterException("failed to access resource [" + RESOURCE + "]");
}
}
Aggregations