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.
- data/VERSION +1 -1
- data/bio-samtools.gemspec +60 -6
- data/doc/Bio.html +171 -0
- data/doc/Bio/DB.html +163 -0
- data/doc/Bio/DB/Alignment.html +780 -0
- data/doc/Bio/DB/SAM.html +1241 -0
- data/doc/Bio/DB/SAM/Library.html +217 -0
- data/doc/Bio/DB/SAM/Tools.html +331 -0
- data/doc/Bio/DB/SAM/Tools/Bam1CoreT.html +159 -0
- data/doc/Bio/DB/SAM/Tools/Bam1T.html +220 -0
- data/doc/Bio/DB/SAM/Tools/BamHeaderT.html +249 -0
- data/doc/Bio/DB/SAM/Tools/BamPileup1T.html +159 -0
- data/doc/Bio/DB/SAM/Tools/SamfileT.html +171 -0
- data/doc/Bio/DB/SAM/Tools/SamfileTX.html +159 -0
- data/doc/Bio/DB/SAMException.html +205 -0
- data/doc/Bio/DB/Tag.html +254 -0
- data/doc/LICENSE_txt.html +881 -0
- data/doc/LibC.html +153 -0
- data/doc/Pileup.html +571 -0
- data/doc/Vcf.html +473 -0
- data/doc/created.rid +10 -1
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +109 -21
- data/doc/js/darkfish.js +153 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/lib/bio-samtools_rb.html +115 -0
- data/doc/lib/bio/db/sam/bam_rb.html +121 -0
- data/doc/lib/bio/db/sam/faidx_rb.html +117 -0
- data/doc/lib/bio/db/sam/library_rb.html +115 -0
- data/doc/lib/bio/db/sam/pileup_rb.html +171 -0
- data/doc/lib/bio/db/sam/sam_rb.html +121 -0
- data/doc/lib/bio/db/sam/vcf_rb.html +124 -0
- data/doc/lib/bio/db/sam_rb.html +115 -0
- data/doc/rdoc.css +543 -0
- data/doc/table_of_contents.html +186 -0
- data/ext/Makefile-bioruby.patch +1 -1
- data/ext/Rakefile +8 -1
- data/ext/mkrf_conf.rb +8 -1
- data/lib/bio/db/sam.rb +140 -27
- data/lib/bio/db/sam/vcf.rb +0 -1
- data/test/basictest.rb +4 -4
- data/test/test_basic.rb +50 -34
- metadata +79 -25
- data/test/coverage.rb +0 -26
- data/test/coverage_plot.rb +0 -28
- data/test/feature.rb +0 -0
- data/test/test_pileup.rb +0 -68
data/doc/Bio/DB/SAM.html
ADDED
@@ -0,0 +1,1241 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
6
|
+
|
7
|
+
<title>Class: Bio::DB::Sam</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 id="top" class="class">
|
24
|
+
<nav id="metadata">
|
25
|
+
<nav id="home-section" class="section">
|
26
|
+
<h3 class="section-header">
|
27
|
+
<a href="../../index.html">Home</a>
|
28
|
+
<a href="../../table_of_contents.html#classes">Classes</a>
|
29
|
+
<a href="../../table_of_contents.html#methods">Methods</a>
|
30
|
+
</h3>
|
31
|
+
</nav>
|
32
|
+
|
33
|
+
|
34
|
+
<nav id="search-section" class="section project-section" class="initially-hidden">
|
35
|
+
<form action="#" method="get" accept-charset="utf-8">
|
36
|
+
<h3 class="section-header">
|
37
|
+
<input type="text" name="search" placeholder="Search" id="search-field"
|
38
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
39
|
+
</h3>
|
40
|
+
</form>
|
41
|
+
|
42
|
+
<ul id="search-results" class="initially-hidden"></ul>
|
43
|
+
</nav>
|
44
|
+
|
45
|
+
|
46
|
+
<div id="file-metadata">
|
47
|
+
<nav id="file-list-section" class="section">
|
48
|
+
<h3 class="section-header">Defined In</h3>
|
49
|
+
<ul>
|
50
|
+
<li>lib/bio/db/sam.rb
|
51
|
+
</ul>
|
52
|
+
</nav>
|
53
|
+
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div id="class-metadata">
|
58
|
+
|
59
|
+
<nav id="parent-class-section" class="section">
|
60
|
+
<h3 class="section-header">Parent</h3>
|
61
|
+
|
62
|
+
<p class="link">Object
|
63
|
+
|
64
|
+
</nav>
|
65
|
+
|
66
|
+
|
67
|
+
<!-- Method Quickref -->
|
68
|
+
<nav id="method-list-section" class="section">
|
69
|
+
<h3 class="section-header">Methods</h3>
|
70
|
+
|
71
|
+
<ul class="link-list">
|
72
|
+
|
73
|
+
<li><a href="#method-c-finalize">::finalize</a>
|
74
|
+
|
75
|
+
<li><a href="#method-c-merge">::merge</a>
|
76
|
+
|
77
|
+
<li><a href="#method-c-new">::new</a>
|
78
|
+
|
79
|
+
<li><a href="#method-i-average_coverage">#average_coverage</a>
|
80
|
+
|
81
|
+
<li><a href="#method-i-chromosome_coverage">#chromosome_coverage</a>
|
82
|
+
|
83
|
+
<li><a href="#method-i-close">#close</a>
|
84
|
+
|
85
|
+
<li><a href="#method-i-deprecated_pileup">#deprecated_pileup</a>
|
86
|
+
|
87
|
+
<li><a href="#method-i-fetch">#fetch</a>
|
88
|
+
|
89
|
+
<li><a href="#method-i-fetch_reference">#fetch_reference</a>
|
90
|
+
|
91
|
+
<li><a href="#method-i-fetch_with_function">#fetch_with_function</a>
|
92
|
+
|
93
|
+
<li><a href="#method-i-index_stats">#index_stats</a>
|
94
|
+
|
95
|
+
<li><a href="#method-i-load_index">#load_index</a>
|
96
|
+
|
97
|
+
<li><a href="#method-i-load_reference">#load_reference</a>
|
98
|
+
|
99
|
+
<li><a href="#method-i-mpileup">#mpileup</a>
|
100
|
+
|
101
|
+
<li><a href="#method-i-mpileup_plus">#mpileup_plus</a>
|
102
|
+
|
103
|
+
<li><a href="#method-i-open">#open</a>
|
104
|
+
|
105
|
+
<li><a href="#method-i-query_string">#query_string</a>
|
106
|
+
|
107
|
+
<li><a href="#method-i-to_s">#to_s</a>
|
108
|
+
|
109
|
+
</ul>
|
110
|
+
</nav>
|
111
|
+
|
112
|
+
</div>
|
113
|
+
|
114
|
+
<div id="project-metadata">
|
115
|
+
<nav id="fileindex-section" class="section project-section">
|
116
|
+
<h3 class="section-header">Pages</h3>
|
117
|
+
|
118
|
+
<ul>
|
119
|
+
|
120
|
+
<li class="file"><a href="../../LICENSE_txt.html">LICENSE</a>
|
121
|
+
|
122
|
+
</ul>
|
123
|
+
</nav>
|
124
|
+
|
125
|
+
<nav id="classindex-section" class="section project-section">
|
126
|
+
<h3 class="section-header">Class and Module Index</h3>
|
127
|
+
|
128
|
+
<ul class="link-list">
|
129
|
+
|
130
|
+
<li><a href="../../Bio.html">Bio</a>
|
131
|
+
|
132
|
+
<li><a href="../../Bio/DB.html">Bio::DB</a>
|
133
|
+
|
134
|
+
<li><a href="../../Bio/DB/Alignment.html">Bio::DB::Alignment</a>
|
135
|
+
|
136
|
+
<li><a href="../../Bio/DB/SAM.html">Bio::DB::SAM</a>
|
137
|
+
|
138
|
+
<li><a href="../../Bio/DB/SAM/Library.html">Bio::DB::SAM::Library</a>
|
139
|
+
|
140
|
+
<li><a href="../../Bio/DB/SAM/Tools.html">Bio::DB::SAM::Tools</a>
|
141
|
+
|
142
|
+
<li><a href="../../Bio/DB/SAM/Tools/Bam1CoreT.html">Bio::DB::SAM::Tools::Bam1CoreT</a>
|
143
|
+
|
144
|
+
<li><a href="../../Bio/DB/SAM/Tools/Bam1T.html">Bio::DB::SAM::Tools::Bam1T</a>
|
145
|
+
|
146
|
+
<li><a href="../../Bio/DB/SAM/Tools/BamHeaderT.html">Bio::DB::SAM::Tools::BamHeaderT</a>
|
147
|
+
|
148
|
+
<li><a href="../../Bio/DB/SAM/Tools/BamPileup1T.html">Bio::DB::SAM::Tools::BamPileup1T</a>
|
149
|
+
|
150
|
+
<li><a href="../../Bio/DB/SAM/Tools/SamfileT.html">Bio::DB::SAM::Tools::SamfileT</a>
|
151
|
+
|
152
|
+
<li><a href="../../Bio/DB/SAM/Tools/SamfileTX.html">Bio::DB::SAM::Tools::SamfileTX</a>
|
153
|
+
|
154
|
+
<li><a href="../../Bio/DB/SAMException.html">Bio::DB::SAMException</a>
|
155
|
+
|
156
|
+
<li><a href="../../Bio/DB/Sam.html">Bio::DB::Sam</a>
|
157
|
+
|
158
|
+
<li><a href="../../Bio/DB/Tag.html">Bio::DB::Tag</a>
|
159
|
+
|
160
|
+
<li><a href="../../LibC.html">LibC</a>
|
161
|
+
|
162
|
+
<li><a href="../../Pileup.html">Pileup</a>
|
163
|
+
|
164
|
+
<li><a href="../../Vcf.html">Vcf</a>
|
165
|
+
|
166
|
+
</ul>
|
167
|
+
</nav>
|
168
|
+
|
169
|
+
</div>
|
170
|
+
</nav>
|
171
|
+
|
172
|
+
<div id="documentation">
|
173
|
+
<h1 class="class">class Bio::DB::Sam</h1>
|
174
|
+
|
175
|
+
<div id="description" class="description">
|
176
|
+
|
177
|
+
</div><!-- description -->
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
<!-- Attributes -->
|
191
|
+
<section id="attribute-method-details" class="method-section section">
|
192
|
+
<h3 class="section-header">Attributes</h3>
|
193
|
+
|
194
|
+
|
195
|
+
<div id="attribute-i-sam_file" class="method-detail">
|
196
|
+
<div class="method-heading attribute-method-heading">
|
197
|
+
<span class="method-name">sam_file</span><span
|
198
|
+
class="attribute-access-type">[R]</span>
|
199
|
+
</div>
|
200
|
+
|
201
|
+
<div class="method-description">
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
</div>
|
206
|
+
</div>
|
207
|
+
|
208
|
+
</section><!-- attribute-method-details -->
|
209
|
+
|
210
|
+
|
211
|
+
<!-- Methods -->
|
212
|
+
|
213
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section section">
|
214
|
+
<h3 class="section-header">Public Class Methods</h3>
|
215
|
+
|
216
|
+
|
217
|
+
<div id="method-c-finalize" class="method-detail ">
|
218
|
+
|
219
|
+
<div class="method-heading">
|
220
|
+
<span class="method-name">finalize</span><span
|
221
|
+
class="method-args">(id)</span>
|
222
|
+
<span class="method-click-advice">click to toggle source</span>
|
223
|
+
</div>
|
224
|
+
|
225
|
+
|
226
|
+
<div class="method-description">
|
227
|
+
|
228
|
+
<p>Destructor method that closes the file before letting the object be garbage
|
229
|
+
collected.</p>
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
<div class="method-source-code" id="finalize-source">
|
234
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 104</span>
|
235
|
+
<span class="ruby-keyword">def</span> <span class="ruby-constant">Sam</span>.<span class="ruby-identifier">finalize</span>(<span class="ruby-identifier">id</span>)
|
236
|
+
<span class="ruby-identifier">id</span>.<span class="ruby-identifier">close</span>()
|
237
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-node">"Finalizing #{id} at #{Time.new}"</span>
|
238
|
+
<span class="ruby-keyword">end</span></pre>
|
239
|
+
</div><!-- finalize-source -->
|
240
|
+
|
241
|
+
</div>
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
</div><!-- finalize-method -->
|
247
|
+
|
248
|
+
|
249
|
+
<div id="method-c-merge" class="method-detail ">
|
250
|
+
|
251
|
+
<div class="method-heading">
|
252
|
+
<span class="method-name">merge</span><span
|
253
|
+
class="method-args">(files, merged_file, headers, add_RG, by_qname)</span>
|
254
|
+
<span class="method-click-advice">click to toggle source</span>
|
255
|
+
</div>
|
256
|
+
|
257
|
+
|
258
|
+
<div class="method-description">
|
259
|
+
|
260
|
+
<p>Merges n BAM files. This doesn’t require to create a <a
|
261
|
+
href="SAM.html">SAM</a> object</p>
|
262
|
+
<dl class="rdoc-list note-list"><dt>files
|
263
|
+
<dd>
|
264
|
+
<p>An array with the paths to the files.</p>
|
265
|
+
</dd><dt>merged_file
|
266
|
+
<dd>
|
267
|
+
<p>The path to the merged file</p>
|
268
|
+
</dd><dt>headers
|
269
|
+
<dd>
|
270
|
+
<p>The BAM file containing the header</p>
|
271
|
+
</dd><dt>add_RG
|
272
|
+
<dd>
|
273
|
+
<p>If true, the RG tag is added (infered from the filenames)</p>
|
274
|
+
</dd><dt>by_qname
|
275
|
+
<dd>
|
276
|
+
<p>If true, the bamfiles should by ordered by query name, if false, by
|
277
|
+
coordinates.</p>
|
278
|
+
</dd></dl>
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
<div class="method-source-code" id="merge-source">
|
283
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 259</span>
|
284
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">files</span>, <span class="ruby-identifier">merged_file</span>, <span class="ruby-identifier">headers</span>, <span class="ruby-identifier">add_RG</span>, <span class="ruby-identifier">by_qname</span>)
|
285
|
+
<span class="ruby-identifier">strptrs</span> = []
|
286
|
+
<span class="ruby-identifier">strptrs</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">from_string</span>(<span class="ruby-string">"merge"</span>)
|
287
|
+
<span class="ruby-identifier">files</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
|
288
|
+
<span class="ruby-identifier">strptrs</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">from_string</span>(<span class="ruby-identifier">file</span>)
|
289
|
+
<span class="ruby-keyword">end</span>
|
290
|
+
<span class="ruby-identifier">strptrs</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword">nil</span>
|
291
|
+
|
292
|
+
<span class="ruby-comment"># Now load all the pointers into a native memory block</span>
|
293
|
+
<span class="ruby-identifier">argv</span> = <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:pointer</span>, <span class="ruby-identifier">strptrs</span>.<span class="ruby-identifier">length</span>)
|
294
|
+
<span class="ruby-identifier">strptrs</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
295
|
+
<span class="ruby-identifier">argv</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">put_pointer</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">p</span>)
|
296
|
+
<span class="ruby-keyword">end</span>
|
297
|
+
<span class="ruby-comment">#void bam_merge_core(int by_qname, const char *out, const char *headers, int n, char * const *fn, int add_RG)</span>
|
298
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">bam_merge_core</span>(<span class="ruby-identifier">by_qname</span>, <span class="ruby-identifier">merged_file</span>, <span class="ruby-identifier">headers</span>, <span class="ruby-identifier">strptrs</span>.<span class="ruby-identifier">length</span>, <span class="ruby-identifier">argv</span>, <span class="ruby-identifier">add_RG</span>)
|
299
|
+
<span class="ruby-keyword">end</span></pre>
|
300
|
+
</div><!-- merge-source -->
|
301
|
+
|
302
|
+
</div>
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
</div><!-- merge-method -->
|
308
|
+
|
309
|
+
|
310
|
+
<div id="method-c-new" class="method-detail ">
|
311
|
+
|
312
|
+
<div class="method-heading">
|
313
|
+
<span class="method-name">new</span><span
|
314
|
+
class="method-args">(optsa={})</span>
|
315
|
+
<span class="method-click-advice">click to toggle source</span>
|
316
|
+
</div>
|
317
|
+
|
318
|
+
|
319
|
+
<div class="method-description">
|
320
|
+
|
321
|
+
<p>To make a new sam object. Initialize expects a hash optsa with the
|
322
|
+
following elemets:</p>
|
323
|
+
<dl class="rdoc-list note-list"><dt>fasta
|
324
|
+
<dd>
|
325
|
+
<p>The fasta file with the reference. (nil)</p>
|
326
|
+
</dd><dt>bam
|
327
|
+
<dd>
|
328
|
+
<p>path to a binary <a href="SAM.html">SAM</a> file (nil)</p>
|
329
|
+
</dd><dt>tam
|
330
|
+
<dd>
|
331
|
+
<p>path to a text <a href="SAM.html">SAM</a> file (nil)</p>
|
332
|
+
</dd><dt>compressed
|
333
|
+
<dd>
|
334
|
+
<p>If the binary file is compressed (true)</p>
|
335
|
+
</dd><dt>write
|
336
|
+
<dd>
|
337
|
+
<p>If the file is to be writen (false). Not supported yet.</p>
|
338
|
+
</dd></dl>
|
339
|
+
|
340
|
+
<p><strong>NOTE:</strong> you can’t use binary and text formats
|
341
|
+
simultaneusly. To make queries, the file has to be a sorted binary. This
|
342
|
+
function doesn’t actually open the file, it just prepares the object to
|
343
|
+
be opened in a later stage.</p>
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
<div class="method-source-code" id="new-source">
|
348
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 29</span>
|
349
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">optsa</span>={})
|
350
|
+
<span class="ruby-identifier">opts</span> = { <span class="ruby-value">:fasta</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">:bam</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>,<span class="ruby-value">:tam</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">:compressed</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>, <span class="ruby-value">:write</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span> }.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">optsa</span>)
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
<span class="ruby-ivar">@fasta_path</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:fasta</span>]
|
355
|
+
<span class="ruby-ivar">@compressed</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:compressed</span>]
|
356
|
+
<span class="ruby-ivar">@write</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:write</span>]
|
357
|
+
<span class="ruby-identifier">bam</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:bam</span>]
|
358
|
+
<span class="ruby-identifier">tam</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:tam</span>]
|
359
|
+
|
360
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">bam</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">tam</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@fasta_path</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">then</span>
|
361
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No alignment or reference file"</span>
|
362
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">bam</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">tam</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">then</span>
|
363
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"Alignment has to be in either text or binary format, not both"</span>
|
364
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">bam</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">then</span>
|
365
|
+
<span class="ruby-ivar">@binary</span> = <span class="ruby-keyword">true</span>
|
366
|
+
<span class="ruby-ivar">@sam</span> = <span class="ruby-identifier">bam</span>
|
367
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">tam</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">then</span>
|
368
|
+
<span class="ruby-ivar">@sam</span> = <span class="ruby-identifier">tam</span>
|
369
|
+
<span class="ruby-ivar">@binary</span> = <span class="ruby-keyword">false</span>
|
370
|
+
|
371
|
+
<span class="ruby-keyword">end</span>
|
372
|
+
<span class="ruby-ivar">@fasta_file</span> = <span class="ruby-keyword">nil</span>
|
373
|
+
<span class="ruby-ivar">@sam_file</span> = <span class="ruby-keyword">nil</span>
|
374
|
+
|
375
|
+
<span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">define_finalizer</span>(<span class="ruby-keyword">self</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">method</span>(<span class="ruby-value">:finalize</span>).<span class="ruby-identifier">to_proc</span>)
|
376
|
+
<span class="ruby-keyword">end</span></pre>
|
377
|
+
</div><!-- new-source -->
|
378
|
+
|
379
|
+
</div>
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
</div><!-- new-method -->
|
385
|
+
|
386
|
+
|
387
|
+
</section><!-- public-class-method-details -->
|
388
|
+
|
389
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
|
390
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
391
|
+
|
392
|
+
|
393
|
+
<div id="method-i-average_coverage" class="method-detail ">
|
394
|
+
|
395
|
+
<div class="method-heading">
|
396
|
+
<span class="method-name">average_coverage</span><span
|
397
|
+
class="method-args">(chromosome, qstart, len)</span>
|
398
|
+
<span class="method-click-advice">click to toggle source</span>
|
399
|
+
</div>
|
400
|
+
|
401
|
+
|
402
|
+
<div class="method-description">
|
403
|
+
|
404
|
+
<p>Returns the average coverage of a region in a bam file.</p>
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
<div class="method-source-code" id="average_coverage-source">
|
409
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 143</span>
|
410
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">average_coverage</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>, <span class="ruby-identifier">len</span>)
|
411
|
+
|
412
|
+
<span class="ruby-comment">#reference = fetch_reference(chromosome, qstart,len)</span>
|
413
|
+
<span class="ruby-comment"># len = reference.length if len > reference.length</span>
|
414
|
+
|
415
|
+
|
416
|
+
<span class="ruby-identifier">coverages</span> = <span class="ruby-identifier">chromosome_coverage</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>, <span class="ruby-identifier">len</span>)
|
417
|
+
<span class="ruby-identifier">total</span> = <span class="ruby-value">0</span>
|
418
|
+
<span class="ruby-identifier">len</span>.<span class="ruby-identifier">times</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">total</span>= <span class="ruby-identifier">total</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">coverages</span>[<span class="ruby-identifier">i</span>] }
|
419
|
+
<span class="ruby-identifier">avg_cov</span> = <span class="ruby-identifier">total</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">len</span>
|
420
|
+
<span class="ruby-comment">#LibC.free reference</span>
|
421
|
+
<span class="ruby-identifier">avg_cov</span>
|
422
|
+
<span class="ruby-keyword">end</span></pre>
|
423
|
+
</div><!-- average_coverage-source -->
|
424
|
+
|
425
|
+
</div>
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
</div><!-- average_coverage-method -->
|
431
|
+
|
432
|
+
|
433
|
+
<div id="method-i-chromosome_coverage" class="method-detail ">
|
434
|
+
|
435
|
+
<div class="method-heading">
|
436
|
+
<span class="method-name">chromosome_coverage</span><span
|
437
|
+
class="method-args">(chromosome, qstart, len)</span>
|
438
|
+
<span class="method-click-advice">click to toggle source</span>
|
439
|
+
</div>
|
440
|
+
|
441
|
+
|
442
|
+
<div class="method-description">
|
443
|
+
|
444
|
+
<p>Returns an array with the coverage at each possition in the queried region
|
445
|
+
This is a simple average coverage just calculated with the first and last
|
446
|
+
possition of the alignment, ignoring the gaps.</p>
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
<div class="method-source-code" id="chromosome_coverage-source">
|
451
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 160</span>
|
452
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">chromosome_coverage</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>, <span class="ruby-identifier">len</span>)
|
453
|
+
<span class="ruby-comment"># reference = fetch_reference(chromosome, qstart,len)</span>
|
454
|
+
<span class="ruby-comment"># len = reference.length if len > reference.length</span>
|
455
|
+
<span class="ruby-comment">#p qend.to_s + "-" + qstart.to_s + "framesize " + (qend - qstart).to_s</span>
|
456
|
+
<span class="ruby-identifier">coverages</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">len</span>, <span class="ruby-value">0</span>)
|
457
|
+
|
458
|
+
<span class="ruby-identifier">chr_cov_proc</span> = <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">alignment</span><span class="ruby-operator">|</span>
|
459
|
+
<span class="ruby-comment">#last = qstart + len</span>
|
460
|
+
<span class="ruby-comment">#first = qstart</span>
|
461
|
+
<span class="ruby-comment">#last = alignment.calend if last > alignment.calend</span>
|
462
|
+
<span class="ruby-comment">#first = alignment.pos if first < alignment.pos</span>
|
463
|
+
<span class="ruby-comment"># p first</span>
|
464
|
+
<span class="ruby-identifier">last</span> = <span class="ruby-identifier">alignment</span>.<span class="ruby-identifier">calend</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">qstart</span>
|
465
|
+
<span class="ruby-identifier">first</span> = <span class="ruby-identifier">alignment</span>.<span class="ruby-identifier">pos</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">qstart</span>
|
466
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">last</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">first</span>
|
467
|
+
<span class="ruby-identifier">tmp</span> = <span class="ruby-identifier">last</span>
|
468
|
+
<span class="ruby-identifier">last</span> = <span class="ruby-identifier">first</span>
|
469
|
+
<span class="ruby-identifier">first</span> = <span class="ruby-identifier">last</span>
|
470
|
+
<span class="ruby-keyword">end</span>
|
471
|
+
|
472
|
+
<span class="ruby-comment"># STDERR.puts "#{first} #{last}\n"</span>
|
473
|
+
<span class="ruby-identifier">first</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">last</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
474
|
+
|
475
|
+
<span class="ruby-identifier">coverages</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>] = <span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">coverages</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-value">1</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">len</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
476
|
+
}
|
477
|
+
<span class="ruby-keyword">end</span>
|
478
|
+
|
479
|
+
<span class="ruby-identifier">fetch_with_function</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>, <span class="ruby-identifier">qstart</span><span class="ruby-operator">+</span><span class="ruby-identifier">len</span>, <span class="ruby-identifier">chr_cov_proc</span>)
|
480
|
+
<span class="ruby-comment">#p coverages</span>
|
481
|
+
<span class="ruby-identifier">coverages</span>
|
482
|
+
<span class="ruby-keyword">end</span></pre>
|
483
|
+
</div><!-- chromosome_coverage-source -->
|
484
|
+
|
485
|
+
</div>
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
</div><!-- chromosome_coverage-method -->
|
491
|
+
|
492
|
+
|
493
|
+
<div id="method-i-close" class="method-detail ">
|
494
|
+
|
495
|
+
<div class="method-heading">
|
496
|
+
<span class="method-name">close</span><span
|
497
|
+
class="method-args">()</span>
|
498
|
+
<span class="method-click-advice">click to toggle source</span>
|
499
|
+
</div>
|
500
|
+
|
501
|
+
|
502
|
+
<div class="method-description">
|
503
|
+
|
504
|
+
<p>Closes the sam file and destroys the C pointers using the functions
|
505
|
+
provided by libbam</p>
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
<div class="method-source-code" id="close-source">
|
510
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 95</span>
|
511
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">close</span>()
|
512
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">fai_destroy</span>(<span class="ruby-ivar">@fasta_index</span>) <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@fasta_index</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@fasta_index</span>.<span class="ruby-identifier">null?</span>
|
513
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">bam_index_destroy</span>(<span class="ruby-ivar">@sam_index</span>) <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sam_index</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@sam_index</span>.<span class="ruby-identifier">null?</span>
|
514
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">samclose</span>(<span class="ruby-ivar">@sam_file</span>) <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sam_file</span>.<span class="ruby-identifier">nil?</span>
|
515
|
+
<span class="ruby-ivar">@sam_file</span> = <span class="ruby-keyword">nil</span>
|
516
|
+
<span class="ruby-ivar">@fasta_index</span> = <span class="ruby-keyword">nil</span>
|
517
|
+
<span class="ruby-keyword">end</span></pre>
|
518
|
+
</div><!-- close-source -->
|
519
|
+
|
520
|
+
</div>
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
</div><!-- close-method -->
|
526
|
+
|
527
|
+
|
528
|
+
<div id="method-i-deprecated_pileup" class="method-detail ">
|
529
|
+
|
530
|
+
<div class="method-heading">
|
531
|
+
<span class="method-name">deprecated_pileup</span><span
|
532
|
+
class="method-args">( cmd ) { |pileup| ... }</span>
|
533
|
+
<span class="method-click-advice">click to toggle source</span>
|
534
|
+
</div>
|
535
|
+
|
536
|
+
|
537
|
+
<div class="method-description">
|
538
|
+
|
539
|
+
<p>utility method that does not use the samtools API, it calls samtools
|
540
|
+
directly as if on the command line and catches the output, to use this
|
541
|
+
method you must have a version of samtools that supports the pileup command
|
542
|
+
(< 0.1.17) otherwise the command will fail. mpileup is the preferred
|
543
|
+
method for getting pileups. With this method the sam object should be
|
544
|
+
created as usual, but you need to pass this method a string of options for
|
545
|
+
samtools you don’t need to provide the call to samtools pileup itself or
|
546
|
+
-f <fasta file> or the bam file itself, these are taken from the sam
|
547
|
+
object</p>
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
<div class="method-source-code" id="deprecated_pileup-source">
|
552
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 472</span>
|
553
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">deprecated_pileup</span>( <span class="ruby-identifier">cmd</span> )
|
554
|
+
|
555
|
+
<span class="ruby-identifier">system</span>(<span class="ruby-string">'samtools pileup > /dev/null 2>&1'</span>)
|
556
|
+
<span class="ruby-comment">##assumes samtools is in the path...</span>
|
557
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">$?</span>.<span class="ruby-identifier">exitstatus</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span>
|
558
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>, <span class="ruby-string">"samtools is required on the path. A version of samtools with the pileup function is required"</span>
|
559
|
+
<span class="ruby-keyword">end</span>
|
560
|
+
|
561
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No BAMFile provided"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sam</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@binary</span>
|
562
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No FastA provided"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@fasta_path</span>
|
563
|
+
|
564
|
+
<span class="ruby-identifier">command</span> = <span class="ruby-string">'samtools pileup '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">cmd</span> <span class="ruby-operator">+</span> <span class="ruby-node">" -f #{@fasta_path}"</span> <span class="ruby-operator">+</span> <span class="ruby-node">" #{@sam}"</span>
|
565
|
+
|
566
|
+
<span class="ruby-identifier">pipe</span> = <span class="ruby-constant">IO</span>.<span class="ruby-identifier">popen</span>(<span class="ruby-identifier">command</span>)
|
567
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">gets</span>
|
568
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-constant">Pileup</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">line</span>)
|
569
|
+
<span class="ruby-keyword">end</span>
|
570
|
+
<span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">close</span>
|
571
|
+
<span class="ruby-keyword">end</span></pre>
|
572
|
+
</div><!-- deprecated_pileup-source -->
|
573
|
+
|
574
|
+
</div>
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
</div><!-- deprecated_pileup-method -->
|
580
|
+
|
581
|
+
|
582
|
+
<div id="method-i-fetch" class="method-detail ">
|
583
|
+
|
584
|
+
<div class="method-heading">
|
585
|
+
<span class="method-name">fetch</span><span
|
586
|
+
class="method-args">(chromosome, qstart, qend)</span>
|
587
|
+
<span class="method-click-advice">click to toggle source</span>
|
588
|
+
</div>
|
589
|
+
|
590
|
+
|
591
|
+
<div class="method-description">
|
592
|
+
|
593
|
+
<p>Returns an array of Alignments on a given region.</p>
|
594
|
+
|
595
|
+
|
596
|
+
|
597
|
+
<div class="method-source-code" id="fetch-source">
|
598
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 211</span>
|
599
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>, <span class="ruby-identifier">qend</span>)
|
600
|
+
<span class="ruby-identifier">als</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
|
601
|
+
<span class="ruby-identifier">fetchAlignment</span> = <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">alignment</span><span class="ruby-operator">|</span>
|
602
|
+
<span class="ruby-identifier">als</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">alignment</span>.<span class="ruby-identifier">clone</span>)
|
603
|
+
<span class="ruby-value">0</span>
|
604
|
+
<span class="ruby-keyword">end</span>
|
605
|
+
<span class="ruby-identifier">fetch_with_function</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>, <span class="ruby-identifier">qend</span>, <span class="ruby-identifier">fetchAlignment</span>)
|
606
|
+
<span class="ruby-identifier">als</span>
|
607
|
+
<span class="ruby-keyword">end</span></pre>
|
608
|
+
</div><!-- fetch-source -->
|
609
|
+
|
610
|
+
</div>
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
</div><!-- fetch-method -->
|
616
|
+
|
617
|
+
|
618
|
+
<div id="method-i-fetch_reference" class="method-detail ">
|
619
|
+
|
620
|
+
<div class="method-heading">
|
621
|
+
<span class="method-name">fetch_reference</span><span
|
622
|
+
class="method-args">(chromosome, qstart,qend)</span>
|
623
|
+
<span class="method-click-advice">click to toggle source</span>
|
624
|
+
</div>
|
625
|
+
|
626
|
+
|
627
|
+
<div class="method-description">
|
628
|
+
|
629
|
+
<p>Returns the sequence for a given region.</p>
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
<div class="method-source-code" id="fetch_reference-source">
|
634
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 193</span>
|
635
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch_reference</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>,<span class="ruby-identifier">qend</span>)
|
636
|
+
<span class="ruby-identifier">load_reference</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@fasta_index</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@fasta_index</span>.<span class="ruby-identifier">null?</span>
|
637
|
+
<span class="ruby-identifier">query</span> = <span class="ruby-identifier">query_string</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>,<span class="ruby-identifier">qend</span>)
|
638
|
+
<span class="ruby-identifier">len</span> = <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:int</span>
|
639
|
+
<span class="ruby-identifier">reference</span> = <span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">fai_fetch</span>(<span class="ruby-ivar">@fasta_index</span>, <span class="ruby-identifier">query</span>, <span class="ruby-identifier">len</span>)
|
640
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"Unable to get sequence for reference: "</span><span class="ruby-operator">+</span><span class="ruby-identifier">query</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">reference</span>.<span class="ruby-identifier">nil?</span>
|
641
|
+
|
642
|
+
<span class="ruby-identifier">reference</span>
|
643
|
+
<span class="ruby-keyword">end</span></pre>
|
644
|
+
</div><!-- fetch_reference-source -->
|
645
|
+
|
646
|
+
</div>
|
647
|
+
|
648
|
+
|
649
|
+
|
650
|
+
|
651
|
+
</div><!-- fetch_reference-method -->
|
652
|
+
|
653
|
+
|
654
|
+
<div id="method-i-fetch_with_function" class="method-detail ">
|
655
|
+
|
656
|
+
<div class="method-heading">
|
657
|
+
<span class="method-name">fetch_with_function</span><span
|
658
|
+
class="method-args">(chromosome, qstart, qend, function)</span>
|
659
|
+
<span class="method-click-advice">click to toggle source</span>
|
660
|
+
</div>
|
661
|
+
|
662
|
+
|
663
|
+
<div class="method-description">
|
664
|
+
|
665
|
+
<p>Executes a function on each <a href="Alignment.html">Alignment</a> inside
|
666
|
+
the queried region of the chromosome. The chromosome can be either the
|
667
|
+
textual name or a FixNum with the internal index. However, you need to get
|
668
|
+
the internal index with the provided API, otherwise the pointer is outside
|
669
|
+
the scope of the C library. Returns the count of alignments in the region.
|
670
|
+
WARNING: Accepts an index already parsed by the library. It fails when you
|
671
|
+
use your own FixNum (FFI-bug?)</p>
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
<div class="method-source-code" id="fetch_with_function-source">
|
676
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 226</span>
|
677
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch_with_function</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>, <span class="ruby-identifier">qend</span>, <span class="ruby-identifier">function</span>)
|
678
|
+
<span class="ruby-identifier">load_index</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@sam_index</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@sam_index</span>.<span class="ruby-identifier">null?</span>
|
679
|
+
<span class="ruby-identifier">chr</span> = <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:int</span>
|
680
|
+
<span class="ruby-identifier">beg</span> = <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:int</span>
|
681
|
+
<span class="ruby-identifier">last</span> = <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:int</span>
|
682
|
+
<span class="ruby-identifier">query</span> = <span class="ruby-identifier">query_string</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>,<span class="ruby-identifier">qend</span>)
|
683
|
+
<span class="ruby-identifier">qpointer</span> = <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">from_string</span>(<span class="ruby-identifier">query</span>)
|
684
|
+
<span class="ruby-identifier">header</span> = <span class="ruby-ivar">@sam_file</span>[<span class="ruby-value">:header</span>]
|
685
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">bam_parse_region</span>(<span class="ruby-identifier">header</span>,<span class="ruby-identifier">qpointer</span>, <span class="ruby-identifier">chr</span>, <span class="ruby-identifier">beg</span>, <span class="ruby-identifier">last</span>)
|
686
|
+
<span class="ruby-comment">#raise SAMException.new(), "invalid query: " + query if(chr.read_int < 0)</span>
|
687
|
+
<span class="ruby-identifier">count</span> = <span class="ruby-value">0</span>;
|
688
|
+
|
689
|
+
<span class="ruby-identifier">fetchAlignment</span> = <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">bam_alignment</span>, <span class="ruby-identifier">data</span><span class="ruby-operator">|</span>
|
690
|
+
<span class="ruby-identifier">alignment</span> = <span class="ruby-constant">Alignment</span>.<span class="ruby-identifier">new</span>
|
691
|
+
<span class="ruby-identifier">alignment</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">bam_alignment</span>, <span class="ruby-identifier">header</span>)
|
692
|
+
<span class="ruby-identifier">function</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">alignment</span>)
|
693
|
+
<span class="ruby-identifier">count</span> = <span class="ruby-identifier">count</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
|
694
|
+
<span class="ruby-value">0</span>
|
695
|
+
<span class="ruby-keyword">end</span>
|
696
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">bam_fetch</span>(<span class="ruby-ivar">@sam_file</span>[<span class="ruby-value">:x</span>][<span class="ruby-value">:bam</span>], <span class="ruby-ivar">@sam_index</span>,<span class="ruby-identifier">chr</span>.<span class="ruby-identifier">read_int</span>,<span class="ruby-identifier">beg</span>.<span class="ruby-identifier">read_int</span>, <span class="ruby-identifier">last</span>.<span class="ruby-identifier">read_int</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">fetchAlignment</span>)
|
697
|
+
<span class="ruby-comment">#LibC.free chr</span>
|
698
|
+
<span class="ruby-comment">#LibC.free beg</span>
|
699
|
+
<span class="ruby-comment">#LibC.free last</span>
|
700
|
+
<span class="ruby-comment">#LibC.free qpointer</span>
|
701
|
+
<span class="ruby-identifier">count</span>
|
702
|
+
<span class="ruby-keyword">end</span></pre>
|
703
|
+
</div><!-- fetch_with_function-source -->
|
704
|
+
|
705
|
+
</div>
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
|
710
|
+
</div><!-- fetch_with_function-method -->
|
711
|
+
|
712
|
+
|
713
|
+
<div id="method-i-index_stats" class="method-detail ">
|
714
|
+
|
715
|
+
<div class="method-heading">
|
716
|
+
<span class="method-name">index_stats</span><span
|
717
|
+
class="method-args">()</span>
|
718
|
+
<span class="method-click-advice">click to toggle source</span>
|
719
|
+
</div>
|
720
|
+
|
721
|
+
|
722
|
+
<div class="method-description">
|
723
|
+
|
724
|
+
|
725
|
+
|
726
|
+
|
727
|
+
|
728
|
+
<div class="method-source-code" id="index_stats-source">
|
729
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 493</span>
|
730
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">index_stats</span>
|
731
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No BAMFile provided"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sam</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@binary</span>
|
732
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No FastA provided"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@fasta_path</span>
|
733
|
+
<span class="ruby-identifier">strptrs</span> = []
|
734
|
+
<span class="ruby-identifier">strptrs</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">from_string</span>(<span class="ruby-string">"idxstats"</span>)
|
735
|
+
<span class="ruby-identifier">strptrs</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">from_string</span>(<span class="ruby-ivar">@sam</span>)
|
736
|
+
<span class="ruby-identifier">strptrs</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword">nil</span>
|
737
|
+
|
738
|
+
<span class="ruby-comment"># Now load all the pointers into a native memory block</span>
|
739
|
+
<span class="ruby-identifier">argv</span> = <span class="ruby-constant">FFI</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryPointer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:pointer</span>, <span class="ruby-identifier">strptrs</span>.<span class="ruby-identifier">length</span>)
|
740
|
+
<span class="ruby-identifier">strptrs</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
741
|
+
<span class="ruby-identifier">argv</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">put_pointer</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">p</span>)
|
742
|
+
<span class="ruby-keyword">end</span>
|
743
|
+
|
744
|
+
<span class="ruby-identifier">index_stats</span> = {}
|
745
|
+
|
746
|
+
<span class="ruby-identifier">old_stdout</span> = <span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">clone</span>
|
747
|
+
<span class="ruby-identifier">read_pipe</span>, <span class="ruby-identifier">write_pipe</span> = <span class="ruby-constant">IO</span>.<span class="ruby-identifier">pipe</span>()
|
748
|
+
<span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span>(<span class="ruby-identifier">write_pipe</span>)
|
749
|
+
|
750
|
+
<span class="ruby-comment">#int bam_idxstats(int argc, char *argv[])</span>
|
751
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">bam_idxstats</span>(<span class="ruby-identifier">strptrs</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>,<span class="ruby-identifier">argv</span>)
|
752
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">fork</span>
|
753
|
+
<span class="ruby-identifier">write_pipe</span>.<span class="ruby-identifier">close</span>
|
754
|
+
<span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">reopen</span>(<span class="ruby-identifier">old_stdout</span>) <span class="ruby-comment">#beware .. stdout from other processes eg tests calling this method can get mixed in...</span>
|
755
|
+
<span class="ruby-keyword">begin</span>
|
756
|
+
|
757
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-identifier">read_pipe</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment">#TAB delimited with each line consisting of reference sequence name, sequence length, # mapped reads and # unmapped reads.</span>
|
758
|
+
<span class="ruby-identifier">info</span> = <span class="ruby-identifier">line</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">/\t/</span>)
|
759
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">info</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">4</span>
|
760
|
+
<span class="ruby-identifier">index_stats</span>[ <span class="ruby-identifier">info</span>[<span class="ruby-value">0</span>] ] = {<span class="ruby-value">:length</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">info</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>, <span class="ruby-value">:mapped_reads</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">info</span>[<span class="ruby-value">2</span>].<span class="ruby-identifier">to_i</span>, <span class="ruby-value">:unmapped_reads</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">info</span>[<span class="ruby-value">3</span>].<span class="ruby-identifier">to_i</span> }
|
761
|
+
<span class="ruby-keyword">end</span>
|
762
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">EOFError</span>
|
763
|
+
<span class="ruby-identifier">read_pipe</span>.<span class="ruby-identifier">close</span>
|
764
|
+
<span class="ruby-constant">Process</span>.<span class="ruby-identifier">wait</span>
|
765
|
+
<span class="ruby-keyword">end</span>
|
766
|
+
<span class="ruby-keyword">end</span> <span class="ruby-comment">#fork</span>
|
767
|
+
<span class="ruby-identifier">index_stats</span>
|
768
|
+
<span class="ruby-keyword">end</span></pre>
|
769
|
+
</div><!-- index_stats-source -->
|
770
|
+
|
771
|
+
</div>
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
|
776
|
+
</div><!-- index_stats-method -->
|
777
|
+
|
778
|
+
|
779
|
+
<div id="method-i-load_index" class="method-detail ">
|
780
|
+
|
781
|
+
<div class="method-heading">
|
782
|
+
<span class="method-name">load_index</span><span
|
783
|
+
class="method-args">()</span>
|
784
|
+
<span class="method-click-advice">click to toggle source</span>
|
785
|
+
</div>
|
786
|
+
|
787
|
+
|
788
|
+
<div class="method-description">
|
789
|
+
|
790
|
+
<p>Loads the bam index to be used for fetching. If the index doesn’t exists
|
791
|
+
the index is built provided that the user has writing access to the folder
|
792
|
+
where the BAM file is located. If the creation of the file fails a <a
|
793
|
+
href="SAMException.html">SAMException</a> is thrown. If the index
|
794
|
+
doesn’t exist, loading it will take more time. It is suggested to
|
795
|
+
generate the index separatedly if the bam file sits on a server where the
|
796
|
+
executing user may not have writing permissions in the server.</p>
|
797
|
+
|
798
|
+
|
799
|
+
|
800
|
+
<div class="method-source-code" id="load_index-source">
|
801
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 114</span>
|
802
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">load_index</span>()
|
803
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"Indexes are only supported by BAM files, please use samtools to convert your SAM file"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@binary</span>
|
804
|
+
<span class="ruby-ivar">@sam_index</span> = <span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">bam_index_load</span>(<span class="ruby-ivar">@sam</span>)
|
805
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@sam_index</span>.<span class="ruby-identifier">null?</span> <span class="ruby-keyword">then</span>
|
806
|
+
<span class="ruby-identifier">p</span> <span class="ruby-string">"Generating index for: "</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@sam</span>
|
807
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">bam_index_build</span>(<span class="ruby-ivar">@sam</span>)
|
808
|
+
<span class="ruby-ivar">@sam_index</span> = <span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">bam_index_load</span>(<span class="ruby-ivar">@sam</span>)
|
809
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"Unable to generate bam index for: "</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@sam</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@sam_index</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@sam_index</span>.<span class="ruby-identifier">null?</span>
|
810
|
+
<span class="ruby-keyword">end</span>
|
811
|
+
<span class="ruby-keyword">end</span></pre>
|
812
|
+
</div><!-- load_index-source -->
|
813
|
+
|
814
|
+
</div>
|
815
|
+
|
816
|
+
|
817
|
+
|
818
|
+
|
819
|
+
</div><!-- load_index-method -->
|
820
|
+
|
821
|
+
|
822
|
+
<div id="method-i-load_reference" class="method-detail ">
|
823
|
+
|
824
|
+
<div class="method-heading">
|
825
|
+
<span class="method-name">load_reference</span><span
|
826
|
+
class="method-args">()</span>
|
827
|
+
<span class="method-click-advice">click to toggle source</span>
|
828
|
+
</div>
|
829
|
+
|
830
|
+
|
831
|
+
<div class="method-description">
|
832
|
+
|
833
|
+
<p>Loads the reference file to be able to query regions of it. This requires
|
834
|
+
the fai index to exist in the same folder than the reference. If it
|
835
|
+
doesn’t exisits, this functions attempts to generate it. If user
|
836
|
+
doesn’t have writing permissions on the folder, or the creation of the
|
837
|
+
fai fails for any reason, a <a href="SAMException.html">SAMException</a> is
|
838
|
+
thrown.</p>
|
839
|
+
|
840
|
+
|
841
|
+
|
842
|
+
<div class="method-source-code" id="load_reference-source">
|
843
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 128</span>
|
844
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">load_reference</span>()
|
845
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No path for the refernce fasta file. "</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@fasta_path</span>.<span class="ruby-identifier">nil?</span>
|
846
|
+
|
847
|
+
<span class="ruby-ivar">@fasta_index</span> = <span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">fai_load</span>(<span class="ruby-ivar">@fasta_path</span>)
|
848
|
+
|
849
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@fasta_index</span>.<span class="ruby-identifier">null?</span> <span class="ruby-keyword">then</span>
|
850
|
+
<span class="ruby-identifier">p</span> <span class="ruby-string">"Generating index for: "</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@fasta_path</span>
|
851
|
+
<span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">fai_build</span>(<span class="ruby-ivar">@fasta_path</span>)
|
852
|
+
<span class="ruby-ivar">@fasta_index</span> = <span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">fai_load</span>(<span class="ruby-ivar">@fasta_path</span>)
|
853
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"Unable to generate fasta index for: "</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@fasta_path</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@fasta_index</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@fasta_index</span>.<span class="ruby-identifier">null?</span>
|
854
|
+
<span class="ruby-keyword">end</span>
|
855
|
+
|
856
|
+
<span class="ruby-keyword">end</span></pre>
|
857
|
+
</div><!-- load_reference-source -->
|
858
|
+
|
859
|
+
</div>
|
860
|
+
|
861
|
+
|
862
|
+
|
863
|
+
|
864
|
+
</div><!-- load_reference-method -->
|
865
|
+
|
866
|
+
|
867
|
+
<div id="method-i-mpileup" class="method-detail ">
|
868
|
+
|
869
|
+
<div class="method-heading">
|
870
|
+
<span class="method-name">mpileup</span><span
|
871
|
+
class="method-args">( opts ) { |pileup| ... }</span>
|
872
|
+
<span class="method-click-advice">click to toggle source</span>
|
873
|
+
</div>
|
874
|
+
|
875
|
+
|
876
|
+
<div class="method-description">
|
877
|
+
|
878
|
+
<p>calls the mpileup function, opts is a hash of options identical to the
|
879
|
+
command line options for mpileup. is an iterator that yields a <a
|
880
|
+
href="../../Pileup.html">Pileup</a> object for each postion the command
|
881
|
+
line options that generate/affect BCF/VCF are ignored ie (g,u,e,h,I,L,o,p)
|
882
|
+
call the option as a symbol of the flag, eg -r for region is called :r
|
883
|
+
=> “some <a href="SAM.html">SAM</a> compatible region” eg
|
884
|
+
bam.mpileup(:r => “chr1:1000-2000”, :q => 50) gets the bases with
|
885
|
+
quality > 50 on chr1 between 1000-5000</p>
|
886
|
+
|
887
|
+
|
888
|
+
|
889
|
+
<div class="method-source-code" id="mpileup-source">
|
890
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 281</span>
|
891
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mpileup</span>( <span class="ruby-identifier">opts</span> )
|
892
|
+
|
893
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No BAMFile provided"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sam</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@binary</span>
|
894
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No FastA provided"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@fasta_path</span>
|
895
|
+
<span class="ruby-comment">#long option form to short samtools form..</span>
|
896
|
+
<span class="ruby-identifier">long_opts</span> = {
|
897
|
+
<span class="ruby-value">:region</span> =<span class="ruby-operator">></span> <span class="ruby-value">:r</span>,
|
898
|
+
<span class="ruby-value">:illumina_quals</span> =<span class="ruby-operator">></span> <span class="ruby-value">:six</span>,
|
899
|
+
<span class="ruby-value">:count_anomalous</span> =<span class="ruby-operator">></span> <span class="ruby-value">:A</span>,
|
900
|
+
<span class="ruby-value">:no_baq</span> =<span class="ruby-operator">></span> <span class="ruby-value">:B</span>,
|
901
|
+
<span class="ruby-value">:adjust_mapq</span> =<span class="ruby-operator">></span> <span class="ruby-value">:C</span>,
|
902
|
+
<span class="ruby-value">:max_per_bam_depth</span> =<span class="ruby-operator">></span> <span class="ruby-value">:d</span>,
|
903
|
+
<span class="ruby-value">:extended_baq</span> =<span class="ruby-operator">></span> <span class="ruby-value">:E</span>,
|
904
|
+
<span class="ruby-value">:exclude_reads_file</span> =<span class="ruby-operator">></span> <span class="ruby-value">:G</span>,
|
905
|
+
<span class="ruby-value">:list_of_positions</span> =<span class="ruby-operator">></span> <span class="ruby-value">:l</span>,
|
906
|
+
<span class="ruby-value">:mapping_quality_cap</span> =<span class="ruby-operator">></span> <span class="ruby-value">:M</span>,
|
907
|
+
<span class="ruby-value">:ignore_rg</span> =<span class="ruby-operator">></span> <span class="ruby-value">:R</span>,
|
908
|
+
<span class="ruby-value">:min_mapping_quality</span> =<span class="ruby-operator">></span> <span class="ruby-value">:q</span>,
|
909
|
+
<span class="ruby-value">:min_base_quality</span> =<span class="ruby-operator">></span> <span class="ruby-value">:Q</span>
|
910
|
+
}
|
911
|
+
|
912
|
+
<span class="ruby-comment">##convert any long_opts to short opts </span>
|
913
|
+
<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
914
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">long_opts</span>[<span class="ruby-identifier">k</span>]
|
915
|
+
<span class="ruby-identifier">opts</span>[<span class="ruby-identifier">long_opts</span>[<span class="ruby-identifier">k</span>]] = <span class="ruby-identifier">v</span>
|
916
|
+
<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">k</span>)
|
917
|
+
<span class="ruby-keyword">end</span>
|
918
|
+
<span class="ruby-keyword">end</span>
|
919
|
+
|
920
|
+
<span class="ruby-comment">##remove any calls to -g or -u for mpileup, bcf output is not yet supported</span>
|
921
|
+
<span class="ruby-comment">##and also associated output options</span>
|
922
|
+
[<span class="ruby-value">:g</span>, <span class="ruby-value">:u</span>, <span class="ruby-value">:e</span>, <span class="ruby-value">:h</span>, <span class="ruby-value">:I</span>, <span class="ruby-value">:L</span>, <span class="ruby-value">:o</span>, <span class="ruby-value">:p</span>].<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">x</span>) }
|
923
|
+
|
924
|
+
<span class="ruby-identifier">sam_opts</span> = []
|
925
|
+
<span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string("mpileup")</span>
|
926
|
+
<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
927
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">k</span>] <span class="ruby-comment">##dont bother unless the values provided are true.. </span>
|
928
|
+
<span class="ruby-identifier">k</span> = <span class="ruby-string">'6'</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-value">:six</span>
|
929
|
+
<span class="ruby-identifier">k</span> = <span class="ruby-string">'-'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>
|
930
|
+
<span class="ruby-identifier">sam_opts</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">k</span> <span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string(k)</span>
|
931
|
+
<span class="ruby-identifier">sam_opts</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword">unless</span> [<span class="ruby-string">"-R"</span>, <span class="ruby-string">"-B"</span>, <span class="ruby-string">"-E"</span>, <span class="ruby-string">"-6"</span>, <span class="ruby-string">"-A"</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>) <span class="ruby-comment">#these are just flags so don't pass a value... strptrs << FFI::MemoryPointer.from_string(v.to_s)</span>
|
932
|
+
<span class="ruby-keyword">end</span>
|
933
|
+
<span class="ruby-identifier">sam_opts</span> = <span class="ruby-identifier">sam_opts</span> <span class="ruby-operator">+</span> [<span class="ruby-string">'-f'</span>, <span class="ruby-ivar">@fasta_path</span>, <span class="ruby-ivar">@sam</span>]
|
934
|
+
<span class="ruby-identifier">sam_command</span> = <span class="ruby-node">"#{File.join(File.expand_path(File.dirname(__FILE__)),'sam','external','samtools')} mpileup #{sam_opts.join(' ')} 2> /dev/null"</span>
|
935
|
+
|
936
|
+
<span class="ruby-identifier">sam_pipe</span> = <span class="ruby-constant">IO</span>.<span class="ruby-identifier">popen</span>(<span class="ruby-identifier">sam_command</span>)
|
937
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-identifier">sam_pipe</span>.<span class="ruby-identifier">gets</span>
|
938
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-constant">Pileup</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">line</span>)
|
939
|
+
<span class="ruby-keyword">end</span>
|
940
|
+
<span class="ruby-identifier">sam_pipe</span>.<span class="ruby-identifier">close</span>
|
941
|
+
<span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string('-f')</span>
|
942
|
+
<span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string(@fasta_path)</span>
|
943
|
+
<span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string(@sam)</span>
|
944
|
+
<span class="ruby-comment">#strptrs << nil</span>
|
945
|
+
|
946
|
+
<span class="ruby-comment"># Now load all the pointers into a native memory block</span>
|
947
|
+
<span class="ruby-comment">#argv = FFI::MemoryPointer.new(:pointer, strptrs.length)</span>
|
948
|
+
<span class="ruby-comment">#strptrs.each_with_index do |p, i|</span>
|
949
|
+
<span class="ruby-comment"># argv[i].put_pointer(0, p)</span>
|
950
|
+
<span class="ruby-comment">#end</span>
|
951
|
+
|
952
|
+
<span class="ruby-comment">#old_stdout = STDOUT.clone</span>
|
953
|
+
<span class="ruby-comment">#read_pipe, write_pipe = IO.pipe()</span>
|
954
|
+
<span class="ruby-comment">#STDOUT.reopen(write_pipe)</span>
|
955
|
+
<span class="ruby-comment">#int bam_mpileup(int argc, char *argv[])</span>
|
956
|
+
<span class="ruby-comment"># Bio::DB::SAM::Tools.bam_mpileup(strptrs.length - 1,argv)</span>
|
957
|
+
<span class="ruby-comment">#if fork</span>
|
958
|
+
<span class="ruby-comment"># write_pipe.close</span>
|
959
|
+
<span class="ruby-comment"># STDOUT.reopen(old_stdout) #beware .. stdout from other processes eg tests calling this method can get mixed in...</span>
|
960
|
+
<span class="ruby-comment"># begin</span>
|
961
|
+
<span class="ruby-comment"># while line = read_pipe.readline</span>
|
962
|
+
<span class="ruby-comment"># yield Pileup.new(line)</span>
|
963
|
+
<span class="ruby-comment"># end</span>
|
964
|
+
<span class="ruby-comment"># rescue EOFError</span>
|
965
|
+
<span class="ruby-comment"># read_pipe.close</span>
|
966
|
+
<span class="ruby-comment"># Process.wait</span>
|
967
|
+
<span class="ruby-comment"># end</span>
|
968
|
+
<span class="ruby-comment">#end</span>
|
969
|
+
<span class="ruby-keyword">end</span></pre>
|
970
|
+
</div><!-- mpileup-source -->
|
971
|
+
|
972
|
+
</div>
|
973
|
+
|
974
|
+
|
975
|
+
|
976
|
+
|
977
|
+
</div><!-- mpileup-method -->
|
978
|
+
|
979
|
+
|
980
|
+
<div id="method-i-mpileup_plus" class="method-detail ">
|
981
|
+
|
982
|
+
<div class="method-heading">
|
983
|
+
<span class="method-name">mpileup_plus</span><span
|
984
|
+
class="method-args">( opts ) { |vcf| ... }</span>
|
985
|
+
<span class="method-click-advice">click to toggle source</span>
|
986
|
+
</div>
|
987
|
+
|
988
|
+
|
989
|
+
<div class="method-description">
|
990
|
+
|
991
|
+
<p>experimental method that spawns a samtools mpileup | bcftools view process
|
992
|
+
and supports returning of pileup vcf</p>
|
993
|
+
|
994
|
+
<pre>otherwise works like mpileup</pre>
|
995
|
+
|
996
|
+
|
997
|
+
|
998
|
+
<div class="method-source-code" id="mpileup_plus-source">
|
999
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 363</span>
|
1000
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mpileup_plus</span>( <span class="ruby-identifier">opts</span> )
|
1001
|
+
|
1002
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No BAMFile provided"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sam</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@binary</span>
|
1003
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No FastA provided"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@fasta_path</span>
|
1004
|
+
<span class="ruby-comment">#long option form to short samtools form..</span>
|
1005
|
+
<span class="ruby-identifier">long_opts</span> = {
|
1006
|
+
<span class="ruby-value">:region</span> =<span class="ruby-operator">></span> <span class="ruby-value">:r</span>,
|
1007
|
+
<span class="ruby-value">:illumina_quals</span> =<span class="ruby-operator">></span> <span class="ruby-value">:six</span>,
|
1008
|
+
<span class="ruby-value">:count_anomalous</span> =<span class="ruby-operator">></span> <span class="ruby-value">:A</span>,
|
1009
|
+
<span class="ruby-value">:no_baq</span> =<span class="ruby-operator">></span> <span class="ruby-value">:B</span>,
|
1010
|
+
<span class="ruby-value">:adjust_mapq</span> =<span class="ruby-operator">></span> <span class="ruby-value">:C</span>,
|
1011
|
+
<span class="ruby-value">:max_per_bam_depth</span> =<span class="ruby-operator">></span> <span class="ruby-value">:d</span>,
|
1012
|
+
<span class="ruby-value">:extended_baq</span> =<span class="ruby-operator">></span> <span class="ruby-value">:E</span>,
|
1013
|
+
<span class="ruby-value">:exclude_reads_file</span> =<span class="ruby-operator">></span> <span class="ruby-value">:G</span>,
|
1014
|
+
<span class="ruby-value">:list_of_positions</span> =<span class="ruby-operator">></span> <span class="ruby-value">:l</span>,
|
1015
|
+
<span class="ruby-value">:mapping_quality_cap</span> =<span class="ruby-operator">></span> <span class="ruby-value">:M</span>,
|
1016
|
+
<span class="ruby-value">:ignore_rg</span> =<span class="ruby-operator">></span> <span class="ruby-value">:R</span>,
|
1017
|
+
<span class="ruby-value">:min_mapping_quality</span> =<span class="ruby-operator">></span> <span class="ruby-value">:q</span>,
|
1018
|
+
<span class="ruby-value">:min_base_quality</span> =<span class="ruby-operator">></span> <span class="ruby-value">:Q</span>,
|
1019
|
+
<span class="ruby-comment">###following options are for the -g -u option</span>
|
1020
|
+
<span class="ruby-value">:genotype_calling</span> =<span class="ruby-operator">></span> <span class="ruby-value">:g</span>,
|
1021
|
+
<span class="ruby-value">:uncompressed_bcf</span> =<span class="ruby-operator">></span> <span class="ruby-value">:u</span>,
|
1022
|
+
<span class="ruby-value">:extension_sequencing_probability</span> =<span class="ruby-operator">></span> <span class="ruby-value">:e</span>,
|
1023
|
+
<span class="ruby-value">:homopolymer_error_coefficient</span> =<span class="ruby-operator">></span> <span class="ruby-value">:h</span>,
|
1024
|
+
<span class="ruby-value">:no_indels</span> =<span class="ruby-operator">></span> <span class="ruby-value">:I</span>,
|
1025
|
+
<span class="ruby-value">:skip_indel_over_average_depth</span> =<span class="ruby-operator">></span> <span class="ruby-value">:L</span>,
|
1026
|
+
<span class="ruby-value">:gap_open_sequencing_error_probability</span> =<span class="ruby-operator">></span> <span class="ruby-value">:o</span>,
|
1027
|
+
<span class="ruby-value">:platforms</span> =<span class="ruby-operator">></span> <span class="ruby-value">:P</span>
|
1028
|
+
}
|
1029
|
+
|
1030
|
+
<span class="ruby-comment">##convert any long_opts to short opts </span>
|
1031
|
+
<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
1032
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">long_opts</span>[<span class="ruby-identifier">k</span>]
|
1033
|
+
<span class="ruby-identifier">opts</span>[<span class="ruby-identifier">long_opts</span>[<span class="ruby-identifier">k</span>]] = <span class="ruby-identifier">v</span>
|
1034
|
+
<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">k</span>)
|
1035
|
+
<span class="ruby-keyword">end</span>
|
1036
|
+
<span class="ruby-keyword">end</span>
|
1037
|
+
|
1038
|
+
<span class="ruby-comment">##remove any calls to -g or -u for mpileup, bcf output is not yet supported</span>
|
1039
|
+
<span class="ruby-comment">##and also associated output options</span>
|
1040
|
+
<span class="ruby-comment">#[:g, :u, :e, :h, :I, :L, :o, :p].each {|x| opts.delete(x) }</span>
|
1041
|
+
<span class="ruby-identifier">opts</span>[<span class="ruby-value">:u</span>] = <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-value">:g</span>] <span class="ruby-comment">#so that we always get uncompressed output</span>
|
1042
|
+
<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:g</span>)
|
1043
|
+
|
1044
|
+
<span class="ruby-identifier">sam_opts</span> = []
|
1045
|
+
<span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string("mpileup")</span>
|
1046
|
+
<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
1047
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">k</span>] <span class="ruby-comment">##dont bother unless the values provided are true.. </span>
|
1048
|
+
<span class="ruby-identifier">k</span> = <span class="ruby-string">'6'</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-value">:six</span>
|
1049
|
+
<span class="ruby-identifier">k</span> = <span class="ruby-string">'-'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>
|
1050
|
+
<span class="ruby-identifier">sam_opts</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">k</span> <span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string(k)</span>
|
1051
|
+
<span class="ruby-identifier">sam_opts</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword">unless</span> [<span class="ruby-string">"-R"</span>, <span class="ruby-string">"-B"</span>, <span class="ruby-string">"-E"</span>, <span class="ruby-string">"-6"</span>, <span class="ruby-string">"-A"</span>, <span class="ruby-string">"-g"</span>, <span class="ruby-string">"-u"</span>, <span class="ruby-string">"-I"</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">k</span>) <span class="ruby-comment">#these are just flags so don't pass a value... strptrs << FFI::MemoryPointer.from_string(v.to_s)</span>
|
1052
|
+
<span class="ruby-keyword">end</span>
|
1053
|
+
<span class="ruby-identifier">sam_opts</span> = <span class="ruby-identifier">sam_opts</span> <span class="ruby-operator">+</span> [<span class="ruby-string">'-f'</span>, <span class="ruby-ivar">@fasta_path</span>, <span class="ruby-ivar">@sam</span>]
|
1054
|
+
|
1055
|
+
<span class="ruby-identifier">command</span> = <span class="ruby-node">"#{File.join(File.expand_path(File.dirname(__FILE__)),'sam','external','samtools')} mpileup #{sam_opts.join(' ')} 2> /dev/null"</span>
|
1056
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-value">:u</span>]
|
1057
|
+
<span class="ruby-identifier">command</span> = <span class="ruby-identifier">command</span> <span class="ruby-operator">+</span> <span class="ruby-node">" | #{File.join(File.expand_path(File.dirname(__FILE__)),'sam','external','bcftools')} view -cg -"</span>
|
1058
|
+
<span class="ruby-keyword">end</span>
|
1059
|
+
<span class="ruby-identifier">pipe</span> = <span class="ruby-constant">IO</span>.<span class="ruby-identifier">popen</span>(<span class="ruby-identifier">command</span>)
|
1060
|
+
<span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">command</span>
|
1061
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-value">:u</span>]
|
1062
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">gets</span>
|
1063
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">line</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>] <span class="ruby-operator">==</span> <span class="ruby-string">'#'</span> <span class="ruby-comment">#skip any header or meta-lines, we dont do anything with those </span>
|
1064
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-constant">Vcf</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">line</span>)
|
1065
|
+
<span class="ruby-keyword">end</span>
|
1066
|
+
<span class="ruby-keyword">else</span>
|
1067
|
+
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">gets</span>
|
1068
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-constant">Pileup</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">line</span>)
|
1069
|
+
<span class="ruby-keyword">end</span>
|
1070
|
+
<span class="ruby-keyword">end</span>
|
1071
|
+
<span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">close</span>
|
1072
|
+
<span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string('-f')</span>
|
1073
|
+
<span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string(@fasta_path)</span>
|
1074
|
+
<span class="ruby-comment">#strptrs << FFI::MemoryPointer.from_string(@sam)</span>
|
1075
|
+
<span class="ruby-comment">#strptrs << nil</span>
|
1076
|
+
|
1077
|
+
<span class="ruby-comment"># Now load all the pointers into a native memory block</span>
|
1078
|
+
<span class="ruby-comment">#argv = FFI::MemoryPointer.new(:pointer, strptrs.length)</span>
|
1079
|
+
<span class="ruby-comment">#strptrs.each_with_index do |p, i|</span>
|
1080
|
+
<span class="ruby-comment"># argv[i].put_pointer(0, p)</span>
|
1081
|
+
<span class="ruby-comment">#end</span>
|
1082
|
+
|
1083
|
+
<span class="ruby-comment">#old_stdout = STDOUT.clone</span>
|
1084
|
+
<span class="ruby-comment">#read_pipe, write_pipe = IO.pipe()</span>
|
1085
|
+
<span class="ruby-comment">#STDOUT.reopen(write_pipe)</span>
|
1086
|
+
<span class="ruby-comment">#int bam_mpileup(int argc, char *argv[])</span>
|
1087
|
+
<span class="ruby-comment"># Bio::DB::SAM::Tools.bam_mpileup(strptrs.length - 1,argv)</span>
|
1088
|
+
<span class="ruby-comment">#if fork</span>
|
1089
|
+
<span class="ruby-comment"># write_pipe.close</span>
|
1090
|
+
<span class="ruby-comment"># STDOUT.reopen(old_stdout) #beware .. stdout from other processes eg tests calling this method can get mixed in...</span>
|
1091
|
+
<span class="ruby-comment"># begin</span>
|
1092
|
+
<span class="ruby-comment"># while line = read_pipe.readline</span>
|
1093
|
+
<span class="ruby-comment"># yield Pileup.new(line)</span>
|
1094
|
+
<span class="ruby-comment"># end</span>
|
1095
|
+
<span class="ruby-comment"># rescue EOFError</span>
|
1096
|
+
<span class="ruby-comment"># read_pipe.close</span>
|
1097
|
+
<span class="ruby-comment"># Process.wait</span>
|
1098
|
+
<span class="ruby-comment"># end</span>
|
1099
|
+
<span class="ruby-comment">#end</span>
|
1100
|
+
<span class="ruby-keyword">end</span></pre>
|
1101
|
+
</div><!-- mpileup_plus-source -->
|
1102
|
+
|
1103
|
+
</div>
|
1104
|
+
|
1105
|
+
|
1106
|
+
|
1107
|
+
|
1108
|
+
</div><!-- mpileup_plus-method -->
|
1109
|
+
|
1110
|
+
|
1111
|
+
<div id="method-i-open" class="method-detail ">
|
1112
|
+
|
1113
|
+
<div class="method-heading">
|
1114
|
+
<span class="method-name">open</span><span
|
1115
|
+
class="method-args">()</span>
|
1116
|
+
<span class="method-click-advice">click to toggle source</span>
|
1117
|
+
</div>
|
1118
|
+
|
1119
|
+
|
1120
|
+
<div class="method-description">
|
1121
|
+
|
1122
|
+
<p>Function that actually opens the sam file Throws a <a
|
1123
|
+
href="SAMException.html">SAMException</a> if the file can’t be open.</p>
|
1124
|
+
|
1125
|
+
|
1126
|
+
|
1127
|
+
<div class="method-source-code" id="open-source">
|
1128
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 60</span>
|
1129
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">open</span>()
|
1130
|
+
|
1131
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"Writing not supported yet"</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@write</span>
|
1132
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"No SAM file specified"</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sam</span>
|
1133
|
+
|
1134
|
+
<span class="ruby-identifier">opts</span> = <span class="ruby-ivar">@write</span> <span class="ruby-operator">?</span> <span class="ruby-string">"w"</span> <span class="ruby-operator">:</span> <span class="ruby-string">"r"</span>
|
1135
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@binary</span> <span class="ruby-keyword">then</span>
|
1136
|
+
<span class="ruby-identifier">opts</span> <span class="ruby-operator">+=</span> <span class="ruby-string">"b"</span>
|
1137
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@write</span> <span class="ruby-keyword">then</span>
|
1138
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-ivar">@compressed</span> <span class="ruby-keyword">then</span>
|
1139
|
+
<span class="ruby-identifier">opts</span> <span class="ruby-operator">+=</span> <span class="ruby-string">"u"</span>
|
1140
|
+
<span class="ruby-keyword">end</span>
|
1141
|
+
<span class="ruby-keyword">end</span>
|
1142
|
+
<span class="ruby-keyword">end</span>
|
1143
|
+
<span class="ruby-identifier">valid</span> = [<span class="ruby-string">"r"</span>, <span class="ruby-string">"w"</span>, <span class="ruby-string">"wh"</span>, <span class="ruby-string">"rb"</span>, <span class="ruby-string">"wb"</span> , <span class="ruby-string">"wbu"</span>]
|
1144
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">valid</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">opts</span>) <span class="ruby-keyword">then</span>
|
1145
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"Invalid options for samopen: "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">opts</span>
|
1146
|
+
<span class="ruby-keyword">end</span>
|
1147
|
+
|
1148
|
+
<span class="ruby-identifier">samFile</span> = <span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span>.<span class="ruby-identifier">samopen</span>(<span class="ruby-ivar">@sam</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-keyword">nil</span>)
|
1149
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">samFile</span>.<span class="ruby-identifier">null?</span> <span class="ruby-keyword">then</span>
|
1150
|
+
<span class="ruby-ivar">@sam_file</span> = <span class="ruby-keyword">nil</span>
|
1151
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SAMException</span>.<span class="ruby-identifier">new</span>(), <span class="ruby-string">"File not opened: "</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@sam</span>
|
1152
|
+
<span class="ruby-keyword">end</span>
|
1153
|
+
<span class="ruby-ivar">@sam_file</span> = <span class="ruby-constant">Bio</span><span class="ruby-operator">::</span><span class="ruby-constant">DB</span><span class="ruby-operator">::</span><span class="ruby-constant">SAM</span><span class="ruby-operator">::</span><span class="ruby-constant">Tools</span><span class="ruby-operator">::</span><span class="ruby-constant">SamfileT</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">samFile</span>)
|
1154
|
+
|
1155
|
+
<span class="ruby-keyword">end</span></pre>
|
1156
|
+
</div><!-- open-source -->
|
1157
|
+
|
1158
|
+
</div>
|
1159
|
+
|
1160
|
+
|
1161
|
+
|
1162
|
+
|
1163
|
+
</div><!-- open-method -->
|
1164
|
+
|
1165
|
+
|
1166
|
+
<div id="method-i-query_string" class="method-detail ">
|
1167
|
+
|
1168
|
+
<div class="method-heading">
|
1169
|
+
<span class="method-name">query_string</span><span
|
1170
|
+
class="method-args">(chromosome, qstart,qend)</span>
|
1171
|
+
<span class="method-click-advice">click to toggle source</span>
|
1172
|
+
</div>
|
1173
|
+
|
1174
|
+
|
1175
|
+
<div class="method-description">
|
1176
|
+
|
1177
|
+
<p>Generates a query sting to be used by the region parser in samtools. In
|
1178
|
+
principle, you shouldn’t need to use this function.</p>
|
1179
|
+
|
1180
|
+
|
1181
|
+
|
1182
|
+
<div class="method-source-code" id="query_string-source">
|
1183
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 205</span>
|
1184
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">query_string</span>(<span class="ruby-identifier">chromosome</span>, <span class="ruby-identifier">qstart</span>,<span class="ruby-identifier">qend</span>)
|
1185
|
+
<span class="ruby-identifier">query</span> = <span class="ruby-identifier">chromosome</span> <span class="ruby-operator">+</span> <span class="ruby-string">":"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">qstart</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-string">"-"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">qend</span>.<span class="ruby-identifier">to_s</span>
|
1186
|
+
<span class="ruby-identifier">query</span>
|
1187
|
+
<span class="ruby-keyword">end</span></pre>
|
1188
|
+
</div><!-- query_string-source -->
|
1189
|
+
|
1190
|
+
</div>
|
1191
|
+
|
1192
|
+
|
1193
|
+
|
1194
|
+
|
1195
|
+
</div><!-- query_string-method -->
|
1196
|
+
|
1197
|
+
|
1198
|
+
<div id="method-i-to_s" class="method-detail ">
|
1199
|
+
|
1200
|
+
<div class="method-heading">
|
1201
|
+
<span class="method-name">to_s</span><span
|
1202
|
+
class="method-args">()</span>
|
1203
|
+
<span class="method-click-advice">click to toggle source</span>
|
1204
|
+
</div>
|
1205
|
+
|
1206
|
+
|
1207
|
+
<div class="method-description">
|
1208
|
+
|
1209
|
+
<p>Prints a description of the sam file in a text format containg if it is
|
1210
|
+
binary or text, the path and the fasta file of the reference</p>
|
1211
|
+
|
1212
|
+
|
1213
|
+
|
1214
|
+
<div class="method-source-code" id="to_s-source">
|
1215
|
+
<pre><span class="ruby-comment"># File lib/bio/db/sam.rb, line 90</span>
|
1216
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">to_s</span>()
|
1217
|
+
(<span class="ruby-ivar">@binary</span> <span class="ruby-operator">?</span> <span class="ruby-string">"Binary"</span> <span class="ruby-operator">:</span> <span class="ruby-string">"Text"</span>) <span class="ruby-operator">+</span> <span class="ruby-string">" file: "</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@sam</span> <span class="ruby-operator">+</span> <span class="ruby-string">" with fasta: "</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@fasta_path</span>
|
1218
|
+
<span class="ruby-keyword">end</span></pre>
|
1219
|
+
</div><!-- to_s-source -->
|
1220
|
+
|
1221
|
+
</div>
|
1222
|
+
|
1223
|
+
|
1224
|
+
|
1225
|
+
|
1226
|
+
</div><!-- to_s-method -->
|
1227
|
+
|
1228
|
+
|
1229
|
+
</section><!-- public-instance-method-details -->
|
1230
|
+
|
1231
|
+
</section><!-- 5Buntitled-5D -->
|
1232
|
+
|
1233
|
+
</div><!-- documentation -->
|
1234
|
+
|
1235
|
+
|
1236
|
+
<footer id="validator-badges">
|
1237
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
1238
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
|
1239
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
1240
|
+
</footer>
|
1241
|
+
|