This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Remove reads from bam file that partially covers a region

Hi,

I have several bam files and am working with a 15bp deletion at a specific region. There are reads that support the deletion and there are reads that partially cover the deleted region.

I want to filter out those reads (as shown in circle in the attached IGV snapshot) that partially cover the deleted region from the bam files. I am new in this area, so any suggestions of suitable tool or way to do that is much appreciated.

enter image description here

indel filter bam

I am not sure if it is as accurate, but the inverse (selecting reads with a 15bp deletion) would be definitely easier.

1 answer

using samjdk:

java -jar dist/samjdk.jar -e 'if(record.getReadUnmappedFlag() || !record.getContig().equals("chr12")) return true; final int start=100; final int end=115; int x= record.getStart(); if(x>=start && x<=end) return false; x= record.getEnd(); if(x>=start && x<=end) return false; return true;' input.bam

Thanks Pierre. It's working well for me. Below is an example of coverage before and after processing.

Before enter image description here

After: enter image description here

Log in to answer this question.