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