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;
}
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);
}
}
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;
}
}
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);
}
}
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);
}
}
Aggregations