Filter out reads with hidden tags in bam files
2
0
Entering edit mode
7 weeks ago
jkim ▴ 130

Hello,

I saw this post filter reads in BAM having a tag / but I couldn't figure out how to filter out the reads having hidden tags (SA) - like the screen shot below. Is there an easy way of removing only those reads?

I tried samtools view -e/-d but it didn't work for me. Any advice would be appreciated. enter image description here

BAM samtools • 438 views
ADD COMMENT
3
Entering edit mode
7 weeks ago
samtools view --expr '![SA]' -O BAM  -o SA.removed.bam  in.bam
ADD COMMENT
1
Entering edit mode

You can combine with this --unmap too which changes it to marking the unselected reads as unmapped instead of removing them. This an be a useful way of retaining all data in the BAM so you can still use it for going back to the original FASTQ if required (potentially saving on disk space for a second copy).

ADD REPLY
0
Entering edit mode

Thanks! I will try it too.

ADD REPLY
0
Entering edit mode

Thank you!

ADD REPLY
0
Entering edit mode
7 weeks ago
jkim ▴ 130
samtools view -d "SA" in.bam -o SA.only.bam

samtools view SA.only.bam | cut -f 1 | sort | uniq > SA.id.list

samtools view -N SA.id.list -U SA.removed.bam -o /dev/null in.bam

found one way to deal with.

ADD COMMENT
0
Entering edit mode

this is wrong. If one read in a pair carries the tag but not the other, you'll remove both reads.

ADD REPLY
0
Entering edit mode

Oh I forgot to say mine are single end reads from Ion torrent sequencers.

ADD REPLY

Login before adding your answer.

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