Search in sources :

Example 6 with TaxonNode

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

the class NodeUtil method connectTaxa.

public static void connectTaxa(Taxon taxon, TaxonNode taxonNode, GraphDatabaseService graphDb, RelTypes relType) {
    Transaction tx = graphDb.beginTx();
    try {
        TaxonNode sameAsTaxon = new TaxonNode(graphDb.createNode());
        TaxonUtil.copy(taxon, sameAsTaxon);
        taxonNode.getUnderlyingNode().createRelationshipTo(sameAsTaxon.getUnderlyingNode(), asNeo4j(relType));
        tx.success();
    } finally {
        tx.finish();
    }
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Transaction(org.neo4j.graphdb.Transaction)

Example 7 with TaxonNode

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

the class ExporterSiteMapForNames method export.

@Override
public void export(GraphDatabaseService graphDatabase, String baseDir) throws StudyImporterException {
    Set<String> names = new HashSet<String>();
    names.add("Homo sapiens");
    // just do it once
    final List<Study> allStudies = NodeUtil.findAllStudies(graphDatabase);
    for (Study allStudy : allStudies) {
        final Iterable<Relationship> specimens = NodeUtil.getSpecimens(allStudy);
        for (Relationship specimen : specimens) {
            final Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
            if (relationships.iterator().hasNext()) {
                final Node endNode = relationships.iterator().next().getEndNode();
                final TaxonNode taxonNode = new TaxonNode(endNode);
                names.add(taxonNode.getName());
            }
        }
    }
    final String queryParamName = "interactionType=interactsWith&sourceTaxon=";
    final String siteMapLocation = "https://depot.globalbioticinteractions.org/snapshot/target/data/sitemap/names/";
    SiteMapUtils.generateSiteMap(names, baseDir, queryParamName, siteMapLocation);
}
Also used : Study(org.eol.globi.domain.Study) TaxonNode(org.eol.globi.domain.TaxonNode) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) HashSet(java.util.HashSet)

Example 8 with TaxonNode

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

the class StudyImporterForGeminaTest method importFewLines.

@Test
public void importFewLines() throws StudyImporterException {
    StudyImporterForGemina importer = new StudyImporterForGemina(new TestParserFactory(firstFewLines), nodeFactory);
    importStudy(importer);
    assertHuman();
    Taxon taxon = taxonIndex.findTaxonByName("Bacillus anthracis");
    assertThat(taxon, is(notNullValue()));
    assertThat(taxon.getExternalId(), is("NCBI:1392"));
    List<String> antraxHosts = new ArrayList<String>();
    Iterable<Relationship> relationships = ((NodeBacked) taxon).getUnderlyingNode().getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.INCOMING);
    for (Relationship rel : relationships) {
        Node specimen = rel.getStartNode();
        Iterable<Relationship> pathogenRels = specimen.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.PATHOGEN_OF));
        for (Relationship pathogenRel : pathogenRels) {
            Relationship singleRelationship = pathogenRel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
            antraxHosts.add(new TaxonNode(singleRelationship.getEndNode()).getName());
        }
    }
    assertThat(antraxHosts, hasItem("Equus caballus"));
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with TaxonNode

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

the class LinkerTaxonIndexTest method assertSingleHit.

protected void assertSingleHit(String query) {
    IndexHits<Node> hits;
    Node next;
    hits = getGraphDb().index().forNodes(LinkerTaxonIndex.INDEX_TAXON_NAMES_AND_IDS).query(query);
    next = hits.next();
    assertThat(new TaxonNode(next).getName(), is("Homo sapiens"));
    assertThat(hits.hasNext(), is(false));
    hits.close();
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode)

Example 10 with TaxonNode

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

the class LinkerTestUtil method assertHasOther.

public static Collection<String> assertHasOther(String name, int expectedCount, TaxonIndex taxonIndex, RelTypes relType) throws NodeFactoryException {
    Set<String> externalIds = new HashSet<>();
    Taxon taxon1 = taxonIndex.findTaxonByName(name);
    assertThat(taxon1, is(notNullValue()));
    assertThat(taxon1.getName(), is(name));
    Iterable<Relationship> rels = ((NodeBacked) taxon1).getUnderlyingNode().getRelationships(NodeUtil.asNeo4j(relType), Direction.OUTGOING);
    for (Relationship rel : rels) {
        externalIds.add(new TaxonNode(rel.getEndNode()).getExternalId());
    }
    assertThat("expected [" + expectedCount + "] relationships for [" + name + "]: [" + externalIds.toString() + "]", externalIds.size(), is(expectedCount));
    return externalIds;
}
Also used : TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) Relationship(org.neo4j.graphdb.Relationship) HashSet(java.util.HashSet)

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