bio-samtools-wrapper 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.travis.yml +27 -0
- data/Gemfile +20 -0
- data/LICENSE.txt +702 -0
- data/README.md +501 -0
- data/Rakefile +73 -0
- data/VERSION +1 -0
- data/bin/bam_consensus.rb +85 -0
- data/bio-samtools-wrapper.gemspec +181 -0
- data/doc/Bio/DB/Alignment.html +552 -0
- data/doc/Bio/DB/Pileup.html +711 -0
- data/doc/Bio/DB/SAM/Library.html +167 -0
- data/doc/Bio/DB/SAM/Tools.html +109 -0
- data/doc/Bio/DB/SAM.html +1853 -0
- data/doc/Bio/DB/Tag.html +208 -0
- data/doc/Bio/DB/Vcf.html +431 -0
- data/doc/Bio/DB.html +105 -0
- data/doc/Bio.html +175 -0
- data/doc/LICENSE_txt.html +846 -0
- data/doc/created.rid +9 -0
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/fonts.css +167 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.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 +106 -0
- data/doc/js/darkfish.js +140 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +109 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +580 -0
- data/doc/table_of_contents.html +305 -0
- data/ext/Makefile-bioruby.patch +12 -0
- data/ext/Makefile-suse.patch +11 -0
- data/ext/mkrf_conf.rb +118 -0
- data/lib/bio/BIOExtensions.rb +89 -0
- data/lib/bio/db/alignment.rb +64 -0
- data/lib/bio/db/fastadb.rb +320 -0
- data/lib/bio/db/pileup.rb +273 -0
- data/lib/bio/db/sam/external/COPYING +21 -0
- data/lib/bio/db/sam/external/VERSION +1 -0
- data/lib/bio/db/sam/library.rb +32 -0
- data/lib/bio/db/sam.rb +778 -0
- data/lib/bio/db/vcf.rb +105 -0
- data/lib/bio-samtools-wrapper.rb +9 -0
- data/test/.gitignore +1 -0
- data/test/helper.rb +18 -0
- data/test/sample.vcf +24 -0
- data/test/samples/.gitignore +1 -0
- data/test/samples/LCI/NC_001988.ffn +2 -0
- data/test/samples/LCI/test.bam +0 -0
- data/test/samples/LCI/test.bam.bai +0 -0
- data/test/samples/small/dupes.bam +0 -0
- data/test/samples/small/dupes.sam +274 -0
- data/test/samples/small/ids2.txt +1 -0
- data/test/samples/small/map_for_reheader.sam +8 -0
- data/test/samples/small/map_to_merge1.bam +0 -0
- data/test/samples/small/map_to_merge1.bam.bai +0 -0
- data/test/samples/small/map_to_merge1.sam +8 -0
- data/test/samples/small/map_to_merge2.bam +0 -0
- data/test/samples/small/map_to_merge2.bam.bai +0 -0
- data/test/samples/small/map_to_merge2.sam +8 -0
- data/test/samples/small/no_md.sam +8 -0
- data/test/samples/small/sorted.bam +0 -0
- data/test/samples/small/sorted.bam.bai +0 -0
- data/test/samples/small/test.sai +0 -0
- data/test/samples/small/test.tam +10 -0
- data/test/samples/small/test_chr.fasta +1000 -0
- data/test/samples/small/test_chr.fasta.1.bt2 +0 -0
- data/test/samples/small/test_chr.fasta.2.bt2 +0 -0
- data/test/samples/small/test_chr.fasta.3.bt2 +0 -0
- data/test/samples/small/test_chr.fasta.4.bt2 +0 -0
- data/test/samples/small/test_chr.fasta.amb +2 -0
- data/test/samples/small/test_chr.fasta.ann +3 -0
- data/test/samples/small/test_chr.fasta.bwt +0 -0
- data/test/samples/small/test_chr.fasta.pac +0 -0
- data/test/samples/small/test_chr.fasta.rbwt +0 -0
- data/test/samples/small/test_chr.fasta.rev.1.bt2 +0 -0
- data/test/samples/small/test_chr.fasta.rev.2.bt2 +0 -0
- data/test/samples/small/test_chr.fasta.rpac +0 -0
- data/test/samples/small/test_chr.fasta.rsa +0 -0
- data/test/samples/small/test_chr.fasta.sa +0 -0
- data/test/samples/small/test_cov.svg +273 -0
- data/test/samples/small/test_fastadb.fasta +34 -0
- data/test/samples/small/testu.bam +0 -0
- data/test/samples/small/testu.bed +2 -0
- data/test/test_bio-samtools-wrapper.rb +1 -0
- data/test/test_fastadb.rb +89 -0
- data/test/test_pileup.rb +90 -0
- data/test/test_sam.rb +421 -0
- data/test/test_vcf.rb +79 -0
- data/tutorial/tutorial.html +474 -0
- data/tutorial/tutorial.md +424 -0
- data/tutorial/tutorial.pdf +0 -0
- metadata +254 -0
@@ -0,0 +1,474 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
6
|
+
<style>
|
7
|
+
h1,
|
8
|
+
h2,
|
9
|
+
h3,
|
10
|
+
h4,
|
11
|
+
h5,
|
12
|
+
h6,
|
13
|
+
p,
|
14
|
+
blockquote {
|
15
|
+
margin: 0;
|
16
|
+
padding: 0;
|
17
|
+
}
|
18
|
+
body {
|
19
|
+
font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif;
|
20
|
+
font-size: 13px;
|
21
|
+
line-height: 18px;
|
22
|
+
color: #737373;
|
23
|
+
background-color: white;
|
24
|
+
margin: 10px 13px 10px 13px;
|
25
|
+
}
|
26
|
+
table {
|
27
|
+
margin: 10px 0 15px 0;
|
28
|
+
border-collapse: collapse;
|
29
|
+
}
|
30
|
+
td,th {
|
31
|
+
border: 1px solid #ddd;
|
32
|
+
padding: 3px 10px;
|
33
|
+
}
|
34
|
+
th {
|
35
|
+
padding: 5px 10px;
|
36
|
+
}
|
37
|
+
|
38
|
+
a {
|
39
|
+
color: #0069d6;
|
40
|
+
}
|
41
|
+
a:hover {
|
42
|
+
color: #0050a3;
|
43
|
+
text-decoration: none;
|
44
|
+
}
|
45
|
+
a img {
|
46
|
+
border: none;
|
47
|
+
}
|
48
|
+
p {
|
49
|
+
margin-bottom: 9px;
|
50
|
+
}
|
51
|
+
h1,
|
52
|
+
h2,
|
53
|
+
h3,
|
54
|
+
h4,
|
55
|
+
h5,
|
56
|
+
h6 {
|
57
|
+
color: #404040;
|
58
|
+
line-height: 36px;
|
59
|
+
}
|
60
|
+
h1 {
|
61
|
+
margin-bottom: 18px;
|
62
|
+
font-size: 30px;
|
63
|
+
}
|
64
|
+
h2 {
|
65
|
+
font-size: 24px;
|
66
|
+
}
|
67
|
+
h3 {
|
68
|
+
font-size: 18px;
|
69
|
+
}
|
70
|
+
h4 {
|
71
|
+
font-size: 16px;
|
72
|
+
}
|
73
|
+
h5 {
|
74
|
+
font-size: 14px;
|
75
|
+
}
|
76
|
+
h6 {
|
77
|
+
font-size: 13px;
|
78
|
+
}
|
79
|
+
hr {
|
80
|
+
margin: 0 0 19px;
|
81
|
+
border: 0;
|
82
|
+
border-bottom: 1px solid #ccc;
|
83
|
+
}
|
84
|
+
blockquote {
|
85
|
+
padding: 13px 13px 21px 15px;
|
86
|
+
margin-bottom: 18px;
|
87
|
+
font-family:georgia,serif;
|
88
|
+
font-style: italic;
|
89
|
+
}
|
90
|
+
blockquote:before {
|
91
|
+
content:"\201C";
|
92
|
+
font-size:40px;
|
93
|
+
margin-left:-10px;
|
94
|
+
font-family:georgia,serif;
|
95
|
+
color:#eee;
|
96
|
+
}
|
97
|
+
blockquote p {
|
98
|
+
font-size: 14px;
|
99
|
+
font-weight: 300;
|
100
|
+
line-height: 18px;
|
101
|
+
margin-bottom: 0;
|
102
|
+
font-style: italic;
|
103
|
+
}
|
104
|
+
code, pre {
|
105
|
+
font-family: Monaco, Andale Mono, Courier New, monospace;
|
106
|
+
}
|
107
|
+
code {
|
108
|
+
background-color: #fee9cc;
|
109
|
+
color: rgba(0, 0, 0, 0.75);
|
110
|
+
padding: 1px 3px;
|
111
|
+
font-size: 12px;
|
112
|
+
-webkit-border-radius: 3px;
|
113
|
+
-moz-border-radius: 3px;
|
114
|
+
border-radius: 3px;
|
115
|
+
}
|
116
|
+
pre {
|
117
|
+
display: block;
|
118
|
+
padding: 14px;
|
119
|
+
margin: 0 0 18px;
|
120
|
+
line-height: 16px;
|
121
|
+
font-size: 11px;
|
122
|
+
border: 1px solid #d9d9d9;
|
123
|
+
white-space: pre-wrap;
|
124
|
+
word-wrap: break-word;
|
125
|
+
}
|
126
|
+
pre code {
|
127
|
+
background-color: #fff;
|
128
|
+
color:#737373;
|
129
|
+
font-size: 11px;
|
130
|
+
padding: 0;
|
131
|
+
}
|
132
|
+
sup {
|
133
|
+
font-size: 0.83em;
|
134
|
+
vertical-align: super;
|
135
|
+
line-height: 0;
|
136
|
+
}
|
137
|
+
* {
|
138
|
+
-webkit-print-color-adjust: exact;
|
139
|
+
}
|
140
|
+
@media screen and (min-width: 914px) {
|
141
|
+
body {
|
142
|
+
width: 854px;
|
143
|
+
margin:10px auto;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
@media print {
|
147
|
+
body,code,pre code,h1,h2,h3,h4,h5,h6 {
|
148
|
+
color: black;
|
149
|
+
}
|
150
|
+
table, pre {
|
151
|
+
page-break-inside: avoid;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
</style>
|
155
|
+
<title>Prerequisites</title>
|
156
|
+
|
157
|
+
</head>
|
158
|
+
<body>
|
159
|
+
<h1>bio-SAMtools Basic Tutorial</h1>
|
160
|
+
|
161
|
+
<h2>Introduction</h2>
|
162
|
+
|
163
|
+
<p>bio-SAMtools is a Ruby binding to the popular <a href="http://SAMtools.sourceforge.net/">SAMtools</a> library, and provides access to individual read alignments as well as BAM files, reference sequence and pileup information.</p>
|
164
|
+
|
165
|
+
<h2>Installation</h2>
|
166
|
+
|
167
|
+
<p>Installation of bio-SAMtools is very straightforward, and is
|
168
|
+
accomplished with the Ruby gems command. All you need is an internet
|
169
|
+
connection.</p>
|
170
|
+
|
171
|
+
<h3>Prerequisites</h3>
|
172
|
+
|
173
|
+
<p>bio-SAMtools relies on the following other rubygems:</p>
|
174
|
+
|
175
|
+
<ul>
|
176
|
+
<li><a href="http://rubygems.org/gems/bio">bio >= 1.4.2</a></li>
|
177
|
+
<li><a href="https://rubygems.org/gems/bio-svgenes">bio-svgenes >= 0.4.1</a></li>
|
178
|
+
</ul>
|
179
|
+
|
180
|
+
|
181
|
+
<p>Once these are installed, bio-SAMtools can be installed with</p>
|
182
|
+
|
183
|
+
<pre><code>sudo gem install bio-SAMtools
|
184
|
+
</code></pre>
|
185
|
+
|
186
|
+
<p>It should then be easy to test whether installation went well. Start
|
187
|
+
interactive Ruby (IRB) in the terminal, and type
|
188
|
+
<code>require 'bio-SAMtools'</code> if the terminal returns <code>true</code> then all is
|
189
|
+
well.</p>
|
190
|
+
|
191
|
+
<pre><code>$ irb
|
192
|
+
>> require 'bio-SAMtools'
|
193
|
+
=> true
|
194
|
+
</code></pre>
|
195
|
+
|
196
|
+
<h2>Working with BAM files</h2>
|
197
|
+
|
198
|
+
<h3>Creating a new SAM object</h3>
|
199
|
+
|
200
|
+
<p>A SAM object represents the alignments in the BAM file. BAM files (and hence SAM objects here) are what most of SAMtools methods operate on and are very straightforward to create. You will need a sorted BAM file, to access the alignments and a reference sequence in FASTA format to use the reference sequence. The object can be created and opened as follows:</p>
|
201
|
+
|
202
|
+
<pre><code>bam = Bio::DB::Sam.new(:bam=>"my_sorted.bam", :fasta=>'ref.fasta')
|
203
|
+
</code></pre>
|
204
|
+
|
205
|
+
<p>Opening the file needs only to be done once for multiple operations on
|
206
|
+
it, access to the alignments is random so you don't need to loop over
|
207
|
+
the entries in the file.</p>
|
208
|
+
|
209
|
+
<h3>Getting Reference Sequence</h3>
|
210
|
+
|
211
|
+
<p>The reference is accessed using reference
|
212
|
+
name, start, end in 1-based co-ordinates. A standard Ruby String object is returned.</p>
|
213
|
+
|
214
|
+
<pre><code>sequence_fragment = bam.fetch_reference("Chr1", 1, 100)
|
215
|
+
</code></pre>
|
216
|
+
|
217
|
+
<p>The output from this would be the raw sequence as a string, e.g.</p>
|
218
|
+
|
219
|
+
<pre><code>cctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaacccta
|
220
|
+
</code></pre>
|
221
|
+
|
222
|
+
<p>A reference sequence can be returned as a Bio::Sequence::NA object buy the use of :as_bio => true</p>
|
223
|
+
|
224
|
+
<pre><code>sequence_fragment = bam.fetch_reference("Chr1", 1, 100, :as_bio => true)
|
225
|
+
</code></pre>
|
226
|
+
|
227
|
+
<p>The output from this would be a Bio::Sequence::NA object, which provides a fasta-formatted string when printed</p>
|
228
|
+
|
229
|
+
<pre><code>>Chr1:1-100
|
230
|
+
cctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaaccctaacccta
|
231
|
+
</code></pre>
|
232
|
+
|
233
|
+
<h3>Alignment Objects</h3>
|
234
|
+
|
235
|
+
<p>The individual alignments represent a single read and are returned as
|
236
|
+
Bio::DB::Alignment objects. These have numerous methods of their own,
|
237
|
+
using <code>require 'pp'</code> will allow you to check the attributes contained in
|
238
|
+
each object. Here is an example alignment object. Remember <code>@</code>
|
239
|
+
represents a Ruby instance variable and can be accessed as any other
|
240
|
+
method. Thus the <code>@is_mapped</code> attribute of an object <code>a</code> is accessed
|
241
|
+
<code>a.is_mapped</code></p>
|
242
|
+
|
243
|
+
<pre><code>require 'pp'
|
244
|
+
pp an_alignment_object ##some Bio::DB::Alignment object
|
245
|
+
#<Bio::DB::Alignment:0x101113f80
|
246
|
+
@al=#<Bio::DB::SAM::Tools::Bam1T:0x101116a50>,
|
247
|
+
@calend=4067,
|
248
|
+
@cigar="76M",
|
249
|
+
@failed_quality=false,
|
250
|
+
@first_in_pair=false,
|
251
|
+
@flag=163,
|
252
|
+
@is_duplicate=false,
|
253
|
+
@is_mapped=true,
|
254
|
+
@is_paired=true,
|
255
|
+
@isize=180,
|
256
|
+
@mapq=60,
|
257
|
+
@mate_strand=false,
|
258
|
+
@mate_unmapped=false,
|
259
|
+
@mpos=4096,
|
260
|
+
@mrnm="=",
|
261
|
+
@pos=3992,
|
262
|
+
@primary=true,
|
263
|
+
@qlen=76,
|
264
|
+
@qname="HWI-EAS396_0001:7:115:17904:15958#0",
|
265
|
+
@qual="IIIIIIIIIIIIHHIHGIHIDGGGG...",
|
266
|
+
@query_strand=true,
|
267
|
+
@query_unmapped=false,
|
268
|
+
@rname="1",
|
269
|
+
@second_in_pair=true,
|
270
|
+
@seq="ACAGTCCAGTCAAAGTACAAATCGAG...",
|
271
|
+
@tags=
|
272
|
+
{"MD"=>#<Bio::DB::Tag:0x101114ed0 @tag="MD", @type="Z", @value="76">,
|
273
|
+
"XO"=>#<Bio::DB::Tag:0x1011155d8 @tag="XO", @type="i", @value="0">,
|
274
|
+
"AM"=>#<Bio::DB::Tag:0x101116280 @tag="AM", @type="i", @value="37">,
|
275
|
+
"X0"=>#<Bio::DB::Tag:0x101115fb0 @tag="X0", @type="i", @value="1">,
|
276
|
+
"X1"=>#<Bio::DB::Tag:0x101115c68 @tag="X1", @type="i", @value="0">,
|
277
|
+
"XG"=>#<Bio::DB::Tag:0x101115240 @tag="XG", @type="i", @value="0">,
|
278
|
+
"SM"=>#<Bio::DB::Tag:0x1011162f8 @tag="SM", @type="i", @value="37">,
|
279
|
+
"XT"=>#<Bio::DB::Tag:0x1011162a8 @tag="XT", @type="A", @value="U">,
|
280
|
+
"NM"=>#<Bio::DB::Tag:0x101116348 @tag="NM", @type="i", @value="0">,
|
281
|
+
"XM"=>#<Bio::DB::Tag:0x101115948 @tag="XM", @type="i", @value="0">}>
|
282
|
+
</code></pre>
|
283
|
+
|
284
|
+
<h3>Getting Alignments</h3>
|
285
|
+
|
286
|
+
<p>Alignments can be obtained one at a time by looping over a specified region using the <code>fetch()</code> function.</p>
|
287
|
+
|
288
|
+
<pre><code>bam.fetch("Chr1",3000,4000).each do |alignment|
|
289
|
+
#do something with the alignment...
|
290
|
+
end
|
291
|
+
</code></pre>
|
292
|
+
|
293
|
+
<p>A separate method <code>fetch_with_function()</code> allows you to pass a block (or
|
294
|
+
a Proc object) to the function for efficient calculation. This example takes
|
295
|
+
an alignment object and returns an array of sequences which exactly match the reference.</p>
|
296
|
+
|
297
|
+
<pre><code>#an array to hold the matching sequences
|
298
|
+
exact_matches = []
|
299
|
+
|
300
|
+
matches = Proc.new do |a|
|
301
|
+
#get the length of each read
|
302
|
+
len = a.seq.length
|
303
|
+
#get the cigar string
|
304
|
+
cigar = a.cigar
|
305
|
+
#create a cigar string which represents a full-length match
|
306
|
+
cstr = len.to_s << "M"
|
307
|
+
if cigar == cstr
|
308
|
+
#add the current sequence to the array if it qualifies
|
309
|
+
exact_matches << a.seq
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
bam.fetch_with_function("Chr1", 100, 500, &matches)
|
314
|
+
|
315
|
+
puts exact_matches
|
316
|
+
</code></pre>
|
317
|
+
|
318
|
+
<h3>Alignment stats</h3>
|
319
|
+
|
320
|
+
<p>The SAMtools flagstat method is implemented in bio-SAMtools to quickly examine the number of reads mapped to the reference. This includes the number of paired and singleton reads mapped and also the number of paired-reads that map to different chromosomes/contigs.</p>
|
321
|
+
|
322
|
+
<pre><code>bam.flag_stats()
|
323
|
+
</code></pre>
|
324
|
+
|
325
|
+
<p>An example output would be</p>
|
326
|
+
|
327
|
+
<pre><code>34672 + 0 in total (QC-passed reads + QC-failed reads)
|
328
|
+
0 + 0 duplicates
|
329
|
+
33196 + 0 mapped (95.74%:nan%)
|
330
|
+
34672 + 0 paired in sequencing
|
331
|
+
17335 + 0 read1
|
332
|
+
17337 + 0 read2
|
333
|
+
31392 + 0 properly paired (90.54%:nan%)
|
334
|
+
31728 + 0 with itself and mate mapped
|
335
|
+
1468 + 0 singletons (4.23%:nan%)
|
336
|
+
0 + 0 with mate mapped to a different chr
|
337
|
+
0 + 0 with mate mapped to a different chr (mapQ>=5)
|
338
|
+
</code></pre>
|
339
|
+
|
340
|
+
<h2>Getting Coverage Information</h2>
|
341
|
+
|
342
|
+
<h3>Per Base Coverage</h3>
|
343
|
+
|
344
|
+
<p>It is easy to get the total depth of reads at a given position, the
|
345
|
+
<code>chromosome_coverage</code> function is used. This differs from the previous
|
346
|
+
functions in that a start position and length (rather than end position)
|
347
|
+
are passed to the function. An array of coverages is returned, the first
|
348
|
+
position in the array gives the depth of coverage at the given start
|
349
|
+
position in the genome, the last position in the array gives the depth
|
350
|
+
of coverage at the given start position plus the length given</p>
|
351
|
+
|
352
|
+
<pre><code>coverages = bam.chromosome_coverage("Chr1", 3000, 1000) #=> [16,16,25,25...]
|
353
|
+
</code></pre>
|
354
|
+
|
355
|
+
<h3>Average Coverage In A Region</h3>
|
356
|
+
|
357
|
+
<p>Similarly, average (arithmetic mean) of coverage can be retrieved with the <code>average_coverage</code> method.</p>
|
358
|
+
|
359
|
+
<pre><code>coverages = bam.average_coverage("Chr1", 3000, 1000) #=> 20.287
|
360
|
+
</code></pre>
|
361
|
+
|
362
|
+
<h2>Getting Pileup Information</h2>
|
363
|
+
|
364
|
+
<p>Pileup format represents the coverage of reads over a single base in the
|
365
|
+
reference. Getting a Pileup over a region is very easy. Note that this
|
366
|
+
is done with <code>mpileup</code> and NOT the now deprecated SAMtools <code>pileup</code>
|
367
|
+
function. Calling the <code>mpileup</code> method creates an iterator that yields a
|
368
|
+
Pileup object for each base.</p>
|
369
|
+
|
370
|
+
<pre><code>bam.mpileup do |pileup|
|
371
|
+
puts pileup.consensus #gives the consensus base from the reads for that postion
|
372
|
+
end
|
373
|
+
</code></pre>
|
374
|
+
|
375
|
+
<h3>Caching pileups</h3>
|
376
|
+
|
377
|
+
<p>A pileup can be cached, so if you want to execute several operations on the same set of regions, mpilup won't be executed several times. Whenever you finish using a region, call mpileup_clear_cache to free the cache. The argument 'Region' is required, as it will be the key for the underlying hash. We asume that the options (other than the region) are constant. If they are not, the cache mechanism may not be consistent.</p>
|
378
|
+
|
379
|
+
<pre><code>#create an mpileup
|
380
|
+
reg = Bio::DB::Fasta::Region.new
|
381
|
+
reg.entry = "Chr1"
|
382
|
+
reg.start = 1
|
383
|
+
reg.end = 334
|
384
|
+
|
385
|
+
bam.mpileup_cached(:r=>reg,:g => false, :min_cov => 1, :min_per =>0.2) do |pileup|
|
386
|
+
puts pileup.consensus
|
387
|
+
end
|
388
|
+
bam.mpileup_clear_cache(reg)
|
389
|
+
</code></pre>
|
390
|
+
|
391
|
+
<h4>Pileup options</h4>
|
392
|
+
|
393
|
+
<p>The <code>mpileup</code> function takes a range of parameters to allow SAMtools
|
394
|
+
level filtering of reads and alignments. They are specified as key =>
|
395
|
+
value pairs eg</p>
|
396
|
+
|
397
|
+
<pre><code>bam.mpileup(:r => "Chr1:1000-2000", :Q => 50) do |pileup|
|
398
|
+
##only pileups on Chr1 between positions 1000-2000 are considered,
|
399
|
+
##bases with Quality Score < 50 are excluded
|
400
|
+
...
|
401
|
+
end
|
402
|
+
</code></pre>
|
403
|
+
|
404
|
+
<p>Not all the options SAMtools allows you to pass to mpileup will return a
|
405
|
+
Pileup object, those that cause mpileup to return BCF/VCF will be
|
406
|
+
ignored. Specifically these are g,u,e,h,I,L,o,p. The table below lists
|
407
|
+
the SAMtools flags supported and the symbols you can use to call them in
|
408
|
+
the mpileup command.</p>
|
409
|
+
|
410
|
+
<table><tr><th>SAMtools options</th><th>description</th><th>short symbol</th><th>long symbol</th><th>default</th><th>example</th></tr>
|
411
|
+
<tr><td>r</td><td>limit retrieval to a region</td><td>:r</td><td>:region</td><td>all positions</td><td>:r => "Chr1:1000-2000"</td></tr>
|
412
|
+
<tr><td>6</td><td>assume Illumina scaled quality scores</td><td>:six</td><td>:illumina_quals</td><td>false</td><td>:six => true</td></tr>
|
413
|
+
<tr><td>A</td><td>count anomalous read pairs scores</td><td>:A</td><td>:count_anomalous</td><td>false</td><td>:A => true</td></tr>
|
414
|
+
<tr><td>B</td><td>disable BAQ computation</td><td>:B</td><td>:no_baq</td><td>false</td><td>:no_baq => true</td></tr>
|
415
|
+
<tr><td>C</td><td>parameter for adjusting mapQ</td><td>:C</td><td>:adjust_mapq</td><td>0</td><td>:C => 25</td></tr>
|
416
|
+
<tr><td>d</td><td>max per-BAM depth to avoid excessive memory usage</td><td>:d</td><td>:max_per_bam_depth</td><td>250</td><td>:d => 123</td></tr>
|
417
|
+
<tr><td>E</td><td>extended BAQ for higher sensitivity but lower specificity</td><td>:E</td><td>:extended_baq</td><td>false</td><td>:E => true</td></tr>
|
418
|
+
<tr><td>G</td><td>exclude read groups listed in FILE</td><td>:G</td><td>:exclude_reads_file</td><td>false</td><td>:G => my_file.txt</td></tr>
|
419
|
+
<tr><td>l</td><td>list of positions (chr pos) or regions (BED)</td><td>:l</td><td>:list_of_positions</td><td>false</td><td>:l => my_posns.bed</td></tr>
|
420
|
+
<tr><td>M</td><td>cap mapping quality at value</td><td>:M</td><td>:mapping_quality_cap</td><td>60</td><td>:M => 40 </td></tr>
|
421
|
+
<tr><td>R</td><td>ignore RG tags</td><td>:R</td><td>:ignore_rg</td><td>false</td><td>:R => true </td></tr>
|
422
|
+
<tr><td>q</td><td>skip alignments with mapping quality smaller than value</td><td>:q</td><td>:min_mapping_quality</td><td>0</td><td>:q => 30 </td></tr>
|
423
|
+
<tr><td>Q</td><td>skip bases with base quality smaller than value</td><td>:Q</td><td>:imin_base_quality</td><td>13</td><td>:Q => 30</td></tr>
|
424
|
+
</table>
|
425
|
+
|
426
|
+
|
427
|
+
<h2>Coverage Plots</h2>
|
428
|
+
|
429
|
+
<p>You can create images that represent read coverage over binned regions of the reference sequence. The output format is svg. A number of parameters can be changed to alter the style of the plot. In the examples below the bin size and fill_color have been used to create plots with different colours and bar widths.</p>
|
430
|
+
|
431
|
+
<p>The following lines of code...</p>
|
432
|
+
|
433
|
+
<pre><code>bam.plot_coverage("Chr1", 201, 2000, :bin=>20, :svg => "out2.svg", :fill_color => '#F1A1B1')
|
434
|
+
bam.plot_coverage("Chr1", 201, 2000, :bin=>50, :svg => "out.svg", :fill_color => '#99CCFF')
|
435
|
+
bam.plot_coverage("Chr1", 201, 1000, :bin=>250, :svg => "out3.svg", :fill_color => '#33AD5C', :stroke => '#33AD5C')
|
436
|
+
</code></pre>
|
437
|
+
|
438
|
+
<p><img src="http://ethering.github.io/bio-samtools/images/out2.svg" alt="Coverage plot 1" />
|
439
|
+
<img src="http://ethering.github.io/bio-samtools/images/out.svg" alt="Coverage plot 2" />
|
440
|
+
<img src="http://ethering.github.io/bio-samtools/images/out3.svg" alt="Coverage plot 2" /></p>
|
441
|
+
|
442
|
+
<h1>VCF methods</h1>
|
443
|
+
|
444
|
+
<p>For enhanced snp calling, we've included a VCF class which reflects each non-metadata line of a VCF file.
|
445
|
+
The VCF class returns the eight fixed fields present in VCF files, namely chromosome, position, ID, reference base, alt bases, alt quality score, filter and info along with the genotype fields, format and samples. This information allows the comparison of variants and their genotypes across any number of samples.
|
446
|
+
The following code takes a number of VCF objects and examines them for homozygous alt (1/1) SNPs</p>
|
447
|
+
|
448
|
+
<pre><code>vcfs = []
|
449
|
+
vcfs << vcf1 = Bio::DB::Vcf.new("20 14370 rs6054257 G A 29 0 NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:-1,-1") #from a 3.3 vcf file
|
450
|
+
vcfs << vcf2 = Bio::DB::Vcf.new("19 111 . A C 9.6 . . GT:HQ 0|0:10,10 0/0:10,10 0/1:3,3") #from a 4.0 vcf file
|
451
|
+
vcfs << vcf3 = Bio::DB::Vcf.new("20 14380 rs6054257 G A 29 PASS NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:.,") #from a 4.0 vcf file
|
452
|
+
|
453
|
+
vcfs.each do |vcf|
|
454
|
+
vcf.samples.each do |sample|
|
455
|
+
genotype = "#{sample[1]['GT']}"
|
456
|
+
if genotype == '1/1' or genotype == '1|1'
|
457
|
+
print vcf.chrom, " "
|
458
|
+
puts vcf.pos
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
=> 20 14370
|
464
|
+
=> 20 14380
|
465
|
+
</code></pre>
|
466
|
+
|
467
|
+
<h2>Tests</h2>
|
468
|
+
|
469
|
+
<p>The easiest way to run the built-in unit tests is to change to the
|
470
|
+
bio-SAMtools source directory and running 'rake test'</p>
|
471
|
+
|
472
|
+
<p>Each test file tests different aspects of the code.</p>
|
473
|
+
</body>
|
474
|
+
</html>
|