# HG changeset patch # User iuc # Date 1736629819 0 # Node ID d1e49c3c0aa2d53a0a4574b33b6005c6855591af # Parent c4209ea387d404d8df2d2af69d41ac6f225aa922 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/anndata/ commit 4f6d044223f374ba44a4d46ad77559ca781e6db7 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 @@ -1,6 +1,6 @@ 0.10.9 - 0 + 1 21.09 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 @@ -37,6 +37,11 @@ #else index_unique=None, #end if + #if str($manipulate.uns_merge) != 'None' + uns_merge='$manipulate.uns_merge', + #else + uns_merge=None, + #end if batch_key='$manipulate.batch_key') #else if $manipulate.function == 'var_names_make_unique' @@ -47,9 +52,30 @@ #else if $manipulate.function == 'rename_categories' #set $categories = [x.strip() for x in str($manipulate.categories).split(',')] + #if $manipulate.update_key.new_key == 'no': adata.rename_categories( key='$manipulate.key', categories=$categories) + #else +if '$manipulate.key' in adata.obs: + print("changing key in obs") + adata.obs['$manipulate.key_name'] = adata.obs['$manipulate.key'] + adata.rename_categories( + key='$manipulate.key_name', + categories=$categories) +elif '$manipulate.key' in adata.var: + print("changing key in var") + adata.var['$manipulate.key_name'] = adata.var['$manipulate.key'] + adata.rename_categories( + key='$manipulate.key_name', + categories=$categories) +else: + print("chanigng key in uns") + adata.uns['$manipulate.key_name'] = adata.uns['$manipulate.key'] + adata.rename_categories( + key='$manipulate.key_name', + categories=$categories) + #end if #else if $manipulate.function == 'remove_keys' #if $manipulate.obs_keys @@ -65,13 +91,29 @@ #else if $manipulate.function == 'flag_genes' ## adapted from anndata operations #for $flag in $manipulate.gene_flags + #if str($flag.col_in) != '': +k_cat = adata.var['${flag.col_in}'].str.startswith('${flag.startswith}') + #else: k_cat = adata.var_names.str.startswith('${flag.startswith}') + #end if if k_cat.sum() > 0: - adata.var['${flag.col_name}'] = k_cat + adata.var['${flag.col_out}'] = k_cat else: print(f'No genes starting with {'${flag.startswith}'} found.') #end for +#else if $manipulate.function == 'rename_obs': +adata.obs['${to_obs}'] = adata.obs['${from_obs}'] +#if not $keep_original: +del adata.obs['${from_obs}'] +#end if + +#else if $manipulate.function == 'rename_var': +adata.var['${to_var}'] = adata.var['${from_var}'] +#if not $keep_original: +del adata.var['${from_var}'] +#end if + #else if $manipulate.function == 'strings_to_categoricals' adata.strings_to_categoricals() @@ -101,54 +143,64 @@ ad_s = adata[adata.obs.${manipulate.key} == field_value] ad_s.write(f"{res_dir}/${manipulate.key}_{s}.h5ad", compression='gzip') -#else if $manipulate.function == 'filter' - #if $manipulate.filter.filter == 'key' - #if $manipulate.var_obs == 'var' -filtered = adata.var['$manipulate.filter.key'] - #else if $manipulate.var_obs == 'obs' -filtered = adata.obs['$manipulate.filter.key'] +#else if $manipulate.function == 'copy_obs' +source_adata = ad.read_h5ad('$source_adata') + #for $key in $manipulate.keys +if '$key.source_key' in source_adata.obs: + #if str($key.target_key) == '': + adata.obs['$key.source_key'] = source_adata.obs['$key.source_key'] + #else + adata.obs['$key.target_key'] = source_adata.obs['$key.source_key'] #end if +else: + print(f"Obs column {'{$key.source_key}'} not found in source AnnData.") + #end for + +#else if $manipulate.function == 'copy_uns' +source_adata = ad.read_h5ad('$source_adata') + #for $key in $manipulate.keys +if '$key.source_key' in source_adata.uns: + #if str($key.target_key) == '': + adata.uns['$key.source_key'] = source_adata.uns['$key.source_key'] + #else + adata.uns['$key.target_key'] = source_adata.uns['$key.source_key'] + #end if +else: + print(f"Uns key {'{$key.source_key}'} not found in source AnnData.") + #end for - #if $manipulate.filter.filter_key.type == 'number' - #if $manipulate.filter.filter_key.filter == 'equal' -filtered = filtered == $manipulate.filter.filter_key.value - #else if $manipulate.filter.filter_key.filter == 'equal' -filtered = filtered != $manipulate.filter.filter_key.value - #else if $manipulate.filter.filter_key.filter == 'less' -filtered = filtered < $manipulate.filter.filter_key.value - #else if $manipulate.filter.filter_key.filter == 'less_or_equal' -filtered = filtered <= $manipulate.filter.filter_key.value - #else if $manipulate.filter.filter_key.filter == 'greater' -filtered = filtered > $manipulate.filter.filter_key.value - #else if $manipulate.filter.filter_key.filter == 'greater_or_equal' -filtered = filtered >= $manipulate.filter.filter_key.value - #end if - #else if $manipulate.filter.filter_key.type == 'text' - #if $manipulate.filter.filter_key.filter == 'equal' -filtered = filtered == '$manipulate.filter.filter_key.value' - #else -filtered = filtered != '$manipulate.filter.filter_key.value' - #end if - #else if $manipulate.filter.filter_key.type == 'boolean' -filtered = filtered == $manipulate.filter.filter_key.value +#else if $manipulate.function == 'copy_embed' +source_adata = ad.read_h5ad('$source_adata') + #for $key in $manipulate.keys +if '$key.source_key' in source_adata.obsm: + #if $key.target_key is None + adata.obsm['$key.source_key'] = source_adata.obsm['$key.source_key'] + #else + adata.obsm['$key.target_key'] = source_adata.obsm['$key.source_key'] #end if +else: + print(f"Embedding key {'{$key.source_key}'} not found in source AnnData.") + #end for - #else if $manipulate.filter.filter == 'index' - #if str($manipulate.filter.index.format) == 'file' -with open('$manipulate.filter.index.file', 'r') as filter_f: - filters = [str(x.strip()) for x in filter_f.readlines()] -filtered = filters +#else if $manipulate.function == 'copy_layers' +source_adata = ad.read_h5ad('$source_adata') + #for $key in $manipulate.keys +if '$key.source_key' in source_adata.layers: + #if $key.target_key is None + adata.layers['$key.source_key'] = source_adata.layers['$key.source_key'] #else - #set $filters = [str(x.strip()) for x in $manipulate.filter.index.text.split(',')] -filtered = $filters + adata.layers['$key.target_key'] = source_adata.layers['$key.source_key'] #end if - #end if -print(filtered) +else: + print(f"Layer {'{$key.source_key}'} not found in source AnnData.") + #end for - #if $manipulate.var_obs == 'var' -adata = adata[:,filtered] - #else if $manipulate.var_obs == 'obs' -adata = adata[filtered, :] +#else if $manipulate.function == 'copy_X' +source_adata = ad.read_h5ad('$source_adata') + #if $target_key is None +adata.X = source_adata.X + #else +adata.layers['$target_key'] = source_adata.X #end if #else if $manipulate.function == 'save_raw' @@ -173,11 +225,17 @@ + + - + + + + + @@ -187,6 +245,13 @@ + + + + + + + @@ -203,6 +268,18 @@ + + + + + + + + + + + + @@ -221,9 +298,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + @@ -232,7 +332,7 @@ + help="The new table should have the same number of rows and the same order as obs or var. The key names should be in the header (1st line)"/> @@ -243,63 +343,57 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + @@ -381,6 +475,9 @@ + + + @@ -478,58 +575,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -544,7 +589,7 @@ - + @@ -561,17 +606,17 @@ - + - + - + @@ -585,7 +630,7 @@ - + @@ -622,11 +667,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `__) - The first occurance of a non-unique value is ignored. + The first occurrence of a non-unique value is ignored. - Makes the var index unique by appending '1', '2', etc (`var_names_make_unique method `__) - The first occurance of a non-unique value is ignored. + The first occurrence of a non-unique value is ignored. - Rename categories of annotation `key` in `obs`, `var` and `uns` (`rename_categories method `__) @@ -654,7 +946,7 @@ - Flag genes start with a pattern - Useful for flagging the mitochoncdrial or ribosomal protein genes + Useful for flagging the mitochondrial or ribosomal protein genes - Transform string annotations to categoricals (`strings_to_categoricals method `__) @@ -668,7 +960,7 @@ - Split the AnnData object into multiple AnnData objects based on the values of a given obs key - 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. + 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. - Filter data variables or observations, by index or key diff -r c4209ea387d4 -r d1e49c3c0aa2 test-data/flag_new_key.h5ad Binary file test-data/flag_new_key.h5ad has changed diff -r c4209ea387d4 -r d1e49c3c0aa2 test-data/tl.umap.h5ad Binary file test-data/tl.umap.h5ad has changed