This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Unmerge Vcfs

Hello all,

I have a merged vcf file for 4 samples and I want to unmerge it and get one vcf per each sample. How can I do that? I’ve found vcftools has only merge-vcf tool … is there any tools to unmerge vcf files?

Thank you

Jean

merge vcf

3 answers

I know this is an old question but, as I've already stated in this post, there's a very efficient way of doing this that hasn't been reported yet. hope it helps:

for file in *.vcf*; do
  for sample in `bcftools view -h $file | grep "^#CHROM" | cut -f10-`; do
    bcftools view -c1 -Oz -s $sample -o ${file/.vcf*/.$sample.vcf.gz} $file
  done
done

something like:

for COL in 10 11 12 13; do S=`grep -E "^#CHROM" input.vcf | cut -d '     ' -f ${COL} `; grep -E '^##'   input.vcf > ${S}.vcf && grep -v  -E '^##'  input.vcf | cut -d '     ' -f1-9,${COL}  >>  ${S}.vcf  ; done

of course, that will not fix the QUAL, the DP field in the INFO column etc...

You can use vcfkeepsamples:

for sample in samples
do
    vcfkeepsamples file.vcf $sample >$sample.vcf
end

If you want to reset relevant INFO fields using genotype information, use vcffixup or something similar.

Log in to answer this question.