""" Contains the UCSC proxy """ from galaxy.web.base.controller import * import sys from galaxy import web, util import re, urllib, logging log = logging.getLogger( __name__ ) class UCSCProxy( BaseController ): 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 = 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 %s
%s' % (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 = "/echo?" + urllib.urlencode(params)
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 = ""
# 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)( %s' % (base_url, exc)
return msg
# HTML for generating the proxy page.
beginning = '''
This is a proxy to the data services provided by the UCSC Genome Browser's Table Browser. To reset all user cart settings (including custom tracks), \nclick here.' : '',
'ACTION="../cgi-bin/hgTables"' : 'ACTION="/ucsc_proxy/index"',
'custom track' : 'custom track',
'' : '',
'' : '',
".*)",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 + "
" + 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 %s
\n\noutput file: (leave blank to keep output in browser) ' : '',
' \nfile type returned: plain text   gzip compressed