changeset 0:ac675f28acfc draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata2ri/ commit f2b398613762cdee5f89fb43382df2bf7321ccde
author iuc
date Thu, 13 Feb 2025 10:38:32 +0000
parents
children
files anndata2ri.xml test-data/krumsiek11.h5ad test-data/krumsiek11.rds
diffstat 3 files changed, 113 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/anndata2ri.xml	Thu Feb 13 10:38:32 2025 +0000
@@ -0,0 +1,113 @@
+<tool id="anndata2ri" name="anndata2ri" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.0">
+    <description>
+        Convert between Anndata and SingCellExperiment objects
+    </description>
+    <macros>
+        <token name="@TOOL_VERSION@">1.3.2</token>
+        <token name="@VERSION_SUFFIX@">0</token>
+    </macros>
+    <xrefs>
+        <xref type="bio.tools">anndata2ri</xref>
+    </xrefs>
+    <requirements>
+        <requirement type="package" version="@TOOL_VERSION@">anndata2ri</requirement>
+        <requirement type="package" version="0.10.9">anndata</requirement>
+        <requirement type="package" version="1.24.0">bioconductor-singlecellexperiment</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+            python '$script_file' '$conversion.direction'
+    ]]></command>
+    <configfiles>
+        <configfile name="script_file"><![CDATA[
+import sys
+import anndata as ad
+import anndata2ri
+import rpy2.robjects as ro
+from rpy2.rlike.container import OrdDict
+
+ro.r('suppressPackageStartupMessages(library(SingleCellExperiment))')
+
+def convert_orddict_to_dict(uns):
+    if isinstance(uns, OrdDict):
+        return {k: convert_orddict_to_dict(v) for k, v in uns.items()}
+    elif isinstance(uns, list):
+        return [convert_orddict_to_dict(v) for v in uns]
+    elif isinstance(uns, tuple):
+        return tuple(convert_orddict_to_dict(v) for v in uns)
+    elif isinstance(uns, dict):
+        return {k: convert_orddict_to_dict(v) for k, v in uns.items()}
+    else:
+        return uns
+
+if sys.argv[1] == 'sce2anndata':
+    sce = ro.r('readRDS')('$conversion.input_object')
+    with ro.conversion.localconverter(ro.default_converter + anndata2ri.converter):
+        adata = ro.conversion.rpy2py(sce)
+    adata.uns = convert_orddict_to_dict(adata.uns)
+    adata.obs.index = adata.obs.index.astype(str)
+    adata.var.index = adata.var.index.astype(str)
+    adata.write('outfile.h5ad', compression='gzip')
+
+elif sys.argv[1] == 'anndata2sce':
+    adata = ad.read_h5ad('$conversion.input_object')
+    with ro.conversion.localconverter(ro.default_converter + anndata2ri.converter):
+        sce = ro.conversion.py2rpy(adata)
+    ro.r('saveRDS')(sce, 'outfile.rds')
+
+        ]]></configfile>
+    </configfiles>
+    <inputs>
+        <conditional name="conversion" >
+            <param name="direction" type="select" label="Convert From / To" >
+                <option value="sce2anndata" >SingleCellexperiment to AnnData</option>
+                <option value="anndata2sce" >AnnData to SingleCellexperiment</option>
+            </param>
+            <when value="sce2anndata">
+                <param name="input_object" type="data" format="rdata.sce,rds" label="SingCellExperiment object to convert" />
+            </when>
+            <when value="anndata2sce" >
+                <param name="input_object" type="data" format="h5ad,h5" label="Anndata object to convert"/>
+            </when>
+        </conditional>
+    </inputs>
+    <outputs>
+        <data name="output_anndata" format="h5ad" from_work_dir="outfile.h5ad" label="${tool.name} on ${on_string}: Anndata object">
+            <filter>conversion['direction'] == 'sce2anndata'</filter>
+        </data>
+        <data name="output_sce" format="rdata.sce" from_work_dir="outfile.rds" label="${tool.name} on ${on_string}: SingleCellExperiment object">
+            <filter>conversion['direction'] == 'anndata2sce'</filter>
+        </data>
+    </outputs>
+    <tests>
+        <test expect_num_outputs="1">
+            <param name="direction" value="sce2anndata"/>
+            <param name="input_object" value="krumsiek11.rds"/>
+            <output name="output_anndata" file="krumsiek11.h5ad" ftype="h5ad" compare="sim_size">
+                <assert_contents>
+                    <has_h5_keys keys="obs/cell_type"/>
+                    <has_h5_keys keys="uns/highlights"/>
+                    <has_h5_keys keys="uns/iroot"/>
+                </assert_contents>
+            </output>
+        </test>
+        <test expect_num_outputs="1">
+            <param name="direction" value="anndata2sce"/>
+            <param name="input_object" value="krumsiek11.h5ad"/>
+            <output name="output_sce" file="krumsiek11.rds" ftype="rdata.sce" compare="sim_size"/>
+        </test>
+    </tests>
+    <help><![CDATA[
+anndata2ri
+==========
+        Convert between Anndata and SingleCellExperiment objects. For conversion of further single-cell file formats, consider using **SCEasy Converter** tool.
+    ]]></help>
+    <citations>
+        <citation type="bibtex">
+        @unpublished{anndata2ri,
+            author = {Theis Lab},
+            title = {Convert between AnnData and SingleCellExperiment },
+            url = {https://github.com/theislab/anndata2ri}
+        }
+        </citation>
+    </citations>
+</tool>
Binary file test-data/krumsiek11.h5ad has changed
Binary file test-data/krumsiek11.rds has changed