Search in sources :

Example 1 with NodeFactoryWithDatasetContext

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

the class LinkerTrustyNanoPubsTest method writingNanopub.

@Test
public void writingNanopub() throws NodeFactoryException, OpenRDFException, IOException, MalformedNanopubException, TrustyUriException {
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com/dataset"));
    NodeFactoryWithDatasetContext factory = populateDataset(dataset);
    LinkerTrustyNanoPubs linker = new LinkerTrustyNanoPubs(getGraphDb());
    linker.link();
    DatasetNode datasetNode = (DatasetNode) factory.getOrCreateDataset(dataset);
    Iterable<Relationship> rels = datasetNode.getUnderlyingNode().getRelationships(NodeUtil.asNeo4j(RelTypes.ACCESSED_AT), Direction.INCOMING);
    InteractionNode interactionNode = new InteractionNode(rels.iterator().next().getStartNode());
    String nanoPubText = LinkerTrustyNanoPubs.writeNanoPub(datasetNode, interactionNode);
    InputStream rdfIn = IOUtils.toInputStream(nanoPubText);
    String rdfActual = toTrigString(rdfIn);
    String rdfExpected = toTrigString(getClass().getResourceAsStream("nanopub.trig"));
    assertThat(rdfActual, is(rdfExpected));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Relationship(org.neo4j.graphdb.Relationship) DatasetImpl(org.eol.globi.service.DatasetImpl) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) InteractionNode(org.eol.globi.domain.InteractionNode) DatasetNode(org.eol.globi.domain.DatasetNode) Test(org.junit.Test)

Example 2 with NodeFactoryWithDatasetContext

use of org.eol.globi.data.NodeFactoryWithDatasetContext 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 3 with NodeFactoryWithDatasetContext

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

the class LinkerTrustyNanoPubsTest method populateDataset.

public NodeFactoryWithDatasetContext populateDataset(DatasetImpl dataset) 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, dataset);
    Interaction interaction = factory.createInteraction(factory.createStudy(study));
    TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
    Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
    donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
    Taxon mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
    Taxon mickeyTaxonEOL = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
    NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonEOL, getGraphDb(), RelTypes.SAME_AS);
    Specimen mickey = factory.createSpecimen(interaction, mickeyTaxonEOL);
    mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxonEOL));
    donald.ate(mickey);
    return factory;
}
Also used : Specimen(org.eol.globi.domain.Specimen) Interaction(org.eol.globi.domain.Interaction) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) TaxonIndex(org.eol.globi.data.TaxonIndex) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext)

Example 4 with NodeFactoryWithDatasetContext

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

the class GitHubImporterFactory method createImporter.

public StudyImporter createImporter(Dataset dataset, final NodeFactory nodeFactory) throws StudyImporterException {
    Class<? extends StudyImporter> anImporter = findImporterFor(dataset);
    try {
        Constructor<? extends StudyImporter> constructor = anImporter.getConstructor(ParserFactory.class, NodeFactory.class);
        ParserFactoryForDataset parserFactory = new ParserFactoryForDataset(dataset);
        StudyImporter studyImporter = constructor.newInstance(parserFactory, new NodeFactoryWithDatasetContext(nodeFactory, dataset));
        studyImporter.setDataset(dataset);
        return studyImporter;
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
        throw new StudyImporterException("failed to instantiate importer for [" + dataset.getNamespace() + "]", e);
    }
}
Also used : StudyImporterException(org.eol.globi.data.StudyImporterException) ParserFactoryForDataset(org.eol.globi.data.ParserFactoryForDataset) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) StudyImporter(org.eol.globi.data.StudyImporter) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with NodeFactoryWithDatasetContext

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

the class ExportFlatInteractionsTest method init.

@Before
public void init() throws IOException {
    super.startGraphDb();
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"));
    factory = new NodeFactoryWithDatasetContext(nodeFactory, dataset);
}
Also used : DatasetImpl(org.eol.globi.service.DatasetImpl) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) Before(org.junit.Before)

Aggregations

NodeFactoryWithDatasetContext (org.eol.globi.data.NodeFactoryWithDatasetContext)5 DatasetImpl (org.eol.globi.service.DatasetImpl)3 TaxonIndex (org.eol.globi.data.TaxonIndex)2 Specimen (org.eol.globi.domain.Specimen)2 StudyImpl (org.eol.globi.domain.StudyImpl)2 Taxon (org.eol.globi.domain.Taxon)2 TaxonImpl (org.eol.globi.domain.TaxonImpl)2 Test (org.junit.Test)2 Relationship (org.neo4j.graphdb.Relationship)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 NodeFactoryNeo4j (org.eol.globi.data.NodeFactoryNeo4j)1 ParserFactoryForDataset (org.eol.globi.data.ParserFactoryForDataset)1 StudyImporter (org.eol.globi.data.StudyImporter)1 StudyImporterException (org.eol.globi.data.StudyImporterException)1 DatasetNode (org.eol.globi.domain.DatasetNode)1