How to create a new VCF 1) filtered by samples, and 2) with only selected fields
1
0
Entering edit mode
2.2 years ago
ariel ▴ 250

I've been trying bcftools

bcftools view -s Sample1: Creates splits out Sample1.

bcftools reheader -s Sample1: Creates a new VCF with only Sample1, and the header, but includes all of the fields.

bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%GT\n': Creates a table with just the fields I want, but it drops the header.

bcftools view -s Sample1 20201229_PS-19-000796A8.vcf -f '%CHROM\t%POS\t%REF\t%ALT\t%GT\n': This should work, but surprisingly keeps all of the fields despite the format request. EDIT: I gues the -f flag with view is for filtering not formatting.

The command that would do what I want would theoretically be bcftools reheader -s Sample1 --f '%CHROM\t%POS\t%REF\t%ALT\t%GT\n'

But this is not a valid command and throws an error. The -f switch with reheader serves another purpose.

VCF bcftools • 1.1k views
ADD COMMENT
0
Entering edit mode

However, it drops the header.

The header was kept on my machine.

$ bcftools view -s S3 in.vcf.gz | grep "#"
##fileformat=VCFv4.2
(...)
#CHROM  POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  S3
ADD REPLY
0
Entering edit mode

Sorry. You are correct, and I edited the question.

ADD REPLY
0
Entering edit mode

bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%GT\n' Creates a table with just the fields I want, but it drops the hea

the output of bcftools query is not VCF

ADD REPLY
0
Entering edit mode

Yes. I get that. But I WANT a VCF. There is a -H, --print-header, but it does not actually print the header.

ADD REPLY
0
Entering edit mode
2.2 years ago

2) with only selected fields

what is a field ? an INFO attribute ? You have to use bcftools annotate -x '^INFO/FIELD1,INFO/FIELD2,INFO/FIELD3'

ADD COMMENT
0
Entering edit mode

Thanks! You sent me in the right direction.

ADD REPLY
0
Entering edit mode

Aha! Indeed this does seem to do the trick:

bcftools view -s Sample1 file.vcf | bcftools annotate -x INFO,^FORMAT/GT

bcftools view -s Sample1 20180323_1803704618.vcf | bcftools annotate -x INFO,^FORMAT/GT - | egrep -v "^##" | head -n2
#CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  Sample1
chrM    150     .       TCT     CCC     281.78  MAC     .       GT      ./.

Thanks Pierre!

ADD REPLY

Login before adding your answer.

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