I looked around and couldn't find an example that meets my needs. I have a bam file with all the hg19 chromosomes and I want to remove the unmapped reads that are located at chrM specifically rather than an entire bam operation. I can think of splitting the bam into chromosomes and treating individually but is there a way to do this without extra steps? It is samtools view -F 4
or samtools view -F 12
ONLY for chrM yet the input is file is still the entire bam file and the output file is still the entire bam file with only the unwanted reads on chrM filtered out.
Thanks
In technical terms @prasundutta87's answer below should would. But your question is a little odd. If the reads were unmapped, how would the be on chrM? By definition an unmapped read is not on any chromosome.
i understand what you mean. in my case i have some reads whose mates are unmapped and they are causing some issues, they are only on chrM. therefore i want to get rid of all the reads with either mate unmapped on chrM only without touching the other chrs.
It would be good to add this clarification to original post.
Reads that are mapped, but whose mate is unmapped are mapped, and therefore will not be caught by
-F 4
, the flag you want is 8, not 4. The unmapped reads themselves (which are the mates to the reads mapped to chrM) won't be located on any chromosome, so any command that only removes unmapped reads on chrM won't remove them.As far as i'm aware the only what to do this would be to divide the BAM file in two (reads on chrM, and reads not on chrM) and then filter only those on chrM, before recombining.