1 .TH samtools 1 "2 September 2009" "samtools-0.1.6" "Bioinformatics tools"
4 samtools - Utilities for the Sequence Alignment/Map (SAM) format
7 samtools view -bt ref_list.txt -o aln.bam aln.sam.gz
9 samtools sort aln.bam aln.sorted
11 samtools index aln.sorted.bam
13 samtools view aln.sorted.bam chr2:20,100,000-20,200,000
15 samtools merge out.bam in1.bam in2.bam in3.bam
17 samtools faidx ref.fasta
19 samtools pileup -f ref.fasta aln.sorted.bam
21 samtools tview aln.sorted.bam ref.fasta
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.
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).
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.
42 .SH COMMANDS AND OPTIONS
46 samtools import <in.ref_list> <in.sam> <out.bam>
48 Since 0.1.4, this command is an alias of:
50 samtools view -bt <in.ref_list> -o <out.bam> <in.sam>
54 samtools sort [-n] [-m maxMem] <in.bam> <out.prefix>
56 Sort alignments by leftmost coordinates. File
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
67 Sort by read names rather than by chromosomal coordinates
70 Approximately the maximum required memory. [500000000]
75 samtools merge [-h inh.sam] [-n] <out.bam> <in1.bam> <in2.bam> [...]
77 Merge multiple sorted alignments.
78 The header reference lists of all the input BAM files, and the @SQ headers of
80 if any, must all refer to the same set of reference sequences.
81 The header reference list and (unless overridden by
87 and the headers of other files will be ignored.
95 as `@' headers to be copied to
97 replacing any header lines that would otherwise be copied from
100 is actually in SAM format, though any alignment records it may contain
104 The input alignments are sorted by read names rather than by chromosomal
110 samtools index <aln.bam>
112 Index sorted alignment for fast random access. Index file
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 [...]]
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', `chr2:1000000' or `chr2:1,000,000-2,000,000'. The
127 coordinate is 1-based.
133 Output in the BAM format.
136 Output uncompressed BAM. This option saves time spent on
137 compression/decomprssion and is thus preferred when the output is piped
138 to another samtools command.
141 Include the header in the output.
144 Output the header only.
147 Input is in SAM. If @SQ header lines are absent, the
152 This file is TAB-delimited. Each line must contain the reference name
153 and the length of the reference, one line for each distinct reference;
154 additional fields are ignored. This file also defines the order of the
155 reference sequences in sorting. If you run `samtools faidx <ref.fa>',
156 the resultant index file
166 Only output alignments with all bits in INT present in the FLAG
167 field. INT can be in hex in the format of /^0x[0-9A-F]+/ [0]
170 Skip alignments with bits present in INT [0]
173 Skip alignments with MAPQ smaller than INT [0]
176 Only output reads in library STR [null]
179 Only output reads in read group STR [null]
184 samtools faidx <ref.fasta> [region1 [...]]
186 Index reference sequence in the FASTA format or extract subsequence from
187 indexed reference sequence. If no region is specified,
189 will index the file and create
191 on the disk. If regions are speficified, the subsequences will be
192 retrieved and printed to stdout in the FASTA format. The input file can
199 samtools pileup [-f in.ref.fasta] [-t in.ref_list] [-l in.site_list]
200 [-iscgS2] [-T theta] [-N nHap] [-r pairDiffRate] <in.bam>|<in.sam>
202 Print the alignment in the pileup format. In the pileup format, each
203 line represents a genomic position, consisting of chromosome name,
204 coordinate, reference base, read bases, read qualities and alignment
205 mapping qualities. Information on match, mismatch, indel, strand,
206 mapping quality and start and end of a read are all encoded at the read
207 base column. At this column, a dot stands for a match to the reference
208 base on the forward strand, a comma for a match on the reverse strand,
209 `ACGTN' for a mismatch on the forward strand and `acgtn' for a mismatch
210 on the reverse strand. A pattern `\\+[0-9]+[ACGTNacgtn]+' indicates
211 there is an insertion between this reference position and the next
212 reference position. The length of the insertion is given by the integer
213 in the pattern, followed by the inserted sequence. Similarly, a pattern
214 `-[0-9]+[ACGTNacgtn]+' represents a deletion from the reference. The
215 deleted bases will be presented as `*' in the following lines. Also at
216 the read base column, a symbol `^' marks the start of a read segment
217 which is a contiguous subsequence on the read separated by `N/S/H' CIGAR
218 operations. The ASCII of the character following `^' minus 33 gives the
219 mapping quality. A symbol `$' marks the end of a read segment.
223 is applied, the consensus base, Phred-scaled consensus quality, SNP
224 quality (i.e. the Phred-scaled probability of the consensus being
225 identical to the reference) and root mean square (RMS) mapping quality
226 of the reads covering the site will be inserted between the `reference
227 base' and the `read bases' columns. An indel occupies an additional
228 line. Each indel line consists of chromosome name, coordinate, a star,
229 the genotype, consensus quality, SNP quality, RMS mapping quality, #
230 covering reads, the first alllele, the second allele, # reads supporting
231 the first allele, # reads supporting the second allele and # reads
232 containing indels different from the top two alleles.
239 Print the mapping quality as the last column. This option makes the
240 output easier to parse, although this format is not space efficient.
244 The input file is in SAM.
248 Only output pileup lines containing indels.
252 The reference sequence in the FASTA format. Index file
259 Cap mapping quality at INT [60]
263 List of reference names ane sequence lengths, in the format described
266 command. If this option is present, samtools assumes the input
268 is in SAM format; otherwise it assumes in BAM format.
272 List of sites at which pileup is output. This file is space
273 delimited. The first two columns are required to be chromosome and
274 1-based coordinate. Additional columns are ignored. It is
275 recommended to use option
279 as in the default format we may not know the mapping quality.
283 Call the consensus sequence using MAQ consensus model. Options
289 are only effective when
297 Generate genotype likelihood in the binary GLFv3 format. This option
298 suppresses -c, -i and -s.
302 The theta parameter (error dependency coefficient) in the maq consensus
307 Number of haplotypes in the sample (>=2) [2]
311 Expected fraction of differences between a pair of haplotypes [0.001]
315 Phred probability of an indel in sequencing/prep. [40]
321 samtools tview <in.sorted.bam> [ref.fasta]
323 Text alignment viewer (based on the ncurses library). In the viewer,
324 press `?' for help and press `g' to check the alignment start from a
325 region in the format like `chr10:10,000,000'.
331 samtools fixmate <in.nameSrt.bam> <out.bam>
333 Fill in mate coordinates, ISIZE and mate related flags from a
334 name-sorted alignment.
338 samtools rmdup <input.srt.bam> <out.bam>
340 Remove potential PCR duplicates: if multiple read pairs have identical
341 external coordinates, only retain the pair with highest mapping quality.
344 works with FR orientation and requires ISIZE is correctly set.
350 samtools rmdupse <input.srt.bam> <out.bam>
352 Remove potential duplicates for single-ended reads. This command will
353 treat all reads as single-ended even if they are paired in fact.
359 samtools fillmd [-e] <aln.bam> <ref.fasta>
361 Generate the MD tag. If the MD tag is already present, this command will
362 give a warning if the MD tag generated is different from the existing
369 Convert a the read base to = if it is identical to the aligned reference
370 base. Indel caller does not support the = bases at the moment.
376 SAM is TAB-delimited. Apart from the header lines, which are started
377 with the `@' symbol, each alignment line consists of:
383 Col Field Description
385 1 QNAME Query (pair) NAME
387 3 RNAME Reference sequence NAME
388 4 POS 1-based leftmost POSition/coordinate of clipped sequence
389 5 MAPQ MAPping Quality (Phred-scaled)
390 6 CIAGR extended CIGAR string
391 7 MRNM Mate Reference sequence NaMe (`=' if same as RNAME)
392 8 MPOS 1-based Mate POSistion
393 9 ISIZE Inferred insert SIZE
394 10 SEQ query SEQuence on the same strand as the reference
395 11 QUAL query QUALity (ASCII-33 gives the Phred base quality)
396 12 OPT variable OPTional fields in the format TAG:VTYPE:VALUE
400 Each bit in the FLAG field is defined as:
408 0x0001 the read is paired in sequencing
409 0x0002 the read is mapped in a proper pair
410 0x0004 the query sequence itself is unmapped
411 0x0008 the mate is unmapped
412 0x0010 strand of the query (1 for reverse)
413 0x0020 strand of the mate
414 0x0040 the read is the first read in a pair
415 0x0080 the read is the second read in a pair
416 0x0100 the alignment is not primary
417 0x0200 the read fails platform/vendor quality checks
418 0x0400 the read is either a PCR or an optical duplicate
424 Unaligned words used in bam_import.c, bam_endian.h, bam.c and bam_aux.c.
426 CIGAR operation P is not properly handled at the moment.
428 In merging, the input files are required to have the same number of
429 reference sequences. The requirement can be relaxed. In addition,
430 merging does not reconstruct the header dictionaries
431 automatically. Endusers have to provide the correct header. Picard is
434 Samtools' rmdup does not work for single-end data and does not remove
435 duplicates across chromosomes. Picard is better.
439 Heng Li from the Sanger Institute wrote the C version of samtools. Bob
440 Handsaker from the Broad Institute implemented the BGZF library and Jue
441 Ruan from Beijing Genomics Institute wrote the RAZF library. Various
442 people in the 1000Genomes Project contributed to the SAM format
447 Samtools website: <http://samtools.sourceforge.net>