diff modify_loom.xml @ 9:0f1aaff9b22d draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit 67b3808b56df343798263ff0c905df8cb789edfa
author iuc
date Sat, 14 Sep 2024 19:59:12 +0000
parents 4b0adaa31c95
children
line wrap: on
line diff
--- a/modify_loom.xml	Sun Nov 12 16:44:29 2023 +0000
+++ b/modify_loom.xml	Sat Sep 14 19:59:12 2024 +0000
@@ -1,62 +1,191 @@
-<tool id="modify_loom" name="Manipulate loom object" version="@TOOL_VERSION@+galaxy1">
-    <description>Add layers, or row/column attributes to a loom file</description>
+<tool id="modify_loom" name="Loom operations" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
+    <description>Manipulate, export and import loom data</description>
     <macros>
         <import>macros.xml</import>
     </macros>
-    <expand macro="requirements"/>
+    <expand macro="requirements">
+        <requirement type="package" version="1.26.4">numpy</requirement><!-- loompy seems to adapt to numpy 2.x. Remove this in the next update -->
+    </expand>
     <expand macro="version_command"/>
     <command detect_errors="exit_code"><![CDATA[
-cp '${input}' loom_add_out.loom &&
-python '$__tool_directory__/modify_loom.py' -f 'loom_add_out.loom'
-#if $which_add.add_type == "cols":
-    -a cols -c '${which_add.cols}'
-#else if $which_add.add_type == "cols":
-    -a rows -r '${which_add.rows}'
-#else if $which_add.add_type == "layers":
-    -a layers -l '${which_add.layers}'
+#if $operation.to_perform == 'manipulate'
+cp '${operation.loom}' converted.loom &&
+python '$__tool_directory__/modify_loom.py' -f 'converted.loom'
+    #if $operation.which_add.add_type == "cols":
+    -a cols -c '${operation.which_add.cols}'
+    #else if $operation.which_add.add_type == "rows":
+    -a rows -r '${operation.which_add.rows}'
+    #else if $operation.which_add.add_type == "layers":
+    -a layers -l '${operation.which_add.layers}'
+    #end if
+
+#else if $operation.to_perform == 'export'
+mkdir ./output &&
+mkdir ./attributes &&
+python '$__tool_directory__/loompy_to_tsv.py' -f '$operation.loom'
+
+#else if $operation.to_perform == 'import'
+    #if $operation.from.file_type == 'ad'
+@CMD@
+    #else if $operation.from.file_type == 'tab'
+python '$__tool_directory__/tsv_to_loompy.py'
+    -c '${operation.coldata}'
+    -r '${operation.rowdata}'
+    -f '${operation.mainmatrix}'
+        #if $operation.other_files
+    '${operation.other_files}'
+        #end if
+    #end if
 #end if
       ]]></command>
+    <configfiles>
+    <configfile name="script_file"><![CDATA[
+@CMD_imports@
+#if $operation.to_perform == 'import'
+    #if $operation.from.file_type == 'ad'
+adata = ad.read_h5ad('$operation.anndata')
+adata.write_loom('converted.loom')
+    #end if
+#end if
+      ]]></configfile>
+    </configfiles>
     <inputs>
-        <param name="input" type="data" format="loom" label="Loom file"/>
-        <conditional name="which_add">
-            <param name="add_type" type="select" label="Select data attribute to add to loom">
-                <option value="cols">Columns</option>
-                <option value="rows">Rows</option>
-                <option value="layers">Layers</option>
+        <conditional name="operation">
+            <param name="to_perform" type="select" label="Operation to perform on loom data">
+                <option value="manipulate">Manipulate loom data</option>
+                <option value="export">Export loom layers and attributes</option>
+                <option value="import">Import loom from an anndata or tabular files</option>
             </param>
-            <when value="cols">
-                <param name="cols" type="data" format="tabular" label="Column file of same dimensions as existing file"/>
+            <when value="manipulate">
+                <param name="loom" type="data" format="loom" label="Loom file"/>
+                <conditional name="which_add">
+                    <param name="add_type" type="select" label="Select data attribute to add to loom">
+                        <option value="cols">Columns</option>
+                        <option value="rows">Rows</option>
+                        <option value="layers">Layers</option>
+                    </param>
+                    <when value="cols">
+                        <param name="cols" type="data" format="tabular" label="Column file of same dimensions as existing file"/>
+                    </when>
+                    <when value="rows">
+                        <param name="rows" type="data" format="tabular" label="Row file of same dimensions as existing file"/>
+                    </when>
+                    <when value="layers">
+                        <param name="layers" type="data" multiple="true" format="tabular" label="Layer file(s) of same dimensions as existing file"/>
+                    </when>
+                </conditional>
             </when>
-            <when value="rows">
-                <param name="rows" type="data" format="tabular" label="Row file of same dimensions as existing file"/>
+            <when value="export">
+                <param name="loom" type="data" format="loom" label="Loom file"/>
             </when>
