Question: reheadering, merging and sorting on different bam file
gravatar for khikho
5.1 years ago by
khikho100 wrote:


Imagine that I have 20 bam files, which I want to change their header then merge them and then sort them! So I just wondering if these two scenarios make different output :

1) reheader (each of them) -> merge all -> sort the output

2) merge all -> reheader the output -> sort 

All bam files have the same read group, and I want to add sample name to each RG field

@RG     ID:1120


bam sequence • 2.5k views
ADD COMMENTlink modified 5.0 years ago by Dan D6.8k • written 5.1 years ago by khikho100
gravatar for Dan D
5.0 years ago by
Dan D6.8k
Dan D6.8k wrote:

It shouldn't make any difference, but what I'd suggest doing is using samtools merge and passing the header you want to apply to the merged file through the -h argument. That will simplify your workflow. samtools merge does expect your input to be already sorted though. If your input is indeed sorted, then that will allow you to accomplish your goal with a single command.

For example, put the header you want in a file called "header.sam":

samtools merge -h header.sam merged.bam 1.bam 2.bam 3.bam ... 20.bam
ADD COMMENTlink written 5.0 years ago by Dan D6.8k

What if my bam files are not sorted, what actually does samtools merge do then? because I've just run samtools merge with unsorted bam files.

many thanks!

ADD REPLYlink written 2.5 years ago by jjaimi92112910
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2048 users visited in the last hour