Question: Given a link that displays genome browser data, how do I download a pdf using a link?
0
gravatar for endrebak
2.2 years ago by
endrebak680
endrebak680 wrote:

I have a link to UCSC that takes me to a region being displayed in the genome browser:

http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr1%3A779770-779967&hgct_customText=track%20type=bigWig%20name=myBigWig%20description=%22a%20bigWig%20track%22%20visibility=full%20bigDataUrl=https://github.com/endrebak/git-lfs/raw/master/PolII.bw&omimGene2=full

How can I use this link to download the graph shown?

If I were to do it by hand I'd right click and choose "show image" and save it, but I need to do this automatically.

There is this answer, but it does not seem completely right:

How can I Get png figures of UCSC genome browser automatically?

Notice it uses the variable $url which is never set.

browser genome • 802 views
ADD COMMENTlink modified 2.2 years ago • written 2.2 years ago by endrebak680

If I do not get an answer here I'll ask at the UCSC mailing list and post the answer here.

ADD REPLYlink modified 2.2 years ago • written 2.2 years ago by endrebak680

More info here: Batch Viewing Of Ucsc Browser Graphic

ADD REPLYlink written 2.2 years ago by endrebak680
3
gravatar for Jean-Karim Heriche
2.2 years ago by
EMBL Heidelberg, Germany
Jean-Karim Heriche16k wrote:

There's wkhtmltopdf. This will make a pdf of the entire page though:

wkhtmltopdf 'http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr1%3A779770-779967&hgct_customText=track%20type=bigWig%20name=myBigWig%20description=%22a%20bigWig%20track%22%20visibility=full%20bigDataUrl=https://github.com/endrebak/git-lfs/raw/master/PolII.bw&omimGene2=full' UCSC.pdf

For just an image, you can use wget. The trick is using the -A option to filter what to get as in the script you're referring to e.g.

wget -A hgt_*.png --no-directories --recursive --convert-links -l 1 --wait=1 --random-wait --tries=2 --timeout=100 http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr1%3A779770-779967&hgct_customText=track%20type=bigWig%20name=myBigWig%20description=%22a%20bigWig%20track%22%20visibility=full%20bigDataUrl=https://github.com/endrebak/git-lfs/raw/master/PolII.bw&omimGene2=full

Note that the UCSC genome browser graphs are png images not pdf.

Alternatively, there's also the perl module WWW:Mechanize:

#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize;

my $url = "http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr1%3A779770-779967&hgct_customText=track%20type=bigWig%20name=myBigWig%20description=%22a%20bigWig%20track%22%20visibility=full%20bigDataUrl=https://github.com/endrebak/git-lfs/raw/master/PolII.bw&omimGene2=full";

my $mech = WWW::Mechanize->new();
$mech->get($url);
foreach my $img($mech->images) {
    if ($img->url =~/hgt_.+\.png/) {
        $mech->mirror($img->url_abs,"ucsc.png");
        last;
   }
}
ADD COMMENTlink written 2.2 years ago by Jean-Karim Heriche16k

I did not know about the WWW:Mechanize module in perl. Sounds great! Thanks for the info!

ADD REPLYlink written 2.2 years ago by microfuge950

Thanks. Other answers also welcome :)

ADD REPLYlink written 2.2 years ago by endrebak680
2
gravatar for endrebak
2.2 years ago by
endrebak680
endrebak680 wrote:

Hi Endre,

Thank you for your question about automatically generating pdf images. There is a way to have the browser generate a single pdf image via the View->PDF/PS option, but scripting this would be tricky. Instead, it may be better to use the hgRenderTracks CGI to generate a PNG image, and then convert that image to PDF with ImageMagick.

To use hgRenderTracks, replace hgTracks in your URL with hgRenderTracks, like so: Your link: http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr1%3A779770-779967&hgct_customText=track%20type=bigWig%20name=myBigWig%20description=%22a%20bigWig%20track%22%20visibility=full%20bigDataUrl=https://github.com/endrebak/git-lfs/raw/master/PolII.bw&omimGene2=full

becomes: http://genome.ucsc.edu/cgi-bin/hgRenderTracks?db=hg18&position=chr1%3A779770-779967&hgct_customText=track%20type=bigWig%20name=myBigWig%20description=%22a%20bigWig%20track%22%20visibility=full%20bigDataUrl=https://github.com/endrebak/git-lfs/raw/master/PolII.bw&omimGene2=full

You can curl this link and pipe the resulting PNG to ImageMagick's convert utility.

Your script will look similar to the following: curl "http://genome.ucsc.edu/cgi-bin/hgRenderTracks?param1=x¶m2=y&..." | convert - example.pdf

Although it sounds like your requests will be reasonable, please keep in mind our Conditions of Use allow no more than one hit per 15 seconds and 5000 hits per day: https://genome.ucsc.edu/conditions.html

For more information about constructing and sharing URLs, please see the following page: https://genome.ucsc.edu/goldenpath/help/hgTracksHelp.html#SHARE

Thank you again for your inquiry and using the UCSC Genome Browser. If you have any further questions, please reply to genome@soe.ucsc.edu. All messages sent to that address are archived on a publicly-accessible forum. If your question includes sensitive data, you may send it instead to genome-www@soe.ucsc.edu.

Christopher Lee UCSC Genomics Institute

ADD COMMENTlink written 2.2 years ago by endrebak680
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 717 users visited in the last hour