Search in sources :

Example 1 with GraphServiceFactory

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

the class NameResolverTest method iNaturalistTaxon.

@Test
public void iNaturalistTaxon() throws NodeFactoryException {
    Specimen someOtherOrganism = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Blaus bla", "INAT_TAXON:58831"));
    Specimen someOtherOrganism2 = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Redus rha", "INAT_TAXON:126777"));
    someOtherOrganism.ate(someOtherOrganism2);
    GraphServiceFactory graphServiceFactory = new GraphServiceFactoryProxy(getGraphDb());
    final NameResolver nameResolver = new NameResolver(graphServiceFactory, new NonResolvingTaxonIndex(getGraphDb()));
    nameResolver.setBatchSize(1L);
    nameResolver.index();
    Taxon resolvedTaxon = taxonIndex.findTaxonById("INAT_TAXON:58831");
    assertThat(resolvedTaxon, is(notNullValue()));
    assertThat(resolvedTaxon.getExternalId(), is("INAT_TAXON:58831"));
    assertThat(resolvedTaxon.getName(), is("Blaus bla"));
    Taxon resolvedTaxon2 = taxonIndex.findTaxonByName("Blaus bla");
    assertThat(resolvedTaxon2, is(notNullValue()));
    assertThat(resolvedTaxon2.getExternalId(), is("INAT_TAXON:58831"));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) GraphServiceFactory(org.eol.globi.db.GraphServiceFactory) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) Test(org.junit.Test)

Example 2 with GraphServiceFactory

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

the class Elton4N method importWithVersion.

private void importWithVersion(CommandLine cmdLine, String neo4jVersion) throws StudyImporterException {
    final String graphDbDirPath = cmdLine.getOptionValue(CmdOptionConstants.OPTION_GRAPHDB_DIR, "graph.db");
    Factories factoriesNeo4j = new Factories() {

        final GraphServiceFactory factory = new GraphServiceFactoryImpl(new File(graphDbDirPath));

        final NodeFactoryFactory nodeFactoryFactory = StringUtils.equals("2", neo4jVersion) ? new NodeFactoryFactoryTransactingOnDatasetNeo4j2(factory) : new NodeFactoryFactoryTransactingOnDatasetNeo4j3(factory);

        @Override
        public GraphServiceFactory getGraphServiceFactory() {
            return factory;
        }

        @Override
        public NodeFactoryFactory getNodeFactoryFactory() {
            return nodeFactoryFactory;
        }
    };
    try {
        String datasetDir = CmdUtil.getDatasetDir(cmdLine);
        GraphServiceFactory graphServiceFactory = factoriesNeo4j.getGraphServiceFactory();
        List<Cmd> steps = new ArrayList<>();
        LOG.info("processing steps: [" + StringUtils.join(cmdLine.getArgList(), ", ") + "]");
        if (cmdLine.getArgList().isEmpty() || cmdLine.getArgList().contains(ELTON_STEP_COMPILE)) {
            steps.add(new CmdImportDatasets(factoriesNeo4j.getNodeFactoryFactory(), graphServiceFactory, datasetDir));
        }
        String exportDir = cmdLine.getOptionValue(CmdOptionConstants.OPTION_EXPORT_DIR, ".");
        CmdInterpretTaxa interpretTaxa = createInterpretTaxaCmd(cmdLine, graphServiceFactory, exportDir);
        if (cmdLine.getArgList().isEmpty() || cmdLine.getArgList().contains(ELTON_STEP_LINK_NAMES)) {
            steps.add(interpretTaxa);
        }
        if (cmdLine.getArgList().isEmpty() || cmdLine.getArgList().contains(ELTON_STEP_LINK)) {
            if (!steps.contains(interpretTaxa)) {
                steps.add(interpretTaxa);
            }
            steps.addAll(Arrays.asList(new CmdIndexTaxa(graphServiceFactory), new CmdIndexTaxonStrings(graphServiceFactory), new CmdGenerateReport(graphServiceFactory.getGraphService())));
        }
        CmdExportInteractionsTSV interactionsTSVExporter = new CmdExportInteractionsTSV(graphServiceFactory, new File(exportDir));
        if (cmdLine.getArgList().isEmpty() || cmdLine.getArgList().contains(ELTON_STEP_PACKAGE_INTERACTIONS_TSV)) {
            steps.add(interactionsTSVExporter);
        }
        if (cmdLine.getArgList().isEmpty() || cmdLine.getArgList().contains(ELTON_STEP_PACKAGE)) {
            if (!steps.contains(interactionsTSVExporter)) {
                steps.add(interactionsTSVExporter);
            }
            steps.add(new CmdExport(graphServiceFactory, new File(exportDir)));
        }
        for (Cmd step : steps) {
            step.run();
        }
    } finally {
        HttpUtil.shutdown();
    }
}
Also used : NodeFactoryFactory(org.eol.globi.tool.NodeFactoryFactory) CmdInterpretTaxa(org.eol.globi.tool.CmdInterpretTaxa) ArrayList(java.util.ArrayList) CmdImportDatasets(org.eol.globi.tool.CmdImportDatasets) CmdExport(org.eol.globi.tool.CmdExport) GraphServiceFactoryImpl(org.eol.globi.db.GraphServiceFactoryImpl) CmdIndexTaxonStrings(org.eol.globi.tool.CmdIndexTaxonStrings) CmdIndexTaxa(org.eol.globi.tool.CmdIndexTaxa) NodeFactoryFactoryTransactingOnDatasetNeo4j3(org.eol.globi.tool.NodeFactoryFactoryTransactingOnDatasetNeo4j3) CmdExportInteractionsTSV(org.eol.globi.tool.CmdExportInteractionsTSV) CmdGenerateReport(org.eol.globi.tool.CmdGenerateReport) GraphServiceFactory(org.eol.globi.db.GraphServiceFactory) Cmd(org.eol.globi.tool.Cmd) Factories(org.eol.globi.tool.Factories) File(java.io.File) NodeFactoryFactoryTransactingOnDatasetNeo4j2(org.eol.globi.tool.NodeFactoryFactoryTransactingOnDatasetNeo4j2)

