mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
@@ -1,165 +0,0 @@
|
||||
"""
|
||||
Contains the UCSC proxy
|
||||
"""
|
||||
|
||||
from galaxy.web.base.controller import BaseUIController
|
||||
|
||||
import json
|
||||
from galaxy import web, util
|
||||
|
||||
import re
|
||||
import urllib
|
||||
import logging
|
||||
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
|
||||
class UCSCProxy( BaseUIController ):
|
||||
|
||||
def create_display(self, store):
|
||||
"""Creates a more meaningulf display name"""
|
||||
track = store.get('hgta_track', 'no track')
|
||||
table = store.get('hgta_table', 'no table')
|
||||
region = store.get('hgta_regionType', '')
|
||||
if region not in [ 'genome', 'encode']:
|
||||
region = store.get('position', '')
|
||||
if track == table:
|
||||
display = 'UCSC: %s (%s)' % (track, region)
|
||||
else:
|
||||
display = 'UCSC: %s, %s (%s)' % (track, table, region)
|
||||
return display
|
||||
|
||||
@web.expose
|
||||
def index(self, trans, init=False, **kwd):
|
||||
base_url = None
|
||||
params = dict(kwd)
|
||||
try:
|
||||
store = params.get("__GALAXY__", None)
|
||||
if store:
|
||||
store = json.loads(util.string_to_object(store))
|
||||
else:
|
||||
store = {}
|
||||
UCSC_URL = 'UCSC_URL'
|
||||
base_url = store.get(UCSC_URL, "http://genome.ucsc.edu/cgi-bin/hgTables?")
|
||||
params = dict(kwd)
|
||||
params['init'] = init
|
||||
|
||||
if not init:
|
||||
for key, value in kwd.items():
|
||||
store[key] = value
|
||||
try:
|
||||
del store["__GALAXY__"]
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
store = {}
|
||||
|
||||
if init == "1":
|
||||
base_url = "http://genome.ucsc.edu/cgi-bin/hgTables?"
|
||||
params['db'] = 'hg17'
|
||||
if init == "2":
|
||||
base_url = "http://genome-test.cse.ucsc.edu/cgi-bin/hgTables?"
|
||||
params['db'] = 'hg17'
|
||||
if init == "3":
|
||||
base_url = "http://archaea.ucsc.edu/cgi-bin/hgTables?"
|
||||
|
||||
store[UCSC_URL] = base_url
|
||||
|
||||
try:
|
||||
del params["__GALAXY__"]
|
||||
except:
|
||||
pass
|
||||
url = base_url + urllib.urlencode(params)
|
||||
|
||||
page = urllib.urlopen(url)
|
||||
content = page.info().get('Content-type', '')
|
||||
except Exception, exc:
|
||||
trans.log_event( "Proxy Error -> %s" % str(exc) )
|
||||
msg = 'There has been a problem connecting to <i>%s</i> <p> <b>%s<b>' % (base_url, exc)
|
||||
return msg
|
||||
|
||||
if content.startswith('text/plain'):
|
||||
params['display'] = self.create_display(store)
|
||||
params['dbkey'] = store.get('db', '*')
|
||||
params['tool_id'] = 'ucsc_proxy'
|
||||
params['proxy_url'] = base_url
|
||||
params['runtool_btn'] = 'T'
|
||||
url = "/tool_runner/index?" + urllib.urlencode(params)
|
||||
trans.response.send_redirect(url)
|
||||
else:
|
||||
try:
|
||||
text = page.read()
|
||||
|
||||
# Serialize store into a form element
|
||||
store_text = "<INPUT TYPE=\"HIDDEN\" NAME=\"__GALAXY__\" ID=\"__GALAXY__\" VALUE=\"" \
|
||||
+ json.dumps(util.object_to_string(store)) + "\" \>"
|
||||
|
||||
# Remove text regions that should not be exposed
|
||||
for key, value in altered_regions.items():
|
||||
text = text.replace(key, value)
|
||||
# Capture only the forms
|
||||
newtext = beginning
|
||||
for form in re.finditer("(?s)(<FORM.*?)(</FORM>)", text):
|
||||
newtext = newtext + form.group(1) + store_text + form.group(2)
|
||||
if 'hgta_doLookupPosition' in params:
|
||||
lookup = re.search("(?s).*?(<H2>.*</PRE>)", text)
|
||||
if lookup:
|
||||
newtext = newtext + lookup.group(1)
|
||||
# if these keys are in the params, then pass the content through
|
||||
passthruContent = ['hgta_doSummaryStats', 'hgta_doSchema', 'hgta_doSchemaDb']
|
||||
for k in passthruContent:
|
||||
if k in params:
|
||||
content = re.search("(?s)CONTENT TABLES.*?-->(.*/TABLE>)", text)
|
||||
if content:
|
||||
newtext = newtext + "<TABLE>" + content.group(1)
|
||||
|
||||
newtext = newtext + ending
|
||||
return newtext
|
||||
except KeyError, exc:
|
||||
log.error(str(exc))
|
||||
trans.log_event( "Proxy Error -> %s" % str(exc) )
|
||||
msg = 'There has been a problem connecting to <i>%s</i> <p> <b>%s<b>' % (base_url, exc)
|
||||
return msg
|
||||
|
||||
# HTML for generating the proxy page.
|
||||
beginning = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Galaxy</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<link href="/static/style/base.css" rel="stylesheet" type="text/css" />
|
||||
<script language="javascript" type="text/javascript">
|
||||
function changeTarget(target)
|
||||
{
|
||||
document.forms['mainForm'].target = target;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="toolForm" id="ucsc_proxy">
|
||||
<div class="toolFormTitle">UCSC Table Browser</div>
|
||||
|
||||
<div class="toolFormBody">
|
||||
'''
|
||||
ending = '''
|
||||
<P>This is a proxy to the data services provided by the <a href=\"http://genome.ucsc.edu\" target=\"_blank\">UCSC Genome Browser</a>'s <a href=\"http://genome.ucsc.edu/cgi-bin/hgTables\" target=\"_blank\">Table Browser.</a></P>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>'''
|
||||
|
||||
# This is a mess of mappings of text to make the proxy friendlier to
|
||||
# galaxy users.
|
||||
altered_regions = {
|
||||
'"../cgi-bin/hgTables' : '"/ucsc_proxy/index',
|
||||
'<TR><TD>\n<B>output file:</B> <INPUT TYPE=TEXT NAME="hgta_outFileName" SIZE=29 VALUE=""> (leave blank to keep output in browser)</TD></TR>\n<TR><TD>\n<B>file type returned: </B><INPUT TYPE=RADIO NAME="hgta_compressType" VALUE="none" CHECKED> plain text  <INPUT TYPE=RADIO NAME="hgta_compressType" VALUE="gzip" > gzip compressed</TD></TR>' : '<INPUT TYPE=HIDDEN NAME="hgta_compressType" VALUE="none" /><INPUT TYPE=HIDDEN NAME="hgta_outFileName" VALUE="" />',
|
||||
' <P>To reset <B>all</B> user cart settings (including custom tracks), \n<A HREF="/cgi-bin/cartReset?destination=/cgi-bin/hgTables">click here</A>.' : '',
|
||||
'ACTION="../cgi-bin/hgTables"' : 'ACTION="/ucsc_proxy/index"',
|
||||
'<A HREF="/goldenPath/help/customTrack.html" TARGET=_blank>custom track</A>' : '<A HREF="http://genome.ucsc.edu/goldenPath/help/customTrack.html" TARGET=_blank>custom track</A>',
|
||||
'<INPUT TYPE=RADIO NAME="hgta_regionType" VALUE="genome" onClick="regionType=\'genome\';" CHECKED>' : '<INPUT TYPE=RADIO NAME="hgta_regionType" VALUE="genome" onClick="regionType=\'genome\';">',
|
||||
'<INPUT TYPE=RADIO NAME="hgta_regionType" VALUE="range" onClick="regionType=\'range\';">' : '<INPUT TYPE=RADIO NAME="hgta_regionType" VALUE="range" onClick="regionType=\'range\';" CHECKED>',
|
||||
"<OPTION VALUE=bed>" : "<OPTION VALUE=bed SELECTED>" ,
|
||||
'<INPUT TYPE=SUBMIT NAME="hgta_doSchema" VALUE="describe table schema">' : '<INPUT TYPE=SUBMIT NAME="hgta_doSchema" VALUE="describe table schema" onClick="changeTarget(\'_blank\')" onMouseOut="changeTarget(\'_self\')">'
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<tool name="UCSC Archaea" id="ucsc_proxy" version="1.0.0">
|
||||
|
||||
<description>table browser</description>
|
||||
|
||||
<command interpreter="python">
|
||||
ucsc_proxy.py $param_file $output
|
||||
</command>
|
||||
|
||||
<inputs action="/ucsc_proxy/index" check_values="false">
|
||||
<display>go to UCSC $init $hgta_outputType</display>
|
||||
<param type="hidden" name="init" value="3"/>
|
||||
<param type="hidden" name="hgta_outputType" value="bed"/>
|
||||
</inputs>
|
||||
|
||||
<code file="ucsc_filter.py"/>
|
||||
|
||||
<outputs>
|
||||
<data name="output" format="bed" />
|
||||
</outputs>
|
||||
|
||||
</tool>
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
# runs after the job (and after the default post-filter)
|
||||
from galaxy import datatypes, jobs
|
||||
|
||||
def validate(incoming):
|
||||
"""Validator"""
|
||||
#raise Exception, 'not quite right'
|
||||
pass
|
||||
|
||||
def exec_before_job( app, inp_data, out_data, param_dict, tool=None):
|
||||
"""Sets the name of the data"""
|
||||
outputType = param_dict.get( 'hgta_outputType', None )
|
||||
if isinstance(outputType, list) and len(outputType)>0: outputType = outputType[-1]
|
||||
items = out_data.items()
|
||||
|
||||
for name, data in items:
|
||||
data.name = param_dict.get('display', data.name)
|
||||
data.dbkey = param_dict.get('dbkey', '???')
|
||||
|
||||
if outputType == 'wigData':
|
||||
ext = "wig"
|
||||
elif outputType == 'maf':
|
||||
ext = "maf"
|
||||
elif outputType == 'gff':
|
||||
ext = "gff"
|
||||
elif outputType == 'gff3':
|
||||
ext = "gff3"
|
||||
else:
|
||||
if 'hgta_doPrintSelectedFields' in param_dict:
|
||||
ext = "interval"
|
||||
elif 'hgta_doGetBed' in param_dict:
|
||||
ext = "bed"
|
||||
elif 'hgta_doGenomicDna' in param_dict:
|
||||
ext = "fasta"
|
||||
elif 'hgta_doGenePredSequence' in param_dict:
|
||||
ext = "fasta"
|
||||
else:
|
||||
ext = "interval"
|
||||
|
||||
data = app.datatypes_registry.change_datatype(data, ext)
|
||||
out_data[name] = data
|
||||
|
||||
def exec_after_process( app, inp_data, out_data, param_dict, tool=None, stdout=None, stderr=None):
|
||||
"""Verifies the data after the run"""
|
||||
items = out_data.items()
|
||||
for name, data in items:
|
||||
data.set_size()
|
||||
try:
|
||||
err_msg, err_flag = 'Errors:', False
|
||||
line_count = 0
|
||||
num_lines = len(file(data.file_name).readlines())
|
||||
for line in file(data.file_name):
|
||||
line_count += 1
|
||||
if line and line[0] == '-':
|
||||
if line_count + 3 == num_lines and not err_flag:
|
||||
err_flag = True
|
||||
err_msg = "Warning: It appears that your results have been truncated by UCSC. View the bottom of your result file for details."
|
||||
break
|
||||
err_flag = True
|
||||
err_msg = err_msg +" (line "+str(line_count)+")"+line
|
||||
data.set_peek()
|
||||
if isinstance(data.datatype, datatypes.interval.Interval) and data.missing_meta():
|
||||
data = app.datatypes_registry.change_datatype(data, 'tabular')
|
||||
out_data[name] = data
|
||||
if err_flag:
|
||||
raise Exception(err_msg)
|
||||
except Exception, exc:
|
||||
data.info = data.info + "\n" + str(exc)
|
||||
data.blurb = "error"
|
||||
@@ -1,65 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import urllib
|
||||
import sys, os
|
||||
|
||||
assert sys.version_info[:2] >= ( 2, 4 )
|
||||
|
||||
CHUNK = 2**20 # 1Mb
|
||||
MAXSIZE = CHUNK * 100
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print 'Usage ucsc.py input_params output_file'
|
||||
sys.exit()
|
||||
|
||||
inp_file = sys.argv[1]
|
||||
out_file = sys.argv[2]
|
||||
|
||||
DEFAULT_URL = "http://genome.ucsc.edu/hgTables?"
|
||||
|
||||
# this must stay a list to allow multiple selections for the same widget name (checkboxes)
|
||||
params = []
|
||||
for line in file(inp_file):
|
||||
line = line.strip()
|
||||
if line:
|
||||
parts = line.split('=')
|
||||
if len(parts) == 0:
|
||||
key = ""
|
||||
value = ""
|
||||
elif len(parts) == 1:
|
||||
key = parts[0]
|
||||
value = ""
|
||||
else:
|
||||
key = parts[0]
|
||||
value = parts[1]
|
||||
if key == 'display':
|
||||
print value
|
||||
# get url from params, refered from proxy.py, initialized by the tool xml
|
||||
elif key == 'proxy_url':
|
||||
DEFAULT_URL = value
|
||||
else:
|
||||
params.append( (key, value) )
|
||||
|
||||
#print params
|
||||
|
||||
encoded_params = urllib.urlencode(params)
|
||||
url = DEFAULT_URL + encoded_params
|
||||
|
||||
#print url
|
||||
|
||||
page = urllib.urlopen(url)
|
||||
|
||||
fp = open(out_file, 'wt')
|
||||
size = 0
|
||||
while 1:
|
||||
data = page.read(CHUNK)
|
||||
if not data:
|
||||
break
|
||||
if size > MAXSIZE:
|
||||
fp.write('----- maximum datasize exceeded ---\n')
|
||||
break
|
||||
size += len(data)
|
||||
fp.write(data)
|
||||
|
||||
fp.close()
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<tool name="UCSC Main" id="ucsc_proxy" version="1.0.0">
|
||||
|
||||
<description>table browser proxy</description>
|
||||
|
||||
<command interpreter="python">
|
||||
ucsc_proxy.py $param_file $output
|
||||
</command>
|
||||
|
||||
<inputs action="/ucsc_proxy/index" check_values="false">
|
||||
<display>go to UCSC $init $hgta_outputType</display>
|
||||
<param type="hidden" name="init" value="1"/>
|
||||
<param type="hidden" name="hgta_outputType" value="bed"/>
|
||||
</inputs>
|
||||
|
||||
<code file="ucsc_filter.py"/>
|
||||
|
||||
<outputs>
|
||||
<data name="output" format="bed" />
|
||||
</outputs>
|
||||
|
||||
</tool>
|
||||
|
||||
@@ -39,4 +39,8 @@
|
||||
<data name="output" format="tabular" label="${tool.name} on ${organism}: ${table} (#if $description == 'range' then $getVar( 'position', 'unknown position' ) else $description#)"/>
|
||||
</outputs>
|
||||
<options sanitize="False" refresh="True"/>
|
||||
<citations>
|
||||
<citation type="doi">10.1093/database/bar011</citation>
|
||||
<citation type="doi">10.1101/gr.229102</citation>
|
||||
</citations>
|
||||
</tool>
|
||||
|
||||
@@ -39,4 +39,9 @@
|
||||
<data name="output" format="tabular" label="${tool.name} on ${organism}: ${table} (#if $description == 'range' then $getVar( 'position', 'unknown position' ) else $description#)"/>
|
||||
</outputs>
|
||||
<options sanitize="False" refresh="True"/>
|
||||
<citations>
|
||||
<citation type="doi">10.1093/database/bar011</citation>
|
||||
<citation type="doi">10.1101/gr.229102</citation>
|
||||
<citation type="doi">10.1093/nar/gkj134</citation>
|
||||
</citations>
|
||||
</tool>
|
||||
|
||||
@@ -39,4 +39,8 @@
|
||||
<data name="output" format="tabular" label="${tool.name} on ${organism}: ${table} (#if $description == 'range' then $getVar( 'position', 'unknown position' ) else $description#)"/>
|
||||
</outputs>
|
||||
<options sanitize="False" refresh="True"/>
|
||||
<citations>
|
||||
<citation type="doi">10.1093/database/bar011</citation>
|
||||
<citation type="doi">10.1101/gr.229102</citation>
|
||||
</citations>
|
||||
</tool>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<tool name="UCSC Test" id="ucsc_testproxy" version="1.0.0">
|
||||
|
||||
<description>table browser proxy</description>
|
||||
|
||||
<command interpreter="python">
|
||||
ucsc_proxy.py $param_file $output
|
||||
</command>
|
||||
|
||||
<inputs action="/ucsc_proxy/index" check_values="false">
|
||||
<display>go to UCSC genome-test $init $hgta_outputType</display>
|
||||
<param type="hidden" name="init" value="2"/>
|
||||
<param type="hidden" name="hgta_outputType" value="bed"/>
|
||||
</inputs>
|
||||
|
||||
<code file="ucsc_filter.py"/>
|
||||
|
||||
<outputs>
|
||||
<data name="output" format="bed" />
|
||||
</outputs>
|
||||
|
||||
</tool>
|
||||
|
||||
Reference in New Issue
Block a user