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;
}
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);
}
}
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;
}
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);
}
}
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);
}
}
}
}
Aggregations