I am trying to add a new
FORMAT field and it's value in
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, lineterminator='\n') 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
Traceback (most recent call last): File "/home/everestial007/PycharmProjects/stitcher/pHASE-Stitcher-Markov/markov_final_test/phase_to_vcf.py", 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
module.py file in https://github.com/jamescasbon/PyVCF/blob/master/vcf/model.py 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?