This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to filter variants called within n base pairs of each other

I've filtered variants based on quality and depth using bcftools, but I also want to filter them that were called within 5 base pairs of each other. Is there any tools that can do this?

Example

Before filter:

1 153489 A T 
1 154895 C T
1 154898 G C
1 157355 C A

After filter:

1 153489 A T 
1 157355 C A
vcf snp sequencing next-gen

1 answer

using vcffilterjdk: http://lindenb.github.io/jvarkit/VcfFilterJdk.html

$ java -jar dist/vcffilterjdk.jar --body -e 'String prev_contig=null;int prev_end=-1; public Object apply(final VariantContext vc) {boolean ret=!(vc.getContig().equals(prev_contig)  && vc.getStart() - prev_end <=5); prev_contig=vc.getContig();prev_end=vc.getEnd();return ret; }'  in.vcf

Log in to answer this question.