use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class NameResolverTest method iNaturalistTaxon.
@Test
public void iNaturalistTaxon() throws NodeFactoryException {
Specimen someOtherOrganism = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Blaus bla", "INAT_TAXON:58831"));
Specimen someOtherOrganism2 = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Redus rha", "INAT_TAXON:126777"));
someOtherOrganism.ate(someOtherOrganism2);
final NameResolver nameResolver = new NameResolver(getGraphDb(), new NonResolvingTaxonIndex(getGraphDb()));
nameResolver.setBatchSize(1L);
nameResolver.resolve();
Taxon resolvedTaxon = taxonIndex.findTaxonById("INAT_TAXON:58831");
assertThat(resolvedTaxon, is(notNullValue()));
assertThat(resolvedTaxon.getExternalId(), is("INAT_TAXON:58831"));
assertThat(resolvedTaxon.getName(), is("Blaus bla"));
Taxon resolvedTaxon2 = taxonIndex.findTaxonByName("Blaus bla");
assertThat(resolvedTaxon2, is(notNullValue()));
assertThat(resolvedTaxon2.getExternalId(), is("INAT_TAXON:58831"));
}
use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class ReportGeneratorTest method createStudy.
protected Study createStudy(Study study1) throws NodeFactoryException {
Study study = nodeFactory.getOrCreateStudy(study1);
Specimen monkey = nodeFactory.createSpecimen(study, new TaxonImpl("Monkey"));
monkey.ate(nodeFactory.createSpecimen(study, new TaxonImpl("Banana")));
monkey.ate(nodeFactory.createSpecimen(study, new TaxonImpl("Banana")));
monkey.ate(nodeFactory.createSpecimen(study, new TaxonImpl("Banana")));
TaxonImpl apple = new TaxonImpl("Apple", "some:id");
apple.setPath("some | path");
monkey.ate(nodeFactory.createSpecimen(study, apple));
return study;
}
use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class StudyImporterForCoetzer method importStudy.
@Override
public void importStudy() throws StudyImporterException {
if (org.apache.commons.lang.StringUtils.isBlank(getResourceArchiveURI())) {
throw new StudyImporterException("failed to import [" + getDataset().getNamespace() + "]: no [archiveURL] specified");
}
DB db = DBMaker.newMemoryDirectDB().compressionEnable().transactionDisable().make();
final HTreeMap<Integer, String> taxonMap = db.createHashMap("taxonMap").make();
final HTreeMap<Integer, String> refMap = db.createHashMap("refMap").make();
try {
InputStream inputStream = DatasetUtil.getNamedResourceStream(getDataset(), "archive");
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
ZipEntry entry;
File taxonTempFile = null;
File assocTempFile = null;
File referencesTempFile = null;
File distributionTempFile = null;
while ((entry = zipInputStream.getNextEntry()) != null) {
if (entry.getName().matches("(^|(.*/))taxon.txt$")) {
taxonTempFile = FileUtils.saveToTmpFile(zipInputStream, entry);
} else if (entry.getName().matches("(^|(.*/))description.txt$")) {
assocTempFile = FileUtils.saveToTmpFile(zipInputStream, entry);
} else if (entry.getName().matches("(^|(.*/))references.txt$")) {
referencesTempFile = FileUtils.saveToTmpFile(zipInputStream, entry);
} else if (entry.getName().matches("(^|(.*/))distribution.txt$")) {
distributionTempFile = FileUtils.saveToTmpFile(zipInputStream, entry);
} else {
IOUtils.copy(zipInputStream, new NullOutputStream());
}
}
IOUtils.closeQuietly(zipInputStream);
if (taxonTempFile == null) {
throw new StudyImporterException("failed to find expected [taxon.txt] resource");
}
if (assocTempFile == null) {
throw new StudyImporterException("failed to find expected [description.txt] resource");
}
if (referencesTempFile == null) {
throw new StudyImporterException("failed to find expected [references.txt] resource");
}
if (distributionTempFile == null) {
throw new StudyImporterException("failed to find expected [distribution.txt] resource");
}
BufferedReader assocReader = FileUtils.getUncompressedBufferedReader(new FileInputStream(taxonTempFile), CharsetConstant.UTF8);
LabeledCSVParser parser = CSVTSVUtil.createLabeledCSVParser(assocReader);
parser.changeDelimiter('\t');
String[] line;
while ((line = parser.getLine()) != null) {
taxonMap.put(Integer.parseInt(line[0]), nameFor(line));
}
LabeledCSVParser refs = CSVTSVUtil.createLabeledCSVParser(new FileInputStream(referencesTempFile));
refs.changeDelimiter('\t');
String[] refsLine;
while ((refsLine = refs.getLine()) != null) {
refMap.put(Integer.parseInt(refsLine[0]), refsLine[1]);
}
LabeledCSVParser assoc = CSVTSVUtil.createLabeledCSVParser(new FileInputStream(assocTempFile));
assoc.changeDelimiter('\t');
final Map<String, InteractType> interactTypeMap = new HashMap<String, InteractType>() {
{
put("Visits flowers of", InteractType.VISITS_FLOWERS_OF);
put("Host of", InteractType.VISITS_FLOWERS_OF);
put("Parasite of", InteractType.PARASITE_OF);
put("Nests in", InteractType.INTERACTS_WITH);
}
};
String[] assocLine;
while ((assocLine = assoc.getLine()) != null) {
final Integer taxonId = Integer.parseInt(assocLine[0]);
final String[] parts = assocLine[2].split(":");
if (parts.length > 1) {
String interactionString = parts[0];
String[] targetTaxonNames = parts[1].split(",");
for (String targetTaxonName : targetTaxonNames) {
final String reference = refMap.get(taxonId);
final String sourceTaxonName = taxonMap.get(taxonId);
if (StringUtils.isNotBlank(reference) && StringUtils.isNotBlank(sourceTaxonName)) {
final Study study = nodeFactory.getOrCreateStudy(new StudyImpl(getSourceCitation() + reference, getSourceCitationLastAccessed(), null, reference));
final Specimen source = nodeFactory.createSpecimen(study, new TaxonImpl(StringUtils.trim(sourceTaxonName), null));
final Specimen target = nodeFactory.createSpecimen(study, new TaxonImpl(StringUtils.trim(targetTaxonName), null));
final InteractType relType = interactTypeMap.get(interactionString);
if (relType == null) {
throw new StudyImporterException("found unsupported interaction type [" + interactionString + "]");
}
source.interactsWith(target, relType);
}
}
}
}
} catch (IOException | NodeFactoryException e) {
throw new StudyImporterException(e);
}
db.close();
}
use of org.eol.globi.domain.Specimen 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);
}
}
use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class StudyImporterForCook method addParasites.
private void addParasites(LabeledCSVParser parser, Study study, Location sampleLocation, Specimen host, Date collectionDate, String isoCol) throws NodeFactoryException {
try {
String valueByLabel = parser.getValueByLabel(isoCol);
boolean parasiteDetected = !"0".equals(valueByLabel);
boolean lengthAvailable = parasiteDetected && !"NA".equals(valueByLabel);
if (parasiteDetected) {
Specimen parasite = nodeFactory.createSpecimen(study, new TaxonImpl("Cymothoa excisa", null));
parasite.caughtIn(sampleLocation);
if (lengthAvailable) {
double parasiteLengthCm = Double.parseDouble(valueByLabel);
parasite.setLengthInMm(parasiteLengthCm * 10.0);
}
parasite.interactsWith(host, InteractType.PARASITE_OF);
nodeFactory.setUnixEpochProperty(parasite, collectionDate);
}
} catch (NumberFormatException ex) {
// ignore
}
}
Aggregations