Mercurial > repos > mikel-egana-aranguren > sparql_galaxy
changeset 4:6501986529b0 draft
HTML or tabular option added
author | mikel-egana-aranguren <mikel.egana.aranguren@gmail.com> |
---|---|
date | Mon, 28 Apr 2014 16:11:05 +0200 |
parents | 24ad2706526c |
children | a0bb4dafb64b |
files | galaxy-dist/tools/sparql_galaxy/SPARQLGalaxy.xml galaxy-dist/tools/sparql_galaxy/sparql.py |
diffstat | 2 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/galaxy-dist/tools/sparql_galaxy/SPARQLGalaxy.xml Fri Apr 25 15:42:31 2014 +0200 +++ b/galaxy-dist/tools/sparql_galaxy/SPARQLGalaxy.xml Mon Apr 28 16:11:05 2014 +0200 @@ -1,18 +1,28 @@ <tool id="SPARQLGalaxy" name="Execute an SPARQL query against an RDF file" version="1.0.1"> <description>It executes an SPARQL query against the input RDF file and generates an HTML file with the variables and bound entities</description> <command interpreter="python"> - sparql.py $ontology "$pasted_query" > $output 2>/dev/null + sparql.py $ontology "$pasted_query" $out_format > $output 2>/dev/null </command> <inputs> <param name="ontology" type="data" format="rdf" label="Input RDF file"/> <param name="pasted_query" type="text" area="True" size="10x50" label="SPARQL Query" value="SELECT * WHERE { ?s ?p ?o }"> <sanitizer sanitize="False"/> + </param> + <param name="out_format" type="select" label="Output format" help=""> + <option value="html" selected="true">HTML</option> + <option value="tab">TABULAR</option> </param> + </inputs> <outputs> - <data format="html" name="output" /> + <data format="html" name="output"> + <change_format> + <when input="out_format" value="tab" format="tabular" /> + </change_format> + </data> </outputs> <help> + **Important note**
--- a/galaxy-dist/tools/sparql_galaxy/sparql.py Fri Apr 25 15:42:31 2014 +0200 +++ b/galaxy-dist/tools/sparql_galaxy/sparql.py Mon Apr 28 16:11:05 2014 +0200 @@ -1,13 +1,21 @@ - import sys import rdflib +from operator import eq def main(argv): g = rdflib.Graph() g.parse(argv[1]) results = g.query(argv[2]) + render = argv[3] + + if (render == "html"): + html_render(results) + else: + tab_render(results) + +def html_render(results): print "<table>" print "<tr>" for key in results.bindings[1].keys(): @@ -23,5 +31,14 @@ print "</tr>" print "</table>" +def tab_render(results): + for key in results.bindings[1].keys(): + print key + "\t", + print "\n" + for binding in results.bindings: + for value in binding.values(): + if isinstance(value, rdflib.term.URIRef): + print value + "\t", + if __name__ == "__main__": main(sys.argv) \ No newline at end of file