Cell_BLAST
Cell_BLAST copied to clipboard
blast.save() TypeError: Object of type 'bytes' is not JSON serializable
Hi, thanks for building this great tool!
I have successfully computed 5 DIRECTi models and created a blast
object. However, when I tried to save it I received the following error messages:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-1abd49d75b19> in <module>
----> 1 blast.save("../data/NEMO_ARCHIVE/Yao_mouse_MOp_Miniatlas/SMARTer_cells_MOp/outs/yao_MOp_blast")
2
3 # This loads the blast object directly to memory
4 # blast = cb.blast.BLAST.load("../data/Baron_2016_Pancreas/baron_human_blast")
~/miniconda3/envs/cellblast/lib/python3.6/site-packages/Cell_BLAST/blast.py in save(self, path, only_used_genes)
690 ref.write_dataset(os.path.join(path, "ref.h5"))
691 for i in range(len(self)):
--> 692 self.models[i].save(os.path.join(path, f"model_{i}"))
693
694 @classmethod
~/miniconda3/envs/cellblast/lib/python3.6/site-packages/Cell_BLAST/model.py in save(self, path, config, weights)
283 elif not os.path.exists(path):
284 os.makedirs(path)
--> 285 self._save_config(os.path.join(path, config))
286 self._save_weights(os.path.join(path, weights))
287
~/miniconda3/envs/cellblast/lib/python3.6/site-packages/Cell_BLAST/model.py in _save_config(self, file)
228 def _save_config(self, file: str) -> None:
229 with open(file, "w") as f:
--> 230 json.dump(self._get_config(), f, indent=4)
231
232 @classmethod
~/miniconda3/envs/cellblast/lib/python3.6/json/__init__.py in dump(obj, fp, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
177 # could accelerate with writelines in some versions of Python, at
178 # a debuggability cost
--> 179 for chunk in iterable:
180 fp.write(chunk)
181
~/miniconda3/envs/cellblast/lib/python3.6/json/encoder.py in _iterencode(o, _current_indent_level)
428 yield from _iterencode_list(o, _current_indent_level)
429 elif isinstance(o, dict):
--> 430 yield from _iterencode_dict(o, _current_indent_level)
431 else:
432 if markers is not None:
~/miniconda3/envs/cellblast/lib/python3.6/json/encoder.py in _iterencode_dict(dct, _current_indent_level)
402 else:
403 chunks = _iterencode(value, _current_indent_level)
--> 404 yield from chunks
405 if newline_indent is not None:
406 _current_indent_level -= 1
~/miniconda3/envs/cellblast/lib/python3.6/json/encoder.py in _iterencode_list(lst, _current_indent_level)
323 else:
324 chunks = _iterencode(value, _current_indent_level)
--> 325 yield from chunks
326 if newline_indent is not None:
327 _current_indent_level -= 1
~/miniconda3/envs/cellblast/lib/python3.6/json/encoder.py in _iterencode(o, _current_indent_level)
435 raise ValueError("Circular reference detected")
436 markers[markerid] = o
--> 437 o = _default(o)
438 yield from _iterencode(o, _current_indent_level)
439 if markers is not None:
~/miniconda3/envs/cellblast/lib/python3.6/json/encoder.py in default(self, o)
178 """
179 raise TypeError("Object of type '%s' is not JSON serializable" %
--> 180 o.__class__.__name__)
181
182 def encode(self, o):
TypeError: Object of type 'bytes' is not JSON serializable
If I BLAST query cells to the blast
object, it works properly. So this seems to be a bug related to the blast.save()
itself.
Best, Ray