Repository 'anndata_manipulate'
hg clone https://toolshed.g2.bx.psu.edu/repos/iuc/anndata_manipulate

Changeset 15:d1e49c3c0aa2 (2025-01-11)
Previous changeset 14:c4209ea387d4 (2024-11-08)
Commit message:
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit 4f6d044223f374ba44a4d46ad77559ca781e6db7
modified:
macros.xml
manipulate.xml
test-data/tl.umap.h5ad
added:
test-data/flag_new_key.h5ad
b
diff -r c4209ea387d4 -r d1e49c3c0aa2 macros.xml
--- a/macros.xml Fri Nov 08 21:59:34 2024 +0000
+++ b/macros.xml Sat Jan 11 21:10:19 2025 +0000
b
@@ -1,6 +1,6 @@
 <macros>
     <token name="@TOOL_VERSION@">0.10.9</token>
-    <token name="@VERSION_SUFFIX@">0</token>
+    <token name="@VERSION_SUFFIX@">1</token>
     <token name="@PROFILE@">21.09</token>
     <xml name="requirements">
         <requirements>
b
diff -r c4209ea387d4 -r d1e49c3c0aa2 manipulate.xml
--- a/manipulate.xml Fri Nov 08 21:59:34 2024 +0000
+++ b/manipulate.xml Sat Jan 11 21:10:19 2025 +0000
[
b'@@ -37,6 +37,11 @@\n     #else\n     index_unique=None,\n     #end if\n+    #if str($manipulate.uns_merge) != \'None\'\n+    uns_merge=\'$manipulate.uns_merge\',\n+    #else\n+    uns_merge=None,\n+    #end if\n     batch_key=\'$manipulate.batch_key\')\n \n #else if $manipulate.function == \'var_names_make_unique\'\n@@ -47,9 +52,30 @@\n \n #else if $manipulate.function == \'rename_categories\'\n     #set $categories = [x.strip() for x in str($manipulate.categories).split(\',\')]\n+    #if $manipulate.update_key.new_key == \'no\':\n adata.rename_categories(\n     key=\'$manipulate.key\',\n     categories=$categories)\n+    #else\n+if \'$manipulate.key\' in adata.obs:\n+    print("changing key in obs")\n+    adata.obs[\'$manipulate.key_name\'] = adata.obs[\'$manipulate.key\']\n+    adata.rename_categories(\n+        key=\'$manipulate.key_name\',\n+        categories=$categories)\n+elif \'$manipulate.key\' in adata.var:\n+    print("changing key in var")\n+    adata.var[\'$manipulate.key_name\'] = adata.var[\'$manipulate.key\']\n+    adata.rename_categories(\n+        key=\'$manipulate.key_name\',\n+        categories=$categories)\n+else:\n+    print("chanigng key in uns")\n+    adata.uns[\'$manipulate.key_name\'] = adata.uns[\'$manipulate.key\']\n+    adata.rename_categories(\n+        key=\'$manipulate.key_name\',\n+        categories=$categories)\n+    #end if\n \n #else if $manipulate.function == \'remove_keys\'\n     #if $manipulate.obs_keys\n@@ -65,13 +91,29 @@\n #else if $manipulate.function == \'flag_genes\'\n ## adapted from anndata operations\n     #for $flag in $manipulate.gene_flags\n+        #if str($flag.col_in) != \'\':\n+k_cat = adata.var[\'${flag.col_in}\'].str.startswith(\'${flag.startswith}\')\n+        #else:\n k_cat = adata.var_names.str.startswith(\'${flag.startswith}\')\n+        #end if\n if k_cat.sum() > 0:\n-    adata.var[\'${flag.col_name}\'] = k_cat\n+    adata.var[\'${flag.col_out}\'] = k_cat\n else:\n     print(f\'No genes starting with {\'${flag.startswith}\'} found.\')\n #end for\n \n+#else if $manipulate.function == \'rename_obs\':\n+adata.obs[\'${to_obs}\'] = adata.obs[\'${from_obs}\']\n+#if not $keep_original:\n+del adata.obs[\'${from_obs}\']\n+#end if\n+\n+#else if $manipulate.function == \'rename_var\':\n+adata.var[\'${to_var}\'] = adata.var[\'${from_var}\']\n+#if not $keep_original:\n+del adata.var[\'${from_var}\']\n+#end if\n+\n #else if $manipulate.function == \'strings_to_categoricals\'\n adata.strings_to_categoricals()\n \n@@ -101,54 +143,64 @@\n     ad_s = adata[adata.obs.${manipulate.key} == field_value]\n     ad_s.write(f"{res_dir}/${manipulate.key}_{s}.h5ad", compression=\'gzip\')\n \n-#else if $manipulate.function == \'filter\'\n-    #if $manipulate.filter.filter == \'key\'\n-        #if $manipulate.var_obs == \'var\'\n-filtered = adata.var[\'$manipulate.filter.key\']\n-        #else if $manipulate.var_obs == \'obs\'\n-filtered = adata.obs[\'$manipulate.filter.key\']\n+#else if $manipulate.function == \'copy_obs\'\n+source_adata = ad.read_h5ad(\'$source_adata\')\n+    #for $key in $manipulate.keys\n+if \'$key.source_key\' in source_adata.obs:\n+        #if str($key.target_key) == \'\':\n+    adata.obs[\'$key.source_key\'] = source_adata.obs[\'$key.source_key\']\n+        #else\n+    adata.obs[\'$key.target_key\'] = source_adata.obs[\'$key.source_key\']\n         #end if\n+else:\n+    print(f"Obs column {\'{$key.source_key}\'} not found in source AnnData.")\n+    #end for\n+\n+#else if $manipulate.function == \'copy_uns\'\n+source_adata = ad.read_h5ad(\'$source_adata\')\n+    #for $key in $manipulate.keys\n+if \'$key.source_key\' in source_adata.uns:\n+        #if str($key.target_key) == \'\':\n+    adata.uns[\'$key.source_key\'] = source_adata.uns[\'$key.source_key\']\n+        #else\n+    adata.uns[\'$key.target_key\'] = source_adata.uns[\'$key.source_key\']\n+        #end if\n+else:\n+    print(f"Uns key {\'{$key.source_key}\'} not found in source AnnData.")\n+    #end for\n \n-        #if $manipulate.filter.filter_key.type == \'number\'\n-            #if $manipulate.filter.filter_key.filter == \'equal\'\n-filtered = filtered == $manipulate.filter.filter_key.value\n-            #else if $manipulate.filter.filter_key.fi'..b'unction" value="rename_obs"/>\n+                <param name="from_obs" value="cell_type"/>\n+                <param name="to_obs" value="new_cell_type"/>\n+                <param name="keep_original" value="false"/>\n+            </conditional>\n+            <assert_stdout>\n+                <has_text_matching expression="adata.obs\\[\'new_cell_type\'\\] = adata.obs\\[\'cell_type\'\\]"/>\n+                <has_text_matching expression="del adata.obs\\[\'cell_type\'\\]"/>\n+                <has_text_matching expression="500 \xc3\x97 11"/>\n+            </assert_stdout>\n+            <output name="anndata" ftype="h5ad">\n+                <assert_contents>\n+                    <has_h5_keys keys="obs/new_cell_type"/>\n+                    <has_h5_keys keys="uns/highlights"/>\n+                    <has_h5_keys keys="uns/iroot"/>\n+                </assert_contents>\n+            </output>\n+        </test>\n+        <test expect_num_outputs="1">\n+            <!-- test 22 rename_var -->\n+            <param name="input" value="flag_new_key.h5ad"/>\n+            <conditional name="manipulate">\n+                <param name="function" value="rename_var"/>\n+                <param name="from_var" value="gene_ids"/>\n+                <param name="to_var" value="new_id"/>\n+                <param name="keep_original" value="false"/>\n+            </conditional>\n+            <assert_stdout>\n+                <has_text_matching expression="adata.var\\[\'new_id\'\\] = adata.var\\[\'gene_ids\'\\]"/>\n+                <has_text_matching expression="del adata.var\\[\'gene_ids\'\\]"/>\n+                <has_text_matching expression="199 \xc3\x97 199"/>\n+            </assert_stdout>\n+            <output name="anndata" ftype="h5ad">\n+                <assert_contents>\n+                    <has_h5_keys keys="var/feature_types"/>\n+                    <has_h5_keys keys="var/test"/>\n+                    <has_h5_keys keys="var/new_id"/>\n+                </assert_contents>\n+            </output>\n+        </test>\n     </tests>\n     <help><![CDATA[\n **What it does**\n \n-This tool takes a AnnData dataset, manipulates it and returns it.\n+This tool takes an AnnData dataset, manipulates it and returns it.\n \n The possible manipulations are:\n \n@@ -638,11 +930,11 @@\n \n - Makes the obs index unique by appending \'1\', \'2\', etc (`obs_names_make_unique method <https://anndata.readthedocs.io/en/latest/generated/anndata.AnnData.obs_names_make_unique.html>`__)\n \n-    The first occurance of a non-unique value is ignored.\n+    The first occurrence of a non-unique value is ignored.\n \n - Makes the var index unique by appending \'1\', \'2\', etc (`var_names_make_unique method <https://anndata.readthedocs.io/en/latest/generated/anndata.AnnData.var_names_make_unique.html>`__)\n \n-    The first occurance of a non-unique value is ignored.\n+    The first occurrence of a non-unique value is ignored.\n \n - Rename categories of annotation `key` in `obs`, `var` and `uns` (`rename_categories method <https://anndata.readthedocs.io/en/latest/generated/anndata.AnnData.rename_categories.html>`__)\n \n@@ -654,7 +946,7 @@\n \n - Flag genes start with a pattern\n \n-    Useful for flagging the mitochoncdrial or ribosomal protein genes\n+    Useful for flagging the mitochondrial or ribosomal protein genes\n \n - Transform string annotations to categoricals (`strings_to_categoricals method <https://anndata.readthedocs.io/en/latest/generated/anndata.AnnData.strings_to_categoricals.html>`__)\n \n@@ -668,7 +960,7 @@\n \n - Split the AnnData object into multiple AnnData objects based on the values of a given obs key\n \n-    For example, helps in splitting an anndata objects based on cluster annotation. This function generates a collection with number of elements equal to the number of categories in the input obs key.\n+    For example, helps in splitting an anndata objects based on cluster annotation. This function generates a collection with a number of elements equal to the number of categories in the input obs key.\n \n - Filter data variables or observations, by index or key\n \n'
b
diff -r c4209ea387d4 -r d1e49c3c0aa2 test-data/flag_new_key.h5ad
b
Binary file test-data/flag_new_key.h5ad has changed
b
diff -r c4209ea387d4 -r d1e49c3c0aa2 test-data/tl.umap.h5ad
b
Binary file test-data/tl.umap.h5ad has changed