I did not know about the WWW:Mechanize module in perl. Sounds great! Thanks for the info!
I have a link to UCSC that takes me to a region being displayed in the genome browser:
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.
2 answers
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;
}
}
Thanks. Other answers also welcome :)
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
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
Log in to answer this question.
If I do not get an answer here I'll ask at the UCSC mailing list and post the answer here.
More info here: Batch Viewing Of Ucsc Browser Graphic