bio-samtools 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/Gemfile.lock +1 -0
  2. data/README.rdoc +1 -0
  3. data/VERSION +1 -1
  4. data/bio-samtools.gemspec +19 -19
  5. data/doc/Bio.html +71 -4
  6. data/doc/Bio/DB.html +6 -4
  7. data/doc/Bio/DB/Alignment.html +8 -8
  8. data/doc/Bio/DB/Pileup.html +515 -0
  9. data/doc/Bio/DB/SAM.html +37 -37
  10. data/doc/Bio/DB/SAM/Library.html +4 -4
  11. data/doc/Bio/DB/SAM/Tools.html +4 -4
  12. data/doc/Bio/DB/SAM/Tools/Bam1CoreT.html +4 -4
  13. data/doc/Bio/DB/SAM/Tools/Bam1T.html +4 -4
  14. data/doc/Bio/DB/SAM/Tools/BamHeaderT.html +4 -4
  15. data/doc/Bio/DB/SAM/Tools/BamPileup1T.html +4 -4
  16. data/doc/Bio/DB/SAM/Tools/SamfileT.html +4 -4
  17. data/doc/Bio/DB/SAM/Tools/SamfileTX.html +4 -4
  18. data/doc/Bio/DB/SAMException.html +5 -5
  19. data/doc/Bio/DB/Tag.html +5 -5
  20. data/doc/Bio/DB/Vcf.html +467 -0
  21. data/doc/LICENSE_txt.html +57 -60
  22. data/doc/LibC.html +6 -4
  23. data/doc/created.rid +7 -7
  24. data/doc/index.html +4 -4
  25. data/doc/js/search_index.js +1 -1
  26. data/doc/lib/bio-samtools_rb.html +4 -4
  27. data/doc/lib/bio/db/pileup_rb.html +171 -0
  28. data/doc/lib/bio/db/sam/bam_rb.html +4 -4
  29. data/doc/lib/bio/db/sam/faidx_rb.html +4 -4
  30. data/doc/lib/bio/db/sam/library_rb.html +4 -4
  31. data/doc/lib/bio/db/sam/sam_rb.html +4 -4
  32. data/doc/lib/bio/db/sam_rb.html +4 -4
  33. data/doc/lib/bio/db/vcf_rb.html +124 -0
  34. data/doc/table_of_contents.html +16 -26
  35. data/doc/tutorial.html +26 -1
  36. data/doc/tutorial.pdf +0 -0
  37. data/lib/bio/db/{sam/pileup.rb → pileup.rb} +6 -4
  38. data/lib/bio/db/sam.rb +13 -12
  39. data/lib/bio/db/{sam/vcf.rb → vcf.rb} +6 -2
  40. data/test/samples/small/sorted.bam.bai +0 -0
  41. data/test/test_basic.rb +7 -5
  42. data/test/test_vcf.rb +5 -5
  43. metadata +29 -26
  44. data/test/basictest.rb +0 -322
  45. data/test/pileup.rb +0 -68
@@ -4,12 +4,14 @@
4
4
  # Forked from vcfruby at https://github.com/jesserod/vcfruby
5
5
  # Modified and tests written by Dan MacLean (dan.maclean@tsl.ac.uk)
6
6
  # VCF is described at http://www.1000genomes.org/node/101
7
-
7
+ module Bio
8
+ class DB
8
9
  class Vcf
9
10
  public
10
11
  attr_accessor :chrom, :pos, :id, :ref, :alt, :qual, :filter, :info, :format, :samples
11
12
 
12
13
  #create the vcf object, use the ordered list of sample names to label samples if provided ['A', 'B', 'C'], otherwise uses, 1,2,3 etc
14
+ #vcf = Bio::DB::Vcf("19 111 . A C 9.6 . . GT:HQ 0|0:10,10 0|0:10,10 0/1:3,3")
13
15
  def initialize(line=nil, sample_names=nil)
14
16
  @info = {}
15
17
  @samples = {}
@@ -20,7 +22,7 @@ public
20
22
  Integer.new(x) rescue x
21
23
  end
22
24
 
23
- #gets the info in the Vcf lines and parses the
25
+ #gets the info in the Vcf lines and parses it, setting the attributes
24
26
  def parse_line(line, sample_names=nil)
25
27
  return false if line[0,1] == '#'
26
28
 
