changeset 4:7a94eb8c345d draft default tip

planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 6f47dff3775455a8c45d39a3863a2306cd942443
author ufz
date Tue, 08 Apr 2025 15:13:16 +0000
parents ecb13e93fae2
children
files omero_get_value.py omero_get_value.xml
diffstat 2 files changed, 103 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/omero_get_value.py	Thu Dec 19 14:57:46 2024 +0000
+++ b/omero_get_value.py	Tue Apr 08 15:13:16 2025 +0000
@@ -1,15 +1,17 @@
 import argparse
 import csv
 import json
+import os
 import sys
 
 import ezomero as ez
+import pandas as pd
 
 
-def get_object_ezo(user, pws, host, port, obj_type, ids, tsv_file):
+def get_object_ezo(user, pws, host, port, obj_type, ids, out_dir):
     # Function to write tabular file from the ezomero output
     def write_values_to_tsv(data, header):
-        with open(tsv_file, 'w', newline='') as f:
+        with open("output.tsv", 'w', newline='') as f:
             writer = csv.writer(f, delimiter='\t')
             writer.writerow([header])  # Write the header
             for item in data:
@@ -17,15 +19,15 @@
 
     # Function to write tabular file from a dictionary ezomero output
     def write_dict_to_tsv(data, headers):
-        with open(tsv_file, 'w', newline='') as f:
+        with open("output.tsv", 'w', newline='') as f:
             writer = csv.writer(f, delimiter='\t')
             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:
+    def write_table_to_tsv(data, id):
+        with open(f"./output/ID_{id}_table.tsv", 'w') as f:
             for row in data:
                 f.write('\t'.join([str(val) for val in row]) + '\n')
 
@@ -35,8 +37,8 @@
             for maid in ids:
                 current_ma_dict = ez.get_map_annotation(conn, maid)
                 ma_dict = {**ma_dict, **current_ma_dict}
+                print(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:
@@ -44,14 +46,18 @@
             # Sort the tags for consistency:
             tags.sort
             write_values_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
-
+            for id in ids:
+                table = ez.get_table(conn, id)
+                print(table)
+                write_table_to_tsv(table, id)
+        elif obj_type == ("Attachment"):
+            for id in ids:
+                attch_path = ez.get_file_annotation(conn, id, folder_path='./output/')
+                base_name = os.path.basename(attch_path)
+                df = pd.read_csv(attch_path, sep='\t')
+                df.to_csv(f"./output/ID_{id}_{base_name}", sep='\t', index=False)
+                os.remove(attch_path)
         else:
             sys.exit(f"Unsupported object type: {filter}")
 
@@ -72,8 +78,8 @@
                        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.")
+    parser.add_argument('--out_dir', required=True,
+                        help="Output path.")
     args = parser.parse_args()
 
     if args.ids_path:
@@ -95,4 +101,4 @@
                    port=args.port,
                    obj_type=args.obj_type,
                    ids=args.ids,
-                   tsv_file=args.tsv_file)
+                   out_dir=args.out_dir)
--- a/omero_get_value.xml	Thu Dec 19 14:57:46 2024 +0000
+++ b/omero_get_value.xml	Tue Apr 08 15:13:16 2025 +0000
@@ -2,13 +2,14 @@
     <description> with ezomero </description>
     <macros>
         <import>macros.xml</import>
-        <token name="@VERSION_SUFFIX@">1</token>
+        <token name="@VERSION_SUFFIX@">2</token>
     </macros>
     <xrefs>
         <xref type="bio.tools">omero</xref>
     </xrefs>
     <expand macro="ezomero_requirements"/>
     <command detect_errors="exit_code"><![CDATA[
+        mkdir output;
         python '$__tool_directory__/omero_get_value.py'
         --credential-file '$credentials'
         @HOST_PORT@
@@ -18,7 +19,7 @@
         #else
             --ids_path '$ids_input.ids_path'
         #end if
-        --tsv_file '$tsv'
+        --out_dir ./output/
     ]]></command>
     <configfiles>
         <expand macro="credentials"/>
