use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.
the class ExporterMeasurementOrFact method doExportStudy.
@Override
public void doExportStudy(StudyNode study, ExportUtil.Appender writer, boolean includeHeader) throws IOException {
Map<String, String> properties = new TreeMap<String, String>();
AtomicReference<IOException> lastException = new AtomicReference<>();
RelationshipListener handler = collectedRel -> {
Node specimenNode = collectedRel.getEndNode();
if (isSpecimenClassified(specimenNode)) {
try {
writeMeasurements(writer, properties, specimenNode, collectedRel, study);
} catch (IOException ex) {
lastException.set(ex);
}
}
};
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
if (lastException.get() != null) {
throw lastException.get();
}
}
use of org.eol.globi.util.RelationshipListener 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/globalbioticinteractions/globalbioticinteractions/wiki/Nanopubs
StudyImpl study = new StudyImpl("some study", new DOI("123.23", "222"), "some study citation");
NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri"), inStream -> inStream));
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(new GraphServiceFactoryProxy(getGraphDb())).index();
NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j2(getGraphDb());
StudyImpl study1 = new StudyImpl("some study", new DOI("123.23", "222"), "come citation");
study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream));
StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
assertThat(interaction.getTitle(), is(someStudy.getTitle()));
RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
Set<Long> ids = new HashSet<>();
List<Long> idList = new ArrayList<>();
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(someStudy.getUnderlyingNode()), new RelationshipListener() {
@Override
public void on(Relationship specimen) {
assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(hasParticipant, Direction.INCOMING);
for (Relationship relationship : relationships) {
long id = relationship.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.util.RelationshipListener in project eol-globi-data by jhpoelen.
the class InteractionImporterTest method importWithLocalityAndLatLng.
@Test
public void importWithLocalityAndLatLng() throws StudyImporterException {
final InteractionListener listener = getAssertingInteractionImporter();
final TreeMap<String, String> link = new TreeMap<>();
link.put(SOURCE_TAXON_NAME, "donald");
link.put(SOURCE_TAXON_ID, "duck");
link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
link.put(TARGET_TAXON_NAME, "mini");
link.put(TARGET_TAXON_ID, "mouse");
link.put(LOCALITY_ID, "back:yard");
link.put(LOCALITY_NAME, "my back yard");
link.put(DECIMAL_LATITUDE, "12.2");
link.put(DECIMAL_LONGITUDE, "13.2");
link.put(REFERENCE_ID, "123");
link.put(DATASET_CITATION, "some source ref");
link.put(REFERENCE_CITATION, "");
link.put(REFERENCE_DOI, "doi:10.12/34");
listener.on(link);
AtomicBoolean foundSpecimen = new AtomicBoolean(false);
RelationshipListener someListener = relationship -> {
final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
LocationNode sampleLocation = someSpecimen.getSampleLocation();
assertThat(sampleLocation.getLatitude(), is(12.2d));
assertThat(sampleLocation.getLongitude(), is(13.2d));
assertThat(sampleLocation.getLocality(), is("my back yard"));
assertThat(sampleLocation.getLocalityId(), is("back:yard"));
foundSpecimen.set(true);
};
handleRelations(someListener, RelTypes.COLLECTED);
assertThat(foundSpecimen.get(), is(true));
}
use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.
the class InteractionImporterTest method importRefutingClaim.
@Test
public void importRefutingClaim() throws StudyImporterException {
final InteractionListener listener = getAssertingInteractionImporter();
final TreeMap<String, String> link = new TreeMap<>();
link.put(SOURCE_TAXON_NAME, "donald");
link.put(SOURCE_TAXON_ID, "duck");
link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
link.put(TARGET_TAXON_NAME, "mini");
link.put(TARGET_TAXON_ID, "mouse");
link.put(ARGUMENT_TYPE_ID, "https://en.wiktionary.org/wiki/refute");
link.put(REFERENCE_ID, "123");
link.put(DATASET_CITATION, "some source ref");
link.put(REFERENCE_CITATION, "");
link.put(REFERENCE_DOI, "doi:10.12/34");
listener.on(link);
AtomicBoolean foundSpecimen = new AtomicBoolean(false);
RelationshipListener relHandler = relationship -> {
final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.REFUTES)));
assertFalse(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
foundSpecimen.set(true);
};
handleRelations(relHandler, RelTypes.REFUTES);
assertThat(foundSpecimen.get(), is(true));
}
use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.
the class InteractionImporterTest method importWithSex.
@Test
public void importWithSex() throws StudyImporterException {
final InteractionListener listener = getAssertingInteractionImporter();
final TreeMap<String, String> link = new TreeMap<>();
link.put(SOURCE_TAXON_NAME, "donald");
link.put(SOURCE_SEX_NAME, "female");
link.put(SOURCE_SEX_ID, "some:female");
link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, InteractType.ATE.getIRI());
link.put(TARGET_TAXON_NAME, "mini");
link.put(TARGET_SEX_NAME, "male");
link.put(TARGET_SEX_ID, "some:male");
link.put(DATASET_CITATION, "some source ref");
link.put(REFERENCE_ID, "123");
link.put(REFERENCE_CITATION, "");
listener.on(link);
AtomicInteger foundSpecimen = new AtomicInteger(0);
RelationshipListener someListener = relationship -> {
final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(NodeUtil.asNeo4j(InteractType.ATE)));
if (someSpecimen.getUnderlyingNode().hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE))) {
assertThat(someSpecimen.getSex().getName(), is("female"));
assertThat(someSpecimen.getSex().getId(), is("some:female"));
} else {
assertThat(someSpecimen.getSex().getName(), is("male"));
assertThat(someSpecimen.getSex().getId(), is("some:male"));
}
foundSpecimen.incrementAndGet();
};
handleRelations(someListener, RelTypes.COLLECTED);
assertThat(foundSpecimen.get(), is(2));
}
Aggregations