@@ -75,3 +77,5 @@ public
75
77
  end
76
78
 
77
79
  end
80
+ end
81
+ end
Binary file
data/test/test_basic.rb CHANGED
@@ -5,7 +5,8 @@ require 'ffi'
5
5
  require "test/unit"
6
6
  require "bio/db/sam"
7
7
  require "bio/db/sam/sam"
8
-
8
+ require "bio/db/pileup"
9
+ require "bio/db/vcf"
9
10
 
10
11
  class TestBioDbSam < Test::Unit::TestCase
11
12
 
@@ -168,6 +169,7 @@ class TestBioDbSam < Test::Unit::TestCase
168
169
  #node_7263 238 60 has 550+, query from 0 to 500, something shall come....
169
170
  end
170
171
 
172
+ =begin ##these tests are correct-ish but the functionality isnt implemented yet ...
171
173
  def test_read_invalid_reference
172
174
  sam = Bio::DB::Sam.new({:bam=>@testBAMFile})
173
175
  sam.open
@@ -223,7 +225,7 @@ class TestBioDbSam < Test::Unit::TestCase
223
225
  assert(true, "Exception generated and catched")
224
226
  end
225
227
  end
226
-
228
+ =end
227
229
  def test_fasta_load_index
228
230
  sam = Bio::DB::Sam.new({:fasta=>@testReference})
229
231
  sam.load_reference
@@ -289,7 +291,7 @@ class TestBioDbSam < Test::Unit::TestCase
289
291
  end
290
292
  assert_equal(10,pileup_list.length)
291
293
  pileup_list.each do |p|
292
- assert_kind_of(Pileup, p)
294
+ assert_kind_of(Bio::DB::Pileup, p)
293
295
  end
294
296
  end
295
297
 
@@ -302,13 +304,13 @@ class TestBioDbSam < Test::Unit::TestCase
302
304
  list << pile
303
305
  end
304
306
  assert_equal(10,list.length)
305
- list.each {|p| assert_kind_of(Pileup, p)}
307
+ list.each {|p| assert_kind_of(Bio::DB::Pileup, p)}
306
308
  vcf_list = []
307
309
  sam.mpileup_plus(:region => "chr_1:100-109", :g => true) do |vcf|
308
310
  vcf_list << vcf
309
311
  end
310
312
  assert_equal(10,vcf_list.length)
311
- vcf_list.each {|p| assert_kind_of(Vcf, p)}
313
+ vcf_list.each {|p| assert_kind_of(Bio::DB::Vcf, p)}
312
314
  end
313
315
 
314
316
  #test whether the call to mpileup returns a vcf object if :g => true is used on the command-line
data/test/test_vcf.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
2
2
  $: << File.expand_path('.')
3
3
  require 'rubygems'
4
- require 'bio/db/sam/vcf'
4
+ require 'bio/db/vcf'
5
5
  require "test/unit"
6
6
 
7
7
 
8
8
  class TestVcf < Test::Unit::TestCase
9
9
 
10
10
  def setup
11
- @vcf1 = Vcf.new("19 111 . A C 9.6 . . GT:HQ 0|0:10,10 0|0:10,10 0/1:3,3",["a","b","c"]) #from a 3.3 vcf file
12
- @vcf2 = Vcf.new("20 14370 rs6054257 G A 29 0 NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:-1,-1") #from a 3.3 vcf file
13
- @vcf3 = Vcf.new("19 111 . A C 9.6 . . GT:HQ 0|0:10,10 0|0:10,10 0/1:3,3") #from a 4.0 vcf file
14
- @vcf4 = Vcf.new("20 14370 rs6054257 G A 29 PASS NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:.,") #from a 4.0 vcf file
11
+ @vcf1 = Bio::DB::Vcf.new("19 111 . A C 9.6 . . GT:HQ 0|0:10,10 0|0:10,10 0/1:3,3",["a","b","c"]) #from a 3.3 vcf file
12
+ @vcf2 = Bio::DB::Vcf.new("20 14370 rs6054257 G A 29 0 NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:-1,-1") #from a 3.3 vcf file
13
+ @vcf3 = Bio::DB::Vcf.new("19 111 . A C 9.6 . . GT:HQ 0|0:10,10 0|0:10,10 0/1:3,3") #from a 4.0 vcf file
14
+ @vcf4 = Bio::DB::Vcf.new("20 14370 rs6054257 G A 29 PASS NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:.,") #from a 4.0 vcf file
15
15
  end
