Mercurial > repos > lldelisle > omero_get_children_ids
changeset 0:b0876c73076b draft
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
author | lldelisle |
---|---|
date | Fri, 22 Dec 2023 12:55:40 +0000 |
parents | |
children | 82f2efb46200 |
files | omero_get_children_ids.py omero_get_children_ids.xml |
diffstat | 2 files changed, 344 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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')
--- /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 @@ +<tool id="omero_get_children_ids" name="Omero" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.01" license="MIT"> + <description>Get children ids</description> + <macros> + <token name="@TOOL_VERSION@">0.1.0</token> + <token name="@VERSION_SUFFIX@">0</token> + </macros> + <requirements> + <requirement type="package" version="5.17.0">omero-py</requirement> + </requirements> + <command detect_errors="exit_code"><![CDATA[ + #if $omero_instance_type.omero_instance == "priv": + ## the user wants to use a non-public OMERO instance + ## check if credentials are set in the user-preferences, if not warn the user and exit + #set $username = $__user__.extra_preferences.get('omero_account|username', "") + #set $password = $__user__.extra_preferences.get('omero_account|password', "") + + #if $omero_instance_type.galaxy_test_param != 'true' and ($username == "" or $password ==""): + echo "OMERO connection credentials are empty. Set your credentials via: User -> 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' + ]]></command> + <configfiles> + <configfile name="credentials"><![CDATA[ +#if $omero_instance_type.omero_instance =='priv' and $omero_instance_type.galaxy_test_param == 'true': + ## as a test for a private instance we actually use a public instance, but with credentials + #set $username = 'public' + #set $password = 'public' +#else: + #set $username = $__user__.extra_preferences.get('omero_account|username', "") + #set $password = $__user__.extra_preferences.get('omero_account|password', "") +#end if +{ + "username": "$username", + "password": "$password" +} + ]]></configfile> + </configfiles> + <inputs> + <conditional name="omero_instance_type"> + <param name="omero_instance" type="select" label="Which OMERO instance to connect?" + help="By default, the tool will request children ID from IDR. If you + need to connect to your own instance, set your connection username and password from User->Preference->Manage Information" > + <option value="idr">IDR</option> + <option value="priv">other OMERO instance</option> + </param> + <when value="priv"> + <param name="omero_host" type="text" label="OMERO host URL"> + <validator type="regex" message="Enter a valid host location, for example, your.omero.server">^[a-zA-Z0-9._-]*$</validator> + <validator type="expression" message="No two dots (..) allowed">'..' not in value</validator> + </param> + <param name="omero_secured" type="boolean" label="Secured connection?" checked="true" truevalue="--omero-secured" falsevalue="" + help="Select Yes if your OMERO instance is running with SSL, otherwise select No"> + </param> + <param name="galaxy_test_param" type="hidden" value="false" /> + </when> + <when value="idr" /> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" type="select" label="Type of parent object"> + <option value="well">Well</option> + <option value="plate">Plate</option> + <option value="screen">Screen</option> + <option value="dataset">Dataset</option> + <option value="project">Project</option> + </param> + <when value="well"> + <param name="omero_id" type="integer" value="" label="Well ID on omero" /> + <param name="final_object_type" type="hidden" value="image"/> + </when> + <when value="plate"> + <param name="omero_id" type="integer" value="" label="Plate ID on omero" /> + <param name="final_object_type" type="select" label="Type of children object for which you want the id"> + <option value="image">All Omero Image Ids</option> + <option value="well">All Omero Well Ids</option> + </param> + </when> + <when value="screen"> + <param name="omero_id" type="integer" value="" label="Screen ID on omero" /> + <param name="final_object_type" type="select" label="Type of children object for which you want the id"> + <option value="image">All Omero Image Ids</option> + <option value="well">All Omero Well Ids</option> + <option value="plate">All Omero Plate Ids</option> + </param> + </when> + <when value="dataset"> + <param name="omero_id" type="integer" value="" label="Dataset ID on omero" /> + <param name="final_object_type" type="hidden" value="image"/> + </when> + <when value="project"> + <param name="omero_id" type="integer" value="" label="Project ID on omero" /> + <param name="final_object_type" type="select" label="Type of children object for which you want the id"> + <option value="image">All Omero Image Ids</option> + <option value="dataset">All Omero Dataset Ids</option> + </param> + </when> + </conditional> + </inputs> + <outputs> + <data name="output" format="tabular" label="All ${omero_object.final_object_type} from ${omero_object.parent_object_type} ID ${omero_object.omero_id}" /> + </outputs> + <tests> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="well"/> + <param name="omero_id" value="2184933"/> + <param name="final_object_type" value="image"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="14263182"/> + <has_n_lines n="4"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="plate"/> + <param name="omero_id" value="10055"/> + <param name="final_object_type" value="image"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="14263182"/> + <has_n_lines n="1300"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="plate"/> + <param name="omero_id" value="10055"/> + <param name="final_object_type" value="well"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="2184933"/> + <has_n_lines n="325"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="screen"/> + <param name="omero_id" value="3302"/> + <param name="final_object_type" value="image"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="14263182"/> + <has_n_lines n="9100"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="screen"/> + <param name="omero_id" value="3302"/> + <param name="final_object_type" value="plate"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="10055"/> + <has_n_lines n="7"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="screen"/> + <param name="omero_id" value="3302"/> + <param name="final_object_type" value="well"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="2184933"/> + <has_n_lines n="2275"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="dataset"/> + <param name="omero_id" value="18101"/> + <param name="final_object_type" value="image"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="15148237"/> + <has_n_lines n="199"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="project"/> + <param name="omero_id" value="2801"/> + <param name="final_object_type" value="image"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="15148237"/> + <has_n_lines n="494"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="1"> + <conditional name="omero_instance_type"> + <param name="omero_instance" value="idr"/> + </conditional> + <conditional name="omero_object"> + <param name="parent_object_type" value="project"/> + <param name="omero_id" value="2801"/> + <param name="final_object_type" value="dataset"/> + </conditional> + <output name="output"> + <assert_contents> + <has_line line="18101"/> + <has_n_lines n="2"/> + </assert_contents> + </output> + </test> + </tests> + <help><![CDATA[ + +.. class:: infomark + +**What it does** + +This tool will create a file with the list of all children ids of a given omero object. + + ]]></help> +</tool> \ No newline at end of file