Skip to content

Commit

Permalink
add get_name option
Browse files Browse the repository at this point in the history
  • Loading branch information
lldelisle committed Jun 14, 2024
1 parent b97db80 commit 1781e31
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
20 changes: 15 additions & 5 deletions tools/omero_get_children_ids/omero_get_children_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,29 @@ def get_omero_credentials(config_file):
return (omero_username, omero_password)


def recursive_get_children_id(parent_object, final_object_type):
def recursive_get_children_id(parent_object, final_object_type, get_name):
output = []
if parent_object.OMERO_CLASS == 'WellSample':
return [parent_object.getImage().id]
if get_name:
return [f"{parent_object.getImage().id}\t{parent_object.getImage().getName()}"]
else:
return [parent_object.getImage().id]
for children in parent_object.listChildren():
if children.OMERO_CLASS == final_object_type.title():
output.append(children.id)
if get_name:
output.append(f"{children.id}\t{children.getName()}")
else:
output.append(children.id)
else:
# We need to go one step further
output += recursive_get_children_id(children, final_object_type)
output += recursive_get_children_id(children, final_object_type, get_name)
return output


def get_children_ids(parent_object_type,
omero_id,
final_object_type,
get_name,
omero_username,
omero_password,
omero_host="idr.openmicroscopy.org",
Expand All @@ -46,7 +53,7 @@ def get_children_ids(parent_object_type,
) 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)
return recursive_get_children_id(parent_object, final_object_type, get_name)


if __name__ == "__main__":
Expand All @@ -62,12 +69,15 @@ def get_children_ids(parent_object_type,
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("--get-name", dest="get_name",
action="store_true", default=False)
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,
args.get_name,
*get_omero_credentials(args.config_file),
omero_host=args.omero_host,
omero_secured=args.omero_secured,
Expand Down
23 changes: 22 additions & 1 deletion tools/omero_get_children_ids/omero_get_children_ids.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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="@TOOL_VERSION@">0.2.0</token>
<token name="@VERSION_SUFFIX@">0</token>
</macros>
<requirements>
Expand Down Expand Up @@ -29,6 +29,7 @@
--omero-id '$omero_object.omero_id'
--final-object-type '$omero_object.final_object_type'
--output '$output'
$get_name
]]></command>
<configfiles>
<configfile name="credentials"><![CDATA[
Expand Down Expand Up @@ -105,6 +106,7 @@
</param>
</when>
</conditional>
<param name="get_name" type="boolean" truevalue="--get-name" falsevalue="" checked="false" label="Retrieve names into a second column" />
</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}" />
Expand All @@ -126,6 +128,23 @@
</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="well"/>
<param name="omero_id" value="2184933"/>
<param name="final_object_type" value="image"/>
</conditional>
<param name="get_name" value="true"/>
<output name="output">
<assert_contents>
<has_text text="003012001.flex [Well A-1; Field #1]"/>
<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"/>
Expand Down Expand Up @@ -263,5 +282,7 @@
This tool will create a file with the list of all children ids of a given omero object.
If the option is set, it can also retrive the names.
]]></help>
</tool>

0 comments on commit 1781e31

Please sign in to comment.