Skip to content

Error when setting identity for SubComponent #410

Open
@noahsprent

Description

@noahsprent

Not sure if this is me being dense or it's a bug. I'm trying to give an identity to a subcomponent, but I'm receiving an error that I don't understand.

import sbol3
doc = sbol3.Document()
comp = sbol3.Component('Comp', sbol3.SBO_DNA, name="Component")
sub = sbol3.Component('subcomp', sbol3.SBO_DNA, name="Subcomponent")
subcomp = sbol3.SubComponent(sub, identity = "Test")
comp.features += [subcomp]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [9], in <cell line: 6>()
      4 sub = sbol3.Component('subcomp', sbol3.SBO_DNA, name="Subcomponent")
      5 subcomp = sbol3.SubComponent(sub, identity = "Test")
----> 6 comp.features += [subcomp]

File ~/src/miniconda3/envs/igem-distribution/lib/python3.9/_collections_abc.py:1111, in MutableSequence.__iadd__(self, values)
   1110 def __iadd__(self, values):
-> 1111     self.extend(values)
   1112     return self

File ~/src/miniconda3/envs/igem-distribution/lib/python3.9/_collections_abc.py:1094, in MutableSequence.extend(self, values)
   1092     values = list(values)
   1093 for v in values:
-> 1094     self.append(v)

File ~/src/miniconda3/envs/igem-distribution/lib/python3.9/_collections_abc.py:1073, in MutableSequence.append(self, value)
   1071 def append(self, value):
   1072     'S.append(value) -- append value to the end of the sequence'
-> 1073     self.insert(len(self), value)

File ~/src/miniconda3/envs/igem-distribution/lib/python3.9/site-packages/sbol3/property_base.py:159, in ListProperty.insert(self, index, value)
    157 item = self.from_user(value)
    158 self._storage()[self.property_uri].insert(index, item)
--> 159 self.item_added(value)

File ~/src/miniconda3/envs/igem-distribution/lib/python3.9/site-packages/sbol3/ownedobject.py:52, in OwnedObjectPropertyMixin.item_added(self, item)
     50     if sibling.identity == new_url:
     51         raise ValueError(f'Duplicate URI: {new_url}')
---> 52 item._update_identity(new_url, new_display_id)

File ~/src/miniconda3/envs/igem-distribution/lib/python3.9/site-packages/sbol3/identified.py:192, in Identified._update_identity(self, identity, display_id)
    190     msg = f'{class_name} already has identity {self.identity}'
    191     msg += ' and cannot be re-parented.'
--> 192     raise ValueError(msg)
    193 self._identity = identity
    194 self._display_id = display_id

ValueError: SubComponent already has identity http://sbols.org/unspecified_namespace/Test and cannot be re-parented.

The thing is, that the subcomponent is added and has the correct identity:

>>> comp.features[0].display_id
'Test'

If identity isn't set, the default display_id for the subcomponent is 'SubComponent[n]'. Setting a name works fine:

doc = sbol3.Document()
comp = sbol3.Component('Comp', sbol3.SBO_DNA, name="Component")
sub = sbol3.Component('subcomp', sbol3.SBO_DNA, name="Subcomponent")
subcomp = sbol3.SubComponent(sub,name="Test")
comp.features += [subcomp]
>>> comp.features[0].display_id
'SubComponent1'
>>> comp.features[0].name
'Test'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions