This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to find the mean inter-marker distance between SNPs from a vcf file?

I have got a vcf file with only SNPs as variants. How can i find the average distance between SNPs and the largest gap between two SNPs ?

vcf snp

1 answer

awk 'BEGIN{C="";P=-1;M=0;T=0.0;N=0;} /^#/{next} {if(C==$1) {L=int($2)-P;T+=L;N++;M=(M>L?M:L);}C=$1;P=int($2);}END{if(N>0) printf("avg=%f max=%d\n",T/N,M);}' in.vcf

with:

C = prev contig
P = prev position
M = max length
T=  total length
N= num variants
L = current distance

Log in to answer this question.