Merging Bam Files With Different Headers
1
0
Entering edit mode
11.1 years ago
Frenkiboy ▴ 250

This might be a trivial question, but I would rather ask then make a mistake.

What is the easiest way to merge two bam files that have different headers - the headers contain the same information regarding the chromosome names and lengths, but in one file they are sorted by char (eg. chr1 chr10), and in another file by chromosome number (chr1 chr2). I know that each read references the exact chromosome name from the header, so that the reheader command should not produce correct results. The only way that I can currently think of is to convert both bam files to sam, merge them and add the header manually.

Is there a way to do this automatically?

Best regards

bam samtools • 4.3k views
ADD COMMENT
0
Entering edit mode
11.1 years ago

I'm not aware of anything that will do that without going to a sam file first. The easiest solution would be:

samtools view -h file1.bam > tmp.sam
samtools view file2.bam >> tmp.sam

You could then convert the resulting file back into bam format. Alternatively, writing a program to keep everything in bam format and merging would be simple.

ADD COMMENT

Login before adding your answer.

Traffic: 2108 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