'Generate links to UCSC genome browser sites based on the dbkey
and content of dataset.'

def ucsc_links(self, dataset, type, app, base_url):

    valid_sites = [(name, url) for (name, url) in app.datatypes_registry.get_legacy_sites_by_build('ucsc', dataset.dbkey) if (name in app.datatypes_registry.get_display_sites('ucsc'))]
    if (not valid_sites):
        return []
    (chrom, start, stop) = self.get_estimated_display_viewport(dataset)
    if (chrom is None):
        return []
    ret_val = []
    for (site_name, site_url) in valid_sites:
        internal_url = url_for(controller='dataset', dataset_id=dataset.id, action='display_at', filename=('ucsc_' + site_name))
        display_url = quote_plus(('%s%s/display_as?id=%i&display_app=%s&authz_method=display_at' % (base_url, url_for(controller='root'), dataset.id, type)))
        redirect_url = quote_plus(('%sdb=%s&position=%s:%s-%s&hgt.customText=%%s' % (site_url, dataset.dbkey, chrom, start, stop)))
        link = ('%s?redirect_url=%s&display_url=%s' % (internal_url, redirect_url, display_url))
        ret_val.append((site_name, link))
    return ret_val
