Split trio vcf file
1
0
Entering edit mode
14 months ago
anasjamshed ▴ 120

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 • 1.2k views
ADD COMMENT
0
Entering edit mode

But it does not give me complete vcf sample.

what does it mean ?

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

we apply bcf tools query on vcf file

ADD REPLY
0
Entering edit mode

yes, you did.

ADD REPLY
0
Entering edit mode

but i want to find proper file after it

ADD REPLY
0
Entering edit mode
14 months ago
cfos4698 ★ 1.1k

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

@cfos4698 why "-c1' ?

ADD REPLY
1
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

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