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

Fix OligosynthesizeOligo serialization #396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Alberto024
Copy link

Example given in documentation for protocol.oligosynthesize does not work because OligosynthesizeOligo objects do not get properly serialized by protocol.as_dict() method:

Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:10:28) [Clang 15.0.7 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from autoprotocol.protocol import Protocol
>>> import json
>>> p = Protocol()
>>> oligo_1 = p.ref("oligo_1", None, "micro-1.5", discard=True)
>>> 
>>> p.oligosynthesize([{"sequence": "CATGGTCCCCTGCACAGG",
...                     "destination": oligo_1.well(0),
...                     "scale": "25nm",
...                     "purification": "standard"}])
Instruction(oligosynthesize, {'oligos': [OligosynthesizeOligo(destination=Well(Container(oligo_1), 0, None), sequence='CATGGTCCCCTGCACAGG', scale='25nm', purification='standard')]}, [])
>>> print(json.dumps(p.as_dict(), indent=2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/encoder.py", line 202, in encode
    chunks = list(chunks)
             ^^^^^^^^^^^^
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/encoder.py", line 432, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/encoder.py", line 326, in _iterencode_list
    yield from chunks
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/encoder.py", line 326, in _iterencode_list
    yield from chunks
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/encoder.py", line 439, in _iterencode
    o = _default(o)
        ^^^^^^^^^^^
  File "/Users/albertonava/mambaforge/envs/dnada11/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type OligosynthesizeOligo is not JSON serializable
>>> print(p.as_dict())
{'instructions': [{'op': 'oligosynthesize', 'oligos': [OligosynthesizeOligo(destination=Well(Container(oligo_1), 0, None), sequence='CATGGTCCCCTGCACAGG', scale='25nm', purification='standard')]}], 'refs': {'oligo_1': {'new': 'micro-1.5', 'discard': True}}}

Python Version: 3.11.4
Autoprotocol-python Version: 10.3.0

This pull request fixes this bug. There are a few other additional line changes from black formatting.

@codecov-commenter
Copy link

Codecov Report

Merging #396 (e3545d9) into master (4795408) will decrease coverage by 0.02%.
The diff coverage is 60.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master     #396      +/-   ##
==========================================
- Coverage   84.57%   84.55%   -0.02%     
==========================================
  Files          24       24              
  Lines        4589     4591       +2     
==========================================
+ Hits         3881     3882       +1     
- Misses        708      709       +1     
Files Changed Coverage Δ
autoprotocol/protocol.py 79.05% <60.00%> (-0.04%) ⬇️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants