This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Filter sam file to remove reads with large deletions

Hello,

I need to filter out reads from my sam files that contain deletions larger than 3bp. Does anyone know of a simple way to do that? I need to keep other low quality reads (like reads that contain small deletions, mismatches and insertions).

Thanks!

rna-seq

Python with pysam could probably do that, do you have any coding experience?

1 answer

using samjs to remove the reads havig a cigar D/N larger than 3 pb.

java -jar dist/samjs.jar -e 'function accept(rec) {if(rec.getReadUnmappedFlag()) return true; var c=rec.getCigar(); if(c==null) return true; for(var i=0;i< c.numCigarElements();++i) {var ce=c.getCigarElement(i);if(ce.getLength()<3) continue;var s=ce.getOperator().name(); if( s=="D"  || s=="N") return false; } return true;}accept(record)' input.bam

Neat tool Pierre, I want to do the opposite, I want to find reads in sam file that span large deletions (>1kb), so I thought I would use your -X option, to save discarded. Running into a few issues, samoutputformat is not considered valid and -X doesn't get recognized? https://pastebin.com/k2dVRxB5

Log in to answer this question.