From 3ee5a931b740922b13c402acc4180be6b73bb175 Mon Sep 17 00:00:00 2001 From: Justin Koestinger Date: Tue, 2 Oct 2018 14:43:44 +0200 Subject: [PATCH 1/3] Added support for bytes read files (ie. for remote files) --- vcf/parser.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/vcf/parser.py b/vcf/parser.py index c3c3d08..766a105 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 @@ -314,6 +314,11 @@ def _parse_metainfo(self): parser = _vcf_metadata_parser() + try: + line = line.decode(self.encoding) + except AttributeError: + pass + line = next(self.reader) while line.startswith('##'): self._header_lines.append(line) @@ -347,7 +352,10 @@ def _parse_metainfo(self): self.metadata[key] = [] 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 +559,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: From 8df5301037288dcb9b97859e95f0b5c51e243e14 Mon Sep 17 00:00:00 2001 From: Justin Koestinger Date: Tue, 2 Oct 2018 14:52:37 +0200 Subject: [PATCH 2/3] Rectified error in implementation --- vcf/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vcf/parser.py b/vcf/parser.py index 766a105..14266c4 100644 --- a/vcf/parser.py +++ b/vcf/parser.py @@ -313,13 +313,14 @@ def _parse_metainfo(self): setattr(self, attr, OrderedDict()) parser = _vcf_metadata_parser() + + line = next(self.reader) try: line = line.decode(self.encoding) except AttributeError: pass - line = next(self.reader) while line.startswith('##'): self._header_lines.append(line) From 46c1c8a45ab8aa3a658233959f110490d3016cb2 Mon Sep 17 00:00:00 2001 From: Justin Koestinger Date: Tue, 2 Oct 2018 14:58:51 +0200 Subject: [PATCH 3/3] Fixed typo --- vcf/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vcf/parser.py b/vcf/parser.py index 14266c4..08daa08 100644 --- a/vcf/parser.py +++ b/vcf/parser.py @@ -313,7 +313,7 @@ def _parse_metainfo(self): setattr(self, attr, OrderedDict()) parser = _vcf_metadata_parser() - + line = next(self.reader) try: @@ -353,6 +353,7 @@ def _parse_metainfo(self): self.metadata[key] = [] self.metadata[key].append(val) + line = next(self.reader) try: line = line.decode(self.encoding) except AttributeError: