]> git.donarmstrong.com Git - samtools.git/blob - samtools.1
backup commit
[samtools.git] / samtools.1
1 .TH samtools 1 "2 September 2011" "samtools-0.1.18" "Bioinformatics tools"
2 .SH NAME
3 .PP
4 samtools - Utilities for the Sequence Alignment/Map (SAM) format
5
6 bcftools - Utilities for the Binary Call Format (BCF) and VCF
7 .SH SYNOPSIS
8 .PP
9 samtools view -bt ref_list.txt -o aln.bam aln.sam.gz
10 .PP
11 samtools sort aln.bam aln.sorted
12 .PP
13 samtools index aln.sorted.bam
14 .PP
15 samtools idxstats aln.sorted.bam
16 .PP
17 samtools view aln.sorted.bam chr2:20,100,000-20,200,000
18 .PP
19 samtools merge out.bam in1.bam in2.bam in3.bam
20 .PP
21 samtools faidx ref.fasta
22 .PP
23 samtools pileup -vcf ref.fasta aln.sorted.bam
24 .PP
25 samtools mpileup -C50 -gf ref.fasta -r chr3:1,000-2,000 in1.bam in2.bam
26 .PP
27 samtools tview aln.sorted.bam ref.fasta
28 .PP
29 bcftools index in.bcf
30 .PP
31 bcftools view in.bcf chr2:100-200 > out.vcf
32 .PP
33 bcftools view -Nvm0.99 in.bcf > out.vcf 2> out.afs
34
35 .SH DESCRIPTION
36 .PP
37 Samtools is a set of utilities that manipulate alignments in the BAM
38 format. It imports from and exports to the SAM (Sequence Alignment/Map)
39 format, does sorting, merging and indexing, and allows to retrieve reads
40 in any regions swiftly.
41
42 Samtools is designed to work on a stream. It regards an input file `-'
43 as the standard input (stdin) and an output file `-' as the standard
44 output (stdout). Several commands can thus be combined with Unix
45 pipes. Samtools always output warning and error messages to the standard
46 error output (stderr).
47
48 Samtools is also able to open a BAM (not SAM) file on a remote FTP or
49 HTTP server if the BAM file name starts with `ftp://' or `http://'.
50 Samtools checks the current working directory for the index file and
51 will download the index upon absence. Samtools does not retrieve the
52 entire alignment file unless it is asked to do so.
53
54 .SH SAMTOOLS COMMANDS AND OPTIONS
55
56 .TP 10
57 .B view
58 samtools view [-bchuHS] [-t in.refList] [-o output] [-f reqFlag] [-F
59 skipFlag] [-q minMapQ] [-l library] [-r readGroup] [-R rgFile] <in.bam>|<in.sam> [region1 [...]]
60
61 Extract/print all or sub alignments in SAM or BAM format. If no region
62 is specified, all the alignments will be printed; otherwise only
63 alignments overlapping the specified regions will be output. An
64 alignment may be given multiple times if it is overlapping several
65 regions. A region can be presented, for example, in the following
66 format: `chr2' (the whole chr2), `chr2:1000000' (region starting from
67 1,000,000bp) or `chr2:1,000,000-2,000,000' (region between 1,000,000 and
68 2,000,000bp including the end points). The coordinate is 1-based.
69
70 .B OPTIONS:
71 .RS
72 .TP 10
73 .B -b
74 Output in the BAM format.
75 .TP
76 .BI -f \ INT
77 Only output alignments with all bits in INT present in the FLAG
78 field. INT can be in hex in the format of /^0x[0-9A-F]+/ [0]
79 .TP
80 .BI -F \ INT
81 Skip alignments with bits present in INT [0]
82 .TP
83 .B -h
84 Include the header in the output.
85 .TP
86 .B -H
87 Output the header only.
88 .TP
89 .BI -l \ STR
90 Only output reads in library STR [null]
91 .TP
92 .BI -o \ FILE
93 Output file [stdout]
94 .TP
95 .BI -q \ INT
96 Skip alignments with MAPQ smaller than INT [0]
97 .TP
98 .BI -r \ STR
99 Only output reads in read group STR [null]
100 .TP
101 .BI -R \ FILE
102 Output reads in read groups listed in
103 .I FILE
104 [null]
105 .TP
106 .BI -s \ FLOAT
107 Fraction of templates/pairs to subsample; the integer part is treated as the
108 seed for the random number generator [-1]
109 .TP
110 .B -S
111 Input is in SAM. If @SQ header lines are absent, the
112 .B `-t'
113 option is required.
114 .TP
115 .B -c
116 Instead of printing the alignments, only count them and print the
117 total number. All filter options, such as
118 .B `-f',
119 .B `-F'
120 and
121 .B `-q'
122 , are taken into account.
123 .TP
124 .BI -t \ FILE
125 This file is TAB-delimited. Each line must contain the reference name
126 and the length of the reference, one line for each distinct reference;
127 additional fields are ignored. This file also defines the order of the
128 reference sequences in sorting. If you run `samtools faidx <ref.fa>',
129 the resultant index file
130 .I <ref.fa>.fai
131 can be used as this
132 .I <in.ref_list>
133 file.
134 .TP
135 .B -u
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.
139 .RE
140
141 .TP
142 .B tview
143 samtools tview 
144 .RB [ \-p 
145 .IR chr:pos ]
146 .RB [ \-s 
147 .IR STR ]
148 .RB [ \-d 
149 .IR display ] 
150 .RI <in.sorted.bam> 
151 .RI [ref.fasta]
152
153 Text alignment viewer (based on the ncurses library). In the viewer,
154 press `?' for help and press `g' to check the alignment start from a
155 region in the format like `chr10:10,000,000' or `=10,000,000' when
156 viewing the same reference sequence.
157
158 .B Options:
159 .RS
160 .TP 14
161 .BI -d \ display
162 Output as (H)tml or (C)urses or (T)ext
163 .TP
164 .BI -p \ chr:pos
165 Go directly to this position
166 .TP
167 .BI -s \ STR
168 Display only reads from this sample or read group
169 .RE
170
171 .TP
172 .B mpileup
173 samtools mpileup
174 .RB [ \-EBugp ]
175 .RB [ \-C
176 .IR capQcoef ]
177 .RB [ \-r
178 .IR reg ]
179 .RB [ \-f
180 .IR in.fa ]
181 .RB [ \-l
182 .IR list ]
183 .RB [ \-M
184 .IR capMapQ ]
185 .RB [ \-Q
186 .IR minBaseQ ]
187 .RB [ \-q
188 .IR minMapQ ]
189 .I in.bam
190 .RI [ in2.bam
191 .RI [ ... ]]
192
193 Generate BCF or pileup for one or multiple BAM files. Alignment records
194 are grouped by sample identifiers in @RG header lines. If sample
195 identifiers are absent, each input file is regarded as one sample.
196
197 In the pileup format (without
198 .BR -u or -g ),
199 each
200 line represents a genomic position, consisting of chromosome name,
201 coordinate, reference base, read bases, read qualities and alignment
202 mapping qualities. Information on match, mismatch, indel, strand,
203 mapping quality and start and end of a read are all encoded at the read
204 base column. At this column, a dot stands for a match to the reference
205 base on the forward strand, a comma for a match on the reverse strand,
206 a '>' or '<' for a reference skip, `ACGTN' for a mismatch on the forward
207 strand and `acgtn' for a mismatch on the reverse strand. A pattern
208 `\\+[0-9]+[ACGTNacgtn]+' indicates there is an insertion between this
209 reference position and the next reference position. The length of the
210 insertion is given by the integer in the pattern, followed by the
211 inserted sequence. Similarly, a pattern `-[0-9]+[ACGTNacgtn]+'
212 represents a deletion from the reference. The deleted bases will be
213 presented as `*' in the following lines. Also at the read base column, a
214 symbol `^' marks the start of a read. The ASCII of the character
215 following `^' minus 33 gives the mapping quality. A symbol `$' marks the
216 end of a read segment.
217
218 .B Input Options:
219 .RS
220 .TP 10
221 .B -6
222 Assume the quality is in the Illumina 1.3+ encoding.
223 .B -A
224 Do not skip anomalous read pairs in variant calling.
225 .TP
226 .B -B
227 Disable probabilistic realignment for the computation of base alignment
228 quality (BAQ). BAQ is the Phred-scaled probability of a read base being
229 misaligned. Applying this option greatly helps to reduce false SNPs
230 caused by misalignments.
231 .TP
232 .BI -b \ FILE
233 List of input BAM files, one file per line [null]
234 .TP
235 .BI -C \ INT
236 Coefficient for downgrading mapping quality for reads containing
237 excessive mismatches. Given a read with a phred-scaled probability q of
238 being generated from the mapped position, the new mapping quality is
239 about sqrt((INT-q)/INT)*INT. A zero value disables this
240 functionality; if enabled, the recommended value for BWA is 50. [0]
241 .TP
242 .BI -d \ INT
243 At a position, read maximally
244 .I INT
245 reads per input BAM. [250]
246 .TP
247 .B -E
248 Extended BAQ computation. This option helps sensitivity especially for MNPs, but may hurt
249 specificity a little bit.
250 .TP
251 .BI -f \ FILE
252 The
253 .BR faidx -indexed
254 reference file in the FASTA format. The file can be optionally compressed by
255 .BR razip .
256 [null]
257 .TP
258 .BI -l \ FILE
259 BED or position list file containing a list of regions or sites where pileup or BCF should be generated [null]
260 .TP
261 .BI -q \ INT
262 Minimum mapping quality for an alignment to be used [0]
263 .TP
264 .BI -Q \ INT
265 Minimum base quality for a base to be considered [13]
266 .TP
267 .BI -r \ STR
268 Only generate pileup in region
269 .I STR
270 [all sites]
271 .TP
272 .B Output Options:
273
274 .TP
275 .B -D
276 Output per-sample read depth
277 .TP
278 .B -g
279 Compute genotype likelihoods and output them in the binary call format (BCF).
280 .TP
281 .B -S
282 Output per-sample Phred-scaled strand bias P-value
283 .TP
284 .B -u
285 Similar to
286 .B -g
287 except that the output is uncompressed BCF, which is preferred for piping.
288
289 .TP
290 .B Options for Genotype Likelihood Computation (for -g or -u):
291
292 .TP
293 .BI -e \ INT
294 Phred-scaled gap extension sequencing error probability. Reducing
295 .I INT
296 leads to longer indels. [20]
297 .TP
298 .BI -h \ INT
299 Coefficient for modeling homopolymer errors. Given an
300 .IR l -long
301 homopolymer
302 run, the sequencing error of an indel of size
303 .I s
304 is modeled as
305 .IR INT * s / l .
306 [100]
307 .TP
308 .B -I
309 Do not perform INDEL calling
310 .TP
311 .BI -L \ INT
312 Skip INDEL calling if the average per-sample depth is above
313 .IR INT .
314 [250]
315 .TP
316 .BI -o \ INT
317 Phred-scaled gap open sequencing error probability. Reducing
318 .I INT
319 leads to more indel calls. [40]
320 .TP
321 .BI -p
322 Apply -m and -F thresholds per sample to increase sensitivity of calling.
323 By default both options are applied to reads pooled from all samples.
324 .TP
325 .BI -P \ STR
326 Comma dilimited list of platforms (determined by
327 .BR @RG-PL )
328 from which indel candidates are obtained. It is recommended to collect
329 indel candidates from sequencing technologies that have low indel error
330 rate such as ILLUMINA. [all]
331 .RE
332
333 .TP
334 .B reheader
335 samtools reheader <in.header.sam> <in.bam>
336
337 Replace the header in
338 .I in.bam
339 with the header in
340 .I in.header.sam.
341 This command is much faster than replacing the header with a
342 BAM->SAM->BAM conversion.
343
344 .TP
345 .B cat
346 samtools cat [-h header.sam] [-o out.bam] <in1.bam> <in2.bam> [ ... ]
347
348 Concatenate BAMs. The sequence dictionary of each input BAM must be identical,
349 although this command does not check this. This command uses a similar trick
350 to
351 .B reheader
352 which enables fast BAM concatenation.
353
354 .TP
355 .B sort
356 samtools sort [-no] [-m maxMem] <in.bam> <out.prefix>
357
358 Sort alignments by leftmost coordinates. File
359 .I <out.prefix>.bam
360 will be created. This command may also create temporary files
361 .I <out.prefix>.%d.bam
362 when the whole alignment cannot be fitted into memory (controlled by
363 option -m).
364
365 .B OPTIONS:
366 .RS
367 .TP 8
368 .B -o
369 Output the final alignment to the standard output.
370 .TP
371 .B -n
372 Sort by read names rather than by chromosomal coordinates
373 .TP
374 .BI -m \ INT
375 Approximately the maximum required memory. [500000000]
376 .RE
377
378 .TP
379 .B merge
380 samtools merge [-nur1f] [-h inh.sam] [-R reg] <out.bam> <in1.bam> <in2.bam> [...]
381
382 Merge multiple sorted alignments.
383 The header reference lists of all the input BAM files, and the @SQ headers of
384 .IR inh.sam ,
385 if any, must all refer to the same set of reference sequences.
386 The header reference list and (unless overridden by
387 .BR -h )
388 `@' headers of
389 .I in1.bam
390 will be copied to
391 .IR out.bam ,
392 and the headers of other files will be ignored.
393
394 .B OPTIONS:
395 .RS
396 .TP 8
397 .B -1
398 Use zlib compression level 1 to comrpess the output
399 .TP
400 .B -f
401 Force to overwrite the output file if present.
402 .TP 8
403 .BI -h \ FILE
404 Use the lines of
405 .I FILE
406 as `@' headers to be copied to
407 .IR out.bam ,
408 replacing any header lines that would otherwise be copied from
409 .IR in1.bam .
410 .RI ( FILE
411 is actually in SAM format, though any alignment records it may contain
412 are ignored.)
413 .TP
414 .B -n
415 The input alignments are sorted by read names rather than by chromosomal
416 coordinates
417 .TP
418 .BI -R \ STR
419 Merge files in the specified region indicated by
420 .I STR
421 [null]
422 .TP
423 .B -r
424 Attach an RG tag to each alignment. The tag value is inferred from file names.
425 .TP
426 .B -u
427 Uncompressed BAM output
428 .RE
429
430 .TP
431 .B index
432 samtools index <aln.bam>
433
434 Index sorted alignment for fast random access. Index file
435 .I <aln.bam>.bai
436 will be created.
437
438 .TP
439 .B idxstats
440 samtools idxstats <aln.bam>
441
442 Retrieve and print stats in the index file. The output is TAB delimited
443 with each line consisting of reference sequence name, sequence length, #
444 mapped reads and # unmapped reads.
445
446 .TP
447 .B faidx
448 samtools faidx <ref.fasta> [region1 [...]]
449
450 Index reference sequence in the FASTA format or extract subsequence from
451 indexed reference sequence. If no region is specified,
452 .B faidx
453 will index the file and create
454 .I <ref.fasta>.fai
455 on the disk. If regions are speficified, the subsequences will be
456 retrieved and printed to stdout in the FASTA format. The input file can
457 be compressed in the
458 .B RAZF
459 format.
460
461 .TP
462 .B fixmate
463 samtools fixmate <in.nameSrt.bam> <out.bam>
464
465 Fill in mate coordinates, ISIZE and mate related flags from a
466 name-sorted alignment.
467
468 .TP
469 .B rmdup
470 samtools rmdup [-sS] <input.srt.bam> <out.bam>
471
472 Remove potential PCR duplicates: if multiple read pairs have identical
473 external coordinates, only retain the pair with highest mapping quality.
474 In the paired-end mode, this command
475 .B ONLY
476 works with FR orientation and requires ISIZE is correctly set. It does
477 not work for unpaired reads (e.g. two ends mapped to different
478 chromosomes or orphan reads).
479
480 .B OPTIONS:
481 .RS
482 .TP 8
483 .B -s
484 Remove duplicate for single-end reads. By default, the command works for
485 paired-end reads only.
486 .TP 8
487 .B -S
488 Treat paired-end reads and single-end reads.
489 .RE
490
491 .TP
492 .B calmd
493 samtools calmd [-EeubSr] [-C capQcoef] <aln.bam> <ref.fasta>
494
495 Generate the MD tag. If the MD tag is already present, this command will
496 give a warning if the MD tag generated is different from the existing
497 tag. Output SAM by default.
498
499 .B OPTIONS:
500 .RS
501 .TP 8
502 .B -A
503 When used jointly with
504 .B -r
505 this option overwrites the original base quality.
506 .TP 8
507 .B -e
508 Convert a the read base to = if it is identical to the aligned reference
509 base. Indel caller does not support the = bases at the moment.
510 .TP
511 .B -u
512 Output uncompressed BAM
513 .TP
514 .B -b
515 Output compressed BAM
516 .TP
517 .B -S
518 The input is SAM with header lines
519 .TP
520 .BI -C \ INT
521 Coefficient to cap mapping quality of poorly mapped reads. See the
522 .B pileup
523 command for details. [0]
524 .TP
525 .B -r
526 Compute the BQ tag (without -A) or cap base quality by BAQ (with -A).
527 .TP
528 .B -E
529 Extended BAQ calculation. This option trades specificity for sensitivity, though the
530 effect is minor.
531 .RE
532
533 .TP
534 .B targetcut
535 samtools targetcut [-Q minBaseQ] [-i inPenalty] [-0 em0] [-1 em1] [-2 em2] [-f ref] <in.bam>
536
537 This command identifies target regions by examining the continuity of read depth, computes
538 haploid consensus sequences of targets and outputs a SAM with each sequence corresponding
539 to a target. When option
540 .B -f
541 is in use, BAQ will be applied. This command is
542 .B only
543 designed for cutting fosmid clones from fosmid pool sequencing [Ref. Kitzman et al. (2010)].
544 .RE
545
546 .TP
547 .B phase
548 samtools phase [-AF] [-k len] [-b prefix] [-q minLOD] [-Q minBaseQ] <in.bam>
549
550 Call and phase heterozygous SNPs.
551 .B OPTIONS:
552 .RS
553 .TP 8
554 .B -A
555 Drop reads with ambiguous phase.
556 .TP 8
557 .BI -b \ STR
558 Prefix of BAM output. When this option is in use, phase-0 reads will be saved in file
559 .BR STR .0.bam
560 and phase-1 reads in
561 .BR STR .1.bam.
562 Phase unknown reads will be randomly allocated to one of the two files. Chimeric reads
563 with switch errors will be saved in
564 .BR STR .chimeric.bam.
565 [null]
566 .TP
567 .B -F
568 Do not attempt to fix chimeric reads.
569 .TP
570 .BI -k \ INT
571 Maximum length for local phasing. [13]
572 .TP
573 .BI -q \ INT
574 Minimum Phred-scaled LOD to call a heterozygote. [40]
575 .TP
576 .BI -Q \ INT
577 Minimum base quality to be used in het calling. [13]
578 .RE
579
580 .SH BCFTOOLS COMMANDS AND OPTIONS
581
582 .TP 10
583 .B view
584 .B bcftools view
585 .RB [ \-AbFGNQSucgv ]
586 .RB [ \-D
587 .IR seqDict ]
588 .RB [ \-l
589 .IR listLoci ]
590 .RB [ \-s
591 .IR listSample ]
592 .RB [ \-i
593 .IR gapSNPratio ]
594 .RB [ \-t
595 .IR mutRate ]
596 .RB [ \-p
597 .IR varThres ]
598 .RB [ \-m
599 .IR varThres ]
600 .RB [ \-P
601 .IR prior ]
602 .RB [ \-1
603 .IR nGroup1 ]
604 .RB [ \-d
605 .IR minFrac ]
606 .RB [ \-U
607 .IR nPerm ]
608 .RB [ \-X
609 .IR permThres ]
610 .RB [ \-T
611 .IR trioType ]
612 .I in.bcf
613 .RI [ region ]
614
615 Convert between BCF and VCF, call variant candidates and estimate allele
616 frequencies.
617
618 .RS
619 .TP
620 .B Input/Output Options:
621 .TP 10
622 .B -A
623 Retain all possible alternate alleles at variant sites. By default, the view
624 command discards unlikely alleles.
625 .TP 10
626 .B -b
627 Output in the BCF format. The default is VCF.
628 .TP
629 .BI -D \ FILE
630 Sequence dictionary (list of chromosome names) for VCF->BCF conversion [null]
631 .TP
632 .B -F
633 Indicate PL is generated by r921 or before (ordering is different).
634 .TP
635 .B -G
636 Suppress all individual genotype information.
637 .TP
638 .BI -l \ FILE
639 List of sites at which information are outputted [all sites]
640 .TP
641 .B -N
642 Skip sites where the REF field is not A/C/G/T
643 .TP
644 .B -Q
645 Output the QCALL likelihood format
646 .TP
647 .BI -s \ FILE
648 List of samples to use. The first column in the input gives the sample names
649 and the second gives the ploidy, which can only be 1 or 2. When the 2nd column
650 is absent, the sample ploidy is assumed to be 2. In the output, the ordering of
651 samples will be identical to the one in
652 .IR FILE .
653 [null]
654 .TP
655 .B -S
656 The input is VCF instead of BCF.
657 .TP
658 .B -u
659 Uncompressed BCF output (force -b).
660 .TP
661 .B Consensus/Variant Calling Options:
662 .TP 10
663 .B -c
664 Call variants using Bayesian inference. This option automatically invokes option
665 .BR -e .
666 .TP
667 .BI -d \ FLOAT
668 When
669 .B -v
670 is in use, skip loci where the fraction of samples covered by reads is below FLOAT. [0]
671 .TP
672 .B -e
673 Perform max-likelihood inference only, including estimating the site allele frequency,
674 testing Hardy-Weinberg equlibrium and testing associations with LRT.
675 .TP
676 .B -g
677 Call per-sample genotypes at variant sites (force -c)
678 .TP
679 .BI -i \ FLOAT
680 Ratio of INDEL-to-SNP mutation rate [0.15]
681 .TP
682 .BI -m \ FLOAT
683 New model for improved multiallelic and rare-variant calling. Another
684 ALT allele is accepted if P(chi^2) of LRT exceeds the FLOAT threshold. The 
685 parameter seems robust and the actual value usually does not affect the results
686 much; a good value to use is 0.99. This is the recommended calling method. [0]
687 .TP
688 .BI -p \ FLOAT
689 A site is considered to be a variant if P(ref|D)<FLOAT [0.5]
690 .TP
691 .BI -P \ STR
692 Prior or initial allele frequency spectrum. If STR can be
693 .IR full ,
694 .IR cond2 ,
695 .I flat
696 or the file consisting of error output from a previous variant calling
697 run.
698 .TP
699 .BI -t \ FLOAT
700 Scaled muttion rate for variant calling [0.001]
701 .TP
702 .BI -T \ STR
703 Enable pair/trio calling. For trio calling, option
704 .B -s
705 is usually needed to be applied to configure the trio members and their ordering.
706 In the file supplied to the option
707 .BR -s ,
708 the first sample must be the child, the second the father and the third the mother.
709 The valid values of
710 .I STR
711 are `pair', `trioauto', `trioxd' and `trioxs', where `pair' calls differences between two input samples, and `trioxd' (`trioxs') specifies that the input
712 is from the X chromosome non-PAR regions and the child is a female (male). [null]
713 .TP
714 .B -v
715 Output variant sites only (force -c)
716 .TP
717 .B Contrast Calling and Association Test Options:
718 .TP
719 .BI -1 \ INT
720 Number of group-1 samples. This option is used for dividing the samples into
721 two groups for contrast SNP calling or association test.
722 When this option is in use, the following VCF INFO will be outputted:
723 PC2, PCHI2 and QCHI2. [0]
724 .TP
725 .BI -U \ INT
726 Number of permutations for association test (effective only with
727 .BR -1 )
728 [0]
729 .TP
730 .BI -X \ FLOAT
731 Only perform permutations for P(chi^2)<FLOAT (effective only with
732 .BR -U )
733 [0.01]
734 .RE
735
736 .TP
737 .B index
738 .B bcftools index
739 .I in.bcf
740
741 Index sorted BCF for random access.
742 .RE
743
744 .TP
745 .B cat
746 .B bcftools cat
747 .I in1.bcf
748 .RI [ "in2.bcf " [ ... "]]]"
749
750 Concatenate BCF files. The input files are required to be sorted and
751 have identical samples appearing in the same order.
752 .RE
753 .SH SAM FORMAT
754
755 Sequence Alignment/Map (SAM) format is TAB-delimited. Apart from the header lines, which are started
756 with the `@' symbol, each alignment line consists of:
757
758 .TS
759 center box;
760 cb | cb | cb
761 n | l | l .
762 Col     Field   Description
763 _
764 1       QNAME   Query template/pair NAME
765 2       FLAG    bitwise FLAG
766 3       RNAME   Reference sequence NAME
767 4       POS     1-based leftmost POSition/coordinate of clipped sequence
768 5       MAPQ    MAPping Quality (Phred-scaled)
769 6       CIAGR   extended CIGAR string
770 7       MRNM    Mate Reference sequence NaMe (`=' if same as RNAME)
771 8       MPOS    1-based Mate POSistion
772 9       TLEN    inferred Template LENgth (insert size)
773 10      SEQ     query SEQuence on the same strand as the reference
774 11      QUAL    query QUALity (ASCII-33 gives the Phred base quality)
775 12+     OPT     variable OPTional fields in the format TAG:VTYPE:VALUE
776 .TE
777
778 .PP
779 Each bit in the FLAG field is defined as:
780
781 .TS
782 center box;
783 cb | cb | cb
784 l | c | l .
785 Flag    Chr     Description
786 _
787 0x0001  p       the read is paired in sequencing
788 0x0002  P       the read is mapped in a proper pair
789 0x0004  u       the query sequence itself is unmapped
790 0x0008  U       the mate is unmapped
791 0x0010  r       strand of the query (1 for reverse)
792 0x0020  R       strand of the mate
793 0x0040  1       the read is the first read in a pair
794 0x0080  2       the read is the second read in a pair
795 0x0100  s       the alignment is not primary
796 0x0200  f       the read fails platform/vendor quality checks
797 0x0400  d       the read is either a PCR or an optical duplicate
798 .TE
799
800 where the second column gives the string representation of the FLAG field.
801
802 .SH VCF FORMAT
803
804 The Variant Call Format (VCF) is a TAB-delimited format with each data line consists of the following fields:
805 .TS
806 center box;
807 cb | cb | cb
808 n | l | l .
809 Col     Field   Description
810 _
811 1       CHROM   CHROMosome name
812 2       POS     the left-most POSition of the variant
813 3       ID      unique variant IDentifier
814 4       REF     the REFerence allele
815 5       ALT     the ALTernate allele(s), separated by comma
816 6       QUAL    variant/reference QUALity
817 7       FILTER  FILTers applied
818 8       INFO    INFOrmation related to the variant, separated by semi-colon
819 9       FORMAT  FORMAT of the genotype fields, separated by colon (optional)
820 10+     SAMPLE  SAMPLE genotypes and per-sample information (optional)
821 .TE
822
823 .PP
824 The following table gives the
825 .B INFO
826 tags used by samtools and bcftools.
827
828 .TS
829 center box;
830 cb | cb | cb
831 l | l | l .
832 Tag     Format  Description
833 _
834 AF1     double  Max-likelihood estimate of the site allele frequency (AF) of the first ALT allele
835 DP      int     Raw read depth (without quality filtering)
836 DP4     int[4]  # high-quality reference forward bases, ref reverse, alternate for and alt rev bases
837 FQ      int     Consensus quality. Positive: sample genotypes different; negative: otherwise
838 MQ      int     Root-Mean-Square mapping quality of covering reads
839 PC2     int[2]  Phred probability of AF in group1 samples being larger (,smaller) than in group2
840 PCHI2   double  Posterior weighted chi^2 P-value between group1 and group2 samples
841 PV4     double[4]       P-value for strand bias, baseQ bias, mapQ bias and tail distance bias
842 QCHI2   int     Phred-scaled PCHI2
843 RP      int     # permutations yielding a smaller PCHI2
844 CLR     int     Phred log ratio of genotype likelihoods with and without the trio/pair constraint
845 UGT     string  Most probable genotype configuration without the trio constraint
846 CGT     string  Most probable configuration with the trio constraint
847 VDB     float   Tests variant positions within reads. Intended for filtering RNA-seq artifacts around splice sites
848 RPB     float   Mann-Whitney rank-sum test for tail distance bias
849 HWE     float   Hardy-Weinberg equilibrium test, Wigginton et al., PMID: 15789306
850 .TE
851
852 .SH EXAMPLES
853 .IP o 2
854 Import SAM to BAM when
855 .B @SQ
856 lines are present in the header:
857
858   samtools view -bS aln.sam > aln.bam
859
860 If
861 .B @SQ
862 lines are absent:
863
864   samtools faidx ref.fa
865   samtools view -bt ref.fa.fai aln.sam > aln.bam
866
867 where
868 .I ref.fa.fai
869 is generated automatically by the
870 .B faidx
871 command.
872
873 .IP o 2
874 Attach the
875 .B RG
876 tag while merging sorted alignments:
877
878   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
879   samtools merge -rh rg.txt merged.bam ga.bam 454.bam
880
881 The value in a
882 .B RG
883 tag is determined by the file name the read is coming from. In this
884 example, in the
885 .IR merged.bam ,
886 reads from
887 .I ga.bam
888 will be attached 
889 .IR RG:Z:ga ,
890 while reads from
891 .I 454.bam
892 will be attached
893 .IR RG:Z:454 .
894
895 .IP o 2
896 Call SNPs and short INDELs for one diploid individual:
897
898   samtools mpileup -ugf ref.fa aln.bam | bcftools view -bvcg - > var.raw.bcf
899   bcftools view var.raw.bcf | vcfutils.pl varFilter -D 100 > var.flt.vcf
900
901 The
902 .B -D
903 option of varFilter controls the maximum read depth, which should be
904 adjusted to about twice the average read depth.  One may consider to add
905 .B -C50
906 to
907 .B mpileup
908 if mapping quality is overestimated for reads containing excessive
909 mismatches. Applying this option usually helps
910 .B BWA-short
911 but may not other mappers.
912
913 .IP o 2
914 Generate the consensus sequence for one diploid individual:
915
916   samtools mpileup -uf ref.fa aln.bam | bcftools view -cg - | vcfutils.pl vcf2fq > cns.fq
917
918 .IP o 2
919 Call somatic mutations from a pair of samples:
920
921   samtools mpileup -DSuf ref.fa aln.bam | bcftools view -bvcgT pair - > var.bcf
922
923 In the output INFO field,
924 .I CLR
925 gives the Phred-log ratio between the likelihood by treating the
926 two samples independently, and the likelihood by requiring the genotype to be identical.
927 This
928 .I CLR
929 is effectively a score measuring the confidence of somatic calls. The higher the better.
930
931 .IP o 2
932 Call de novo and somatic mutations from a family trio:
933
934   samtools mpileup -DSuf ref.fa aln.bam | bcftools view -bvcgT pair -s samples.txt - > var.bcf
935
936 File
937 .I samples.txt
938 should consist of three lines specifying the member and order of samples (in the order of child-father-mother).
939 Similarly,
940 .I CLR
941 gives the Phred-log likelihood ratio with and without the trio constraint.
942 .I UGT
943 shows the most likely genotype configuration without the trio constraint, and
944 .I CGT
945 gives the most likely genotype configuration satisfying the trio constraint.
946
947 .IP o 2
948 Phase one individual:
949
950   samtools calmd -AEur aln.bam ref.fa | samtools phase -b prefix - > phase.out
951
952 The
953 .B calmd
954 command is used to reduce false heterozygotes around INDELs.
955
956 .IP o 2
957 Call SNPs and short indels for multiple diploid individuals:
958
959   samtools mpileup -P ILLUMINA -ugf ref.fa *.bam | bcftools view -bcvg - > var.raw.bcf
960   bcftools view var.raw.bcf | vcfutils.pl varFilter -D 2000 > var.flt.vcf
961
962 Individuals are identified from the
963 .B SM
964 tags in the
965 .B @RG
966 header lines. Individuals can be pooled in one alignment file; one
967 individual can also be separated into multiple files. The
968 .B -P
969 option specifies that indel candidates should be collected only from
970 read groups with the
971 .B @RG-PL
972 tag set to
973 .IR ILLUMINA .
974 Collecting indel candidates from reads sequenced by an indel-prone
975 technology may affect the performance of indel calling.
976
977 .IP o 2
978 Derive the allele frequency spectrum (AFS) on a list of sites from multiple individuals:
979
980   samtools mpileup -Igf ref.fa *.bam > all.bcf
981   bcftools view -bl sites.list all.bcf > sites.bcf
982   bcftools view -cGP cond2 sites.bcf > /dev/null 2> sites.1.afs
983   bcftools view -cGP sites.1.afs sites.bcf > /dev/null 2> sites.2.afs
984   bcftools view -cGP sites.2.afs sites.bcf > /dev/null 2> sites.3.afs
985   ......
986
987 where
988 .I sites.list
989 contains the list of sites with each line consisting of the reference
990 sequence name and position. The following
991 .B bcftools
992 commands estimate AFS by EM.
993
994 .IP o 2
995 Dump BAQ applied alignment for other SNP callers:
996
997   samtools calmd -bAr aln.bam > aln.baq.bam
998
999 It adds and corrects the
1000 .B NM
1001 and
1002 .B MD
1003 tags at the same time. The
1004 .B calmd
1005 command also comes with the
1006 .B -C
1007 option, the same as the one in
1008 .B pileup
1009 and
1010 .BR mpileup .
1011 Apply if it helps.
1012
1013 .SH LIMITATIONS
1014 .PP
1015 .IP o 2
1016 Unaligned words used in bam_import.c, bam_endian.h, bam.c and bam_aux.c.
1017 .IP o 2
1018 Samtools paired-end rmdup does not work for unpaired reads (e.g. orphan
1019 reads or ends mapped to different chromosomes). If this is a concern,
1020 please use Picard's MarkDuplicate which correctly handles these cases,
1021 although a little slower.
1022
1023 .SH AUTHOR
1024 .PP
1025 Heng Li from the Sanger Institute wrote the C version of samtools. Bob
1026 Handsaker from the Broad Institute implemented the BGZF library and Jue
1027 Ruan from Beijing Genomics Institute wrote the RAZF library. John
1028 Marshall and Petr Danecek contribute to the source code and various
1029 people from the 1000 Genomes Project have contributed to the SAM format
1030 specification.
1031
1032 .SH SEE ALSO
1033 .PP
1034 Samtools website: <http://samtools.sourceforge.net>