Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change Reader constructor to deal with encoding issues

  • Loading branch information...
commit bc6918c85263a6c7f3a21cdc31caed3c3c0f5b9b 1 parent fbc3e0e
@marcelm authored
Showing with 11 additions and 11 deletions.
  1. +11 −11 vcf/parser.py
View
22 vcf/parser.py
@@ -5,6 +5,7 @@
import gzip
import sys
import itertools
+import codecs
try:
import pysam
@@ -452,20 +453,19 @@ def __init__(self, fsock=None, filename=None, compressed=False, prepend_chr=Fals
if not (fsock or filename):
raise Exception('You must provide at least fsock or filename')
- if filename:
- self.filename = filename
- if fsock is None:
- self.reader = file(filename)
-
if fsock:
self.reader = fsock
- if filename is None:
- if hasattr(fsock, 'name'):
- filename = fsock.name
- self.filename = filename
-
- if compressed or (filename and filename.endswith('.gz')):
+ if filename is None and hasattr(fsock, 'name'):
+ filename = fsock.name
+ compressed = compressed or filename.endswith('.gz')
+ elif filename:
+ compressed = compressed or filename.endswith('.gz')
+ self.reader = open(filename, 'rb' if compressed else 'rt')
+ self.filename = filename
+ if compressed:
self.reader = gzip.GzipFile(fileobj=self.reader)
+ if sys.version > '3':
+ self.reader = codecs.getreader('ascii')(self.reader)
#: metadata fields from header
self.metadata = None
Please sign in to comment.
Something went wrong with that request. Please try again.