16
16
 
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-samtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-11-10 00:00:00.000000000Z
14
+ date: 2012-01-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: ffi
18
- requirement: &2157872120 !ruby/object:Gem::Requirement
18
+ requirement: &2153534240 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2157872120
26
+ version_requirements: *2153534240
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bio
29
- requirement: &2157870700 !ruby/object:Gem::Requirement
29
+ requirement: &2153533620 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 1.4.2
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2157870700
37
+ version_requirements: *2153533620
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: shoulda
40
- requirement: &2157869680 !ruby/object:Gem::Requirement
40
+ requirement: &2153531760 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *2157869680
48
+ version_requirements: *2153531760
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: bundler
51
- requirement: &2157868840 !ruby/object:Gem::Requirement
51
+ requirement: &2153529440 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 1.0.0
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *2157868840
59
+ version_requirements: *2153529440
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: jeweler
62
- requirement: &2157857240 !ruby/object:Gem::Requirement
62
+ requirement: &2153526840 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *2157857240
70
+ version_requirements: *2153526840
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rcov
73
- requirement: &2157856580 !ruby/object:Gem::Requirement
73
+ requirement: &2153524760 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *2157856580
81
+ version_requirements: *2153524760
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: bio
84
- requirement: &2157856020 !ruby/object:Gem::Requirement
84
+ requirement: &2153522840 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: 1.4.2
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *2157856020
92
+ version_requirements: *2153522840
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: ffi
95
- requirement: &2157855320 !ruby/object:Gem::Requirement
95
+ requirement: &2153483000 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ! '>='
@@ -100,10 +100,10 @@ dependencies:
100
100
  version: '0'
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *2157855320
103
+ version_requirements: *2153483000
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rdoc
106
- requirement: &2157854640 !ruby/object:Gem::Requirement
106
+ requirement: &2153482380 !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
109
109
  - - ! '>='
@@ -111,7 +111,7 @@ dependencies:
111
111
  version: '0'
112
112
  type: :development
113
113
  prerelease: false
114
- version_requirements: *2157854640
114
+ version_requirements: *2153482380
115
115
  description: ! "Binder of samtools for ruby, on the top of FFI. \n\n This project
116
116
  was born from the need to add support of BAM files to \n the gee_fu genome browser
