Skip to content

Commit

Permalink
Use chardet to auto-detect encoding from Pathway Tools terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBelcour committed Oct 7, 2020
1 parent 914bf6e commit bc77418
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mpwt/pwt_wrapper.py
Expand Up @@ -2,7 +2,7 @@
Wrapping Pathway Tools for PathoLogic and attribute-values dat files creation.
Move results files to an output folder.
"""

import chardet
import logging
import os
import shutil
Expand Down Expand Up @@ -133,7 +133,8 @@ def run_pwt(species_input_folder_path, patho_hole_filler, patho_operon_predictor
# Check internal error of Pathway Tools.
with open(pwt_log, 'w') as pwt_writer:
for patho_line in iter(patho_subprocess.stdout.readline, b''):
patho_line = patho_line.decode('ascii')
encoding = chardet.detect(patho_line)['encoding']
patho_line = patho_line.decode(encoding)
pwt_writer.write(patho_line)
if any(error in patho_line for error in errors):
logger.info('Error possibly with the genbank file.')
Expand Down Expand Up @@ -196,7 +197,8 @@ def run_pwt_dat(species_input_folder_path):
load_subprocess = subprocess.Popen(cmd_dat, stdout=subprocess.PIPE, universal_newlines="")
with open(dat_log, 'w') as dat_file_writer:
for load_line in iter(load_subprocess.stdout.readline, b''):
load_line = load_line.decode('ascii')
encoding = chardet.detect(load_line)['encoding']
load_line = load_line.decode(encoding)
dat_file_writer.write(load_line)
if any(dat_end in load_line for dat_end in dat_creation_ends):
load_subprocess.stdout.close()
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -30,6 +30,7 @@
packages=['mpwt'],
install_requires=[
'biopython>=1.70',
'chardet>=3.0.4'
'docopt>=0.6.2',
'gffutils>=0.9',
],
Expand Down

0 comments on commit bc77418

Please sign in to comment.