bettersam 0.0.1.alpha → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c1a3a8ba1fafb9fce91bc76a62d3869a4c60b5e
4
+ data.tar.gz: 477b54306d56e399ce7a996dcd8f80ef5db44fd6
5
+ SHA512:
6
+ metadata.gz: 6d8d6e1e3d2ff18fb3021a0eb4357da7de7b8d1669ed2d0313dff291bf7093d58ab006fa65d54f933af898f2cb4dc7109621a031ab5118a778902b53bd15e2c1
7
+ data.tar.gz: 5145d5824bbc7891e900cdddb9b80fe1de837fb28c5467a5ec2d3eb55a5402c3ff1588d56703626cef133519310993f0c8d8181f72ab217a60800f2dfb55f1ab
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Richard Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ BetterSAM
2
+ ============
3
+
4
+ A SAM library for ruby, based on https://github.com/jesserod/samruby.
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/bettersam.png)][gem]
7
+ [![Build Status](https://secure.travis-ci.org/Blahah/bettersam.png?branch=master)][travis]
8
+ [![Dependency Status](https://gemnasium.com/Blahah/bettersam.png?travis)][gemnasium]
9
+ [![Code Climate](https://codeclimate.com/github/Blahah/bettersam.png)][codeclimate]
10
+ [![Coverage Status](https://coveralls.io/repos/Blahah/bettersam/badge.png?branch=master)][coveralls]
11
+
12
+ [gem]: https://badge.fury.io/rb/bettersam
13
+ [travis]: https://travis-ci.org/Blahah/bettersam
14
+ [gemnasium]: https://gemnasium.com/Blahah/bettersam
15
+ [codeclimate]: https://codeclimate.com/github/Blahah/bettersam
16
+ [coveralls]: https://coveralls.io/r/Blahah/bettersam
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
9
+
@@ -19,6 +19,8 @@ class BetterSam
19
19
 
20
20
  public
21
21
  attr_accessor :name, :flag, :chrom, :pos, :mapq, :cigar, :mchrom, :mpos, :insert, :seq, :qual, :tags
22
+ attr_accessor :snp
23
+ attr_reader :cigar_list
22
24
 
23
25
  def initialize(line=nil)
24
26
  @tags = {}
@@ -121,6 +123,123 @@ public
121
123
  !self.pair_opposite_strands?
122
124
  end
123
125
 
126
+ # cigar parsing methods
127
+
128
+ def exact_match?
129
+ @cigar=="100M"
130
+ end
131
+
132
+ def endpos
133
+ if !@cigar_list
134
+ self.parse_cigar
135
+ end
136
+ e = @pos
137
+ @cigar_list.each do |h|
138
+ a = h.to_a
139
+ bases = a[0][0]
140
+ match = a[0][1]
141
+ if match =~ /[MD]/
142
+ e += bases
143
+ end
144
+ end
145
+ return e
146
+ end
147
+
148
+ def parse_cigar
149
+ str = @cigar
150
+ l = str.length
151
+ @cigar_list = []
152
+ while str.length>0
153
+ if str =~ /([0-9]+[MIDNSHPX=]+)/
154
+ @cigar_list << {$1[0..-2].to_i => $1[-1]}
155
+ str = str.slice($1.length, l)
156
+ else
157
+ puts str
158
+ end
159
+ end
160
+ end
161
+
162
+ # snp storing
163
+
164
+ def contains_snp?(snp)
165
+ snp >= @pos and snp < self.endpos
166
+ end
167
+
168
+ def mark_snp(snp)
169
+ if self.contains_snp?(snp)
170
+ if !@cigar_list
171
+ self.parse_cigar
172
+ end
173
+ p = @pos
174
+ s = snp
175
+ @cigar_list.each do |h|
176
+ if p > s and s >= @pos
177
+ @snp = s - @pos
178
+ else
179
+ a = h.to_a
180
+ bases = a[0][0]
181
+ match = a[0][1]
182
+ if match == "M"
183
+ p += bases
184
+ elsif match == "I"
185
+ s += bases
186
+ elsif match == "D"
187
+ s -= bases
188
+ end
189
+ end
190
+ end
191
+ if p > s and s >= @pos
192
+ @snp = s - @pos
193
+ end
194
+ end
195
+ @snp
196
+ end
197
+
198
+ def transfer_snp(bs) # load in another bettersam object
199
+ if !self.read_unmapped? and !bs.read_unmapped?
200
+ if (self.read_reverse_strand? and bs.read_reverse_strand?) or (!self.read_reverse_strand? and !bs.read_reverse_strand?)
201
+ @snp = bs.snp
202
+ else
203
+ end
204
+ end
205
+ end
206
+
207
+ def put_snp # find the location of a snp on the genome
208
+ if @snp
209
+ if !@cigar_list
210
+ self.parse_cigar
211
+ end
212
+ s = @snp
213
+ p = 0
214
+ @cigar_list.each do |h|
215
+ if p > s
216
+ return s+@pos
217
+ else
218
+ a = h.to_a
219
+ bases = a[0][0]
220
+ match = a[0][1]
221
+ if match=="M"
222
+ p += bases
223
+ elsif match=="D"
224
+ s += bases
225
+ elsif match=="I"
226
+ s -= bases
227
+ end
228
+ end
229
+ end
230
+ if p > s
231
+ return s+@pos
232
+ end
233
+ else
234
+ puts "need to run mark_snp and transfer_snp first"
235
+ return nil
236
+ end
237
+ return -1
238
+ end
239
+
240
+ def get_base_at(p)
241
+ @seq[p]
242
+ end
124
243
 
125
244
  private
126
245
 
@@ -132,4 +251,5 @@ private
132
251
  Integer(x) rescue x
133
252
  end
134
253
 
254
+
135
255
  end
@@ -0,0 +1,16 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
10
+ require 'test/unit'
11
+ begin; require 'turn/autorun'; rescue LoadError; end
12
+ require 'shoulda-context'
13
+ require 'bettersam'
14
+
15
+ Turn.config.format = :pretty
16
+ Turn.config.trace = 1
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'helper'
4
+
5
+ class TestBetterSam < Test::Unit::TestCase
6
+
7
+ context "BetterSam" do
8
+
9
+ setup do
10
+ # this is run before each test
11
+ @l1 = BetterSam.new("FCC00CKABXX:2:1101:10117:6470#CAGATCAT 81 nivara_3s 1572276 40 100M = 1571527 -849 AGGATCGGGCCTCGTGAGCCGACGGTGAGCGAGTTGTTGTTGTTCCATACGGGGGCGCCGGAGTTGGTGCTCCACAGCGGGCCGTTGAACGAGCTCGACG ZbaX^_baX\_S]_ZdYccYebeffddZdbebdadc[bdVeeeceeeddggggggggggggggggegeggdffbfefegggggggggggggggggggggg AS:i:-24 XN:i:0 XM:i:4 XO:i:0 XG:i:0 NM:i:4 MD:Z:1T1G3T0A91 YS:i:-5 YT:Z:DP")
12
+ @l2 = BetterSam.new("FCC00CKABXX:2:1101:10117:6470#CAGATCAT 81 chromosome03 1789384 24 4M5I91M = 1788782 -697 AGGATCGGGCCTCGTGAGCCGACGGTGAGCGAGTTGTTGTTGTTCCATACGGGGGCGCCGGAGTTGGTGCTCCACAGCGGGCCGTTGAACGAGCTCGACG ZbaX^_baX\_S]_ZdYccYebeffddZdbebdadc[bdVeeeceeeddggggggggggggggggegeggdffbfefegggggggggggggggggggggg AS:i:-38 XN:i:0 XM:i:3 XO:i:1 XG:i:5 NM:i:8 MD:Z:0C1T6G85 YS:i:-5 YT:Z:DP")
13
+ @l3 = BetterSam.new("FCC00CKABXX:2:1101:19524:66398#CAGATCAT 145 chromosome03 1789377 23 4M1I2M1D93M = 1788766 -711 GGAGGATCGGGCCTCGTGGGCCGACGGTGAGCGAGTTGTTGTTGTTCCATACGGGGGCGCCGGAGTTGGTGCTCCACAGCGGGCCGTTGAACGAGCTCGA Bc`aaT\Y_]RLMKKMHEMV_T[Y[deaeeeaadbaaa\_feecedddddadfcegdcXdggcggggggggg`gfbecbcggggggggeggggggggggg AS:i:-51 XN:i:0 XM:i:6 XO:i:2 XG:i:2 NM:i:8 MD:Z:2T0C2^A2T0A5G1A81 YS:i:0 YT:Z:DP")
14
+ @l4l = BetterSam.new("FCC00CKABXX:2:1101:16909:83925#CAGATCAT 145 nivara_3s 1572267 23 5M2D3M2I3M1I86M = 1571498 -868 GTCCTCCAGGAGGATCGGGCCTCGTGAGCCGACGGTGAGCGAGTTGTTGTTGTTCCATACGGGGGCGCCGGAGTTGGTGCTCCACAGCGGGCCGTTGAAC BBBBBB_Z`cU]^SZS][]USKV[L`ac`dedeageeefagegagffdd`egedgggedgggggggdggggggggefeeeQgeagggggggggggggggg AS:i:-53 XN:i:0 XM:i:4 XO:i:3 XG:i:5 NM:i:9 MD:Z:2G2^TG3T5T0A81 YS:i:0 YT:Z:DP")
15
+ @l4r = BetterSam.new("FCC00CKABXX:2:1101:16909:83925#CAGATCAT 145 chromosome03 1789378 23 7M4I3M5I81M = 1788753 -716 GTCCTCCAGGAGGATCGGGCCTCGTGAGCCGACGGTGAGCGAGTTGTTGTTGTTCCATACGGGGGCGCCGGAGTTGGTGCTCCACAGCGGGCCGTTGAAC BBBBBB_Z`cU]^SZS][]USKV[L`ac`dedeageeefagegagffdd`egedgggedgggggggdggggggggefeeeQgeagggggggggggggggg AS:i:-59 XN:i:0 XM:i:4 XO:i:2 XG:i:9 NM:i:13 MD:Z:3A1A2T6G75 YS:i:0 YT:Z:DP")
16
+ end
17
+
18
+ should "be a paired read" do
19
+ assert @l1.read_paired?
20
+ end
21
+
22
+ should "be on the reverse strand" do
23
+ assert @l1.read_reverse_strand?
24
+ end
25
+
26
+ should "be the first pair" do
27
+ assert @l1.first_in_pair?
28
+ end
29
+
30
+ should "get the mappping position" do
31
+ assert @l1.pos == 1572276
32
+ end
33
+
34
+ should "get the end position" do
35
+ assert @l1.endpos == 1572376
36
+ end
37
+
38
+ should "get the end position too" do
39
+ assert @l2.endpos == 1789479, "this is #{@l1.endpos} but should be 1789479"
40
+ end
41
+
42
+ should "be exact match" do
43
+ assert @l1.exact_match?
44
+ end
45
+
46
+ should "contain snp" do
47
+ assert @l1.contains_snp?(1572283)
48
+ end
49
+
50
+ should "give A" do
51
+ assert @l1.get_base_at(0)=="A", "this is #{@l1.get_base_at(0)}, but should be A"
52
+ end
53
+
54
+ should "parse the cigar string correctly" do
55
+ @l3.parse_cigar
56
+ assert @l3.cigar_list.size == 5
57
+ end
58
+
59
+ should "parse another cigar string correctly" do
60
+ @l4l.parse_cigar
61
+ assert @l4l.cigar_list.size == 7
62
+ end
63
+
64
+ should "mark a snp" do
65
+ assert @l1.mark_snp(1572283)==7, "this is #{@l1.mark_snp(1572283)}, but i think it should be 7"
66
+ end
67
+
68
+ should "mark yet another snp" do
69
+ assert @l4l.mark_snp(1572283)==17, "this is #{@l4l.mark_snp(1572283)}, but i think it should be 17"
70
+ end
71
+
72
+ should "transfer a snp from one object to another" do
73
+ @l1.mark_snp(1572283)
74
+ @l2.transfer_snp(@l1)
75
+ assert @l2.snp == 7, "this is #{@l2.snp}, but i think it should be 7"
76
+ end
77
+
78
+ should "mark another snp" do
79
+ assert @l2.mark_snp(1789386)==2, "this is #{@l2.mark_snp(1789386)}, but i think it should be 3"
80
+ end
81
+
82
+ should "mark a third snp" do
83
+ assert @l3.mark_snp(1789386)==9, "this is #{@l3.mark_snp(1789386)}, but i think it should be 9"
84
+ end
85
+
86
+ should "find the location of a snp on the genome" do
87
+ @l4l.mark_snp(1572283)
88
+ @l4r.transfer_snp(@l4l)
89
+ assert @l4r.put_snp==1789386, "this is #{@l4r.put_snp}, but I think it should be 1789386"
90
+ end
91
+
92
+ end
93
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bettersam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha
5
- prerelease: 6
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Richard Smith
@@ -10,38 +9,112 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-09-17 00:00:00.000000000 Z
14
- dependencies: []
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: simplecov
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: turn
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: shoulda-context
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: coveralls
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
15
84
  description: Extended SAM (Sequence Alignment/Map) file parsing
16
85
  email: rds45@cam.ac.uk
17
86
  executables: []
18
87
  extensions: []
19
88
  extra_rdoc_files: []
20
89
  files:
90
+ - Rakefile
21
91
  - lib/bettersam.rb
92
+ - test/test_test.rb
93
+ - test/helper.rb
94
+ - README.md
95
+ - LICENSE
22
96
  homepage: https://github.com/blahah/bettersam
23
97
  licenses:
24
98
  - MIT
99
+ metadata: {}
25
100
  post_install_message:
26
101
  rdoc_options: []
27
102
  require_paths:
28
103
  - lib
29
104
  required_ruby_version: !ruby/object:Gem::Requirement
30
- none: false
31
105
  requirements:
32
- - - ! '>='
106
+ - - ">="
33
107
  - !ruby/object:Gem::Version
34
108
  version: '0'
35
109
  required_rubygems_version: !ruby/object:Gem::Requirement
36
- none: false
37
110
  requirements:
38
- - - ! '>'
111
+ - - ">="
39
112
  - !ruby/object:Gem::Version
40
- version: 1.3.1
113
+ version: '0'
41
114
  requirements: []
42
115
  rubyforge_project:
43
- rubygems_version: 1.8.24
116
+ rubygems_version: 2.1.4
44
117
  signing_key:
45
- specification_version: 3
118
+ specification_version: 4
46
119
  summary: Extended SAM file parsing
47
120
  test_files: []