-
Notifications
You must be signed in to change notification settings - Fork 32
Move_Annotations #134
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
Move_Annotations #134
Conversation
| """Move annotations from Images in this Well onto the Well itself.""" | ||
| print "Processing Well:", well.id, well.getWellPos() | ||
| iids = [wellSample.getImage().id for wellSample in well.listChildren()] | ||
| print " Image IDs:", iids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have remove print from all other scripts.
Could you remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhhh! The prints for scripts provide the log for the user. If you don't have any prints then they won't know what's gone wrong or won't have any "info" on what the script has done. They are essential.
At least where I've used a log() function to do the printing, it's only a case of adding back the print statement there, but for scripts with individual print statements this will be a fair bit harder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now I will follow what has been done in the export scripts i.e. log and do a print at the end if required (that could be turned into an option)
and many of those prints are not necessary
they are helpful when debugging.
We will have to review that part in another round (analyis scripts initialize a logger that is not used)
|
|
||
| new_links = [] | ||
| for l in old_links: | ||
| print " Annotation:", l.child.id.val, l.child.__class__.__name__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| try: | ||
| conn.getUpdateService().saveArray(new_links) | ||
| except Exception, ex: | ||
| print "Failed to create links: ", ex.message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same. Log error instead
| return 0 | ||
|
|
||
| if remove_anns: | ||
| print "Deleting ImageAnnotation links...", link_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| to_delete = ImageAnnotationLinkI(link_id, False) | ||
| conn.getUpdateService().deleteObject(to_delete) | ||
| except Exception, ex: | ||
| print "Failed to delete links: ", ex.message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| return ann_total | ||
|
|
||
|
|
||
| def runScript(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run_script to match the formatting used in the other script
|
|
||
| client = scripts.client( | ||
| 'Move_Annotations.py', | ||
| """Move Annotations from SPW Images to their parent Wells.""", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't use SPW, better to be explicit
|
|
||
| scripts.List( | ||
| "IDs", optional=False, grouping="2", | ||
| description="List of Screen IDs or Plate IDs").ofType(rlong(0)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well is supported as a data_type, this need to be reflected in the description of the ids param
| scripts.String( | ||
| "Annotation_Type", grouping="3", | ||
| description="Move All annotations OR just one type of annotation" | ||
| " Z below.", values=ann_types, default='All'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's Z below?
| conn = BlitzGateway(client_obj=client) | ||
|
|
||
| script_params = client.getInputs(unwrap=True) | ||
| print script_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same please remove
|
Since this will be an official test, an integration test must be added to https://github.com/openmicroscopy/openmicroscopy/blob/develop/components/tools/OmeroPy/test/integration/scriptstest/test_util_scripts.py |
|
|
|
note that on this repo "flake8" is more "aggressive" than on the openmicroscopy repo |
|
Would it be possible to avoid attempting to link when such a link already exists? Might be especially useful for trying to re-run a script after deleting old links failed. |
|
If an admin runs the script would it be worth trying to preserve the ownership of the previous link? |
| try: | ||
| for link_id in link_ids: | ||
| to_delete = ImageAnnotationLinkI(link_id, False) | ||
| conn.getUpdateService().deleteObject(to_delete) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could delete in bulk?
|
@mtbc: I think we have to preserve the ownership of the links |
|
NB: This seems like code ripe for wrapping into a server-side method: "relink". cc: @mtbc |
|
Certainly feasible. If it might be done enough in general to warrant server-side support, might be worth a design issue to discuss exactly what it should be able to do and what use cases should be supported. |
|
I'm curious about users in read-only groups running this on others' data: what happens? Also, can I make a plate from someone else's dataset in a read-only group? What happens then when the annotations are being moved from a same-owner link to a different-owner link (whether by the plate owner or the image owner)? |
|
Would a dry-run mode be useful? |
|
After discussion with @pwalczysko and @mtbc, we decided to only move links that you own (unless you are an Admin). Also, we now check for existing links, so we should avoid ValidationExceptions (e.g. if you run the script twice without removing annotations). |
|
|
|
@jburel What do you think to @pwalczysko's suggestion that "Remove Annotations" should not be checked by default? |
|
I will agree with @pwalczysko |
|
Tested up till now:
|
|
Looks good, tested (locally) with Screen, Plate and Well <-> Tags, Map, File, Rating, Comment. Only own annotations get moved, unless run as admin (in which case original ownership is preserved) 👍 |
| 'File': 'FileAnnotationI', | ||
| 'Comment': 'CommentAnnotationI', | ||
| 'Rating': 'LongAnnotationI', | ||
| 'Key-Value': 'MapAnnotationI' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This subset is basically those that the web UI will usefully display for wells?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. My assumption is that users who have added annotations via their own scripts / clients will either have given them a useful namespace that can be used to select them in the Move_Annotations script OR they can also write their own script (or update this one) to customise the task.
Although I could add extra types here, I think this adds extra complexity for users and more testing for us which is probably not justified at this stage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, thank you.
|
|
||
| scripts.String( | ||
| "Annotation_Type", grouping="3", | ||
| description="Move All annotations OR just one type of annotation", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is "All" capitalized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops - getting a touch of Title Case here. https://medium.com/@jsaito/making-a-case-for-letter-case-19d09f653c98#.h1s476nc6. I'll fix...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's because "All" is an option in the dropdown list
|
Retest in UI went fine, finished all the ToDo's from #134 (comment) as well as checked the new label on the checkbox Ready to merge after the questions of @mtbc are answered. |
|
NB: I still need to finish the integration test for this script, and also add support for linking to Wells from the 'Browse' button in the Activities panel. |
|
one RFE: Support for plate acquisition in the type |
| try: | ||
| for link_id in link_ids: | ||
| to_delete = ImageAnnotationLinkI(link_id, False) | ||
| conn.getUpdateService().deleteObject(to_delete) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not use the deprecated method, use delete2 instead
|
|
|
https://trello.com/c/TNJk38iN/36-move-annotation-rfe to capture suggestions |
|
Thanks for making the changes. |


Script to Select Screens, Plates, or Wells and move Annotations from Images onto their parent Wells.
See https://trello.com/c/gasafKWk/291-update-script-wellsample-well-annotation-migration
To test:
openmicroscopy.org/omero/client/mapAnnotationfor Map Annotations).