Search in sources :

Example 1 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project goci by EBISPOT.

the class KBLoader method quantifyKnowledgeBase.

public Map<IRI, Integer> quantifyKnowledgeBase(URL efoLocation, URL gwasSchemaLocation, URL kbLocation) throws OWLOntologyCreationException, URISyntaxException {
    Map<IRI, Integer> results = new HashMap<IRI, Integer>();
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    // do iri mapping
    URI efoURI = efoLocation.toURI();
    URI gwasSchemaURI = gwasSchemaLocation.toURI();
    URI kbURI = kbLocation.toURI();
    getLog().info("Mapping EFO to " + efoURI);
    manager.addIRIMapper(new SimpleIRIMapper(IRI.create(OntologyConstants.EFO_ONTOLOGY_SCHEMA_IRI), IRI.create(efoURI)));
    getLog().info("Mapping GWAS schema to " + gwasSchemaURI);
    manager.addIRIMapper(new SimpleIRIMapper(IRI.create(OntologyConstants.GWAS_ONTOLOGY_SCHEMA_IRI), IRI.create(gwasSchemaURI)));
    System.out.println("Loading knowledge base " + kbURI);
    getLog().info("Loading knowledge base " + kbURI);
    // load the knowledgebase
    OWLOntology kb = manager.loadOntology(IRI.create(kbURI));
    System.out.println("Processing knowledge base");
    getLog().info("Processing knowledge base");
    // retrieve all individuals
    Set<OWLNamedIndividual> inds = kb.getIndividualsInSignature();
    System.out.println("The knowledge base contains " + inds.size() + " individuals");
    getLog().info("The knowledge base contains " + inds.size() + " individuals");
    for (OWLNamedIndividual ind : inds) {
        // for each individual, check if it is an association
        boolean isAssociation = false;
        Set<OWLClassExpression> types = ind.getTypes(kb);
        for (OWLClassExpression type : types) {
            if (type.asOWLClass().getIRI().toString().equals(OntologyConstants.TRAIT_ASSOCIATION_CLASS_IRI)) {
                isAssociation = true;
                break;
            }
        }
        if (isAssociation) {
            // get the IRI of the trait class (from EFO) this individual is associated with
            Set<IRI> traitClasses = getTraitClass(kb, ind);
            for (IRI traitClass : traitClasses) {
                // skip SNPs
                if (traitClass.toString().equals(OntologyConstants.SNP_CLASS_IRI)) {
                    continue;
                }
                // increment count
                if (results.containsKey(traitClass)) {
                    int count = results.get(traitClass) + 1;
                    results.put(traitClass, count);
                } else {
                    results.put(traitClass, 1);
                }
            }
        }
    }
    return results;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) SimpleIRIMapper(org.semanticweb.owlapi.util.SimpleIRIMapper) HashMap(java.util.HashMap) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) URI(java.net.URI) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Example 2 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project goci by EBISPOT.

the class DefaultGWASOWLConverter method createConversionOntology.

public OWLOntology createConversionOntology() throws OWLConversionException {
    try {
        // create a new graph to represent our data dump
        OWLOntology conversion = getManager().createOntology(IRI.create(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI + "/" + new SimpleDateFormat("yyyy/MM/dd").format(new Date())));
        // import the gwas ontology schema and efo
        OWLImportsDeclaration gwasImportDecl = getDataFactory().getOWLImportsDeclaration(IRI.create(OntologyConstants.GWAS_ONTOLOGY_SCHEMA_IRI));
        ImportChange gwasImport = new AddImport(conversion, gwasImportDecl);
        getManager().applyChange(gwasImport);
        OWLImportsDeclaration efoImportDecl = getDataFactory().getOWLImportsDeclaration(IRI.create(OntologyConstants.EFO_ONTOLOGY_SCHEMA_IRI));
        ImportChange efoImport = new AddImport(conversion, efoImportDecl);
        getManager().applyChange(efoImport);
        return conversion;
    } catch (OWLOntologyCreationException e) {
        throw new OWLConversionException("Failed to create new ontology", e);
    }
}
Also used : OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLImportsDeclaration(org.semanticweb.owlapi.model.OWLImportsDeclaration) SimpleDateFormat(java.text.SimpleDateFormat) AddImport(org.semanticweb.owlapi.model.AddImport) Date(java.util.Date) ImportChange(org.semanticweb.owlapi.model.ImportChange)

Example 3 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project goci by EBISPOT.

the class DefaultGWASOWLPublisher method publishGWASDataInferredView.

public OWLReasoner publishGWASDataInferredView(OWLOntology ontology) throws OWLConversionException {
    getLog().debug("Loading any missing imports...");
    StringBuilder loadedOntologies = new StringBuilder();
    int n = 1;
    for (OWLOntology o : ontology.getOWLOntologyManager().getOntologies()) {
        loadedOntologies.append("\t").append(n++).append(") ").append(o.getOntologyID().getOntologyIRI()).append("\n");
    }
    getLog().debug("Imports collected: the following ontologies have been loaded in this session:\n" + loadedOntologies.toString());
    getLog().info("Classifying ontology from " + ontology.getOntologyID().getOntologyIRI());
    getLog().debug("Creating reasoner... ");
    OWLReasonerFactory factory = new Reasoner.ReasonerFactory();
    ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
    OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
    OWLReasoner reasoner = factory.createReasoner(ontology, config);
    getLog().debug("Precomputing inferences...");
    reasoner.precomputeInferences();
    getLog().debug("Checking ontology consistency...");
    reasoner.isConsistent();
    getLog().debug("Checking for unsatisfiable classes...");
    if (reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size() > 0) {
        throw new OWLConversionException("Once classified, unsatisfiable classes were detected");
    } else {
        getLog().info("Reasoning complete! ");
        return reasoner;
    }
}
Also used : OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLReasonerFactory(org.semanticweb.owlapi.reasoner.OWLReasonerFactory) OWLReasonerConfiguration(org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) SimpleConfiguration(org.semanticweb.owlapi.reasoner.SimpleConfiguration) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) ConsoleProgressMonitor(org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor) OWLReasonerFactory(org.semanticweb.owlapi.reasoner.OWLReasonerFactory)

