-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgbrowseCapture
executable file
·80 lines (55 loc) · 1.78 KB
/
gbrowseCapture
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /usr/bin/ruby
# TheParkerLab
# Vivek Rai
# GPLv3
#
# August ??, 2018
require 'optparse'
require 'ostruct'
options = OpenStruct.new
options.png = false
parseargs = OptionParser.new do |opts|
opts.version = 1.0
opts.banner = <<~BANNER
USAGE: gbrowse_capture [URL] [options] (requires cURL)
Download PDF from UCSC Genome Browser for the corresponding URL. Simply copy
and paste the URL corresponding to current view of your Genome Browser
session.
Optionally convert the output to `PNG` (requires convert).
See -h or --help for more options.
BANNER
opts.on('-o', '--output', "=FILE", :REQUIRED, "Output File") do |a|
options.out = a
options.prefix = File.basename(a, File.extname(a))
end
opts.on('--png', "Convert to PNG? (--output must be specified)") do |v|
options.png = v
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
pargs = parseargs.parse!
url = pargs.first || nil
unless url
parseargs.parse('-h')
end
STDERR.syswrite "Rendering Genome Browser PDF.."
hgsid = url.split('=').last
# Retrieve the URI of rendered PDF from the UCSC Genome Browser website and
# downloades silently using cURL.
#
# Each Genome Browser Session has an unique `hgsid`.
COMMAND = <<-CMD
curl -s 'https://genome.ucsc.edu/cgi-bin/hgTracks?hgsid=#{hgsid}&hgt.psOutput=on' \
| grep -Eo 'hgt_genome_.*.pdf' \
| xargs -I{} curl -s -o #{options.out} 'https://genome.ucsc.edu/trash/hgt/{}'
CMD
STDOUT.syswrite `#{COMMAND}`
# Convert to high quality PNG;
# TODO: Is further high quality possible?
if options.out and options.png
STDERR.syswrite "Converting to PNG.."
`which convert && convert -density 600 -quality 100 -flatten -trim #{options.out} #{options.prefix}.png`
end