Problem with BAM file headers
2
0
Entering edit mode
2.6 years ago
Lucas • 0

Hello Everyone,

I have noticed an issue with my BAM file headers, where the @RG line is either mal-formed or is missing entirely. I think I can sed the files that are mal-formed, and add the sample names necessary to complete my further analyses in GATK. But is there a way to add an entire line to the headers?

Thanks,

SAM GATK BAM • 1.1k views
ADD COMMENT
2
Entering edit mode
2.6 years ago
samtools addreplacerg -w -r ID:oldid -r LB:Lib -r SM:SAMPLE -O BAM -o output.bam bad.bam
ADD COMMENT
0
Entering edit mode

Ahh, I think that's what I am looing for. Thanks!

ADD REPLY
0
Entering edit mode
2.6 years ago

You should be able to open and edit the header in plain text format, and you can just add it to the top of a headerless bam. Something like

samtools view -H bad.bam > bad_header.txt

<edit bad_header.txt>

samtools view bad.bam | cat good_header - | samtools view -hb - > good.bam
ADD COMMENT
0
Entering edit mode

Hi,

I think that's close to the solution I want, but the BAM files I have are not headerless, their headers are just really poorly formatted. I simply want to add a line to the header, I think I can do what you said, but then use samtools reheader to edit the original BAM.

So:

samtools reheader edited_header.sam bad.bam > good.bam

ADD REPLY

Login before adding your answer.

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