Per sample information from a multi sample vcf file
1
0
Entering edit mode
23 months ago
Peerzada • 0

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.9k views
ADD COMMENT
1
Entering edit mode
23 months ago
barslmn ★ 2.3k

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

ADD COMMENT
0
Entering edit mode

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 .

ADD REPLY
1
Entering edit mode

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
ADD REPLY
0
Entering edit mode

Thank you Sir

ADD REPLY

Login before adding your answer.

Traffic: 2028 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