remove unmapped reads on a specific chromosome only
1
0
Entering edit mode
3.7 years ago
firatuyulur ▴ 320

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

bam remove unmapped • 1.9k views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

therefore i want to get rid of all the reads with either mate unmapped on chrM only

It would be good to add this clarification to original post.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode
3.7 years ago
prasundutta87 ▴ 670

You can specify the region of the BAM file you want in your samtools view command. In your case, it should be your chromosome name (without start and end position information). You can find the information in the manual/help file of the command (http://www.htslib.org/doc/samtools-view.html):

REGIONS: Regions can be specified as: RNAME[:STARTPOS[-ENDPOS]] and all position coordinates are 1-based

You would of course need to index your BAM file first.

ADD COMMENT
0
Entering edit mode

could you give an example? when I do samtools view -F 12 my.bam chrM this will give me only chrM but not the other chromosomes if this is what you meant.

ADD REPLY
0
Entering edit mode

Yes, you are right.

ADD REPLY

Login before adding your answer.

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