TreeSAPP icon indicating copy to clipboard operation
TreeSAPP copied to clipboard

Bug: TypeError in jplace_utils.py due to invalid 'encoding' parameter in json.load()

Open SilentGene opened this issue 5 months ago • 0 comments

Describe the bug

Traceback (most recent call last):
  File "/mnt/weka/pkg/cmr/heyu/treesapp/bin/treesapp", line 11, in <module>
    sys.exit(main())
  File "/mnt/weka/pkg/cmr/heyu/treesapp/lib/python3.9/site-packages/treesapp/__main__.py", line 65, in main
    cmd(sys_args[2:])
  File "/mnt/weka/pkg/cmr/heyu/treesapp/lib/python3.9/site-packages/treesapp/assign.py", line 1487, in assign
    ts_assign.place(refpkg_dict, numeric_contig_index, split_msa_files, n_proc)
  File "/mnt/weka/pkg/cmr/heyu/treesapp/lib/python3.9/site-packages/treesapp/assign.py", line 425, in place
    jplace_utils.sub_indices_for_seq_names_jplace(jplace_dir=self.stage_lookup("place").dir_path,
  File "/mnt/weka/pkg/cmr/heyu/treesapp/lib/python3.9/site-packages/treesapp/jplace_utils.py", line 238, in sub_indices_for_seq_names_jplace
    jplace_data = jplace_parser(jplace_path)
  File "/mnt/weka/pkg/cmr/heyu/treesapp/lib/python3.9/site-packages/treesapp/jplace_utils.py", line 122, in jplace_parser
    jplace_json = load(jplace, encoding="utf-8")
  File "/mnt/weka/pkg/cmr/heyu/treesapp/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/mnt/weka/pkg/cmr/heyu/treesapp/lib/python3.9/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
TypeError: __init__() got an unexpected keyword argument 'encoding'

To Reproduce Steps to reproduce the behavior:

  1. Run the command:
treesapp assign -i $input_faa -m prot --trim_align -n 4 \
  --refpkg_dir ./RefPkgs-master/Methanogenesis/McrA/seed_refpkg/final_outputs/ \
  --output $output_folder

Expected behavior Finish assign

System information (please complete the following information):

  • OS: Linux
  • Python version 3.9
  • TreeSAPP Version 0.11.4

Additional context In Python 3, the json.load() function does not accept an encoding parameter. The error occurs in jplace_utils.py at line 122 where encoding="utf-8" is passed to the load() function.

Fixed code:

jplace_json = load(jplace)

Alternatively, if encoding specification is needed, it should be applied when opening the file:

with open(filename, 'r', encoding='utf-8') as jplace:
    jplace_json = json.load(jplace)

I made the changes to the code above, and that fixed the issue.

SilentGene avatar Aug 27 '25 14:08 SilentGene