Thank you!
Filter out reads with hidden tags in bam files
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.
• 3,115 views
•
link
2 answers
samtools view --expr '![SA]' -O BAM -o SA.removed.bam in.bam
• 0 views
•
link
• 0 views
•
link
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).
• 0 views
•
link
Thanks! I will try it too.
• 0 views
•
link
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.
• 0 views
•
link
Log in to answer this question.