1 .TH samtools 1 "16 March 2011" "samtools-0.1.14" "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 idxstats aln.sorted.bam
15 samtools view aln.sorted.bam chr2:20,100,000-20,200,000
17 samtools merge out.bam in1.bam in2.bam in3.bam
19 samtools faidx ref.fasta
21 samtools pileup -vcf ref.fasta aln.sorted.bam
23 samtools mpileup -C50 -gf ref.fasta -r chr3:1,000-2,000 in1.bam in2.bam
25 samtools tview aln.sorted.bam ref.fasta
29 Samtools is a set of utilities that manipulate alignments in the BAM
30 format. It imports from and exports to the SAM (Sequence Alignment/Map)
31 format, does sorting, merging and indexing, and allows to retrieve reads
32 in any regions swiftly.
34 Samtools is designed to work on a stream. It regards an input file `-'
35 as the standard input (stdin) and an output file `-' as the standard
36 output (stdout). Several commands can thus be combined with Unix
37 pipes. Samtools always output warning and error messages to the standard
38 error output (stderr).
40 Samtools is also able to open a BAM (not SAM) file on a remote FTP or
41 HTTP server if the BAM file name starts with `ftp://' or `http://'.
42 Samtools checks the current working directory for the index file and
43 will download the index upon absence. Samtools does not retrieve the
44 entire alignment file unless it is asked to do so.
46 .SH COMMANDS AND OPTIONS
50 samtools view [-bchuHS] [-t in.refList] [-o output] [-f reqFlag] [-F
51 skipFlag] [-q minMapQ] [-l library] [-r readGroup] [-R rgFile] <in.bam>|<in.sam> [region1 [...]]
53 Extract/print all or sub alignments in SAM or BAM format. If no region
54 is specified, all the alignments will be printed; otherwise only
55 alignments overlapping the specified regions will be output. An
56 alignment may be given multiple times if it is overlapping several
57 regions. A region can be presented, for example, in the following
58 format: `chr2' (the whole chr2), `chr2:1000000' (region starting from
59 1,000,000bp) or `chr2:1,000,000-2,000,000' (region between 1,000,000 and
60 2,000,000bp including the end points). The coordinate is 1-based.
66 Output in the BAM format.
69 Only output alignments with all bits in INT present in the FLAG
70 field. INT can be in hex in the format of /^0x[0-9A-F]+/ [0]
73 Skip alignments with bits present in INT [0]
76 Include the header in the output.
79 Output the header only.
82 Only output reads in library STR [null]
88 Skip alignments with MAPQ smaller than INT [0]
91 Only output reads in read group STR [null]
94 Output reads in read groups listed in
99 Input is in SAM. If @SQ header lines are absent, the
104 Instead of printing the alignments, only count them and print the
105 total number. All filter options, such as
110 , are taken into account.
113 This file is TAB-delimited. Each line must contain the reference name
114 and the length of the reference, one line for each distinct reference;
115 additional fields are ignored. This file also defines the order of the
116 reference sequences in sorting. If you run `samtools faidx <ref.fa>',
117 the resultant index file
124 Output uncompressed BAM. This option saves time spent on
125 compression/decomprssion and is thus preferred when the output is piped
126 to another samtools command.
131 samtools tview <in.sorted.bam> [ref.fasta]
133 Text alignment viewer (based on the ncurses library). In the viewer,
134 press `?' for help and press `g' to check the alignment start from a
135 region in the format like `chr10:10,000,000' or `=10,000,000' when
136 viewing the same reference sequence.
140 samtools mpileup [-EBug] [-C capQcoef] [-r reg] [-f in.fa] [-l list] [-M capMapQ] [-Q minBaseQ] [-q minMapQ] in.bam [in2.bam [...]]
142 Generate BCF or pileup for one or multiple BAM files. Alignment records
143 are grouped by sample identifiers in @RG header lines. If sample
144 identifiers are absent, each input file is regarded as one sample.
150 Do not skip anomalous read pairs in variant calling.
153 Disable probabilistic realignment for the computation of base alignment
154 quality (BAQ). BAQ is the Phred-scaled probability of a read base being
155 misaligned. Applying this option greatly helps to reduce false SNPs
156 caused by misalignments.
159 Coefficient for downgrading mapping quality for reads containing
160 excessive mismatches. Given a read with a phred-scaled probability q of
161 being generated from the mapped position, the new mapping quality is
162 about sqrt((INT-q)/INT)*INT. A zero value disables this
163 functionality; if enabled, the recommended value for BWA is 50. [0]
166 At a position, read maximally
168 reads per input BAM. [250]
171 Output per-sample read depth
174 Phred-scaled gap extension sequencing error probability. Reducing
176 leads to longer indels. [20]
179 Extended BAQ computation. This option helps sensitivity especially for MNPs, but may hurt
180 specificity a little bit.
183 The reference file [null]
186 Compute genotype likelihoods and output them in the binary call format (BCF).
189 Coefficient for modeling homopolymer errors. Given an
192 run, the sequencing error of an indel of size
199 Do not perform INDEL calling
202 File containing a list of sites where pileup or BCF is outputted [null]
205 Skip INDEL calling if the average per-sample depth is above
210 Phred-scaled gap open sequencing error probability. Reducing
212 leads to more indel calls. [40]
215 Comma dilimited list of platforms (determined by
217 from which indel candidates are obtained. It is recommended to collect
218 indel candidates from sequencing technologies that have low indel error
219 rate such as ILLUMINA. [all]
222 Minimum mapping quality for an alignment to be used [0]
225 Minimum base quality for a base to be considered [13]
228 Only generate pileup in region
233 Output per-sample Phred-scaled strand bias P-value
238 except that the output is uncompressed BCF, which is preferred for piping.
243 samtools reheader <in.header.sam> <in.bam>
245 Replace the header in
249 This command is much faster than replacing the header with a
250 BAM->SAM->BAM conversion.
254 samtools sort [-no] [-m maxMem] <in.bam> <out.prefix>
256 Sort alignments by leftmost coordinates. File
258 will be created. This command may also create temporary files
259 .I <out.prefix>.%d.bam
260 when the whole alignment cannot be fitted into memory (controlled by
267 Output the final alignment to the standard output.
270 Sort by read names rather than by chromosomal coordinates
273 Approximately the maximum required memory. [500000000]
278 samtools merge [-nur] [-h inh.sam] [-R reg] <out.bam> <in1.bam> <in2.bam> [...]
280 Merge multiple sorted alignments.
281 The header reference lists of all the input BAM files, and the @SQ headers of
283 if any, must all refer to the same set of reference sequences.
284 The header reference list and (unless overridden by
290 and the headers of other files will be ignored.
298 as `@' headers to be copied to
300 replacing any header lines that would otherwise be copied from
303 is actually in SAM format, though any alignment records it may contain
307 Merge files in the specified region indicated by
311 Attach an RG tag to each alignment. The tag value is inferred from file names.
314 The input alignments are sorted by read names rather than by chromosomal
318 Uncompressed BAM output
323 samtools index <aln.bam>
325 Index sorted alignment for fast random access. Index file
331 samtools idxstats <aln.bam>
333 Retrieve and print stats in the index file. The output is TAB delimited
334 with each line consisting of reference sequence name, sequence length, #
335 mapped reads and # unmapped reads.
339 samtools faidx <ref.fasta> [region1 [...]]
341 Index reference sequence in the FASTA format or extract subsequence from
342 indexed reference sequence. If no region is specified,
344 will index the file and create
346 on the disk. If regions are speficified, the subsequences will be
347 retrieved and printed to stdout in the FASTA format. The input file can
354 samtools fixmate <in.nameSrt.bam> <out.bam>
356 Fill in mate coordinates, ISIZE and mate related flags from a
357 name-sorted alignment.
361 samtools rmdup [-sS] <input.srt.bam> <out.bam>
363 Remove potential PCR duplicates: if multiple read pairs have identical
364 external coordinates, only retain the pair with highest mapping quality.
365 In the paired-end mode, this command
367 works with FR orientation and requires ISIZE is correctly set. It does
368 not work for unpaired reads (e.g. two ends mapped to different
369 chromosomes or orphan reads).
375 Remove duplicate for single-end reads. By default, the command works for
376 paired-end reads only.
379 Treat paired-end reads and single-end reads.
384 samtools calmd [-EeubSr] [-C capQcoef] <aln.bam> <ref.fasta>
386 Generate the MD tag. If the MD tag is already present, this command will
387 give a warning if the MD tag generated is different from the existing
388 tag. Output SAM by default.
394 When used jointly with
396 this option overwrites the original base quality.
399 Convert a the read base to = if it is identical to the aligned reference
400 base. Indel caller does not support the = bases at the moment.
403 Output uncompressed BAM
406 Output compressed BAM
409 The input is SAM with header lines
412 Coefficient to cap mapping quality of poorly mapped reads. See the
414 command for details. [0]
417 Compute the BQ tag (without -A) or cap base quality by BAQ (with -A).
420 Extended BAQ calculation. This option trades specificity for sensitivity, though the
426 samtools targetcut [-Q minBaseQ] [-i inPenalty] [-0 em0] [-1 em1] [-2 em2] [-f ref] <in.bam>
428 This command identifies target regions by examining the continuity of read depth, computes
429 haploid consensus sequences of targets and outputs a SAM with each sequence corresponding
430 to a target. When option
432 is in use, BAQ will be applied. This command is
434 designed for cutting fosmid clones from fosmid pool sequencing [Ref. Kitzman et al. (2010)].
439 samtools phase [-AF] [-k len] [-b prefix] [-q minLOD] [-Q minBaseQ] <in.bam>
441 Call and phase heterozygous SNPs.
446 Drop reads with ambiguous phase.
449 Prefix of BAM output. When this option is in use, phase-0 reads will be saved in file
453 Phase unknown reads will be randomly allocated to one of the two files. Chimeric reads
454 with switch errors will be saved in
455 .BR STR .chimeric.bam.
459 Do not attempt to fix chimeric reads.
462 Maximum length for local phasing. [13]
465 Minimum Phred-scaled LOD to call a heterozygote. [40]
468 Minimum base quality to be used in het calling. [13]
473 samtools pileup [-2sSBicv] [-f in.ref.fasta] [-t in.ref_list] [-l
474 in.site_list] [-C capMapQ] [-M maxMapQ] [-T theta] [-N nHap] [-r
475 pairDiffRate] [-m mask] [-d maxIndelDepth] [-G indelPrior]
478 Print the alignment in the pileup format. In the pileup format, each
479 line represents a genomic position, consisting of chromosome name,
480 coordinate, reference base, read bases, read qualities and alignment
481 mapping qualities. Information on match, mismatch, indel, strand,
482 mapping quality and start and end of a read are all encoded at the read
483 base column. At this column, a dot stands for a match to the reference
484 base on the forward strand, a comma for a match on the reverse strand,
485 a '>' or '<' for a reference skip, `ACGTN' for a mismatch on the forward
486 strand and `acgtn' for a mismatch on the reverse strand. A pattern
487 `\\+[0-9]+[ACGTNacgtn]+' indicates there is an insertion between this
488 reference position and the next reference position. The length of the
489 insertion is given by the integer in the pattern, followed by the
490 inserted sequence. Similarly, a pattern `-[0-9]+[ACGTNacgtn]+'
491 represents a deletion from the reference. The deleted bases will be
492 presented as `*' in the following lines. Also at the read base column, a
493 symbol `^' marks the start of a read. The ASCII of the character
494 following `^' minus 33 gives the mapping quality. A symbol `$' marks the
495 end of a read segment.
499 is applied, the consensus base, Phred-scaled consensus quality, SNP
500 quality (i.e. the Phred-scaled probability of the consensus being
501 identical to the reference) and root mean square (RMS) mapping quality
502 of the reads covering the site will be inserted between the `reference
503 base' and the `read bases' columns. An indel occupies an additional
504 line. Each indel line consists of chromosome name, coordinate, a star,
505 the genotype, consensus quality, SNP quality, RMS mapping quality, #
506 covering reads, the first alllele, the second allele, # reads supporting
507 the first allele, # reads supporting the second allele and # reads
508 containing indels different from the top two alleles.
511 Since 0.1.10, the `pileup' command is deprecated by `mpileup'.
517 Disable the BAQ computation. See the
522 Call the consensus sequence. Options
523 .BR -T ", " -N ", " -I " and " -r
524 are only effective when
529 Coefficient for downgrading the mapping quality of poorly mapped
532 command for details. [0]
537 reads in the pileup for indel calling for speed up. Zero for unlimited. [1024]
540 The reference sequence in the FASTA format. Index file
546 Generate genotype likelihood in the binary GLFv3 format. This option
547 suppresses -c, -i and -s. This option is deprecated by the
552 Only output pileup lines containing indels.
555 Phred probability of an indel in sequencing/prep. [40]
558 List of sites at which pileup is output. This file is space
559 delimited. The first two columns are required to be chromosome and
560 1-based coordinate. Additional columns are ignored. It is
561 recommended to use option
564 Filter reads with flag containing bits in
569 Cap mapping quality at INT [60]
572 Number of haplotypes in the sample (>=2) [2]
575 Expected fraction of differences between a pair of haplotypes [0.001]
578 Print the mapping quality as the last column. This option makes the
579 output easier to parse, although this format is not space efficient.
582 The input file is in SAM.
585 List of reference names ane sequence lengths, in the format described
588 command. If this option is present, samtools assumes the input
590 is in SAM format; otherwise it assumes in BAM format.
594 as in the default format we may not know the mapping quality.
597 The theta parameter (error dependency coefficient) in the maq consensus
603 SAM is TAB-delimited. Apart from the header lines, which are started
604 with the `@' symbol, each alignment line consists of:
610 Col Field Description
612 1 QNAME Query (pair) NAME
614 3 RNAME Reference sequence NAME
615 4 POS 1-based leftmost POSition/coordinate of clipped sequence
616 5 MAPQ MAPping Quality (Phred-scaled)
617 6 CIAGR extended CIGAR string
618 7 MRNM Mate Reference sequence NaMe (`=' if same as RNAME)
619 8 MPOS 1-based Mate POSistion
620 9 ISIZE Inferred insert SIZE
621 10 SEQ query SEQuence on the same strand as the reference
622 11 QUAL query QUALity (ASCII-33 gives the Phred base quality)
623 12 OPT variable OPTional fields in the format TAG:VTYPE:VALUE
627 Each bit in the FLAG field is defined as:
635 0x0001 p the read is paired in sequencing
636 0x0002 P the read is mapped in a proper pair
637 0x0004 u the query sequence itself is unmapped
638 0x0008 U the mate is unmapped
639 0x0010 r strand of the query (1 for reverse)
640 0x0020 R strand of the mate
641 0x0040 1 the read is the first read in a pair
642 0x0080 2 the read is the second read in a pair
643 0x0100 s the alignment is not primary
644 0x0200 f the read fails platform/vendor quality checks
645 0x0400 d the read is either a PCR or an optical duplicate
650 Import SAM to BAM when
652 lines are present in the header:
654 samtools view -bS aln.sam > aln.bam
660 samtools faidx ref.fa
661 samtools view -bt ref.fa.fai aln.sam > aln.bam
665 is generated automatically by the
672 tag while merging sorted alignments:
674 perl -e 'print "@RG\\tID:ga\\tSM:hs\\tLB:ga\\tPL:Illumina\\n@RG\\tID:454\\tSM:hs\\tLB:454\\tPL:454\\n"' > rg.txt
675 samtools merge -rh rg.txt merged.bam ga.bam 454.bam
679 tag is determined by the file name the read is coming from. In this
692 Call SNPs and short indels for one diploid individual:
694 samtools mpileup -ugf ref.fa aln.bam | bcftools view -bvcg - > var.raw.bcf
695 bcftools view var.raw.bcf | vcfutils.pl varFilter -D 100 > var.flt.vcf
699 option of varFilter controls the maximum read depth, which should be
700 adjusted to about twice the average read depth. One may consider to add
704 if mapping quality is overestimated for reads containing excessive
705 mismatches. Applying this option usually helps
707 but may not other mappers.
710 Generate the consensus sequence for one diploid individual:
712 samtools mpileup -uf ref.fa aln.bam | bcftools view -cg - | vcfutils.pl vcf2fq > cns.fq
715 Phase one individual:
717 samtools calmd -AEur aln.bam ref.fa | samtools phase -b prefix - > phase.out
721 command is used to reduce false heterozygotes around INDELs.
724 Call SNPs and short indels for multiple diploid individuals:
726 samtools mpileup -P ILLUMINA -ugf ref.fa *.bam | bcftools view -bcvg - > var.raw.bcf
727 bcftools view var.raw.bcf | vcfutils.pl varFilter -D 2000 > var.flt.vcf
729 Individuals are identified from the
733 header lines. Individuals can be pooled in one alignment file; one
734 individual can also be separated into multiple files. The
736 option specifies that indel candidates should be collected only from
741 Collecting indel candidates from reads sequenced by an indel-prone
742 technology may affect the performance of indel calling.
745 Derive the allele frequency spectrum (AFS) on a list of sites from multiple individuals:
747 samtools mpileup -Igf ref.fa *.bam > all.bcf
748 bcftools view -bl sites.list all.bcf > sites.bcf
749 bcftools view -cGP cond2 sites.bcf > /dev/null 2> sites.1.afs
750 bcftools view -cGP sites.1.afs sites.bcf > /dev/null 2> sites.2.afs
751 bcftools view -cGP sites.2.afs sites.bcf > /dev/null 2> sites.3.afs
756 contains the list of sites with each line consisting of the reference
757 sequence name and position. The following
759 commands estimate AFS by EM.
762 Dump BAQ applied alignment for other SNP callers:
764 samtools calmd -bAr aln.bam > aln.baq.bam
766 It adds and corrects the
770 tags at the same time. The
772 command also comes with the
774 option, the same as the one in
783 Unaligned words used in bam_import.c, bam_endian.h, bam.c and bam_aux.c.
785 In merging, the input files are required to have the same number of
786 reference sequences. The requirement can be relaxed. In addition,
787 merging does not reconstruct the header dictionaries
788 automatically. Endusers have to provide the correct header. Picard is
791 Samtools paired-end rmdup does not work for unpaired reads (e.g. orphan
792 reads or ends mapped to different chromosomes). If this is a concern,
793 please use Picard's MarkDuplicate which correctly handles these cases,
794 although a little slower.
798 Heng Li from the Sanger Institute wrote the C version of samtools. Bob
799 Handsaker from the Broad Institute implemented the BGZF library and Jue
800 Ruan from Beijing Genomics Institute wrote the RAZF library. John
801 Marshall and Petr Danecek contribute to the source code and various
802 people from the 1000 Genomes Project have contributed to the SAM format
807 Samtools website: <http://samtools.sourceforge.net>