bio-samtools 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/VERSION +1 -1
  2. data/bio-samtools.gemspec +60 -6
  3. data/doc/Bio.html +171 -0
  4. data/doc/Bio/DB.html +163 -0
  5. data/doc/Bio/DB/Alignment.html +780 -0
  6. data/doc/Bio/DB/SAM.html +1241 -0
  7. data/doc/Bio/DB/SAM/Library.html +217 -0
  8. data/doc/Bio/DB/SAM/Tools.html +331 -0
  9. data/doc/Bio/DB/SAM/Tools/Bam1CoreT.html +159 -0
  10. data/doc/Bio/DB/SAM/Tools/Bam1T.html +220 -0
  11. data/doc/Bio/DB/SAM/Tools/BamHeaderT.html +249 -0
  12. data/doc/Bio/DB/SAM/Tools/BamPileup1T.html +159 -0
  13. data/doc/Bio/DB/SAM/Tools/SamfileT.html +171 -0
  14. data/doc/Bio/DB/SAM/Tools/SamfileTX.html +159 -0
  15. data/doc/Bio/DB/SAMException.html +205 -0
  16. data/doc/Bio/DB/Tag.html +254 -0
  17. data/doc/LICENSE_txt.html +881 -0
  18. data/doc/LibC.html +153 -0
  19. data/doc/Pileup.html +571 -0
  20. data/doc/Vcf.html +473 -0
  21. data/doc/created.rid +10 -1
  22. data/doc/images/add.png +0 -0
  23. data/doc/images/brick.png +0 -0
  24. data/doc/images/brick_link.png +0 -0
  25. data/doc/images/bug.png +0 -0
  26. data/doc/images/bullet_black.png +0 -0
  27. data/doc/images/bullet_toggle_minus.png +0 -0
  28. data/doc/images/bullet_toggle_plus.png +0 -0
  29. data/doc/images/date.png +0 -0
  30. data/doc/images/delete.png +0 -0
  31. data/doc/images/find.png +0 -0
  32. data/doc/images/loadingAnimation.gif +0 -0
  33. data/doc/images/macFFBgHack.png +0 -0
  34. data/doc/images/package.png +0 -0
  35. data/doc/images/page_green.png +0 -0
  36. data/doc/images/page_white_text.png +0 -0
  37. data/doc/images/page_white_width.png +0 -0
  38. data/doc/images/plugin.png +0 -0
  39. data/doc/images/ruby.png +0 -0
  40. data/doc/images/tag_blue.png +0 -0
  41. data/doc/images/tag_green.png +0 -0
  42. data/doc/images/transparent.png +0 -0
  43. data/doc/images/wrench.png +0 -0
  44. data/doc/images/wrench_orange.png +0 -0
  45. data/doc/images/zoom.png +0 -0
  46. data/doc/index.html +109 -21
  47. data/doc/js/darkfish.js +153 -0
  48. data/doc/js/jquery.js +18 -0
  49. data/doc/js/navigation.js +142 -0
  50. data/doc/js/search.js +94 -0
  51. data/doc/js/search_index.js +1 -0
  52. data/doc/js/searcher.js +228 -0
  53. data/doc/lib/bio-samtools_rb.html +115 -0
  54. data/doc/lib/bio/db/sam/bam_rb.html +121 -0
  55. data/doc/lib/bio/db/sam/faidx_rb.html +117 -0
  56. data/doc/lib/bio/db/sam/library_rb.html +115 -0
  57. data/doc/lib/bio/db/sam/pileup_rb.html +171 -0
  58. data/doc/lib/bio/db/sam/sam_rb.html +121 -0
  59. data/doc/lib/bio/db/sam/vcf_rb.html +124 -0
  60. data/doc/lib/bio/db/sam_rb.html +115 -0
  61. data/doc/rdoc.css +543 -0
  62. data/doc/table_of_contents.html +186 -0
  63. data/ext/Makefile-bioruby.patch +1 -1
  64. data/ext/Rakefile +8 -1
  65. data/ext/mkrf_conf.rb +8 -1
  66. data/lib/bio/db/sam.rb +140 -27
  67. data/lib/bio/db/sam/vcf.rb +0 -1
  68. data/test/basictest.rb +4 -4
  69. data/test/test_basic.rb +50 -34
  70. metadata +79 -25
  71. data/test/coverage.rb +0 -26
  72. data/test/coverage_plot.rb +0 -28
  73. data/test/feature.rb +0 -0
  74. data/test/test_pileup.rb +0 -68
