I have been working on making script for automatic tagging on import for the Omero client. I have been having trouble with one tiny problem which I think could easily be solved.
- Code: Select all
def saveAndLinkAnnotation(updateService, parent, annotation, ns=None, description=None):
""" Saves the Annotation and Links it to a Project, Dataset or Image """
if ns:
annotation.setNs(rstring(ns))
if description:
annotation.setDescription(rstring(description))
annotation = updateService.saveAndReturnObject(annotation)
if type(parent) == omero.model.DatasetI:
l = omero.model.DatasetAnnotationLinkI()
elif type(parent) == omero.model.ProjectI:
l = omero.model.ProjectAnnotationLinkI()
elif type(parent) == omero.model.ImageI:
l = omero.model.ImageAnnotationLinkI()
else:
return
parent = parent.__class__(parent.id.val, False)
l.setParent(parent)
l.setChild(annotation)
return updateService.saveAndReturnObject(l)
# Text Annotations
def addTag(updateService, parent, text, ns=None, description=None):
""" Adds a Tag. """
child = omero.model.TagAnnotationI()
child.setTextValue(rstring(text))
saveAndLinkAnnotation(updateService, parent, child, ns, description)
These are the functions I am using to add a tag, so far so good. Then I want to go through all the images in my dataset and tag them all.
- Code: Select all
obs = conn.getObjects(dataType, ids)
objects = list(obs)
if len(objects) == 0:
print "No %ss found for specified IDs" % dataType
return
images = []
if dataType == 'Dataset':
for ds in objects:
print "Processing Images from Dataset: %s" % ds.getName()
imgs = list(ds.listChildren())
images.extend(imgs)
else:
print "Processing Images identified by ID"
images = objects
editedImgIds = []
for i in images:
print " Editing image ID: %d Name: %s" % (i.id, i.name)
# i.name returns full name of file with .jpg ending
#print conn.getObject("Dataset", 102)._obj
#print conn.getObject("Image", i.id)._obj
### EXPERIMENTAL TAGGING
addTag(updateService, i._obj, "Test_Tag", "test/omero/tag/ns", description=None)
editedImgIds.append(i.id)
return editedImgIds
When I select dataset when I am running the script I am only able to tag the datasets with given IDs and when I am running the scripts with selecting multiple images the script works fine and tags all the images.
I would though like to be able to select multiple datasets and be able to tag all images in these given datasets, not the datasets themselves. I don't want to select all the images as they could be thousands and would therefore make my automatic tagging useless.
There is also one slight problem, in the given example above I tagged multiple images with the "Test_Tag" tag and when I look at my tags the "Test_Tag" tag is shown multiple times in my tags, is there an easy way to solve this problem?
P.S. this is not the code as whole, if you are missing context I could show you all of the code.
Best regards,
Ívar