Do you mean at the mapping stage to produce directly a bam file, and after that whatever I want to extract it will keep the header?
How to keep the header when I'm extracting a specific region from a bam file
Hello,
I have used bowtie2 to map some newly sequenced reads to the sheep reference genome.
After that with samtools I converted the sam file to bam file. I'm interested for the reads that are aligned in the mitochondria, so I extracted the particular region from the bam fie. So far everything seems ok, except the fact that the new bam file has "invalid BAM binary header". How can I keep the header to the new bam file?
Thank you very much in advance
Vasilis
• 11,957 views
•
link
1 answer
Try to generate a BAM file, not a SAM file. for SAM, by default samtools-view ignores the header.
samtools view -b -o new.bam old.bam MT
• 0 views
•
link
Log in to answer this question.
Can you show the commands used? How did you extract the region of interest?
I used:
and after that I converted again into bam.
Just do
Yes, it works!
Thank you very much