Extract single chromosome reads from Bam file
I'm trying to extract the reads relating to chrM from an aligned BAM file but without success. These are my commands:
samtools view -h Linfo_mt6394_aligned_sorted.bam chrM > Linfo_mt6394_chrM_aligned.sorted.sam
samtools view -bS Linfo_mt6394_chrM_aligned.sorted.sam > Linfo_mt6394_chrM_aligned.sorted.bam
when I check with samtools idxstats results all chromosome. Why? Are there alternative ways to extract single chromosome reads from a BAM file?
Thanks
• 803 views
•
link
1 answer
You see that all chromosomes are still in the header, but only chrM will have reads. The header is not updated. Note that the sam/bam conversion is unnecessary.
samtools view -h -o Linfo_mt6394_chrM_aligned.sorted.bam Linfo_mt6394_aligned_sorted.bam chrM
That command is the same without unnecessary conversion.
• 0 views
•
link
Log in to answer this question.