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

Changeset 13:7e8c677a7b71 (2024-09-14)
Previous changeset 12:ed4996a16f7f (2023-11-12) Next changeset 14:c4209ea387d4 (2024-11-08)
Commit message:
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit 67b3808b56df343798263ff0c905df8cb789edfa
modified:
macros.xml
manipulate.xml
test-data/addloomout1.loom
test-data/addloomout3.loom
test-data/converted.loom.test
test-data/export.krumsiek11.loom
test-data/import.csv.h5ad
test-data/krumsiek11.h5ad
test-data/pp.neighbors_umap_euclidean.recipe_weinreb17.paul15_subsample.h5ad
test-data/pp.pca.krumsiek11.h5ad
test-data/tl.diffmap.h5ad
test-data/tl.draw_graph.h5ad
test-data/tl.paga.neighbors_gauss_braycurtis.recipe_weinreb17.paul15_subsample.h5ad
test-data/tl.rank_genes_groups.krumsiek11.h5ad
test-data/tl.tsne.h5ad
test-data/tl.umap.h5ad
removed:
test-data/import.loom.krumsiek11.h5ad
test-data/import.mtx.legacy_10x.h5ad
test-data/import.mtx.no_10x.h5ad
test-data/import.mtx.v3_10x.h5ad
test-data/import.tsv.h5ad
test-data/import.umi_tools.h5ad
test-data/manipulate.add_annotation_obs.h5ad
test-data/manipulate.add_annotation_var.h5ad
test-data/manipulate.concatenate.h5ad
test-data/manipulate.filter_obs_key.h5ad
test-data/manipulate.filter_var_index.h5ad
test-data/manipulate.obs_names_make_unique.h5ad
test-data/manipulate.rename_categories.h5ad
test-data/manipulate.save_raw.h5ad
test-data/manipulate.strings_to_categoricals.h5ad
test-data/manipulate.transpose.h5ad
test-data/manipulate.var_names_make_unique.h5ad
b
diff -r ed4996a16f7f -r 7e8c677a7b71 macros.xml
--- a/macros.xml Sun Nov 12 16:42:25 2023 +0000
+++ b/macros.xml Sat Sep 14 19:58:00 2024 +0000
[
@@ -1,6 +1,7 @@
 <macros>
-    <token name="@TOOL_VERSION@">0.10.3</token>
+    <token name="@TOOL_VERSION@">0.10.9</token>
     <token name="@VERSION_SUFFIX@">0</token>
+    <token name="@PROFILE@">21.09</token>
     <xml name="requirements">
         <requirements>
             <requirement type="package" version="@TOOL_VERSION@">anndata</requirement>
@@ -21,12 +22,6 @@
 python '$script_file'
     ]]>
     </token>
-    <token name="@LOOMCMD@"><![CDATA[
-mkdir ./output &&
-mkdir ./attributes &&
-python '$__tool_directory__/loompy_to_tsv.py' -f '${hd5_format.input}'
-    ]]>
-    </token>
     <token name="@CMD_imports@"><![CDATA[
 import anndata as ad
     ]]>
@@ -76,4 +71,11 @@
             </when>
         </conditional>
     </xml>
+    <xml name="sanitize_query" token_validinitial="string.printable">
+        <sanitizer>
+            <valid initial="@VALIDINITIAL@">
+                <remove value="&apos;" />
+            </valid>
+       </sanitizer>
+    </xml>
 </macros>
