| name | samtools |
| description | SAM/BAM/CRAM processing for metagenomic mapping outputs — sort, index, flagstat, coverage, and filtering. Use whenever an aligner writes SAM/BAM before CoverM, MetaBAT2, inStrain, or BASALT. Upstream: https://github.com/samtools/samtools.
|
| license | MIT |
| category | analysis-tools |
| tags | ["mapping","bam","sam","qc"] |
| upstream | https://github.com/samtools/samtools |
| stage | mapping |
Samtools
Upstream: samtools/samtools
Citation
Danecek, P. et al. Twelve years of SAMtools and BCFtools. GigaScience 10,
giab008 (2021). https://doi.org/10.1093/gigascience/giab008
Analytical thinking
Aligners produce records; samtools makes them usable. Binning and CoverM
expect coordinate-sorted, indexed BAMs. Always stream aligner | samtools sort
to avoid multi-hundred-GB unsorted SAM files.
flagstat / coverage are your first QC after mapping — catch wrong references
before spending days on MetaBAT/BASALT.
Essential recipes
samtools sort -@ 8 -o out.bam in.sam
samtools index out.bam
samtools flagstat out.bam
samtools idxstats out.bam | head
samtools coverage out.bam | head
samtools view -@ 8 -b -F 0x900 out.bam > out.primary.bam
samtools merge -@ 8 sample.bam L1.bam L2.bam && samtools index sample.bam
Key options
| Option | Guidance |
|---|
-@ | Threads for CPU-heavy ops |
-o | Output path (sort/view) |
-F/-f | Flag filters; know 0x4 unmapped, 0x900 secondary/supplementary |
TMPDIR | Point to large scratch for sort |
Decision notes
- Never feed unsorted BAM to MetaBAT depth helpers expecting coordinate order
- Archive flagstat next to BAM for provenance
- CRAM saves space but ensure reference FASTA remains available
Related skills
bowtie2 · strobealign · bwa-mem2 · minimap2 · coverm · metabat2 · instrain