117
117
  (http://github.com/danmaclean/gee_fu)."
@@ -134,6 +134,7 @@ files:
134
134
  - doc/Bio.html
135
135
  - doc/Bio/DB.html
136
136
  - doc/Bio/DB/Alignment.html
137
+ - doc/Bio/DB/Pileup.html
137
138
  - doc/Bio/DB/SAM.html
138
139
  - doc/Bio/DB/SAM/Library.html
139
140
  - doc/Bio/DB/SAM/Tools.html
@@ -145,6 +146,7 @@ files:
145
146
  - doc/Bio/DB/SAM/Tools/SamfileTX.html
146
147
  - doc/Bio/DB/SAMException.html
147
148
  - doc/Bio/DB/Tag.html
149
+ - doc/Bio/DB/Vcf.html
148
150
  - doc/LICENSE_txt.html
149
151
  - doc/LibC.html
150
152
  - doc/Pileup.html
@@ -241,6 +243,7 @@ files:
241
243
  - doc/js/search_index.js
242
244
  - doc/js/searcher.js
243
245
  - doc/lib/bio-samtools_rb.html
246
+ - doc/lib/bio/db/pileup_rb.html
244
247
  - doc/lib/bio/db/sam/bam_rb.html
245
248
  - doc/lib/bio/db/sam/faidx_rb.html
246
249
  - doc/lib/bio/db/sam/library_rb.html
@@ -248,6 +251,7 @@ files:
248
251
  - doc/lib/bio/db/sam/sam_rb.html
249
252
  - doc/lib/bio/db/sam/vcf_rb.html
250
253
  - doc/lib/bio/db/sam_rb.html
254
+ - doc/lib/bio/db/vcf_rb.html
251
255
  - doc/rdoc-style.css
252
256
  - doc/rdoc.css
253
257
  - doc/table_of_contents.html
@@ -258,20 +262,19 @@ files:
258
262
  - ext/mkrf_conf.rb
259
263
  - lib/bio-samtools.rb
260
264
  - lib/bio/.DS_Store
265
+ - lib/bio/db/pileup.rb
261
266
  - lib/bio/db/sam.rb
262
267
  - lib/bio/db/sam/bam.rb
263
268
  - lib/bio/db/sam/external/COPYING
264
269
  - lib/bio/db/sam/external/VERSION
265
270
  - lib/bio/db/sam/faidx.rb
266
271
  - lib/bio/db/sam/library.rb
267
- - lib/bio/db/sam/pileup.rb
268
272
  - lib/bio/db/sam/sam.rb
269
- - lib/bio/db/sam/vcf.rb
270
- - test/basictest.rb
273
+ - lib/bio/db/vcf.rb
271
274
  - test/helper.rb
272
- - test/pileup.rb
273
275
  - test/samples/small/ids2.txt
274
276
  - test/samples/small/sorted.bam
277
+ - test/samples/small/sorted.bam.bai
275
278
  - test/samples/small/test
276
279
  - test/samples/small/test.bam
277
280
  - test/samples/small/test.fa
@@ -307,7 +310,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
307
310
  version: '0'
308
311
  segments:
309
312
  - 0
310
- hash: -4357702541244266034
313
+ hash: 2724404510118255875
311
314
  required_rubygems_version: !ruby/object:Gem::Requirement
312
315
  none: false
313
316
  requirements:
@@ -316,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
319
  version: '0'
317
320
  requirements: []
318
321
  rubyforge_project:
319
- rubygems_version: 1.8.6
322
+ rubygems_version: 1.8.10
320
323
  signing_key:
321
324
  specification_version: 3
322
325
  summary: Binder of samtools for ruby, on the top of FFI.
data/test/basictest.rb DELETED
@@ -1,322 +0,0 @@
1
- $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
2
- $: << File.expand_path('.')
3
- require "test/unit"
4
- require "bio/db/sam"
5
- require "bio/db/sam/sam"
6
-
7
-
8
- class TestBioDbSam < Test::Unit::TestCase
9
-
10
- #Set up the paths
11
- def setup
12
- @test_folder = "test/samples/small"
13
- @testTAMFile = @test_folder + "/test.tam"
14
- @testBAMFile = @test_folder + "/testu.bam"
15
- @testReference = @test_folder + "/test_chr.fasta"
16
-
17
- end
18
-
19
- #Removing the index files
20
- def teardown
21
- begin
22
- File.delete(@testReference + ".fai")
23
- p "deleted: " + @testReference + ".fai "
24
- rescue
25
- end
26
- begin
27
- File.delete(@testBAMFile + ".fai")
28
- p "deleted: " + @testBAMFile + ".bai "
29
- rescue
30
- end
31
- end
32
- =begi
33
- def default_test
34
- puts $LOAD_PATH
35
- assert(true, "Unit test test")
36
- end
37
-
38
- def test_openSAMFile
39
- bamfile = Bio::DB::SAM::Tools.samopen(@testTAMFile,"r",nil)
40
- Bio::DB::SAM::Tools.samclose(bamfile)
41
- assert(true, "file open and closed")
42
- end
43
-
44
- def test_new_class_empty
45
- begin
46
- bam = Bio::DB::Sam.new({})
47
- assert(false, "Should fail while opening without parameters")
48
- rescue Bio::DB::SAMException => e
49
- puts e.message
50
- assert(true, e.message)
51
- end
52
- end
53
-
54
- def test_new_class_empty_invalid_path
55
- begin
56
- sam = Bio::DB::Sam.new({:bam=>"INVALID"})
57
- sam.open
58
- sam.close
59
- assert(false, "Should fail with an invalid path")
60
- rescue Bio::DB::SAMException => e
61
- puts e.message
62
- assert(true, e.message)
63
- end
64
- end
65
-
66
- def test_class_text_read_no_faidx
67
- sam = Bio::DB::Sam.new({:tam=>@testTAMFile})
68
- sam.open
69
- sam.close
70
- assert(true, "file open and closed with the class")
71
- end
72
-
73
- def test_class_text_read_no_close
74
-
75
- fam = Bio::DB::Sam.new({:tam=>@testTAMFile})
76
- fam.open
77
- fam = nil
78
- ObjectSpace.garbage_collect
79
-
80
- assert(true, "file openend but not closed")
81
- end
82
-
83
- def test_class_binary_read_no_close
84
-
85
- Bio::DB::Sam.new({:bam=>@testBAMFile}).open
86
- ObjectSpace.garbage_collect
87
- assert(true, "BINARY file openend but not closed")
88
- end
89
-
90
- def test_read_coverage
91
- sam = Bio::DB::Sam.new({:bam=>@testBAMFile, :fasta=>@testReference})
92
- sam.open
93
- File.open( @test_folder +"/ids2.txt", "r") do |file|
94
- puts "file opened"
95
- file.each_line{|line|
96
- fetching = line.split(' ')[0]
97
- puts "fetching: " + fetching
98
- sam.load_reference
99
- seq = sam.fetch_reference(fetching, 0, 16000)
100
- # puts seq
101
- # puts seq.length
102
- als = sam.fetch(fetching, 0, seq.length)
103
- # p als
104
- if als.length() > 0 then
105
- p fetching
106
- p als
107
- end
108
- }
109
-
110
- end
111
- sam.close
112
- assert(true, "Finish")
113
- end
114
- # def test_read_TAM_as_BAM
115
- # begin
116
- # sam = Bio::DB::Sam.new({:bam=>@testTAMFile})
117
- # sam.open
118
- # sam.close
119
- # assert(false, "Should raise an exception for reading a BAM as TAM")
120
- # rescue Bio::DB::SAMException => e
121
- # assert(true, "Properly handled")
122
- # end
123
- # end
124
-
125
- # def test_read_BAM_as_TAM
126
- # begin
127
- # sam = Bio::DB::Sam.new({:tam=>@testBAMFile})
128
- # sam.open
129
- # sam.close
130
- # assert(false, "Should raise an exception for reading a BAM as TAM")
131
- # rescue Bio::DB::SAMException => e
132
- # assert(true, "Properly handled")
133
- # end
134
- # end
135
-
136
- def test_bam_load_index
137
- sam = Bio::DB::Sam.new({:bam=>@testBAMFile})
138
- sam.open
139
- index = sam.load_index
140
- sam.close
141
- assert(true, "BAM index loaded")
142
- # attach_function :bam_index_build, [ :string ], :int
143
- # attach_function :bam_index_load, [ :string ], :pointer
144
- # attach_function :bam_index_destroy, [ :pointer ], :void
145
- end
146
-
147
- def test_tam_load_index
148
- begin
149
- sam = Bio::DB::Sam.new({:tam=>@testTAMFile})
150
- sam.open
151
- sam.load_index
152
- sam.close
153
- assert(false, "TAM index loaded")
154
- rescue Bio::DB::SAMException => e
155
- assert(true, "Unable to load an index for a TAM file")
156
- end
157
- end
158
-
159
- def test_read_segment
160
- sam = Bio::DB::Sam.new({:bam=>@testBAMFile})
161
- sam.open
162
- als = sam.fetch("chr_1", 0, 500)
163
- p als
164
- sam.close
165
- assert(true, "Seems it ran the query")
166
- #node_7263 238 60 has 550+, query from 0 to 500, something shall come....
167
- end
168
- =end
169
- def test_read_invalid_reference
170
- sam = Bio::DB::Sam.new({:bam=>@testBAMFile})
171
- sam.open
172
- begin
173
- als = sam.fetch("Chr1", 0, 500)
174
- p als
175
- sam.close
176
- assert(false, "Seems it ran the query")
177
- rescue Bio::DB::SAMException => e
178
- p e
179
- assert(true, "Exception generated and catched")
180
- end
181
- end
182
-
183
- def test_read_invalid_reference_start_coordinate
184
- sam = Bio::DB::Sam.new({:bam=>@testBAMFile})
185
- sam.open
186
- begin
187
- als = sam.fetch("chr", -1, 500)
188
- p als
189
- sam.close
190
- assert(false, "Seems it ran the query")
191
- rescue Bio::DB::SAMException => e
192
- p e
193
- assert(true, "Exception generated and catched")
194
- end
195
- end
196
-
197
- def test_read_invalid_reference_end_coordinate
198
- sam = Bio::DB::Sam.new({:bam=>@testBAMFile})
199
- sam.open
200
- begin
201
- als = sam.fetch("chr", 0, 50000)
202
- p als
203
- sam.close
204
- assert(false, "Seems it ran the query")
205
- rescue Bio::DB::SAMException => e
206
- p e
207
- assert(true, "Exception generated and catched")
208
- end
209
- end
210
-
211
- def test_read_invalid_reference_swaped_coordinates
212
- sam = Bio::DB::Sam.new({:bam=>@testBAMFile})
213
- sam.open
214
- begin
215
- als = sam.fetch("chr", 500, 0)
216
- p als
217
- sam.close
218
- assert(false, "Seems it ran the query")
219
- rescue Bio::DB::SAMException => e
220
- p e
221
- assert(true, "Exception generated and catched")
222
- end
223
- end
224
-
225
- def test_fasta_load_index
226
- sam = Bio::DB::Sam.new({:fasta=>@testReference})
227
- sam.load_reference
228
- seq = sam.fetch_reference("chr_1", 0, 500)
229
- p seq
230
- sam.close
231
- assert(true, "The reference was loaded")
232
- end
233
-
234
- def test_fasta_load_index
235
- sam = Bio::DB::Sam.new({:fasta=>@testReference})
236
- sam.load_reference
237
- begin
238
- seq = sam.fetch_reference("chr1", 0, 500)
239
- p "Error seq:"+ seq
240
- sam.close
241
- assert(false, "The reference was loaded")
242
- rescue Bio::DB::SAMException => e
243
- p e
244
- assert(true, "The references was not loaded")
245
- end
246
- end
247
-
248
- def test_load_feature
249
-
250
- fs = Feature.find_by_bam("chr_1", 0, 500,@testBAMFile)
251
-
252
- p fs
253
- assert(true, "Loaded as features")
254
- end
255
-
256
- def test_avg_coverage
257
- sam = Bio::DB::Sam.new({:fasta=>@testReference, :bam=>@testBAMFile })
258
- sam.open
259
- cov = sam.average_coverage("chr_1", 60, 30)
260
- p "Coverage: " + cov.to_s
261
- sam.close
262
- assert(true, "Average coverage ran")
263
- assert(3 == cov, "The coverage is 3")
264
- end
265
-
266
-
267
- def test_chromosome_coverage
268
- sam = Bio::DB::Sam.new({:fasta=>@testReference, :bam=>@testBAMFile })
269
- sam.open
270
- covs = sam.chromosome_coverage("chr_1", 0, 60)
271
- p "Coverage: "
272
- p covs
273
- puts "POS\tCOV"
274
- covs.each_with_index{ |cov, i| puts "#{i}\t#{cov}" }
275
- sam.close
276
- assert(true, "Average coverage ran")
277
- #assert(3 == cov, "The coverage is 3")
278
- end
279
-
280
- #test whether the call to mpileup works and returns 10 objects of class pileup
281
- def test_pileup
282
- sam = Bio::DB::Sam.new(:fasta=>@testReference, :bam=>@testBAMFile )
283
- pileup_list = []
284
- sam.mpileup(:region => "chr_1:100-1100") do |pile|
285
- next unless pile.ref_name == 'chr_1' ##required because in the test environment stdout gets mixed in with the captured stdout in the function and non pileup lines are passed...
286
- pileup_list << pile
287
- end
288
- assert_equal(1000,pileup_list.length)
289
- pileup_list.each do |p|
290
- assert_kind_of(Pileup, p)
291
- end
292
- end
293
-
294
- end
295
-
296
- class Feature
297
- attr_reader :start, :end, :strand, :sequence, :quality
298
-
299
- def initialize(a={})
300
- p a
301
- @start = a[:start]
302
- @end = a[:enf]
303
- @strand = a[:strand]
304
- @sequence = a[:sequence]
305
- @quality = a[:quality]
306
- end
307
-
308
- def self.find_by_bam(reference,start,stop,bam_file_path)
309
-
310
- sam = Bio::DB::Sam.new({:bam=>bam_file_path})
311
- features = []
312
- sam.open
313
-
314
- fetchAlignment = Proc.new do |a|
315
- a.query_strand ? strand = '+' : strand = '-'
316
- features << Feature.new({:start=>a.pos,:end=>a.calend,:strand=>strand,:sequence=>a.seq,:quality=>a.qual})
317
- end
318
- sam.fetch_with_function(reference, start, stop, fetchAlignment)
319
- sam.close
320
- features
321
- end
322
- end