Example 3 with GraphServiceFactory

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

the class GraphDBTestCaseAbstract method getGraphFactory.

protected GraphServiceFactory getGraphFactory() {
    return new GraphServiceFactory() {

        private GraphDatabaseService graphDb = null;

        @Override
        public GraphDatabaseService getGraphService() {
            GraphDatabaseService graphDb = this.graphDb;
            GraphServiceUtil.verifyState(graphDb);
            if (this.graphDb == null) {
                this.graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
            }
            return this.graphDb;
        }

        @Override
        public void close() {
            if (graphDb != null) {
                graphDb.shutdown();
                graphDb = null;
            }
        }
    };
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphServiceFactory(org.eol.globi.db.GraphServiceFactory)

Example 4 with GraphServiceFactory

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

the class NameResolverTest method assertResolveNames.

private void assertResolveNames(RelTypes relTypes, final GraphDatabaseService graphDb) throws NodeFactoryException {
    Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Homo sapiens", "NCBI:9606"), relTypes);
    Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Animalia", "WORMS:2"), relTypes);
    human.ate(animal);
    Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Arius felis", "WORMS:158711"), relTypes);
    human.ate(fish);
    assertNull(taxonIndex.findTaxonById("NCBI:9606"));
    assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
    final GraphServiceFactory factory = new GraphServiceFactory() {

        @Override
        public GraphDatabaseService getGraphService() {
            return getGraphDb();
        }

        @Override
        public void close() {
        }
    };
    final NameResolver nameResolver = new NameResolver(factory, new NonResolvingTaxonIndex(graphDb));
    nameResolver.setBatchSize(1L);
    nameResolver.index();
    assertAnimalia(taxonIndex.findTaxonById("WORMS:2"));
    assertThat(taxonIndex.findTaxonByName("Arius felis"), is(notNullValue()));
    Taxon homoSapiens = taxonIndex.findTaxonByName("Homo sapiens");
    assertNotNull(homoSapiens);
    assertThat(homoSapiens.getExternalId(), is("NCBI:9606"));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) GraphServiceFactory(org.eol.globi.db.GraphServiceFactory)

Aggregations

GraphServiceFactory (org.eol.globi.db.GraphServiceFactory)4 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 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 GraphServiceFactoryImpl (org.eol.globi.db.GraphServiceFactoryImpl)1 GraphServiceFactoryProxy (org.eol.globi.db.GraphServiceFactoryProxy)1 Cmd (org.eol.globi.tool.Cmd)1 CmdExport (org.eol.globi.tool.CmdExport)1 CmdExportInteractionsTSV (org.eol.globi.tool.CmdExportInteractionsTSV)1 CmdGenerateReport (org.eol.globi.tool.CmdGenerateReport)1 CmdImportDatasets (org.eol.globi.tool.CmdImportDatasets)1 CmdIndexTaxa (org.eol.globi.tool.CmdIndexTaxa)1 CmdIndexTaxonStrings (org.eol.globi.tool.CmdIndexTaxonStrings)1 CmdInterpretTaxa (org.eol.globi.tool.CmdInterpretTaxa)1 Factories (org.eol.globi.tool.Factories)1 NodeFactoryFactory (org.eol.globi.tool.NodeFactoryFactory)1