Search in sources :

Example 11 with TaxonNode

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

the class ExporterRDF method taxonOfSpecimen.

public List<List<String>> taxonOfSpecimen(Node specimen) {
    List<List<String>> statements = new ArrayList<List<String>>();
    Relationship singleRelationship = specimen.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
    if (singleRelationship != null) {
        Node taxonNode = singleRelationship.getEndNode();
        List<String> sameAsTaxa = addSameAsTaxaFor(taxonNode);
        final String s = taxonIRI(taxonNode);
        final String taxon = iriNode(s);
        statements.add(Arrays.asList(blankNode(specimen), iriNode(MEMBER_OF), taxon));
        for (String sameAsTaxon : sameAsTaxa) {
            statements.add(Arrays.asList(taxon, iriNode(SAME_AS), iriNode(sameAsTaxon)));
        }
    }
    return statements;
}
Also used : Relationship(org.neo4j.graphdb.Relationship) LocationNode(org.eol.globi.domain.LocationNode) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) TaxonNode(org.eol.globi.domain.TaxonNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with TaxonNode

use of org.eol.globi.domain.TaxonNode 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 13 with TaxonNode

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

the class ReportGenerator method countInteractionsAndTaxa.

private void countInteractionsAndTaxa(Iterable<Relationship> specimens, Set<Long> ids, Counter interactionCounter, Set<Long> idsNoMatch) {
    for (Relationship specimen : specimens) {
        Iterable<Relationship> relationships = specimen.getEndNode().getRelationships();
        for (Relationship relationship : relationships) {
            InteractType[] types = InteractType.values();
            for (InteractType type : types) {
                if (relationship.isType(NodeUtil.asNeo4j(type)) && !relationship.hasProperty(PropertyAndValueDictionary.INVERTED)) {
                    interactionCounter.count();
                    break;
                }
            }
        }
        Relationship classifiedAs = specimen.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
        if (classifiedAs != null) {
            Node taxonNode = classifiedAs.getEndNode();
            ids.add(taxonNode.getId());
            if (!TaxonUtil.isResolved(new TaxonNode(taxonNode))) {
                idsNoMatch.add(taxonNode.getId());
            }
        }
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) TaxonNode(org.eol.globi.domain.TaxonNode) Relationship(org.neo4j.graphdb.Relationship) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode)

Example 14 with TaxonNode

use of org.eol.globi.domain.TaxonNode 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/jhpoelen/eol-globi-data/wiki/Nanopubs
    StudyImpl study = new StudyImpl("some study", "some source", "http://doi.org/123.23/222", "some study citation");
    NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri")));
    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(getGraphDb()).link();
    NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j(getGraphDb());
    StudyImpl study1 = new StudyImpl("some study", "some source", null, "come citation");
    study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri")));
    StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
    assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
    assertThat(interaction.getTitle(), is(someStudy.getTitle()));
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(someStudy);
    RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
    Set<Long> ids = new HashSet<>();
    List<Long> idList = new ArrayList<>();
    for (Relationship specimen : specimens) {
        assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
        Relationship singleRelationship = specimen.getEndNode().getSingleRelationship(hasParticipant, Direction.INCOMING);
        long id = singleRelationship.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)));
}
Also used : Study(org.eol.globi.domain.Study) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) DatasetImpl(org.eol.globi.service.DatasetImpl) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) StudyNode(org.eol.globi.domain.StudyNode) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) TaxonIndex(org.eol.globi.data.TaxonIndex) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with TaxonNode

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

the class ResolvingTaxonIndexTest method synonymsAddedToIndexOnce.

@Test
public final void synonymsAddedToIndexOnce() throws NodeFactoryException {
    ResolvingTaxonIndex taxonService = createTaxonService(getGraphDb());
    taxonService.setEnricher(new PropertyEnricher() {

        private boolean firstTime = true;

        @Override
        public Map<String, String> enrich(Map<String, String> properties) throws PropertyEnricherException {
            Taxon taxon = TaxonUtil.mapToTaxon(properties);
            if ("not pref".equals(taxon.getName())) {
                if (!firstTime) {
                    fail("should already have indexed [" + taxon.getName() + "]...");
                }
                taxon.setName("preferred");
                taxon.setExternalId("bla:123");
                taxon.setPath("one | two | three");
                taxon.setPathIds("1 | 2 | 3");
                firstTime = false;
            }
            return TaxonUtil.taxonToMap(taxon);
        }

        @Override
        public void shutdown() {
        }
    });
    this.taxonService = taxonService;
    Taxon taxon2 = new TaxonImpl("not pref", null);
    taxon2.setPath(null);
    TaxonNode first = this.taxonService.getOrCreateTaxon(taxon2);
    assertThat(first.getName(), is("preferred"));
    assertThat(first.getPath(), is("one | two | three"));
    assertThat(first.getPathIds(), is("1 | 2 | 3"));
    Taxon taxon1 = new TaxonImpl("not pref", null);
    taxon1.setPath(null);
    TaxonNode second = this.taxonService.getOrCreateTaxon(taxon1);
    assertThat(second.getNodeID(), is(first.getNodeID()));
    TaxonNode third = this.taxonService.getOrCreateTaxon(new TaxonImpl("not pref"));
    assertThat(third.getNodeID(), is(first.getNodeID()));
    TaxonNode foundTaxon = this.taxonService.findTaxonByName("not pref");
    assertThat(foundTaxon.getNodeID(), is(first.getNodeID()));
    foundTaxon = this.taxonService.findTaxonByName("preferred");
    assertThat(foundTaxon.getNodeID(), is(first.getNodeID()));
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) TaxonNode(org.eol.globi.domain.TaxonNode) PropertyEnricher(org.eol.globi.service.PropertyEnricher) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

TaxonNode (org.eol.globi.domain.TaxonNode)31 Taxon (org.eol.globi.domain.Taxon)13 Test (org.junit.Test)13 Node (org.neo4j.graphdb.Node)12 Relationship (org.neo4j.graphdb.Relationship)12 TaxonImpl (org.eol.globi.domain.TaxonImpl)11 Study (org.eol.globi.domain.Study)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Specimen (org.eol.globi.domain.Specimen)5 SpecimenNode (org.eol.globi.domain.SpecimenNode)5 Transaction (org.neo4j.graphdb.Transaction)4 HashSet (java.util.HashSet)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 PropertyEnricherException (org.eol.globi.service.PropertyEnricherException)3 StudyImpl (org.eol.globi.domain.StudyImpl)2 StudyNode (org.eol.globi.domain.StudyNode)2 PropertyEnricher (org.eol.globi.service.PropertyEnricher)2 TaxonFuzzySearchIndex (org.eol.globi.taxon.TaxonFuzzySearchIndex)2