Annotation scripts
Convert KeyVal namespace
Convert_KeyVal_namespace.py
Convert the namespace of objects key-value pairs.
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- Convert_KeyVal_namespace.annotate_object(conn, obj, kv_list, namespace)
Create a new MapAnnotation with specified Key-Value pairs on an OMERO object.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection object for annotation.
obj (omero.model.<ObjectType>) – OMERO object to annotate.
kv_list (list of tuples) – Key-Value pairs to include in the annotation.
namespace (str) – Namespace for the new annotation.
- Returns
The annotation is linked to the object within the OMERO database.
- Return type
None
- Convert_KeyVal_namespace.get_children_recursive(source_object, target_type)
Recursively retrieve child objects of a specified type from a source OMERO object.
- Parameters
source_object (omero.model.<ObjectType>) – The OMERO source object from which child objects are retrieved.
target_type (str) – The OMERO object type to be retrieved as children.
- Returns
A list of child objects of the specified target type.
- Return type
list
- Convert_KeyVal_namespace.get_existing_map_annotations(obj, namespace_l)
Retrieve existing map annotations with specified Namespaces from an OMERO object.
- Parameters
obj (omero.model.<ObjectType>) – OMERO object from which annotations are retrieved.
namespace_l (list of str) – List of namespaces used to filter annotations.
- Returns
A tuple containing a list of Key-Value pairs and a list of MapAnnotation objects.
- Return type
tuple
- Convert_KeyVal_namespace.main_loop(conn, script_params)
Process OMERO objects, updating or merging Namespaces of Key-Value annotations.
This function iterates over objects, identifies annotations with specified Namespaces, and either updates or merges them according to provided parameters.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection object for database operations.
script_params (dict) – Dictionary of parameters required by the script.
- Returns
Summary message indicating update counts, and the result object.
- Return type
tuple
- Convert_KeyVal_namespace.parameters_parsing(client)
Parse input parameters from the OMERO client, establishing defaults and validating specific combinations for data types and Namespaces.
- Parameters
client – The OMERO client object from which input parameters are
retrieved. :type client: omero.gateway.BlitzGateway :return: A dictionary of parsed parameters, including validated and default
values for processing the script logic.
- Return type
dict
- Convert_KeyVal_namespace.remove_map_annotations(conn, ann_l)
Delete specified MapAnnotations from OMERO.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
ann_l (list of omero.model.MapAnnotationWrapper) – List of map annotation objects to delete.
- Returns
Returns 1 if deletion succeeds, otherwise 0.
- Return type
int
- Convert_KeyVal_namespace.run_script()
Execute the OMERO script to convert Namespaces for key-value pair annotations.
This function initializes the script parameters, processes input from the OMERO client, and orchestrates the execution of the main script logic, including handling target data types and merging annotations.
- Parameters
None – This function does not take any parameters.
- Returns
This function does not return a value; it sets outputs directly to the client.
- Return type
None
- Convert_KeyVal_namespace.target_iterator(conn, source_object, target_type, is_tag)
Iterate over and yield target objects of a specified type from a source OMERO object.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
source_object (omero.model.<ObjectType>) – Source OMERO object to iterate over.
target_type (str) – Target object type to retrieve.
is_tag (bool) – Flag indicating if the source object is a tag.
- Yield
Target objects of the specified type.
- Return type
omero.model.<ObjectType>
Export to CSV
Export_to_csv.py
Reads the metadata associated with the images in a dataset and creates a csv file attached to dataset
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- Export_to_csv.attach_csv(conn, obj_, rows, separator, csv_name)
Attaches a generated CSV file to an OMERO object.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
obj (omero.model.<ObjectType>) – OMERO object to which the CSV file will be attached.
rows (list) – Data rows to write into the CSV.
separator (str) – Separator character for CSV file.
csv_name (str) – Name for the generated CSV file.
- Returns
File annotation object if the file is attached, None otherwise.
- Return type
omero.model.FileAnnotation
- Export_to_csv.build_rows(annotation_dict_l, tagannotation_l, include_namespace)
Constructs rows for CSV export by organizing annotations and Tags.
- Parameters
annotation_dict_l (defaultdict(list)) – Dictionary of annotations organized by Namespace.
tagannotation_l (list) – List of Tag annotations.
include_namespace (bool) – Flag indicating if Namespace should be included in the CSV.
- Returns
Tuple containing Namespace row, header row, and data rows for the CSV.
- Return type
tuple
- Export_to_csv.get_all_tags(conn)
Retrieves all Tag annotations and Tagsets from OMERO.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
- Returns
Dictionary mapping tag IDs to Tag names or Tagset names.
- Return type
dict
- Export_to_csv.get_children_recursive(source_object, target_type)
Recursively retrieve child objects of a specified type from a source OMERO object.
- Parameters
source_object – The OMERO source object from which child objects
are retrieved. :type source_object: omero.model.<ObjectType> :param target_type: The OMERO object type to be retrieved as children. :type target_type: str :return: A list of child objects of the specified target type. :rtype: list
- Export_to_csv.get_existing_map_annotations(obj, namespace)
Retrieves existing Key-Value pair annotations from an OMERO object.
- Parameters
obj (omero.model.<ObjectType>) – OMERO object to retrieve annotations from.
namespace (str) – Specific Namespace of annotations to retrieve; ‘*’ retrieves all.
- Returns
List of MapAnnotationWrapper objects for the specified Namespace.
- Return type
list
- Export_to_csv.get_existing_tag_annotations(obj, all_tag_d)
Retrieves existing Tag annotations from an OMERO object.
- Parameters
obj (omero.model.<ObjectType>) – OMERO object to retrieve Tags from.
all_tag_d (dict) – Dictionary of all Tags with Tagset names, if applicable.
- Returns
List of Tag names associated with the specified OMERO object.
- Return type
list
- Export_to_csv.get_obj_name(omero_obj)
Helper function
- Export_to_csv.group_keyvalues(objannotation_l)
Groups Key-Value pairs of each object into a unified structure for CSV export.
- Parameters
objannotation_l (list) – List of object annotations to be grouped.
- Returns
Tuple containing the header row and data rows for each object’s annotations.
- Return type
tuple
- Export_to_csv.main_loop(conn, script_params)
Main loop to process each object, gathering annotations, ancestry, and writing to a single CSV file.
Final steps: - Combine all annotations into a single structure. - Sort rows for better organization. - Write the collected data to a single CSV file.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
script_params (dict) – Dictionary of script parameters including data types, IDs, namespaces, and flags for options like including ancestry and tags.
- Returns
Message regarding CSV attachment status, file annotation, and result object.
- Return type
tuple
- Export_to_csv.parameters_parsing(client)
Parses and validates input parameters from the client.
- Parameters
client (omero.scripts.ScriptClient) – Script client used to obtain input parameters.
- Returns
Parsed parameters dictionary with defaults for unspecified options.
- Return type
dict
- Export_to_csv.run_script()
Entry point for the script, called by the client.
Sets up and executes the main loop based on user-defined parameters, and generates output message or URL for the CSV file download.
- Returns
Sets output messages and result objects for OMERO client session.
- Return type
None
- Export_to_csv.sort_concat_rows(ns_row, header_row, rows, obj_id_l, obj_name_l, obj_ancestry_l)
Sorts and concatenates rows, including object IDs, names, and ancestry if applicable.
- Parameters
ns_row (list) – Namespace row for CSV.
header_row (list) – Column headers for CSV.
rows (list) – Data rows for CSV.
obj_id_l (list) – List of object IDs.
obj_name_l (list) – List of object names.
obj_ancestry_l (list) – List of ancestry details for each object.
- Returns
Tuple containing updated Namespace row, header row, and sorted data rows.
- Return type
tuple
- Export_to_csv.target_iterator(conn, source_object, target_type, is_tag)
Iterate over and yield target objects of a specified type from a source OMERO object.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
source_object (omero.model.<ObjectType>) – Source OMERO object to iterate over.
target_type (str) – Target object type to retrieve.
is_tag (bool) – Flag indicating if the source object is a tag.
- Yield
Target objects of the specified type.
- Return type
omero.model.<ObjectType>
Import from CSV
Import_from_csv.py
Adds key-value pairs to a target object on OMERO from a CSV file.
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- Import_from_csv.annotate_object(conn, obj, row, header, namespaces, exclude_empty_value, tagid_d, split_on)
Annotate a target object with Key-Value pairs and tags based on a row of CSV data.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
obj (omero.model.<ObjectType>) – OMERO object to be annotated.
row (list of str) – Data row containing Values for annotations.
header (list of str) – Column headers corresponding to the row Values.
namespaces (list of str) – Namespace for each header, specifying context of annotation.
exclude_empty_value (bool) – If True, excludes empty Values in annotations.
tagid_d (dict) – Dictionary of Tag IDs to their Tag objects.
split_on (str) – Character to split multi-value fields.
- Returns
True if the object was updated with new annotations; False otherwise.
- Return type
bool
- Import_from_csv.get_children_recursive(source_object, target_type)
Recursively retrieve child objects of a specified type from a source OMERO object.
- Parameters
source_object – The OMERO source object from which child objects
are retrieved. :type source_object: omero.model.<ObjectType> :param target_type: The OMERO object type to be retrieved as children. :type target_type: str :return: A list of child objects of the specified target type. :rtype: list
- Import_from_csv.get_obj_name(omero_obj)
Helper function
- Import_from_csv.get_original_file(omero_obj)
Retrieve the latest CSV or TSV file annotation linked to an OMERO object.
- Parameters
omero_obj (omero.model.<ObjectType>) – OMERO object to retrieve file annotation from.
- Returns
The most recent CSV or TSV file annotation.
- Return type
omero.model.FileAnnotation
- Import_from_csv.get_tag_dict(conn, use_personal_tags)
Create dictionaries of Tags, Tagsets, and Tags in Tagsets for annotation.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
use_personal_tags (bool) – If True, only Tags owned by the user are used.
- Returns
Four dictionaries: tag_d, tagset_d, tagtree_d, and tagid_d for Tags and Tag relationships.
- Return type
tuple
- Returns
tag_d: dictionary of tag_ids {“tagA”: [12], “tagB”:[34,56]}
- Returns
tagset_d: dictionary of tagset_ids {“tagsetX”:[78]}
- Returns
tagtree_d: dictionary of tags in tagsets {“tagsetX”:{“tagA”:[12]}}
- Returns
tagid_d: dictionary of tag objects {12:tagA_obj, 34:tagB_obj}
- Import_from_csv.link_file_ann(conn, obj_to_link, file_ann)
Link a File Annotation to a specified OMERO object if not already linked.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
obj_to_link (omero.model.<ObjectType>) – OMERO object to which the file annotation will be linked.
file_ann (omero.model.FileAnnotation) – File Annotation object to link to the OMERO object.
- Returns
The file annotation is linked directly within the OMERO database.
- Return type
None
- Import_from_csv.main_loop(conn, script_params)
Main function to annotate objects in OMERO based on CSV input.
This function reads a CSV file, identifies objects in OMERO based on specified criteria, and annotates them with metadata from the CSV.
- Startup:
Find CSV and reads it
- For every object:
Gather name and ID
- Finalize:
Find a match between CSV rows and objects
Annotate the objects
(opt) attach the CSV to the source object
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for interacting with the OMERO server.
script_params (dict) – Dictionary of parameters passed to the script, specifying the source and target data types, IDs, annotations, CSV separator, namespaces, and other options.
- Returns
Message with annotation summary and the first annotated target object.
- Return type
tuple
- Import_from_csv.parameters_parsing(client)
Parse and validate input parameters for the OMERO CSV import script.
This function collects and prepares the input parameters provided by the client. It sets defaults for optional parameters, verifies the consistency of input values, and transforms certain parameters into appropriate formats for use in annotation.
- Parameters
client (omero.scripts.client) – OMERO client providing the interface for parameter input.
- Returns
Dictionary of parsed and validated input parameters, with defaults applied and necessary transformations made.
- Return type
dict
- Import_from_csv.preprocess_tag_rows(conn, header, rows, tag_d, tagset_d, tagtree_d, tagid_d, create_new_tags, split_on)
Convert Tag names in CSV rows to Tag IDs for efficient processing. In case of an error, the script fails here before the annotation process starts.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
header (list of str) – Headers from the CSV file.
rows (list of list of str) – Rows of CSV data with Tag information.
tag_d (dict) – Dictionary mapping Tag names to their IDs.
tagset_d (dict) – Dictionary mapping Tagset names to their IDs.
tagtree_d (dict) – Dictionary of Tags grouped by Tagset names.
tagid_d (dict) – Dictionary mapping Tag IDs to their tag objects.
create_new_tags (bool) – If True, new Tags are created if not found.
split_on (str) – Character to split multi-value Tag cells.
- Returns
Processed rows with Tag IDs, updated dictionaries for tags and tagsets.
- Return type
tuple
- Import_from_csv.read_csv(conn, original_file, delimiter, import_tags)
Read a CSV file linked to an OMERO FileAnnotation and process its contents.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for accessing the server.
original_file (omero.model.OriginalFileI) – File object containing the CSV data.
delimiter (str) – Delimiter for the CSV file; detected if None.
import_tags (bool) – If True, columns named “Tag” are included for annotation.
- Returns
Parsed rows, header, and namespaces from the CSV file.
- Return type
tuple
- Import_from_csv.run_script()
Execute the main OMERO import script for annotating OMERO objects from CSV.
This function establishes a client connection, gathers user input parameters, and initializes a connection to the OMERO server to parse a CSV file for Key-Value pairs, tags, and other metadata to annotate objects in the OMERO database.
- Returns
Sets output messages and result objects for OMERO client session.
- Return type
None
- Import_from_csv.target_iterator(conn, source_object, target_type, is_tag)
Iterate over and yield target objects of a specified type from a source OMERO object.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
source_object (omero.model.<ObjectType>) – Source OMERO object to iterate over.
target_type (str) – Target object type to retrieve.
is_tag (bool) – Flag indicating if the source object is a tag.
- Yield
Target objects of the specified type.
- Return type
omero.model.<ObjectType>
Remove KeyVal
Remove_KeyVal.py”
Remove all key-value pairs associated with a namespace from objects on OMERO.
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- Remove_KeyVal.get_children_recursive(source_object, target_type)
Recursively retrieve child objects of a specified type from a source OMERO object.
- Parameters
source_object – The OMERO source object from which child objects
are retrieved. :type source_object: omero.model.<ObjectType> :param target_type: The OMERO object type to be retrieved as children. :type target_type: str :return: A list of child objects of the specified target type. :rtype: list
- Remove_KeyVal.main_loop(conn, script_params)
Iterates through specified OMERO objects and removes Key-Value pair annotations within given Namespaces.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
script_params (dict) – Dictionary of script parameters including source data type, target data type, object IDs, and Namespace list.
- Returns
Message indicating the success of the deletions, and the result object if any annotation was removed.
- Return type
tuple
- Remove_KeyVal.parameters_parsing(client)
Parses and validates input parameters from the client, with defaults for optional inputs.
- Parameters
client (omero.scripts.ScriptClient) – Script client used to obtain input parameters.
- Returns
Dictionary of parsed parameters, ready for processing.
- Return type
dict
- Remove_KeyVal.remove_map_annotations(conn, obj, namespace_l)
Deletes map annotations within the specified Namespaces from an OMERO object.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
obj (omero.model.<ObjectType>) – OMERO object from which MapAnnotations will be removed.
namespace_l (list) – List of Namespaces to remove annotations from; ‘*’ denotes all namespaces.
- Returns
1 if annotations were successfully deleted, 0 otherwise.
- Return type
int
- Remove_KeyVal.run_script()
Main entry point, called by the client to initiate the script, collect parameters, and execute annotation deletion based on user input.
- Returns
Sets output messages and result objects for OMERO client session.
- Return type
None
- Remove_KeyVal.target_iterator(conn, source_object, target_type, is_tag)
Iterate over and yield target objects of a specified type from a source OMERO object.
- Parameters
conn (omero.gateway.BlitzGateway) – OMERO connection for server interaction.
source_object (omero.model.<ObjectType>) – Source OMERO object to iterate over.
target_type (str) – Target object type to retrieve.
is_tag (bool) – Flag indicating if the source object is a Tag.
- Yield
Target objects of the specified type.
- Return type
omero.model.<ObjectType>