use of org.eol.globi.domain.StudyImpl 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.StudyImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForSimons method importStudy.
private Study importStudy(ParserFactory parserFactory, String studyResource) throws StudyImporterException {
Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Simons 1997", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, null, ExternalIdUtil.toCitation("James D. Simons", "Food habits and trophic structure of the demersal fish assemblages on the Mississippi-Alabama continental shelf.", "1997")));
try {
LabeledCSVParser csvParser = parserFactory.createParser(studyResource, CharsetConstant.UTF8);
Map<String, String> columnMapper = COLUMN_MAPPER;
LengthParser parser = new LengthRangeParserImpl(columnMapper.get(LENGTH_RANGE_IN_MM));
while (csvParser.getLine() != null) {
addNextRecordToStudy(csvParser, study, COLUMN_MAPPER, parser);
}
} catch (IOException e) {
throw new StudyImporterException("failed to createTaxon study [" + studyResource + "]", e);
}
return study;
}
use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.
the class StudyImporterForSIAD method downloadAndImportResource.
private void downloadAndImportResource(String resource, String source) throws StudyImporterException {
try {
LabeledCSVParser labeledCSVParser = parserFactory.createParser(resource, "UTF-8");
labeledCSVParser.changeDelimiter('\t');
while (labeledCSVParser.getLine() != null) {
String name = labeledCSVParser.getValueByLabel("name");
String ref = labeledCSVParser.getValueByLabel("source");
String title = "SIAD-" + ref;
String citation = "ABRS 2009. Australian Faunal Directory. " + name + ". Australian Biological Resources StudyNode, Canberra. " + CitationUtil.createLastAccessedString(ref);
StudyImpl study1 = new StudyImpl(title, source, null, citation);
study1.setExternalId(ref);
Study study = nodeFactory.getOrCreateStudy(study1);
Specimen specimen = nodeFactory.createSpecimen(study, new TaxonImpl(name, null));
String hostName = labeledCSVParser.getValueByLabel("host name");
Specimen hostSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
InteractType type = map.get(labeledCSVParser.getValueByLabel("interaction"));
specimen.interactsWith(hostSpecimen, type);
}
} catch (FileNotFoundException e) {
throw new StudyImporterException("failed to open tmp file", e);
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to map data", e);
} catch (IOException e) {
throw new StudyImporterException("failed to read resource [" + resource + "]", e);
}
}
use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.
the class TaxonInteractionIndexerTest method indexNoNameNoMatch.
@Test
public void indexNoNameNoMatch() throws NodeFactoryException {
Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Homo sapiens", PropertyAndValueDictionary.NO_MATCH));
Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Canis lupus", PropertyAndValueDictionary.NO_MATCH));
human.ate(animal);
for (int i = 0; i < 10; i++) {
Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Arius felis", null));
human.ate(fish);
}
assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
new NameResolver(getGraphDb(), new NonResolvingTaxonIndex(getGraphDb())).resolve();
assertNotNull(taxonIndex.findTaxonByName("Homo sapiens"));
assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
assertNull(taxonIndex.findTaxonByName(PropertyAndValueDictionary.NO_NAME));
}
use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.
the class TaxonInteractionIndexerTest method buildTaxonInterIndex.
@Test
public void buildTaxonInterIndex() throws NodeFactoryException, PropertyEnricherException {
Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Homo sapiens", "NCBI:9606"));
Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Canis lupus", "WORMS:2"));
human.ate(animal);
for (int i = 0; i < 10; i++) {
Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Arius felis", "WORMS:158711"));
human.ate(fish);
}
assertNull(taxonIndex.findTaxonById("WORMS:2"));
assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
new NameResolver(getGraphDb(), new NonResolvingTaxonIndex(getGraphDb())).resolve();
new TaxonInteractionIndexer(getGraphDb()).index();
Taxon homoSapiens = taxonIndex.findTaxonByName("Homo sapiens");
assertNotNull(homoSapiens);
Iterable<Relationship> rels = ((NodeBacked) homoSapiens).getUnderlyingNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
List<String> humanFood = new ArrayList<String>();
List<Long> counts = new ArrayList<Long>();
List<String> labels = new ArrayList<>();
for (Relationship rel : rels) {
humanFood.add((String) rel.getEndNode().getProperty("name"));
counts.add((Long) rel.getProperty("count"));
labels.add((String) rel.getProperty("label"));
}
assertThat(humanFood.size(), is(4));
assertThat(humanFood, hasItems("Arius felis", "Canis lupus"));
assertThat(counts, hasItems(10L, 1L));
assertThat(labels, hasItems("eats"));
}
Aggregations