@@ -0,0 +1,186 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>Table of Contents</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body class="indexpage">
24
+ <h1>Table of Contents</h1>
25
+
26
+ <h2>Pages</h2>
27
+ <ul>
28
+ <li class="file">
29
+ <a href="LICENSE_txt.html">LICENSE</a>
30
+ </li>
31
+
32
+ </ul>
33
+
34
+ <h2 id="classes">Classes/Modules</h2>
35
+ <ul>
36
+ <li class="module">
37
+ <a href="Bio.html">Bio</a>
38
+ </li>
39
+ <li class="class">
40
+ <a href="Bio/DB.html">Bio::DB</a>
41
+ </li>
42
+ <li class="class">
43
+ <a href="Bio/DB/Alignment.html">Bio::DB::Alignment</a>
44
+ </li>
45
+ <li class="module">
46
+ <a href="Bio/DB/SAM.html">Bio::DB::SAM</a>
47
+ </li>
48
+ <li class="module">
49
+ <a href="Bio/DB/SAM/Library.html">Bio::DB::SAM::Library</a>
50
+ </li>
51
+ <li class="module">
52
+ <a href="Bio/DB/SAM/Tools.html">Bio::DB::SAM::Tools</a>
53
+ </li>
54
+ <li class="class">
55
+ <a href="Bio/DB/SAM/Tools/Bam1CoreT.html">Bio::DB::SAM::Tools::Bam1CoreT</a>
56
+ </li>
57
+ <li class="class">
58
+ <a href="Bio/DB/SAM/Tools/Bam1T.html">Bio::DB::SAM::Tools::Bam1T</a>
59
+ </li>
60
+ <li class="class">
61
+ <a href="Bio/DB/SAM/Tools/BamHeaderT.html">Bio::DB::SAM::Tools::BamHeaderT</a>
62
+ </li>
63
+ <li class="class">
64
+ <a href="Bio/DB/SAM/Tools/BamPileup1T.html">Bio::DB::SAM::Tools::BamPileup1T</a>
65
+ </li>
66
+ <li class="class">
67
+ <a href="Bio/DB/SAM/Tools/SamfileT.html">Bio::DB::SAM::Tools::SamfileT</a>
68
+ </li>
69
+ <li class="class">
70
+ <a href="Bio/DB/SAM/Tools/SamfileTX.html">Bio::DB::SAM::Tools::SamfileTX</a>
71
+ </li>
72
+ <li class="class">
73
+ <a href="Bio/DB/SAMException.html">Bio::DB::SAMException</a>
74
+ </li>
75
+ <li class="class">
76
+ <a href="Bio/DB/Sam.html">Bio::DB::Sam</a>
77
+ </li>
78
+ <li class="class">
79
+ <a href="Bio/DB/Tag.html">Bio::DB::Tag</a>
80
+ </li>
81
+ <li class="module">
82
+ <a href="LibC.html">LibC</a>
83
+ </li>
84
+ <li class="class">
85
+ <a href="Pileup.html">Pileup</a>
86
+
87
+ <img class="toc-toggle" src="images/transparent.png" alt="" title="toggle headings">
88
+ <ul class="initially-hidden">
89
+ <li><a href="Pileup.html#label-Pileup+">Pileup </a>
90
+ </ul>
91
+ </li>
92
+ <li class="class">
93
+ <a href="Vcf.html">Vcf</a>
94
+
95
+ <img class="toc-toggle" src="images/transparent.png" alt="" title="toggle headings">
96
+ <ul class="initially-hidden">
97
+ <li><a href="Vcf.html#label-Vcf+">Vcf </a>
98
+ </ul>
99
+ </li>
100
+
101
+ </ul>
102
+
103
+ <h2 id="methods">Methods</h2>
104
+ <ul>
105
+
106
+ <li class="method"><a href="Bio/DB/SAM/Tools.html#method-c-bam_sort">::bam_sort &mdash; Bio::DB::SAM::Tools</a>
107
+
108
+ <li class="method"><a href="Bio/DB/SAM/Library.html#method-c-filename">::filename &mdash; Bio::DB::SAM::Library</a>
109
+
110
+ <li class="method"><a href="Bio/DB/Sam.html#method-c-finalize">::finalize &mdash; Bio::DB::Sam</a>
111
+
112
+ <li class="method"><a href="Bio/DB/Alignment.html#method-c-finalize">::finalize &mdash; Bio::DB::Alignment</a>
113
+
114
+ <li class="method"><a href="Bio/DB/Sam.html#method-c-merge">::merge &mdash; Bio::DB::Sam</a>
115
+
116
+ <li class="method"><a href="Bio/DB/Alignment.html#method-c-new">::new &mdash; Bio::DB::Alignment</a>
117
+
118
+ <li class="method"><a href="Pileup.html#method-c-new">::new &mdash; Pileup</a>
119
+
120
+ <li class="method"><a href="Vcf.html#method-c-new">::new &mdash; Vcf</a>
121
+
122
+ <li class="method"><a href="Bio/DB/Sam.html#method-c-new">::new &mdash; Bio::DB::Sam</a>
123
+
124
+ <li class="method"><a href="Bio/DB/SAMException.html#method-c-new">::new &mdash; Bio::DB::SAMException</a>
125
+
126
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-average_coverage">#average_coverage &mdash; Bio::DB::Sam</a>
127
+
128
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-chromosome_coverage">#chromosome_coverage &mdash; Bio::DB::Sam</a>
129
+
130
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-close">#close &mdash; Bio::DB::Sam</a>
131
+
132
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-deprecated_pileup">#deprecated_pileup &mdash; Bio::DB::Sam</a>
133
+
134
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-fetch">#fetch &mdash; Bio::DB::Sam</a>
135
+
136
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-fetch_reference">#fetch_reference &mdash; Bio::DB::Sam</a>
137
+
138
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-fetch_with_function">#fetch_with_function &mdash; Bio::DB::Sam</a>
139
+
140
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-index_stats">#index_stats &mdash; Bio::DB::Sam</a>
141
+
142
+ <li class="method"><a href="Vcf.html#method-i-int_or_raw">#int_or_raw &mdash; Vcf</a>
143
+
144
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-load_index">#load_index &mdash; Bio::DB::Sam</a>
145
+
146
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-load_reference">#load_reference &mdash; Bio::DB::Sam</a>
147
+
148
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-mpileup">#mpileup &mdash; Bio::DB::Sam</a>
149
+
150
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-mpileup_plus">#mpileup_plus &mdash; Bio::DB::Sam</a>
151
+
152
+ <li class="method"><a href="Pileup.html#method-i-non_ref_count">#non_ref_count &mdash; Pileup</a>
153
+
154
+ <li class="method"><a href="Pileup.html#method-i-non_refs">#non_refs &mdash; Pileup</a>
155
+
156
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-open">#open &mdash; Bio::DB::Sam</a>
157
+
158
+ <li class="method"><a href="Vcf.html#method-i-parse_line">#parse_line &mdash; Vcf</a>
159
+
160
+ <li class="method"><a href="Bio/DB/SAM/Tools/Bam1T.html#method-i-qname">#qname &mdash; Bio::DB::SAM::Tools::Bam1T</a>
161
+
162
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-query_string">#query_string &mdash; Bio::DB::Sam</a>
163
+
164
+ <li class="method"><a href="Pileup.html#method-i-ref_count">#ref_count &mdash; Pileup</a>
165
+
166
+ <li class="method"><a href="Bio/DB/Alignment.html#method-i-sam-3D">#sam= &mdash; Bio::DB::Alignment</a>
167
+
168
+ <li class="method"><a href="Bio/DB/Alignment.html#method-i-set">#set &mdash; Bio::DB::Alignment</a>
169
+
170
+ <li class="method"><a href="Bio/DB/Tag.html#method-i-set">#set &mdash; Bio::DB::Tag</a>
171
+
172
+ <li class="method"><a href="Bio/DB/SAM/Tools/BamHeaderT.html#method-i-text">#text &mdash; Bio::DB::SAM::Tools::BamHeaderT</a>
173
+
174
+ <li class="method"><a href="Bio/DB/SAM/Tools/BamHeaderT.html#method-i-text-3D">#text= &mdash; Bio::DB::SAM::Tools::BamHeaderT</a>
175
+
176
+ <li class="method"><a href="Bio/DB/Sam.html#method-i-to_s">#to_s &mdash; Bio::DB::Sam</a>
177
+
178
+ </ul>
179
+
180
+
181
+ <footer id="validator-badges">
182
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
183
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
184
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
185
+ </footer>
186
+
@@ -3,7 +3,7 @@
3
3
  @@ -1,10 +1,11 @@
