bio-samtools 0.6.2 → 2.0.3

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 (160) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -2
  3. data/README.md +4 -7
  4. data/VERSION +1 -1
  5. data/bio-samtools.gemspec +47 -105
  6. data/doc/Bio.html +68 -131
  7. data/doc/Bio/DB.html +51 -111
  8. data/doc/Bio/DB/Alignment.html +135 -363
  9. data/doc/Bio/DB/Pileup.html +183 -170
  10. data/doc/Bio/DB/SAM.html +1396 -820
  11. data/doc/Bio/DB/SAM/Library.html +73 -123
  12. data/doc/Bio/DB/SAM/Tools.html +51 -273
  13. data/doc/Bio/DB/Tag.html +78 -124
  14. data/doc/Bio/DB/Vcf.html +111 -147
  15. data/doc/LICENSE_txt.html +113 -148
  16. data/doc/created.rid +9 -10
  17. data/doc/fonts.css +167 -0
  18. data/doc/fonts/Lato-Light.ttf +0 -0
  19. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  20. data/doc/fonts/Lato-Regular.ttf +0 -0
  21. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  22. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  23. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  24. data/doc/images/add.png +0 -0
  25. data/doc/images/arrow_up.png +0 -0
  26. data/doc/images/delete.png +0 -0
  27. data/doc/images/tag_blue.png +0 -0
  28. data/doc/index.html +48 -54
  29. data/doc/js/darkfish.js +9 -22
  30. data/doc/js/search.js +20 -5
  31. data/doc/js/search_index.js +1 -1
  32. data/doc/rdoc.css +255 -218
  33. data/doc/table_of_contents.html +256 -137
  34. data/ext/Rakefile +57 -0
  35. data/lib/bio-samtools.rb +7 -2
  36. data/lib/bio/BIOExtensions.rb +89 -0
  37. data/lib/bio/db/alignment.rb +59 -0
  38. data/lib/bio/db/fastadb.rb +255 -0
  39. data/lib/bio/db/pileup.rb +221 -172
  40. data/lib/bio/db/sam.rb +639 -589
  41. data/lib/bio/db/sam/{faidx.rb → faidx_old.rb} +0 -0
  42. data/lib/bio/db/vcf.rb +69 -68
  43. data/test/.gitignore +1 -0
  44. data/test/{test_basic.rb → old_test_basic.rb} +33 -1
  45. data/test/samples/small/dupes.bam +0 -0
  46. data/test/samples/small/dupes.sam +274 -0
  47. data/test/samples/small/map_for_reheader.sam +8 -0
  48. data/test/samples/small/map_to_merge1.bam +0 -0
  49. data/test/samples/small/map_to_merge1.bam.bai +0 -0
  50. data/test/samples/small/map_to_merge1.sam +8 -0
  51. data/test/samples/small/map_to_merge2.bam +0 -0
  52. data/test/samples/small/map_to_merge2.bam.bai +0 -0
  53. data/test/samples/small/map_to_merge2.sam +8 -0
  54. data/test/samples/small/no_md.sam +8 -0
  55. data/test/samples/small/test_chr.fasta.1.bt2 +0 -0
  56. data/test/samples/small/test_chr.fasta.2.bt2 +0 -0
  57. data/test/samples/small/test_chr.fasta.3.bt2 +0 -0
  58. data/test/samples/small/test_chr.fasta.4.bt2 +0 -0
  59. data/test/samples/small/test_chr.fasta.rev.1.bt2 +0 -0
  60. data/test/samples/small/test_chr.fasta.rev.2.bt2 +0 -0
  61. data/test/samples/small/test_cov.svg +273 -0
  62. data/test/samples/small/testu.bam.bai +0 -0
  63. data/test/svg +133 -0
  64. data/test/test_pileup.rb +84 -0
  65. data/test/test_sam.rb +331 -0
  66. data/test/test_vcf.rb +11 -0
  67. data/{doc → tutorial}/tutorial.html +0 -0
  68. data/{doc → tutorial}/tutorial.pdf +0 -0
  69. metadata +56 -114
  70. data/doc/Bio/DB/SAM/Tools/Bam1CoreT.html +0 -159
  71. data/doc/Bio/DB/SAM/Tools/Bam1T.html +0 -220
  72. data/doc/Bio/DB/SAM/Tools/BamHeaderT.html +0 -249
  73. data/doc/Bio/DB/SAM/Tools/BamPileup1T.html +0 -159
  74. data/doc/Bio/DB/SAM/Tools/SamfileT.html +0 -171
  75. data/doc/Bio/DB/SAM/Tools/SamfileTX.html +0 -159
  76. data/doc/Bio/DB/SAMException.html +0 -205
  77. data/doc/LibC.html +0 -155
  78. data/doc/Pileup.html +0 -571
  79. data/doc/Vcf.html +0 -473
  80. data/doc/basic_styles.css +0 -31
  81. data/doc/classes/Bio.html +0 -139
  82. data/doc/classes/Bio/DB.html +0 -137
  83. data/doc/classes/Bio/DB/Alignment.html +0 -441
  84. data/doc/classes/Bio/DB/Alignment.src/M000012.html +0 -19
  85. data/doc/classes/Bio/DB/Alignment.src/M000013.html +0 -27
  86. data/doc/classes/Bio/DB/Alignment.src/M000014.html +0 -45
  87. data/doc/classes/Bio/DB/Alignment.src/M000015.html +0 -40
  88. data/doc/classes/Bio/DB/SAM.html +0 -510
  89. data/doc/classes/Bio/DB/SAM/Library.html +0 -135
  90. data/doc/classes/Bio/DB/SAM/Library.src/M000006.html +0 -28
  91. data/doc/classes/Bio/DB/SAM/Tools.html +0 -278
  92. data/doc/classes/Bio/DB/SAM/Tools.src/M000007.html +0 -20
  93. data/doc/classes/Bio/DB/SAM/Tools/Bam1CoreT.html +0 -111
  94. data/doc/classes/Bio/DB/SAM/Tools/Bam1T.html +0 -150
  95. data/doc/classes/Bio/DB/SAM/Tools/Bam1T.src/M000010.html +0 -20
  96. data/doc/classes/Bio/DB/SAM/Tools/BamHeaderT.html +0 -169
  97. data/doc/classes/Bio/DB/SAM/Tools/BamHeaderT.src/M000008.html +0 -19
  98. data/doc/classes/Bio/DB/SAM/Tools/BamHeaderT.src/M000009.html +0 -18
  99. data/doc/classes/Bio/DB/SAM/Tools/BamPileup1T.html +0 -111
  100. data/doc/classes/Bio/DB/SAM/Tools/SamfileT.html +0 -129
  101. data/doc/classes/Bio/DB/SAM/Tools/SamfileTX.html +0 -111
  102. data/doc/classes/Bio/DB/SAMException.html +0 -140
  103. data/doc/classes/Bio/DB/SAMException.src/M000016.html +0 -18
  104. data/doc/classes/Bio/DB/Sam.src/M000017.html +0 -43
  105. data/doc/classes/Bio/DB/Sam.src/M000018.html +0 -42
  106. data/doc/classes/Bio/DB/Sam.src/M000019.html +0 -18
  107. data/doc/classes/Bio/DB/Sam.src/M000020.html +0 -22
  108. data/doc/classes/Bio/DB/Sam.src/M000021.html +0 -19
  109. data/doc/classes/Bio/DB/Sam.src/M000022.html +0 -25
  110. data/doc/classes/Bio/DB/Sam.src/M000023.html +0 -28
  111. data/doc/classes/Bio/DB/Sam.src/M000024.html +0 -28
  112. data/doc/classes/Bio/DB/Sam.src/M000025.html +0 -46
  113. data/doc/classes/Bio/DB/Sam.src/M000026.html +0 -24
  114. data/doc/classes/Bio/DB/Sam.src/M000027.html +0 -19
  115. data/doc/classes/Bio/DB/Sam.src/M000028.html +0 -24
  116. data/doc/classes/Bio/DB/Sam.src/M000029.html +0 -41
  117. data/doc/classes/Bio/DB/Sam.src/M000030.html +0 -31
  118. data/doc/classes/Bio/DB/Sam.src/M000031.html +0 -86
  119. data/doc/classes/Bio/DB/Sam.src/M000032.html +0 -34
  120. data/doc/classes/Bio/DB/Tag.html +0 -160
  121. data/doc/classes/Bio/DB/Tag.src/M000011.html +0 -21
  122. data/doc/classes/LibC.html +0 -105
  123. data/doc/classes/Pileup.html +0 -374
  124. data/doc/classes/Pileup.src/M000001.html +0 -34
  125. data/doc/classes/Pileup.src/M000002.html +0 -21
  126. data/doc/classes/Pileup.src/M000003.html +0 -21
  127. data/doc/classes/Pileup.src/M000004.html +0 -21
  128. data/doc/classes/Pileup.src/M000005.html +0 -31
  129. data/doc/files/lib/bio-samtools_rb.html +0 -109
  130. data/doc/files/lib/bio/db/sam/bam_rb.html +0 -108
  131. data/doc/files/lib/bio/db/sam/faidx_rb.html +0 -108
  132. data/doc/files/lib/bio/db/sam/library_rb.html +0 -101
  133. data/doc/files/lib/bio/db/sam/pileup_rb.html +0 -178
  134. data/doc/files/lib/bio/db/sam/sam_rb.html +0 -113
  135. data/doc/files/lib/bio/db/sam_rb.html +0 -111
  136. data/doc/fr_class_index.html +0 -43
  137. data/doc/fr_file_index.html +0 -33
  138. data/doc/fr_method_index.html +0 -58
  139. data/doc/lib/bio-samtools_rb.html +0 -115
  140. data/doc/lib/bio/db/pileup_rb.html +0 -171
  141. data/doc/lib/bio/db/sam/bam_rb.html +0 -121
  142. data/doc/lib/bio/db/sam/faidx_rb.html +0 -117
  143. data/doc/lib/bio/db/sam/library_rb.html +0 -115
  144. data/doc/lib/bio/db/sam/pileup_rb.html +0 -171
  145. data/doc/lib/bio/db/sam/sam_rb.html +0 -121
  146. data/doc/lib/bio/db/sam/vcf_rb.html +0 -124
  147. data/doc/lib/bio/db/sam_rb.html +0 -115
  148. data/doc/lib/bio/db/vcf_rb.html +0 -124
  149. data/doc/rdoc-style.css +0 -208
  150. data/lib/bio/db/sam/bam.rb +0 -210
  151. data/lib/bio/db/sam/sam.rb +0 -86
  152. data/test/samples/pipe_char/test.bam +0 -0
  153. data/test/samples/pipe_char/test.bam.bai +0 -0
  154. data/test/samples/pipe_char/test.tam +0 -10
  155. data/test/samples/pipe_char/test_chr.fasta +0 -1000
  156. data/test/samples/pipe_char/test_chr.fasta.fai +0 -1
  157. data/test/samples/small/test +0 -0
  158. data/test/samples/small/test.bam +0 -0
  159. data/test/samples/small/test.fa +0 -20
  160. data/test/samples/small/test.fai +0 -0
