Open eoberortner opened 5 years ago
Hi, one thing to keep in mind is that Activity.usages expects a Usage object, not a URI reference. So, something like this:
>>> product = ComponentDefinition('product')
>>> substrate = ComponentDefinition('substrate')
>>> a = Activity('a')
>>> product.wasGeneratedBy = a.identity
>>> u = a.usages.create('u')
>>> u.entity = substrate.identity
In general when modifying properties that can contain multiple values, you have to use the following idiom:
>>> product.roles = SO + "0000001"
>>> product.roles
['http://identifiers.org/so/SO:0000001']
>>> product.roles += [SO + "1234567"]
>>> product.roles
['http://identifiers.org/so/SO:0000001', 'http://identifiers.org/so/SO:1234567']
It's doesn't behave exactly like a pythonic list, because it's actually a wrapped C++ data structure. So, avoid using append
and extend
methods.
Thanks Bryan for pointing out that there’s a Usage object needed and to avoid python list operations! It’ll still take some time for me to understand the python SBOL library.
Thanks, Ernst
On Jun 11, 2019, at 7:21 AM, bbartley notifications@github.com wrote:
Hi, one thing to keep in mind is that Activity.usages expects a Usage object, not a URI reference. So, something like this:
product = ComponentDefinition('product') substrate = ComponentDefinition('substrate') a = Activity('a') product.wasGeneratedBy = a.identity u = a.usages.create('u') u.entity = substrate.identity In general when modifying properties that can contain multiple values, you have to use the following idiom:
product.roles = SO + "0000001" product.roles ['http://identifiers.org/so/SO:0000001'] product.roles += [SO + "1234567"] product.roles ['http://identifiers.org/so/SO:0000001', 'http://identifiers.org/so/SO:1234567'] It's doesn't behave exactly like a pythonic list, because it's actually a wrapped C++ data structure. So, avoid using append and extend methods.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SynBioDex/pySBOL/issues/97?email_source=notifications&email_token=AAKQ4ZXTPEOZMAKDGT5K7L3PZ6YGHA5CNFSM4HW6LMDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXNJF7Y#issuecomment-500863743, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKQ4ZWCLMOEQ3CGCB4KKBLPZ6YGHANCNFSM4HW6LMDA.
Hi, how do you set the qualifiedUsages of an Activity properly?
The following piece of code does not serialize the usages of the Activity:
And here's the generated serialized document that I get:
My other question is creating your own list and assigning it to an SBOL object's property (1) vs. using python's functions (.append(), .extend(),...) for adding objects to a list (2)? Here's an example: (1)
vs (2)
When using (2), the following error comes up "AttributeError: 'OwnedUsage' object has no attribute 'append'" How do I know when to use option (1) and when to use option (2)? Based on when an error is thrown?
Thanks for your help!