use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.
the class InteractionImporterTest method assertSymbiotaDateString.
public void assertSymbiotaDateString(String symbiotaTime, String expectedUTC) throws StudyImporterException {
final InteractionListener listener = getAssertingInteractionImporter();
final TreeMap<String, String> link = new TreeMap<>();
link.put(SOURCE_TAXON_NAME, "donald");
link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
link.put(TARGET_TAXON_NAME, "mini");
link.put(DatasetImporterForMetaTable.EVENT_DATE, symbiotaTime);
link.put(REFERENCE_ID, "123");
link.put(DATASET_CITATION, "some source ref");
link.put(REFERENCE_CITATION, "");
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)));
try {
Date eventDate = nodeFactory.getUnixEpochProperty(someSpecimen);
assertThat(DateUtil.printDate(eventDate), is(expectedUTC));
} catch (NodeFactoryException e) {
fail(e.getMessage());
}
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 StudyTest method populateStudy.
@Test
public void populateStudy() throws NodeFactoryException {
Study study = nodeFactory.createStudy(new StudyImpl("Our first study", null, null));
taxonIndex.getOrCreateTaxon(new TaxonImpl(CARCHARODON_CARCHARIAS, null));
Specimen goldFish = nodeFactory.createSpecimen(study, new TaxonImpl(CARASSIUS_AURATUS_AURATUS, null));
Specimen shark = nodeFactory.createSpecimen(study, new TaxonImpl(CARCHARODON_CARCHARIAS, null));
Specimen fuzzyShark = nodeFactory.createSpecimen(study, new TaxonImpl(CARCHARODON, null));
shark.ate(goldFish);
fuzzyShark.ate(goldFish);
Location bolinasBay = nodeFactory.getOrCreateLocation(new LocationImpl(12.2d, 12.1d, -100.0d, null));
shark.caughtIn(bolinasBay);
Season winter = nodeFactory.createSeason("winter");
shark.caughtDuring(winter);
shark.setLengthInMm(1.2d);
resolveNames();
StudyNode foundStudy = getStudySingleton(getGraphDb());
assertEquals(study.getTitle(), foundStudy.getTitle());
RelationshipListener handler = rel -> {
Specimen specimen = new SpecimenNode(rel.getEndNode());
Relationship caughtDuringRel = rel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CAUGHT_DURING), Direction.OUTGOING);
if (caughtDuringRel != null) {
Node seasonNode = caughtDuringRel.getEndNode();
if (seasonNode != null && seasonNode.getProperty(SeasonNode.TITLE).equals("winter")) {
Relationship next = NodeUtil.getClassifications(specimen).iterator().next();
Node endNode = next.getEndNode();
String speciesName = (String) endNode.getProperty("name");
assertEquals(CARCHARODON_CARCHARIAS, speciesName);
assertEquals(new Double(-100.0d), specimen.getSampleLocation().getAltitude());
assertEquals(new Double(1.2d), specimen.getLengthInMm());
} else {
fail("expected to findNamespaces a specimen");
}
} else if (specimen.equals(goldFish)) {
Node genusNode = NodeUtil.getClassifications(specimen).iterator().next().getEndNode();
assertEquals(CARASSIUS_AURATUS_AURATUS, genusNode.getProperty("name"));
} else if (specimen.equals(fuzzyShark)) {
Node genusNode = NodeUtil.getClassifications(specimen).iterator().next().getEndNode();
assertEquals(CARCHARODON, genusNode.getProperty("name"));
} else {
fail("found unexpected specimen [" + specimen + "] in study");
}
};
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(foundStudy.getUnderlyingNode()), handler);
}
use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForBlewettTest method importLines.
@Test
public void importLines() throws StudyImporterException {
String predatorPreyMapping = "\"Collection #\",\"Sp#\",\"Standard Length\",\"ID\",\"Far duoraum\",\"Cal sapidus\",\"Unid fish\",\"Anchoa spp\",\"Mug gyrans\",\"Bai chrysoura\",\"Portunus spp\",\"Bivalves\",\"Portunidae\",\"Lag rhomboides\",\"Xanthidae\",\"Palaemonidae\",\"Eucinostomus spp\",\"Mugil spp\",\"Alpheidae\",\"Atherinidae\",\"Syn foetens\",\"Ort chrysoptera\",\"Snails\",\"Euc gula\",\"Cynoscion spp\",\"Cyp. Variegatus\",\"Fun majalis\",\"Poe latipinna\",\"Unid crab\",\"Har jaguana\",\"Arm mierii\",\"Fun grandis\",\"Mic gulosus\",\"Ari felis\",\"Clupeidae\",\"Fundulus spp\",\"Diapterus/Eugerres spp\",\"Isopods\",\"Cyn nebulosus\",\"Opi oglinum\",\"Flo carpio\",\"Luc parva\",\"Uca spp\",\"Majidae\",\"Mug cephalus\",\"Squ empusa\",\"Opi robinsi\",\"Ariidae\",\"Sci ocellatus\",\"Unid shrimp\",\"Uca thayeri\",\"Grapsidae\",\"Lei xanthurus\",\"Elo saurus\",\"Brevoortia spp\"\n" + "\"CHD01101502\",1,549,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHD01102504\",1,548,\"E\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHD01102504\",2,550,,3,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHM000152\",1,580,\"E\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHM000152\",2,556,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
String dateLocationString = "\"Collection #\",\"Longitude\",\"Latitude\",\"Time\",\"Date\",\"Temperature\",\"Salinity\"\n" + "\"CHD01101502\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHD01102504\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHM000151\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHM000152\",-82.103833,26.651833,12:40:00,1-Mar-00,24.8,30.3\n" + "\"CHM000153\",-82.087333,26.644833,13:40:00,1-Mar-00,25.1,30.1\n" + "\"CHM000154\",-82.083167,26.671167,14:40:00,1-Mar-00,26,30.4\n" + "\"CHM000175\",-82.197833,26.688167,10:00:00,8-Mar-00,22.2,35.05\n" + "\"CHM000176\",-82.191333,26.667333,11:00:00,8-Mar-00,22.7,35.25";
final TestParserFactory preyPredatorFactory = new TestParserFactory(predatorPreyMapping);
final TestParserFactory dateLocationFactory = new TestParserFactory(dateLocationString);
ParserFactory testFactory = (studyResource, characterEncoding) -> {
LabeledCSVParser parser;
if (studyResource.toString().contains("abundance")) {
parser = preyPredatorFactory.createParser(studyResource, characterEncoding);
} else {
parser = dateLocationFactory.createParser(studyResource, characterEncoding);
}
return parser;
};
DatasetImporter importer = new StudyImporterTestFactory(testFactory, nodeFactory).instantiateImporter(DatasetImporterForBlewett.class);
importStudy(importer);
StudyNode study = getStudySingleton(getGraphDb());
AtomicBoolean success = new AtomicBoolean(false);
RelationshipListener handler1 = collectedRel -> {
Date unixEpochProperty = null;
try {
unixEpochProperty = nodeFactory.getUnixEpochProperty(new SpecimenNode(collectedRel.getEndNode()));
} catch (NodeFactoryException e) {
fail(e.getMessage());
}
assertThat(unixEpochProperty, is(not(nullValue())));
String actual = dateToString(unixEpochProperty);
Node predatorNode = collectedRel.getEndNode();
if (StringUtils.equals(actual, "2000-03-01T10:55:00.000-06:00") && predatorNode.hasProperty(SpecimenConstant.LIFE_STAGE_LABEL) && predatorNode.hasRelationship(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING)) {
assertThat(predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_LABEL), is("post-juvenile adult stage"));
assertThat(predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_ID), is("UBERON:0000113"));
Node predatorTaxonNode = predatorNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
assertThat(predatorTaxonNode.getProperty(PropertyAndValueDictionary.NAME), is("Centropomus undecimalis"));
Set<String> preyNames = new HashSet<>();
Iterable<Relationship> ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
for (Relationship preyRels : ate) {
Node preyNode = preyRels.getEndNode();
assertThat(preyNode, is(not(nullValue())));
Node taxonNode = preyNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
assertThat(taxonNode, is(not(nullValue())));
preyNames.add((String) taxonNode.getProperty(PropertyAndValueDictionary.NAME));
}
assertThat(preyNames, hasItem("Lag rhomboides"));
success.set(true);
}
};
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler1);
assertTrue(success.get());
success.set(false);
RelationshipListener handler2 = collectedRel -> {
Node predatorNode = collectedRel.getEndNode();
if (predatorNode.hasProperty(SpecimenConstant.LENGTH_IN_MM) && (Double) predatorNode.getProperty(SpecimenConstant.LENGTH_IN_MM) == 548.0) {
Iterable<Relationship> ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
assertThat(ate.iterator().hasNext(), is(false));
Location location = null;
try {
location = nodeFactory.findLocation(new LocationImpl(26.651833, -82.103833, 0.0, null));
} catch (NodeFactoryException e) {
fail(e.getMessage());
}
assertThat(location, is(not(nullValue())));
Iterable<Relationship> specimenCaughtHere = NodeUtil.getSpecimenCaughtHere(location);
Iterator<Relationship> iterator = specimenCaughtHere.iterator();
assertThat(iterator.hasNext(), is(true));
iterator.next();
assertThat(iterator.hasNext(), is(true));
iterator.next();
assertThat(iterator.hasNext(), is(true));
iterator.next();
assertThat(iterator.hasNext(), is(false));
success.set(true);
}
};
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler2);
assertTrue(success.get());
}
use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForCookTest method importFirstFewLines.
@Test
public void importFirstFewLines() throws IOException, NodeFactoryException, StudyImporterException {
String firstFiveLines = "\"Date\",\"Individual\",\"Fish Length\",\"Infected\",\"Iso 1\",\"Iso 2\",\"Iso 3\",\"Iso 4 \",\"Iso 5\",\"Iso #\",,\n" + "8/10/2010,22,15.6,1,\"NA\",\"NA\",0,0,0,2,,\"Notes: All fish collected were Atlantic Croaker (Micropogonias undulatus) and measured in total length (cm). Isopods collected were Cymothoa excisa. For the Infected column 1= infected and 0= not infected. Numbers for the isopods are total length in cm and the Iso# represents the number of isopods found per fish. \"\n" + "8/10/2010,1,14.7,1,1.6,0.67,0,0,0,2,,\n" + "8/10/2010,5,14.2,1,1.53,0.7,0,0,0,2,,\n" + "8/10/2010,2,13.2,1,1.42,0.71,0.52,0.45,0,4,,\n";
DatasetImporterForCook importer = new DatasetImporterForCook(new TestParserFactory(firstFiveLines), nodeFactory);
importStudy(importer);
StudyNode study = getStudySingleton(getGraphDb());
Taxon hostTaxon = taxonIndex.findTaxonByName("Micropogonias undulatus");
assertThat(hostTaxon, is(notNullValue()));
Taxon parasiteTaxon = taxonIndex.findTaxonByName("Cymothoa excisa");
assertThat(parasiteTaxon, is(notNullValue()));
assertThat("missing location", nodeFactory.findLocation(new LocationImpl(27.85, -(97.0 + 8.0 / 60.0), -3.0, null)), is(notNullValue()));
AtomicInteger count = new AtomicInteger(0);
AtomicBoolean foundFirstHost = new AtomicBoolean(false);
RelationshipListener handler = relationship -> {
assertThat(relationship.getProperty(SpecimenConstant.EVENT_DATE), is(notNullValue()));
Node specimen = relationship.getEndNode();
if (specimen.hasProperty(SpecimenConstant.LENGTH_IN_MM)) {
Object property = specimen.getProperty(SpecimenConstant.LENGTH_IN_MM);
if (new Double(156.0).equals(property)) {
assertTaxonClassification(specimen, ((NodeBacked) hostTaxon).getUnderlyingNode());
foundFirstHost.set(true);
Iterable<Relationship> parasiteRel = specimen.getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(InteractType.PARASITE_OF));
for (Relationship rel : parasiteRel) {
Node parasite = rel.getStartNode();
assertThat(parasite.hasProperty(SpecimenConstant.LENGTH_IN_MM), is(false));
assertTaxonClassification(parasite, ((NodeBacked) parasiteTaxon).getUnderlyingNode());
}
}
}
count.incrementAndGet();
};
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
assertThat(count.get(), is(14));
assertThat(foundFirstHost.get(), is(true));
}
use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.
the class DatasetImporterForBioInfoTest method parseSomeRelations.
@Test
public void parseSomeRelations() throws IOException, StudyImporterException {
assertThat(taxonIndex.findTaxonByName("Homo sapiens"), is(nullValue()));
LabeledCSVParser labeledCSVParser = createParser(RELATIONS_STRING);
DatasetImporterForBioInfo importer = new DatasetImporterForBioInfo(new ParserFactoryLocal(), nodeFactory);
importer.createRelations(labeledCSVParser, new TreeMap<String, String>() {
{
put("60527", "citation A");
put("60536", "citation B");
}
}, new TreeMap<>());
resolveNames();
StudyImpl study2 = new StudyImpl(TaxonomyProvider.BIO_INFO + "ref:60536");
study2.setExternalId("http://bioinfo.org.uk/html/b60536.htm");
Study study = nodeFactory.findStudy(study2);
assertNotNull(study);
assertThat(study.getExternalId(), is("http://bioinfo.org.uk/html/b60536.htm"));
assertNull(nodeFactory.findStudy(new StudyImpl(TaxonomyProvider.BIO_INFO + "ref:bla")));
StudyImpl study3 = new StudyImpl(TaxonomyProvider.BIO_INFO + "ref:60527");
study3.setExternalId("http://bioinfo.org.uk/html/b60527.htm");
StudyNode study1 = (StudyNode) nodeFactory.findStudy(study3);
assertThat(study1.getCitation(), is("citation A"));
assertThat(study1, is(notNullValue()));
List<Node> specimenList = new ArrayList<Node>();
RelationshipListener handler = relationship -> {
assertThat(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING), is(notNullValue()));
assertThat(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(InteractType.INTERACTS_WITH), Direction.OUTGOING), is(notNullValue()));
assertThat(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(InteractType.INTERACTS_WITH), Direction.INCOMING), is(notNullValue()));
assertThat(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(InteractType.INTERACTS_WITH), Direction.INCOMING), is(notNullValue()));
specimenList.add(relationship.getEndNode());
};
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study1.getUnderlyingNode()), handler);
assertThat(specimenList.size(), is(16));
Relationship classifiedAs = specimenList.get(0).getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
assertThat(classifiedAs, is(notNullValue()));
assertThat((String) classifiedAs.getEndNode().getProperty(PropertyAndValueDictionary.EXTERNAL_ID), startsWith("NBN:NBNSYS"));
assertThat(specimenList.get(1).getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING), is(notNullValue()));
assertThat(taxonIndex.findTaxonById(TaxonomyProvider.NBN.getIdPrefix() + "NBNSYS0000024889"), is(notNullValue()));
assertThat(taxonIndex.findTaxonById(TaxonomyProvider.NBN.getIdPrefix() + "NBNSYS0000024891"), is(notNullValue()));
}
Aggregations