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