See http://htslib.org/ for the new 1.x releases of SAMtools, BCFtools, and HTSlib. This website contains information pertaining to the old 0.1.19 samtools release, and so is useful but somewhat out of date. As time permits, this information will be updated for the new samtools/bcftools versions and moved to the new website.
Working on a stream
SAMtools is designed to work on a stream. You can output SAM/BAM to the standard output (stdout) and pipe it to a SAMtools command via standard input (stdin) without generating a temporary file. For example, the following command runs pileup for reads from library libSC_NA12878_1:
- samtools view -ul libSC_NA12878_1 aln.bam | samtools pileup -cf ref.fa -
- samtools view -u aln.bam X:1,000,000-1,100,000 | samtools pileup -
- samtools view -h in.bam | grep -v "\<RG:Z:ERR00001\>" | samtools view -bS - > out.bam
- samtools view -h aln.bam | awk '$6!~/[ID]/' | samtools pileup -S -
In the examples above, we only see how to combine the `view' and `pileup' commands. In fact, most of samtools commands, except indexing and external sorting, recognize an input file `-' as stdin and an output file `-' as stdout. You can run several samtools commands on one stream, which extends the ability of each single command, saves diskspace and reduces wall-clock time.
NOTE: some options in the examples are implemented in the latest SVN (r347 or above) which is not released at the time of my writing this page.