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

support deep copying of a given opil.Document() #164

Open
tramyn opened this issue Mar 14, 2021 · 4 comments
Open

support deep copying of a given opil.Document() #164

tramyn opened this issue Mar 14, 2021 · 4 comments
Labels
enhancement New feature or request highest priority

Comments

@tramyn
Copy link

tramyn commented Mar 14, 2021

I want to perform a deep copy of a given opil.Document(). However, the current version of opil==1.0b3.post2 does not support. I need this type of method supported in order to create an opil.ExperimentalRequest from a template.

@bbartley
Copy link
Collaborator

Hi @tramyn do you want to clone the Document (all objects retain their original URIs) or copy the Document (copy objects to objects with new URIs)? From the use case you describe, it sounds like you want to copy an ExperimentalRequest rather than clone it.

Also, do you need to copy the whole Document or just a single top level object, i.e. ExperimentalRequest? The latter is already supported, I think.

@tramyn
Copy link
Author

tramyn commented Mar 18, 2021

Hi @bbartley I will want a copy of an entire opil.Document. Currently, opil allows me to copy TopLevel objects but when I have a scenario where a users tells Intent Parser to generate opil from an Experimental Request document, Intent Parser does not need to know what TopLevel objects it should copy over from a lab protocol. Instead, Intent Parser needs to know all contents originally described in a lab protocol are copied over to a new opil.Document before adding in values processed from an ER document. I want to ensure no opil objects are dropped and avoid Intent Parser from keeping track of all objects described in a given opil document.

@tramyn tramyn changed the title support deep cloning of a given opil.Document() support deep copying of a given opil.Document() Mar 18, 2021
@bbartley
Copy link
Collaborator

Hi @tramyn this issue has been cross-posted to pysbol here:
SynBioDex/pySBOL3#211

In the meantime, the following will ensure that everything from a Document gets copied over to a new Document. Basically, you just need to iterate over all the top levels objects and copy them one by one. All of the child objects will get copies over, too.

doc = opil.Document()
doc.read('ObstacleCourse.ttl')
target_doc = opil.Document()
for o in doc.objects:
     copy = o.copy()
     target_doc.add(copy)

@tramyn
Copy link
Author

tramyn commented Mar 30, 2021

@bbartley sounds good. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request highest priority
Projects
None yet
Development

No branches or pull requests

2 participants