Skip to content

Error in reading VCF #78

Closed
dawe opened this Issue Nov 16, 2012 · 3 comments

3 participants

@dawe
dawe commented Nov 16, 2012

I'm trying to parse a VCF (generated by GATK and modified with snpEff and SnpSift). Unfortunately I'm not able to read any record because an unhandled exception:

In [29]: a = vcf.Reader(open("/Users/dawe/Downloads/Tier2.vcf", 'r'))

In [30]: for rec in a: print rec
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-e05998bcc130> in <module>()
----> 1 for rec in a: print rec

/Library/Python/2.7/site-packages/PyVCF-0.6.0-py2.7-macosx-10.8-intel.egg/vcf/parser.pyc in next(self)
    462         if filt == 'PASS':
    463             filt = None
--> 464         info = self._parse_info(row[7])
    465 
    466         try:

/Library/Python/2.7/site-packages/PyVCF-0.6.0-py2.7-macosx-10.8-intel.egg/vcf/parser.pyc in _parse_info(self, info_str)
    312             try:
    313                 if self.infos[ID].num == 1 and entry_type != 'String':
--> 314                     val = val[0]
    315             except KeyError:
    316                 pass

TypeError: 'bool' object is not subscriptable
@martijnvermaat
Collaborator

It looks like this has prevented us from parsing any record with any entry of type Flag in the INFO field, so I guess we need a test case (actually, the very first example VCF file in the specification will do).

I think replacing (line 314 in vcf/parser.py)

                if self.infos[ID].num == 1 and entry_type != 'String':

with

                if self.infos[ID].num == 1 and entry_type not in ('String', 'Flag'):

will do.

@dawe
dawe commented Nov 16, 2012

Great, that works perfectly!

@dawe dawe closed this Nov 16, 2012
@jamescasbon
Owner

Needs to be added to repository

@jamescasbon jamescasbon reopened this Nov 27, 2012
@jamescasbon jamescasbon pushed a commit that closed this issue Dec 6, 2012
@seandavi seandavi Fixes #78 b793020
@gotgenes gotgenes pushed a commit to gotgenes/PyVCF that referenced this issue May 13, 2014
@seandavi seandavi Fixes #78 1c0a209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.