4
4
  CC= gcc
5
5
  -CFLAGS= -g -Wall -O2 #-m64 #-arch ppc
6
- +CFLAGS= -g -Wall -O2 -m64 #-arch ppc
6
+ +CFLAGS= -g -Wall -O2 -m64 -fPIC #-arch ppc
7
7
  DFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_USE_KNETFILE -D_CURSES_LIB=1
8
8
  KNETFILE_O= knetfile.o
9
9
  LOBJS= bgzf.o kstring.o bam_aux.o bam.o bam_import.o sam.o bam_index.o \
data/ext/Rakefile CHANGED
@@ -25,15 +25,22 @@ task :compile do
25
25
  cp("libbam.a","/Users/macleand/bioruby-samtools/ext/../lib/bio/db/sam/external")
26
26
  #sh "CFLAGS='-g -Wall -O2 -fPIC' make -e libbam.so.1-local"
27
27
  sh "make libbam.so.1-local"
28
+ cp("samtools", "/Users/macleand/bioruby-samtools/ext/../lib/bio/db/sam/external")
28
29
  cp("libbam.so.1","/Users/macleand/bioruby-samtools/ext/../lib/bio/db/sam/external")
29
30
  when /darwin/
30
31
  sh "make"
31
32
  cp("libbam.a","/Users/macleand/bioruby-samtools/ext/../lib/bio/db/sam/external")
