Search in sources :

Example 1 with SpecimenNode

use of org.eol.globi.domain.SpecimenNode in project eol-globi-data by jhpoelen.

the class StudyImporterForGoMexSI2IT method assertThatSomeDataIsImported.

private static void assertThatSomeDataIsImported(NodeFactory nodeFactory, TaxonIndex taxonIndex) throws StudyImporterException, NodeFactoryException {
    Study study = nodeFactory.findStudy("Divita et al 1983");
    assertSpecimenProperties(((NodeBacked) study).getUnderlyingNode().getGraphDatabase());
    assertNotNull(study);
    assertThat(study.getTitle(), is("Divita et al 1983"));
    assertThat(study.getExternalId(), is(ExternalIdUtil.urlForExternalId("GAME:2689")));
    assertThat(study.getCitation(), is("Regina Divita, Mischelle Creel, Peter Sheridan. 1983. Foods of coastal fishes during brown shrimp Penaeus aztecus, migration from Texas estuaries (June - July 1981)."));
    assertNotNull(nodeFactory.findStudy("Beaumariage 1973"));
    assertNotNull(nodeFactory.findStudy("Baughman, 1943"));
    assertNotNull(taxonIndex.findTaxonByName("Chloroscombrus chrysurus"));
    assertNotNull(taxonIndex.findTaxonByName("Micropogonias undulatus"));
    assertNotNull(taxonIndex.findTaxonByName("Amphipoda"));
    assertNotNull(taxonIndex.findTaxonByName("Crustacea"));
    Taxon taxon = taxonIndex.findTaxonByName("Scomberomorus cavalla");
    List<String> preyList = new ArrayList<String>();
    final List<String> titles = new ArrayList<String>();
    Iterable<Relationship> classifiedAsRels = ((NodeBacked) taxon).getUnderlyingNode().getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
    int count = 0;
    for (Relationship classifiedAsRel : classifiedAsRels) {
        Node predatorSpecimen = classifiedAsRel.getStartNode();
        Specimen predator = new SpecimenNode(predatorSpecimen);
        Iterable<Relationship> stomachContents = NodeUtil.getStomachContents(predator);
        for (Relationship prey : stomachContents) {
            Relationship singleRelationship = prey.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
            preyList.add((String) singleRelationship.getEndNode().getProperty("name"));
        }
        count++;
        Relationship collectedBy = predatorSpecimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED), Direction.INCOMING);
        assertThat(collectedBy, is(notNullValue()));
        String title = (String) collectedBy.getStartNode().getProperty("title");
        titles.add(title);
    }
    assertThat(count > 7, is(true));
    assertThat(preyList, hasItem("Organic matter"));
    assertThat(preyList, hasItem("Triglidae"));
    assertThat(preyList, hasItem("Sparidae"));
    assertThat(titles, hasItem("Beaumariage 1973"));
    assertThat(titles, hasItem("Blanton et al 1972"));
    assertNotNull(taxon);
    final String footprintWKT = WKT_FOOTPRINT2;
    LocationImpl expectedLocation = new LocationImpl(29.346953, -92.980614, -13.641, footprintWKT);
    expectedLocation.setLocality("Louisiana inner continental shelf");
    Location location = nodeFactory.findLocation(expectedLocation);
    assertThat(location, is(notNullValue()));
    assertThat(location.getFootprintWKT(), is(footprintWKT));
    assertThat(location.getLocality(), is("Louisiana inner continental shelf"));
    assertNotNull(location);
    List<Environment> environments = location.getEnvironments();
    assertThat(environments.size(), not(is(0)));
    assertThat(environments.get(0).getExternalId(), is("http://cmecscatalog.org/classification/aquaticSetting/13"));
    assertThat(environments.get(0).getName(), is("Marine Nearshore Subtidal"));
    assertNotNull(nodeFactory.findStudy("GoMexSI"));
}
Also used : Study(org.eol.globi.domain.Study) Taxon(org.eol.globi.domain.Taxon) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) ArrayList(java.util.ArrayList) SpecimenNode(org.eol.globi.domain.SpecimenNode) Specimen(org.eol.globi.domain.Specimen) NodeBacked(org.eol.globi.domain.NodeBacked) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) Environment(org.eol.globi.domain.Environment) Location(org.eol.globi.domain.Location)

Example 2 with SpecimenNode

use of org.eol.globi.domain.SpecimenNode in project eol-globi-data by jhpoelen.

the class StudyImporterForBioInfoTest method importAbout600Records.

