This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Filter Reads With Bowtie ?

We did an alignment with BWA and have 4 BAM files. How can I filter only mitochondria reads with Bowtie ?

bowtie

Are you working with BWA or bowtie?

I'm working with Bowtie :)

1 answer

EDIT: You should read the SAM format specification. The 3rd column tells the name of your chromosome in the reference. If ChrM is your mitochondrial chromosome name, and you want to merge filtered multiple bam (with corresponding .bai files available) files, then you could do:

samtools merge -r -h file1.bam -R ChrM ChrM_merged.bam *.bam

OLD REPLY:

samtools view my_file.bam | grep "ChrM" > mitochondria_alone.txt

samtools view decodes the binary sam file (bam file) for you and displays on screen. I write here .txt because, for it to be a sam format, you should have the header as well which you can obtain by

samtools view -H my_file.bam

But we have 4 BAM files to search .. Is it gonna work If I type

samtools view file1.bam file2.bam file3.bam file4.bam | grep "ChrM" > mitochondria_alone.txt

Had to change the reply quite sometimes. Sorry about that. samtools merge is what you want. It has changed a little from the last time I used it.

Log in to answer this question.