create, manage, and upload track hubs for use in the UCSC genome browser
Python Shell
Switch branches/tags
Nothing to show
Latest commit 8675508 Apr 9, 2017 @daler committed on GitHub Merge pull request #24 from detrout/access_attribute_safely
Avoid accessing g._html if it doesn't exist



trackhub is a Python package for handling the creation and uploading of track hubs for the UCSC Genome Browser (see for more info)

Some reasons for using trackhub to manage your track hubs:

  • filename handling: automatic (yet still completely configurable, if needed) handling of filenames and directory structure
  • uploading: upload a full hub -- hub/genomes/trackdb files, plus all data files (bam/bigWig/bigBed) -- via rsync over ssh
  • validation: mechanisms for handling validation of parameters so errors are [hopefully] caught prior to uploading
  • rapid deployment: mapping local filenames to remote filenames on the host enables rapid updating of the hub with new or updated data (e.g., when analysis parameters change)
  • flexibility: support for simple hubs up through complex composite hubs with views and subtracks
  • extensible: provides a framework for working with hub components, allowing new functionality to be easily added

Full documentation, including a full in-depth tutorial, can be found at

Here's an example of creating a hub, and uploading the hub and files to a remote server. This hub will show all the bigWig files in the current directory, and any of them that have "control" in the filename will be colored gray in the hub

from trackhub import Track, default_hub
from trackhub.upload import upload_hub, upload_track

hub, genomes_file, genome, trackdb = default_hub(
    short_label="example hub",
    long_label="My example hub",

# publicly accessible hub URL
hub.url = ""

# hub's location on remote host, for use with rsync
hub.remote_fn = "/var/www/data/hubs/my_example_hub.txt"

# Make tracks for all bigWigs in current dir
import glob, os
for fn in glob.glob('*.bigwig'):
    label = fn.replace('.bigwig', '')

    # Parameters are checked for valid values, see
    # for what's available
    track = Track(

# Demonstrate some post-creation, just make control
# samples gray
for track in trackdb.tracks:
    if 'control' in

# Render the hub to text files

# Upload the hub files and all the bigwig files using rsync.
kwargs = dict(host='', user='me')
upload_hub(hub=hub, **kwargs)
for track, level in hub.leaves(Track):
    upload_track(track=track, **kwargs)

Copyright 2012 Ryan Dale; BSD 2-clause license.