Add UCSC Table Browser direct connection tool.

This commit is contained in:
Daniel Blankenberg
2007-02-28 20:46:06 +00:00
parent 0dfd869918
commit 412b9a9677
4 changed files with 112 additions and 0 deletions
+1
View File
@@ -2,6 +2,7 @@
<toolbox>
<section name="Get Data" id="getext">
<tool file="data_source/upload.xml"/>
<tool file="data_source/ucsc_tablebrowser.xml" />
<tool file="data_source/ucsc_proxy.xml"/>
<tool file="data_source/ucsc_testproxy.xml" />
<tool file="data_source/ucsc_archaea.xml" />
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env python2.4
#Retreives data from UCSC and stores in a file. UCSC parameters are provided in the input/output file.
import urllib, sys
def __main__():
filename = sys.argv[1]
params = {}
for line in open(filename, 'r'):
try:
line = line.strip()
fields = line.split('\t')
params[fields[0]] = fields[1]
except:
continue
URL = params.get('URL',None)
if not URL:
open(filename, 'w').write("")
#raise Exception('Datasource has not sent back a URL parameter')
print >> sys.stderr, 'Datasource has not sent back a URL parameter'
sys.exit(0)
out = open(filename, 'w')
CHUNK_SIZE = 2**20 # 1Mb
try:
page = urllib.urlopen(URL, urllib.urlencode(params))
except Exception, exc:
#raise Exception('Problems connecting to %s (%s)' % (URL, exc) )
print >> sys.stderr, 'Problems connecting to %s (%s)' % (URL, exc)
sys.exit(0)
while 1:
chunk = page.read(CHUNK_SIZE)
if not chunk:
break
out.write(chunk)
out.close()
if __name__ == "__main__": __main__()
+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<tool name="UCSC Table Browser" id="ucsc_table_direct1">
<description>direct connection</description>
<command interpreter="python2.4">ucsc_tablebrowser.py $output</command>
<inputs action="http://genome-test.cse.ucsc.edu/cgi-bin/hgTables" check_values="false" method="get">
<display>go to UCSC Table Browser $GALAXY_URL</display>
<param name="GALAXY_URL" type="baseurl" value="/tool_runner" />
<param name="tool_id" type="hidden" value="ucsc_table_direct1" />
<param name="sendToGalaxy" type="hidden" value="1" />
<param name="hgta_compressType" type="hidden" value="none" />
</inputs>
<code file="ucsc_tablebrowser_code.py"/>
<outputs>
<data name="output" format="bed" />
</outputs>
<options sanitize="False" refresh="True"/>
</tool>
@@ -0,0 +1,44 @@
#Code for direct connection to UCSC
from galaxy import datatypes
def exec_before_job( trans, inp_data, out_data, param_dict, tool=None):
"""Sets the name of the data"""
outputType = param_dict.get( 'hgta_outputType', "interval" ) #assume all data is interval, we will fix later if not the case
#list for converting ucsc to galaxy exts, if not in here, use raw reported value
outputType_to_ext = {'wigData':'wig','tab':'interval'}
items = out_data.items()
description = param_dict.get('hgta_regionType',"")
organism = param_dict.get('org',"unkown species")
table = param_dict.get('hgta_track',"")
if description == 'range':
try:
description = param_dict.get('position',"")
except:
description = "unkown position"
for name, data in items:
data.name = "%s on %s: %s (%s)" % (data.name, organism, table, description)
data.dbkey = param_dict.get('db', '?')
ext = outputType
try: ext = outputType_to_ext[outputType]
except: pass
data = datatypes.change_datatype(data, ext)
#store ucsc parameters temporarily in output file
out = open(data.file_name,'w')
for key, value in param_dict.items():
print >> out, "%s\t%s" % (key,value)
out.close()
out_data[name] = data
def exec_after_process(app, inp_data, out_data, param_dict, tool=None, stdout=None, stderr=None):
"""Verifies the datatype after the run"""
name, data = out_data.items()[0]
if data.state == data.states.OK: data.info = data.name
if not isinstance(data.datatype, datatypes.interval.Bed) and isinstance(data.datatype, datatypes.interval.Interval):
data.set_meta()
if data.missing_meta(): data = datatypes.change_datatype(data, 'tabular')
data.set_peek()
data.flush()