@@ -0,0 +1,84 @@
1
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
2
+ $: << File.expand_path('.')
3
+ require 'rubygems'
4
+ require 'bio/db/pileup'
5
+ require "test/unit"
6
+ gem 'test-unit'
7
+
8
+
9
+ class TestPileup < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @pu = Bio::DB::Pileup.new("seq1 279 C 23 A..T,,.,.,...,,,.,..... ;75&<<<<<<<<<=<<<9<<:<<")
13
+ #a snp...
14
+ @pu2 = Bio::DB::Pileup.new("seq1 279 C 23 ATTT,,.,.TTTT,,,.,TTTTT ;75&<<<<<<<<<=<<<9<<:<<")
15
+ #an indel..
16
+ @pu3 = Bio::DB::Pileup.new("seq2 156 * +AG/+AG 71 252 99 11 +AG * 3 8 0")
17
+ end
18
+
19
+ def test_non_ref_count
20
+ assert_equal(2, @pu.non_ref_count)
21
+ end
22
+
23
+ def test_ref_count
24
+ assert_equal(21, @pu.ref_count)
25
+ end
26
+
27
+ def test_consensus
28
+ assert_equal('C', @pu.consensus)
29
+ assert_equal('T', @pu2.consensus)
30
+ end
31
+
32
+ def test_non_refs
33
+ assert_equal(1, @pu.non_refs[:T])
34
+ assert_equal(1, @pu.non_refs[:A])
35
+ assert_equal(0, @pu.non_refs[:G])
36
+ assert_equal(0, @pu.non_refs[:C])
37
+ end
38
+
39
+
40
+ def test_to_vcf
41
+ @vcf = Bio::DB::Vcf.new(@pu.to_vcf)
42
+ assert_equal('seq1', @vcf.chrom)
43
+ end
44
+
45
+
46
+ def test_indel_gt
47
+ indel = @pu3.send(:indel_gt)
48
+ assert_equal('IAG', indel[0])
49
+ assert_equal('1/1', indel[1])
50
+ end
51
+
52
+ def test_snp_gt
53
+ snp = @pu2.send(:snp_gt)
54
+ assert_equal('T,', snp[0])
55
+ assert_equal('1/2', snp[1])
56
+ end
57
+
58
+ def test_genotype_list
59
+ gt2 = @pu2.genotype_list
60
+ gt3 = @pu3.genotype_list
61
+ assert_equal('T,', gt2[0])
62
+ assert_equal('1/2', gt2[1])
63
+ assert_equal('IAG', gt3[0])
64
+ assert_equal('1/1', gt3[1])
65
+ end
66
+
67
+ def test_iupac_to_base
68
+ iupac = Bio::DB::Pileup.iupac_to_base('R')
69
+ iupac.each do |pu|
70
+ assert_send([['A' , 'G'], :member?, pu])
71
+ end
72
+ end
73
+
74
+ def test_parse_indel
75
+ assert_equal('IAG/+AG', @pu3.parse_indel(@pu3.consensus))
76
+ end
77
+
78
+ def test_to_s
79
+ #check whether there are the correct number of tabs in the string (number of columns -1)
80
+ assert_equal(12, @pu3.to_s.count("\t"))
81
+ assert_equal(5, @pu.to_s.count("\t"))
82
+ end
83
+
84
+ end
@@ -0,0 +1,331 @@
1
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
2
+ $: << File.expand_path('.')
3
+ require 'rubygems'
4
+ require 'bio/db/sam'
5
+ require "test/unit"
6
+ gem 'test-unit'
7
+
8
+
9
+ class TestBioDbSam < Test::Unit::TestCase
10
+
11
+ class << self
12
+ def shutdown
13
+ File.delete("test/samples/small/different_index.bam.bai")
14
+ File.delete("test/samples/small/dupes_rmdup.bam")
15
+ File.delete("test/samples/small/mates_fixed.bam")
16
+ File.delete("test/samples/small/reheader.bam")
17
+ File.delete("test/samples/small/test_chr.fasta.fai")
18
+ File.delete("test/samples/small/test_sorted.bam")
19
+ File.delete("test/samples/small/maps_merged.bam")
20
+ File.delete("test/samples/small/maps_cated.bam")
21
+ end
22
+ end
23
+
24
+
25
+ def setup
26
+ @test_folder = "test/samples/small"
27
+ @testTAMFile = @test_folder + "/test.tam"
28
+ @testBAMFile = @test_folder + "/testu.bam"
29
+ @testReference = @test_folder + "/test_chr.fasta"
30
+ @sam = Bio::DB::Sam.new(
31
+ :fasta => @testReference,
32
+ :bam => @testBAMFile
33
+ )
34
+ end
35
+
36
+
37
+
38
+ def test_new
39
+ assert_kind_of(Bio::DB::Sam, @sam)
40
+ end
41
+
42
+ def test_index
43
+ test_bai_file = @testBAMFile+".bai"
44
+ #test to see if the index file exists. If so, delete it
45
+ if File.exist?(test_bai_file) == true
46
+ puts "bam index exists....deleting..."
47
+ File.delete(test_bai_file)
48
+ end
49
+ #index the bam file
50
+ @sam.index()
51
+
52
+ #make sure the .bai file exists
53
+ assert_nothing_thrown do
54
+ File.open(test_bai_file, "r")
55
+ end
56
+ assert(File.size(test_bai_file) > 0, "From test_index: .bai file is empty")
57
+ #as above, but give the output a different name
58
+ test_bai_file = @test_folder+"/different_index.bam.bai"
59
+ @sam.index(:out_index=> test_bai_file)
60
+ assert_nothing_thrown do
61
+ File.open(test_bai_file, "r")
62
+ end
63
+ assert(File.size(test_bai_file) > 0, "From test_index: .bai file is empty")
64
+ end
65
+
66
+ def test_view
67
+ #how to get Bio::DB::Alignment objects ..
68
+ @sam.view() do |sam|
69
+ #test that all the objects are Bio::DB::Alignment objects and their reference is 'chr_1'
70
+ assert_equal(sam.class, Bio::DB::Alignment)
71
+ assert_equal(sam.rname, "chr_1")
72
+ end
73
+ end
74
+
75
+ def test_fetch
76
+ @sam.fetch("chr_1", 10,1000) do |sam|
77
+ #test that all the objects are Bio::DB::Alignment objects
78
+ assert_equal(sam.class, Bio::DB::Alignment)
79
+ assert_equal(sam.rname, "chr_1")
80
+ end
81
+ end
82
+
83
+ def test_fetch_with_function
84
+ #pass the assert to method
85
+ block = Proc.new {|a| assert_equal(a.class, Bio::DB::Alignment)}
86
+ @sam.fetch_with_function("chr_1", 10,1000, &block)
87
+ end
88
+
89
+ def test_chromosome_coverage
90
+ #the coverage should only be 1.0 or 2.0
91
+ cov = @sam.chromosome_coverage("chr_1", 33, 19)
92
+ cov.each do |pu|
93
+ assert_send([[1.0 , 2.0], :member?, pu])
94
+ end
95
+ end
96
+
97
+ def test_average_coverage
98
+ #there should be 10 positions with cov of 1.0 and 10 with cov of 2.0, so average of 1.5
99
+ test_bai_file = @testBAMFile+".bai"
100
+ if File.exist?(test_bai_file) == false
101
+ @sam.index()
102
+ end
103
+ avcov = @sam.average_coverage("chr_1", 33, 19)
104
+ assert_equal(avcov, 1.5)
105
+ File.delete(test_bai_file)
106
+ end
107
+
108
+ def test_faidx
109
+ @sam.faidx()
110
+ test_fai_file = @testReference+".fai"
111
+ #test that the .fai file exists
112
+ assert_nothing_thrown do
113
+ File.open(test_fai_file, "r")
114
+ end
115
+ #test that the file is not empty
116
+ assert(File.size(test_fai_file) > 0, "From test_faidx: .fai file is empty")
117
+ end
118
+
119
+ def test_index_stats
120
+ @sam.index_stats.each_pair do |seq, stat|
121
+ assert_send([['chr_1' , '*'], :member?, seq])
122
+ end
123
+ end
124
+
125
+ def test_fetch_reference
126
+ #this is the first 70 nucleotides of the test seqeunce
127
+ seq_expected = "CCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTA"
128
+ #fetch the first 70 nuclotides
129
+ seq_fetched = @sam.fetch_reference("chr_1", 1, 70, :as_bio => false)
130
+ #test they're the same
131
+ assert_equal(seq_fetched, seq_expected)
132
+ end
133
+
134
+ def test_sort
135
+ #sort the bam file
136
+ sortedsam = @test_folder + "/test_sorted.bam"
137
+ @sam.sort(:prefix=>@test_folder + "/test_sorted")
138
+ #create a new Bio::DB::Sam from the sorted bam
139
+ @sortsam = Bio::DB::Sam.new(
140
+ :fasta => @testReference,
141
+ :bam => sortedsam
142
+ )
143
+ pos = 0
144
+ #iterate over the sorted sam file and make sure that the it's sorted by checking the order of the start positions for each read.
145
+ @sortsam.view()do |sam|
146
+ assert(sam.pos > pos, "Not sorted by position")
147
+ pos = sam.pos
148
+ end
149
+ end
150
+
151
+ def test_reheader
152
+ sam_header = @test_folder + "/map_for_reheader.sam"
153
+ outfile = @test_folder + "/reheader.bam"
154
+
155
+ @sam.reheader(sam_header, :out=>outfile)
156
+ reheader_bam = Bio::DB::Sam.new(:fasta => @testReference, :bam => outfile)
157
+ #check that the reference is 'chr_2'
158
+ reheader_bam.view()do |sam|
159
+ assert_equal(sam.rname, "chr_2")
160
+ end
161
+ end
162
+
163
+ def test_calmd
164
+ no_md_sam = @test_folder + "/no_md.sam"
165
+ md = Bio::DB::Sam.new(:fasta => @testReference, :bam => no_md_sam)
166
+ block = Proc.new {|a| assert(a.tags.has_key?('MD'), "From test_calmd: couldn't find the MD tag")}
167
+ md.calmd(:S=>true, &block)
168
+
169
+ end
170
+
171
+ def test_mpileup
172
+ #create an mpileup
173
+ @sam.mpileup(:g => false) do |pileup|
174
+ #test that all the objects are Bio::DB::Pileup objects
175
+ assert_kind_of(Bio::DB::Pileup, pileup)
176
+ #test that the reference name is 'chr_1' for all objects
177
+ assert_equal(pileup.ref_name, 'chr_1')
178
+ end
179
+ #do the same for Vcf output
180
+ @sam.mpileup(:u => true) do |pileup|
181
+ assert_kind_of(Bio::DB::Vcf, pileup)
182
+ assert_equal(pileup.chrom, 'chr_1')
183
+ end
184
+ end
185
+
186
+ def test_mpileup_reg
187
+ #create an mpileup
188
+ reg = Bio::DB::Fasta::Region.new
189
+ reg.entry = "chr_1"
190
+ reg.start = 1
191
+ reg.end = 334
192
+
193
+ @sam.mpileup_cached(:r=>reg,:g => false, :min_cov => 1, :min_per =>0.2) do |pileup|
194
+ #test that all the objects are Bio::DB::Pileup objects
195
+ assert_kind_of(Bio::DB::Pileup, pileup)
196
+ #test that the reference name is 'chr_1' for all objects
197
+ #puts pileup
198
+ assert_equal(pileup.ref_name, 'chr_1')
199
+ end
200
+
201
+ region = @sam.cached_regions[reg.to_s]
202
+ #puts "cahced_region: #{region.inspect}"
203
+ puts "AVG COV: #{region.average_coverage}"
204
+ puts "Reference: #{region.reference}"
205
+ puts "Consensus: #{region.consensus}"
206
+ puts "called: #{region.called}"
207
+ #, :snps, :reference, :base_ratios, :consensus, :coverages
208
+ snps_tot = Bio::Sequence.snps_between(region.reference, region.consensus)
209
+ assert_equal(snps_tot, 5)
210
+ assert_equal(region.called, 213)
211
+ end
212
+
213
+ def test_mpileup_reg_05
214
+ #create an mpileup
215
+ reg = Bio::DB::Fasta::Region.new
216
+ reg.entry = "chr_1"
217
+ reg.start = 1
218
+ reg.end = 334
219
+ @sam.mpileup_cached(:r=>reg,:g => false, :min_cov => 1, :min_per =>0.4) do |pileup|
220
+ #test that all the objects are Bio::DB::Pileup objects
221
+ assert_kind_of(Bio::DB::Pileup, pileup)
222
+ #test that the reference name is 'chr_1' for all objects
223
+ #puts pileup
224
+ assert_equal(pileup.ref_name, 'chr_1')
225
+
226
+ end
227
+
228
+ region = @sam.cached_regions[reg.to_s]
229
+
230
+ #, :snps, :reference, :base_ratios, :consensus, :coverages
231
+ snps_tot = Bio::Sequence.snps_between(region.reference, region.consensus)
232
+ assert_equal(snps_tot, 1)
233
+ assert_equal(region.called, 213)
234
+ end
235
+
236
+ def test_depth
237
+ #the depth of coverage should be '1' at all given positions
238
+ @sam.depth(:r=>"chr_1:25-42") do |al|
239
+ assert_equal(al[2].to_i, 1)
240
+ end
241
+ end
242
+
243
+ def test_fixmate
244
+ mates_fixed_bam = @test_folder + "/mates_fixed.bam"
245
+ @sam.fix_mates(:out_bam=>mates_fixed_bam)
246
+ assert_nothing_thrown do
247
+ File.open(mates_fixed_bam, "r")
248
+ end
249
+ assert(File.size(mates_fixed_bam) > 0, "From test_fixmate: .bam file is empty")
250
+ end
251
+
252
+ def test_flagstats
253
+ #get the stats
254
+ stats = @sam.flag_stats()
255
+ #the number of reads mapped will be the first character on the first line.
256
+ no_reads_mapped = stats[0][0].to_i
257
+ #check that it's '9'
258
+ assert_equal(no_reads_mapped, 9)
259
+ end
260
+
261
+ def test_merge
262
+ bam1 = @test_folder + "/map_to_merge1.bam"
263
+ bam2 = @test_folder + "/map_to_merge2.bam"
264
+ bam_to_merge1 = Bio::DB::Sam.new(:fasta => @testReference, :bam => bam1)
265
+ bam_to_merge2 = Bio::DB::Sam.new(:fasta => @testReference, :bam => bam2)
266
+ bam_files = [bam_to_merge1, bam_to_merge2]
267
+
268
+ merged_bam_file = @test_folder + "/maps_merged.bam"
269
+
270
+ @sam.merge(:out=>merged_bam_file, :bams=>bam_files, :n=>true)
271
+ merged_bam = Bio::DB::Sam.new(:fasta => @testReference, :bam => merged_bam_file)
272
+ no_reads_mapped = 0;
273
+
274
+ merged_bam.view() do |al|
275
+ assert_kind_of(Bio::DB::Alignment, al)
276
+ no_reads_mapped+=1
277
+ end
278
+ assert_equal(no_reads_mapped, 10)
279
+ end
280
+
281
+ def test_cat
282
+ #same files used for merge, but we'll cat them instead
283
+ bam1 = @test_folder + "/map_to_merge1.bam"
284
+ bam2 = @test_folder + "/map_to_merge2.bam"
285
+
286
+ bam_files = [bam1, bam2]
287
+
288
+ cat_bam_file = @test_folder + "/maps_cated.bam"
289
+
290
+ @sam.merge(:out=>cat_bam_file, :bams=>bam_files)
291
+ cated_bam = Bio::DB::Sam.new(:fasta => @testReference, :bam => cat_bam_file)
292
+
293
+ no_reads_mapped = 0;
294
+ cated_bam.view() do |al|
295
+ assert_kind_of(Bio::DB::Alignment, al)
296
+ no_reads_mapped+=1
297
+ end
298
+ #there should be 10 reads in the cat'd maps
299
+ assert_equal(no_reads_mapped, 10)
300
+ end
301
+
302
+ def test_rmdup
303
+ #dupes contains 4 reads mapped once and one read mapped to the same place 268 times.
304
+ dupes = @test_folder + "/dupes.bam"
305
+ unduped = @test_folder + "/dupes_rmdup.bam"
306
+ bam_with_dupes = Bio::DB::Sam.new(:fasta => @testReference, :bam => dupes)
307
+ bam_with_dupes.remove_duplicates(:s=>true, :out=>unduped)
308
+
309
+ unduped_bam = Bio::DB::Sam.new(:fasta => @testReference, :bam => unduped)
310
+ #rmdup should remove 267 of the 268 reads mapping to the same place, so producing a bam file with 5 reads
311
+ readcount = 0
312
+ unduped_bam.view()do |sam|
313
+ readcount +=1
314
+ end
315
+ assert_equal(readcount, 5)
316
+ end
317
+
318
+ def test_targetcut
319
+ sorted_bam = @test_folder + "/sorted.bam"
320
+ cut = Bio::DB::Sam.new(:fasta => @testReference, :bam => sorted_bam)
321
+ assert_nothing_thrown do
322
+ cut.targetcut
323
+ end
324
+ end
325
+
326
+ def test_docs
327
+ #force an error (use 'samtool' instead of 'samtools')
328
+ output = Bio::DB::Sam.docs('samtool', 'tview')
329
+ assert_equal(output, "program must be 'samtools' or 'bcftools'")
330
+ end
331
+ end
@@ -3,6 +3,7 @@ $: << File.expand_path('.')
3
3
  require 'rubygems'