32
33
  sh "make libbam.1.dylib-local"
33
- cp("libbam.1.dylib","/Users/macleand/bioruby-samtools/ext/../lib/bio/db/sam/external")
34
+ cp("libbam.1.dylib","/Users/macleand/bioruby-samtools/ext/../lib/bio/db/sam/external")
35
+ sh "make"
36
+ cp('samtools', "/Users/macleand/bioruby-samtools/ext/../lib/bio/db/sam/external")
34
37
  when /mswin|mingw/ then raise NotImplementedError, "BWA library is not available for Windows platform"
35
38
  end #case
36
39
  end #cd
40
+ cd("samtools-0.1.18/bcftools") do
41
+ sh "make"
42
+ cp('bcftools', "/Users/macleand/bioruby-samtools/ext/../lib/bio/db/sam/external")
43
+ end
37
44
  end
38
45
 
39
46
  task :clean do
data/ext/mkrf_conf.rb CHANGED
@@ -44,15 +44,22 @@ task :compile do
44
44
  cp("libbam.a","#{path_external}")
45
45
  #sh "CFLAGS='-g -Wall -O2 -fPIC' make -e libbam.so.1-local"
46
46
  sh "make libbam.so.1-local"
47
+ cp("samtools", "#{path_external}")
47
48
  cp("libbam.so.1","#{path_external}")
