Skip to content

Commit

Permalink
FastQC: fix UnicodeDecodeError parsing fastqc_data.txt (try latin-1…
Browse files Browse the repository at this point in the history
… or fail gracefully) (#2024)

* Gracefully catch UnicodeDecodeError

* FastQC: fix `UnicodeDecodeError` parsing fastqc_data.txt (try latin-1 or fail gracefully)
  • Loading branch information
vladsavelyev committed Sep 3, 2023
1 parent 8e471b3 commit fc87b71
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions multiqc/modules/fastqc/fastqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ def __init__(self):
# FastQC zip files should have just one directory inside, containing report
d_name = fqc_zip.namelist()[0]
try:
with fqc_zip.open(os.path.join(d_name, "fastqc_data.txt")) as fh:
r_data = fh.read().decode("utf8")
path = os.path.join(d_name, "fastqc_data.txt")
with fqc_zip.open(path) as fh:
r_data = fh.read()
try:
r_data = r_data.decode("utf8")
except UnicodeDecodeError as e:
log.debug(f"Could not parse {path} as Unicode: {e}, attempting the latin-1 encoding")
try:
r_data = r_data.decode("latin-1")
except Exception as e:
log.warning(f"Error reading FastQC data file {path}: {e}. Skipping sample {s_name}.")
continue
self.parse_fastqc_report(r_data, s_name, f)
except KeyError:
log.warning("Error - can't find fastqc_raw_data.txt in {}".format(f))
Expand Down

0 comments on commit fc87b71

Please sign in to comment.