-
Notifications
You must be signed in to change notification settings - Fork 16
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
if the namespace of an object is changed it should be reflected in the object #412
Comments
pySBOL3 intentionally uses a "permissive" model of property changes, in which it does not check for potential inconsistencies until the user requests validation, since the user may be performing a given operation in the middle of some sort of multi-stage operation. If you run a document validation after running the code that you provided, however, you will find that it does identify an error due to the invalid state that has been created:
Changing the namespace of an object is a potentially dangerous operation, since it can break links with other objects that point to this object, as well with with its child objects. As such, we recommend changing namespace via the "safe" function provided for that purpose on the Document class:
This function provides a guaranteed safe change for a group of objects, moving all of them as a unit into the new namespace and preserving links both within the group and with external references. |
The change_object_namespace almost does what I want, unfortunately it doesn't update other references to the object (e.g. if a component is used in a combinatorial derivation the component is updated but the reference to it in the combinatorial derivation is not). Is there a function to do that too, i.e. to preserve the external references? |
@JMante1 this could be a bug. |
I wrote this as a work around:
|
@JMante1 Thank you for the short and simple test case to demonstrate the problem, and thank you for taking the time to develop a workaround. Both are appreciated. |
@JMante1 I have merged an enhancement to provide the functionality I think you need. With this enhancement you can add a third argument to doc.change_object_namespace([seq], 'http://parts.igem.org', doc) Are you able to test from the "main" branch to see if this fix works for your original case? If possible I'd like to hear back from you before I cut a new release of pySBOL3 that includes this fix. |
Reopening because the autoclose happened before @JMante1 could test the fix. |
Hi @JMante1 please let us know when you are able to test this fix. Does it resolve your issue? |
Hi, it does work for the simpler test case but not for the more complicated one. I am not sure if it is because of the way I am referencing documents or not? Additionally, I have derived parts e.g. partname_sequence etc that I also want to update. Your code doesn't allow this. Do you intend to add this or should I continue to use the work around for that case anyway? |
I'd be happy to try, but I'll need more information. There's not enough to go on here. For "the more complicated" test case, I'm assuming you are referring to this one: import sbol3
import os
direct = os.path.split(__file__)[0]
file_path_out = os.path.join(direct, 'out.nt')
doc = sbol3.Document()
comp = sbol3.Component('http://sbolstandard.org/testfiles/hello', sbol3.SBO_DNA)
seq = sbol3.Sequence('http://sbolstandard.org/testfiles/hello_sequence', elements='ATGC')
doc.add(comp)
doc.add(seq)
comp.sequences = [seq]
doc.change_object_namespace([seq], 'http://parts.igem.org')
doc.write(file_path_out) Did you make the change I noted in my comment? Here is the change you need to make, in case you did not update the code: doc.change_object_namespace([seq], 'http://parts.igem.org', doc) Note the third argument. The above code works for me. I think I used a variant of your code for a test case. Let's get this settled before moving on to the derived parts issue. For that one I think I will need an example of failing code in order to understand the differences and test a fix. Thanks! |
No, for test case above it does work for me. I am using it as part of the excel to sbol code and it doesn't work as part of that code. However, that is a really complicated code base. I can try and create a simpler version that gives the same errors, however, I was wondering if it was worth the effort if the derived objects will still need to be fixed via the work around. |
I've read your workaround code and I think a derived object is one whose URI appears to be "derived from" another URI. For example, If both of those objects, the I think your third case, under the comment I could work up an example if you think I'm understanding your code and your question. Thanks for your patience. |
I think you understand and it would work if I restructured my code somewhat. What happens to your function if you give it objects to change which don't exist? Does it just skip them or do I need to create an intersect of possible derived objects and objects that exist? |
obj = sbol3.Component('hello', [sbol3.SBO_DNA]) obj.name = 'hello' obj.namespace = 'parts.igem.org' doc.add(obj)
This code leads to an object with http://sbols.org/unspecified_namespace used everywhere, except for the has namespace property. if the namespace property is updated it should change the namespace used throughout the property
The text was updated successfully, but these errors were encountered: