← 返回命令列表

Linux command

samtools 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

View BAM file

samtools view [alignment.bam]

Convert SAM to BAM

samtools view -b [alignment.sam] -o [alignment.bam]

Sort BAM file

samtools sort [input.bam] -o [sorted.bam]

Index BAM file

samtools index [sorted.bam]

View specific region

samtools view [sorted.bam] [chr1:1000-2000]

Count alignments

samtools view -c [alignment.bam]

Generate statistics

samtools flagstat [alignment.bam]

Merge BAM files

samtools merge [output.bam] [input1.bam] [input2.bam]

说明

samtools manipulates alignments in SAM (Sequence Alignment/Map) format and its binary equivalent BAM. It's essential for next-generation sequencing data analysis. SAM/BAM files contain sequence reads aligned to reference genomes. Each record includes read name, position, mapping quality, CIGAR string (alignment operations), and optional tags. The view command converts between formats and filters alignments. Sorted BAM files with indices enable random access to genomic regions. Most downstream tools require sorted, indexed BAM. Statistics commands (flagstat, stats, idxstats) summarize alignment characteristics: mapping rates, insert sizes, coverage distributions. These quality metrics guide analysis decisions. Pileup output (mpileup) aggregates alignments at each position for variant calling. Coverage commands calculate read depth across regions. CRAM format provides better compression than BAM with reference-based encoding. Samtools handles CRAM transparently.

参数

view
View/convert SAM/BAM/CRAM.
sort
Sort alignments.
index
Create BAM index.
merge
Merge sorted files.
flagstat
Statistics from FLAG field.
stats
Comprehensive statistics.
idxstats
Per-reference statistics.
faidx
Index FASTA file.
depth
Compute depth at each position.
mpileup
Generate pileup for variants.
coverage
Calculate coverage statistics.
fastq
Extract FASTQ from BAM.
collate
Shuffle and group alignments by name.
calmd
Recalculate MD/NM tags.
-b
Output BAM format.
-S
Input is SAM (ignored, format is auto-detected).
-o _FILE_
Output file.
-@ _NUM_, --threads _NUM_
Number of threads.
-f _FLAGS_
Only include reads with FLAGS.
-F _FLAGS_
Exclude reads with FLAGS.
-q _MAPQ_
Minimum mapping quality.
-h
Include header.

FAQ

What is the samtools command used for?

samtools manipulates alignments in SAM (Sequence Alignment/Map) format and its binary equivalent BAM. It's essential for next-generation sequencing data analysis. SAM/BAM files contain sequence reads aligned to reference genomes. Each record includes read name, position, mapping quality, CIGAR string (alignment operations), and optional tags. The view command converts between formats and filters alignments. Sorted BAM files with indices enable random access to genomic regions. Most downstream tools require sorted, indexed BAM. Statistics commands (flagstat, stats, idxstats) summarize alignment characteristics: mapping rates, insert sizes, coverage distributions. These quality metrics guide analysis decisions. Pileup output (mpileup) aggregates alignments at each position for variant calling. Coverage commands calculate read depth across regions. CRAM format provides better compression than BAM with reference-based encoding. Samtools handles CRAM transparently.

How do I run a basic samtools example?

Run `samtools view [alignment.bam]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does view do in samtools?

View/convert SAM/BAM/CRAM.