use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.
the class DatasetImporterForSzoboszlaiIT 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. https://doi.org/10.5061/dryad.nv5d2\",\n" + " \"doi\": \"https://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"), inStream -> inStream);
dataset.setConfig(config);
ParserFactory parserFactory = new ParserFactoryForDataset(dataset);
DatasetImporterForSzoboszlai importer = new DatasetImporterForSzoboszlai(parserFactory, nodeFactory);
importer.setDataset(dataset);
importStudy(importer);
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(getStudySingleton(getGraphDb()).getUnderlyingNode()), relationship -> {
Specimen specimenNode = new SpecimenNode(relationship.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.util.NodeTypeDirection 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()));
}
use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.
the class DatasetImporterForRSSLocalTest method importLocalMCZArchive.
@Test
public void importLocalMCZArchive() throws StudyImporterException, IOException {
DatasetImporter importer = new StudyImporterTestFactory(nodeFactory).instantiateImporter(DatasetImporterForRSS.class);
DatasetLocal dataset = new DatasetLocal(inStream -> inStream) {
@Override
public InputStream retrieve(URI resourceName) throws IOException {
if (resourceName.toString().endsWith("mapping.csv")) {
return IOUtils.toInputStream("provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id\n" + "found in association with,,interactsWith,http://purl.obolibrary.org/obo/RO_0002437", StandardCharsets.UTF_8);
} else {
return super.retrieve(resourceName);
}
}
};
URL resource = getClass().getResource("/org/eol/globi/data/rss/mcz_issue_659.zip");
assertNotNull(resource);
importDwCAViaRSS(importer, dataset, resource);
List<StudyNode> allStudies = NodeUtil.findAllStudies(getGraphDb());
assertThat(allStudies.size(), greaterThan(0));
Map<String, StudyNode> studyMap = new TreeMap<>();
for (StudyNode study : allStudies) {
studyMap.put(study.getExternalId(), study);
}
StudyNode study = studyMap.get("http://mczbase.mcz.harvard.edu/guid/MCZ:Mamm:61296");
assertThat(study.getExternalId(), is("http://mczbase.mcz.harvard.edu/guid/MCZ:Mamm:61296"));
TaxonNode taxonNode = (TaxonNode) taxonIndex.findTaxonByName("Grampus griseus");
Assert.assertNotNull(taxonNode);
Set<String> sourceTaxa = new TreeSet<>();
Set<String> targetTaxa = new TreeSet<>();
Set<String> targetCatalogNumbers = new TreeSet<>();
Set<String> sourceCatalogNumbers = new TreeSet<>();
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), relationship -> {
assertThat(relationship.getType().name(), is("COLLECTED"));
Specimen source = new SpecimenNode(relationship.getEndNode());
String sourceCatalogNumber = source.getProperty("catalogNumber");
if (StringUtils.isNotBlank(sourceCatalogNumber)) {
sourceCatalogNumbers.add(sourceCatalogNumber);
}
Relationship singleRelationship = ((SpecimenNode) source).getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(InteractType.INTERACTS_WITH), Direction.OUTGOING);
Specimen target = new SpecimenNode(singleRelationship.getEndNode());
String catalogNumber = target.getProperty("catalogNumber");
if (StringUtils.isNotBlank(catalogNumber)) {
targetCatalogNumbers.add(catalogNumber);
}
assertNotNull(target);
assertNotNull(source);
Node sourceOrigTaxon = ((SpecimenNode) source).getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS), Direction.OUTGOING).getEndNode();
Node targetOrigTaxon = ((SpecimenNode) target).getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS), Direction.OUTGOING).getEndNode();
sourceTaxa.add(new TaxonNode(sourceOrigTaxon).getName());
targetTaxa.add(new TaxonNode(targetOrigTaxon).getName());
});
assertThat(sourceTaxa, hasItem("Grampus griseus"));
assertThat(sourceCatalogNumbers, hasItem("61296"));
assertThat(targetTaxa, hasItem("Grampus griseus"));
assertThat(targetTaxa, hasItem("MCZ:Mamm:61298"));
assertThat(targetTaxa, Matchers.not(hasItem("MCZ:Mamm:61297")));
assertThat(targetCatalogNumbers, hasItem("61297"));
}
use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.
the class DatasetImporterForBioInfoTest method importAbout600Records.
@Test
public void importAbout600Records() throws StudyImporterException {
DatasetImporter importer = new StudyImporterTestFactory(nodeFactory).instantiateImporter((Class) DatasetImporterForBioInfo.class);
final List<String> msgs = new ArrayList<String>();
importer.setLogger(new ImportLogger() {
@Override
public void warn(LogContext ctx, String message) {
msgs.add(message);
}
@Override
public void info(LogContext ctx, String message) {
msgs.add(message);
}
@Override
public void severe(LogContext ctx, String message) {
msgs.add(message);
}
});
// limit the number of line to be imported to make test runs reasonably fast
importer.setFilter(recordNumber -> recordNumber < 1000 || recordNumber == 4585 || (recordNumber > 47310 && recordNumber < 47320) || (recordNumber > 24220 && recordNumber < 24340));
importStudy(importer);
StudyImpl study1 = new StudyImpl(TaxonomyProvider.BIO_INFO + "ref:153303");
study1.setExternalId("http://bioinfo.org.uk/html/b153303.htm");
Study vectorStudy = nodeFactory.findStudy(study1);
assertThat(vectorStudy, is(notNullValue()));
StudyImpl study2 = new StudyImpl(TaxonomyProvider.BIO_INFO + "ref:60527");
study2.setExternalId("http://bioinfo.org.uk/html/b60527.htm");
StudyNode study = (StudyNode) nodeFactory.findStudy(study2);
AtomicBoolean success = new AtomicBoolean(false);
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), relationship -> {
SpecimenNode specimen = new SpecimenNode(relationship.getEndNode());
String externalId = specimen.getExternalId();
assertThat(externalId, is(notNullValue()));
assertThat(externalId, CoreMatchers.containsString(TaxonomyProvider.BIO_INFO + "rel:"));
success.set(true);
});
assertTrue(success.get());
Result result = getGraphDb().execute("CYPHER 2.3 START taxon = node:taxons('*:*') MATCH taxon<-[:CLASSIFIED_AS]-specimen-[r]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon RETURN taxon.externalId + ' ' + lower(type(r)) + ' ' + targetTaxon.externalId as interaction");
List<String> interactions = new ArrayList<String>();
while (((ResourceIterator<Map<String, Object>>) result).hasNext()) {
Map<String, Object> next = ((ResourceIterator<Map<String, Object>>) result).next();
interactions.add((String) next.get("interaction"));
}
assertThat(interactions, CoreMatchers.hasItem("NBN:NHMSYS0000455771 interacts_with NBN:NBNSYS0000024890"));
assertThat(interactions, CoreMatchers.hasItem("NBN:NBNSYS0000030148 endoparasitoid_of NBN:NHMSYS0000502366"));
assertThat(interactions, CoreMatchers.hasItem("NBN:NHMSYS0000500943 has_endoparasitoid NBN:NBNSYS0000030148"));
assertThat(interactions, CoreMatchers.hasItem("bioinfo:taxon:160260 has_vector bioinfo:taxon:162065"));
assertThat(study.getTitle(), is("bioinfo:ref:60527"));
assertThat("found unexpected log messages: [" + StringUtils.join(msgs, "\n") + "]", msgs.size(), is(1));
assertThat(msgs.get(0), is("empty/no taxon name for bioinfo taxon id [149359] on line [4171]"));
}
use of org.eol.globi.util.NodeTypeDirection in project eol-globi-data by jhpoelen.
the class DatasetImporterForRSSLocalTest method importLocalArctosArchive.
@Test
public void importLocalArctosArchive() throws StudyImporterException, IOException {
URL resource = getClass().getResource("/org/eol/globi/data/rss/arctos_issue_461.zip");
importDwCViaRSS(resource);
List<StudyNode> allStudies = NodeUtil.findAllStudies(getGraphDb());
assertThat(allStudies.size(), greaterThan(0));
StudyNode study = allStudies.get(0);
TaxonNode taxonNode = (TaxonNode) taxonIndex.findTaxonByName("Anaxyrus cognatus");
Assert.assertNotNull(taxonNode);
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), relationship -> {
assertThat(relationship.getType().name(), is("COLLECTED"));
Specimen source = new SpecimenNode(relationship.getEndNode());
Relationship singleRelationship = ((SpecimenNode) source).getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(InteractType.INTERACTS_WITH), Direction.OUTGOING);
Specimen target = new SpecimenNode(singleRelationship.getEndNode());
assertNotNull(target);
assertNotNull(source);
Node sourceOrigTaxon = ((SpecimenNode) source).getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS), Direction.OUTGOING).getEndNode();
Node targetOrigTaxon = ((SpecimenNode) target).getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS), Direction.OUTGOING).getEndNode();
assertThat(new TaxonNode(sourceOrigTaxon).getName(), is("Anaxyrus cognatus"));
assertThat(new TaxonNode(targetOrigTaxon).getName(), is("Anaxyrus cognatus"));
});
}
Aggregations