48
49
  when /darwin/
49
50
  sh "make"
50
51
  cp("libbam.a","#{path_external}")
51
52
  sh "make libbam.1.dylib-local"
52
- cp("libbam.1.dylib","#{path_external}")
53
+ cp("libbam.1.dylib","#{path_external}")
54
+ sh "make"
55
+ cp('samtools', "#{path_external}")
53
56
  when /mswin|mingw/ then raise NotImplementedError, "BWA library is not available for Windows platform"
54
57
  end #case
55
58
  end #cd
59
+ cd("samtools-#{Version}/bcftools") do
60
+ sh "make"
61
+ cp('bcftools', "#{path_external}")
62
+ end
56
63
  end
57
64
 
58
65
  task :clean do
data/lib/bio/db/sam.rb CHANGED
@@ -311,44 +311,157 @@ module Bio
311
311
  ##and also associated output options
312
312
  [:g, :u, :e, :h, :I, :L, :o, :p].each {|x| opts.delete(x) }
313
313
 
314
- strptrs = []
315
- strptrs << FFI::MemoryPointer.from_string("mpileup")
314
+ sam_opts = []
315
+ #strptrs << FFI::MemoryPointer.from_string("mpileup")
316
316
  opts.each do |k,v|
317
317
  next unless opts[k] ##dont bother unless the values provided are true..
318
318
  k = '6' if k == :six
319
319
  k = '-' + k.to_s
320
- strptrs << FFI::MemoryPointer.from_string(k)
321
- strptrs << FFI::MemoryPointer.from_string(v.to_s) unless ["-R", "-B", "-E", "-6", "-A"].include?(k) #these are just flags so don't pass a value...
320
+ sam_opts << k #strptrs << FFI::MemoryPointer.from_string(k)
321
+ sam_opts << v.to_s unless ["-R", "-B", "-E", "-6", "-A"].include?(k) #these are just flags so don't pass a value... strptrs << FFI::MemoryPointer.from_string(v.to_s)
322
322
  end
323
- strptrs << FFI::MemoryPointer.from_string('-f')
324
- strptrs << FFI::MemoryPointer.from_string(@fasta_path)
325
- strptrs << FFI::MemoryPointer.from_string(@sam)
326
- strptrs << nil
323
+ sam_opts = sam_opts + ['-f', @fasta_path, @sam]
324
+ sam_command = "#{File.join(File.expand_path(File.dirname(__FILE__)),'sam','external','samtools')} mpileup #{sam_opts.join(' ')} 2> /dev/null"
327
325
 
328
- # Now load all the pointers into a native memory block
329
- argv = FFI::MemoryPointer.new(:pointer, strptrs.length)
330
- strptrs.each_with_index do |p, i|
331
- argv[i].put_pointer(0, p)
326
+ sam_pipe = IO.popen(sam_command)
327
+ while line = sam_pipe.gets
328
+ yield Pileup.new(line)
332
329
  end
330
+ sam_pipe.close
331
+ #strptrs << FFI::MemoryPointer.from_string('-f')
332
+ #strptrs << FFI::MemoryPointer.from_string(@fasta_path)
333
+ #strptrs << FFI::MemoryPointer.from_string(@sam)
334
+ #strptrs << nil
333
335
 
334
- old_stdout = STDOUT.clone
335
- read_pipe, write_pipe = IO.pipe()
336
- STDOUT.reopen(write_pipe)
336
+ # Now load all the pointers into a native memory block
337
+ #argv = FFI::MemoryPointer.new(:pointer, strptrs.length)
338
+ #strptrs.each_with_index do |p, i|
339
+ # argv[i].put_pointer(0, p)
340
+ #end
341
+
342
+ #old_stdout = STDOUT.clone
343
+ #read_pipe, write_pipe = IO.pipe()
344
+ #STDOUT.reopen(write_pipe)
337
345
  #int bam_mpileup(int argc, char *argv[])
