# HG changeset patch # User Mikel Egaña Aranguren # Date 1333025362 -7200 # Node ID 7e6604a5ee557f86cebd4fbd07518733ea2dab15 # Parent d0722148cb59afbd6917247a562ae56563fd5193 New query tool added diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/README --- a/OPPL/README Thu Mar 22 14:37:46 2012 +0100 +++ b/OPPL/README Thu Mar 29 14:49:22 2012 +0200 @@ -10,21 +10,25 @@ /galaxy-dist/tool-data/shared/jars/: oppl_galaxy_tool.jar -oppl_galax_lib/ +inference.jar +query.jar +oppl_galaxy_lib/ +inference_lib/ +query_lib/ FaCT++-linux-v1.5.2/ FaCT++-OSX-v1.5.2/ -inference.jar -inference_lib/ - + 3.- Create directory /galaxy-dist/tools/OPPL/ -4.- Copy oppl.xml and inference.xml to /galaxy-dist/tools/OPPL/ +4.- Copy oppl.xml, inference.xml and query.xml to +/galaxy-dist/tools/OPPL/ 5.- Add the following lines to /galaxy-dist/tool_conf.xml:
+
6.- Start Galaxy. @@ -34,24 +38,28 @@ FORESEEN FEATURES ================= -OPPL: +General (OPPL, Inference, Query): - Support for processing ontologies that import other ontologies loaded in galaxy. -- Rendering definition (URI fragment, label, etc). +- Entities rendering definition (URI fragment, rdfs:label, QName, etc). + +- OWLLink and Racer support. + + +OPPL: - Standalone OPPL assertions parsing (e.g. ADD phagocyte subClassOf cell). -- OWLLink and Racer support. +- Other output formats apart from RDF/XML. Inference: -- DataPropertyAssertion, DataPropertyHierarchy, DifferentIndividuals, -... - +- Support for DataPropertyAssertion, DataPropertyHierarchy, +DifferentIndividuals, ... @@ -87,10 +95,11 @@ Copyright (c) 2011 Mikel Egaña Aranguren. -(OPPL|Inference)-Galaxy is free software: you can redistribute it and/or -modify it under the terms of the GNU General Public License as published -by the Free Software Foundation, either version 3 of the License, or (at -your option) any later version. +(OPPL|Inference|Query)-Galaxy +is free software: you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your +option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query.jar Binary file OPPL/query.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OPPL/query.xml Thu Mar 29 14:49:22 2012 +0200 @@ -0,0 +1,73 @@ + + It performs a query, expressed in Manchester OWL Syntax, against an OWL ontology + + + + + + + java -Xmx7000M -Xms250M -DentityExpansionLimit=1000000000 -jar ${__tool_data_path__}/shared/jars/query.jar $ontology $reasoner $answer_type $answer_format "$query" > $output + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +**About Query-Galaxy** + + Query-Galaxy can be used to execute a DL query against an OWL ontology (e.g. GO_0007049 or part_of some GO_0007049). The result is a list of entities from the target ontology. How those entities relate to the query can be chosen (A DL query is just an anonymous OWL Class). + +**Formats** + + Inference-Galaxy uses the OWL API, and therefore it can load any ontology format that such API is able to load: OBO flat file, OWL (RDF/XML, OWL/XML, Functional, Manchester), turtle, and KRSS. The output is a list of terms. + +**Contact** + + Please send any request or comment to mikel.egana.aranguren@gmail.com. + + + + diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/FaCTpp-OWLAPI-3.2-v1.5.2.jar Binary file OPPL/query_lib/FaCTpp-OWLAPI-3.2-v1.5.2.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/HermiT.jar Binary file OPPL/query_lib/HermiT.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/antlr-runtime-3.2.jar Binary file OPPL/query_lib/antlr-runtime-3.2.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/aterm-java-1.6.jar Binary file OPPL/query_lib/aterm-java-1.6.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/commons-logging-1.1.1.jar Binary file OPPL/query_lib/commons-logging-1.1.1.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/jgrapht-jdk1.5.jar Binary file OPPL/query_lib/jgrapht-jdk1.5.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/junit-4.8.2.jar Binary file OPPL/query_lib/junit-4.8.2.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/junit.jar Binary file OPPL/query_lib/junit.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/log4j-1.2.15.jar Binary file OPPL/query_lib/log4j-1.2.15.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/oboformat.jar Binary file OPPL/query_lib/oboformat.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/org.coode.oppl-API.jar Binary file OPPL/query_lib/org.coode.oppl-API.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/owlapi-bin.jar Binary file OPPL/query_lib/owlapi-bin.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/owlapi-bin_2.jar Binary file OPPL/query_lib/owlapi-bin_2.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/owllink-bin.jar Binary file OPPL/query_lib/owllink-bin.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/parsers.jar Binary file OPPL/query_lib/parsers.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/pellet-core.jar Binary file OPPL/query_lib/pellet-core.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/pellet-datatypes.jar Binary file OPPL/query_lib/pellet-datatypes.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/pellet-el.jar Binary file OPPL/query_lib/pellet-el.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/pellet-owlapiv3.jar Binary file OPPL/query_lib/pellet-owlapiv3.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/pellet-query.jar Binary file OPPL/query_lib/pellet-query.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/query_lib/pellet-rules.jar Binary file OPPL/query_lib/pellet-rules.jar has changed diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/src/GalaxyOWLAPI.java --- a/OPPL/src/GalaxyOWLAPI.java Thu Mar 22 14:37:46 2012 +0100 +++ b/OPPL/src/GalaxyOWLAPI.java Thu Mar 29 14:49:22 2012 +0200 @@ -10,10 +10,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Scanner; +import java.util.Set; +import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxEditorParser; import org.coode.owlapi.obo.parser.OBOOntologyFormat; +import org.coode.parsers.BidirectionalShortFormProviderAdapter; import org.semanticweb.HermiT.Reasoner; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.expression.OWLEntityChecker; +import org.semanticweb.owlapi.expression.ParserException; +import org.semanticweb.owlapi.expression.ShortFormEntityChecker; import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.io.SystemOutDocumentTarget; import org.semanticweb.owlapi.model.AddAxiom; @@ -22,16 +28,20 @@ import org.semanticweb.owlapi.model.OWLAnnotationProperty; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassExpression; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyChange; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.reasoner.InferenceType; +import org.semanticweb.owlapi.reasoner.NodeSet; import org.semanticweb.owlapi.reasoner.OWLReasoner; import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; +import org.semanticweb.owlapi.util.BidirectionalShortFormProvider; import org.semanticweb.owlapi.util.InferredAxiomGenerator; import org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator; import org.semanticweb.owlapi.util.InferredDisjointClassesAxiomGenerator; @@ -41,8 +51,10 @@ import org.semanticweb.owlapi.util.InferredSubObjectPropertyAxiomGenerator; import org.semanticweb.owlapi.util.OWLEntityRenamer; import org.semanticweb.owlapi.util.OWLOntologyMerger; +import org.semanticweb.owlapi.util.SimpleShortFormProvider; import org.semanticweb.owlapi.vocab.OWL2Datatype; import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; +import org.semanticweb.owlapi.reasoner.Node; import uk.ac.manchester.cs.factplusplus.owlapiv3.FaCTPlusPlusReasonerFactory; @@ -103,7 +115,47 @@ IRI mergedOntologyIRI = IRI.create("http://oeg-upm.net/oppl_galaxy/merged.owl"); ontology = merger.createMergedOntology(manager, mergedOntologyIRI); } - + + public OWLClassExpression parseMOSClassExpression (String expr) throws ParserException{ + Set importsClosure = ontology.getImportsClosure(); + BidirectionalShortFormProvider bidiShortFormProvider = new BidirectionalShortFormProviderAdapter(manager, importsClosure, new SimpleShortFormProvider()); + OWLEntityChecker entityChecker = new ShortFormEntityChecker(bidiShortFormProvider); + ManchesterOWLSyntaxEditorParser MOSparser = new ManchesterOWLSyntaxEditorParser(manager.getOWLDataFactory(), expr); + MOSparser.setOWLEntityChecker(entityChecker); + return MOSparser.parseClassExpression(); + } + + public Set getIndividuals (OWLClassExpression expr){ + return (reasoner.getInstances(expr, false)).getFlattened(); + } + public Set getEquivalentClasses (OWLClassExpression expr){ + Node equivalentClasses = reasoner.getEquivalentClasses(expr); + Set result; + if (expr.isAnonymous()) { + result = equivalentClasses.getEntities(); + } + else { + result = equivalentClasses.getEntitiesMinus(expr.asOWLClass()); + } + return result; + } + + public Set getDirectSuperClasses (OWLClassExpression expr){ + return (reasoner.getSuperClasses(expr, true)).getFlattened(); + } + + public Set getAncestors (OWLClassExpression expr){ + return (reasoner.getSuperClasses(expr, false)).getFlattened(); + } + + public Set getDirectSubClasses (OWLClassExpression expr){ + return (reasoner.getSubClasses(expr, true)).getFlattened(); + } + + public Set getDescendants (OWLClassExpression expr){ + return (reasoner.getSubClasses(expr, false)).getFlattened(); + } + // CLASS_ASSERTIONS Denotes the computation of the direct types of individuals for each individual in the signature of the imports closure of the root ontology. public void addCLASS_ASSERTIONS(){ diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/src/OPPLGalaxy.java --- a/OPPL/src/OPPLGalaxy.java Thu Mar 22 14:37:46 2012 +0100 +++ b/OPPL/src/OPPLGalaxy.java Thu Mar 29 14:49:22 2012 +0200 @@ -24,6 +24,7 @@ import org.semanticweb.owlapi.reasoner.OWLReasoner; + /** * @author Mikel Egaña Aranguren * @@ -81,11 +82,13 @@ // Parse the OPPL script ParserFactory parserFactory = new ParserFactory(manager, ontology, reasoner); - Logger logger = Logger.getLogger(Tool.class.getName()); + Logger logger = Logger.getLogger(OPPLGalaxy.class.getName()); // Logging.getQueryLogger().setLevel(Level.OFF); // The normal messages are errors for galaxy (Fixed in Galaxy by 2 > /dev/null) ErrorListener errorListener = (ErrorListener)new LoggerErrorListener(logger); OPPLParser opplparser = parserFactory.build(errorListener); OPPLScript OPPLscript = opplparser.parse(OPPL_script_source); + + // Execute the script ChangeExtractor extractor = new ChangeExtractor(new QuickFailRuntimeExceptionHandler(), true); diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/src/OWLQueryGalaxy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OPPL/src/OWLQueryGalaxy.java Thu Mar 29 14:49:22 2012 +0200 @@ -0,0 +1,119 @@ +package es.upm.fi.dia.oeg.oppl.galaxy; + +import java.util.Set; + +import org.semanticweb.owlapi.expression.ParserException; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLNamedIndividual; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; + +public class OWLQueryGalaxy { + + /** + * @param args + * @throws OWLOntologyCreationException + * @throws ParserException + */ + public static void main(String[] args) throws OWLOntologyCreationException, ParserException { + // Get the arguments from command-line + String OWLFilePath = args [0]; // /home/pik/UPM/Paper/SWAT4LS_2011/JBS/Workflows_JBS/GO_module_transitive/go_no_trans.owl + String reasoner_type = args [1]; // Pellet|FaCTPlusPlus|HermiT + + String Answer_type = args [2]; // Individuals|EquivalentClasses|DirectSuperClasses|Ancestors|DirectSubClasses|Descendants + String Answer_render = args [3]; // URI|URIfragment|URIfragment2OBO + String MOS_query = args [4]; // GO_0007049 or part_of some GO_0007049 + + // Create the manager + GalaxyOWLAPI galaxyowlapi = new GalaxyOWLAPI(); + + // Load the main ontology and hope for the imported URIs to be resolvable + galaxyowlapi.loadMainOntology(OWLFilePath); + + // Set the reasoner + + // Pellet + if(reasoner_type.equals("Pellet")){ + galaxyowlapi.setReasonerPellet(); + } + // FaCTPlusPlus + else if (reasoner_type.equals("FaCTPlusPlus")){ + galaxyowlapi.setReasonerFaCT(); + } + // HermiT + else{ + galaxyowlapi.setReasonerHermit(); + } + + // Parse the expression to an OWLexpression + OWLClassExpression class_expr = galaxyowlapi.parseMOSClassExpression(MOS_query); + + // Execute query and print results + if(Answer_type.equals("Individuals")){ + Set inds = galaxyowlapi.getIndividuals(class_expr); + for(OWLNamedIndividual ind : inds){ + print_result_entity(ind.getIRI(), Answer_render); + } + } + else if (Answer_type.equals("EquivalentClasses")) { + Set answer_classes = galaxyowlapi.getEquivalentClasses(class_expr); + for(OWLClass cls : answer_classes){ + print_result_entity(cls.getIRI(), Answer_render); + } + } + else if (Answer_type.equals("DirectSuperClasses")) { + Set answer_classes = galaxyowlapi.getDirectSuperClasses(class_expr); + for(OWLClass cls : answer_classes){ + print_result_entity(cls.getIRI(), Answer_render); + } + } + else if (Answer_type.equals("Ancestors")) { + Set answer_classes = galaxyowlapi.getAncestors(class_expr); + for(OWLClass cls : answer_classes){ + print_result_entity(cls.getIRI(), Answer_render); + } + } + else if (Answer_type.equals("DirectSubClasses")) { + Set answer_classes = galaxyowlapi.getDirectSubClasses(class_expr); + for(OWLClass cls : answer_classes){ + print_result_entity(cls.getIRI(), Answer_render); + } + } + // Descendants + else { + Set answer_classes = galaxyowlapi.getDescendants(class_expr); + for(OWLClass cls : answer_classes){ + print_result_entity(cls.getIRI(), Answer_render); + } + } + } + + //URI|URIfragment|URIfragment2OBO + private static void print_result_entity (IRI iri, String Answer_render){ + if(Answer_render.equals("URI")){ + System.out.println(iri); + } + + // Weird bug: in eclipse it can print out the IRIs of every entity, but in Galaxy it can't! + // done manually + else if(Answer_render.equals("URIfragment")){ + if(iri.toString().contains("#")){ + System.out.println(iri.getFragment()); + } + else{ + String [] iri_tokens = iri.toString().split("/"); + System.out.println(iri_tokens[iri_tokens.length-1]); + } + } + else{ + if(iri.toString().contains("#")){ + System.out.println((iri.getFragment()).replace("_", ":")); + } + else{ + String [] iri_tokens = iri.toString().split("/"); + System.out.println((iri_tokens[iri_tokens.length-1]).replace("_", ":")); + } + } + } +} diff -r d0722148cb59 -r 7e6604a5ee55 OPPL/test-data/ontology/single/OWLQueryGalaxyTest.owl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OPPL/test-data/ontology/single/OWLQueryGalaxyTest.owl Thu Mar 29 14:49:22 2012 +0200 @@ -0,0 +1,193 @@ + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p some d: + +equiv a +sub b +desc b,b1, +ind aa + +inv_p some c + +ances d,f +sup d + + + + + + + + + + + + + + + + + + + + + + + + + + + + +