Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #73 from martijnvermaat/ignore-empty-lines

Ignore empty lines
  • Loading branch information...
commit 5da6932e84f9b3fdee7b6aaa5bb7f789a2b9ed82 2 parents 964c372 + 9712355
James Casbon authored
Showing with 9 additions and 8 deletions.
  1. +9 −8 vcf/parser.py
View
17 vcf/parser.py
@@ -185,18 +185,20 @@ def __init__(self, fsock=None, filename=None, compressed=False, prepend_chr=Fals
raise Exception('You must provide at least fsock or filename')
if fsock:
- self.reader = fsock
+ self._reader = fsock
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._reader = open(filename, 'rb' if compressed else 'rt')
self.filename = filename
if compressed:
- self.reader = gzip.GzipFile(fileobj=self.reader)
+ self._reader = gzip.GzipFile(fileobj=self._reader)
if sys.version > '3':
- self.reader = codecs.getreader('ascii')(self.reader)
+ self._reader = codecs.getreader('ascii')(self._reader)
+
+ self.reader = (line.strip() for line in self._reader if line.strip())
#: metadata fields from header (string or hash, depending)
self.metadata = None
@@ -232,7 +234,6 @@ def _parse_metainfo(self):
line = self.reader.next()
while line.startswith('##'):
self._header_lines.append(line)
- line = line.strip()
if line.startswith('##INFO'):
key, val = parser.read_info(line)
@@ -251,7 +252,7 @@ def _parse_metainfo(self):
self.formats[key] = val
else:
- key, val = parser.read_meta(line.strip())
+ key, val = parser.read_meta(line)
if key in SINGULAR_METADATA:
self.metadata[key] = val
else:
@@ -261,7 +262,7 @@ def _parse_metainfo(self):
line = self.reader.next()
- fields = re.split('\t| +', line.rstrip())
+ fields = re.split('\t| +', line)
self.samples = fields[9:]
self._sample_indexes = dict([(x,i) for (i,x) in enumerate(self.samples)])
@@ -436,7 +437,7 @@ def _parse_alt(self, str):
def next(self):
'''Return the next record in the file.'''
line = self.reader.next()
- row = re.split('\t| +', line.strip())
+ row = re.split('\t| +', line)
chrom = row[0]
if self._prepend_chr:
chrom = 'chr' + chrom
Please sign in to comment.
Something went wrong with that request. Please try again.