Search in sources :

Example 1 with OWLConversionException

use of uk.ac.ebi.spot.goci.exception.OWLConversionException 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 2 with OWLConversionException

use of uk.ac.ebi.spot.goci.exception.OWLConversionException 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 3 with OWLConversionException

use of uk.ac.ebi.spot.goci.exception.OWLConversionException 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 4 with OWLConversionException

use of uk.ac.ebi.spot.goci.exception.OWLConversionException in project goci by EBISPOT.

the class DefaultGWASOWLPublisher method saveGWASData.

public void saveGWASData(OWLOntology ontology, File outputFile) throws OWLConversionException {
    try {
        getLog().info("Saving GWAS catalog data...");
        OWLOntologyFormat format = new RDFXMLOntologyFormat();
        getManager().saveOntology(ontology, format, IRI.create(outputFile));
        getLog().info("GWAS catalog data saved ok");
        getLog().info("Resulting ontology contains " + ontology.getAxiomCount() + " axioms " + "and is saved at " + outputFile.getAbsolutePath());
    } catch (OWLOntologyStorageException e) {
        throw new OWLConversionException("Failed to save GWAS data", e);
    }
}
Also used : OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLOntologyFormat(org.semanticweb.owlapi.model.OWLOntologyFormat) RDFXMLOntologyFormat(org.semanticweb.owlapi.io.RDFXMLOntologyFormat) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 5 with OWLConversionException

use of uk.ac.ebi.spot.goci.exception.OWLConversionException in project goci by EBISPOT.

the class GOCIDataPublisherDriver method publishAndSave.

public void publishAndSave(File assertedOntologyFile, File inferredOntologyFile) throws RuntimeException {
    try {
        // publishAndSave the data
        System.out.println("Attempting to convert and publish GWAS data as OWL...");
        OWLOntology ontology = getGwasOwlPublisher().publishGWASData();
        // and save the result
        System.out.print("Ontology converted, saving asserted results...");
        getGwasOwlPublisher().saveGWASData(ontology, assertedOntologyFile);
        System.out.println("..done!");
        if (inferredOntologyFile != null) {
            // now get the inferred view
            System.out.println("Evaluating inferred view...");
            OWLReasoner reasoner = getGwasOwlPublisher().publishGWASDataInferredView(ontology);
            // now save inferred view
            System.out.print("Ontology fully classified, saving inferred results...");
            getGwasOwlPublisher().saveGWASDataInferredView(reasoner, inferredOntologyFile);
            System.out.println("..done!");
        }
    } catch (OWLConversionException e) {
        System.err.println("Failed to publish data to OWL: " + e.getMessage());
        getLog().error("Failed to publish data to OWL: ", e);
        throw new RuntimeException(e);
    } 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 : OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

OWLConversionException (uk.ac.ebi.spot.goci.exception.OWLConversionException)5 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)4 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)2 OWLReasoner (org.semanticweb.owlapi.reasoner.OWLReasoner)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ParseException (org.apache.commons.cli.ParseException)1 RDFXMLOntologyFormat (org.semanticweb.owlapi.io.RDFXMLOntologyFormat)1 AddImport (org.semanticweb.owlapi.model.AddImport)1 ImportChange (org.semanticweb.owlapi.model.ImportChange)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLImportsDeclaration (org.semanticweb.owlapi.model.OWLImportsDeclaration)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyFormat (org.semanticweb.owlapi.model.OWLOntologyFormat)1 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)1 ConsoleProgressMonitor (org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor)1 OWLReasonerConfiguration (org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration)1 OWLReasonerFactory (org.semanticweb.owlapi.reasoner.OWLReasonerFactory)1 SimpleConfiguration (org.semanticweb.owlapi.reasoner.SimpleConfiguration)1