ruby-igv 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -11
  3. data/lib/igv/version.rb +1 -1
  4. data/lib/igv.rb +69 -6
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ca8294136b5eab8a344a40bf1d5ebb6d8ebf08f2794a1c6e1f582f593432049
4
- data.tar.gz: c36d4c09a163ade8bfd860519a50519a28ae3f93121a14c482bf1bceb6239cde
3
+ metadata.gz: ed0319fd387ae14300d7f596b0a0e2a6aa6cd1dab63a67921070e66446b532db
4
+ data.tar.gz: 7d3e5587f800b76b5f96c9fccb44c210e8b36ee6fb598a368b686bff6c1745e7
5
5
  SHA512:
6
- metadata.gz: 1a085655336dcd4d06db5b51269f6b72d8d7174767f0b2990796d29cd410fb90adc884b86df3cf97087e75b35d387f655ed557628145c3af9badf17d3b29c50e
7
- data.tar.gz: d8e0741301b1504f7714077ef435a987b51c520fcc3788f85acaf42ad3785fcec7bf435e897666a5f9a16050d2f503cfab5daa68525a1fc86a18b5219018a6ed
6
+ metadata.gz: e85423c90acd6a974e5b29a1890a1177823785043b6bae0736d6f234c9bcdb6b57f2dc22858ccfdc53af270e367b9576f309f6235d6754bce2d71b6ed7fd90dc
7
+ data.tar.gz: 445d5ce3a05e5d876ac4813cce4fdaad9bee4fe568a706838a97f8958cb247429bad6cf996072e68b246fa5a345e1827b45bf9210b8f12890550d8bd6b00b6d9
data/README.md CHANGED
@@ -5,6 +5,7 @@
5
5
  [![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg)](LICENSE.txt)
