samtools
Quick Start
- Command:
samtools - Local executable:
/home/vimalinx/miniforge3/envs/bio/bin/samtools - Version: 1.22.1
- Reference: See
references/help.mdfor full command documentation and options
When To Use This Tool
- Inspect, convert, sort, index, and summarize SAM/BAM/CRAM files.
- It is the default plumbing tool around almost every alignment workflow.
- Use it immediately after aligners and before most downstream coverage or variant workflows.
- Prefer subcommand-oriented usage;
samtoolsis a dispatcher, not a single operation.
Common Patterns
# 1) Convert SAM to BAM
samtools view -b -o sample.bam sample.sam
# 2) Sort and index a BAM
samtools sort -@ 8 -o sample.sorted.bam sample.bam
samtools index sample.sorted.bam
# 3) Inspect basic mapping statistics
samtools flagstat sample.sorted.bam
samtools stats sample.sorted.bam > sample.stats.txt
# 4) Extract one region
samtools view sample.sorted.bam chr1:100000-110000
Recommended Workflow
- Convert aligner output into BAM or CRAM as needed.
- Sort the file before indexing or region-based access.
- Run
flagstat,stats,coverage, ordepthto sanity-check the alignment. - Use specialized subcommands like
fastq,fasta,faidx, ordictonly when the workflow specifically needs them.
Guardrails
- Region-based operations require sorted and indexed files.
samtools quickcheckis a cheap integrity test before burning compute on a broken BAM/CRAM.- Use
-@for thread-aware subcommands, but do not assume every subcommand parallelizes the same way. - Be explicit about output format and destination; many subcommands default to stdout.