use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class StudyImporterForSeltmannIT method importArchive.
protected void importArchive(String archiveName) throws StudyImporterException {
StudyImporterForSeltmann importer = new StudyImporterForSeltmann(null, nodeFactory);
importer.setDataset(new DatasetImpl(null, URI.create(ARCHIVE_URI_PREFIX + archiveName)));
importStudy(importer);
List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
for (Study allStudy : allStudies) {
assertThat(allStudy.getSource(), startsWith("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
assertThat(allStudy.getCitation(), is("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
Iterable<Relationship> specimens = NodeUtil.getSpecimens(allStudy);
for (Relationship specimen : specimens) {
Specimen spec = new SpecimenNode(specimen.getEndNode());
Term basisOfRecord = spec.getBasisOfRecord();
assertThat(basisOfRecord.getId(), either(is("TEST:PreservedSpecimen")).or(is("TEST:LabelObservation")));
assertThat(basisOfRecord.getName(), either(is("PreservedSpecimen")).or(is("LabelObservation")));
}
}
assertThat(taxonIndex.findTaxonByName("Megandrena mentzeliae"), is(notNullValue()));
assertThat(taxonIndex.findTaxonByName("Mentzelia tricuspis"), is(notNullValue()));
}
use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class StudyImporterForSzoboszlaiIT method importAll.
@Test
public void importAll() throws StudyImporterException, IOException {
JsonNode config = new ObjectMapper().readTree("{ \"citation\": \"Szoboszlai AI, Thayer JA, Wood SA, Sydeman WJ, Koehn LE (2015) Data from: Forage species in predator diets: synthesis of data from the California Current. Dryad Digital Repository. http://dx.doi.org/10.5061/dryad.nv5d2\",\n" + " \"doi\": \"http://dx.doi.org/10.5061/dryad.nv5d2\",\n" + " \"format\": \"szoboszlai\",\n" + " \"resources\": {\n" + " \"links\": \"http://datadryad.org/bitstream/handle/10255/dryad.94536/CCPDDlinkdata_v1.csv\",\n" + " \"shapes\": \"http://datadryad.org/bitstream/handle/10255/dryad.94535/CCPDDlocationdata_v1.zip\"\n" + " }\n" + "}");
DatasetImpl dataset = new DatasetImpl("someRepo", URI.create("http://example.com"));
dataset.setConfig(config);
ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
StudyImporterForSzoboszlai importer = new StudyImporterForSzoboszlai(parserFactory, nodeFactory);
importer.setDataset(dataset);
importStudy(importer);
List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
assertThat(allStudies.size(), is(not(0)));
Study firstStudy = allStudies.get(0);
Iterable<Relationship> specimens = NodeUtil.getSpecimens(firstStudy);
for (Relationship specimen : specimens) {
Specimen specimenNode = new SpecimenNode(specimen.getEndNode());
Location sampleLocation = specimenNode.getSampleLocation();
assertThat(sampleLocation, is(notNullValue()));
assertThat(sampleLocation.getLatitude(), is(notNullValue()));
assertThat(sampleLocation.getLongitude(), is(notNullValue()));
}
assertThat(taxonIndex.findTaxonByName("Thunnus thynnus"), is(notNullValue()));
assertThat(nodeFactory.findLocation(new LocationImpl(34.00824202376044, -120.72716166720323, null, null)), is(notNullValue()));
}
use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class IndexInteractionsTest method indexInteractions.
@Test
public void indexInteractions() throws NodeFactoryException {
TaxonIndex taxonIndex = getOrCreateTaxonIndex();
// see https://github.com/jhpoelen/eol-globi-data/wiki/Nanopubs
StudyImpl study = new StudyImpl("some study", "some source", "http://doi.org/123.23/222", "some study citation");
NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri")));
Study interaction = factory.getOrCreateStudy(study);
TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
TaxonImpl mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
Taxon mickeyTaxonNCBI = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonNCBI, getGraphDb(), RelTypes.SAME_AS);
Specimen mickey = factory.createSpecimen(interaction, mickeyTaxon);
mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxon));
donald.ate(mickey);
new IndexInteractions(getGraphDb()).link();
NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j(getGraphDb());
StudyImpl study1 = new StudyImpl("some study", "some source", null, "come citation");
study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri")));
StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
assertThat(interaction.getTitle(), is(someStudy.getTitle()));
Iterable<Relationship> specimens = NodeUtil.getSpecimens(someStudy);
RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
Set<Long> ids = new HashSet<>();
List<Long> idList = new ArrayList<>();
for (Relationship specimen : specimens) {
assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
Relationship singleRelationship = specimen.getEndNode().getSingleRelationship(hasParticipant, Direction.INCOMING);
long id = singleRelationship.getStartNode().getId();
ids.add(id);
idList.add(id);
}
assertThat(ids.size(), Is.is(1));
assertThat(idList.size(), Is.is(2));
Node interactionNode = getGraphDb().getNodeById(idList.get(0));
assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.DERIVED_FROM)));
assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.ACCESSED_AT)));
}
use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class StudyImporterForBlewett method addPreyForPredator.
private List<Specimen> addPreyForPredator(String[] header, String[] line, Study study) throws NodeFactoryException {
List<Specimen> preyItems = new ArrayList<Specimen>();
int preyColumn = 4;
for (int i = preyColumn; i < header.length; i++) {
if (i < line.length) {
String preyCountString = line[i];
if (preyCountString.trim().length() > 0) {
try {
int preyCount = Integer.parseInt(preyCountString);
String preyName = header[i];
for (int j = 0; j < preyCount; j++) {
Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(preyName, null));
preyItems.add(preySpecimen);
}
} catch (NumberFormatException e) {
getLogger().warn(study, "failed to parse prey count line/column:");
}
}
}
}
return preyItems;
}
use of org.eol.globi.domain.Specimen in project eol-globi-data by jhpoelen.
the class StudyImporterForBrose method addInteractionForConsumer.
private void addInteractionForConsumer(LabeledCSVParser parser, Study localStudy, String predatorName) throws NodeFactoryException, StudyImporterException {
Location location = null;
String locationString = parser.getValueByLabel("Geographic location");
LatLng latLng = LOC_MAP.get(StringUtils.trim(locationString));
if (latLng == null) {
getLogger().warn(localStudy, "failed to find location for [" + locationString + "]");
} else {
location = nodeFactory.getOrCreateLocation(new LocationImpl(latLng.getLat(), latLng.getLng(), null, null));
String habitat = StringUtils.join(parser.getValueByLabel("General habitat"), " ", parser.getValueByLabel("Specific habitat"));
String habitatId = "BROSE:" + habitat.replaceAll("\\W", "_");
nodeFactory.getOrCreateEnvironments(location, habitatId, habitat);
}
Specimen consumer = nodeFactory.createSpecimen(localStudy, new TaxonImpl(predatorName, null));
consumer.caughtIn(location);
addLifeStage(parser, consumer, "Lifestage consumer");
String name = getName(parser, "Taxonomy resource", "Common name(s) resource");
if (StringUtils.isBlank(name) || StringUtils.length(name) < 2) {
String message = "found (near) empty prey name on line [" + parser.lastLineNumber() + "] + [" + name + "]";
LOG.warn(message);
getLogger().warn(localStudy, message);
} else {
Specimen resource = nodeFactory.createSpecimen(localStudy, new TaxonImpl(name, null));
resource.caughtIn(location);
addLifeStage(parser, resource, "Lifestage - resource");
String interactionType = parser.getValueByLabel("Type of feeding interaction");
Map<String, InteractType> typeMapping = new HashMap<String, InteractType>() {
{
put("predacious", InteractType.PREYS_UPON);
put("predator", InteractType.PREYS_UPON);
put("herbivorous", InteractType.ATE);
put("parasitoid", InteractType.PARASITE_OF);
put("parasitic", InteractType.PARASITE_OF);
put("bacterivorous", InteractType.ATE);
put("omnivore", InteractType.ATE);
put("detritivorous", InteractType.ATE);
put("pathogen", InteractType.PATHOGEN_OF);
}
};
InteractType interactType = typeMapping.get(interactionType);
if (interactType == null) {
throw new StudyImporterException("found unsupported interaction type [" + interactionType + "]");
}
consumer.interactsWith(resource, interactType);
}
}
Aggregations