reheadering, merging and sorting on different bam file
1
2
Entering edit mode
10.7 years ago
khikho ▴ 100

Hi,

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

Thanks

bam sequence • 4.3k views
ADD COMMENT
2
Entering edit mode
10.6 years ago
Dan D 7.4k

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 COMMENT
0
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 1851 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6