How to tag and retrieve tags from data#
Another key concept of organizing data on OMERO (besides key-value pairs) is given by tags. Can be used to group data in a more flexible way than the hierarchy of projects, datasets and images. For a more in-depth explanation of some of the underlying concepts, see these excellent training materials regarding OMERO in general.
import ezomero
host = 'omero-int.biotec.tu-dresden.de'
user = '' # replace this with your username
secure = True
port = 4064
group = 'default'
conn = ezomero.connect(host=host, user=user, secure=secure, port=port, group=group)
Tagging data#
The easiest and most straightforward way to tag your data is arguably to simply do this through the web interface of your OMERO servers. Omero extensions such as the excellent autotag extension make setting meaningful tags on your data a breeze. The question then becomes - how do you retrieve tags that have already been added to your data?
Adding a tag to data#
Adding a tag to an image is a little less straightforward. For once, it makes more sense to create and organize the tags through the web interface. The following tutorial introduces a way to set tags and tag groups from a yaml file, but this is a bit more complicated. For simplicity, let’s assume we already created some tags and we know their ids from the web interface:
To add this newly created tag to our image, we need to first retrieve both the tag and the image objects from the remote server:
tag_object = conn.getObject('Annotation', 8354)
image_object = conn.getObject('Image', 330)
In the next step, we link the tag to the image:
image_object.linkAnnotation(tag_object)
Let’s check whether this worked:
tag_ids = ezomero.get_tag_ids(conn, object_type='Image', object_id=330, ns=None)
for tag_id in tag_ids:
print(ezomero.get_tag(conn, tag_id=tag_id), ' ', f'(Tag id: {tag_id})')
Fluorescence (Tag id: 1088)
Raw data (Tag id: 8354)