gyorilab / pybiopax

PyBioPAX: A python implementation of the BioPAX object model
BSD 2-Clause "Simplified" License
24 stars 6 forks source link

Adding second protein to BioPax model gives TypeError #40

Closed aditya-ml closed 2 years ago

aditya-ml commented 2 years ago

Hi all, @matthiaskoenig and I are trying to create a BioPax document for repressilator. Following @bgyori help in #36 we have the first protein as follows:

Script:

import pybiopax
from pybiopax.biopax.model import BioPaxModel
from pybiopax.biopax.base import Protein
from pybiopax.api import model_to_owl_str

objects = []
p1 = Protein(uid="PX", display_name="LacI protein")
objects.append(p1)
model = BioPaxModel(objects={o.uid: o for o in objects}, xml_base="http://www.biopax.org/release/biopax-level3.owl#")
owl_str: str = model_to_owl_str(model)

print("-" * 80)
print(owl_str)
print("-" * 80)

We get the correct output:

<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:bp="http://www.biopax.org/release/biopax-level3.owl#" xml:base="http://www.biopax.org/release/biopax-level3.owl#">
  <owl:Ontology rdf:about="">
 <owl:imports rdf:resource="http://www.biopax.org/release/biopax-level3.owl#"/>
  </owl:Ontology>

<bp:Protein rdf:ID="PX">
 <bp:displayName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">LacI protein</bp:displayName>
</bp:Protein>
</rdf:RDF>

But, adding a second Protein or any other entity (BiochemicalReaction/Stoichiometry/Provenance etc.) throws error Modified Code:

import pybiopax
from pybiopax.biopax.model import BioPaxModel
from pybiopax.biopax.base import Protein
from pybiopax.api import model_to_owl_str

objects = []
p1 = Protein(uid="PX", display_name="LacI protein")
objects.append(p1)
p2 = Protein(uid="RIGHT_0_conversion_Reaction5_PY", displayName="PY")
objects.append(p2)
model = BioPaxModel(objects={o.uid: o for o in objects}, xml_base="http://www.biopax.org/release/biopax-level3.owl#")
owl_str: str = model_to_owl_str(model)

print("-" * 80)
print(owl_str)
print("-" * 80)

Output:

Traceback (most recent call last):
  File "/Users/adityasinghal/PycharmProjects/combine-notebooks/src/combine_notebooks/example_biopax.py", line 54, in <module>
    p2 = Protein(uid="RIGHT_0_conversion_Reaction5_PY", displayName="PY")
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pybiopax/biopax/physical_entity.py", line 55, in __init__
    super().__init__(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pybiopax/biopax/physical_entity.py", line 22, in __init__
    super().__init__(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pybiopax/biopax/base.py", line 161, in __init__
    super().__init__(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pybiopax/biopax/base.py", line 25, in __init__
    super().__init__(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pybiopax/biopax/base.py", line 148, in __init__
    super().__init__(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pybiopax/biopax/base.py", line 127, in __init__
    super().__init__(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pybiopax/biopax/base.py", line 117, in __init__
    super().__init__(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pybiopax/biopax/base.py", line 181, in __init__
    super().__init__(**kwargs)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

Process finished with exit code 1
bgyori commented 2 years ago

Hi @aditya-ml, in this case there is a simple typo in your input: in the second protein, you wrote displayName instead of display_name. In PyBioPAX, all attributes use the Python-standard casing (e.g., display_name), not camel case (displayName). After fixing the typo, your example works for me.

aditya-ml commented 2 years ago

Thanks for pointing it out:)