This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Split trio vcf file

I have trio_vcf file with samples N1 , N2 and N3.I am trying this command to split the samples:

bcftools query -H trio_example.vcf.gz -f '%CHROM\t%POS\t%REF\t%ALT\t%VT[\t%SAMPLE=%GT]\n' --samples 'N1' >N1.vcf

But it does not give me complete vcf sample. Which commands should I change after -f to get complete N1 sample?

bcftools vcf

But it does not give me complete vcf sample.

what does it mean ?

I mean not with all columns as I want vcf file with all columns

using bcftools query this cannot be a vcf, it's just a tab delimited file.

we apply bcf tools query on vcf file

but i want to find proper file after it

1 answer

As Pierre is pointing out, you need to make sure you are using the correct tool for the job. bcftools query will return a tab-delimited file by design. If you want to split a VCF file into individual files per sample, try bcftools view. For example:

vcf="/path/to/your_file.vcf.gz"
for sample in `bcftools query -l $vcf`; do
  OUT=$(basename ${vcf} | sed "s/.vcf.gz/.${sample}.vcf.gz/")
  bcftools view -c1 -Oz -s $sample -o ${OUT} ${vcf}
done

I tested the code by working with two merged samples, let's call them sample1 and sample2. When making sure it'd work as expected, I found that omitting -c1 retained variants in all output files, even if they were originally only found in sample1 OR sample2 (and vice versa). In these cases, the variants were assigned a missing genotype of './.'. Including -c1 removed these variants with a missing genotype. If the desired behaviour is to retain these variants, then I guess OP should omit the -c1 part.

Log in to answer this question.