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