338
- Bio::DB::SAM::Tools.bam_mpileup(strptrs.length - 1,argv)
339
- if fork
340
- write_pipe.close
341
- STDOUT.reopen(old_stdout) #beware .. stdout from other processes eg tests calling this method can get mixed in...
342
- begin
343
- while line = read_pipe.readline
344
- yield Pileup.new(line)
346
+ # Bio::DB::SAM::Tools.bam_mpileup(strptrs.length - 1,argv)
347
+ #if fork
348
+ # write_pipe.close
349
+ # STDOUT.reopen(old_stdout) #beware .. stdout from other processes eg tests calling this method can get mixed in...
350
+ # begin
351
+ # while line = read_pipe.readline
352
+ # yield Pileup.new(line)
353
+ # end
354
+ # rescue EOFError
355
+ # read_pipe.close
356
+ # Process.wait
357
+ # end
358
+ #end
359
+ end
360
+
361
+ #experimental method that spawns a samtools mpileup | bcftools view process and supports returning of pileup vcf
362
+ ##otherwise works like mpileup
363
+ def mpileup_plus( opts )
364
+
365
+ raise SAMException.new(), "No BAMFile provided" unless @sam and @binary
366
+ raise SAMException.new(), "No FastA provided" unless @fasta_path
367
+ #long option form to short samtools form..
368
+ long_opts = {
369
+ :region => :r,
370
+ :illumina_quals => :six,
371
+ :count_anomalous => :A,
372
+ :no_baq => :B,
373
+ :adjust_mapq => :C,
374
+ :max_per_bam_depth => :d,
375
+ :extended_baq => :E,
376
+ :exclude_reads_file => :G,
377
+ :list_of_positions => :l,
378
+ :mapping_quality_cap => :M,
379
+ :ignore_rg => :R,
380
+ :min_mapping_quality => :q,
381
+ :min_base_quality => :Q,
382
+ ###following options are for the -g -u option
383
+ :genotype_calling => :g,
384
+ :uncompressed_bcf => :u,
385
+ :extension_sequencing_probability => :e,
386
+ :homopolymer_error_coefficient => :h,
387
+ :no_indels => :I,
388
+ :skip_indel_over_average_depth => :L,
389
+ :gap_open_sequencing_error_probability => :o,
390
+ :platforms => :P
391
+ }
392
+
393
+ ##convert any long_opts to short opts
394
+ opts.each_pair do |k,v|
395
+ if long_opts[k]
396
+ opts[long_opts[k]] = v
397
+ opts.delete(k)
398
+ end
399
+ end
400
+
401
+ ##remove any calls to -g or -u for mpileup, bcf output is not yet supported
402
+ ##and also associated output options
403
+ #[:g, :u, :e, :h, :I, :L, :o, :p].each {|x| opts.delete(x) }
404
+ opts[:u] = true if opts[:g] #so that we always get uncompressed output
405
+ opts.delete(:g)
406
+
407
+ sam_opts = []
408
+ #strptrs << FFI::MemoryPointer.from_string("mpileup")
409
+ opts.each do |k,v|
410
+ next unless opts[k] ##dont bother unless the values provided are true..
411
+ k = '6' if k == :six
412
+ k = '-' + k.to_s
413
+ sam_opts << k #strptrs << FFI::MemoryPointer.from_string(k)
414
+ sam_opts << v.to_s unless ["-R", "-B", "-E", "-6", "-A", "-g", "-u", "-I"].include?(k) #these are just flags so don't pass a value... strptrs << FFI::MemoryPointer.from_string(v.to_s)
345
415
  end