6
6
  [![DOI](https://zenodo.org/badge/281373245.svg)](https://zenodo.org/badge/latestdoi/281373245)
7
7
 
8
+ Ruby-IGV is a simple tool for controlling the Integrated Genomics Viewer (IGV) from the Ruby language. It provides an automated way to load files, specify genome locations, and take and save screenshots using IGV.
8
9
 
9
10
  <img src="https://user-images.githubusercontent.com/5798442/182540876-c3ca2906-7d05-4c93-9107-ce4135ae9765.png" align="right">
10
11
 
@@ -23,42 +24,47 @@ gem install ruby-igv
23
24
 
24
25
  ## Quickstart
25
26
 
27
+ <img src="https://user-images.githubusercontent.com/5798442/182623864-a9fa59aa-abb9-4cb1-8311-2b3479b7414e.png" width="300" align="left">
28
+
26
29
  ```ruby
27
30
  require 'igv'
28
31
 
29
32
  igv = IGV.start # This launch IGV
33
+
34
+ igv.set :SleepInterval, 200 # give a time interval
30
35
  igv.genome 'hg19'
31
- igv.load 'http://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/' \
32
- 'wgEncodeUwRepliSeq/wgEncodeUwRepliSeqK562G1AlnRep1.bam'
33
- igv.go 'chr18:78,016,233-78,016,640'
36
+ igv.load 'http://hgdownload.cse.ucsc.edu/goldenPath/' \
37
+ 'hg19/encodeDCC/wgEncodeUwRepliSeq/' \
38
+ 'wgEncodeUwRepliSeqK562G1AlnRep1.bam'
39
+ igv.go 'chr18:78016233-78016640'
34
40
  igv.snapshot 'region.png'
35
- igv.exit
36
41
  ```
37
42
 
38
43
  ## Usage
39
44
 
40
- ### docs
45
+ ### commands
41
46
 
42
- See [the list of Batch commands](https://github.com/igvteam/igv/wiki/Batch-commands).
47
+ 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.
43
48
 
44
49
  ```ruby
45
50
  igv.commands # Show the IGV command reference in your browser
46
51
  ```
47
52
 
48
- [docs](https://rubydoc.info/gems/ruby-igv)
53
+ ### docs
54
+
55
+ See [docs](https://rubydoc.info/gems/ruby-igv/IGV). Not all commands are implemented in Ruby.
49
56
 
50
57
  ### send
51
58
 
52
- Not all commands are implemented in Ruby. Commands that are not implemented can be sent using the send method.
59
+ Commands that are not implemented can be sent using the send method.
53
60
 
54
61
  ```ruby
55
62
  igv.send("maxPanelHeight", 10)
56
63
  ```
57
64
 
58
-
59
65
  ### Launch IGV
60
66
 
61
- Launch IGV from Ruby scripot.
67
+ Launch IGV from Ruby script.
62
68
 
63
69
  ```ruby
64
70
  igv = IGV.start # launch IGV app using spawn
@@ -77,7 +83,7 @@ The behavior of the following methods is different.
77
83
 
78
84
  ```ruby
79
85
  igv.close # close the socket connection
80
- igv.exit # send exit command to IGV
86
+ igv.exit # send exit command to IGV then close the socket connection
81
87
  igv.quit # alias method to exit
82
88
  igv.kill # kill group pid created with IGV.start
83
89
  ```
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.7'
4
+ VERSION = '0.0.8'
5
5
  end
data/lib/igv.rb CHANGED
@@ -11,13 +11,31 @@ class IGV
11
11
 
12
12
  attr_reader :host, :port, :history
13
13
 
14
+ # Create IGV client object
15
+ #
16
+ # @param host [String] hostname or IP address of IGV server
17
+ # @param port [Integer] port number of IGV server
18
+ # @param path [String] directory path to save snapshots
19
+ # @return [IGV] IGV client object
20
+
14
21
  def initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd)
22
+ raise ArgumentError, 'new dose not take a block' if block_given?
23
+
15
24
  @host = host
16
25
  @port = port
17
26
  @snapshot_dir = File.expand_path(snapshot_dir)
18
27
  @history = []
19
28
  end
20
29
 
30
+ # Create IGV object and connect to IGV server
31
+ # This method accepts a block.
32
+ #
33
+ # @param host [String] hostname or IP address of IGV server
34
+ # @param port [Integer] port number of IGV server
35
+ # @param path [String] directory path to save snapshots
36
+ # @return [IGV] IGV client object
37
+ # @yield [IGV] IGV client object
38
+
21
39
  def self.open(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd)
22
40
  igv = new(host: host, port: port, snapshot_dir: snapshot_dir)
23
41
  igv.connect
@@ -31,9 +49,24 @@ class IGV
31
49
  igv
32
50
  end
33
51
 
34
- # Launch IGV from ruby script
52
+ def self.port_open?(port)
53
+ !system("lsof -i:#{port}", out: '/dev/null')
54
+ end
55
+ private_class_method :port_open?
35
56
 
36
- def self.start(port: 60_151, command: 'igv')
57
+ # Launch IGV from ruby script
58
+ #
59
+ # @param port [Integer] port number
60
+ # @param command [String] command to launch IGV
61
+ # @param snapshot_dir [String] directory path to save snapshots
62
+ # @return [IGV] IGV client object
63
+
64
+ def self.start(port: 60_151, command: 'igv', snapshot_dir: Dir.pwd)
65
+ case port_open?(port)
66
+ when nil then warn "Cannot tell if port #{port} is open"
67
+ when false then raise("Port #{port} is already in use")
68
+ when true then warn "Port #{port} is available"
69
+ end
37
70
  r, w = IO.pipe
38
71
  pid_igv = spawn(command, '-p', port.to_s, pgroup: true, out: w, err: w)
39
72
  pgid_igv = Process.getpgid(pid_igv)
@@ -44,7 +77,7 @@ class IGV
44
77
  break if line.include? "Listening on port #{port}"
45
78
  end
46
79
  puts "\e[0m"
47
- igv = open(port: port)
80
+ igv = open(port: port, snapshot_dir: snapshot_dir)
48
81
  igv.instance_variable_set(:@pgid_igv, pgid_igv)
49
82
  igv
50
83
  end
@@ -88,7 +121,9 @@ class IGV
88
121
  end
89
122
 
90
123
  # Send batch commands to IGV.
91
- # @param [String] cmds
124
+ #
125
+ # @param *cmds [String, Symbol, Numeric] batch commands
126
+ # @return [String] response from IGV
92
127
 
93
128
  def send(*cmds)
94
129
  cmd = \
@@ -107,6 +142,19 @@ class IGV
107
142
  @socket.gets&.chomp("\n")
108
143
  end
109
144
 
145
+ # Syntactic sugar for IGV commands that begin with set.
146
+ #
147
+ # @example
148
+ # igv.set :SleepInterval, 100
149
+ # igv.send "setSleepInterval", 100 # same as above
150
+ # @param cmd [String, Symbol] batch commands
151
+ # @param *params [String, Symbol, Numeric] batch commands
152
+
153
+ def set(cmd, *params)
154
+ cmd = "set#{cmd}"
155
+ send(cmd, *params)
156
+ end
157
+
110
158
  # Show IGV batch commands in the browser.
111
159
  # https://github.com/igvteam/igv/wiki/Batch-commands
112
160
 
@@ -116,6 +164,7 @@ class IGV
116
164
  end
117
165
 
118
166
  # Writes the value of "param" back to the response
167
+ # @note IGV Batch command
119
168
  #
120
169
  # @param param [String] The parameter to echo.
121
170
  # @return [String] The value of "param". If param is not specified, "echo".
@@ -125,6 +174,7 @@ class IGV
125
174
  end
126
175
 
127
176
  # Selects a genome by id, or loads a genome (or indexed fasta) from the supplied path.
177
+ # @note IGV Batch command
128
178
  #
129
179
  # @param name_or_path [String] The genome to load
130
180
 
@@ -138,6 +188,7 @@ class IGV
138
188
  end
139
189
 
140
190
  # Loads a data or session file by specifying a full path to a local file or a URL.
191
+ # @note IGV Batch command
141
192
  #
142
193
  # @param path_or_url [String] The path to a local file or a URL
143
194
  # @param index [String] The index of the file
@@ -153,6 +204,7 @@ class IGV
153
204
  end
154
205
 
155
206
  # Go to the specified location
207
+ # @note IGV Batch command
156
208
  #
157
209
  # @param location [String] The location to go to.
158
210
 
@@ -162,6 +214,7 @@ class IGV
162
214
  alias go goto
163
215
 
164
216
  # Defines a region of interest bounded by the two loci
217
+ # @note IGV Batch command
165
218
  #
166
219
  # @param chr [String] The chromosome of the region
167
220
  # @param start [Integer] The start position of the region
@@ -179,6 +232,7 @@ class IGV
179
232
  end
180
233
 
181
234
  # Expands the given track.
235
+ # @note IGV Batch command
182
236
  #
183
237
  # @param track [String] The track to expand.
184
238
  # If not specified, expands all tracks.
@@ -188,6 +242,7 @@ class IGV
188
242
  end
189
243
 
190
244
  # Collapses a given track.
245
+ # @note IGV Batch command
191
246
  #
192
247
  # @param track [String] The track to collapse.
193
248
  # If not specified, collapses all tracks.
@@ -197,6 +252,7 @@ class IGV
197
252
  end
198
253
 
199
254
  # Squish a given track.
255
+ # @note IGV Batch command
200
256
  #
201
257
  # @param track [String] The track to squish.
202
258
  # If not specified, squishes all tracks.
@@ -205,7 +261,7 @@ class IGV
205
261
  send :squish, track
206
262
  end
207
263
 
208
- # Set the display mode for an alignment track to "View as pairs".
264
+ # Set the display mode for an alignment track to "View as pairs".
209
265
  #
210
266
  # @param track [String] The track to set.
211
267
  # If not specified, sets all tracks.
@@ -214,11 +270,14 @@ class IGV
214
270
  send :viewaspairs, track
215
271
  end
216
272
 
273
+ # @note IGV Batch command
274
+
217
275
  def clear
218
276
  send :clear
219
277
  end
220
278
 
221
- # Exit (close) the IGV application.
279
+ # Exit (close) the IGV application and close the socket.
280
+ # @note IGV Batch command (modifyed)
222
281
 
223
282
  def exit
224
283
  send :exit
@@ -228,6 +287,7 @@ class IGV
228
287
 
229
288
  # Sets the directory in which to write images.
230
289
  # Retruns the current snapshot directory if no argument is given.
290
+ # @note IGV Batch command (modified)
231
291
  #
232
292
  # @param path [String] The path to the directory.
233
293
 
@@ -252,6 +312,7 @@ class IGV
252
312
  # If filename is omitted, writes a PNG file with a filename generated based on the locus.
253
313
  # If filename is specified, the filename extension determines the image file format,
254
314
  # which must be either .png or .svg.
315
+ # @note IGV Batch command (modified)
255
316
  # @note In Ruby-IGV, it is possible to pass absolute or relative paths as well as file names;
256
317
  # the Snapshot directory is set to Dir.pwd by default.
257
318
  #
@@ -273,6 +334,7 @@ class IGV
273
334
  end
274
335
 
275
336
  # Temporarily set the preference named key to the specified value.
337
+ # @note IGV Batch command
276
338
  #
277
339
  # @param key [String] The preference name
278
340
  # @param value [String] The preference value
@@ -290,6 +352,7 @@ class IGV
290
352
 
291
353
  # Save the current session.
292
354
  # It is recommended that a full path be used for filename. IGV release 2.11.1
355
+ # @note IGV Batch command
293
356
  #
294
357
  # @param filename [String] The path to the session file
295
358
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-igv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2