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

Activity usages #97

Open
eoberortner opened this issue Jun 11, 2019 · 2 comments
Open

Activity usages #97

eoberortner opened this issue Jun 11, 2019 · 2 comments

Comments

@eoberortner
Copy link

eoberortner commented Jun 11, 2019

Hi, how do you set the qualifiedUsages of an Activity properly?

The following piece of code does not serialize the usages of the Activity:

    document = Document()
    
    original_cd = ComponentDefinition('original_CD')
    document.addComponentDefinition(original_cd)
    
    my_activity = Activity('my_activity')
    activity_usages = [original_cd.identity]
    my_activity.usages = activity_usages
    document.addActivity(my_activity)
    
    updated_cd = ComponentDefinition('updated_CD')
    updated_cd.wasDerivedFrom = original_cd.identity
    updated_cd.wasGeneratedBy = my_activity.identity
    document.addComponentDefinition(updated_cd)

    print(document.writeString())

And here's the generated serialized document that I get:

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/"
   xmlns:prov="http://www.w3.org/ns/prov#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:sbol="http://sbols.org/v2#"
   xmlns:sys-bio="http://sys-bio.org#">
  <prov:Activity rdf:about="http://examples.org/Activity/my_activity/1">
    <sbol:displayId>my_activity</sbol:displayId>
    <sbol:persistentIdentity rdf:resource="http://examples.org/Activity/my_activity"/>
    <sbol:version>1</sbol:version>
  </prov:Activity>
  <sbol:ComponentDefinition rdf:about="http://examples.org/ComponentDefinition/original_CD/1">
    <sbol:displayId>original_CD</sbol:displayId>
    <sbol:persistentIdentity rdf:resource="http://examples.org/ComponentDefinition/original_CD"/>
    <sbol:type rdf:resource="http://www.biopax.org/release/biopax-level3.owl#DnaRegion"/>
    <sbol:version>1</sbol:version>
  </sbol:ComponentDefinition>
  <sbol:ComponentDefinition rdf:about="http://examples.org/ComponentDefinition/updated_CD/1">
    <sbol:displayId>updated_CD</sbol:displayId>
    <sbol:persistentIdentity rdf:resource="http://examples.org/ComponentDefinition/updated_CD"/>
    <sbol:type rdf:resource="http://www.biopax.org/release/biopax-level3.owl#DnaRegion"/>
    <sbol:version>1</sbol:version>
    <prov:wasDerivedFrom rdf:resource="http://examples.org/ComponentDefinition/original_CD/1"/>
    <prov:wasGeneratedBy rdf:resource="http://examples.org/Activity/my_activity/1"/>
  </sbol:ComponentDefinition>
</rdf:RDF>

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)

    activity_usages = [original_cd.identity]
    my_activity.usages = activity_usages

vs
(2)

    my_activity.usages.append(original_cd.identity)

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!

@bbartley
Copy link
Contributor

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.

@eoberortner
Copy link
Author

eoberortner commented Jun 11, 2019 via email

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

No branches or pull requests

2 participants