-            <when value="layers">
-                <param name="layers" type="data" multiple="true" format="tabular" label="Layer file(s) of same dimensions as existing file"/>
+            <when value="import">
+                <conditional name="from">
+                    <param name="file_type" type="select" label="Create loom file from">
+                        <option value="ad">an anndata object</option>
+                        <option value="tab">from tabular files of matrix and row and column attributes</option>
+                    </param>
+                    <when value="ad">
+                        <param name="anndata" type="data" format="h5ad" label="Anndata file"/>
+                    </when>
+                    <when value="tab">
+                        <param name="mainmatrix" type="data" format="tabular" label="File for main layer of loom file." help="All subsequent tsv must be the same dimensions as this file. When converted back to tsv using hd5 export, this will be labeled as 'mainmatrix.tsv'"/>
+                        <param name="other_files" type="data" format="tabular" multiple="true" optional="true" label="Add layers" help="Adds layers of same dimension to the loom file. When converted to tsv using hd5 export, these layers will retain their names."/>
+                        <param name="coldata" type="data" format="tabular" label="Tsv of column data." help="First row is column attributes, subsequent are values."/>
+                        <param name="rowdata" type="data" format="tabular" label="Tsv of row data." help="First row is row attributes, subsequent are values."/>
+                    </when>
+                </conditional>
+
             </when>
         </conditional>
     </inputs>
     <outputs>
-        <data name="loomout" format="loom" from_work_dir='loom_add_out.loom' label="Expanded loom file from '${on_string}'"/>
+        <data name="loomout" format="loom" from_work_dir='converted.loom' label="${tool.name} (${operation.to_perform}) on ${on_string} Loom file">
+            <filter>operation['to_perform'] == 'manipulate' or operation['to_perform'] == 'import'</filter>
+        </data>
+        <collection name="layer_tsvs" type="list" label="Layer matrices" >
+            <filter>operation['to_perform'] == 'export'</filter>
+            <discover_datasets pattern="__designation__" format="tabular" directory="output" visible="false" />
+        </collection>
+        <collection name="attribute_tsvs" type="list" label="Attribute matrices" >
+            <filter>operation['to_perform'] == 'export'</filter>
+            <discover_datasets pattern="__designation__" format="tabular" directory="attributes" visible="false" />
+        </collection>
     </outputs>
     <tests>
         <test expect_num_outputs="1">
-            <param name="input" value="addtest.loom"/>
-            <param name="add_type" value="cols"/>
-            <param name="cols" value="cols.tsv"/>
+            <conditional name="operation">
+                <param name="to_perform" value="manipulate"/>
+                <param name="loom" value="addtest.loom"/>
+                <conditional name="which_add">
+                    <param name="add_type" value="cols"/>
+                    <param name="cols" value="cols.tsv"/>
+                </conditional>
+            </conditional>
             <output name="loomout" value="addloomout1.loom" ftype="loom" compare="sim_size"/>
         </test>
         <test expect_num_outputs="1">
-            <param name="input" value="addtest.loom"/>
-            <param name="add_type" value="rows"/>
-            <param name="rows" value="rows.tsv"/>
+            <conditional name="operation">
+                <param name="to_perform" value="manipulate"/>
+                <param name="loom" value="addtest.loom"/>
+                <conditional name="which_add">
+                    <param name="add_type" value="rows"/>
+                    <param name="rows" value="rows.tsv"/>
+                </conditional>
+            </conditional>
             <output name="loomout" value="addloomout2.loom" ftype="loom" compare="sim_size"/>
         </test>
         <test expect_num_outputs="1">
-            <param name="input" value="addtest.loom"/>
-            <param name="add_type" value="layers"/>
-            <param name="layers" value="addlayer1.tsv"/>
+            <conditional name="operation">
+                <param name="to_perform" value="manipulate"/>
+                <param name="loom" value="addtest.loom"/>
+                <conditional name="which_add">
+                    <param name="add_type" value="layers"/>
+                    <param name="layers" value="addlayer1.tsv"/>
+                </conditional>
+            </conditional>
             <output name="loomout" value="addloomout3.loom" ftype="loom" compare="sim_size"/>
         </test>
+        <test expect_num_outputs="2">
+            <conditional name="operation">
+                <param name="to_perform" value="export"/>
+                <param name="loom" value="loomtest.loom"/>
+            </conditional>
+            <output_collection name="layer_tsvs" type="list">
+                <element name="extralayer.tsv" value="secondlayer.tsv" ftype="tabular"/>
+                <element name="mainmatrix.tsv" value="firstlayer.tsv" ftype="tabular"/>
+                <element name="thirdlayer.tsv" value="finallayer.tsv" ftype="tabular"/>
+            </output_collection>
+            <output_collection name="attribute_tsvs" type="list">
+                <element name="col_attr.tsv" value="cols.tsv" ftype="tabular"/>
+                <element name="row_attr.tsv" value="rows.tsv" ftype="tabular"/>
+            </output_collection>
+        </test>
+        <test expect_num_outputs="1">
+            <conditional name="operation">
+                <param name="to_perform" value="import"/>
+                <conditional name="from">
+                    <param name="file_type" value="ad"/>
+                    <param name="anndata" value="krumsiek11.h5ad"/>
+                </conditional>
+            </conditional>
+            <assert_stdout>
+                <has_text_matching expression="adata.write_loom"/>
+            </assert_stdout>
+            <output name="loomout" value="export.krumsiek11.loom" ftype="loom" compare="sim_size"/>
+        </test>
+        <test expect_num_outputs="1">
+            <conditional name="operation">
+                <param name="to_perform" value="import"/>
+                <conditional name="from">
+                    <param name="file_type" value="tab"/>
+                    <param name="mainmatrix" value="firstlayer.tsv"/>
+                    <param name="other_files" value="secondlayer.tsv"/>
+                    <param name="coldata" value="cols.tsv"/>
+                    <param name="rowdata" value="rows.tsv"/>
+                </conditional>
+            </conditional>
+            <output name="loomout" value="converted.loom.test" ftype="loom" compare="sim_size"/>
+        </test>
     </tests>
     <help><![CDATA[
 This tool allows the user to modify an existing loom data file by adding column attributes, row attributes or additional layers via tsv files.