ruby-igv 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -13
  3. data/lib/igv/version.rb +1 -1
  4. data/lib/igv.rb +335 -151
  5. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e4a99096506fa47659b90377b84c90adfdaa05212d158f182c2f5350463f927
4
- data.tar.gz: ffa21ca61aa0c54c89082e7b2094b716a9949c3380f00d2ba20a6142a2986940
3
+ metadata.gz: 19fb874a7ea3fe0edee703b42b481db4c718609287a1ed4c1407a03bec2b1e9a
4
+ data.tar.gz: 982188fc06b54fc0d772f1b0fb21228c2aa9a0d7c2319c527b03f0b5411cb916
5
5
  SHA512:
6
- metadata.gz: e9f3bf96a5830840591966525f26a43e2c63c1aaf76efc1c6ba48cc76622f56390ef8f2ce82f0f8c28e18b8dc2bc4074047257c72b7ad77bdc26511f1cc27970
7
- data.tar.gz: 27542e590daa398caa2fc460b82c05da84195c16e7d220e9a58973979321b776cfcbc2c44473e572d17401d1570a18a8494bdeb66d4bbc16bd531f400f9cb64a
6
+ metadata.gz: 6e6035336e6cf7a1d850dd33bf565a54e8c32283a40992e496f94ec516ba8a1a054ea283b5dfb16d5bf700efc296b37a85cb19827f7154b0b9756b6baa123d53
7
+ data.tar.gz: 36bac381a140a15803418711682e5b4f82c1442703d467042f0d3a76db311ed2da675846792333582465aff98e4f6647469d03bc11d5dfaf1a9c542ccfd6595e
data/README.md CHANGED
@@ -12,12 +12,12 @@ Ruby-IGV is a simple tool for controlling the Integrated Genomics Viewer (IGV) f
12
12
 
13
13
  <img src="https://user-images.githubusercontent.com/5798442/182540876-c3ca2906-7d05-4c93-9107-ce4135ae9765.png" width="300" align="right">
14
14
 
15
- Requirement :
15
+ Requirement :
16
16
 
