Previous changeset 25:a36d7a315be7 (2021-10-28) Next changeset 27:7ebc22f77d86 (2023-04-14) |
Commit message:
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/tree/develop/tools/tertiary-analysis/scanpy commit 6c9d530aa653101e9e21804393ec11f38cddf027-dirty |
modified:
anndata_operations.xml scanpy_macros2.xml |
b |
diff -r a36d7a315be7 -r 825dfd66e3fb anndata_operations.xml --- a/anndata_operations.xml Thu Oct 28 09:55:27 2021 +0000 +++ b/anndata_operations.xml Thu Feb 16 13:28:31 2023 +0000 |
[ |
b'@@ -1,5 +1,5 @@\n <?xml version="1.0" encoding="utf-8"?>\n-<tool id="anndata_ops" name="AnnData Operations" version="@TOOL_VERSION@+galaxy0" profile="@PROFILE@">\n+<tool id="anndata_ops" name="AnnData Operations" version="@TOOL_VERSION@+galaxy9" profile="@PROFILE@">\n <description>modifies metadata and flags genes</description>\n <macros>\n <import>scanpy_macros2.xml</import>\n@@ -45,11 +45,19 @@\n ]]></command>\n <configfiles>\n <configfile name="operations">\n+import gc\n import scanpy as sc\n import anndata\n from numpy import all\n import logging\n \n+def make_column_values_unique(df, field, new_field=None, suffix = \'-duplicate-\'):\n+ if new_field is None:\n+ new_field = f"{field}_u"\n+ appendents = (suffix + df.groupby(field).cumcount().astype(str).replace(\'0\',\'\')).replace(suffix, \'\')\n+ df[new_field] = df[field].astype(str) + appendents.astype(str)\n+ return df\n+\n adata = sc.read(\'input.h5\')\n \n #if $copy_adata_to_raw:\n@@ -60,14 +68,22 @@\n qc_vars = list()\n \n #for $i, $s in enumerate($modifications)\n+#if $s.make_unique:\n+adata.obs = make_column_values_unique(adata.obs, field=\'${s.from_obs}\', new_field=\'${s.to_obs}\', suffix = "_d")\n+#else\n adata.obs[\'${s.to_obs}\'] = adata.obs[\'${s.from_obs}\']\n+#end if\n #if not $s.keep_original:\n del adata.obs[\'${s.from_obs}\']\n #end if\n #end for\n \n #for $i, $s in enumerate($var_modifications)\n+#if $s.make_unique:\n+adata.var = make_column_values_unique(adata.var, field=\'${s.from_var}\', new_field=\'${s.to_var}\', suffix = "_d")\n+#else\n adata.var[\'${s.to_var}\'] = adata.var[\'${s.from_var}\']\n+#end if\n #if not $s.keep_original:\n del adata.var[\'${s.from_var}\']\n #end if\n@@ -84,6 +100,21 @@\n logging.warning(\'No genes starting with {} found, skip calculating expression of {} genes\'.format(\'${flag.startswith}\', \'${flag.flag}\'))\n #end for\n \n+#if $field_unique:\n+field_unique = \'${field_unique}\'\n+made_unique = 0\n+if field_unique in adata.var_keys(): \t \n+ adata.var = make_column_values_unique(adata.var, field_unique, suffix = "_d")\n+ made_unique += 1\n+if field_unique in adata.obs_keys():\n+ adata.obs = make_column_values_unique(adata.obs, field_unique, suffix = "_d")\n+ made_unique += 1\n+\t \n+if made_unique == 0:\n+ logging.error("Specified field to be made unique is not in var or obs.")\n+ sys.exit(1) \n+#end if\t\n+\t \n #if $copy_r.default and $copy_r.r_source:\n ad_s = sc.read(\'r_source.h5\')\n if not all(adata.obs.index.isin(ad_s.obs.index)):\n@@ -92,6 +123,7 @@\n else:\n adata.raw = ad_s[adata.obs.index]\n del ad_s\n+gc.collect()\n #end if\n \n #if $copy_x.default and len($copy_x.xlayers) > 0:\n@@ -107,6 +139,7 @@\n logging.error("X source ${i} AnnData file is not compatible to be merged to main AnnData file, different cell names.")\n sys.exit(1)\n del ad_s\n+gc.collect()\n #end for\n #end if\n \n@@ -120,13 +153,13 @@\n suffix=\'\'\n if l_to_copy in adata.layers:\n suffix = "_${i}"\n-\n adata.layers[l_to_copy+suffix] = ad_s.layers[l_to_copy]\n #end for\n else:\n logging.error("Layer source ${i} AnnData file is not compatible to be merged to main AnnData file, different cell names.")\n sys.exit(1)\n del ad_s\n+gc.collect()\n #end for\n #end if\n \n@@ -149,6 +182,7 @@\n logging.error("Observation source ${i} AnnData file is not compatible to be merged to main AnnData file, different cell names.")\n sys.exit(1)\n del ad_s\n+gc.collect()\n #end for\n #end if\n \n@@ -169,6 +203,7 @@\n logging.error("Embedding source ${i} AnnData file is not compatible to be merged to main AnnData file, different cell names.")\n sys.exit(1)\n del ad_s\n+gc.collect()\n #end for\n #end if\n \n@@ -188,6 +223,7 @@\n logging.error("Uns source ${i} AnnData file is not compatible to be merged to main AnnData file, different cell names.")\n sys.exit(1)\n del ad_s\n+gc.collect()\n #end for\n #end if\n \n@@ -224,8 +260,9 @@\n <valid initial="string.printable"/>\n </sanitizer>\n </param>\n- <param name="to_obs" type="text" label="New name" help="New name in observations that you want to change"/>\n+ <param name="to_'..b'/test>\n <test>\n+ <param name="input_obj_file" value="anndata_ops.h5"/>\n+ <repeat name="var_modifications" >\n+ <param name="from_var" value = "gene_symbols" />\n+ <param name="to_var" value = "gene_symbols_unique" />\n+ <param name="make_unique" value = "True" />\n+ </repeat>\n+ <output name="output_h5ad" ftype="h5ad">\n+ <assert_contents>\n+ <has_h5_keys keys="var/gene_symbols_unique" />\n+ </assert_contents>\n+ </output>\n+ </test>\n+ <test>\n+ <param name="input_obj_file" value="anndata_ops.h5"/>\n+ <param name="field_unique" value = "gene_symbols" />\n+ <output name="output_h5ad" ftype="h5ad">\n+ <assert_contents>\n+ <has_h5_keys keys="var/gene_symbols_u" />\n+ </assert_contents>\n+ </output>\n+ </test>\n+ <test>\n <param name="input_obj_file" value="find_cluster.h5"/>\n- <param name="input_format" value="anndata"/>\n <conditional name="copy_r">\n <param name="default" value="true"/>\n <param name="r_source" value="read_10x.h5"/>\n@@ -334,39 +392,37 @@\n <output name="output_h5ad" file="anndata_ops_raw.h5" ftype="h5ad" compare="sim_size">\n <assert_contents>\n <has_h5_keys keys="raw/X" />\n-\t</assert_contents>\n+ </assert_contents>\n </output>\n </test>\n <test>\n <param name="input_obj_file" value="normalise_data.h5"/>\n- <param name="input_format" value="anndata"/>\n <conditional name="copy_x">\n <param name="default" value="true"/>\n <repeat name="xlayers">\n-\t <param name="x_source" value=\'filter_genes.h5\'/>\n-\t <param name="dest" value=\'filtered\'/>\n-\t</repeat>\n+ <param name="x_source" value=\'filter_genes.h5\'/>\n+ <param name="dest" value=\'filtered\'/>\n+ </repeat>\n </conditional>\n <output name="output_h5ad" file="anndata_ops_xlayer.h5" ftype="h5ad" compare="sim_size">\n <assert_contents>\n <has_h5_keys keys="layers/filtered" />\n-\t</assert_contents>\n+ </assert_contents>\n </output>\n </test>\n <test>\n <param name="input_obj_file" value="find_cluster.h5"/>\n- <param name="input_format" value="anndata"/>\n <conditional name="copy_l">\n <param name="default" value="true"/>\n <repeat name="layers">\n-\t <param name="contains" value=\'filtered\'/>\n-\t</repeat>\n-\t<param name="layer_sources" value=\'anndata_ops_xlayer.h5\'/>\n+ <param name="contains" value=\'filtered\'/>\n+ </repeat>\n+ <param name="layer_sources" value=\'anndata_ops_xlayer.h5\'/>\n </conditional>\n <output name="output_h5ad" file="anndata_ops_layer.h5" ftype="h5ad" compare="sim_size">\n <assert_contents>\n <has_h5_keys keys="layers/filtered" />\n-\t</assert_contents>\n+ </assert_contents>\n </output>\n </test>\n </tests>\n@@ -378,11 +434,12 @@\n \n Performs the following operations:\n \n-* Change observation/var fields, mostly for downstreaming processes convenience. Multiple fields can be changed as one.\n+* Change observation/var fields, mostly for downstreaming processes convenience. Multiple fields can be changed at once.\n * Flag genes that start with a certain text: useful for flagging mitochondrial, spikes or other groups of genes.\n * For the flags created, calculates qc metrics (pct_<flag>_counts).\n * Calculates `n_genes`, `n_counts` for cells and `n_cells`, `n_counts` for genes.\n * For top <N> genes specified, calculate qc metrics (pct_counts_in_top_<N>_genes).\n+* Make a specified column of var or obs unique (normally useful for gene symbols).\n * Copy from a set of compatible AnnData objects (same cells and genes):\n * Observations, such as clustering results.\n * Embeddings, such as tSNE or UMAPs.\n@@ -392,6 +449,7 @@\n \n History\n -------\n+1.8.1+galaxy10: Adds field to be made unique in obs or var.\n \n 1.6.0+galaxy0: Moves to Scanpy Scripts 0.3.0 (Scanpy 1.6.0), versioning switched to track Scanpy as other tools.\n \n' |
b |
diff -r a36d7a315be7 -r 825dfd66e3fb scanpy_macros2.xml --- a/scanpy_macros2.xml Thu Oct 28 09:55:27 2021 +0000 +++ b/scanpy_macros2.xml Thu Feb 16 13:28:31 2023 +0000 |
[ |
@@ -1,9 +1,11 @@ <macros> - <token name="@TOOL_VERSION@">1.8.1+3</token> + <token name="@TOOL_VERSION@">1.8.1</token> <token name="@HELP@">More information can be found at https://scanpy.readthedocs.io</token> <token name="@PROFILE@">18.01</token> <token name="@VERSION_HISTORY@"><![CDATA[ **Version history** +1.8.1+galaxy9: Fixes version label to get versions sorted properly on Galaxy (equivalent to 1.8.1+3+galaxy0). In addition, adds ability to make fields unique in AnnData operations, +adds additional handler on Scrubblet for workflows convenience, enables Scanpy tools to avoid outputing AnnData/matrix files when not required. 1.8.1+3+galaxy0: Upate to scanpy-scripts 1.1.3 (running scanpy ==1.8.1), including a fix to MTX output and a bugfix for the Scrublet wrapper. @@ -99,18 +101,20 @@ </xml> <xml name="output_object_params"> - <param name="output_format" argument="--output-format" type="select" label="Format of output object"> + <param name="output_format" argument="--output-format" type="select" label="Format of output object" help="AnnData or Loom. Legacy 'h5' datatypes are useful for interacting with older tools. Choosing 'No packaged matrix output' is useful for cases where auxiliary files are generated (like in marker genes). Do not use when there are no other output files, as the tool will generate no output in Galaxy then."> <option value="anndata_h5ad" selected="true">AnnData format</option> <option value="anndata">AnnData format (h5 for older versions)</option> <option value="loom">Loom format</option> <option value="loom_legacy">Loom format (h5 for older versions)</option> + <option value="no_matrix_output">No packaged matrix output</option> </param> </xml> <xml name="output_object_params_no_loom"> - <param name="output_format" argument="--output-format" type="select" label="Format of output object"> + <param name="output_format" argument="--output-format" type="select" label="Format of output object" help="Legacy 'h5' datatypes are useful for interacting with older tools. Choosing 'No packaged matrix output' is useful for cases where auxiliary files are generated (like in marker genes). Do not use when there are no other output files, as the tool will generate no output in Galaxy then."> <option value="anndata_h5ad" selected="true">AnnData format</option> <option value="anndata">AnnData format (h5 for older versions)</option> + <option value="no_matrix_output">No packaged matrix output (useful for cases where auxiliary files are generated)</option> </param> </xml> @@ -118,7 +122,7 @@ <data name="output_h5ad" format="h5ad" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ AnnData"> <filter>output_format == 'anndata_h5ad'</filter> </data> - <data name="output_h5" format="h5" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ AnnData"> + <data name="output_h5" format="h5" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ AnnData (h5)"> <filter>output_format == 'anndata'</filter> </data> </xml> @@ -127,13 +131,13 @@ <data name="output_h5ad" format="h5ad" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ AnnData"> <filter>output_format == 'anndata_h5ad'</filter> </data> - <data name="output_h5" format="h5" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ AnnData"> + <data name="output_h5" format="h5" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ AnnData (h5)"> <filter>output_format == 'anndata'</filter> </data> <data name="output_loom_legacy" format="h5" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ Loom"> <filter>output_format == 'loom_legacy'</filter> </data> - <data name="output_loom" format="loom" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ Loom"> + <data name="output_loom" format="loom" from_work_dir="output.h5" label="${tool.name} on ${on_string}: @DESCRIPTION@ Loom (h5)"> <filter>output_format == 'loom'</filter> </data> </xml> |