@Test
public void importAbout600Records() throws StudyImporterException {
    StudyImporter importer = new StudyImporterTestFactory(nodeFactory).instantiateImporter((Class) StudyImporterForBioInfo.class);
    final List<String> msgs = new ArrayList<String>();
    importer.setLogger(new ImportLogger() {

        @Override
        public void warn(LogContext study, String message) {
            msgs.add(message);
        }

        @Override
        public void info(LogContext study, String message) {
            msgs.add(message);
        }

        @Override
        public void severe(LogContext study, 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);
    Study vectorStudy = nodeFactory.findStudy(TaxonomyProvider.BIO_INFO + "ref:153303");
    assertThat(vectorStudy, is(notNullValue()));
    Study study = nodeFactory.findStudy(TaxonomyProvider.BIO_INFO + "ref:60527");
    for (Relationship collectedRel : NodeUtil.getSpecimens(study)) {
        SpecimenNode specimen = new SpecimenNode(collectedRel.getEndNode());
        String externalId = specimen.getExternalId();
        assertThat(externalId, is(notNullValue()));
        assertThat(externalId, containsString(TaxonomyProvider.BIO_INFO + "rel:"));
    }
    ExecutionEngine engine = new ExecutionEngine(getGraphDb());
    ExecutionResult result = engine.execute("START taxon = node:taxons('*:*') MATCH taxon<-[:CLASSIFIED_AS]-specimen-[r]->targetSpecimen-[:CLASSIFIED_AS]->targetTaxon RETURN taxon.externalId + ' ' + lower(type(r)) + ' ' + targetTaxon.externalId as interaction");
    ResourceIterator<Map<String, Object>> iterator = result.iterator();
    List<String> interactions = new ArrayList<String>();
    while (iterator.hasNext()) {
        Map<String, Object> next = iterator.next();
        interactions.add((String) next.get("interaction"));
    }
    assertThat(interactions, hasItem("NBN:NHMSYS0000455771 interacts_with NBN:NBNSYS0000024890"));
    assertThat(interactions, hasItem("NBN:NBNSYS0000030148 endoparasitoid_of NBN:NHMSYS0000502366"));
    assertThat(interactions, hasItem("NBN:NHMSYS0000500943 has_endoparasitoid NBN:NBNSYS0000030148"));
    assertThat(interactions, hasItem("bioinfo:taxon:160260 has_vector bioinfo:taxon:162065"));
    assertThat(study.getTitle(), is("bioinfo:ref:60527"));
    assertThat(study.getSource(), is("Food Webs and Species Interactions in the Biodiversity of UK and Ireland (Online). 2015. Data provided by Malcolm Storey. Also available from http://bioinfo.org.uk."));
    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) ArrayList(java.util.ArrayList) LogContext(org.eol.globi.domain.LogContext) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) SpecimenNode(org.eol.globi.domain.SpecimenNode) ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) Relationship(org.neo4j.graphdb.Relationship) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with SpecimenNode

use of org.eol.globi.domain.SpecimenNode in project eol-globi-data by jhpoelen.

the class ExporterRDF method writeParticipantStatements.

public void writeParticipantStatements(Writer writer, Relationship ixnR, Node participant1) throws IOException {
    writeStatement(writer, Arrays.asList(blankNode(ixnR), iriNode(HAS_PARTICIPANT), blankNode(participant1)));
    writeStatement(writer, Arrays.asList(blankNode(participant1), iriNode(HAS_TYPE), iriNode(ORGANISM)));
    writeStatements(writer, taxonOfSpecimen(participant1));
    LocationNode location = new SpecimenNode(participant1).getSampleLocation();
    if (location != null) {
        for (Environment env : location.getEnvironments()) {
            String envoId = ExternalIdUtil.urlForExternalId(env.getExternalId());
            if (StringUtils.isNotBlank(envoId)) {
                writeStatement(writer, Arrays.asList(blankNode(participant1), iriNode(OCCURS_IN), iriNode(envoId)));
            }
        }
    }
}
Also used : LocationNode(org.eol.globi.domain.LocationNode) Environment(org.eol.globi.domain.Environment) SpecimenNode(org.eol.globi.domain.SpecimenNode)

Example 4 with SpecimenNode

use of org.eol.globi.domain.SpecimenNode in project eol-globi-data by jhpoelen.

the class InteractionListenerImplTest method importAssociatedTaxa.

