Search in sources :

Example 11 with UndoAwareMolecularModelManager

use of org.geneontology.minerva.UndoAwareMolecularModelManager in project minerva by geneontology.

the class StartUpTool method startUp.

public static Server startUp(final MinervaStartUpConfig conf) throws Exception {
    // load ontology
    LOGGER.info("Start loading ontology: " + conf.ontology);
    ParserWrapper pw = new ParserWrapper();
    // if available, set catalog
    if (conf.catalog != null) {
        LOGGER.info("Adding catalog xml: " + conf.catalog);
        pw.addIRIMapper(new CatalogXmlIRIMapper(conf.catalog));
    }
    MinervaOWLGraphWrapper graph = pw.parseToOWLGraph(conf.ontology);
    // grab ontology metadata and store for status service
    Map<IRI, Set<OWLAnnotation>> ont_annos = new HashMap<IRI, Set<OWLAnnotation>>();
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    OWLAnnotationProperty versionIRI = factory.getOWLAnnotationProperty(OWLRDFVocabulary.OWL_VERSION_IRI.getIRI());
    for (OWLOntology ont : graph.getAllOntologies()) {
        Set<OWLAnnotation> maybeVersionAnnotation = ont.getOntologyID().getVersionIRI().transform(iri -> factory.getOWLAnnotation(versionIRI, iri)).asSet();
        Set<OWLAnnotation> annotations = ont.getAnnotations();
        annotations.addAll(maybeVersionAnnotation);
        ont_annos.put(ont.getOWLOntologyManager().getOntologyDocumentIRI(ont), annotations);
    }
    OWLOntology full_tbox = forceMergeImports(graph.getSourceOntology(), graph.getAllOntologies());
    graph.setSourceOntology(full_tbox);
    if (conf.importantRelationParent != null) {
        // try to find parent property
        OWLObjectProperty parentProperty = getRelation(conf.importantRelationParent, graph);
        if (parentProperty != null) {
            // find all asserted direct sub properties of the parent property
            conf.importantRelations = getAssertedSubProperties(parentProperty, graph);
            if (conf.importantRelations.isEmpty()) {
                LOGGER.warn("Could not find any asserted sub properties for parent: " + conf.importantRelationParent);
            }
        } else {
            LOGGER.warn("Could not find a property for rel: " + conf.importantRelationParent);
        }
    }
    // set folder to  models
    LOGGER.info("Model path: " + conf.journalFile);
    // create model manager
    LOGGER.info("Start initializing Minerva");
    UndoAwareMolecularModelManager models = new UndoAwareMolecularModelManager(graph.getSourceOntology(), conf.curieHandler, conf.modelIdPrefix, conf.journalFile, conf.exportFolder, conf.pathToOntologyJournal, true);
    // set pre and post file handlers
    models.addPostLoadOntologyFilter(ModelReaderHelper.INSTANCE);
    // conf.shex.tbox_reasoner = models.getTbox_reasoner();
    conf.shex.setGo_lego_repo(models.getGolego_repo());
    conf.shex.curieHandler = conf.curieHandler;
    // start server
    Server server = startUp(models, conf, ont_annos);
    return server;
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) OWLRDFVocabulary(org.semanticweb.owlapi.vocab.OWLRDFVocabulary) java.util(java.util) org.semanticweb.owlapi.model(org.semanticweb.owlapi.model) CatalogXmlIRIMapper(owltools.io.CatalogXmlIRIMapper) URL(java.net.URL) SimpleEcoMapper(owltools.gaf.eco.SimpleEcoMapper) ExternalLookupService(org.geneontology.minerva.lookup.ExternalLookupService) OWLManager(org.semanticweb.owlapi.apibinding.OWLManager) Logger(org.apache.log4j.Logger) CachingInferenceProviderCreatorImpl(org.geneontology.minerva.server.inferences.CachingInferenceProviderCreatorImpl) CurieMappings(org.geneontology.minerva.curie.CurieMappings) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) LocalTime(java.time.LocalTime) Server(org.eclipse.jetty.server.Server) MinervaShexValidator(org.geneontology.minerva.server.validation.MinervaShexValidator) ParserWrapper(owltools.io.ParserWrapper) UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) org.geneontology.minerva.server.handler(org.geneontology.minerva.server.handler) EcoMapperFactory(owltools.gaf.eco.EcoMapperFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ServerConnector(org.eclipse.jetty.server.ServerConnector) MinervaOWLGraphWrapper(org.geneontology.minerva.MinervaOWLGraphWrapper) Opts(owltools.cli.Opts) CurieHandler(org.geneontology.minerva.curie.CurieHandler) LocalDate(java.time.LocalDate) DefaultCurieHandler(org.geneontology.minerva.curie.DefaultCurieHandler) ModelReaderHelper(org.geneontology.minerva.ModelReaderHelper) InferenceProviderCreator(org.geneontology.minerva.server.inferences.InferenceProviderCreator) MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) Server(org.eclipse.jetty.server.Server) UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) CatalogXmlIRIMapper(owltools.io.CatalogXmlIRIMapper) MinervaOWLGraphWrapper(org.geneontology.minerva.MinervaOWLGraphWrapper) ParserWrapper(owltools.io.ParserWrapper)

