This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Per sample information from a multi sample vcf file

Hello all,

I wanted to know how can I extract separate sample vcf files for each sample from a multi sample vcf file containing data of more than 1000 samples.

Thank you

vcf

1 answer

You can use bcftools view with -s parameter. https://samtools.github.io/bcftools/bcftools.html#view

Here I need to give samples names separately as input which is too tedious for all samples . I need all samples regardless of any particular one .

bcftools query -l prints all the samples which you can loop over. Here is an example snippet I use. It gonna create a directory and write each individual sample with their sample name in to that directory.

MULTISAMPLEVCF="mymultisample.vcf.gz"
OUTDIR="splitsamples"
mkdir -p "$OUTDIR"
for sample in $(bcftools query -l "$MULTISAMPLEVCF"); do
    echo "$sample"
    bcftools view -c 1 -s $sample $MULTISAMPLEVCF -Oz -o "$OUTDIR/$sample"
done

Log in to answer this question.