4
4
  require 'bio/db/vcf'
5
5
  require "test/unit"
6
+ gem 'test-unit'
6
7
 
7
8
 
8
9
  class TestVcf < Test::Unit::TestCase
@@ -65,4 +66,14 @@ class TestVcf < Test::Unit::TestCase
65
66
  "3"=>{"DP"=>"5", "GT"=>"1/1", "HQ"=>".,", "GQ"=>"43"}}, @vcf4.samples)
66
67
  end
67
68
 
69
+ def test_int_or_raw
70
+ assert_nothing_raised do
71
+ @vcf1.int_or_raw(1)
72
+ end
73
+ assert_raise do
74
+ @vcf1.int_or_raw(A)
75
+ end
76
+ end
77
+
78
+
68
79
  end
File without changes
File without changes
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.6.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Ramirez-Gonzalez
@@ -10,22 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-25 00:00:00.000000000 Z
13
+ date: 2014-04-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: ffi
16
+ name: bio-svgenes
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.4.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '0'
28
+ version: 0.4.1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bio
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -40,20 +40,6 @@ dependencies:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: 1.4.2
43
- - !ruby/object:Gem::Dependency
44
- name: systemu
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 2.5.2
50
- type: :runtime
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 2.5.2
57
43
  - !ruby/object:Gem::Dependency
