use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class StudyImporterForSimonsTest method createAndPopulateStudy.
@Test
public void createAndPopulateStudy() throws StudyImporterException {
String csvString = "\"Obs\",\"spcode\", \"sizecl\", \"cruise\", \"stcode\", \"numstom\", \"numfood\", \"pctfull\", \"predator famcode\", \"prey\", \"number\", \"season\", \"depth\", \"transect\", \"alphcode\", \"taxord\", \"station\", \"long\", \"lat\", \"time\", \"sizeclass\", \"predator\"\n";
csvString += "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
csvString += "1, 1, 16, 3, 2, 6, 6, 205.5, 1, \"Ampelisca agassizi\", 1, \"Summer\", 60, \"Chandeleur Islands\", \"aabd\", 47.11, \"C2\", 348078.84, 3257617.25, 313, \"201-300\", \"Rhynchoconger flavus\"\n";
csvString += "2, 11, 2, 1, 1, 20, 15, 592.5, 6, \"Ampelisca sp. (abdita complex)\", 1, \"Summer\", 20, \"Chandeleur Islands\", \"aabd\", 47.11, \"C1\", 344445.31, 3323087.25, 144, \"26-50\", \"Halieutichthys aculeatus\"\n";
StudyImporterForSimons importer = new StudyImporterForSimons(new TestParserFactory(csvString), nodeFactory);
importStudy(importer);
assertNotNull(taxonIndex.findTaxonByName("Rhynchoconger flavus"));
assertNotNull(taxonIndex.findTaxonByName("Halieutichthys aculeatus"));
assertNotNull(taxonIndex.findTaxonByName("Ampelisca sp. (abdita complex)"));
assertNotNull(nodeFactory.findStudy("Simons 1997"));
assertNotNull(nodeFactory.findLocation(new LocationImpl(LAT_1, LONG_1, -60.0d, null)));
assertNotNull(nodeFactory.findLocation(new LocationImpl(LAT_2, LONG_2, -20.0d, null)));
assertNotNull(nodeFactory.findSeason("summer"));
Study foundStudy = nodeFactory.findStudy("Simons 1997");
assertNotNull(foundStudy);
for (Relationship rel : NodeUtil.getSpecimens(foundStudy)) {
Node specimen = rel.getEndNode();
Node speciesNode = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
String scientificName = (String) speciesNode.getProperty("name");
if ("Rhynchoconger flavus".equals(scientificName)) {
String seasonName = "summer";
String genusName = "Ampelisca sp. (abdita complex)";
double length = (201.0d + 300.0d) / 2.0d;
assertSpecimen(specimen, LONG_1, LAT_1, -60.0, seasonName, genusName, length);
Iterable<Relationship> ateRelationships = specimen.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
List<String> preyNames = new ArrayList<String>();
for (Relationship ateRel : ateRelationships) {
Node preyTaxonNode = ateRel.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS)).iterator().next().getEndNode();
preyNames.add(preyTaxonNode.getProperty(PropertyAndValueDictionary.NAME).toString());
}
assertThat(preyNames, hasItem("Ampelisca sp. (abdita complex)"));
assertThat(preyNames.contains("Ampelisca agassizi"), Is.is(true));
assertThat(preyNames.size(), Is.is(2));
} else if ("Halieutichthys aculeatus".equals(scientificName)) {
String genusName = "Ampelisca sp. (abdita complex)";
String seasonName = "summer";
double length = (26.0d + 50.0d) / 2.0d;
assertSpecimen(specimen, LONG_2, LAT_2, -20.0, seasonName, genusName, length);
} else if ("Ampelisca sp. (abdita complex)".equals(scientificName)) {
Node locationNode = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING).getEndNode();
assertNotNull(locationNode);
assertTrue(locationNode.hasProperty(LocationConstant.LONGITUDE));
assertTrue(locationNode.hasProperty(LocationConstant.ALTITUDE));
assertTrue(locationNode.hasProperty(LocationConstant.LATITUDE));
} else if ("Ampelisca agassizi".equals(scientificName)) {
assertPreySpecimen(specimen, LONG_1, LAT_1, -60.0);
} else {
fail("found predator with unexpected scientificName [" + scientificName + "]");
}
}
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class StudyImporterForTSVTest method assertStudyTitles.
public void assertStudyTitles(String element) {
final List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
final List<String> titles = new ArrayList<String>();
for (Study study : allStudies) {
titles.add(study.getTitle());
}
assertThat(titles, hasItem(element));
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class StudyImporterForStronaIT method importFirst200.
@Test
public void importFirst200() throws NodeFactoryException, StudyImporterException {
StudyImporter importer = new StudyImporterForStrona(new ParserFactoryLocal(), nodeFactory);
importer.setFilter(new ImportFilter() {
@Override
public boolean shouldImportRecord(Long recordNumber) {
return recordNumber < 200;
}
});
importStudy(importer);
List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
assertThat(allStudies.size(), is(1));
assertThat(taxonIndex.findTaxonByName("Aidablennius sphynx"), is(notNullValue()));
assertThat(taxonIndex.findTaxonByName("Acanthocephaloides incrassatus"), is(notNullValue()));
Study study = allStudies.get(0);
assertThat(study.getSource(), containsString(" Accessed at"));
assertThat(study.getCitation(), containsString("http://dx.doi.org/10.1890/12-1419.1"));
assertThat(study.getCitation(), containsString("Strona"));
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class NormalizerTest method doSingleImport.
@Test
public void doSingleImport() throws IOException, StudyImporterException {
importData(StudyImporterForSimons.class, new NodeFactoryNeo4j(getGraphDb()));
GraphDatabaseService graphService = getGraphDb();
Study study = getStudySingleton(graphService);
assertThat(study.getTitle(), is("Simons 1997"));
assertNotNull(graphService.getNodeById(1));
assertNotNull(graphService.getNodeById(200));
}
use of org.eol.globi.domain.Study in project eol-globi-data by jhpoelen.
the class StudyImporterForCruaud 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("cruaud", SOURCE, "http://dx.doi.org/10.1093/sysbio/sys068", null));
while (dataParser.getLine() != null) {
if (importFilter.shouldImportRecord((long) dataParser.getLastLineNumber())) {
try {
String parasiteName = StringUtils.trim(dataParser.getValueByLabel("Family and Species"));
String hostName = StringUtils.trim(dataParser.getValueByLabel("Natural host Ficus species"));
hostName = StringUtils.replace(hostName, "F.", "Ficus");
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);
String samplingLocation = StringUtils.trim(dataParser.getValueByLabel("Sampling location"));
if (getGeoNamesService().hasTermForLocale(samplingLocation)) {
LatLng pointForLocality = getGeoNamesService().findLatLng(samplingLocation);
if (pointForLocality == null) {
LOG.warn("no location associated with locality [" + samplingLocation + "]");
} else {
Location location = nodeFactory.getOrCreateLocation(new LocationImpl(pointForLocality.getLat(), pointForLocality.getLng(), null, null));
parasite.caughtIn(location);
host.caughtIn(location);
}
} else {
LOG.warn("no location associated with locality [" + samplingLocation + "]");
}
}
} catch (NodeFactoryException | NumberFormatException e) {
throw new StudyImporterException("failed to import line [" + (dataParser.lastLineNumber() + 1) + "]", e);
}
}
}
} catch (IOException e) {
throw new StudyImporterException("problem importing [" + RESOURCE_PATH + "]", e);
}
}
Aggregations