Upload multiple BAM/SAM/CRAM files to merge into a single file.
samtools merge
samtools merge is a command-line utility used to
combine multiple SAM, BAM, or CRAM alignment files into a single
output file. This is particularly useful when sequencing data
originates from multiple lanes, flow cells, or sequencing runs
and needs to be consolidated before downstream analysis.
.bam)
.sam)
.cram)
Input files should generally be coordinate-sorted and generated against the same reference genome to ensure compatibility.
.bai)
can be generated after merging.
# Merge two BAM files
samtools merge merged.bam lane1.bam lane2.bam
# Merge multiple BAM files
samtools merge merged.bam lane1.bam lane2.bam lane3.bam
# Force overwrite existing output
samtools merge -f merged.bam input1.bam input2.bam
# Merge while preserving read groups
samtools merge -r merged.bam input1.bam input2.bam
Input:
sample_lane1.bam
sample_lane2.bam
sample_lane3.bam
Output:
merged.bam
The resulting merged BAM file contains all alignments from the input files while preserving alignment information and read metadata.
samtools index merged.bam
Official Samtools Documentation: Samtools Merge Manual
If you use samtools merge in your work,
please cite:
Li, H., Handsaker, B., Wysoker, A., Fennell, T., Ruan, J., Homer, N., et al. (2009). The Sequence Alignment/Map (SAM) format and SAMtools. Bioinformatics, 25(16), 2078–2079. DOI: 10.1093/bioinformatics/btp352