Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastQC: fix UnicodeDecodeError parsing fastqc_data.txt (try latin-1 or fail gracefully) #2024

Merged
merged 2 commits into from
Sep 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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