346
- rescue EOFError
347
- read_pipe.close
348
- Process.wait
416
+ sam_opts = sam_opts + ['-f', @fasta_path, @sam]
417
+
418
+ command = "#{File.join(File.expand_path(File.dirname(__FILE__)),'sam','external','samtools')} mpileup #{sam_opts.join(' ')} 2> /dev/null"
419
+ if opts[:u]
420
+ command = command + " | #{File.join(File.expand_path(File.dirname(__FILE__)),'sam','external','bcftools')} view -cg -"
421
+ end
422
+ pipe = IO.popen(command)
423
+ $stderr.puts command
424
+ if opts[:u]
425
+ while line = pipe.gets
426
+ next if line[0,1] == '#' #skip any header or meta-lines, we dont do anything with those
427
+ yield Vcf.new(line)
428
+ end
429
+ else
430
+ while line = pipe.gets
431
+ yield Pileup.new(line)
432
+ end
433
+ end
434
+ pipe.close
435
+ #strptrs << FFI::MemoryPointer.from_string('-f')
436
+ #strptrs << FFI::MemoryPointer.from_string(@fasta_path)
437
+ #strptrs << FFI::MemoryPointer.from_string(@sam)
438
+ #strptrs << nil
439
+
440
+ # Now load all the pointers into a native memory block
441
+ #argv = FFI::MemoryPointer.new(:pointer, strptrs.length)
442
+ #strptrs.each_with_index do |p, i|
443
+ # argv[i].put_pointer(0, p)
444
+ #end
445
+
446
+ #old_stdout = STDOUT.clone
447
+ #read_pipe, write_pipe = IO.pipe()
448
+ #STDOUT.reopen(write_pipe)
449
+ #int bam_mpileup(int argc, char *argv[])
450
+ # Bio::DB::SAM::Tools.bam_mpileup(strptrs.length - 1,argv)
451
+ #if fork
452
+ # write_pipe.close
453
+ # STDOUT.reopen(old_stdout) #beware .. stdout from other processes eg tests calling this method can get mixed in...
454
+ # begin
455
+ # while line = read_pipe.readline
456
+ # yield Pileup.new(line)
457
+ # end
458
+ # rescue EOFError
459
+ # read_pipe.close
460
+ # Process.wait
461
+ # end
462
+ #end
349
463
  end
350
- end
351
- end
464
+
352
465
 
353
466
  # utility method that does not use the samtools API, it calls samtools directly as if on the command line and catches the output,
354
467
  # to use this method you must have a version of samtools that supports the pileup command (< 0.1.17)
@@ -11,7 +11,6 @@ public
11
11
 
12
12
  #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
13
13
  def initialize(line=nil, sample_names=nil)
14
- next if line[0,1] == '#' #skip any header or meta-lines... inadvertantly passed..
15
14
  @info = {}
16
15
  @samples = {}
17
16
  parse_line(line, sample_names) if line != nil
data/test/basictest.rb CHANGED
@@ -29,7 +29,7 @@ class TestBioDbSam < Test::Unit::TestCase
29
29
  rescue
30
30
  end
31
31
  end
32
-
32
+ =begi
33
33
  def default_test
34
34
  puts $LOAD_PATH
35
35
  assert(true, "Unit test test")
@@ -165,7 +165,7 @@ class TestBioDbSam < Test::Unit::TestCase
165
165
  assert(true, "Seems it ran the query")
166
166
  #node_7263 238 60 has 550+, query from 0 to 500, something shall come....
167
167
  end
168
-
168
+ =end
169
169
  def test_read_invalid_reference
170
170
  sam = Bio::DB::Sam.new({:bam=>@testBAMFile})
171
171
  sam.open
@@ -281,11 +281,11 @@ class TestBioDbSam < Test::Unit::TestCase
281
281
  def test_pileup
282
282
  sam = Bio::DB::Sam.new(:fasta=>@testReference, :bam=>@testBAMFile )
283
283
  pileup_list = []
284
- sam.mpileup(:region => "chr_1:100-110") do |pile|
284
+ sam.mpileup(:region => "chr_1:100-1100") do |pile|
285
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
286
  pileup_list << pile
287
287
  end
288
- assert_equal(10,pileup_list.length)
288
+ assert_equal(1000,pileup_list.length)
289
289
  pileup_list.each do |p|
290
290
  assert_kind_of(Pileup, p)
291
291
  end