Question: Merging Bam Files With Different Headers
0
gravatar for Frenkiboy
6.7 years ago by
Frenkiboy250
Frenkiboy250 wrote:

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 • 3.1k views
ADD COMMENTlink modified 6.7 years ago by Devon Ryan93k • written 6.7 years ago by Frenkiboy250
0
gravatar for Devon Ryan
6.7 years ago by
Devon Ryan93k
Freiburg, Germany
Devon Ryan93k wrote:

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 COMMENTlink written 6.7 years ago by Devon Ryan93k
Please log in to add an answer.

Help
Access

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