@Test
public void importAssociatedTaxa() throws StudyImporterException {
    final InteractionListenerImpl listener = new InteractionListenerImpl(nodeFactory, null, new ImportLogger() {

        @Override
        public void warn(LogContext study, String message) {
            fail("got message: " + message);
        }

        @Override
        public void info(LogContext study, String message) {
        }

        @Override
        public void severe(LogContext study, String message) {
            fail("got message: " + message);
        }
    });
    final HashMap<String, String> link = new HashMap<>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(SOURCE_TAXON_ID, "duck");
    link.put(SOURCE_BODY_PART_ID, "bla:123");
    link.put(SOURCE_BODY_PART_NAME, "snout");
    link.put("associatedTaxa", "parasite of: Mini mouse");
    link.put(StudyImporterForMetaTable.EVENT_DATE, "20160404T21:31:40Z");
    link.put(StudyImporterForMetaTable.LATITUDE, "12.1");
    link.put(StudyImporterForMetaTable.LONGITUDE, "13.2");
    link.put(REFERENCE_ID, "123");
    link.put(STUDY_SOURCE_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    link.put(REFERENCE_DOI, "doi:1234");
    listener.newLink(link);
    final List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(allStudies.size(), is(1));
    final Study study = allStudies.get(0);
    assertThat(study.getCitation(), is(""));
    boolean foundPair = false;
    for (Relationship specimenRel : NodeUtil.getSpecimens(study)) {
        final SpecimenNode predator = new SpecimenNode(specimenRel.getEndNode());
        for (Relationship hosts : ((NodeBacked) predator).getUnderlyingNode().getRelationships(NodeUtil.asNeo4j(InteractType.PARASITE_OF), Direction.OUTGOING)) {
            final SpecimenNode host = new SpecimenNode(hosts.getEndNode());
            final TaxonNode hostTaxon = getOrigTaxon(host);
            final TaxonNode predTaxon = getOrigTaxon(predator);
            assertThat(hostTaxon.getName(), is("Mini mouse"));
            assertThat(predTaxon.getName(), is("donald"));
            assertThat(predTaxon.getExternalId(), is("duck"));
            foundPair = true;
        }
    }
    assertThat(foundPair, is(true));
}
Also used : Study(org.eol.globi.domain.Study) TaxonNode(org.eol.globi.domain.TaxonNode) HashMap(java.util.HashMap) LogContext(org.eol.globi.domain.LogContext) SpecimenNode(org.eol.globi.domain.SpecimenNode) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 5 with SpecimenNode

use of org.eol.globi.domain.SpecimenNode in project eol-globi-data by jhpoelen.

the class TaxonInteractionIndexer method collectTaxonInteractions.

public void collectTaxonInteractions(Map<Fun.Tuple3<Long, String, Long>, Long> taxonInteractions) {
    StopWatch watchForEntireRun = new StopWatch();
    watchForEntireRun.start();
    StopWatch watchForBatch = new StopWatch();
    watchForBatch.start();
    long count = 0L;
    int batchSize = 1000;
    Index<Node> taxonIndex = graphService.index().forNodes("taxons");
    IndexHits<Node> taxa = taxonIndex.query("name", "*");
    for (Node sourceTaxon : taxa) {
        final Iterable<Relationship> classifiedAs = sourceTaxon.getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
        for (Relationship classifiedA : classifiedAs) {
            Node specimenNode = classifiedA.getStartNode();
            final Iterable<Relationship> interactions = specimenNode.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.values()));
            for (Relationship interaction : interactions) {
                final Iterable<Relationship> targetClassifications = interaction.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
                for (Relationship targetClassification : targetClassifications) {
                    final Node targetTaxonNode = targetClassification.getEndNode();
                    final Fun.Tuple3<Long, String, Long> interactionKey = new Fun.Tuple3<Long, String, Long>(sourceTaxon.getId(), interaction.getType().name(), targetTaxonNode.getId());
                    final Long distinctInteractions = taxonInteractions.get(interactionKey);
                    taxonInteractions.put(interactionKey, distinctInteractions == null ? 1L : (distinctInteractions + 1L));
                    count++;
                }
            }
        }
        if (count % batchSize == 0) {
            watchForBatch.stop();
            final long duration = watchForBatch.getTime();
            if (duration > 0) {
                LOG.info("walked [" + batchSize + "] interactions in " + getProgressMsg(batchSize, duration));
            }
            watchForBatch.reset();
            watchForBatch.start();
        }
    }
    taxa.close();
    watchForEntireRun.stop();
    LOG.info("walked [" + count + "] interactions in " + getProgressMsg(count, watchForEntireRun.getTime()));
}
Also used : Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) StopWatch(org.apache.commons.lang.time.StopWatch) Relationship(org.neo4j.graphdb.Relationship) Fun(org.mapdb.Fun)

Aggregations

SpecimenNode (org.eol.globi.domain.SpecimenNode)18 Relationship (org.neo4j.graphdb.Relationship)17 Study (org.eol.globi.domain.Study)13 Test (org.junit.Test)11 Specimen (org.eol.globi.domain.Specimen)9 Node (org.neo4j.graphdb.Node)7 HashMap (java.util.HashMap)6 JsonNode (org.codehaus.jackson.JsonNode)5 Location (org.eol.globi.domain.Location)5 Taxon (org.eol.globi.domain.Taxon)4 TaxonNode (org.eol.globi.domain.TaxonNode)4 Date (java.util.Date)3 Environment (org.eol.globi.domain.Environment)3 LocationImpl (org.eol.globi.domain.LocationImpl)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 LogContext (org.eol.globi.domain.LogContext)2 Term (org.eol.globi.domain.Term)2 DatasetImpl (org.eol.globi.service.DatasetImpl)2