Mercurial > repos > iuc > preprocess_muon
changeset 0:678260997e94 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/muon/ commit bcf2ec32c3d13b29da55e0e638da7ddd7162c436
author | iuc |
---|---|
date | Wed, 05 Feb 2025 10:53:25 +0000 |
parents | |
children | 117dbdeec9db |
files | macros.xml preprocess_muon.xml |
diffstat | 2 files changed, 586 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/macros.xml Wed Feb 05 10:53:25 2025 +0000 @@ -0,0 +1,264 @@ +<macros> + <token name="@TOOL_VERSION@">0.1.6</token> + <token name="@VERSION_SUFFIX@">0</token> + <token name="@PROFILE@">23.0</token> + <xml name="requirements"> + <requirements> + <requirement type="package" version="@TOOL_VERSION@">muon</requirement> + <requirement type="package" version="0.10.2">leidenalg</requirement> + <requirement type="package" version="0.8.2">louvain</requirement> + <requirement type="package" version="0.7.2">mofapy2</requirement> + </requirements> + </xml> + <xml name="bio_tools"> + <xrefs> + <xref type="bio.tools">muon</xref> + </xrefs> + </xml> + <xml name="creators"> + <creator> + <organization name="European Galaxy Team" url="https://galaxyproject.org/eu/" /> + </creator> + </xml> + <xml name="citations"> + <citations> + <citation type="doi">10.1186/s13059-021-02577-8</citation> + </citations> + </xml> + <xml name="sanitize_query"> + <sanitizer> + <valid initial="string.printable"> + <remove value="'" /> + </valid> + </sanitizer> + </xml> + <xml name="sanitize_string"> + <sanitizer> + <valid initial="string.letters,string.digits"><add value="_" /></valid> + </sanitizer> + </xml> + <xml name="version_command"> + <version_command><![CDATA[python -c "import muon as mu;print('Muon version: %s' % mu.__version__)"]]></version_command> + </xml> + + <token name="@CMD_imports@"><![CDATA[ +import mudata as md +import muon as mu +import scanpy as sc +import os + ]]> + </token> + <xml name="inputs_mudata"> + <param name="mdata" type="data" format="h5ad" label="MuData input file"/> + </xml> + <token name="@CMD_read_inputs@"><![CDATA[ +mdata = md.read('mudata.h5mu') + ]]> + </token> + <token name="@CMD_prettify_stdout@"><![CDATA[ | sed -r '1 s|MuData object with (.+) = (.*)\s*|\1: \2|g' | sed "s|'||g" | sed -r 's|^\s*(.*):\s(.*)|[\1]\n- \2|g' | sed 's|, |\n- |g' + ]]></token> + <token name="@COPY_MUDATA@"><![CDATA[ +cp '$mdata' 'mudata.h5mu' && + ]]> + </token> + + <token name="@CMD@"><![CDATA[ +cat '$script_file' > '$hidden_output' && +python '$script_file' >> '$hidden_output' && +touch 'mudata_info.txt' && +cat 'mudata_info.txt' @CMD_prettify_stdout@ + ]]> + </token> + + <token name="@CMD_params_clustering@"><![CDATA[ + #if $method.res.type == 'same' + #if str($method.res.resolution) + resolution=$method.res.resolution, + #end if + #else if $method.res.type == 'separate' + resolution={ + #for $modality in $method.res.modalities + '$modality.mod_name': $modality.resolution, + #end for + }, + #end if + #if $method.weights.type == 'same' + #if str($method.weights.mod_weights) + mod_weights=$method.weights.mod_weights, + #end if + #else if $method.weights.type == 'separate' + mod_weights={ + #for $modality in $method.weights.modalities + '$modality.mod_name': $modality.mod_weights, + #end for + }, + #end if + random_state=$method.random_state, + key_added='$method.key_added', + #if $method.neighbors_key + neighbors_key='$method.neighbors_key', + #end if + directed=$method.directed + ]]></token> + + <token name="@CMD_neighbor_keys@"><![CDATA[ + #if $method.n_keys.type == 'same' + neighbor_keys='$method.n_keys.neighbor_keys', + #else if $method.n_keys.type == 'separate' + neighbor_keys={ + #for $modality in $method.n_keys.modalities + '$modality.mod_name': '$modality.neighbor_keys', + #end for + }, + #end if + ]]></token> + <token name="@CMD_params_embedding@"><![CDATA[ + #if $method.color + #set $color = ([x.strip() for x in str($method.color).split(',')]) + color=$color, + #end if + use_raw=$method.use_raw, + #if $method.layer + layer='$method.layer', + #end if + ]]></token> + + <xml name="inputs_common_advanced"> + <section name="advanced_common" title="Advanced Options" expanded="false"> + <param name="show_log" type="boolean" checked="false" label="Output Log?" /> + </section> + </xml> + <xml name="outputs_common_advanced"> + <data name="hidden_output" format="txt" label="Log file" > + <filter>advanced_common['show_log']</filter> + </data> + </xml> + <xml name="muon_outputs"> + <data name="mudata_out" format="h5ad" from_work_dir="mudata.h5mu" label="${tool.name} (${method.method}) on ${on_string}: MuData"/> + <expand macro="outputs_common_advanced"/> + </xml> + <token name="@CMD_mudata_write_outputs@"><![CDATA[ +mdata.write('mudata.h5mu') +with open('mudata_info.txt','w', encoding='utf-8') as ainfo: + print(mdata, file=ainfo) + ]]> + </token> + + <xml name="param_neighbor_keys"> + <conditional name="n_keys"> + <param name="type" type="select" label="Same or separate neighborhood information for each modality?"> + <option value="same">Same neighborhood key for all modalities</option> + <option value="separate">Separate neighborhood keys per modality</option> + </param> + <when value="same"> + <param argument="neighbor_keys" type="text" value="neighbors" label="Keys in .uns where per-modality neighborhood information is stored"/> + </when> + <when value="separate"> + <repeat name="modalities" title="Modalities" min="2" default="2"> + <param name="mod_name" type="text" label="Modality name" optional="true"> + <expand macro="sanitize_string" /> + </param> + <param argument="neighbor_keys" type="text" value="neighbors" label="Keys in .uns where neighborhood information is stored"/> + </repeat> + </when> + </conditional> + </xml> + <xml name="param_resolution"> + <conditional name="res"> + <param name="type" type="select" label="Same or separate resolutions for each modality?"> + <option value="same">Same resolution for all modalities</option> + <option value="separate">Separate resolutions per modality</option> + </param> + <when value="same"> + <param argument="resolution" type="float" optional="true" label="Coarseness of the clustering" help="Higher values -> more clusters"/> + </when> + <when value="separate"> + <repeat name="modalities" title="Modalities" min="2" default="2"> + <param name="mod_name" type="text" label="Modality name" optional="true"> + <expand macro="sanitize_string" /> + </param> + <param name="resolution" type="float" label="Resolution for the above modality" help="Higher values -> more clusters"/> + </repeat> + </when> + </conditional> + </xml> + <xml name="param_weight"> + <conditional name="weights"> + <param name="type" type="select" label="Same or separate weights for each modality?"> + <option value="same">Same weight for all modalities</option> + <option value="separate">Separate weight per modality</option> + </param> + <when value="same"> + <param argument="mod_weights" type="float" optional="true" label="Weight each modality controlling its contribution" help="Higher values -> more important"/> + </when> + <when value="separate"> + <repeat name="modalities" title="Modalities" min="2" default="2"> + <param name="mod_name" type="text" label="Modality name" optional="true"> + <expand macro="sanitize_string" /> + </param> + <param name="mod_weights" type="float" label="Weight for the above modality" help="Higher values -> more important"/> + </repeat> + </when> + </conditional> + </xml> + <xml name="param_random_state" tokens="seed"> + <param argument="random_state" type="integer" value="@SEED@" optional="true" label="Random seed for the optimization"/> + </xml> + <xml name="param_key_added" tokens="key_added"> + <param argument="key_added" type="text" value="@KEY_ADDED@" label="mdata.obs key where cluster labels to be added"> + <expand macro="sanitize_string" /> + </param> + </xml> + <xml name="param_neighbors_key"> + <param argument="neighbors_key" type="text" optional="true" label="Use neighbors connectivities as adjacency" + help="If not specified, look for .obsp['connectivities'] in each modality. + If specified, look for .obsp[.uns[neighbors_key]['connectivities_key']] in each modality for connectivities."> + <expand macro="sanitize_string" /> + </param> + </xml> + <xml name="param_directed"> + <param argument="directed" type="boolean" truevalue="True" falsevalue="False" checked="true" label="Treat the graph as directed"/> + </xml> + <xml name="param_key_added_common"> + <param argument="key_added" type="text" optional="true" label="Key to be added to store neighbors, distances and connectivities data" + help="If not specified, the multimodal neighbors data is stored in .uns['neighbors'], distances and connectivities are stored in .obsp['distances'] and .obsp['connectivities'], respectively. + If specified, the neighbors data is added to .uns[key_added], distances are stored in .obsp[key_added + '_distances'] and connectivities in .obsp[key_added + '_connectivities']."> + <expand macro="sanitize_string" /> + </param> + </xml> + <xml name="param_eps" tokens="eps_value"> + <param argument="eps" type="float" value="@EPS_VALUE@" label="Small number to avoid numerical errors"/> + </xml> + <xml name="param_use_raw" tokens="label,checked"> + <param argument="use_raw" type="boolean" truevalue="True" falsevalue="False" checked="@CHECKED@" label="@LABEL@" /> + </xml> + <xml name="param_keys"> + <conditional name="key_variables"> + <param name="type" type="select" label="Keys to plot"> + <option value="var_names">All variables in '.var_names'</option> + <option value="obs">All fields in '.obs'</option> + <option value="custom">Subset of variables in 'adata.var_names' or fields of '.obs'</option> + </param> + <when value="var_names"/> + <when value="obs"/> + <when value="custom"> + <param argument="keys" type="text" value="" label="Keys to plot" help="One or a list of comma-separated index or key from '.var_names' or fields of '.obs'"> + <expand macro="sanitize_query" /> + </param> + </when> + </conditional> + </xml> + <xml name="param_color"> + <param argument="color" type="text" optional="true" label="Keys for variables or annotations of observations (.obs columns)" help="Can be from any modality."> + <expand macro="sanitize_query" /> + </param> + </xml> + <xml name="params_embedding"> + <expand macro="param_color"/> + <expand macro="param_use_raw" label="Use raw slot of AnnData as input values" checked="true"/> + <param argument="layer" type="text" optional="true" label="Name of the layer in the modality where a feature (from color) is derived from" + help="If a valid layer is provided, this takes precedence over use_raw=True"> + <expand macro="sanitize_query" /> + </param> + </xml> +</macros>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/preprocess_muon.xml Wed Feb 05 10:53:25 2025 +0000 @@ -0,0 +1,322 @@ +<tool id="preprocess_muon" name="muon filter and normalize" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@"> + <macros> + <import>macros.xml</import> + </macros> + <expand macro="requirements"/> + <expand macro="version_command"/> + <command detect_errors="exit_code"><![CDATA[ +@COPY_MUDATA@ +@CMD@ + ]]></command> + <configfiles> + <configfile name="script_file"><![CDATA[ +@CMD_imports@ +@CMD_read_inputs@ + +#if $method.method == 'pp.intersect_obs' +mu.pp.intersect_obs( + mdata +) +## Update the features. Only union features of the modalities are considered +mdata.update_var() + + +#else if $method.method == 'pp.l2norm' +mu.pp.l2norm( + mdata, + #if $method.mod + mod='$method.mod', + #end if + #if $method.rep + rep='$method.rep', + #end if + n_pcs=$method.n_pcs, + copy=False +) + +#else if $method.method == 'pp.neighbors' +mu.pp.neighbors( + mdata, + #if str($method.n_neighbors) + n_neighbors=$method.n_neighbors, + #end if + n_bandwidth_neighbors=$method.n_bandwidth_neighbors, + n_multineighbors=$method.n_multineighbors, + @CMD_neighbor_keys@ + metric='$method.metric', + #if $method.key_added + key_added='$method.key_added', + #end if + weight_key='$method.weight_key', + add_weights_to_modalities=$method.add_weights_to_modalities, + eps=$method.eps, + random_state=$method.random_state, + copy=False +) + +#else if $method.method == 'pp.sample_obs' +mu.pp.sample_obs( + mdata, + frac=$method.frac, + #if $method.groupby + groupby='$method.groupby', + #end if + #if str($method.min_n) + min_n=$method.min_n + #end if +) +#end if + +@CMD_mudata_write_outputs@ +]]></configfile> + </configfiles> + <inputs> + <expand macro="inputs_mudata"/> + <conditional name="method"> + <param name="method" type="select" label="Method used for plotting"> + <option value="pp.intersect_obs">Subset: Subset observations present only in all modalities, using 'muon.pp.intersect_obs'</option> + <option value="pp.l2norm">Normalize: Normalize observations to unit L2 norm, using 'muon.pp.l2norm'</option> + <option value="pp.neighbors">Search: Multimodal nearest neighbor search, using 'muon.pp.neighbors'</option> + <option value="pp.sample_obs">Return an object with some of the observations (subsampling). 'muon.pp.sample_obs'</option> + </param> + <when value="pp.intersect_obs"/> + <when value="pp.l2norm"> + <param argument="mod" type="text" optional="true" label="Names of the modalities to normalize" help="Leave empty to use all modalities"> + <expand macro="sanitize_string" /> + </param> + <param argument="rep" type="text" optional="true" label="The representation to normalize." help="X or any key for .obsm is valid, for all modalities"> + <expand macro="sanitize_query" /> + </param> + <param argument="n_pcs" type="integer" min="0" value="0" label="The number of principal components to use." help="This affects the result only if a PCA representation is being normalized"/> + </when> + <when value="pp.neighbors"> + <param argument="n_neighbors" type="integer" optional="true" label="Number of nearest neighbors to find" + help="If not set, arithmetic mean of per-modality neighbors will be used"/> + <param argument="n_bandwidth_neighbors" type="integer" value="20" label="Number of nearest neighbors to use for bandwidth selection"/> + <param argument="n_multineighbors" type="integer" value="200" label="Number of nearest neighbors in each modality to consider as candidates for multimodal nearest neighbors" + help="Only points in the union of per-modality nearest neighbors are candidates for multimodal nearest neighbors. + This will use the same metric that was used for the nearest neighbor search in the respective modality."/> + <expand macro="param_neighbor_keys"/> + <param argument="metric" type="select" label="Distance measure to use" help="This will only be used in the final step to search for nearest neighbors in the set of candidates."> + <option value="euclidean" selected="true">euclidean</option> + <option value="braycurtis">braycurtis</option> + <option value="canberra">canberra</option> + <option value="chebyshev">chebyshev</option> + <option value="cityblock">cityblock</option> + <option value="correlation">correlation</option> + <option value="cosine">cosine</option> + <option value="dice">dice</option> + <option value="hamming">hamming</option> + <option value="jaccard">jaccard</option> + <option value="jensenshannon">jensenshannon</option> + <option value="kulsinski">kulsinski</option> + <option value="mahalanobis">mahalanobis</option> + <option value="matching">matching</option> + <option value="minkowski">minkowski</option> + <option value="rogerstanimoto">rogerstanimoto</option> + <option value="russellrao">russellrao</option> + <option value="seuclidean">seuclidean</option> + <option value="sokalmichener">sokalmichener</option> + <option value="sokalsneath">sokalsneath</option> + <option value="sqeuclidean">sqeuclidean</option> + <option value="wminkowski">wminkowski</option> + <option value="yule">yule</option> + </param> + <expand macro="param_key_added_common"/> + <param argument="weight_key" type="text" value="mod_weight" label="Weight key to add to each modality’s .obs or to mdata.obs"> + <expand macro="sanitize_query" /> + </param> + <param argument="add_weights_to_modalities" type="boolean" truevalue="True" falsevalue="False" checked="false" label="If to add weights to individual modalities" help="By default, the weights will be added to mdata.obs"/> + <expand macro="param_eps" eps_value="0.0001"/> + <expand macro="param_random_state" seed="42"/> + </when> + <when value="pp.sample_obs"> + <param argument="frac" type="float" min="0" max="1" value="0.1" label="A fraction of observations to return"/> + <param argument="groupby" type="text" optional="true" label="Categorical column in .obs that is used for prior grouping before sampling observations"> + <expand macro="sanitize_query"/> + </param> + <param argument="min_n" type="integer" min="0" optional="true" label="Return min_n observations if fraction frac of observations is below min_n" + help="When groupby is not None, min_n is applied per group."/> + </when> + </conditional> + <expand macro="inputs_common_advanced" /> + </inputs> + <outputs> + <expand macro="muon_outputs"/> + </outputs> + <tests> + <test expect_num_outputs="2"> + <!-- test1: intersect_obs --> + <param name="mdata" ftype="h5ad" location="https://zenodo.org/records/12570984/files/pbmc3k_chr21.h5mu"/> + <param name="method" value="pp.intersect_obs"/> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pp.intersect_obs"/> + </assert_contents> + </output> + <assert_stdout> + <has_text_matching expression="179 × 490"/> + <has_text_matching expression="179 x 178"/> + <has_text_matching expression="179 x 312"/> + </assert_stdout> + <output name="mudata_out" ftype="h5ad"> + <assert_contents> + <has_h5_keys keys="mod/rna"/> + <has_h5_keys keys="mod/atac"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="2"> + <!-- test2: l2norm --> + <param name="mdata" ftype="h5ad" location="https://zenodo.org/records/12570984/files/pbmc3k_chr21.h5mu"/> + <param name="method" value="pp.l2norm"/> + <param name="n_pcs" value="5"/> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pp.l2norm"/> + <has_text_matching expression="copy=False"/> + <has_text_matching expression="n_pcs=5"/> + </assert_contents> + </output> + <assert_stdout> + <has_text_matching expression="179 × 490"/> + <has_text_matching expression="179 x 178"/> + <has_text_matching expression="179 x 312"/> + </assert_stdout> + <output name="mudata_out" ftype="h5ad"> + <assert_contents> + <has_h5_keys keys="mod/rna"/> + <has_h5_keys keys="mod/atac"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="2"> + <!-- test3: neighbors --> + <param name="mdata" ftype="h5ad" location="https://zenodo.org/records/12570984/files/pbmc3k_chr21_pp.neighbors_in.h5mu"/> + <param name="method" value="pp.neighbors"/> + <param name="n_neighbors" value="2"/> + <param name="n_bandwidth_neighbors" value="3"/> + <param name="n_multineighbors" value="5"/> + <conditional name="n_keys"> + <param name="type" value="separate"/> + <repeat name="modalities"> + <param name="mod_name" value="rna"/> + <param name="neighbor_keys" value="neighbors"/> + </repeat> + <repeat name="modalities"> + <param name="mod_name" value="atac"/> + <param name="neighbor_keys" value="neighbors"/> + </repeat> + </conditional> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pp.neighbors"/> + <has_text_matching expression="copy=False"/> + <has_text_matching expression="n_neighbors=2"/> + <has_text_matching expression="n_bandwidth_neighbors=3"/> + <has_text_matching expression="n_multineighbors=5"/> + <has_text_matching expression="metric='euclidean'"/> + <has_text_matching expression="weight_key='mod_weight'"/> + <has_text_matching expression="add_weights_to_modalities=False"/> + <has_text_matching expression="eps=0.0001"/> + <has_text_matching expression="random_state=42"/> + </assert_contents> + </output> + <assert_stdout> + <has_text_matching expression="2711 × 1781"/> + <has_text_matching expression="2711 x 555"/> + <has_text_matching expression="2711 x 1226"/> + </assert_stdout> + <output name="mudata_out" ftype="h5ad"> + <assert_contents> + <has_h5_keys keys="mod/rna"/> + <has_h5_keys keys="mod/atac"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="2"> + <!-- test4: sample_obs --> + <param name="mdata" ftype="h5ad" location="https://zenodo.org/records/12570984/files/pbmc3k_chr21.h5mu"/> + <param name="method" value="pp.sample_obs"/> + <param name="frac" value="0.5"/> + <param name="min_n" value="10"/> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pp.sample_obs"/> + <has_text_matching expression="frac=0.5"/> + <has_text_matching expression="min_n=10"/> + </assert_contents> + </output> + <assert_stdout> + <has_text_matching expression="179 × 490"/> + <has_text_matching expression="179 x 178"/> + <has_text_matching expression="179 x 312"/> + </assert_stdout> + <output name="mudata_out" ftype="h5ad"> + <assert_contents> + <has_h5_keys keys="mod/rna"/> + <has_h5_keys keys="mod/atac"/> + </assert_contents> + </output> + </test> + </tests> + <help><![CDATA[ +Filter: Filter observations (samples or cells) in-place using any column in .obs or in .X ('muon.pp.filter_obs') +================================================================================================================ + + Filter observations (samples or cells) in-place using any column in .obs or in .X. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pp.filter_obs.html#muon.pp.filter_obs>`__ + +Filter: Filter variables (features) ('muon.pp.filter_var') +========================================================== + + Filter variables (features, e.g. genes) in-place using any column in .var or row in .X. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pp.filter_var.html#muon.pp.filter_var>`__ + +Subset: Subset observations (samples or cells) in-place taking observations present only in all modalities ('muon.pp.intersect_obs') +==================================================================================================================================== + + Subset observations (samples or cells) in-place taking observations present only in all modalities. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pp.intersect_obs.html#muon.pp.intersect_obs>`__ + +Normalize: Normalize observations to unit L2 norm ('muon.pp.l2norm') +==================================================================== + + Normalize observations to unit L2 norm. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pp.l2norm.html#muon.pp.l2norm>`__ + +Search: Multimodal nearest neighbor search ('muon.pp.neighbors') +================================================================ + + Multimodal nearest neighbor search by implementing the multimodal nearest neighbor method of Hao et al. and Swanson et al. + The neighbor search efficiency on this heavily relies on UMAP. In particular, you may want to decrease + n_multineighbors for large data set to avoid excessive peak memory use. To achieve results as close as possible + to the Seurat implementation, observations must be normalized to unit L2 norm prior to running per-modality + nearest-neighbor search. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pp.neighbors.html#muon.pp.neighbors>`__ + + ]]></help> + <expand macro="citations"/> +</tool> \ No newline at end of file