@@ -29,6 +30,7 @@
             <option value="Annotation">Annotation</option>
             <option value="Tag">Tag</option>
             <option value="Table">Table</option>
+            <option value="Attachment">Attachment</option>
         </param>
         <conditional name="ids_input">
             <param name="ids_format" type="select" label="How do you provide the ID(s) of the OMERO object?">
@@ -46,10 +48,16 @@
         </conditional>
     </inputs>
     <outputs>
-        <data name="tsv" format="tabular"/>
+        <collection name="split_output" type="list">
+            <discover_datasets pattern="__name_and_ext__" directory="output"/>
+            <filter> not (obj_type=="Tag" or obj_type=="Annotation")</filter>
+        </collection>
+        <data name="tsv" from_work_dir="output.tsv" format="tabular">
+            <filter> obj_type=="Tag" or obj_type=="Annotation"</filter>
+        </data>
     </outputs>
     <tests>
-        <test>
+        <test expect_num_outputs="1">
             <param name="omero_host" value="host.docker.internal"/>
             <param name="omero_port" value="6064"/>
             <param name="obj_type" value="Tag"/>
@@ -66,12 +74,79 @@
                 </assert_contents>
             </output>
         </test>
+        <test expect_num_outputs="1">
+            <param name="omero_host" value="host.docker.internal"/>
+            <param name="omero_port" value="6064"/>
+            <param name="obj_type" value="Annotation"/>
+            <conditional name="ids_input">
+                <param name="ids_format" value="values"/>
+                <param name="ids" value="7"/>
+            </conditional>
+            <param name="test_username" value="root"/>
+            <param name="test_password" value="omero"/>
+            <output name="tsv" ftype="tabular">
+                <assert_contents>
+                    <has_n_lines n="4"/>
+                </assert_contents>
+            </output>
+        </test>
+        <test expect_num_outputs="1">
+            <param name="omero_host" value="host.docker.internal"/>
+            <param name="omero_port" value="6064"/>
+            <param name="obj_type" value="Attachment"/>
+            <conditional name="ids_input">
+                <param name="ids_format" value="values"/>
+                <param name="ids" value="2,3,4"/>
+            </conditional>
+            <param name="test_username" value="root"/>
+            <param name="test_password" value="omero"/>
+            <output_collection name="split_output" type="list" count="3">
+                <element name="ID_2_attachment">
+                    <assert_contents>
+                        <has_text text="col1"/>
+                    </assert_contents>
+                </element>
+                <element name="ID_3_attachment">
+                    <assert_contents>
+                         <has_text text="col1"/>
+                    </assert_contents>
+                 </element>
+                <element name="ID_4_attachment">
+                    <assert_contents>
+                         <has_text text="col1"/>
+                    </assert_contents>
+                 </element>
+            </output_collection>
+        </test>
+        <test expect_num_outputs="1">
+            <param name="omero_host" value="host.docker.internal"/>
+            <param name="omero_port" value="6064"/>
+            <param name="obj_type" value="Table"/>
+            <conditional name="ids_input">
+                <param name="ids_format" value="values"/>
+                <param name="ids" value="5,6"/>
+            </conditional>
+            <param name="test_username" value="root"/>
+            <param name="test_password" value="omero"/>
+            <output_collection name="split_output" type="list" count="2">
+                <element name="ID_5_table">
+                    <assert_contents>
+                        <has_n_lines n="5"/>
+                    </assert_contents>
+                </element>
+                <element name="ID_6_table">
+                    <assert_contents>
+                         <has_n_lines n="5"/>
+                    </assert_contents>
+                 </element>
+            </output_collection>
+        </test>
     </tests>
     <help>
 Description
 -----------
 
-Tool to fetch Annotation, Tag and Tables from IDs.
+Tool to fetch Annotation, Tag, Tables and Attachments from IDs.
 
 The IDs can be obtained with the tool OMERO get IDs with ezomero
 
@@ -80,4 +155,4 @@
     <citations>
         <citation type="doi">10.1038/nmeth.1896</citation>
     </citations>
-</tool>
\ No newline at end of file
+</tool>