a script to fetch images from the UCSC browser

The UCSC browser is a nice, useful but “mammoth-ish” bioinformatics tool that despite its web 1.0 aspect, can be a very powerful ally for any bioinformaticians or biologist.

I have to admit that for many years I avoided using the UCSC browser, dismissing it because of its very old fashioned look. It was silly of me to think that way, but its interface is objectively old: for example, the user is forced to reload the whole page to update the visualization, and the fonts are not anti-aliased, and they look ugly. To me, it didn’t seem “professional” to use a pre-Ajax website for doing research.

Recently, however, I have changed my mind about this, as I discovered that this tool can be very powerful to integrate data from different sources and for doing “mash-ups”. A local UCSC browser instance can be installed in a computer and be used as a central repository for all the annotations produced in a research unit: for example, sequencing data, results from experiments and from statistical genome-wide tests, etc. If all the custom annotations produced in a lab are available in a local UCSC browser instance (either as custom tracks or as tables), it is possible to compare them, and also to compare them against annotations available publicly, such as position of genes, non-coding regions and much more. The real strength of this tool is that if you have a workflow to automatize retrieval of data from it, you are able to compare your results with virtually anything that is known about a genome.

So, let’s go to the point: I wrote a script to automatically fetch screenshots of a UCSC browser instance. It is available at this page:

The first difficulty I faced when writing this script was that there are a lot of possible different options, to define a region and how to visualize it. So, I have made the script to require three different configuration files: one for the regions to be visualized, one for the tracks to be shown, and one for the connection parameters. So here it is how you would call it:

Have a look at this pdf that created with this script. If you continue reading the post, I will also describe the different configuration files.

example of report created by this script. Click on the image to see the full pdf.

The Regions file is a CSV file containing all the regions to be shown, one per line. For each region defined in this file, the script will connect to the UCSC browser and fetch a screenshot of that regions as a pdf file. If rst2pdf is installed in your computer, the script will also generate a multi-page report.

I know that CSV is not optimal for a configuration file, but in this case it seemed a good compromise. The script will fail if you miss a comma or if you change the order of a column; but if you are careful, everything should go fine.

The Tracks file contains the list of tracks to be shown. Everytime the script is called, all the regions will be fetched with the same tracks visualized. If you need to plot the same regions with different tracks visualized, just call the script more than once.

I am planning to change the format of this file to a CSV-like one, allowing to define other options for each track, such as the color and the height of the track. However, implementing these parameters would require a lot of changes in how the script connects to the browser, so I am leaving this for later.

The last configuration file is the Connection Configuration file. Here you can define your email address (mandatory), URL to a custom UCSC browser installation, HTTP proxy address and password, and so on.

Finally, let me explain the requirements. The script requires the mechanize library from python to connect, and optionally, the rst2pdf tool, to produce the multi-page reports.

One Comment

  1. Thanks, This is very cool.
    It would be a nice option if the regions file could be a BED file with the 4th column being the label and description and the up/downstream set from a kwarg on the command-line.

Leave a Reply to brentp Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">