Unmerge Vcfs
3
2
Entering edit mode
10.6 years ago
jeansimon32 ▴ 170

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.9k views
ADD COMMENT
1
Entering edit mode
9.5 years ago

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
ADD COMMENT
0
Entering edit mode
10.6 years ago

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...

ADD COMMENT
0
Entering edit mode
10.6 years ago
Erik Garrison ★ 2.4k

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.

ADD COMMENT

Login before adding your answer.

Traffic: 1819 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6