Hello!!

I have been trying to figure out how can I calculate the number of SNPs using sliding windows?
I have a list with three columns: Scaffold"\t"Scaffold_Length"\t"Number_SNPs (per scaffold)

    Scaffold_28	70818817	894731
    Scaffold_3	5123947	57985
    Scaffold_13	4491039	67622
    Scaffold_12	3793473	51663
    Scaffold_23	3593776	31841
    Scaffold_11	3547442	63973
    Scaffold_26	2720936	36018
    Scaffold_16	2719413	24318
    Scaffold_27	1987753	53938
    Scaffold_24	1647859	18408
    Scaffold_9	1630703	15792
    Scaffold_32	1545880	21094

 . . .

Based on the second column, I want to use sliding windows (500kbp) and calculate how many SNPs are there into each sliding windows.
I performed: bedtools makewindows, but I have not figured out how to count and sum the SNP density.

Thanks a lots for your help!!


One way is to pipe BED-formatted, sliding windows into `bedmap`, using its `--count` operator to count the number of SNPs that fall within each window. 

The following `bedops` statement would generate 500knt windows from scaffolds, spaced every 100knt. These windows are passed along to `bedmap`, which counts the number of SNPs that fall in each of those windows:

    $ bedops --chop 500000 --stagger 100000 -x <(awk -vOFS="\t" '{ print $1, $2-1, $2; }' scaffolds.txt | sort-bed -) | bedmap --echo --count --delim '\t' - <(vcf2bed < snps.vcf) > answer.bed

The result is written to `answer.bed`, each line of which containing the window and the number of SNPs over that window.