# HG changeset patch # User lldelisle # Date 1703249740 0 # Node ID b0876c73076b9a15bbce77e89aeb68b86bf429c1 planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731 diff -r 000000000000 -r b0876c73076b omero_get_children_ids.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/omero_get_children_ids.py Fri Dec 22 12:55:40 2023 +0000 @@ -0,0 +1,77 @@ +import argparse +import json + +from omero.gateway import BlitzGateway + + +def get_omero_credentials(config_file): + if config_file is None: # IDR connection + omero_username = "public" + omero_password = "public" + else: # other omero instance + with open(config_file) as f: + cfg = json.load(f) + omero_username = cfg["username"] + omero_password = cfg["password"] + + if omero_username == "" or omero_password == "": + omero_username = "public" + omero_password = "public" + return (omero_username, omero_password) + + +def recursive_get_children_id(parent_object, final_object_type): + output = [] + if parent_object.OMERO_CLASS == 'WellSample': + return [parent_object.getImage().id] + for children in parent_object.listChildren(): + if children.OMERO_CLASS == final_object_type.title(): + output.append(children.id) + else: + # We need to go one step further + output += recursive_get_children_id(children, final_object_type) + return output + + +def get_children_ids(parent_object_type, + omero_id, + final_object_type, + omero_username, + omero_password, + omero_host="idr.openmicroscopy.org", + omero_secured=False): + # Connect to omero: + with BlitzGateway( + omero_username, omero_password, host=omero_host, secure=omero_secured + ) as conn: + # Retrieve omero object + parent_object = conn.getObject(parent_object_type.title(), omero_id) + return recursive_get_children_id(parent_object, final_object_type) + + +if __name__ == "__main__": + p = argparse.ArgumentParser() + p.add_argument("-oh", "--omero-host", type=str, + default="idr.openmicroscopy.org") + p.add_argument("--omero-secured", action="store_true", default=True) + p.add_argument("-cf", "--config-file", dest="config_file", + default=None) + p.add_argument("--parent-object-type", dest="parent_object_type", + type=str, default=None, required=True) + p.add_argument("--omero-id", dest="omero_id", + type=int, default=None, required=True) + p.add_argument("--final-object-type", dest="final_object_type", + type=str, default=None, required=True) + p.add_argument("--output", type=str, default=None, required=True) + args = p.parse_args() + children_ids = get_children_ids( + args.parent_object_type, + args.omero_id, + args.final_object_type, + *get_omero_credentials(args.config_file), + omero_host=args.omero_host, + omero_secured=args.omero_secured, + ) + with open(args.output, 'w') as fo: + fo.write('\n'.join([str(id) for id in children_ids])) + fo.write('\n') diff -r 000000000000 -r b0876c73076b omero_get_children_ids.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/omero_get_children_ids.xml Fri Dec 22 12:55:40 2023 +0000 @@ -0,0 +1,267 @@ + + Get children ids + + 0.1.0 + 0 + + + omero-py + + Preferences -> Manage Information" 1>&2 && + exit 1 && + #end if + #end if + python '$__tool_directory__/omero_get_children_ids.py' + #if $omero_instance_type.omero_instance =='priv': + -oh '$omero_instance_type.omero_host' + $omero_instance_type.omero_secured + -cf '$credentials' + #end if + --parent-object-type '$omero_object.parent_object_type' + --omero-id '$omero_object.omero_id' + --final-object-type '$omero_object.final_object_type' + --output '$output' + ]]> + + + + + + + + + + + + ^[a-zA-Z0-9._-]*$ + '..' not in value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file