Search in sources :

Example 6 with NodeTypeDirection

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()));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) LocationImpl(org.eol.globi.domain.LocationImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) SpecimenNode(org.eol.globi.domain.SpecimenNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 7 with NodeTypeDirection

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()));
}
Also used : CSVTSVUtil(org.eol.globi.util.CSVTSVUtil) CoreMatchers(org.hamcrest.CoreMatchers) ResourceIterator(org.neo4j.graphdb.ResourceIterator) LogContext(org.eol.globi.domain.LogContext) NodeUtil(org.eol.globi.util.NodeUtil) Direction(org.neo4j.graphdb.Direction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StringUtils(org.apache.commons.lang3.StringUtils) RelTypes(org.eol.globi.domain.RelTypes) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) ArrayList(java.util.ArrayList) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) RelationshipListener(org.eol.globi.util.RelationshipListener) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) TaxonomyProvider(org.eol.globi.domain.TaxonomyProvider) Taxon(org.eol.globi.domain.Taxon) Result(org.neo4j.graphdb.Result) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) Assert.assertNull(org.junit.Assert.assertNull) StringReader(java.io.StringReader) TreeMap(java.util.TreeMap) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) SpecimenNode(org.eol.globi.domain.SpecimenNode) Study(org.eol.globi.domain.Study) Study(org.eol.globi.domain.Study) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) StudyImpl(org.eol.globi.domain.StudyImpl) ArrayList(java.util.ArrayList) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 8 with NodeTypeDirection

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"));
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) TaxonNode(org.eol.globi.domain.TaxonNode) TreeMap(java.util.TreeMap) SpecimenNode(org.eol.globi.domain.SpecimenNode) DatasetLocal(org.eol.globi.service.DatasetLocal) URI(java.net.URI) URL(java.net.URL) StudyNode(org.eol.globi.domain.StudyNode) Specimen(org.eol.globi.domain.Specimen) TreeSet(java.util.TreeSet) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 9 with NodeTypeDirection

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]"));
}
Also used : Study(org.eol.globi.domain.Study) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) ArrayList(java.util.ArrayList) StudyImpl(org.eol.globi.domain.StudyImpl) LogContext(org.eol.globi.domain.LogContext) SpecimenNode(org.eol.globi.domain.SpecimenNode) StudyNode(org.eol.globi.domain.StudyNode) Result(org.neo4j.graphdb.Result) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Test(org.junit.Test)

Example 10 with NodeTypeDirection

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"));
    });
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonNode(org.eol.globi.domain.TaxonNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Relationship(org.neo4j.graphdb.Relationship) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) TaxonNode(org.eol.globi.domain.TaxonNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) URL(java.net.URL) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Aggregations

NodeTypeDirection (org.eol.globi.util.NodeTypeDirection)29 StudyNode (org.eol.globi.domain.StudyNode)25 Node (org.neo4j.graphdb.Node)21 Relationship (org.neo4j.graphdb.Relationship)20 Test (org.junit.Test)19 NodeUtil (org.eol.globi.util.NodeUtil)16 RelationshipListener (org.eol.globi.util.RelationshipListener)16 SpecimenNode (org.eol.globi.domain.SpecimenNode)15 Direction (org.neo4j.graphdb.Direction)14 RelTypes (org.eol.globi.domain.RelTypes)12 Specimen (org.eol.globi.domain.Specimen)10 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 TaxonNode (org.eol.globi.domain.TaxonNode)9 IOException (java.io.IOException)8 InteractType (org.eol.globi.domain.InteractType)8 Is.is (org.hamcrest.core.Is.is)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Study (org.eol.globi.domain.Study)7 Assert.assertTrue (org.junit.Assert.assertTrue)7