17
- * [Ruby](https://github.com/ruby/ruby)
18
- * [IGV (Integrative Genomics Viewer)](http://software.broadinstitute.org/software/igv/)
19
- * [Enable IGV to listen on the port](https://software.broadinstitute.org/software/igv/Preferences#Advanced)
20
- * View > Preference > Advanced > Enable port ☑
17
+ - [Ruby](https://github.com/ruby/ruby)
18
+ - [IGV (Integrative Genomics Viewer)](http://software.broadinstitute.org/software/igv/)
19
+ - [Enable IGV to listen on the port](https://software.broadinstitute.org/software/igv/Preferences#Advanced)
20
+ - View > Preference > Advanced > Enable port ☑
21
21
 
22
22
  ```ruby
23
23
  gem install ruby-igv
@@ -45,7 +45,7 @@ igv.snapshot 'region.png'
45
45
 
46
46
  ### IGV batch commands
47
47
 
48
- The commonly used commands in IGV are summarized in the official [list of batch commands](https://github.com/igvteam/igv/wiki/Batch-commands). (but even this does not seem to be all of them). You can also call the `commands` method from Ruby to open a browser and view the list.
48
+ The commonly used commands in IGV are summarized in the official [list of batch commands](https://igv.org/doc/desktop/#UserGuide/tools/batch/#script-commands). (but even this does not seem to be all of them). You can also call the `commands` method from Ruby to open a browser and view the list.
49
49
 
50
50
  ```ruby
51
51
  igv.commands # Show the IGV command reference in your browser
@@ -53,18 +53,35 @@ igv.commands # Show the IGV command reference in your browser
53
53
 
54
54
  ### docs
55
55
 
56
- See [yard docs](https://rubydoc.info/gems/ruby-igv/IGV). Commonly used IGV batch commands can be called from Ruby methods of the same name. However, not all IGV batch commands are implemented in Ruby. Use the `send` method described below.
56
+ See [yard docs](https://kojix2.github.io/ruby-igv/).
57
+ Most IGV batch commands are available as Ruby methods of the same name.
58
+ If you need to use a command not directly wrapped, you can use the `send` method as shown below.
57
59
 
58
60
  ### send
59
61
 
60
- Commands that are not implemented can be sent using the send method.
62
+ You can send any IGV batch command using the `send` method.
61
63
 
62
64
  ```ruby
63
65
  igv.send("maxPanelHeight", 10)
66
+ igv.send("scrollToTop")
67
+ igv.send("setAccessToken", "token", "host")
64
68
  ```
65
69
 
66
70
  To avoid unexpected behavior, ruby-igv does not use the `method_missing` mechanism.
67
71
 
72
+ ### Supported IGV batch commands
73
+
74
+ Most official IGV batch commands are available as Ruby methods, including:
75
+
76
+ - collapse, color_by, echo, exit, expand, genome, goto, group, load, max_panel_height, new, overlay, preference, region, save_session, scroll_to_top, separate, set_alt_color, set_color, set_data_range, set_log_scale, set_sequence_strand, set_sequence_show_translation, set_sleep_interval, set_track_height, snapshot_dir, snapshot, sort, squish, viewaspairs, set_access_token, clear_access_tokens
77
+
78
+ See the [official IGV batch command list](https://igv.org/doc/desktop/#UserGuide/tools/batch/#script-commands) for details.
79
+
80
+ ### Return values and error handling
81
+
82
+ Most methods return the IGV response string (e.g. "OK" or an error message).
83
+ You can check the return value to handle errors or confirm success.
84
+
68
85
  ### Launch IGV
69
86
 
70
87
  Launch IGV from Ruby script.
@@ -121,10 +138,10 @@ igv.kill # kill group pid created with IGV.start
121
138
 
122
139
  ## Contributing
123
140
 
124
- * [Report bugs](https://github.com/kojix2/ruby-igv/issues)
125
- * Fix bugs and submit [pull requests](https://github.com/kojix2/ruby-igv/pulls)
126
- * Write, clarify, or fix documentation
127
- * Suggest or add new features
141
+ - [Report bugs](https://github.com/kojix2/ruby-igv/issues)
142
+ - Fix bugs and submit [pull requests](https://github.com/kojix2/ruby-igv/pulls)
143
+ - Write, clarify, or fix documentation
144
+ - Suggest or add new features
128
145
 
129
146
  ```
130
147
  Do you need commit rights to this repository?
@@ -133,8 +150,10 @@ If so, please feel free to contact me @kojix2.
133
150
  ```
134
151
 
135
152
  ## Acknowledgement
153
+
136
154
  This gem is strongly inspired by a Python script developed by Brent Pedersen.
137
- * [brentp/bio-playground/igv](https://github.com/brentp/bio-playground).
155
+
156
+ - [brentp/bio-playground/igv](https://github.com/brentp/bio-playground).
138
157
 
139
158
  ## License
140
159
 
data/lib/igv/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class IGV
4
- VERSION = '0.0.9'
4
+ VERSION = '0.0.10'
5
5
  end
data/lib/igv.rb CHANGED
@@ -5,20 +5,21 @@ require 'uri'
5
5
  require 'socket'
6
6
  require 'fileutils'
7
7
 
8
- # The Integrative Genomics Viewer (IGV)
9
- # https://software.broadinstitute.org/software/igv/
8
+ # The Integrative Genomics Viewer (IGV) Ruby client.
9
+ # Provides a Ruby interface to control IGV via its batch command protocol.
10
+ #
11
+ # @see https://igv.org/doc/desktop/#UserGuide/tools/batch/#script-commands IGV Batch Script Documentation
10
12
  class IGV
11
13
  class Error < StandardError; end
12
14
 
13
15
  attr_reader :host, :port, :history
14
16
 
15
- # Create IGV client object
17
+ # Create IGV client object.
16
18
  #
17
- # @param host [String] hostname or IP address of IGV server
18
- # @param port [Integer] port number of IGV server
19
- # @param path [String] directory path to save snapshots
20
- # @return [IGV] IGV client object
21
-
19
+ # @param host [String] Hostname or IP address of IGV server.
20
+ # @param port [Integer] Port number of IGV server.
21
+ # @param snapshot_dir [String] Directory path to save snapshots.
22
+ # @return [IGV] IGV client object.
22
23
  def initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd)
23
24
  raise ArgumentError, 'IGV#initialize does not accept a block.' if block_given?
24
25
 
@@ -28,15 +29,14 @@ class IGV
28
29
  @history = []
29
30
  end
30
31
 
31
- # Create IGV object and connect to IGV server
32
+ # Create IGV object and connect to IGV server.
32
33
  # This method accepts a block.
33
34
  #
34
- # @param host [String] hostname or IP address of IGV server
35
- # @param port [Integer] port number of IGV server
36
- # @param path [String] directory path to save snapshots
37
- # @return [IGV] IGV client object
38
- # @yield [IGV] IGV client object
39
-
35
+ # @param host [String] Hostname or IP address of IGV server.
36
+ # @param port [Integer] Port number of IGV server.
37
+ # @param snapshot_dir [String] Directory path to save snapshots.
38
+ # @yield [IGV] IGV client object.
39
+ # @return [IGV] IGV client object.
40
40
  def self.open(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd)
41
41
  igv = new(host: host, port: port, snapshot_dir: snapshot_dir)
42
42
  igv.connect
@@ -50,23 +50,26 @@ class IGV
50
50
  igv
51
51
  end
52
52
 
53
+ # Check if a port is open.
54
+ # @param port [Integer] Port number.
55
+ # @return [Boolean, nil] true if open, false if closed, nil if unknown.
53
56
  def self.port_open?(port)
54
57
  system("lsof -i:#{port}", out: '/dev/null')
55
58
  end
56
59
  private_class_method :port_open?
57
60
 
58
- # Launch IGV from ruby script
61
+ # Launch IGV from Ruby script.
59
62
  #
60
- # @param port [Integer] port number
61
- # @param command [String] command to launch IGV
62
- # @param snapshot_dir [String] directory path to save snapshots
63
- # @return [IGV] IGV client object
64
-
63
+ # @param port [Integer] Port number.
64
+ # @param command [String] Command to launch IGV.
65
+ # @param snapshot_dir [String] Directory path to save snapshots.
66
+ # @return [IGV] IGV client object.
67
+ # @note This will spawn a new IGV process and connect to it.
65
68
  def self.start(port: 60_151, command: 'igv', snapshot_dir: Dir.pwd)
66
69
  case port_open?(port)
67
- when nil then warn "Cannot tell if port #{port} is open"
70
+ when nil then warn "[ruby-igv] Cannot tell if port #{port} is open"
68
71
  when true then raise("Port #{port} is already in use")
69
- when false then warn "Port #{port} is available"
72
+ when false then warn "[ruby-igv] Port #{port} is available"
70
73
  else raise "Unexpected return value from port_open?(#{port})"
71
74
  end
72
75
  r, w = IO.pipe
@@ -84,38 +87,44 @@ class IGV
84
87
  igv
85
88
  end
86
89
 
87
- # Kill IGV process by process group id
88
-
90
+ # Kill IGV process by process group id.
91
+ #
92
+ # @note Only works for IGV processes started by IGV.start.
93
+ # @return [nil] Kills the IGV process if started by this client, otherwise does nothing.
89
94
  def kill
90
95
  if instance_variable_defined?(:@pgid_igv)
91
- warn \
92
- 'This method kills the process with the group ID specified at startup. ' \
93
- 'Please use exit or quit if possible.'
96
+ warn '[ruby-igv] This method kills the process with the group ID specified at startup. Please use exit or quit if possible.'
94
97
  else
95
- warn \
96
- 'The kill method terminates only IGV commands invoked by the start method.' \
97
- 'Otherwise, use exit or quit.'
98
- return
98
+ warn '[ruby-igv] The kill method terminates only IGV commands invoked by the start method. Otherwise, use exit or quit.'
99
+ return nil
99
100
  end
100
101
  pgid = @pgid_igv
101
102
  Process.kill(:TERM, -pgid)
102
103
  close
104
+ nil
103
105
  end
104
106
 
105
- # Connect to IGV server
106
-
107
+ # Connect to IGV server.
108
+ #
109
+ # @param host2 [String] Hostname or IP address.
110
+ # @param port2 [Integer] Port number.
111
+ # @param connect_timeout [Integer, nil] Timeout in seconds.
112
+ # @return [self] Returns self for method chaining.
107
113
  def connect(host2 = @host, port2 = @port, connect_timeout: nil)
108
114
  @socket&.close
109
115
  @socket = Socket.tcp(host2, port2, connect_timeout: connect_timeout)
116
+ self
110
117
  end
111
118
 
112
- # Close the socket.
113
- # This method dose not exit IGV.
114
-
119
+ # Close the socket. This does not exit IGV.
120
+ # @return [nil] Closes the socket and returns nil.
115
121
  def close
116
122
  @socket&.close
123
+ nil
117
124
  end
118
125
 
126
+ # Check if the socket is closed.
127
+ # @return [Boolean]
119
128
  def closed?
120
129
  return true if @socket.nil?
121
130
 
@@ -124,9 +133,10 @@ class IGV
124
133
 
125
134
  # Send batch commands to IGV.
126
135
  #
127
- # @param *cmds [String, Symbol, Numeric] batch commands
128
- # @return [String] response from IGV
129
-
136
+ # @param cmds [Array<String, Symbol, Numeric>] Batch commands.
137
+ # @return [String] Response from IGV.
138
+ # @example
139
+ # igv.send("goto", "chr1:1000-2000")
130
140
  def send(*cmds)
131
141
  cmd = \
132
142
  cmds
@@ -146,40 +156,42 @@ class IGV
146
156
 
147
157
  # Syntactic sugar for IGV commands that begin with set.
148
158
  #
159
+ # @param cmd [String, Symbol] Batch command name (without "set" prefix).
160
+ # @param params [Array<String, Symbol, Numeric>] Parameters for the command.
161
+ # @return [String] Response from IGV.
149
162
  # @example
150
163
  # igv.set :SleepInterval, 100
151
164
  # igv.send "setSleepInterval", 100 # same as above
152
- # @param cmd [String, Symbol] batch commands
153
- # @param *params [String, Symbol, Numeric] batch commands
154
-
155
165
  def set(cmd, *params)
156
166
  cmd = "set#{cmd}"
157
167
  send(cmd, *params)
158
168
  end
159
169
 
160
- # Show IGV batch commands in the browser.
161
- # https://github.com/igvteam/igv/wiki/Batch-commands
162
-
170
+ # Open IGV batch command documentation in the browser.
163
171
  def commands
164
172
  require 'launchy'
165
- Launchy.open('https://github.com/igvteam/igv/wiki/Batch-commands')
173
+ Launchy.open('https://igv.org/doc/desktop/#UserGuide/tools/batch/#script-commands')
166
174
  end
167
175
 
168
- # Writes the value of "param" back to the response
169
- # @note IGV Batch command
176
+ # Write the value of "param" back to the response.
170
177
  #
171
- # @param param [String] The parameter to echo.
178
+ # @note IGV Batch command: echo
179
+ # @param param [String, nil] The parameter to echo.
172
180
  # @return [String] The value of "param". If param is not specified, "echo".
173
-
181
+ # @example
182
+ # igv.echo("Hello!") #=> "Hello!"
174
183
  def echo(param = nil)
175
184
  send :echo, param
176
185
  end
177
186
 
178
- # Selects a genome by id, or loads a genome (or indexed fasta) from the supplied path.
179
- # @note IGV Batch command
187
+ # Select a genome by id, or load a genome (or indexed fasta) from the supplied path.
180
188
  #
181
- # @param name_or_path [String] The genome to load
182
-
189
+ # @note IGV Batch command: genome
190
+ # @param name_or_path [String] Genome id (e.g. "hg19") or path to fasta/indexed genome.
191
+ # @return [String] IGV response.
192
+ # @example
193
+ # igv.genome("hg19")
194
+ # igv.genome("/path/to/genome.fa")
183
195
  def genome(name_or_path)
184
196
  path = File.expand_path(name_or_path)
185
197
  if File.exist?(path)
@@ -189,12 +201,15 @@ class IGV
189
201
  end
190
202
  end
191
203
 
192
- # Loads a data or session file by specifying a full path to a local file or a URL.
193
- # @note IGV Batch command
204
+ # Load a data or session file by specifying a full path to a local file or a URL.
194
205
  #
195
- # @param path_or_url [String] The path to a local file or a URL
196
- # @param index [String] The index of the file
197
-
206
+ # @note IGV Batch command: load
207
+ # @param path_or_url [String] Path to a local file or a URL.
208
+ # @param index [String, nil] Optional index file path.
209
+ # @return [String] IGV response.
210
+ # @example
211
+ # igv.load("http://example.com/data.bam")
212
+ # igv.load("/path/to/data.bam", index: "/path/to/data.bai")
198
213
  def load(path_or_url, index: nil)
199
214
  path_or_url = if URI.parse(path_or_url).scheme
200
215
  path_or_url
@@ -207,27 +222,38 @@ class IGV
207
222
  raise ArgumentError, "Invalid URI or file path: #{path_or_url}"
208
223
  end
209
224
 
210
- # Go to the specified location
211
- # @note IGV Batch command
225
+ # Go to the specified location or list of loci.
212
226
  #
213
- # @param location [String] The location to go to.
214
-
215
- def goto(*position)
216
- send :goto, *position
227
+ # @note IGV Batch command: goto
228
+ # @param position [String] Locus or list of loci (e.g. "chr1:1000-2000").
229
+ # @return [String] IGV response.
230
+ # @example
231
+ # igv.goto("chr1:1000-2000")
232
+ def goto(position)
233
+ send :goto, position
217
234
  end
218
235
  alias go goto
219
236
 
220
- # Defines a region of interest bounded by the two loci
221
- # @note IGV Batch command
237
+ # Define a region of interest bounded by the two loci.
222
238
  #
223
- # @param chr [String] The chromosome of the region
224
- # @param start [Integer] The start position of the region
225
- # @param end_ [Integer] The end position of the region
226
-
239
+ # @note IGV Batch command: region
240
+ # @param chr [String] Chromosome name.
241
+ # @param start [Integer] Start position.
242
+ # @param end_ [Integer] End position.
243
+ # @return [String] IGV response.
244
+ # @example
245
+ # igv.region("chr1", 100, 200)
227
246
  def region(chr, start, end_)
228
247
  send :region, chr, start, end_
229
248
  end
230
249
 
250
+ # Sort alignment or segmented copy number tracks.
251
+ #
252
+ # @note IGV Batch command: sort
253
+ # @param option [String] Sort option (e.g. "base", "position", "strand", "quality", "sample", "readGroup").
254
+ # @return [String] IGV response.
255
+ # @example
256
+ # igv.sort("position")
231
257
  def sort(option = 'base')
232
258
  vop = %w[base position strand quality sample readGroup]
233
259
  raise "options is one of: #{vop.join(', ')}" unless vop.include? option
@@ -235,72 +261,97 @@ class IGV
235
261
  send :sort, option
236
262
  end
237
263
 
238
- # Expands the given track.
239
- # @note IGV Batch command
264
+ # Expand a given track. If not specified, expands all tracks.
240
265
  #
241
- # @param track [String] The track to expand.
242
- # If not specified, expands all tracks.
243
-
266
+ # @note IGV Batch command: expand
267
+ # @param track [String, nil] Track name (optional).
268
+ # @return [String] IGV response.
269
+ # @example
270
+ # igv.expand
271
+ # igv.expand("track1")
244
272
  def expand(track = nil)
245
273
  send :expand, track
246
274
  end
247
275
 
248
- # Collapses a given track.
249
- # @note IGV Batch command
276
+ # Collapse a given track. If not specified, collapses all tracks.
250
277
  #
251
- # @param track [String] The track to collapse.
252
- # If not specified, collapses all tracks.
253
-
278
+ # @note IGV Batch command: collapse
279
+ # @param track [String, nil] Track name (optional).
280
+ # @return [String] IGV response.
281
+ # @example
282
+ # igv.collapse
283
+ # igv.collapse("track1")
254
284
  def collapse(track = nil)
255
285
  send :collapse, track
256
286
  end
257
287
 
258
- # Squish a given track.
259
- # @note IGV Batch command
288
+ # Squish a given track. If not specified, squishes all annotation tracks.
260
289
  #
261
- # @param track [String] The track to squish.
262
- # If not specified, squishes all tracks.
263
-
290
+ # @note IGV Batch command: squish
291
+ # @param track [String, nil] Track name (optional).
292
+ # @return [String] IGV response.
293
+ # @example
294
+ # igv.squish
295
+ # igv.squish("track1")
264
296
  def squish(track = nil)
265
297
  send :squish, track
266
298
  end
267
299
 
268
300
  # Set the display mode for an alignment track to "View as pairs".
269
301
  #
270
- # @param track [String] The track to set.
271
- # If not specified, sets all tracks.
272
-
302
+ # @note IGV Batch command: viewaspairs
303
+ # @param track [String, nil] Track name (optional).
304
+ # @return [String] IGV response.
305
+ # @example
306
+ # igv.viewaspairs
307
+ # igv.viewaspairs("track1")
273
308
  def viewaspairs(track = nil)
274
309
  send :viewaspairs, track
275
310
  end
276
311
 
277
- # @note IGV Batch command
278
-
312
+ # Create a new session. Unloads all tracks except the default genome annotations.
313
+ #
314
+ # @note IGV Batch command: new
315
+ # @return [self] Returns self for method chaining.
316
+ # @example
317
+ # igv.new
279
318
  def new
280
319
  send :new
320
+ self
281
321
  end
282
322
 
283
- # @note IGV Batch command
284
-
323
+ # Clear all loaded tracks and data.
324
+ #
325
+ # @note IGV Batch command: clear
326
+ # @return [self] Returns self for method chaining.
327
+ # @example
328
+ # igv.clear
285
329
  def clear
286
330
  send :clear
331
+ self
287
332
  end
288
333
 
289
334
  # Exit (close) the IGV application and close the socket.
290
- # @note IGV Batch command (modified)
291
-
335
+ #
336
+ # @note IGV Batch command: exit
337
+ # @return [nil] Exits IGV and closes the socket.
338
+ # @example
339
+ # igv.exit
292
340
  def exit
293
341
  send :exit
294
342
  @socket.close
343
+ nil
295
344
  end
296
345
  alias quit exit
297
346
 
298
- # Sets the directory in which to write images.
299
- # Returns the current snapshot directory if no argument is given.
300
- # @note IGV Batch command (modified)
347
+ # Set or get the directory in which to write images (snapshots).
301
348
  #
302
- # @param path [String] The path to the directory.
303
-
349
+ # @note IGV Batch command: snapshotDirectory
350
+ # @param dir_path [String, nil] Directory path. If nil, returns current snapshot directory.
351
+ # @return [String] IGV response or current directory.
352
+ # @example
353
+ # igv.snapshot_dir("/tmp/snapshots")
354
+ # igv.snapshot_dir #=> "/tmp/snapshots"
304
355
  def snapshot_dir(dir_path = nil)
305
356
  return @snapshot_dir if dir_path.nil?
306
357
 
@@ -314,136 +365,269 @@ class IGV
314
365
 
315
366
  private def snapshot_dir_internal(dir_path)
316
367
  dir_path = File.expand_path(dir_path)
368
+ warn "[ruby-igv] Directory #{dir_path} does not exist. Creating it." unless File.exist?(dir_path)
317
369
  FileUtils.mkdir_p(dir_path)
318
370
  send :snapshotDirectory, dir_path
319
371
  end
320
372
 
321
- # Saves a snapshot of the IGV window to an image file.
322
- # If filename is omitted, writes a PNG file with a filename generated based on the locus.
323
- # If filename is specified, the filename extension determines the image file format,
324
- # which must be either .png or .svg.
325
- # @note IGV Batch command (modified)
326
- # @note In Ruby-IGV, it is possible to pass absolute or relative paths as well as file names;
327
- # the Snapshot directory is set to Dir.pwd by default.
373
+ # Save a snapshot of the IGV window to an image file.
328
374
  #
329
- # @param file_path [String] The path to the image file.
375
+ # @note IGV Batch command: snapshot
376
+ # @param file_name [String, nil] Name of the image file. If nil, uses the current locus.
377
+ # If filename is omitted, writes a PNG file with a filename generated based on the locus.
378
+ # If filename is specified, the filename extension determines the image file format, which must be either .png or .svg.
379
+ # Passing a path might work, but is not recommended.
380
+ # @example
381
+ # igv.snapshot("region.png")
382
+ def snapshot(file_name = nil)
383
+ return send(:snapshot) if file_name.nil?
384
+ dir_path = File.dirname(file_name)
385
+
386
+ # file_name is a file name
387
+ return send(:snapshot, file_name) if dir_path == "."
330
388
 
331
- def snapshot(file_path = nil)
332
- return send(:snapshot) if file_path.nil?
389
+ # file_name is a path
390
+ file_path = file_name
391
+ warn "[ruby-igv] snapshot: Passing a path is not recommended. "
392
+
393
+ if File.absolute_path?(file_path)
394
+ dir_path = File.expand_path(dir_path)
395
+ else
396
+ dir_path = File.expand_path(File.join(@snapshot_dir, dir_path))
397
+ end
333
398
 
334
- dir_path = File.dirname(file_path)
335
399
  filename = File.basename(file_path)
336
- if dir_path != @snapshot_dir
337
- snapshot_dir_internal(dir_path)
338
- r = send :snapshot, filename
339
- snapshot_dir_internal(@snapshot_dir)
340
- r
400
+
401
+ # Only change directory if needed
402
+ if dir_path == @snapshot_dir
403
+ send(:snapshot, filename)
341
404
  else
342
- send :snapshot, filename
405
+ # Temporarily change snapshot directory
406
+ original_dir = @snapshot_dir
407
+ snapshot_dir_internal(dir_path)
408
+ result = send(:snapshot, filename)
409
+ snapshot_dir_internal(original_dir)
410
+ result
343
411
  end
344
412
  end
345
413
 
346
414
  # Temporarily set the preference named key to the specified value.
347
- # @note IGV Batch command
348
415
  #
349
- # @param key [String] The preference name
350
- # @param value [String] The preference value
351
-
416
+ # @note IGV Batch command: preference
417
+ # @param key [String] Preference key.
418
+ # @param value [String] Preference value.
419
+ # @return [String] IGV response.
420
+ # @see https://raw.githubusercontent.com/igvteam/igv/master/src/main/resources/org/broad/igv/prefs/preferences.tab
421
+ # @example
422
+ # igv.preferences("SAM.READ_GROUP_COLOR", "sample")
352
423
  def preferences(key, value)
353
424
  send :preferences, key, value
354
425
  end
355
426
 
356
427
  # Show "preference.tab" in your browser.
357
-
358
428
  def show_preferences_table
359
429
  require 'launchy'
360
430
  Launchy.open('https://raw.githubusercontent.com/igvteam/igv/master/src/main/resources/org/broad/igv/prefs/preferences.tab')
361
431
  end
362
432
 
363
433
  # Save the current session.
364
- # It is recommended that a full path be used for filename. IGV release 2.11.1
365
- # @note IGV Batch command
366
434
  #
367
- # @param filename [String] The path to the session file
368
-
435
+ # @note IGV Batch command: saveSession
436
+ # @param file_path [String] Path to the session file.
437
+ # @return [String] IGV response.
438
+ # @example
439
+ # igv.save_session("session.xml")
369
440
  def save_session(file_path)
370
441
  file_path = File.expand_path(file_path)
371
442
  send :saveSession, file_path
372
443
  end
373
444
 
374
- # @note IGV Batch command
375
-
445
+ # Set the track "altColor", used for negative values in a wig track or negative strand features.
446
+ #
447
+ # @note IGV Batch command: setAltColor
448
+ # @param color [String] Color string (e.g. "255,0,0" or "FF0000").
449
+ # @param track [String] Track name.
450
+ # @return [String] IGV response.
451
+ # @example
452
+ # igv.set_alt_color("255,0,0", "track1")
376
453
  def set_alt_color(color, track)
377
454
  send :setAltColor, color, track
378
455
  end
379
456
 
380
- # @note IGV Batch command
381
-
457
+ # Set the track color.
458
+ #
459
+ # @note IGV Batch command: setColor
460
+ # @param color [String] Color string (e.g. "255,0,0" or "FF0000").
461
+ # @param track [String] Track name.
462
+ # @return [String] IGV response.
463
+ # @example
464
+ # igv.set_color("FF0000", "track1")
382
465
  def set_color(color, track)
383
466
  send :setColor, color, track
384
467
  end
385
468
 
386
- # @note IGV Batch command
387
-
469
+ # Set the data range (scale) for all numeric tracks, or a specific track.
470
+ #
471
+ # @note IGV Batch command: setDataRange
472
+ # @param range [String] Range string (e.g. "0,100" or "auto").
473
+ # @param track [String] Track name.
474
+ # @return [String] IGV response.
475
+ # @example
476
+ # igv.set_data_range("0,100", "track1")
388
477
  def set_data_range(range, track)
389
478
  send :setDataRange, range, track
390
479
  end
391
480
 
392
- # @note IGV Batch command
393
-
481
+ # Set the data scale to log (true) or linear (false).
482
+ #
483
+ # @note IGV Batch command: setLogScale
484
+ # @param bool [Boolean] true for log scale, false for linear.
485
+ # @param track [String] Track name (optional).
486
+ # @return [String] IGV response.
487
+ # @example
488
+ # igv.set_log_scale(true, "track1")
394
489
  def set_log_scale(bool, track)
395
490
  bool = 'true' if bool == true
396
491
  bool = 'false' if bool == false
397
492
  send :setLogScale, bool, track
398
493
  end
399
494
 
400
- # @note IGV Batch command
401
-
495
+ # Set the sequence strand to positive (+) or negative (-).
496
+ #
497
+ # @note IGV Batch command: setSequenceStrand
498
+ # @param strand [String] "+" or "-".
499
+ # @return [String] IGV response.
500
+ # @example
501
+ # igv.set_sequence_strand("+")
402
502
  def set_sequence_strand(strand)
403
503
  send :setSequenceStrand, strand
404
504
  end
405
505
 
406
- # @note IGV Batch command
407
-
506
+ # Show or hide the 3-frame translation rows of the sequence track.
507
+ #
508
+ # @note IGV Batch command: setSequenceShowTranslation
509
+ # @param bool [Boolean] true to show, false to hide.
510
+ # @return [String] IGV response.
511
+ # @example
512
+ # igv.set_sequence_show_translation(true)
408
513
  def set_sequence_show_translation(bool)
409
514
  bool = 'true' if bool == true
410
515
  bool = 'false' if bool == false
411
516
  send :setSequenceShowTranslation, bool
412
517
  end
413
518
 
414
- # @note IGV Batch command
415
-
519
+ # Set a delay (sleep) time in milliseconds between successive commands.
520
+ #
521
+ # @note IGV Batch command: setSleepInterval
522
+ # @param ms [Integer] Milliseconds to sleep.
523
+ # @return [String] IGV response.
524
+ # @example
525
+ # igv.set_sleep_interval(200)
416
526
  def set_sleep_interval(ms)
417
527
  send :setSleepInterval, ms
418
528
  end
419
529
 
420
- # @note IGV Batch command
421
-
530
+ # Set the specified track's height in integer units.
531
+ #
532
+ # @note IGV Batch command: setTrackHeight
533
+ # @param height [Integer] Height in pixels.
534
+ # @param track [String] Track name.
535
+ # @return [String] IGV response.
536
+ # @example
537
+ # igv.set_track_height(50, "track1")
422
538
  def set_track_height(height, track)
423
539
  send :setTrackHeight, height, track
424
540
  end
425
541
 
426
- # @note IGV Batch command
427
-
542
+ # Set the number of vertical pixels (height) of each panel to include in image.
543
+ #
544
+ # @note IGV Batch command: maxPanelHeight
545
+ # @param height [Integer] Height in pixels.
546
+ # @return [String] IGV response.
547
+ # @example
548
+ # igv.max_panel_height(2000)
428
549
  def max_panel_height(height)
429
550
  send :maxPanelHeight, height
430
551
  end
431
552
 
432
- # @note IGV Batch command
433
-
553
+ # Set the "color by" option for alignment tracks.
554
+ #
555
+ # @note IGV Batch command: colorBy
556
+ # @param option [String] Color by option (e.g. "SAMPLE", "READ_GROUP", "TAG", ...).
557
+ # @param tag [String, nil] Tag name (required for option "TAG").
558
+ # @return [String] IGV response.
559
+ # @example
560
+ # igv.color_by("SAMPLE")
561
+ # igv.color_by("TAG", "NM")
434
562
  def color_by(option, tag)
435
563
  send :colorBy, option, tag
436
564
  end
437
565
 
438
- # @note IGV Batch command
439
-
566
+ # Group alignments by the specified option.
567
+ #
568
+ # @note IGV Batch command: group
569
+ # @param option [String] Group option (e.g. "SAMPLE", "READ_GROUP", "TAG", ...).
570
+ # @param tag [String, nil] Tag name or position (required for option "TAG").
571
+ # @return [String] IGV response.
572
+ # @example
573
+ # igv.group("SAMPLE")
574
+ # igv.group("TAG", "NM")
440
575
  def group(option, tag)
441
576
  send :group, option, tag
442
577
  end
443
578
 
444
- # @note IGV Batch command
445
-
579
+ # Overlay a list of tracks.
580
+ #
581
+ # @note IGV Batch command: overlay
582
+ # @param overlaid_track [String] The track to overlay.
583
+ # @param tracks [Array<String>] List of tracks to overlay.
584
+ # @return [String] IGV response.
585
+ # @example
586
+ # igv.overlay("track1", "track2", "track3")
446
587
  def overlay(overlaid_track, *tracks)
447
588
  send :overlay, overlaid_track, *tracks
448
589
  end
590
+
591
+ # Scroll all panels to the top of the view.
592
+ #
593
+ # @note IGV Batch command: scrollToTop
594
+ # @return [String] IGV response.
595
+ # @example
596
+ # igv.scroll_to_top
597
+ def scroll_to_top
598
+ send :scrollToTop
599
+ end
600
+
601
+ # Separate an overlaid track into its constituitive tracks.
602
+ #
603
+ # @note IGV Batch command: separate
604
+ # @param overlaid_track_name [String] The name of the overlaid track to separate.
605
+ # @return [String] IGV response.
606
+ # @example
607
+ # igv.separate("track1")
608
+ def separate(overlaid_track_name)
609
+ send :separate, overlaid_track_name
610
+ end
611
+
612
+ # Set an access token to be used in an Authorization header for all requests to host.
613
+ #
614
+ # @note IGV Batch command: setAccessToken
615
+ # @param token [String] The access token.
616
+ # @param host [String, nil] The host to use the token for (optional).
617
+ # @return [String] IGV response.
618
+ # @example
619
+ # igv.set_access_token("mytoken", "example.com")
620
+ def set_access_token(token, host = nil)
621
+ send :setAccessToken, token, host
622
+ end
623
+
624
+ # Clears all access tokens.
625
+ #
626
+ # @note IGV Batch command: clearAccessTokens
627
+ # @return [String] IGV response.
628
+ # @example
629
+ # igv.clear_access_tokens
630
+ def clear_access_tokens
631
+ send :clearAccessTokens
632
+ end
449
633
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-igv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-04-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: launchy
@@ -95,7 +94,6 @@ homepage: https://github.com/kojix2/ruby-igv
95
94
  licenses:
96
95
  - MIT
97
96
  metadata: {}
98
- post_install_message:
99
97
  rdoc_options: []
100
98
  require_paths:
101
99
  - lib
@@ -110,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
108
  - !ruby/object:Gem::Version
111
109
  version: '0'
112
110
  requirements: []
113
- rubygems_version: 3.5.5
114
- signing_key:
111
+ rubygems_version: 3.6.7
115
112
  specification_version: 4
116
113
  summary: Control IGV (Integrative Genomics Viewer) with Ruby.
117
114
  test_files: []