Example 12 with UndoAwareMolecularModelManager

use of org.geneontology.minerva.UndoAwareMolecularModelManager in project minerva by geneontology.

the class BatchModelHandlerTest method init.

static void init(ParserWrapper pw) throws OWLOntologyCreationException, IOException, UnknownIdentifierException {
    final MinervaOWLGraphWrapper graph = pw.parseToOWLGraph("src/test/resources/go-lego-minimal.owl");
    final OWLObjectProperty legorelParent = StartUpTool.getRelation("http://purl.obolibrary.org/obo/LEGOREL_0000000", graph);
    assertNotNull(legorelParent);
    importantRelations = StartUpTool.getAssertedSubProperties(legorelParent, graph);
    assertFalse(importantRelations.isEmpty());
    // curie handler
    final String modelIdcurie = "gomodel";
    final String modelIdPrefix = "http://model.geneontology.org/";
    final CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
    curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
    InferenceProviderCreator ipc = CachingInferenceProviderCreatorImpl.createElk(false, null);
    models = new UndoAwareMolecularModelManager(graph.getSourceOntology(), curieHandler, modelIdPrefix, folder.newFile().getAbsolutePath(), null, ontology_journal_file, true);
    lookupService = createTestProteins(curieHandler);
    handler = new JsonOrJsonpBatchHandler(models, "development", ipc, importantRelations, lookupService) {

        @Override
        protected String generateDateString() {
            // hook for overriding the date generation with a custom counter
            if (dateGenerator.useCounter) {
                int count = dateGenerator.counter;
                dateGenerator.counter += 1;
                return Integer.toString(count);
            }
            return super.generateDateString();
        }
    };
    JsonOrJsonpBatchHandler.VALIDATE_BEFORE_SAVE = true;
}
Also used : MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) CurieMappings(org.geneontology.minerva.curie.CurieMappings) MinervaOWLGraphWrapper(org.geneontology.minerva.MinervaOWLGraphWrapper) UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) InferenceProviderCreator(org.geneontology.minerva.server.inferences.InferenceProviderCreator) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty)

Example 13 with UndoAwareMolecularModelManager

use of org.geneontology.minerva.UndoAwareMolecularModelManager in project minerva by geneontology.

the class GoCamModelTest method testRootTypesForComplements.

@Test
public void testRootTypesForComplements() throws Exception {
    String ontologyJournalFile = "/tmp/test-go-lego-blazegraph-complements.jnl";
    OWLOntologyManager man = OWLManager.createOWLOntologyManager();
    OWLOntology tboxOntology = man.loadOntologyFromOntologyDocument(new File("src/test/resources/go-basic.obo"));
    CurieHandler curieHandler = new MappedCurieHandler();
    String inputDB = "/tmp/test-blazegraph-models-complements.jnl";
    UndoAwareMolecularModelManager m3 = null;
    m3 = new UndoAwareMolecularModelManager(tboxOntology, curieHandler, "gomodel", inputDB, null, ontologyJournalFile, true);
    m3.importModelToDatabase(new File("src/test/resources/test-complement-roots.ttl"), true);
    ModelContainer mc = m3.getModel(IRI.create("http://model.geneontology.org/61f3310500000003"));
    OWLOntology gocam_via_mc = mc.getAboxOntology();
    GoCamModel g = new GoCamModel(gocam_via_mc, m3);
    assertTrue("Can get roots for classes and complements", g.ind_types.get(man.getOWLDataFactory().getOWLNamedIndividual(IRI.create("http://model.geneontology.org/61f3310500000003/61f3310500000004"))).contains("http://purl.obolibrary.org/obo/GO_0008150"));
    assertTrue("Can get roots for classes and complements", g.ind_types.get(man.getOWLDataFactory().getOWLNamedIndividual(IRI.create("http://model.geneontology.org/61f3310500000003/61f3310500000005"))).contains("http://purl.obolibrary.org/obo/GO_0008150"));
    m3.getGolego_repo().dispose();
}
Also used : MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) CurieHandler(org.geneontology.minerva.curie.CurieHandler) MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) ModelContainer(org.geneontology.minerva.ModelContainer) File(java.io.File) Test(org.junit.Test)

Example 14 with UndoAwareMolecularModelManager

use of org.geneontology.minerva.UndoAwareMolecularModelManager in project minerva by geneontology.

the class GoCamModelTest method testGoModelStats.

@Test
public void testGoModelStats() throws Exception {
    OWLOntologyManager man = OWLManager.createOWLOntologyManager();
    OWLOntology tbox_ontology = man.loadOntology(IRI.create("http://purl.obolibrary.org/obo/go/extensions/go-lego.owl"));
    CurieHandler curieHandler = new MappedCurieHandler();
    String inputDB = "/tmp/test-blazegraph-models.jnl";
    // load it into a journal and launch an m3
    UndoAwareMolecularModelManager m3 = null;
    File f = new File(gocam_dir);
    if (f.isDirectory()) {
        // remove anything that existed from previous runs
        File bgdb = new File(inputDB);
        if (bgdb.exists()) {
            bgdb.delete();
        }
        // set it up with empty db
        m3 = new UndoAwareMolecularModelManager(tbox_ontology, curieHandler, "gomodel", inputDB, null, ontology_journal_file, true);
        onto_repo = m3.getGolego_repo();
        // load the db
        for (File file : f.listFiles()) {
            if (file.getName().endsWith("ttl")) {
                m3.importModelToDatabase(file, true);
            }
        }
    }
    // read it back out and check on stats
    for (IRI modelIRI : m3.getAvailableModelIds()) {
        ModelContainer mc = m3.getModel(modelIRI);
        OWLOntology gocam_via_mc = mc.getAboxOntology();
        GoCamModel g = new GoCamModel(gocam_via_mc, m3);
        // testing for an issue with the OWL blazegraph loader
        assertFalse("title not read out of M3 retrieved model " + modelIRI, (g.getTitle() == null));
        // these reactions are not counted as activities, but causal relations coming from them are counted.
        if (modelIRI.toString().contains("R-HSA-5654719")) {
            // SHC-mediated cascade:FGFR4
            assertTrue("wrong n activities " + g.getStats().n_activity_units, g.getStats().n_activity_units == 4);
            assertTrue("wrong n complete activities " + g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units == 2);
            assertTrue("wrong n unenabled activities " + g.getStats().n_no_enabler, g.getStats().n_no_enabler == 2);
            assertTrue("wrong n causal relations " + g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions == 6);
        } else if (modelIRI.toString().contains("R-HSA-201688")) {
            // WNT mediated activation of DVL
            assertTrue("wrong n activities " + g.getStats().n_activity_units, g.getStats().n_activity_units == 4);
            assertTrue("wrong n complete activities " + g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units == 3);
            assertTrue("wrong n unenabled activities " + g.getStats().n_no_enabler, g.getStats().n_no_enabler == 1);
            assertTrue("wrong n causal relations " + g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions == 3);
        } else if (modelIRI.toString().contains("R-HSA-5654733")) {
            // Negative regulation of FGFR4 signaling
            assertTrue("wrong n activities " + g.getStats().n_activity_units, g.getStats().n_activity_units == 3);
            assertTrue("wrong n complete activities " + g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units == 2);
            assertTrue("wrong n unenabled activities " + g.getStats().n_no_enabler, g.getStats().n_no_enabler == 1);
            assertTrue("wrong n causal relations " + g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions == 3);
        }
    }
}
Also used : MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) IRI(org.semanticweb.owlapi.model.IRI) UndoAwareMolecularModelManager(org.geneontology.minerva.UndoAwareMolecularModelManager) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) CurieHandler(org.geneontology.minerva.curie.CurieHandler) MappedCurieHandler(org.geneontology.minerva.curie.MappedCurieHandler) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) ModelContainer(org.geneontology.minerva.ModelContainer) File(java.io.File) Test(org.junit.Test)

Aggregations

UndoAwareMolecularModelManager (org.geneontology.minerva.UndoAwareMolecularModelManager)14 MappedCurieHandler (org.geneontology.minerva.curie.MappedCurieHandler)11 File (java.io.File)9 CurieMappings (org.geneontology.minerva.curie.CurieMappings)8 InferenceProviderCreator (org.geneontology.minerva.server.inferences.InferenceProviderCreator)7 ExternalLookupService (org.geneontology.minerva.lookup.ExternalLookupService)6 ModelContainer (org.geneontology.minerva.ModelContainer)5 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)4 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)4 Server (org.eclipse.jetty.server.Server)4 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)4 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)4 Test (org.junit.Test)4 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)4 CurieHandler (org.geneontology.minerva.curie.CurieHandler)3 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)3 URL (java.net.URL)2