This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Splitting VCF into 10mb window subfiles for a given chromosome

Hello everyone, is there an efficient way to split a given vcf file (lets say for chromosome 1) into several sub-vcf files each of which contain 10mb each pertaining to the same chromosome? Many thanks in advance!

vcf bedtools bcftools

1 answer

I wrote http://lindenb.github.io/jvarkit/VcfToIntervals.html

(not tested)

bcftools view in.vcf.gz |  java -jar dist/vcf2intervals.jar --bed --distance "10mb" --min-distance 0 | awk '{printf("%s:%d-%s\n",$1,int($2)+1,$3);}' | while read R
do
    bcftools view -O z -o "${R//[:-]/_}.out.vcf.gz" "in.vcf.gz" "${R}"
done

Log in to answer this question.