How to add a flag to the INFO column of a vcf with pysam?
0
0
Entering edit mode
3.8 years ago
curious ▴ 750

so for info content of a vcf I know I can set key value pairs like this:

vcf_in = VariantFile("chr22.vcf")

for counter, rec in enumerate(vcf_in.fetch('chr22', 10510227, 10540227)):
    rec.info["MAF"] = whatever

But I want to add something at Type=Flag, the flag IMPUTED to be more specific.

so going from and info field like this:

AF=2.33333e-05;MAF=2.33333e-05

to this:

IMPUTED;AF=2.33333e-05;MAF=2.33333e-05

Every example of setting the info attribute of the rec object seems to use key value pairs. Is setting flags possible?

bcf vcf pysam • 1.8k views
ADD COMMENT
0
Entering edit mode

I figured it out:

vcf_in = VariantFile("chr22.vcf")
vcf_in.header.add_meta('INFO', items=[('ID',"IMPUTED"), ('Number',0), ('Type','Flag'), ('Description','Marker was imputed')])

for counter, rec in enumerate(vcf_in.fetch('chr22', 10510227, 10540227)):
    rec.info.__setitem__('IMPUTED', 1)
ADD REPLY

Login before adding your answer.

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