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.
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
yes, you did.
but i want to find proper file after it