vierstralab / footprint-tools

A toolset to analyze genomic footprinting data
GNU General Public License v3.0
19 stars 3 forks source link

ftd-learn-dispersion-model reports error when dumping model to json #10

Closed yushengak47 closed 3 years ago

yushengak47 commented 3 years ago

Hi,

Thanks for developing this toolkit.

When I run ftd-learn-dispersion-model, it reported the following error:

Traceback (most recent call last): File "/home/yus/.local/bin/ftd-learn-dispersion-model", line 161, in sys.exit(main()) File "/home/yus/.local/bin/ftd-learn-dispersion-model", line 155, in main print(dispersion.write_dispersion_model(model), file = sys.stdout) File "footprint_tools/modeling/dispersion.pyx", line 419, in footprint_tools.modeling.dispersion.write_dispersion_model File "/home/yus/anaconda3/envs/footprint/lib/python3.9/json/init.py", line 234, in dumps return cls( File "/home/yus/anaconda3/envs/footprint/lib/python3.9/json/encoder.py", line 201, in encode chunks = list(chunks) File "/home/yus/anaconda3/envs/footprint/lib/python3.9/json/encoder.py", line 431, in _iterencode yield from _iterencode_dict(o, _current_indent_level) File "/home/yus/anaconda3/envs/footprint/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict yield from chunks File "/home/yus/anaconda3/envs/footprint/lib/python3.9/json/encoder.py", line 325, in _iterencode_list yield from chunks File "/home/yus/anaconda3/envs/footprint/lib/python3.9/json/encoder.py", line 438, in _iterencode o = _default(o) File "/home/yus/anaconda3/envs/footprint/lib/python3.9/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.class.name} ' TypeError: Object of type bytes is not JSON serializable

I searched around and tried several methods with no lucky. Could you give me some help? Thanks.

YU Sheng

jvierstra commented 3 years ago

I think this error is unique to Python3.8+. I am updating the serialization code. In the meantime, do you have access to version 3.6?

yushengak47 commented 3 years ago

Thanks for your reply.

Yes, I'll have a try using python3.6. Will get back to you soon.

yushengak47 commented 3 years ago

The program reports the same error in python3.6 environment

jvierstra commented 3 years ago

Hmm. I will take a look today and get back to you.

yushengak47 commented 3 years ago

I searched a bit and solved the problem by changing the 365th line of dispersion.pyx:

original: return [str(x.dtype), base64.b64encode(x), x.shape] modified: return [str(x.dtype), base64.b64encode(x).decode('latin1'), x.shape]

By the way, I've encountered another compatible issue in script 'generate_bias_model.sh'. I found the following modifications could solve the problem:

original: 97 while(1): 98 try: 99 read = reads.next() 100 except: 101 break

modified: 97 for read in reads.fetch():

Cheers,

YU Sheng

jvierstra commented 3 years ago

I just updated the code-base to fix many issues (including the JSON serialization). It is on PyPi: pip install footprint-tools=1.2.1. You can also use conda to replicate my build environment -- see the README.md file for details.

jvierstra commented 3 years ago

Fixed in version 1.3.3