diff --git a/vcf/parser.py b/vcf/parser.py index c3c3d08..08daa08 100644 --- a/vcf/parser.py +++ b/vcf/parser.py @@ -297,9 +297,9 @@ def __init__(self, fsock=None, filename=None, compressed=None, prepend_chr=False self._column_headers = [] self._tabix = None self._prepend_chr = prepend_chr + self.encoding = encoding self._parse_metainfo() self._format_cache = {} - self.encoding = encoding def __iter__(self): return self @@ -315,6 +315,12 @@ def _parse_metainfo(self): parser = _vcf_metadata_parser() line = next(self.reader) + + try: + line = line.decode(self.encoding) + except AttributeError: + pass + while line.startswith('##'): self._header_lines.append(line) @@ -348,6 +354,10 @@ def _parse_metainfo(self): self.metadata[key].append(val) line = next(self.reader) + try: + line = line.decode(self.encoding) + except AttributeError: + pass fields = self._row_pattern.split(line[1:]) self._column_headers = fields[:9] @@ -551,6 +561,12 @@ def _parse_alt(self, str): def next(self): '''Return the next record in the file.''' line = next(self.reader) + + try: + line = line.decode(self.encoding) + except AttributeError: + pass + row = self._row_pattern.split(line.rstrip()) chrom = row[0] if self._prepend_chr: