]> git.donarmstrong.com Git - samtools.git/blob - samtools.1
rename iterf as iter
[samtools.git] / samtools.1
1 .TH samtools 1 "10 November 2009" "samtools-0.1.7" "Bioinformatics tools"
2 .SH NAME
3 .PP
4 samtools - Utilities for the Sequence Alignment/Map (SAM) format
5 .SH SYNOPSIS
6 .PP
7 samtools view -bt ref_list.txt -o aln.bam aln.sam.gz
8 .PP
9 samtools sort aln.bam aln.sorted
10 .PP
11 samtools index aln.sorted.bam
12 .PP
13 samtools view aln.sorted.bam chr2:20,100,000-20,200,000
14 .PP
15 samtools merge out.bam in1.bam in2.bam in3.bam
16 .PP
17 samtools faidx ref.fasta
18 .PP
19 samtools pileup -f ref.fasta aln.sorted.bam
20 .PP
21 samtools mpileup -f ref.fasta -r chr3:1,000-2,000 in1.bam in2.bam
22 .PP
23 samtools tview aln.sorted.bam ref.fasta
24
25 .SH DESCRIPTION
26 .PP
27 Samtools is a set of utilities that manipulate alignments in the BAM
28 format. It imports from and exports to the SAM (Sequence Alignment/Map)
29 format, does sorting, merging and indexing, and allows to retrieve reads
30 in any regions swiftly.
31
32 Samtools is designed to work on a stream. It regards an input file `-'
33 as the standard input (stdin) and an output file `-' as the standard
34 output (stdout). Several commands can thus be combined with Unix
35 pipes. Samtools always output warning and error messages to the standard
36 error output (stderr).
37
38 Samtools is also able to open a BAM (not SAM) file on a remote FTP or
39 HTTP server if the BAM file name starts with `ftp://' or `http://'.
40 Samtools checks the current working directory for the index file and
41 will download the index upon absence. Samtools does not retrieve the
42 entire alignment file unless it is asked to do so.
43
44 .SH COMMANDS AND OPTIONS
45
46 .TP 10
47 .B import
48 samtools import <in.ref_list> <in.sam> <out.bam>
49
50 Since 0.1.4, this command is an alias of:
51
52 samtools view -bt <in.ref_list> -o <out.bam> <in.sam>
53
54 .TP
55 .B sort
56 samtools sort [-n] [-m maxMem] <in.bam> <out.prefix>
57
58 Sort alignments by leftmost coordinates. File
59 .I <out.prefix>.bam
60 will be created. This command may also create temporary files
61 .I <out.prefix>.%d.bam
62 when the whole alignment cannot be fitted into memory (controlled by
63 option -m).
64
65 .B OPTIONS:
66 .RS
67 .TP 8
68 .B -n
69 Sort by read names rather than by chromosomal coordinates
70 .TP
71 .B -m INT
72 Approximately the maximum required memory. [500000000]
73 .RE
74
75 .TP
76 .B merge
77 samtools merge [-h inh.sam] [-n] <out.bam> <in1.bam> <in2.bam> [...]
78
79 Merge multiple sorted alignments.
80 The header reference lists of all the input BAM files, and the @SQ headers of
81 .IR inh.sam ,
82 if any, must all refer to the same set of reference sequences.
83 The header reference list and (unless overridden by
84 .BR -h )
85 `@' headers of
86 .I in1.bam
87 will be copied to
88 .IR out.bam ,
89 and the headers of other files will be ignored.
90
91 .B OPTIONS:
92 .RS
93 .TP 8
94 .B -h FILE
95 Use the lines of
96 .I FILE
97 as `@' headers to be copied to
98 .IR out.bam ,
99 replacing any header lines that would otherwise be copied from
100 .IR in1.bam .
101 .RI ( FILE
102 is actually in SAM format, though any alignment records it may contain
103 are ignored.)
104 .TP
105 .B -n
106 The input alignments are sorted by read names rather than by chromosomal
107 coordinates
108 .RE
109
110 .TP
111 .B index
112 samtools index <aln.bam>
113
114 Index sorted alignment for fast random access. Index file
115 .I <aln.bam>.bai
116 will be created.
117
118 .TP
119 .B view
120 samtools view [-bhuHS] [-t in.refList] [-o output] [-f reqFlag] [-F
121 skipFlag] [-q minMapQ] [-l library] [-r readGroup] <in.bam>|<in.sam> [region1 [...]]
122
123 Extract/print all or sub alignments in SAM or BAM format. If no region
124 is specified, all the alignments will be printed; otherwise only
125 alignments overlapping the specified regions will be output. An
126 alignment may be given multiple times if it is overlapping several
127 regions. A region can be presented, for example, in the following
128 format: `chr2' (the whole chr2), `chr2:1000000' (region starting from
129 1,000,000bp) or `chr2:1,000,000-2,000,000' (region between 1,000,000 and
130 2,000,000bp including the end points). The coordinate is 1-based.
131
132 .B OPTIONS:
133 .RS
134 .TP 8
135 .B -b
136 Output in the BAM format.
137 .TP
138 .B -u
139 Output uncompressed BAM. This option saves time spent on
140 compression/decomprssion and is thus preferred when the output is piped
141 to another samtools command.
142 .TP
143 .B -h
144 Include the header in the output.
145 .TP
146 .B -H
147 Output the header only.
148 .TP
149 .B -S
150 Input is in SAM. If @SQ header lines are absent, the
151 .B `-t'
152 option is required.
153 .TP
154 .B -t FILE
155 This file is TAB-delimited. Each line must contain the reference name
156 and the length of the reference, one line for each distinct reference;
157 additional fields are ignored. This file also defines the order of the
158 reference sequences in sorting. If you run `samtools faidx <ref.fa>',
159 the resultant index file
160 .I <ref.fa>.fai
161 can be used as this
162 .I <in.ref_list>
163 file.
164 .TP
165 .B -o FILE
166 Output file [stdout]
167 .TP
168 .B -f INT
169 Only output alignments with all bits in INT present in the FLAG
170 field. INT can be in hex in the format of /^0x[0-9A-F]+/ [0]
171 .TP
172 .B -F INT
173 Skip alignments with bits present in INT [0]
174 .TP
175 .B -q INT
176 Skip alignments with MAPQ smaller than INT [0]
177 .TP
178 .B -l STR
179 Only output reads in library STR [null]
180 .TP
181 .B -r STR
182 Only output reads in read group STR [null]
183 .RE
184
185 .TP
186 .B faidx
187 samtools faidx <ref.fasta> [region1 [...]]
188
189 Index reference sequence in the FASTA format or extract subsequence from
190 indexed reference sequence. If no region is specified,
191 .B faidx
192 will index the file and create
193 .I <ref.fasta>.fai
194 on the disk. If regions are speficified, the subsequences will be
195 retrieved and printed to stdout in the FASTA format. The input file can
196 be compressed in the
197 .B RAZF
198 format.
199
200 .TP
201 .B pileup
202 samtools pileup [-f in.ref.fasta] [-t in.ref_list] [-l in.site_list]
203 [-iscgS2] [-T theta] [-N nHap] [-r pairDiffRate] <in.bam>|<in.sam>
204
205 Print the alignment in the pileup format. In the pileup format, each
206 line represents a genomic position, consisting of chromosome name,
207 coordinate, reference base, read bases, read qualities and alignment
208 mapping qualities. Information on match, mismatch, indel, strand,
209 mapping quality and start and end of a read are all encoded at the read
210 base column. At this column, a dot stands for a match to the reference
211 base on the forward strand, a comma for a match on the reverse strand,
212 `ACGTN' for a mismatch on the forward strand and `acgtn' for a mismatch
213 on the reverse strand. A pattern `\\+[0-9]+[ACGTNacgtn]+' indicates
214 there is an insertion between this reference position and the next
215 reference position. The length of the insertion is given by the integer
216 in the pattern, followed by the inserted sequence. Similarly, a pattern
217 `-[0-9]+[ACGTNacgtn]+' represents a deletion from the reference. The
218 deleted bases will be presented as `*' in the following lines. Also at
219 the read base column, a symbol `^' marks the start of a read segment
220 which is a contiguous subsequence on the read separated by `N/S/H' CIGAR
221 operations. The ASCII of the character following `^' minus 33 gives the
222 mapping quality. A symbol `$' marks the end of a read segment.
223
224 If option
225 .B -c
226 is applied, the consensus base, Phred-scaled consensus quality, SNP
227 quality (i.e. the Phred-scaled probability of the consensus being
228 identical to the reference) and root mean square (RMS) mapping quality
229 of the reads covering the site will be inserted between the `reference
230 base' and the `read bases' columns. An indel occupies an additional
231 line. Each indel line consists of chromosome name, coordinate, a star,
232 the genotype, consensus quality, SNP quality, RMS mapping quality, #
233 covering reads, the first alllele, the second allele, # reads supporting
234 the first allele, # reads supporting the second allele and # reads
235 containing indels different from the top two alleles.
236
237 The position of indels is offset by -1.
238
239 .B OPTIONS:
240 .RS
241
242 .TP 10
243 .B -s
244 Print the mapping quality as the last column. This option makes the
245 output easier to parse, although this format is not space efficient.
246
247 .TP
248 .B -S
249 The input file is in SAM.
250
251 .TP
252 .B -i
253 Only output pileup lines containing indels.
254
255 .TP
256 .B -f FILE
257 The reference sequence in the FASTA format. Index file
258 .I FILE.fai
259 will be created if
260 absent.
261
262 .TP
263 .B -M INT
264 Cap mapping quality at INT [60]
265
266 .TP
267 .B -t FILE
268 List of reference names ane sequence lengths, in the format described
269 for the
270 .B import
271 command. If this option is present, samtools assumes the input
272 .I <in.alignment>
273 is in SAM format; otherwise it assumes in BAM format.
274
275 .TP
276 .B -l FILE
277 List of sites at which pileup is output. This file is space
278 delimited. The first two columns are required to be chromosome and
279 1-based coordinate. Additional columns are ignored. It is
280 recommended to use option
281 .B -s
282 together with
283 .B -l
284 as in the default format we may not know the mapping quality.
285
286 .TP
287 .B -c
288 Call the consensus sequence using MAQ consensus model. Options
289 .B -T,
290 .B -N,
291 .B -I
292 and
293 .B -r
294 are only effective when
295 .B -c
296 or
297 .B -g
298 is in use.
299
300 .TP
301 .B -g
302 Generate genotype likelihood in the binary GLFv3 format. This option
303 suppresses -c, -i and -s.
304
305 .TP
306 .B -T FLOAT
307 The theta parameter (error dependency coefficient) in the maq consensus
308 calling model [0.85]
309
310 .TP
311 .B -N INT
312 Number of haplotypes in the sample (>=2) [2]
313
314 .TP
315 .B -r FLOAT
316 Expected fraction of differences between a pair of haplotypes [0.001]
317
318 .TP
319 .B -I INT
320 Phred probability of an indel in sequencing/prep. [40]
321
322 .RE
323
324 .TP
325 .B tview
326 samtools tview <in.sorted.bam> [ref.fasta]
327
328 Text alignment viewer (based on the ncurses library). In the viewer,
329 press `?' for help and press `g' to check the alignment start from a
330 region in the format like `chr10:10,000,000'.
331
332 .TP
333 .B fixmate
334 samtools fixmate <in.nameSrt.bam> <out.bam>
335
336 Fill in mate coordinates, ISIZE and mate related flags from a
337 name-sorted alignment.
338
339 .TP
340 .B rmdup
341 samtools rmdup <input.srt.bam> <out.bam>
342
343 Remove potential PCR duplicates: if multiple read pairs have identical
344 external coordinates, only retain the pair with highest mapping quality.
345 This command
346 .B ONLY
347 works with FR orientation and requires ISIZE is correctly set.
348
349 .TP
350 .B rmdupse
351 samtools rmdupse <input.srt.bam> <out.bam>
352
353 Remove potential duplicates for single-ended reads. This command will
354 treat all reads as single-ended even if they are paired in fact.
355
356 .TP
357 .B fillmd
358 samtools fillmd [-e] <aln.bam> <ref.fasta>
359
360 Generate the MD tag. If the MD tag is already present, this command will
361 give a warning if the MD tag generated is different from the existing
362 tag.
363
364 .B OPTIONS:
365 .RS
366 .TP 8
367 .B -e
368 Convert a the read base to = if it is identical to the aligned reference
369 base. Indel caller does not support the = bases at the moment.
370
371 .RE
372
373 .SH SAM FORMAT
374
375 SAM is TAB-delimited. Apart from the header lines, which are started
376 with the `@' symbol, each alignment line consists of:
377
378 .TS
379 center box;
380 cb | cb | cb
381 n | l | l .
382 Col     Field   Description
383 _
384 1       QNAME   Query (pair) NAME
385 2       FLAG    bitwise FLAG
386 3       RNAME   Reference sequence NAME
387 4       POS     1-based leftmost POSition/coordinate of clipped sequence
388 5       MAPQ    MAPping Quality (Phred-scaled)
389 6       CIAGR   extended CIGAR string
390 7       MRNM    Mate Reference sequence NaMe (`=' if same as RNAME)
391 8       MPOS    1-based Mate POSistion
392 9       ISIZE   Inferred insert SIZE
393 10      SEQ     query SEQuence on the same strand as the reference
394 11      QUAL    query QUALity (ASCII-33 gives the Phred base quality)
395 12      OPT     variable OPTional fields in the format TAG:VTYPE:VALUE
396 .TE
397
398 .PP
399 Each bit in the FLAG field is defined as:
400
401 .TS
402 center box;
403 cb | cb
404 l | l .
405 Flag    Description
406 _
407 0x0001  the read is paired in sequencing
408 0x0002  the read is mapped in a proper pair
409 0x0004  the query sequence itself is unmapped
410 0x0008  the mate is unmapped
411 0x0010  strand of the query (1 for reverse)
412 0x0020  strand of the mate
413 0x0040  the read is the first read in a pair
414 0x0080  the read is the second read in a pair
415 0x0100  the alignment is not primary
416 0x0200  the read fails platform/vendor quality checks
417 0x0400  the read is either a PCR or an optical duplicate
418 .TE
419
420 .SH LIMITATIONS
421 .PP
422 .IP o 2
423 Unaligned words used in bam_import.c, bam_endian.h, bam.c and bam_aux.c.
424 .IP o 2
425 CIGAR operation P is not properly handled at the moment.
426 .IP o 2
427 In merging, the input files are required to have the same number of
428 reference sequences. The requirement can be relaxed. In addition,
429 merging does not reconstruct the header dictionaries
430 automatically. Endusers have to provide the correct header. Picard is
431 better at merging.
432 .IP o 2
433 Samtools' rmdup does not work for single-end data and does not remove
434 duplicates across chromosomes. Picard is better.
435
436 .SH AUTHOR
437 .PP
438 Heng Li from the Sanger Institute wrote the C version of samtools. Bob
439 Handsaker from the Broad Institute implemented the BGZF library and Jue
440 Ruan from Beijing Genomics Institute wrote the RAZF library. Various
441 people in the 1000Genomes Project contributed to the SAM format
442 specification.
443
444 .SH SEE ALSO
445 .PP
446 Samtools website: <http://samtools.sourceforge.net>