aboutsummaryrefslogtreecommitdiff
path: root/quality_control
diff options
context:
space:
mode:
Diffstat (limited to 'quality_control')
-rw-r--r--quality_control/parsing.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/quality_control/parsing.py b/quality_control/parsing.py
index 9f8e8ee..f1f4f79 100644
--- a/quality_control/parsing.py
+++ b/quality_control/parsing.py
@@ -4,6 +4,7 @@ import os
import collections
from enum import Enum
from functools import partial
+from zipfile import ZipFile, is_zipfile
from typing import Iterable, Generator, Callable, Optional
import quality_control.average as avg
@@ -79,11 +80,21 @@ def collect_errors(
return errors + tuple(error for error in errs if error is not None)
return errors + (errs,)
- with open(filepath, encoding="utf-8") as input_file:
+ def __open_file__(filepath):
+ if not is_zipfile(filepath):
+ return open(filepath, encoding="utf-8")
+
+ with ZipFile(filepath, "r") as zfile:
+ return zfile.open(zfile.infolist()[0], "r")
+
+ with __open_file__(filepath) as input_file:
for line_number, line in enumerate(input_file, start=1):
if user_aborted():
break
+ if isinstance(line, bytes):
+ line = line.decode("utf-8")
+
if line_number == 1:
for error in __process_errors__(
line_number, line, partial(header_errors, strains=strains),