Example 4 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project goci by EBISPOT.

the class DefaultGWASOWLPublisher method saveGWASDataInferredView.

public void saveGWASDataInferredView(OWLReasoner reasoner, File outputFile) throws OWLConversionException {
    try {
        // create new ontology to hold inferred axioms
        OWLOntology inferredOntology = getConverter().createConversionOntology();
        getLog().info("Saving inferred view...");
        List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
        // we require all inferred stuff except for disjoints...
        gens.add(new InferredClassAssertionAxiomGenerator());
        gens.add(new InferredDataPropertyCharacteristicAxiomGenerator());
        gens.add(new InferredEquivalentClassAxiomGenerator());
        gens.add(new InferredEquivalentDataPropertiesAxiomGenerator());
        gens.add(new InferredEquivalentObjectPropertyAxiomGenerator());
        gens.add(new InferredInverseObjectPropertiesAxiomGenerator());
        gens.add(new InferredObjectPropertyCharacteristicAxiomGenerator());
        gens.add(new InferredPropertyAssertionGenerator());
        gens.add(new InferredSubClassAxiomGenerator());
        gens.add(new InferredSubDataPropertyAxiomGenerator());
        gens.add(new InferredSubObjectPropertyAxiomGenerator());
        // now create the target ontology and save
        OWLOntologyManager inferredManager = inferredOntology.getOWLOntologyManager();
        InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
        iog.fillOntology(inferredManager, inferredOntology);
        inferredManager.saveOntology(inferredOntology, IRI.create(outputFile));
        getLog().info("Inferred view saved ok");
    } catch (OWLOntologyStorageException e) {
        throw new OWLConversionException("Failed to save GWAS data (inferred view)", e);
    }
}
Also used : InferredSubClassAxiomGenerator(org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator) InferredDataPropertyCharacteristicAxiomGenerator(org.semanticweb.owlapi.util.InferredDataPropertyCharacteristicAxiomGenerator) InferredEquivalentDataPropertiesAxiomGenerator(org.semanticweb.owlapi.util.InferredEquivalentDataPropertiesAxiomGenerator) InferredPropertyAssertionGenerator(org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator) InferredObjectPropertyCharacteristicAxiomGenerator(org.semanticweb.owlapi.util.InferredObjectPropertyCharacteristicAxiomGenerator) InferredInverseObjectPropertiesAxiomGenerator(org.semanticweb.owlapi.util.InferredInverseObjectPropertiesAxiomGenerator) InferredAxiomGenerator(org.semanticweb.owlapi.util.InferredAxiomGenerator) ArrayList(java.util.ArrayList) InferredSubDataPropertyAxiomGenerator(org.semanticweb.owlapi.util.InferredSubDataPropertyAxiomGenerator) InferredEquivalentClassAxiomGenerator(org.semanticweb.owlapi.util.InferredEquivalentClassAxiomGenerator) OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) InferredClassAssertionAxiomGenerator(org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) InferredSubObjectPropertyAxiomGenerator(org.semanticweb.owlapi.util.InferredSubObjectPropertyAxiomGenerator) InferredEquivalentObjectPropertyAxiomGenerator(org.semanticweb.owlapi.util.InferredEquivalentObjectPropertyAxiomGenerator) InferredOntologyGenerator(org.semanticweb.owlapi.util.InferredOntologyGenerator) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 5 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project goci by EBISPOT.

the class GOCIDataPublisherDriver method loadAndPrintStats.

public void loadAndPrintStats(File assertedOntologyFile) {
    try {
        // load ontology
        URI gwasDataURI = assertedOntologyFile.toURI();
        getLog().info("Loading GWAS data from " + gwasDataURI);
        OWLOntology ontology = ontologyLoader.getOntology();
        // print some stats
        int individualCount = ontology.getIndividualsInSignature().size();
        int axiomCount = ontology.getAxiomCount();
        System.out.println("Ontology '" + ontology.getOntologyID().getOntologyIRI() + "' contains:\n\t" + individualCount + " indivuals,\n\t" + axiomCount + " axioms");
    } catch (Exception e) {
        System.err.println("Failed to publish data to OWL (an unexpected exception occurred): " + e.getMessage());
        getLog().error("Failed to publish data to OWL (an unexpected exception occurred): ", e);
        throw new RuntimeException(e);
    }
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) URI(java.net.URI) OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

OWLOntology (org.semanticweb.owlapi.model.OWLOntology)116 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)58 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)49 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)31 IRI (org.semanticweb.owlapi.model.IRI)30 Test (org.junit.Test)25 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)24 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)22 HashSet (java.util.HashSet)21 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)18 Produces (javax.ws.rs.Produces)17 AddImport (org.semanticweb.owlapi.model.AddImport)16 OntModel (com.hp.hpl.jena.ontology.OntModel)15 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)15 InputStream (java.io.InputStream)14 GET (javax.ws.rs.GET)14 OWLClass (org.semanticweb.owlapi.model.OWLClass)14 ArrayList (java.util.ArrayList)13 Graph (org.apache.clerezza.commons.rdf.Graph)12 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)11