ruby-igv 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +34 -0
  4. data/lib/igv.rb +94 -0
  5. data/lib/igv/version.rb +3 -0
  6. metadata +103 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 224cade620bf730aabd99e3f5369c10eea4a18714d5713148cd73044b7236ce8
4
+ data.tar.gz: 11b31803bc1df5b2393f5d0c980caf7092aaf86defd94b89a88ed366e3dc318f
5
+ SHA512:
6
+ metadata.gz: e8f1e9a25e9467ddcb0ddb8571b81910fb48e607ca898a34290a28b62533b1b617826c139f37008c019990db76a6e2a91fc500e6a0b740d24ba16ce7d3816bb9
7
+ data.tar.gz: 0f9f95a3fc8cbdf52bee48f1830392b7f64594565de16fc5108f3af3ffc6aa2517e0af4035c44967122a27e1f2524f4e0370b4517d43f313ed869ce51d3b7468
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 kojix2
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # Ruby-IGV
2
+
3
+ Using Integrative Genomics Viewer (IGV) with the Ruby language.
4
+
5
+ Based on [brentp/bio-playground/igv](https://github.com/brentp/bio-playground).
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem install ruby-igv
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ igv = IGV.new
17
+ igv.gnome 'hg19'
18
+ igv.load 'http://www.broadinstitute.org/igvdata/1KG/pilot2Bams/NA12878.SLX.bam'
19
+ igv.go 'chr1:45,600-45,800'
20
+ igv.save '/tmp/r/region.svg'
21
+ igv.save '/tmp/r/region.png'
22
+ igv.send 'echo' #whatever
23
+ ```
24
+
25
+ ## Contributing
26
+
27
+ * [Report bugs](https://github.com/kojix2/ruby-igv/issues)
28
+ * Fix bugs and submit [pull requests](https://github.com/kojix2/ruby-igv/pulls)
29
+ * Write, clarify, or fix documentation
30
+ * Suggest or add new features
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,94 @@
1
+ require 'igv/version'
2
+ require 'socket'
3
+ require 'fileutils'
4
+ require 'pathname'
5
+
6
+ class IGV
7
+ class Error < StandardError; end
8
+
9
+ attr_reader :host, :port, :snapshot_dir, :commands
10
+ def initialize(host: '127.0.0.1', port: 60_151, snapshot_dir: '/tmp/igv')
11
+ @host = host
12
+ @port = port
13
+ @commands = []
14
+ connect
15
+ set_snapshot_dir(snapshot_dir)
16
+ end
17
+
18
+ # def self.start
19
+ # end
20
+
21
+ def connect
22
+ @socket&.close
23
+ @socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
24
+ addr = Socket.sockaddr_in(port, host)
25
+ @socket.connect(addr)
26
+ end
27
+
28
+ def go(position)
29
+ send 'goto ' + position
30
+ end
31
+ alias goto go
32
+
33
+ def genome(name_or_path)
34
+ send 'genome ' + name_or_path
35
+ end
36
+
37
+ def load(path_or_url)
38
+ send 'load ' + path_or_url
39
+ end
40
+
41
+ def region(contig, start, end_)
42
+ send ['region', contig, start, end_].join(' ')
43
+ end
44
+
45
+ def sort(option = 'base')
46
+ if %w[base position strand quality sample readGroup].include? option
47
+ send 'sort ' + option
48
+ else
49
+ raise 'options is one of: base, position, strand, quality, sample, and readGroup.'
50
+ end
51
+ end
52
+
53
+ def snapshot_dir=(snapshot_dir)
54
+ snapshot_dir = File.expand_path(snapshot_dir)
55
+ return if snapshot_dir == @snaphot_dir
56
+
57
+ FileUtils.mkdir_p(snapshot_dir)
58
+ send "snapshotDirectory #{snapshot_dir}"
59
+ @snapshot_dir = snapshot_dir
60
+ end
61
+ alias set_snapshot_dir snapshot_dir=
62
+
63
+ def expand(_track = '')
64
+ send "expand #{track}"
65
+ end
66
+
67
+ def collapse(_track = '')
68
+ send "collapse #{track}"
69
+ end
70
+
71
+ def clear
72
+ send 'clear'
73
+ end
74
+
75
+ def send(cmd)
76
+ @commands << cmd
77
+ cmd += "\n"
78
+ @socket.puts(cmd.encode(Encoding::UTF_8))
79
+ @socket.readline.chomp("\n")
80
+ end
81
+
82
+ def save(file_path = nil)
83
+ if file_path
84
+ # igv assumes the path is just a single filename, but
85
+ # we can set the snapshot dir. then just use the filename.
86
+ dir_path = Pathname(File.expand_path(file_path)).dirname
87
+ set_snapshot_dir(dir_path)
88
+ send 'snapshot ' + File.basename(file_path)
89
+ else
90
+ send 'snapshot'
91
+ end
92
+ end
93
+ alias snapshot save
94
+ end
@@ -0,0 +1,3 @@
1
+ class IGV
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-igv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kojix2
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Operate IGV (Integrative Genomics Viewer) from Ruby.
70
+ email:
71
+ - 2xijok@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - lib/igv.rb
79
+ - lib/igv/version.rb
80
+ homepage: https://github.com/kojix2/ruby-igv
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.3.0
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.1.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Operate IGV (Integrative Genomics Viewer) from Ruby.
103
+ test_files: []