SynBioDex / pySBOL2

A pure Python implementation of the SBOL standard.
Apache License 2.0
20 stars 6 forks source link

Copy Function Changes Namespace for Sub-Component Definition #398

Open nroehner opened 3 years ago

nroehner commented 3 years ago

When copying a ComponentDefinition "parent" that has a sub-Component "child" into a new namespace, if the definition property of "child" refers to a ComponentDefinition in the same document, then the definition property of the copy of "child" appears to be imported into the same namespace as the copy of "child". As a user, I would expect the copy of "child" to retain the same definition property as the original "child". I would only expect this definition property to be copied into a different namespace if the ComponentDefinition to which it refers is also copied into a new namespace, which it currently is not. Maybe there should be an option to recursively copy in this manner. Here is some example code:

import sbol2

sbol2.Config.setOption('sbol_typed_uris', False)
sbol2.Config.setOption('validate', False)
sbol2.setHomespace('http://synbict.org')

test_doc = sbol2.Document()

parent_comp = test_doc.componentDefinitions.create('parent')

child_sub_comp = parent_comp.components.create('child')

child_sub_comp.definition = 'http://synbict.org/child/1'

child_comp = test_doc.componentDefinitions.create('child')

sbol2.setHomespace('http://sd2e.org')

parent_comp.copy(test_doc, 'http://synbict.org', '1')

parent_copy = test_doc.componentDefinitions.get('http://sd2e.org/parent/1')

child_copy = parent_copy.components.get('http://sd2e.org/parent/child/1')

print('Should be True: ' + str(child_copy .definition == 'http://synbict.org/child/1'))
tcmitchell commented 3 years ago

This one is probably a sticky wicket. It will require a two-pass approach to copying that isn't set up in the current recursive implementation. The first pass would do all the renaming and create a map of old-to-new names. The second pass would then update references based on the renaming map. There may be other approaches as well.