This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Samtools Filter by CIGAR string

Hi,

I have a bam file and want to filter it by CIGAR string. I want to keep the lines that have a match larger than 100. For example, the CIGAR string is 20S80M12S, then I want to discard this sequence.

How should use samtools to do this?

I'm currently using

./samtools view -h -e '$6 =~ "(^|[^0-9])([1-9][0-9]{2,}|[1-9][0-9]{3,})M[^0-9]"' -o D1.sorted.dup.filt.bam D1.sorted.dup.bam

But this doesn't work, what should I do?

samtools bam

1 answer

using samjdk



java -jar  dist/jvarkit.jar samjdk -e 'return !record.getReadUnmappedFlag() && record.getCigar().getCigarElements().stream().filter(CE->CE.getOperator().equals(CigarOperator.M)).anyMatch(CE->CE.getLength()>100);' in.bam

similar to Filter bam file based on cigar string?

biostars is broken. I need to add stuff to validate my answer. I need to add stuff to validate my answer. I need to add stuff to validate my answer. I need to add stuff to validate my answer. I need to add stuff to validate my answer.

Log in to answer this question.