b
diff -r ed4996a16f7f -r 7e8c677a7b71 manipulate.xml
--- a/manipulate.xml Sun Nov 12 16:42:25 2023 +0000
+++ b/manipulate.xml Sat Sep 14 19:58:00 2024 +0000
[
b'@@ -1,4 +1,4 @@\n-<tool id="anndata_manipulate" name="Manipulate AnnData" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@">\n+<tool id="anndata_manipulate" name="Manipulate AnnData" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">\n     <description>object</description>\n     <macros>\n         <import>macros.xml</import>\n@@ -50,6 +50,27 @@\n     key=\'$manipulate.key\',\n     categories=$categories)\n \n+#else if $manipulate.function == \'remove_keys\'\n+    #if $manipulate.obs_keys\n+        #set $keys = [x.strip() for x in str($manipulate.obs_keys).split(\',\')]\n+adata.obs = adata.obs.drop(columns=$keys)\n+    #end if\n+\n+    #if $manipulate.var_keys\n+        #set $keys = [x.strip() for x in str($manipulate.var_keys).split(\',\')]\n+adata.var = adata.vars.drop(columns=$keys)\n+    #end if\n+\n+#else if $manipulate.function == \'flag_genes\'\n+## adapted from anndata operations\n+    #for $flag in $manipulate.gene_flags\n+k_cat = adata.var_names.str.startswith(\'${flag.startswith}\')\n+if k_cat.sum() > 0:\n+    adata.var[\'${flag.col_name}\'] = k_cat\n+else:\n+    print(f\'No genes starting with {\'${flag.startswith}\'} found.\')\n+#end for\n+\n #else if $manipulate.function == \'strings_to_categoricals\'\n adata.strings_to_categoricals()\n \n@@ -71,6 +92,14 @@\n adata.obs = obs\n     #end if\n \n+#else if $manipulate.function == \'split_on_obs\'\n+import os\n+res_dir = "output_split"\n+os.makedirs(res_dir, exist_ok=True)\n+for s,field_value in enumerate(adata.obs["${manipulate.key}"].unique()):\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@@ -126,7 +155,11 @@\n \n #end if\n \n-adata.write(\'anndata.h5ad\')\n+#if $manipulate.function != \'split_on_obs\'\n+adata.write(\'anndata.h5ad\', compression=\'gzip\')\n+print(adata)\n+#end if\n+\n ]]></configfile>\n     </configfiles>\n     <inputs>\n@@ -137,9 +170,12 @@\n                 <option value="obs_names_make_unique">Makes the obs index unique by appending \'1\', \'2\', etc</option>\n                 <option value="var_names_make_unique">Makes the var index unique by appending \'1\', \'2\', etc</option>\n                 <option value="rename_categories">Rename categories of annotation</option>\n+                <option value="remove_keys">Remove keys from obs or var annotations</option>\n+                <option value="flag_genes">Flag genes start with a pattern</option><!--adapted from EBI anndata operations tool -->\n                 <option value="strings_to_categoricals">Transform string annotations to categoricals</option>\n                 <option value="transpose">Transpose the data matrix, leaving observations and variables interchanged</option>\n                 <option value="add_annotation">Add new annotation(s) for observations or variables</option>\n+                <option value="split_on_obs">Split the AnnData object into multiple AnnData objects based on the values of a given obs key</option><!--adapted from EBI anndata operations tool-->\n                 <option value="filter">Filter observations or variables</option>\n                 <option value="save_raw">Freeze the current state into the \'raw\' attribute</option>\n             </param>\n@@ -167,6 +203,26 @@\n                 <param name="key" type="text" value="" label="Key for observations or variables annotation" help="Annotation key in obs or var"/>\n                 <param name="categories" type="text" value="" label="Comma-separated list of new categories" help="It should be the same number as the old categories"/>\n             </when>\n+            <when value="remove_keys">\n+                <param name="obs_keys" type="text" value="" optional="true" label="Keys/fields to remove from observations (obs)">\n+                    <expand macro="sanitize_query"/>\n+                </param>\n+                <param name="var_keys" type="text" value="" optional="true" la'..b'+            </conditional>\n+            <assert_stdout>\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="var/Gata_TF"/>\n+                    <has_h5_keys keys="var/GF"/>\n+                </assert_contents>\n+            </output>\n+        </test>\n+        <test expect_num_outputs="1">\n+            <!-- test 14 split_on_obs -->\n+            <param name="input" value="krumsiek11.h5ad"/>\n+            <conditional name="manipulate">\n+                <param name="function" value="split_on_obs"/>\n+                <param name="key" value="cell_type"/>\n+            </conditional>\n+            <output_collection name="output_h5ad_split" type="list">\n+                <element name="cell_type_0">\n+                    <assert_contents>\n+                        <has_h5_keys keys="obs/cell_type"/>\n+                        <has_h5_keys keys="uns/highlights"/>\n+                        <has_h5_keys keys="uns/iroot"/>\n+                    </assert_contents>\n+                </element>\n+                <element name="cell_type_1">\n+                    <assert_contents>\n+                        <has_h5_keys keys="obs/cell_type"/>\n+                        <has_h5_keys keys="uns/highlights"/>\n+                        <has_h5_keys keys="uns/iroot"/>\n+                    </assert_contents>\n+                </element>\n+                <element name="cell_type_2">\n+                    <assert_contents>\n+                        <has_h5_keys keys="obs/cell_type"/>\n+                        <has_h5_keys keys="uns/highlights"/>\n+                        <has_h5_keys keys="uns/iroot"/>\n+                    </assert_contents>\n+                </element>\n+                <element name="cell_type_3">\n+                    <assert_contents>\n+                        <has_h5_keys keys="obs/cell_type"/>\n+                        <has_h5_keys keys="uns/highlights"/>\n+                        <has_h5_keys keys="uns/iroot"/>\n+                    </assert_contents>\n+                </element>\n+            </output_collection>\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 a AnnData dataset, manipulates it and returns it.\n \n-The possible manipulations are: \n+The possible manipulations are:\n \n - Concatenate along the observations axis (`concatenate method <https://anndata.readthedocs.io/en/latest/generated/anndata.AnnData.concatenate.html>`__)\n \n@@ -408,6 +647,14 @@\n \n     Besides calling `self.obs[key].cat.categories = categories` - similar for `var` - this also renames categories in unstructured annotation that uses the categorical annotation `key`\n \n+- Remove keys from obs or var annotations\n+\n+    Helps in cleaning up andata with many annotations. For example, helps in removing qc metrics calculated during the preprocesing or already existing cluster annotations.\n+\n+- Flag genes start with a pattern\n+\n+    Useful for flagging the mitochoncdrial 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     Only affects string annotations that lead to less categories than the total number of observations.\n@@ -416,7 +663,11 @@\n \n     Data matrix is transposed, observations and variables are interchanged.\n \n-- Add annotation for variables or observations \n+- Add annotation for variables or\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 \n - Filter data variables or observations, by index or key\n \n'
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/addloomout1.loom
b
Binary file test-data/addloomout1.loom has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/addloomout3.loom
b
Binary file test-data/addloomout3.loom has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/converted.loom.test
b
Binary file test-data/converted.loom.test has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/export.krumsiek11.loom
b
Binary file test-data/export.krumsiek11.loom has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/import.csv.h5ad
b
Binary file test-data/import.csv.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/import.loom.krumsiek11.h5ad
b
Binary file test-data/import.loom.krumsiek11.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/import.mtx.legacy_10x.h5ad
b
Binary file test-data/import.mtx.legacy_10x.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/import.mtx.no_10x.h5ad
b
Binary file test-data/import.mtx.no_10x.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/import.mtx.v3_10x.h5ad
b
Binary file test-data/import.mtx.v3_10x.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/import.tsv.h5ad
b
Binary file test-data/import.tsv.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/import.umi_tools.h5ad
b
Binary file test-data/import.umi_tools.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/krumsiek11.h5ad
b
Binary file test-data/krumsiek11.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.add_annotation_obs.h5ad
b
Binary file test-data/manipulate.add_annotation_obs.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.add_annotation_var.h5ad
b
Binary file test-data/manipulate.add_annotation_var.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.concatenate.h5ad
b
Binary file test-data/manipulate.concatenate.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.filter_obs_key.h5ad
b
Binary file test-data/manipulate.filter_obs_key.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.filter_var_index.h5ad
b
Binary file test-data/manipulate.filter_var_index.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.obs_names_make_unique.h5ad
b
Binary file test-data/manipulate.obs_names_make_unique.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.rename_categories.h5ad
b
Binary file test-data/manipulate.rename_categories.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.save_raw.h5ad
b
Binary file test-data/manipulate.save_raw.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.strings_to_categoricals.h5ad
b
Binary file test-data/manipulate.strings_to_categoricals.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.transpose.h5ad
b
Binary file test-data/manipulate.transpose.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/manipulate.var_names_make_unique.h5ad
b
Binary file test-data/manipulate.var_names_make_unique.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/pp.neighbors_umap_euclidean.recipe_weinreb17.paul15_subsample.h5ad
b
Binary file test-data/pp.neighbors_umap_euclidean.recipe_weinreb17.paul15_subsample.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/pp.pca.krumsiek11.h5ad
b
Binary file test-data/pp.pca.krumsiek11.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/tl.diffmap.h5ad
b
Binary file test-data/tl.diffmap.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/tl.draw_graph.h5ad
b
Binary file test-data/tl.draw_graph.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/tl.paga.neighbors_gauss_braycurtis.recipe_weinreb17.paul15_subsample.h5ad
b
Binary file test-data/tl.paga.neighbors_gauss_braycurtis.recipe_weinreb17.paul15_subsample.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/tl.rank_genes_groups.krumsiek11.h5ad
b
Binary file test-data/tl.rank_genes_groups.krumsiek11.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/tl.tsne.h5ad
b
Binary file test-data/tl.tsne.h5ad has changed
b
diff -r ed4996a16f7f -r 7e8c677a7b71 test-data/tl.umap.h5ad
b
Binary file test-data/tl.umap.h5ad has changed