From 1ee41a83a807bc22805591b7419222f0a7b9f47b Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 11:00:06 +0200 Subject: [PATCH 01/11] use conditionals to more explicitely indicate the id required. --- tools/omero/omero_get.py | 5 ++++- tools/omero/omero_get.xml | 46 +++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/tools/omero/omero_get.py b/tools/omero/omero_get.py index c8cc484d..085f886f 100644 --- a/tools/omero/omero_get.py +++ b/tools/omero/omero_get.py @@ -74,11 +74,14 @@ def write_dict_to_tsv(data, headers): parser.add_argument('--obj_type', required=True, help="Type of object to fetch: dataset, image, annotation, project, roi, or table.") parser.add_argument('--id', required=False, - help="ID of the specific OMERO object.") + help="ID of the OMERO object attached to this object (project id for dataset, dataset id for image, image id for annotation, roi, or table). This is ignored for project.") parser.add_argument('--tsv_file', default='id_list.tsv', required=True, help="Output TSV file path.") args = parser.parse_args() + if args.id is None and args.obj_type != "project": + raise ValueError(f"ID is required for {args.obj_type}") + with open(args.credential_file, 'r') as f: crds = json.load(f) diff --git a/tools/omero/omero_get.xml b/tools/omero/omero_get.xml index b21a0cca..8d86f192 100644 --- a/tools/omero/omero_get.xml +++ b/tools/omero/omero_get.xml @@ -1,4 +1,4 @@ - with ezomero @@ -18,8 +18,8 @@ --credential-file '$credentials' --host $omero_host --port $omero_port - --obj_type $obj_type - --id $did + --obj_type $cond_obj_type.obj_type + --id $cond_obj_type.did --tsv_file $tsv ]]> @@ -36,16 +36,35 @@ '..' not in value - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -57,7 +76,6 @@ - From 85c9889ee0d2a751bf37e6a4ba8072f121682517 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 11:10:06 +0200 Subject: [PATCH 02/11] fix annotation part --- tools/omero/omero_get.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/omero/omero_get.py b/tools/omero/omero_get.py index 085f886f..5e0dd85d 100644 --- a/tools/omero/omero_get.py +++ b/tools/omero/omero_get.py @@ -39,7 +39,11 @@ def write_dict_to_tsv(data, headers): write_ids_to_tsv(ds_ims, "Image IDs") return ds_ims elif obj_type == "annotation": - ma_dict = ez.get_map_annotation(conn, int(id)) + map_annot_ids = ez.get_map_annotation_ids(conn, "Image", int(id)) + ma_dict = {} + for maid in map_annot_ids: + current_ma_dict = ez.get_map_annotation(conn, maid) + ma_dict = {**ma_dict, **current_ma_dict} write_dict_to_tsv(ma_dict, ["Annotation ID", "Annotation Value"]) return ma_dict elif obj_type == "project": From a18ab9d2630768efec43cee744c5b6d8d85076be Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 12:04:51 +0200 Subject: [PATCH 03/11] convert omero_get to omero_get_id --- tools/omero/omero_get.py | 97 ------------------- tools/omero/omero_get.xml | 136 --------------------------- tools/omero/omero_get_id.py | 125 +++++++++++++++++++++++++ tools/omero/omero_get_id.xml | 174 +++++++++++++++++++++++++++++++++++ 4 files changed, 299 insertions(+), 233 deletions(-) delete mode 100644 tools/omero/omero_get.py delete mode 100644 tools/omero/omero_get.xml create mode 100644 tools/omero/omero_get_id.py create mode 100644 tools/omero/omero_get_id.xml diff --git a/tools/omero/omero_get.py b/tools/omero/omero_get.py deleted file mode 100644 index 5e0dd85d..00000000 --- a/tools/omero/omero_get.py +++ /dev/null @@ -1,97 +0,0 @@ -import argparse -import csv -import json - -import ezomero as ez - - -def get_object_ezo(user, pws, host, port, obj_type, id=None, tsv_file="id_list.tsv"): - # Function to write tabular file from the ezomero output - def write_ids_to_tsv(data, header): - with open(tsv_file, 'a+', newline='') as f: - f.seek(0) - is_empty = f.tell() == 0 # Check if file is empty - writer = csv.writer(f, delimiter='\t') - if is_empty: - writer.writerow([header]) # Write the header - for item in data: - writer.writerow([item]) # Write each ID - - # Function to write tabular file from a dictionary ezomero output - def write_dict_to_tsv(data, headers): - with open(tsv_file, 'a+', newline='') as f: - f.seek(0) - is_empty = f.tell() == 0 # Check if file is empty - writer = csv.writer(f, delimiter='\t') - if is_empty: - writer.writerow(headers) # Write the headers - for key, value in data.items(): - writer.writerow([key, value]) # Write each key-value pair - - try: - with ez.connect(user, pws, "", host, port, secure=True) as conn: - if obj_type == "dataset": - ds_ids = ez.get_dataset_ids(conn, project=int(id)) - write_ids_to_tsv(ds_ids, "Dataset IDs") - return ds_ids - elif obj_type == "image": - ds_ims = ez.get_image_ids(conn, dataset=int(id)) - write_ids_to_tsv(ds_ims, "Image IDs") - return ds_ims - elif obj_type == "annotation": - map_annot_ids = ez.get_map_annotation_ids(conn, "Image", int(id)) - ma_dict = {} - for maid in map_annot_ids: - current_ma_dict = ez.get_map_annotation(conn, maid) - ma_dict = {**ma_dict, **current_ma_dict} - write_dict_to_tsv(ma_dict, ["Annotation ID", "Annotation Value"]) - return ma_dict - elif obj_type == "project": - proj_ids = ez.get_project_ids(conn) - write_ids_to_tsv(proj_ids, "Project IDs") - return proj_ids - elif obj_type == "roi": - roi_ids = ez.get_roi_ids(conn, int(id)) - write_ids_to_tsv(roi_ids, "ROI IDs") - return roi_ids - elif obj_type == "table": - table = ez.get_table(conn, int(id)) - write_dict_to_tsv(table, ["Table ID", "Table Value"]) - return table - else: - raise ValueError(f"Unsupported object type: {obj_type}") - - except Exception as e: - print(f"Connection error: {str(e)}") - return None - - -# Argument parsing -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Fetch and save data as TSV based on object type.") - parser.add_argument("--credential-file", dest="credential_file", type=str, - required=True, help="Credential file (JSON file with username and password for OMERO)") - parser.add_argument('--host', required=True, - help="Host server address.") - parser.add_argument('--port', required=True, type=int, - help='OMERO port') - parser.add_argument('--obj_type', required=True, - help="Type of object to fetch: dataset, image, annotation, project, roi, or table.") - parser.add_argument('--id', required=False, - help="ID of the OMERO object attached to this object (project id for dataset, dataset id for image, image id for annotation, roi, or table). This is ignored for project.") - parser.add_argument('--tsv_file', default='id_list.tsv', required=True, - help="Output TSV file path.") - args = parser.parse_args() - - if args.id is None and args.obj_type != "project": - raise ValueError(f"ID is required for {args.obj_type}") - - with open(args.credential_file, 'r') as f: - crds = json.load(f) - - # Call the main function to get the object and save it as a TSV - get_object_ezo(user=crds['username'], pws=crds['password'], host=args.host, - port=args.port, - obj_type=args.obj_type, - id=args.id, - tsv_file=args.tsv_file) diff --git a/tools/omero/omero_get.xml b/tools/omero/omero_get.xml deleted file mode 100644 index 8d86f192..00000000 --- a/tools/omero/omero_get.xml +++ /dev/null @@ -1,136 +0,0 @@ - - with ezomero - - 5.18.0 - 0 - - - omero - - - ezomero - - openjdk - - - - - - - - ^[a-zA-Z0-9._-]*$ - '..' not in value - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Description ------------ - -Tool to fetch project, dataset, images and ROIs IDs user defined OMERO.server. -Additionally, this tool fetch attachments and tables linked to an Image - -Options: -Project -> Project IDs present in the OMERO.server -Dataset -> Dataset IDs present in a specific Project -Image -> Image IDs present in a specific Dataset -Annotation -> Annotation File (Key-Value Pairs) linked to an Image -ROI -> ROI IDs linked to an Image -Table -> Table linked to an Image - - - - 10.1038/nmeth.1896 - - \ No newline at end of file diff --git a/tools/omero/omero_get_id.py b/tools/omero/omero_get_id.py new file mode 100644 index 00000000..af30883f --- /dev/null +++ b/tools/omero/omero_get_id.py @@ -0,0 +1,125 @@ +import argparse +import csv +import json + +import ezomero as ez + + +def get_ids_ezo(user, pws, host, port, final_obj_type, parent_obj_type, parent_id=None, tsv_file="id_list.tsv"): + # Function to write tabular file from the ezomero output + def write_ids_to_tsv(data, header): + with open(tsv_file, 'a+', newline='') as f: + f.seek(0) + is_empty = f.tell() == 0 # Check if file is empty + writer = csv.writer(f, delimiter='\t') + if is_empty: + writer.writerow([header]) # Write the header + for item in data: + writer.writerow([item]) # Write each ID + + # Function to write tabular file from a dictionary ezomero output + def write_dict_to_tsv(data, headers): + with open(tsv_file, 'a+', newline='') as f: + f.seek(0) + is_empty = f.tell() == 0 # Check if file is empty + writer = csv.writer(f, delimiter='\t') + if is_empty: + writer.writerow(headers) # Write the headers + for key, value in data.items(): + writer.writerow([key, value]) # Write each key-value pair + + try: + with ez.connect(user, pws, "", host, port, secure=True) as conn: + if final_obj_type == "Project": + proj_ids = ez.get_project_ids(conn) + write_ids_to_tsv(proj_ids, "Project IDs") + return proj_ids + elif final_obj_type == "Dataset": + args = {'project': None} + if parent_obj_type == "Project": + args['project'] = parent_id + ds_ids = ez.get_dataset_ids(conn, **args) + write_ids_to_tsv(ds_ids, "Dataset IDs") + return ds_ids + elif final_obj_type == "Image": + args = { + 'project': None, + 'dataset': None, + 'plate': None, + 'well': None + } + if parent_obj_type == "Project": + args['project'] = parent_id + elif parent_obj_type == "Dataset": + args['dataset'] = parent_id + elif parent_obj_type == "Plate": + args['plate'] = parent_id + elif parent_obj_type == "Well": + args['well'] = parent_id + elif parent_obj_type != "All": + raise ValueError(f"Object set as parent_obj_type is not compatible") + ds_ims = ez.get_image_ids(conn, **args) + write_ids_to_tsv(ds_ims, "Image IDs") + return ds_ims + elif final_obj_type == "Annotation": + map_annot_ids = ez.get_map_annotation_ids(conn, parent_obj_type, parent_id) + write_ids_to_tsv(map_annot_ids, "Annotation IDs") + return map_annot_ids + elif final_obj_type == "Tag": + tag_ids = ez.get_tag_ids(conn, parent_obj_type, parent_id) + write_ids_to_tsv(tag_ids, "Tag IDs") + return tag_ids + elif final_obj_type == "Roi": + roi_ids = ez.get_roi_ids(conn, parent_id) + write_ids_to_tsv(roi_ids, "ROI IDs") + return roi_ids + elif final_obj_type == "Table": + file_ann_ids = ez.get_file_annotation_ids(conn, parent_obj_type, parent_id) + write_ids_to_tsv(file_ann_ids, "Table IDs") + return file_ann_ids + else: + raise ValueError(f"Unsupported object type: {final_obj_type}") + + except Exception as e: + print(f"Connection error: {str(e)}") + return None + + +# Argument parsing +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Fetch OMERO object IDs as TSV from parent object.") + parser.add_argument("--credential-file", dest="credential_file", type=str, + required=True, help="Credential file (JSON file with username and password for OMERO)") + parser.add_argument('--host', required=True, + help="Host server address.") + parser.add_argument('--port', required=True, type=int, + help='OMERO port') + parser.add_argument('--final_obj_type', required=True, + help="Type of object to fetch ID: Project, Dataset, Image, Annotation, Tag, Roi, or Table.") + parser.add_argument('--parent_obj_type', required=True, + help="Type of object from which you fetch IDs: Project, Dataset, Plate, Well, Image (or 'All' if you want to get all objects).") + parser.add_argument('--parent_id', required=False, type=int, + help="ID of the OMERO object in `--parent_obj_type`, not required if you used `--parent_obj_type All`.") + parser.add_argument('--tsv_file', default='id_list.tsv', required=True, + help="Output TSV file path.") + args = parser.parse_args() + + if args.parent_id is None and args.parent_obj_type != "All": + raise ValueError(f"ID is only optional is you use `--parent_obj_type All`") + + if args.final_obj_type == "Roi" and args.parent_obj_type != "Image": + raise ValueError("Roi IDs can only be retrived from images, use `--parent_obj_type Image`") + + if args.parent_obj_type == "All" and not args.final_obj_type in ["Image", "Dataset", "Project"]: + raise ValueError("Only Images, Datasets and Projects is compatible with `--parent_obj_type All`") + + with open(args.credential_file, 'r') as f: + crds = json.load(f) + + # Call the main function to get the object and save it as a TSV + get_ids_ezo(user=crds['username'], pws=crds['password'], host=args.host, + port=args.port, + final_obj_type=args.final_obj_type, + parent_obj_type=args.parent_obj_type, + parent_id=args.parent_id, + tsv_file=args.tsv_file) diff --git a/tools/omero/omero_get_id.xml b/tools/omero/omero_get_id.xml new file mode 100644 index 00000000..85cd783b --- /dev/null +++ b/tools/omero/omero_get_id.xml @@ -0,0 +1,174 @@ + + with ezomero + + 5.18.0 + 0 + + + omero + + + ezomero + + openjdk + + + + + + + + ^[a-zA-Z0-9._-]*$ + '..' not in value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Description +----------- + +Tool to fetch project, dataset, images, annotations, tags, table and ROIs IDs user defined OMERO.server. + +Options: +Project -> Project IDs present in the OMERO.server +Dataset -> Dataset IDs present in a specific Project or in the server +Image -> Image IDs present in a specific Dataset or Project or Well or Plate or in the server +Annotation (Key-Value Pairs) -> Annotation IDs linked to an Image or Dataset or Project or Well or Plate +Tag -> Tag IDs linked to an Image or Dataset or Project or Well or Plate +ROI -> ROI IDs linked to an Image +Table -> Table linked to an Image or Dataset or Project or Well or Plate + + + + 10.1038/nmeth.1896 + + \ No newline at end of file From 60455869c7d171d8ed05e83a7b4957655652cfc1 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 12:41:26 +0200 Subject: [PATCH 04/11] add get_value --- tools/omero/omero_get_value.py | 107 ++++++++++++++++++++++++++++++++ tools/omero/omero_get_value.xml | 83 +++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 tools/omero/omero_get_value.py create mode 100644 tools/omero/omero_get_value.xml diff --git a/tools/omero/omero_get_value.py b/tools/omero/omero_get_value.py new file mode 100644 index 00000000..7a0caa9d --- /dev/null +++ b/tools/omero/omero_get_value.py @@ -0,0 +1,107 @@ +import argparse +import csv +import json + +import ezomero as ez + + +def get_object_ezo(user, pws, host, port, obj_type, ids, tsv_file): + # Function to write tabular file from the ezomero output + def write_values_to_tsv(data, header): + with open(tsv_file, 'a+', newline='') as f: + f.seek(0) + is_empty = f.tell() == 0 # Check if file is empty + writer = csv.writer(f, delimiter='\t') + if is_empty: + writer.writerow([header]) # Write the header + for item in data: + writer.writerow([item]) # Write each value + + # Function to write tabular file from a dictionary ezomero output + def write_dict_to_tsv(data, headers): + with open(tsv_file, 'a+', newline='') as f: + f.seek(0) + is_empty = f.tell() == 0 # Check if file is empty + writer = csv.writer(f, delimiter='\t') + if is_empty: + writer.writerow(headers) # Write the headers + for key, value in data.items(): + writer.writerow([key, value]) # Write each key-value pair + + # Function to write tabular file from list of list ezomero output + def write_table_to_tsv(data): + with open(tsv_file, 'w') as f: + for row in data: + f.write('\t'.join([str(val) for val in row]) + '\n') + + try: + with ez.connect(user, pws, "", host, port, secure=True) as conn: + if obj_type == "Annotation": + ma_dict = {} + for maid in ids: + current_ma_dict = ez.get_map_annotation(conn, maid) + ma_dict = {**ma_dict, **current_ma_dict} + write_dict_to_tsv(ma_dict, ["Annotation ID", "Annotation Value"]) + return ma_dict + elif obj_type == "Tag": + tags = [] + for tag_id in ids: + tags.append(ez.get_tag(conn, tag_id)) + # Sort the tags for consistency: + tags.sort + write_ids_to_tsv(tags, "Tags") + return tags + elif obj_type == "Table": + if len(ids) > 1: + raise ValueError("Only one table can be exported at a time") + table = ez.get_table(conn, ids[0]) + write_table_to_tsv(table) + return table + else: + raise ValueError(f"Unsupported object type: {obj_type}") + + except Exception as e: + print(f"Connection error: {str(e)}") + return None + + +# Argument parsing +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Fetch and save data as TSV based on object type.") + parser.add_argument("--credential-file", dest="credential_file", type=str, + required=True, help="Credential file (JSON file with username and password for OMERO)") + parser.add_argument('--host', required=True, + help="Host server address.") + parser.add_argument('--port', required=True, type=int, + help='OMERO port') + parser.add_argument('--obj_type', required=True, + help="Type of object to fetch: Annotation, Table or Tag.") + group = parser.add_mutually_exclusive_group() + group.add_argument('--ids', nargs = '+', type = int, + help="IDs of the OMERO objects.") + group.add_argument('--ids_path', + help="File with IDs of the OMERO objects (one per line).") + parser.add_argument('--tsv_file', default='id_list.tsv', required=True, + help="Output TSV file path.") + args = parser.parse_args() + + if args.ids_path: + args.ids = [] + with open(args.ids_path, 'r') as f: + for line in f: + try: + args.ids.append(int(line)) + except ValueError: + print(f"{line.strip()} is not a valid ID.") + if len(args.ids) == 0: + raise ValueError("Cound not find a single ID in the file.") + + with open(args.credential_file, 'r') as f: + crds = json.load(f) + + # Call the main function to get the object and save it as a TSV + get_object_ezo(user=crds['username'], pws=crds['password'], host=args.host, + port=args.port, + obj_type=args.obj_type, + ids=args.ids, + tsv_file=args.tsv_file) diff --git a/tools/omero/omero_get_value.xml b/tools/omero/omero_get_value.xml new file mode 100644 index 00000000..fd0a5a84 --- /dev/null +++ b/tools/omero/omero_get_value.xml @@ -0,0 +1,83 @@ + + with ezomero + + 5.18.0 + 0 + + + omero + + + ezomero + + openjdk + + + + + + + + ^[a-zA-Z0-9._-]*$ + '..' not in value + + + + + + + + + + + + + + + [0-9]+(,[0-9]+)* + + + + + + + + + + + + + + + + +Description +----------- + +Tool to fetch Annotation, Tag and Tables from IDs. + +The IDs can be obtained with the tool OMERO get IDs with ezomero + + + + 10.1038/nmeth.1896 + + \ No newline at end of file From 4351fdf6bf632e15b941e0295241b3e4eef8dc2b Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 12:46:52 +0200 Subject: [PATCH 05/11] add single quotes --- tools/omero/omero_get_id.xml | 10 +++++----- tools/omero/omero_get_value.xml | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/omero/omero_get_id.xml b/tools/omero/omero_get_id.xml index 85cd783b..03925165 100644 --- a/tools/omero/omero_get_id.xml +++ b/tools/omero/omero_get_id.xml @@ -14,14 +14,14 @@ openjdk openjdk Date: Fri, 11 Oct 2024 12:47:30 +0200 Subject: [PATCH 06/11] Fix bad copy paste --- tools/omero/omero_get_id.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/omero/omero_get_id.xml b/tools/omero/omero_get_id.xml index 03925165..9e31603a 100644 --- a/tools/omero/omero_get_id.xml +++ b/tools/omero/omero_get_id.xml @@ -43,7 +43,7 @@ - + From f9e9b42b54947e6cd6c8fd9406c8ca31e4ef7029 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 12:54:53 +0200 Subject: [PATCH 07/11] add tests --- tools/omero/omero_get_id.xml | 35 ++++++++++++++++++++++++++++----- tools/omero/omero_get_value.xml | 18 ++++++++++++++++- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/tools/omero/omero_get_id.xml b/tools/omero/omero_get_id.xml index 9e31603a..823f07fe 100644 --- a/tools/omero/omero_get_id.xml +++ b/tools/omero/omero_get_id.xml @@ -113,7 +113,9 @@ - + + + @@ -126,8 +128,11 @@ - - + + + + + @@ -140,8 +145,11 @@ - - + + + + + @@ -151,6 +159,23 @@ + + + + + + + + + + + + + + + + + Description diff --git a/tools/omero/omero_get_value.xml b/tools/omero/omero_get_value.xml index d1bacdd3..991ff95c 100644 --- a/tools/omero/omero_get_value.xml +++ b/tools/omero/omero_get_value.xml @@ -66,7 +66,23 @@ - + + + + + + + + + + + + + + + + + Description From a62a9254685a7320f25cbf66ca7b9770cd84d19f Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 13:09:03 +0200 Subject: [PATCH 08/11] remove unused f --- tools/omero/omero_get_id.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/omero/omero_get_id.py b/tools/omero/omero_get_id.py index af30883f..de03946a 100644 --- a/tools/omero/omero_get_id.py +++ b/tools/omero/omero_get_id.py @@ -57,7 +57,7 @@ def write_dict_to_tsv(data, headers): elif parent_obj_type == "Well": args['well'] = parent_id elif parent_obj_type != "All": - raise ValueError(f"Object set as parent_obj_type is not compatible") + raise ValueError("Object set as parent_obj_type is not compatible") ds_ims = ez.get_image_ids(conn, **args) write_ids_to_tsv(ds_ims, "Image IDs") return ds_ims @@ -105,7 +105,7 @@ def write_dict_to_tsv(data, headers): args = parser.parse_args() if args.parent_id is None and args.parent_obj_type != "All": - raise ValueError(f"ID is only optional is you use `--parent_obj_type All`") + raise ValueError("ID is only optional is you use `--parent_obj_type All`") if args.final_obj_type == "Roi" and args.parent_obj_type != "Image": raise ValueError("Roi IDs can only be retrived from images, use `--parent_obj_type Image`") From 9293ed3726513c25cb9450605c286efe4b524560 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 13:10:03 +0200 Subject: [PATCH 09/11] remove unused function --- tools/omero/omero_get_id.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tools/omero/omero_get_id.py b/tools/omero/omero_get_id.py index de03946a..fc9cde96 100644 --- a/tools/omero/omero_get_id.py +++ b/tools/omero/omero_get_id.py @@ -16,18 +16,6 @@ def write_ids_to_tsv(data, header): writer.writerow([header]) # Write the header for item in data: writer.writerow([item]) # Write each ID - - # Function to write tabular file from a dictionary ezomero output - def write_dict_to_tsv(data, headers): - with open(tsv_file, 'a+', newline='') as f: - f.seek(0) - is_empty = f.tell() == 0 # Check if file is empty - writer = csv.writer(f, delimiter='\t') - if is_empty: - writer.writerow(headers) # Write the headers - for key, value in data.items(): - writer.writerow([key, value]) # Write each key-value pair - try: with ez.connect(user, pws, "", host, port, secure=True) as conn: if final_obj_type == "Project": @@ -110,7 +98,7 @@ def write_dict_to_tsv(data, headers): if args.final_obj_type == "Roi" and args.parent_obj_type != "Image": raise ValueError("Roi IDs can only be retrived from images, use `--parent_obj_type Image`") - if args.parent_obj_type == "All" and not args.final_obj_type in ["Image", "Dataset", "Project"]: + if args.parent_obj_type == "All" and args.final_obj_type not in ["Image", "Dataset", "Project"]: raise ValueError("Only Images, Datasets and Projects is compatible with `--parent_obj_type All`") with open(args.credential_file, 'r') as f: From 338521661c1bb5fb7999fec5674f4106d875ef88 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 13:11:24 +0200 Subject: [PATCH 10/11] fix function name --- tools/omero/omero_get_value.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/omero/omero_get_value.py b/tools/omero/omero_get_value.py index 7a0caa9d..0191536a 100644 --- a/tools/omero/omero_get_value.py +++ b/tools/omero/omero_get_value.py @@ -49,7 +49,7 @@ def write_table_to_tsv(data): tags.append(ez.get_tag(conn, tag_id)) # Sort the tags for consistency: tags.sort - write_ids_to_tsv(tags, "Tags") + write_values_to_tsv(tags, "Tags") return tags elif obj_type == "Table": if len(ids) > 1: From ecf308546a02c2505ed22463da1806bc4b6edf87 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Fri, 11 Oct 2024 13:11:37 +0200 Subject: [PATCH 11/11] fix spaces --- tools/omero/omero_get_value.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/omero/omero_get_value.py b/tools/omero/omero_get_value.py index 0191536a..597c830a 100644 --- a/tools/omero/omero_get_value.py +++ b/tools/omero/omero_get_value.py @@ -77,7 +77,7 @@ def write_table_to_tsv(data): parser.add_argument('--obj_type', required=True, help="Type of object to fetch: Annotation, Table or Tag.") group = parser.add_mutually_exclusive_group() - group.add_argument('--ids', nargs = '+', type = int, + group.add_argument('--ids', nargs='+', type=int, help="IDs of the OMERO objects.") group.add_argument('--ids_path', help="File with IDs of the OMERO objects (one per line).")