58
44
  name: shoulda
59
45
  requirement: !ruby/object:Gem::Requirement
@@ -166,6 +152,20 @@ dependencies:
166
152
  - - ">="
167
153
  - !ruby/object:Gem::Version
168
154
  version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: test-unit
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
169
  description: "Binder of samtools for ruby, on the top of FFI. \n\n This project was
170
170
  born from the need to add support of BAM files to \n the gee_fu genome browser
171
171
  (http://github.com/danmaclean/gee_fu)."
@@ -192,80 +192,19 @@ files:
192
192
  - doc/Bio/DB/SAM.html
193
193
  - doc/Bio/DB/SAM/Library.html
194
194
  - doc/Bio/DB/SAM/Tools.html
195
- - doc/Bio/DB/SAM/Tools/Bam1CoreT.html
196
- - doc/Bio/DB/SAM/Tools/Bam1T.html
197
- - doc/Bio/DB/SAM/Tools/BamHeaderT.html
198
- - doc/Bio/DB/SAM/Tools/BamPileup1T.html
199
- - doc/Bio/DB/SAM/Tools/SamfileT.html
200
- - doc/Bio/DB/SAM/Tools/SamfileTX.html
201
- - doc/Bio/DB/SAMException.html
202
195
  - doc/Bio/DB/Tag.html
203
196
  - doc/Bio/DB/Vcf.html
204
197
  - doc/LICENSE_txt.html
205
- - doc/LibC.html
206
- - doc/Pileup.html
207
- - doc/Vcf.html
208
- - doc/basic_styles.css
209
- - doc/classes/Bio.html
210
- - doc/classes/Bio/DB.html
211
- - doc/classes/Bio/DB/Alignment.html
212
- - doc/classes/Bio/DB/Alignment.src/M000012.html
213
- - doc/classes/Bio/DB/Alignment.src/M000013.html
214
- - doc/classes/Bio/DB/Alignment.src/M000014.html
215
- - doc/classes/Bio/DB/Alignment.src/M000015.html
216
- - doc/classes/Bio/DB/SAM.html
217
- - doc/classes/Bio/DB/SAM/Library.html
218
- - doc/classes/Bio/DB/SAM/Library.src/M000006.html
219
- - doc/classes/Bio/DB/SAM/Tools.html
220
- - doc/classes/Bio/DB/SAM/Tools.src/M000007.html
221
- - doc/classes/Bio/DB/SAM/Tools/Bam1CoreT.html
222
- - doc/classes/Bio/DB/SAM/Tools/Bam1T.html
223
- - doc/classes/Bio/DB/SAM/Tools/Bam1T.src/M000010.html
224
- - doc/classes/Bio/DB/SAM/Tools/BamHeaderT.html
225
- - doc/classes/Bio/DB/SAM/Tools/BamHeaderT.src/M000008.html
226
- - doc/classes/Bio/DB/SAM/Tools/BamHeaderT.src/M000009.html
227
- - doc/classes/Bio/DB/SAM/Tools/BamPileup1T.html
228
- - doc/classes/Bio/DB/SAM/Tools/SamfileT.html
229
- - doc/classes/Bio/DB/SAM/Tools/SamfileTX.html
230
- - doc/classes/Bio/DB/SAMException.html
231
- - doc/classes/Bio/DB/SAMException.src/M000016.html
232
- - doc/classes/Bio/DB/Sam.src/M000017.html
233
- - doc/classes/Bio/DB/Sam.src/M000018.html
234
- - doc/classes/Bio/DB/Sam.src/M000019.html
235
- - doc/classes/Bio/DB/Sam.src/M000020.html
236
- - doc/classes/Bio/DB/Sam.src/M000021.html
237
- - doc/classes/Bio/DB/Sam.src/M000022.html
238
- - doc/classes/Bio/DB/Sam.src/M000023.html
239
- - doc/classes/Bio/DB/Sam.src/M000024.html
240
- - doc/classes/Bio/DB/Sam.src/M000025.html
241
- - doc/classes/Bio/DB/Sam.src/M000026.html
242
- - doc/classes/Bio/DB/Sam.src/M000027.html
243
- - doc/classes/Bio/DB/Sam.src/M000028.html
244
- - doc/classes/Bio/DB/Sam.src/M000029.html
245
- - doc/classes/Bio/DB/Sam.src/M000030.html
246
- - doc/classes/Bio/DB/Sam.src/M000031.html
247
- - doc/classes/Bio/DB/Sam.src/M000032.html
248
- - doc/classes/Bio/DB/Tag.html
249
- - doc/classes/Bio/DB/Tag.src/M000011.html
250
- - doc/classes/LibC.html
251
- - doc/classes/Pileup.html
252
- - doc/classes/Pileup.src/M000001.html
253
- - doc/classes/Pileup.src/M000002.html
254
- - doc/classes/Pileup.src/M000003.html
255
- - doc/classes/Pileup.src/M000004.html
256
- - doc/classes/Pileup.src/M000005.html
257
198
  - doc/created.rid
258
- - doc/files/lib/bio-samtools_rb.html
259
- - doc/files/lib/bio/db/sam/bam_rb.html
260
- - doc/files/lib/bio/db/sam/faidx_rb.html
261
- - doc/files/lib/bio/db/sam/library_rb.html
262
- - doc/files/lib/bio/db/sam/pileup_rb.html
263
- - doc/files/lib/bio/db/sam/sam_rb.html
264
- - doc/files/lib/bio/db/sam_rb.html
265
- - doc/fr_class_index.html
266
- - doc/fr_file_index.html
267
- - doc/fr_method_index.html
199
+ - doc/fonts.css
200
+ - doc/fonts/Lato-Light.ttf
201
+ - doc/fonts/Lato-LightItalic.ttf
202
+ - doc/fonts/Lato-Regular.ttf
203
+ - doc/fonts/Lato-RegularItalic.ttf
204
+ - doc/fonts/SourceCodePro-Bold.ttf
205
+ - doc/fonts/SourceCodePro-Regular.ttf
268
206
  - doc/images/add.png
207
+ - doc/images/arrow_up.png
269
208
  - doc/images/brick.png
270
209
  - doc/images/brick_link.png
271
210
  - doc/images/bug.png
@@ -296,64 +235,67 @@ files:
296
235
  - doc/js/search.js
297
236
  - doc/js/search_index.js
298
237
  - doc/js/searcher.js
299
- - doc/lib/bio-samtools_rb.html
300
- - doc/lib/bio/db/pileup_rb.html
301
- - doc/lib/bio/db/sam/bam_rb.html
302
- - doc/lib/bio/db/sam/faidx_rb.html
303
- - doc/lib/bio/db/sam/library_rb.html
304
- - doc/lib/bio/db/sam/pileup_rb.html
305
- - doc/lib/bio/db/sam/sam_rb.html
306
- - doc/lib/bio/db/sam/vcf_rb.html
307
- - doc/lib/bio/db/sam_rb.html
308
- - doc/lib/bio/db/vcf_rb.html
309
- - doc/rdoc-style.css
310
238
  - doc/rdoc.css
311
239
  - doc/table_of_contents.html
312
- - doc/tutorial.html
313
- - doc/tutorial.pdf
314
240
  - ext/Makefile-bioruby.patch
315
241
  - ext/Makefile-suse.patch
242
+ - ext/Rakefile
316
243
  - ext/mkrf_conf.rb
317
244
  - lib/bio-samtools.rb
318
245
  - lib/bio/.DS_Store
246
+ - lib/bio/BIOExtensions.rb
247
+ - lib/bio/db/alignment.rb
248
+ - lib/bio/db/fastadb.rb
319
249
  - lib/bio/db/pileup.rb
320
250
  - lib/bio/db/sam.rb
321
- - lib/bio/db/sam/bam.rb
322
251
  - lib/bio/db/sam/external/COPYING
323
252
  - lib/bio/db/sam/external/VERSION
324
- - lib/bio/db/sam/faidx.rb
253
+ - lib/bio/db/sam/faidx_old.rb
325
254
  - lib/bio/db/sam/library.rb
326
- - lib/bio/db/sam/sam.rb
327
255
  - lib/bio/db/vcf.rb
256
+ - test/.gitignore
328
257
  - test/helper.rb
329
- - test/samples/pipe_char/test.bam
330
- - test/samples/pipe_char/test.bam.bai
331
- - test/samples/pipe_char/test.tam
332
- - test/samples/pipe_char/test_chr.fasta
333
- - test/samples/pipe_char/test_chr.fasta.fai
258
+ - test/old_test_basic.rb
259
+ - test/samples/small/dupes.bam
260
+ - test/samples/small/dupes.sam
334
261
  - test/samples/small/ids2.txt
262
+ - test/samples/small/map_for_reheader.sam
263
+ - test/samples/small/map_to_merge1.bam
264
+ - test/samples/small/map_to_merge1.bam.bai
265
+ - test/samples/small/map_to_merge1.sam
266
+ - test/samples/small/map_to_merge2.bam
267
+ - test/samples/small/map_to_merge2.bam.bai
268
+ - test/samples/small/map_to_merge2.sam
269
+ - test/samples/small/no_md.sam
335
270
  - test/samples/small/sorted.bam
336
271
  - test/samples/small/sorted.bam.bai
337
- - test/samples/small/test
338
- - test/samples/small/test.bam
339
- - test/samples/small/test.fa
340
- - test/samples/small/test.fai
341
272
  - test/samples/small/test.sai
342
273
  - test/samples/small/test.tam
343
274
  - test/samples/small/test_chr.fasta
275
+ - test/samples/small/test_chr.fasta.1.bt2
276
+ - test/samples/small/test_chr.fasta.2.bt2
277
+ - test/samples/small/test_chr.fasta.3.bt2
278
+ - test/samples/small/test_chr.fasta.4.bt2
344
279
  - test/samples/small/test_chr.fasta.amb
345
280
  - test/samples/small/test_chr.fasta.ann
346
281
  - test/samples/small/test_chr.fasta.bwt
347
282
  - test/samples/small/test_chr.fasta.pac
348
283
  - test/samples/small/test_chr.fasta.rbwt
284
+ - test/samples/small/test_chr.fasta.rev.1.bt2
285
+ - test/samples/small/test_chr.fasta.rev.2.bt2
349
286
  - test/samples/small/test_chr.fasta.rpac
350
287
  - test/samples/small/test_chr.fasta.rsa
351
288
  - test/samples/small/test_chr.fasta.sa
289
+ - test/samples/small/test_cov.svg
352
290
  - test/samples/small/testu.bam
353
291
  - test/samples/small/testu.bam.bai
354
- - test/test_basic.rb
292
+ - test/svg
355
293
  - test/test_bio-samtools.rb
294
+ - test/test_pileup.rb
295
+ - test/test_sam.rb
356
296
  - test/test_vcf.rb
297
+ - tutorial/tutorial.html
298
+ - tutorial/tutorial.pdf
357
299
  homepage: http://github.com/helios/bioruby-samtools
358
300
  licenses:
359
301
  - MIT