How do I add/update the FORMAT field and it values in SAMPLE field?
Entering edit mode
4.5 years ago
kirannbishwa01 ★ 1.4k

I am trying to add a new FORMAT field and it's value in SAMPLE field.

vcf_read = vcf.Reader(open('RNA_seq.test.vcf'))

# adding the description of new field in the header
vcf_read.formats['My|Sp'] = VcfInfo('My|Sp', num=4, type=str,
                                desc='phased genotype state of the population',
                                source=devnull, version=devnull)

 # now opening the file to write the vcf data to
 vcf_write = vcf.Writer(open('RNA_seq.write.vcf', 'w'), vcf_read,

for record in vcf_read:

    # update the FORMAT field id
    record.FORMAT = record.FORMAT+'foo'   # this works

    # select the sample to be updated
    sample_name = record.genotype('2ms01e')

    sample_name.add_field('foo', 'bar')  # this doesn't work

Error message:

Traceback (most recent call last):
  File "/home/everestial007/PycharmProjects/stitcher/pHASE-Stitcher-Markov/markov_final_test/", line 108, in <module>
    sample_name.add_field('foo', 'bar')
AttributeError: '_Call' object has no attribute 'add_field'

But, according to the documents in pyVCF this is supposed to work. I then checked the file in to see if add_field exists or not, and it unfortunately doesn't.

I then tried to reinstall the new version of PyVcf but still the same problem.

How do I add/update the FORMAT field and it values in SAMPLE field?

software error vcf pyvcf python add_field • 1.9k views

Login before adding your answer.

Traffic: 1761 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6