Mercurial > repos > mikel-egana-aranguren > oppl
changeset 13:7e6604a5ee55
New query tool added
line wrap: on
line diff
--- 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: <section name="Ontology Pre Processor Language" id="oppl"> <tool file="OPPL/oppl.xml"/> <tool file="OPPL/inference.xml"/> + <tool file="OPPL/query.xml"/> </section> 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
--- /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 @@ +<tool id="query" name="Perform an OWL query against an ontology" version="1.0.1"> + <description>It performs a query, expressed in Manchester OWL Syntax, against an OWL ontology</description> + + <!-- DEFAULT SETTINGS --> + + <!-- For big ontologies I use -Xmx7000M -Xms250M -DentityExpansionLimit=1000000000 If that's too much for your machine simply delete or modify at will, but since Galaxy is usually used in a server setting it makes sense to use a big chunk of memory --> + + <command> + java -Xmx7000M -Xms250M -DentityExpansionLimit=1000000000 -jar ${__tool_data_path__}/shared/jars/query.jar $ontology $reasoner $answer_type $answer_format "$query" > $output + </command> + + <!-- FACT++ --> + + <!-- If you are planning to use FaCT++ you have to uncomment bellow (And comment the default settings above) and replace the -Djava.library.path with the appropiate JNI library path for your platform:FaCT++-linux-v1.5.2/64bit, FaCT++-linux-v1.5.2/32bit, FaCT++-OSX-v1.5.2/64bit, ...... --> + <!-- Using this setting doesn't upset the rest of the reasoners so you may as well leave it on if you plan to switch between FaCT++, Pellet and HermiT --> + + <!--<command> + java -Djava.library.path=${__tool_data_path__}/shared/jars/FaCT++-linux-v1.5.2/64bit -Xmx7000M -Xms250M -DentityExpansionLimit=1000000000 -jar ${__tool_data_path__}/shared/jars/query.jar $ontology $reasoner $answer_type $answer_format "$query" > $output + </commadn>--> + + + <inputs> + <param format="text" name="ontology" type="data" label="Input ontology file"/> + <param name="query" type="text" size="100" value="" label="Query" /> + <param name="reasoner" type="select" label="Choose reasoner"> + <option value="Pellet" selected="true">Pellet</option> + <option value="HermiT">HermiT</option> + <option value="FaCTPlusPlus">FaCT++</option> + </param> + <param name="answer_type" type="select" label="Choose answer type"> + <option value="Descendants">Descendant classes</option> + <option value="DirectSubClasses" selected="true">Direct sub-classes</option> + <option value="Ancestors">Ancestor classes</option> + <option value="DirectSuperClasses">Direct super-classes</option> + <option value="EquivalentClasses">Equivalent classes</option> + <option value="Individuals">Individuals</option> + </param> + <param name="answer_format" type="select" label="Choose how to render the retrieved entities"> + <option value="URI" selected="true">URI</option> + <option value="URIfragment">URI fragment</option> + <option value="URIfragment2OBO">OBO type URI fragment (e.g. GO_0000022 to GO:0000022)</option> + </param> + </inputs> + <outputs> + <data format="text" name="output" /> + </outputs> + <tests> + <test> + <param name="input" value="OWLQueryGalaxyTest.owl"/> + <param name="query" value="p some d"/> + <param name="reasoner" value="Pellet"/> + <param name="answer_type" value="DirectSubClasses"/> + <param name="answer_format" value="URIfragment"/> + <output name="out_file" file="query_result"/> + </test> + </tests> + <help> + +**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. + + </help> + +</tool>
--- 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<OWLOntology> 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<OWLNamedIndividual> getIndividuals (OWLClassExpression expr){ + return (reasoner.getInstances(expr, false)).getFlattened(); + } + public Set<OWLClass> getEquivalentClasses (OWLClassExpression expr){ + Node<OWLClass> equivalentClasses = reasoner.getEquivalentClasses(expr); + Set<OWLClass> result; + if (expr.isAnonymous()) { + result = equivalentClasses.getEntities(); + } + else { + result = equivalentClasses.getEntitiesMinus(expr.asOWLClass()); + } + return result; + } + + public Set<OWLClass> getDirectSuperClasses (OWLClassExpression expr){ + return (reasoner.getSuperClasses(expr, true)).getFlattened(); + } + + public Set<OWLClass> getAncestors (OWLClassExpression expr){ + return (reasoner.getSuperClasses(expr, false)).getFlattened(); + } + + public Set<OWLClass> getDirectSubClasses (OWLClassExpression expr){ + return (reasoner.getSubClasses(expr, true)).getFlattened(); + } + + public Set<OWLClass> 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(){
--- 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);
--- /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<OWLNamedIndividual> inds = galaxyowlapi.getIndividuals(class_expr); + for(OWLNamedIndividual ind : inds){ + print_result_entity(ind.getIRI(), Answer_render); + } + } + else if (Answer_type.equals("EquivalentClasses")) { + Set<OWLClass> 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<OWLClass> 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<OWLClass> 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<OWLClass> answer_classes = galaxyowlapi.getDirectSubClasses(class_expr); + for(OWLClass cls : answer_classes){ + print_result_entity(cls.getIRI(), Answer_render); + } + } + // Descendants + else { + Set<OWLClass> 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("_", ":")); + } + } + } +}
--- /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 @@ +<?xml version="1.0"?> + + +<!DOCTYPE rdf:RDF [ + <!ENTITY owl "http://www.w3.org/2002/07/owl#" > + <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" > + <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" > + <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > + <!ENTITY OWLQueryGalaxyTest2 "http://www.oeg-upm.net/OWLQueryGalaxyTest.owl#" > + <!ENTITY OWLQueryGalaxyTest "http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/" > +]> + + +<rdf:RDF xmlns="http://www.oeg-upm.net/OWLQueryGalaxyTest.owl#" + xml:base="http://www.oeg-upm.net/OWLQueryGalaxyTest.owl" + xmlns:OWLQueryGalaxyTest2="http://www.oeg-upm.net/OWLQueryGalaxyTest.owl#" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:OWLQueryGalaxyTest="http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + <owl:Ontology rdf:about="http://www.oeg-upm.net/OWLQueryGalaxyTest.owl"/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Annotation properties + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Datatypes + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Object Properties + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/inv_p --> + + <owl:ObjectProperty rdf:about="&OWLQueryGalaxyTest;inv_p"/> + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/p --> + + <owl:ObjectProperty rdf:about="&OWLQueryGalaxyTest;p"> + <owl:inverseOf rdf:resource="&OWLQueryGalaxyTest;inv_p"/> + </owl:ObjectProperty> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Classes + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl#GO_0000034 --> + + <owl:Class rdf:about="&OWLQueryGalaxyTest2;GO_0000034"> + <rdfs:subClassOf> + <owl:Restriction> + <owl:onProperty rdf:resource="&OWLQueryGalaxyTest;p"/> + <owl:someValuesFrom rdf:resource="&OWLQueryGalaxyTest;d"/> + </owl:Restriction> + </rdfs:subClassOf> + </owl:Class> + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/GO_0000033 --> + + <owl:Class rdf:about="&OWLQueryGalaxyTest;GO_0000033"> + <rdfs:subClassOf rdf:resource="&OWLQueryGalaxyTest2;GO_0000034"/> + </owl:Class> + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/a --> + + <owl:Class rdf:about="&OWLQueryGalaxyTest;a"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="&OWLQueryGalaxyTest;p"/> + <owl:someValuesFrom rdf:resource="&OWLQueryGalaxyTest;d"/> + </owl:Restriction> + </owl:equivalentClass> + </owl:Class> + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/c --> + + <owl:Class rdf:about="&OWLQueryGalaxyTest;c"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="&OWLQueryGalaxyTest;p"/> + <owl:allValuesFrom rdf:resource="&OWLQueryGalaxyTest;d"/> + </owl:Restriction> + </owl:equivalentClass> + </owl:Class> + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/d --> + + <owl:Class rdf:about="&OWLQueryGalaxyTest;d"> + <rdfs:subClassOf rdf:resource="&OWLQueryGalaxyTest;f"/> + </owl:Class> + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/f --> + + <owl:Class rdf:about="&OWLQueryGalaxyTest;f"/> + + + + <!-- http://www.w3.org/2002/07/owl#Thing --> + + <rdf:Description rdf:about="&owl;Thing"> + <rdfs:comment>p some d: + +equiv a +sub b +desc b,b1, +ind aa + +inv_p some c + +ances d,f +sup d</rdfs:comment> + </rdf:Description> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Individuals + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/aa --> + + <owl:Thing rdf:about="&OWLQueryGalaxyTest;aa"> + <rdf:type rdf:resource="&owl;NamedIndividual"/> + <OWLQueryGalaxyTest:p rdf:resource="&OWLQueryGalaxyTest;dd"/> + </owl:Thing> + + + + <!-- http://www.oeg-upm.net/OWLQueryGalaxyTest.owl/dd --> + + <owl:NamedIndividual rdf:about="&OWLQueryGalaxyTest;dd"> + <rdf:type rdf:resource="&OWLQueryGalaxyTest;d"/> + </owl:NamedIndividual> +</rdf:RDF> + + + +<!-- Generated by the OWL API (version 3.2.2.1782) http://owlapi.sourceforge.net --> +