-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
904f946
commit f364a6c
Showing
15 changed files
with
1,362 additions
and
9 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Metadata | ||
|
||
Metadata is a central concept for the entirety of working with OMERo. This section will introduce some ways to interact with metadata in OMERO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Reading, writing and editing key-value pairs\n", | ||
"\n", | ||
"Key value pairs are a key (pun intended) part of annotating data in OMERO in a very flexible way. In essence, they provide a way of adding Python dictionaries to an image, a project or a dataset - and a Python dictionary is fit for data of virtually any form. Here are a few ways of interacting with data in this form through Python." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 29, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ezomero\n", | ||
"from omero.rtypes import rstring, rlong" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"host = 'omero-int.biotec.tu-dresden.de'\n", | ||
"user = 'johamuel' # replace this with your username\n", | ||
"secure = True\n", | ||
"port = 4064\n", | ||
"group = 'default'\n", | ||
"\n", | ||
"conn = ezomero.connect(host=host, user=user, secure=secure, port=port, group=group)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Adding key value pairs\n", | ||
"\n", | ||
"Let's add some kv pairs from a Python dictionary. In the OMERO terminology, key value pairs are referred to as \"map annotations\", so that's the function we'll need to use:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"kv_pairs = {'Age': 35, 'Patient name': 'John Doe'}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"object group 3\n", | ||
"8257\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"map_annotation_id = ezomero.post_map_annotation(\n", | ||
" conn,\n", | ||
" object_type='Image',\n", | ||
" object_id=330,\n", | ||
" kv_dict=kv_pairs,\n", | ||
" ns='openmicroscopy.org/omero/client/mapAnnotation')\n", | ||
"print(map_annotation_id)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If you check out your image on OMERo, you see the posted key-value pairs:\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"Let's quickly talk about the elephant the room: What exactly is the `ns` argument of the `post_map_annotation` function? It stands for \"namespace\" and is a way of grouping key-value pairs. If you have a lot of key-value pairs, you might want to group them into different namespaces to keep things organized. If you don't care about namespaces, you can just use an empty string. The default namespace is `'openmicroscopy.org/omero/client/mapAnnotation'`. \n", | ||
"\n", | ||
"```{note}\n", | ||
"If you set the namespace to a value different from 'openmicroscopy.org/omero/client/mapAnnotation', you will not be able to edit the key-value pairs in the OMERO web interface.\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Reading a key-value pair from OMERO\n", | ||
"\n", | ||
"Let's now do it the other way round: read a key-value pair from OMERO. For this, we need a two-step process: We first need to retrieve all map annotations of a single image (there can be more than one) and then we can access the key-value pairs of the individual annotations." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[8257]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"map_annotation_ids = ezomero.get_map_annotation_ids(conn, object_type='Image', object_id=330)\n", | ||
"print(map_annotation_ids)a" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Let's look at the first (and only) map annotation we just retrieved:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'Age': '35', 'Patient name': 'John Doe'}" | ||
] | ||
}, | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"kv_pairs = ezomero.get_map_annotation(conn, map_ann_id=map_annotation_ids[0])\n", | ||
"kv_pairs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Edit key-value pairs\n", | ||
"\n", | ||
"Lastly, let's say we don't want to read or write a kv pairs, but we really just want to edit a particular entry of a key-value dictionary. We start just as before by getting the map_annotation_id of the particular map annotation we are interested in." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[8257]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"map_annotation_ids = ezomero.get_map_annotation_ids(conn, object_type='Image', object_id=330)\n", | ||
"print(map_annotation_ids)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now we retrieve the map annotation as an omero object:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 42, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"mapAnnotation = conn.getObject(obj_type='MapAnnotation', oid=map_annotation_ids[0])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"This is the new dictoinary we want to save.\n", | ||
"\n", | ||
"```{warning}\n", | ||
"Setting a key-value pair like this will overwrite the entire map annotation. If you want to keep the existing key-value pairs, you will need to read the existing key-value pairs first and then update or append the dictionary.\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 45, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"kv_pairs = [\n", | ||
" ('Age', '36'),\n", | ||
" ('Patient name', 'John Doe2')\n", | ||
" ] # Note: the value should be a string - no integers allowed here" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 46, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Save the updated annotation\n", | ||
"mapAnnotation.setValue(kv_pairs)\n", | ||
"conn.getUpdateService().saveObject(mapAnnotation._obj)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"There's your result:\n", | ||
"\n", | ||
"" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "stress", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.19" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.