Class: IGV
- Inherits:
-
Object
- Object
- IGV
- Defined in:
- lib/igv.rb,
lib/igv/version.rb
Overview
The Integrative Genomics Viewer (IGV) software.broadinstitute.org/software/igv/
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
'0.0.7'
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
- .open(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) ⇒ Object
-
.start(port: 60_151, command: 'igv') ⇒ Object
Launch IGV from ruby script.
Instance Method Summary collapse
- #clear ⇒ Object
-
#close ⇒ Object
Close the socket.
- #closed? ⇒ Boolean
-
#collapse(track = nil) ⇒ Object
Collapses a given track.
-
#commands ⇒ Object
Show IGV batch commands in the browser.
-
#connect(host2 = @host, port2 = @port, connect_timeout: nil) ⇒ Object
Connect to IGV server.
-
#echo(param = nil) ⇒ String
Writes the value of “param” back to the response.
-
#exit ⇒ Object
(also: #quit)
Exit (close) the IGV application.
-
#expand(track = nil) ⇒ Object
Expands the given track.
-
#genome(name_or_path) ⇒ Object
Selects a genome by id, or loads a genome (or indexed fasta) from the supplied path.
-
#goto(position) ⇒ Object
(also: #go)
Go to the specified location.
-
#initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) ⇒ IGV
constructor
A new instance of IGV.
-
#kill ⇒ Object
Kill IGV process by process group id.
-
#load(path_or_url, index: nil) ⇒ Object
Loads a data or session file by specifying a full path to a local file or a URL.
-
#preferences(key, value) ⇒ Object
Temporarily set the preference named key to the specified value.
-
#region(chr, start, end_) ⇒ Object
Defines a region of interest bounded by the two loci.
-
#save_session(file_path) ⇒ Object
Save the current session.
-
#send(*cmds) ⇒ Object
Send batch commands to IGV.
-
#show_preferences_table ⇒ Object
Show “preference.tab” in your browser.
-
#snapshot(file_path = nil) ⇒ Object
Saves a snapshot of the IGV window to an image file.
-
#snapshot_dir(dir_path = nil) ⇒ Object
Sets the directory in which to write images.
- #sort(option = 'base') ⇒ Object
-
#squish(track = nil) ⇒ Object
Squish a given track.
-
#viewaspairs(track = nil) ⇒ Object
Set the display mode for an alignment track to “View as pairs”.
Constructor Details
#initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) ⇒ IGV
Returns a new instance of IGV.
14 15 16 17 18 19 |
# File 'lib/igv.rb', line 14 def initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) @host = host @port = port @snapshot_dir = File.(snapshot_dir) @history = [] end |
Instance Attribute Details
#history ⇒ Object (readonly)
Returns the value of attribute history.
12 13 14 |
# File 'lib/igv.rb', line 12 def history @history end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
12 13 14 |
# File 'lib/igv.rb', line 12 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/igv.rb', line 12 def port @port end |
Class Method Details
.open(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/igv.rb', line 21 def self.open(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) igv = new(host: host, port: port, snapshot_dir: snapshot_dir) igv.connect return igv unless block_given? begin yield igv ensure @socket&.close end igv end |
.start(port: 60_151, command: 'igv') ⇒ Object
Launch IGV from ruby script
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/igv.rb', line 36 def self.start(port: 60_151, command: 'igv') r, w = IO.pipe pid_igv = spawn(command, '-p', port.to_s, pgroup: true, out: w, err: w) pgid_igv = Process.getpgid(pid_igv) Process.detach(pid_igv) puts "\e[33m" while (line = r.gets.chomp("\n")) puts line break if line.include? "Listening on port #{port}" end puts "\e[0m" igv = open(port: port) igv.instance_variable_set(:@pgid_igv, pgid_igv) igv end |
Instance Method Details
#clear ⇒ Object
217 218 219 |
# File 'lib/igv.rb', line 217 def clear send :clear end |
#close ⇒ Object
Close the socket. This method dose not exit IGV.
80 81 82 |
# File 'lib/igv.rb', line 80 def close @socket&.close end |
#closed? ⇒ Boolean
84 85 86 87 88 |
# File 'lib/igv.rb', line 84 def closed? return true if @socket.nil? @socket.closed? end |
#collapse(track = nil) ⇒ Object
Collapses a given track.
195 196 197 |
# File 'lib/igv.rb', line 195 def collapse(track = nil) send :collapse, track end |
#commands ⇒ Object
Show IGV batch commands in the browser. github.com/igvteam/igv/wiki/Batch-commands
113 114 115 116 |
# File 'lib/igv.rb', line 113 def commands require 'launchy' Launchy.open('https://github.com/igvteam/igv/wiki/Batch-commands') end |
#connect(host2 = @host, port2 = @port, connect_timeout: nil) ⇒ Object
Connect to IGV server
72 73 74 75 |
# File 'lib/igv.rb', line 72 def connect(host2 = @host, port2 = @port, connect_timeout: nil) @socket&.close @socket = Socket.tcp(host2, port2, connect_timeout: connect_timeout) end |
#echo(param = nil) ⇒ String
Writes the value of “param” back to the response
123 124 125 |
# File 'lib/igv.rb', line 123 def echo(param = nil) send :echo, param end |
#exit ⇒ Object Also known as: quit
Exit (close) the IGV application.
223 224 225 226 |
# File 'lib/igv.rb', line 223 def exit send :exit @socket.close end |
#expand(track = nil) ⇒ Object
Expands the given track.
186 187 188 |
# File 'lib/igv.rb', line 186 def (track = nil) send :expand, track end |
#genome(name_or_path) ⇒ Object
Selects a genome by id, or loads a genome (or indexed fasta) from the supplied path.
131 132 133 134 135 136 137 138 |
# File 'lib/igv.rb', line 131 def genome(name_or_path) path = File.(name_or_path) if File.exist?(path) send :genome, path else send :genome, name_or_path end end |
#goto(position) ⇒ Object Also known as: go
Go to the specified location
159 160 161 |
# File 'lib/igv.rb', line 159 def goto(position) send :goto, position end |
#kill ⇒ Object
Kill IGV process by process group id
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/igv.rb', line 54 def kill if instance_variable_defined?(:@pgid_igv) warn \ 'This method kills the process with the group ID specified at startup. ' \ 'Please use exit or quit if possible.' else warn \ 'The kill method terminates only IGV commands invoked by the start method.' \ 'Otherwise, use exit or quit.' return end pgid = @pgid_igv Process.kill(:TERM, -pgid) close end |
#load(path_or_url, index: nil) ⇒ Object
Loads a data or session file by specifying a full path to a local file or a URL.
145 146 147 148 149 150 151 152 153 |
# File 'lib/igv.rb', line 145 def load(path_or_url, index: nil) path_or_url = if URI.parse(path_or_url).scheme path_or_url else File.(path_or_url) end index = "index=#{index}" if index send :load, path_or_url, index end |
#preferences(key, value) ⇒ Object
Temporarily set the preference named key to the specified value.
280 281 282 |
# File 'lib/igv.rb', line 280 def preferences(key, value) send :preferences, key, value end |
#region(chr, start, end_) ⇒ Object
Defines a region of interest bounded by the two loci
170 171 172 |
# File 'lib/igv.rb', line 170 def region(chr, start, end_) send :region, chr, start, end_ end |
#save_session(file_path) ⇒ Object
Save the current session. It is recommended that a full path be used for filename. IGV release 2.11.1
296 297 298 299 |
# File 'lib/igv.rb', line 296 def save_session(file_path) file_path = File.(file_path) send :saveSession, file_path end |
#send(*cmds) ⇒ Object
Send batch commands to IGV.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/igv.rb', line 93 def send(*cmds) cmd = \ cmds .compact .map do |cmd| case cmd when String, Symbol, Numeric then cmd.to_s when ->(c) { c.respond_to?(:to_str) } then cmd.to_str else raise ArgumentError, "#{cmd.inspect} is not a string" end.strip.encode(Encoding::UTF_8) end .join(' ') @history << cmd @socket.puts(cmd) @socket.gets&.chomp("\n") end |
#show_preferences_table ⇒ Object
Show “preference.tab” in your browser.
286 287 288 289 |
# File 'lib/igv.rb', line 286 def show_preferences_table require 'launchy' Launchy.open('https://raw.githubusercontent.com/igvteam/igv/master/src/main/resources/org/broad/igv/prefs/preferences.tab') end |
#snapshot(file_path = nil) ⇒ Object
In Ruby-IGV, it is possible to pass absolute or relative paths as well as file names; the Snapshot directory is set to Dir.pwd by default.
Saves a snapshot of the IGV window to an image file. If filename is omitted, writes a PNG file with a filename generated based on the locus. If filename is specified, the filename extension determines the image file format, which must be either .png or .svg.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/igv.rb', line 260 def snapshot(file_path = nil) return send(:snapshot) if file_path.nil? dir_path = File.dirname(file_path) filename = File.basename(file_path) if dir_path != @snapshot_dir snapshot_dir_internal(dir_path) r = send :snapshot, filename snapshot_dir_internal(@snapshot_dir) r else send :snapshot, filename end end |
#snapshot_dir(dir_path = nil) ⇒ Object
Sets the directory in which to write images. Retruns the current snapshot directory if no argument is given.
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/igv.rb', line 234 def snapshot_dir(dir_path = nil) return @snapshot_dir if dir_path.nil? dir_path = File.(dir_path) return if dir_path == @snapshot_dir r = snapshot_dir_internal(dir_path) @snapshot_dir = dir_path r end |
#sort(option = 'base') ⇒ Object
174 175 176 177 178 179 |
# File 'lib/igv.rb', line 174 def sort(option = 'base') vop = %w[base position strand quality sample readGroup] raise "options is one of: #{vop.join(', ')}" unless vop.include? option send :sort, option end |
#squish(track = nil) ⇒ Object
Squish a given track.
204 205 206 |
# File 'lib/igv.rb', line 204 def squish(track = nil) send :squish, track end |
#viewaspairs(track = nil) ⇒ Object
Set the display mode for an alignment track to “View as pairs”.
213 214 215 |
# File 'lib/igv.rb', line 213 def viewaspairs(track = nil) send :viewaspairs, track end |