ruby-igv 0.0.8 → 0.0.9

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 +39 -8
  3. data/lib/igv/version.rb +1 -1
  4. data/lib/igv.rb +100 -14
  5. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed0319fd387ae14300d7f596b0a0e2a6aa6cd1dab63a67921070e66446b532db
4
- data.tar.gz: 7d3e5587f800b76b5f96c9fccb44c210e8b36ee6fb598a368b686bff6c1745e7
3
+ metadata.gz: 7e4a99096506fa47659b90377b84c90adfdaa05212d158f182c2f5350463f927
4
+ data.tar.gz: ffa21ca61aa0c54c89082e7b2094b716a9949c3380f00d2ba20a6142a2986940
5
5
  SHA512:
6
- metadata.gz: e85423c90acd6a974e5b29a1890a1177823785043b6bae0736d6f234c9bcdb6b57f2dc22858ccfdc53af270e367b9576f309f6235d6754bce2d71b6ed7fd90dc
7
- data.tar.gz: 445d5ce3a05e5d876ac4813cce4fdaad9bee4fe568a706838a97f8958cb247429bad6cf996072e68b246fa5a345e1827b45bf9210b8f12890550d8bd6b00b6d9
6
+ metadata.gz: e9f3bf96a5830840591966525f26a43e2c63c1aaf76efc1c6ba48cc76622f56390ef8f2ce82f0f8c28e18b8dc2bc4074047257c72b7ad77bdc26511f1cc27970
7
+ data.tar.gz: 27542e590daa398caa2fc460b82c05da84195c16e7d220e9a58973979321b776cfcbc2c44473e572d17401d1570a18a8494bdeb66d4bbc16bd531f400f9cb64a
data/README.md CHANGED
@@ -1,16 +1,17 @@
1
1
  # ruby-igv
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/ruby-igv.svg)](https://badge.fury.io/rb/ruby-igv)
4
- [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://rubydoc.info/gems/ruby-igv)
4
+ [![Docs Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://rubydoc.info/gems/ruby-igv)
5
+ [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://kojix2.github.io/ruby-igv)
5
6
  [![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg)](LICENSE.txt)
6
7
  [![DOI](https://zenodo.org/badge/281373245.svg)](https://zenodo.org/badge/latestdoi/281373245)
7
8
 
8
9
  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.
9
10
 
10
- <img src="https://user-images.githubusercontent.com/5798442/182540876-c3ca2906-7d05-4c93-9107-ce4135ae9765.png" align="right">
11
-
12
11
  ## Installation
13
12
 
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
16
 
16
17
  * [Ruby](https://github.com/ruby/ruby)
@@ -24,7 +25,7 @@ gem install ruby-igv
24
25
 
25
26
  ## Quickstart
26
27
 
27
- <img src="https://user-images.githubusercontent.com/5798442/182623864-a9fa59aa-abb9-4cb1-8311-2b3479b7414e.png" width="300" align="left">
28
+ <img src="https://user-images.githubusercontent.com/5798442/182623864-a9fa59aa-abb9-4cb1-8311-2b3479b7414e.png" width="300" align="right">
28
29
 
29
30
  ```ruby
30
31
  require 'igv'
@@ -42,9 +43,9 @@ igv.snapshot 'region.png'
42
43
 
43
44
  ## Usage
44
45
 
45
- ### commands
46
+ ### IGV batch commands
46
47
 
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.
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
49
 
49
50
  ```ruby
50
51
  igv.commands # Show the IGV command reference in your browser
@@ -52,7 +53,7 @@ igv.commands # Show the IGV command reference in your browser
52
53
 
53
54
  ### docs
54
55
 
55
- See [docs](https://rubydoc.info/gems/ruby-igv/IGV). Not all commands are implemented in Ruby.
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
57
 
57
58
  ### send
58
59
 
@@ -62,6 +63,8 @@ Commands that are not implemented can be sent using the send method.
62
63
  igv.send("maxPanelHeight", 10)
63
64
  ```
64
65
 
66
+ To avoid unexpected behavior, ruby-igv does not use the `method_missing` mechanism.
67
+
65
68
  ### Launch IGV
66
69
 
67
70
  Launch IGV from Ruby script.
@@ -70,11 +73,39 @@ Launch IGV from Ruby script.
70
73
  igv = IGV.start # launch IGV app using spawn
71
74
  ```
72
75
 
76
+ You can specify the port.
77
+
78
+ ```ruby
79
+ igv = IGV.start(port: 60152)
80
+ ```
81
+
82
+ If you start IGV in this way, you can force IGV to terminate by calling the kill method.
83
+
84
+ ```ruby
85
+ igv.kill
86
+ ```
87
+
73
88
  ### Open socket connection to IGV
74
89
 
90
+ If IGV is already running, use `new` or `open`.
91
+
92
+ new
93
+
75
94
  ```ruby
76
95
  igv = IGV.new # create an IGV object. Then you will type `igv.connect`
96
+ igv = IGV.new(host: "127.0.0.1", port: 60151, snapshot_dir: "~/igv_snapshot")
97
+ igv.connect # To start a connection, call connect explicitly.
98
+ igv.close
99
+ ```
100
+
101
+ open
102
+
103
+ ```ruby
77
104
  igv = IGV.open # create an IGV object and connect it to an already activated IGV.
105
+ igv.close
106
+ IGV.open(host: "127.0.0.1", port: 60151, snapshot_dir: "~/igv_snapshot") do |igv|
107
+ # do something
108
+ end # The socket is automatically closed.
78
109
  ```
79
110
 
80
111
  ### Close IGV
@@ -96,7 +127,7 @@ igv.kill # kill group pid created with IGV.start
96
127
  * Suggest or add new features
97
128
 
98
129
  ```
99
- Do you need commit rights to my repository?
130
+ Do you need commit rights to this repository?
100
131
  Do you want to get admin rights and take over the project?
101
132
  If so, please feel free to contact me @kojix2.
102
133
  ```
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.8'
4
+ VERSION = '0.0.9'
5
5
  end
data/lib/igv.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'igv/version'
4
+ require 'uri'
4
5
  require 'socket'
5
6
  require 'fileutils'
6
7
 
@@ -19,7 +20,7 @@ class IGV
19
20
  # @return [IGV] IGV client object
20
21
 
21
22
  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
+ raise ArgumentError, 'IGV#initialize does not accept a block.' if block_given?
23
24
 
24
25
  @host = host
25
26
  @port = port
@@ -50,7 +51,7 @@ class IGV
50
51
  end
51
52
 
52
53
  def self.port_open?(port)
53
- !system("lsof -i:#{port}", out: '/dev/null')
54
+ system("lsof -i:#{port}", out: '/dev/null')
54
55
  end
55
56
  private_class_method :port_open?
56
57
 
@@ -64,8 +65,9 @@ class IGV
64
65
  def self.start(port: 60_151, command: 'igv', snapshot_dir: Dir.pwd)
65
66
  case port_open?(port)
66
67
  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"
68
+ when true then raise("Port #{port} is already in use")
69
+ when false then warn "Port #{port} is available"
70
+ else raise "Unexpected return value from port_open?(#{port})"
69
71
  end
70
72
  r, w = IO.pipe
71
73
  pid_igv = spawn(command, '-p', port.to_s, pgroup: true, out: w, err: w)
@@ -77,7 +79,7 @@ class IGV
77
79
  break if line.include? "Listening on port #{port}"
78
80
  end
79
81
  puts "\e[0m"
80
- igv = open(port: port, snapshot_dir: snapshot_dir)
82
+ igv = self.open(port: port, snapshot_dir: snapshot_dir)
81
83
  igv.instance_variable_set(:@pgid_igv, pgid_igv)
82
84
  igv
83
85
  end
@@ -129,11 +131,11 @@ class IGV
129
131
  cmd = \
130
132
  cmds
131
133
  .compact
132
- .map do |cmd|
133
- case cmd
134
- when String, Symbol, Numeric then cmd.to_s
135
- when ->(c) { c.respond_to?(:to_str) } then cmd.to_str
136
- else raise ArgumentError, "#{cmd.inspect} is not a string"
134
+ .map do |cm|
135
+ case cm
136
+ when String, Symbol, Numeric then cm.to_s
137
+ when ->(c) { c.respond_to?(:to_str) } then cm.to_str
138
+ else raise ArgumentError, "#{cm.inspect} is not a string"
137
139
  end.strip.encode(Encoding::UTF_8)
138
140
  end
139
141
  .join(' ')
@@ -201,6 +203,8 @@ class IGV
201
203
  end
202
204
  index = "index=#{index}" if index
203
205
  send :load, path_or_url, index
206
+ rescue URI::InvalidURIError
207
+ raise ArgumentError, "Invalid URI or file path: #{path_or_url}"
204
208
  end
205
209
 
206
210
  # Go to the specified location
@@ -208,8 +212,8 @@ class IGV
208
212
  #
209
213
  # @param location [String] The location to go to.
210
214
 
211
- def goto(position)
212
- send :goto, position
215
+ def goto(*position)
216
+ send :goto, *position
213
217
  end
214
218
  alias go goto
215
219
 
@@ -272,12 +276,18 @@ class IGV
272
276
 
273
277
  # @note IGV Batch command
274
278
 
279
+ def new
280
+ send :new
281
+ end
282
+
283
+ # @note IGV Batch command
284
+
275
285
  def clear
276
286
  send :clear
277
287
  end
278
288
 
279
289
  # Exit (close) the IGV application and close the socket.
280
- # @note IGV Batch command (modifyed)
290
+ # @note IGV Batch command (modified)
281
291
 
282
292
  def exit
283
293
  send :exit
@@ -286,7 +296,7 @@ class IGV
286
296
  alias quit exit
287
297
 
288
298
  # Sets the directory in which to write images.
289
- # Retruns the current snapshot directory if no argument is given.
299
+ # Returns the current snapshot directory if no argument is given.
290
300
  # @note IGV Batch command (modified)
291
301
  #
292
302
  # @param path [String] The path to the directory.
@@ -360,4 +370,80 @@ class IGV
360
370
  file_path = File.expand_path(file_path)
361
371
  send :saveSession, file_path
362
372
  end
373
+
374
+ # @note IGV Batch command
375
+
376
+ def set_alt_color(color, track)
377
+ send :setAltColor, color, track
378
+ end
379
+
380
+ # @note IGV Batch command
381
+
382
+ def set_color(color, track)
383
+ send :setColor, color, track
384
+ end
385
+
386
+ # @note IGV Batch command
387
+
388
+ def set_data_range(range, track)
389
+ send :setDataRange, range, track
390
+ end
391
+
392
+ # @note IGV Batch command
393
+
394
+ def set_log_scale(bool, track)
395
+ bool = 'true' if bool == true
396
+ bool = 'false' if bool == false
397
+ send :setLogScale, bool, track
398
+ end
399
+
400
+ # @note IGV Batch command
401
+
402
+ def set_sequence_strand(strand)
403
+ send :setSequenceStrand, strand
404
+ end
405
+
406
+ # @note IGV Batch command
407
+
408
+ def set_sequence_show_translation(bool)
409
+ bool = 'true' if bool == true
410
+ bool = 'false' if bool == false
411
+ send :setSequenceShowTranslation, bool
412
+ end
413
+
414
+ # @note IGV Batch command
415
+
416
+ def set_sleep_interval(ms)
417
+ send :setSleepInterval, ms
418
+ end
419
+
420
+ # @note IGV Batch command
421
+
422
+ def set_track_height(height, track)
423
+ send :setTrackHeight, height, track
424
+ end
425
+
426
+ # @note IGV Batch command
427
+
428
+ def max_panel_height(height)
429
+ send :maxPanelHeight, height
430
+ end
431
+
432
+ # @note IGV Batch command
433
+
434
+ def color_by(option, tag)
435
+ send :colorBy, option, tag
436
+ end
437
+
438
+ # @note IGV Batch command
439
+
440
+ def group(option, tag)
441
+ send :group, option, tag
442
+ end
443
+
444
+ # @note IGV Batch command
445
+
446
+ def overlay(overlaid_track, *tracks)
447
+ send :overlay, overlaid_track, *tracks
448
+ end
363
449
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-igv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-03 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: launchy
@@ -95,7 +95,7 @@ homepage: https://github.com/kojix2/ruby-igv
95
95
  licenses:
96
96
  - MIT
97
97
  metadata: {}
98
- post_install_message:
98
+ post_install_message:
99
99
  rdoc_options: []
100
100
  require_paths:
101
101
  - lib
@@ -103,15 +103,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: '2.4'
106
+ version: '2.6'
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.3.7
114
- signing_key:
113
+ rubygems_version: 3.5.5
114
+ signing_key:
115
115
  specification_version: 4
116
116
  summary: Control IGV (Integrative Genomics Viewer) with Ruby.
117
117
  test_files: []