Question: Unmerge Vcfs
1
gravatar for jeansimon32
6.7 years ago by
jeansimon32150
jeansimon32150 wrote:

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

• 2.2k views
ADD COMMENTlink modified 5.6 years ago by Jorge Amigo11k • written 6.7 years ago by jeansimon32150
0
gravatar for Pierre Lindenbaum
6.7 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum128k wrote:

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 COMMENTlink modified 5 months ago by RamRS27k • written 6.7 years ago by Pierre Lindenbaum128k
0
gravatar for Erik Garrison
6.7 years ago by
Erik Garrison2.3k
Napoli, IT / UCSC
Erik Garrison2.3k wrote:

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 COMMENTlink modified 5 months ago by RamRS27k • written 6.7 years ago by Erik Garrison2.3k
0
gravatar for Jorge Amigo
5.6 years ago by
Jorge Amigo11k
Santiago de Compostela, Spain
Jorge Amigo11k wrote:

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 COMMENTlink modified 5 months ago by RamRS27k • written 5.6 years ago by Jorge Amigo11k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 845 users visited in the last hour