+EXAMPLES
+ o Import SAM to BAM when @SQ lines are present in the header:
+
+ samtools view -bS aln.sam > aln.bam
+
+ If @SQ lines are absent:
+
+ samtools faidx ref.fa
+ samtools view -bt ref.fa.fai aln.sam > aln.bam
+
+ where ref.fa.fai is generated automatically by the faidx command.
+
+
+ o Attach the RG tag while merging sorted alignments:
+
+ perl -e 'print "@RG\tID:ga\tSM:hs\tLB:ga\tPL:Illu-
+ mina\n@RG\tID:454\tSM:hs\tLB:454\tPL:454\n"' > rg.txt
+ samtools merge -rh rg.txt merged.bam ga.bam 454.bam
+
+ The value in a RG tag is determined by the file name the read is com-
+ ing from. In this example, in the merged.bam, reads from ga.bam will
+ be attached RG:Z:ga, while reads from 454.bam will be attached
+ RG:Z:454.
+
+
+ o Call SNPs and short indels for one diploid individual:
+
+ samtools pileup -vcf ref.fa aln.bam > var.raw.plp
+ samtools.pl varFilter -D 100 var.raw.plp > var.flt.plp
+ awk '($3=="*"&&$6>=50)||($3!="*"&&$6>=20)' var.flt.plp >
+ var.final.plp
+
+ The -D option of varFilter controls the maximum read depth, which
+ should be adjusted to about twice the average read depth. One may
+ consider to add -C50 to pileup if mapping quality is overestimated
+ for reads containing excessive mismatches. Applying this option usu-
+ ally helps BWA-short but may not other mappers. It also potentially
+ increases reference biases.
+
+
+ o Call SNPs (not short indels) for multiple diploid individuals:
+
+ samtools mpileup -augf ref.fa *.bam | bcftools view -bcv - >
+ snp.raw.bcf
+ bcftools view snp.raw.bcf | vcfutils.pl filter4vcf -D 2000 | bgzip
+ > snp.flt.vcf.gz
+
+ Individuals are identified from the SM tags in the @RG header lines.
+ Individuals can be pooled in one alignment file; one individual can
+ also be separated into multiple files. Similarly, one may consider to
+ apply -C50 to mpileup. SNP calling in this way also works for single
+ sample and has the advantage of enabling more powerful filtering. The
+ drawback is the lack of short indel calling, which may be implemented
+ in future.
+
+
+ o Derive the allele frequency spectrum (AFS) on a list of sites from
+ multiple individuals:
+
+ samtools mpileup -gf ref.fa *.bam > all.bcf
+ bcftools view -bl sites.list all.bcf > sites.bcf
+ bcftools view -cGP cond2 sites.bcf > /dev/null 2> sites.1.afs
+ bcftools view -cGP sites.1.afs sites.bcf > /dev/null 2> sites.2.afs
+ bcftools view -cGP sites.2.afs sites.bcf > /dev/null 2> sites.3.afs
+ ......
+
+ where sites.list contains the list of sites with each line consisting
+ of the reference sequence name and position. The following bcftools
+ commands estimate AFS by EM.
+
+
+ o Dump BAQ applied alignment for other SNP callers:
+
+ samtools calmd -br aln.bam > aln.baq.bam
+
+ It adds and corrects the NM and MD tags at the same time. The calmd
+ command also comes with the -C option, the same as the on in pileup
+ and mpileup. Apply if it helps.
+
+