Class: IGV
- Inherits:
-
Object
- Object
- IGV
- Defined in:
- lib/igv.rb,
lib/igv/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
'0.0.3'.freeze
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#snapshot_dir ⇒ Object
Returns the value of attribute snapshot_dir.
Instance Method Summary collapse
- #clear ⇒ Object
- #collapse(_track = '') ⇒ Object
-
#connect ⇒ Object
def self.start end.
- #exit ⇒ Object (also: #quit)
- #expand(_track = '') ⇒ Object
- #genome(name_or_path) ⇒ Object
- #go(position) ⇒ Object (also: #goto)
-
#initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) ⇒ IGV
constructor
A new instance of IGV.
- #load(path_or_url) ⇒ Object
- #region(contig, start, end_) ⇒ Object
- #save(file_path = nil) ⇒ Object (also: #snapshot)
- #send(cmd) ⇒ Object
- #sort(option = 'base') ⇒ Object
Constructor Details
#initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) ⇒ IGV
Returns a new instance of IGV.
9 10 11 12 13 14 15 |
# File 'lib/igv.rb', line 9 def initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: Dir.pwd) @host = host @port = port @commands = [] connect set_snapshot_dir(snapshot_dir) end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
8 9 10 |
# File 'lib/igv.rb', line 8 def commands @commands end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/igv.rb', line 8 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/igv.rb', line 8 def port @port end |
#snapshot_dir ⇒ Object
Returns the value of attribute snapshot_dir.
8 9 10 |
# File 'lib/igv.rb', line 8 def snapshot_dir @snapshot_dir end |
Instance Method Details
#clear ⇒ Object
70 71 72 |
# File 'lib/igv.rb', line 70 def clear send 'clear' end |
#collapse(_track = '') ⇒ Object
66 67 68 |
# File 'lib/igv.rb', line 66 def collapse(_track = '') send "collapse #{track}" end |
#connect ⇒ Object
def self.start end
20 21 22 23 24 25 |
# File 'lib/igv.rb', line 20 def connect @socket&.close @socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) addr = Socket.sockaddr_in(port, host) @socket.connect(addr) end |
#exit ⇒ Object Also known as: quit
74 75 76 |
# File 'lib/igv.rb', line 74 def exit send 'exit' end |
#expand(_track = '') ⇒ Object
62 63 64 |
# File 'lib/igv.rb', line 62 def (_track = '') send "expand #{track}" end |
#genome(name_or_path) ⇒ Object
32 33 34 |
# File 'lib/igv.rb', line 32 def genome(name_or_path) send 'genome ' + name_or_path end |
#go(position) ⇒ Object Also known as: goto
27 28 29 |
# File 'lib/igv.rb', line 27 def go(position) send 'goto ' + position end |
#load(path_or_url) ⇒ Object
36 37 38 |
# File 'lib/igv.rb', line 36 def load(path_or_url) send 'load ' + path_or_url end |
#region(contig, start, end_) ⇒ Object
40 41 42 |
# File 'lib/igv.rb', line 40 def region(contig, start, end_) send ['region', contig, start, end_].join(' ') end |
#save(file_path = nil) ⇒ Object Also known as: snapshot
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/igv.rb', line 85 def save(file_path = nil) if file_path # igv assumes the path is just a single filename, but # we can set the snapshot dir. then just use the filename. dir_path = File.dirname(file_path) set_snapshot_dir(File.(dir_path)) if dir_path != '.' send 'snapshot ' + File.basename(file_path) else send 'snapshot' end end |
#send(cmd) ⇒ Object
79 80 81 82 83 |
# File 'lib/igv.rb', line 79 def send(cmd) @commands << cmd @socket.puts(cmd.encode(Encoding::UTF_8)) @socket.gets&.chomp("\n") end |
#sort(option = 'base') ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/igv.rb', line 44 def sort(option = 'base') if %w[base position strand quality sample readGroup].include? option send 'sort ' + option else raise 'options is one of: base, position, strand, quality, sample, and readGroup.' end end |