Mercurial > repos > iuc > plot_muon
changeset 0:36f2cd69d20e 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:37 +0000 |
parents | |
children | 49bee59efec0 |
files | macros.xml plot_muon.xml |
diffstat | 2 files changed, 535 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:37 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/plot_muon.xml Wed Feb 05 10:53:37 2025 +0000 @@ -0,0 +1,271 @@ +<tool id="plot_muon" name="muon plot" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@"> + <macros> + <import>macros.xml</import> + </macros> + <expand macro="bio_tools"/> + <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 == "pl.embedding" +plot = mu.pl.embedding( + mdata, + basis='$method.basis', + @CMD_params_embedding@ + return_fig=True +) +plot.savefig("plot.$plot_ext") + +#else if $method.method == "pl.histogram" +plot = mu.pl.histogram( + mdata, + #if $method.key_variables.type == "var_names" + #set $key_list = mdata.var_names + #else if $method.key_variables.type == "obs" + #set $key_list = mdata.obs.select_dtypes(exclude=['category']).columns + #else if $method.key_variables.type == "custom" + #set $key_list=([x.strip() for x in str($method.key_variables.keys).split(',')]) + #end if + keys=$key_list, + #if $method.groupby + groupby='$method.groupby', + #end if + save='plot.$plot_ext' +) +os.rename(os.path.join('figures', 'histogram_plot.$plot_ext'), 'plot.$plot_ext') + +#else if $method.method == "pl.mofa" +plot = mu.pl.mofa( + mdata, + @CMD_params_embedding@ + return_fig=True +) +plot.savefig("plot.$plot_ext") + +#else if $method.method == "pl.mofa_loadings" +plot = mu.pl.mofa_loadings( + mdata, + #if $method.factors + factors='$method.factors', + #end if + include_lowest=$method.include_lowest, + #if str($method.n_points) + n_points=$method.n_points, + #end if + save='plot.$plot_ext' +) +os.rename(os.path.join('figures', 'mofa_loadings_plot.$plot_ext'), 'plot.$plot_ext') + +#else if $method.method == "pl.umap" +plot = mu.pl.umap( + mdata, + @CMD_params_embedding@ + return_fig=True +) +plot.savefig("plot.$plot_ext") + +#end if + +]]></configfile> + </configfiles> + <inputs> + <expand macro="inputs_mudata"/> + <conditional name="method"> + <param name="method" type="select" label="Method used for plotting"> + <option value="pl.embedding">Scatter: Scatter plot along observations (.obs column), using 'muon.pl.embedding'</option> + <option value="pl.histogram">Histogram: Plot Histogram of Fragment lengths within specified region, using 'muon.pl.histogram'</option> + <option value="pl.mofa">Scatter: Scatter plot in MOFA factor coordinates, using 'muon.pl.mofa'</option> + <option value="pl.mofa_loadings">Ranking: Rank genes according to contributions to MOFA factors, using 'muon.pl.mofa_loadings'</option> + <option value="pl.umap">Scatter: UMAP scatter plot, using 'muon.pl.umap'</option> + </param> + <when value="pl.embedding"> + <param argument="basis" type="text" value="X_mofa" label="Name of the obsm basis to use" help="can also be a basis inside any modality, e.g. 'rna:X_pca'"> + <expand macro="sanitize_query" /> + </param> + <expand macro="params_embedding"/> + </when> + <when value="pl.histogram"> + <expand macro="param_keys"/> + <param argument="groupby" type="text" optional="true" label="Column name(s) of .obs slot of the AnnData object according to which the plot is split"> + <expand macro="sanitize_query" /> + </param> + </when> + <when value="pl.mofa"> + <expand macro="params_embedding"/> + </when> + <when value="pl.mofa_loadings"> + <param argument="factors" type="text" optional="true" label="Comma separated list of factors" help="For example, '1,2,3' means [1, 2, 3], first, second, third factors"> + <expand macro="sanitize_query" /> + </param> + <param argument="include_lowest" type="boolean" truevalue="True" falsevalue="False" checked="true" label="Whether to show the variables with both highest and lowest loadings"/> + <param argument="n_points" type="integer" optional="true" label="Number of variables to plot for each factor"/> + </when> + <when value="pl.umap"> + <expand macro="params_embedding"/> + </when> + </conditional> + <param name="plot_ext" type="select" label="Type of output plot"> + <option value="png" selected="true">PNG</option> + <option value="svg">SVG</option> + <option value="pdf">PDF</option> + </param> + <expand macro="inputs_common_advanced" /> + </inputs> + <outputs> + <data name="out_png" format="png" from_work_dir="plot.png" label="PNG plot from ${tool.name} (${method.method}) on ${on_string}"> + <filter>plot_ext == 'png'</filter> + </data> + <data name="out_pdf" format="pdf" from_work_dir="plot.pdf" label="PDF plot from ${tool.name} (${method.method}) on ${on_string}"> + <filter>plot_ext == 'pdf'</filter> + </data> + <data name="out_svg" format="svg" from_work_dir="plot.svg" label="SVG plot from ${tool.name} (${method.method}) on ${on_string}"> + <filter>plot_ext == 'svg'</filter> + </data> + <data name="hidden_output" format="txt" label="Log file" hidden="true" > + <filter>advanced_common['show_log']</filter> + </data> + </outputs> + <tests> + <test expect_num_outputs="2"> + <!-- test1: pl.embedding --> + <param name="mdata" location="https://zenodo.org/records/12570984/files/tl.mofa.h5mu"/> + <param name="method" value="pl.embedding"/> + <param name="basis" value="X_mofa"/> + <param name="color" value="rna:leiden,atac:leiden"/> + <param name="use_raw" value="False"/> + <param name="plot_ext" value="pdf"/> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pl.embedding"/> + <has_text_matching expression="basis='X_mofa'"/> + <has_text_matching expression="color=\['rna:leiden', 'atac:leiden'\]"/> + <has_text_matching expression="use_raw=False"/> + </assert_contents> + </output> + <output name="out_pdf" ftype="pdf" location="https://zenodo.org/records/12570984/files/pl.embedding.pdf" compare="sim_size" delta_frac="0.1"/> + </test> + <test expect_num_outputs="2"> + <!-- test2 pl.histogram --> + <param name="mdata" location="https://zenodo.org/records/12570984/files/tl.mofa.h5mu"/> + <param name="method" value="pl.histogram"/> + <conditional name="key_variables"> + <param name="type" value="custom"/> + <param name="keys" value="rna:n_genes_by_counts,rna:total_counts"/> + </conditional> + <param name="plot_ext" value="png"/> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pl.histogram"/> + <has_text_matching expression="keys=\['rna:n_genes_by_counts', 'rna:total_counts'\]"/> + </assert_contents> + </output> + <output name="out_png" ftype="png" location="https://zenodo.org/records/12570984/files/pl.histogram.png" compare="image_diff"/> + </test> + <test expect_num_outputs="2"> + <!-- test3: pl.mofa --> + <param name="mdata" location="https://zenodo.org/records/12570984/files/tl.mofa.h5mu"/> + <param name="method" value="pl.mofa"/> + <param name="use_raw" value="False"/> + <param name="plot_ext" value="svg"/> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pl.mofa"/> + <has_text_matching expression="use_raw=False"/> + </assert_contents> + </output> + <output name="out_svg" ftype="svg" location="https://zenodo.org/records/12570984/files/pl.mofa.svg" compare="sim_size" delta_frac="0.1"/> + </test> + <test expect_num_outputs="2"> + <!-- test4: pl.mofa_loadings --> + <param name="mdata" location="https://zenodo.org/records/12570984/files/tl.mofa.h5mu"/> + <param name="method" value="pl.mofa_loadings"/> + <param name="factors" value="1,2,3"/> + <param name="include_lowest" value="True"/> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pl.mofa_loadings"/> + <has_text_matching expression="factors='1,2,3'"/> + <has_text_matching expression="include_lowest=True"/> + </assert_contents> + </output> + <output name="out_png" ftype="png" location="https://zenodo.org/records/12570984/files/pl.mofa_loadings.png" compare="image_diff"/> + </test> + <test expect_num_outputs="2"> + <!-- test5: pl.umap --> + <param name="mdata" location="https://zenodo.org/records/12570984/files/tl.umap.h5mu"/> + <param name="method" value="pl.umap"/> + <param name="use_raw" value="False"/> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="mu.pl.umap"/> + <has_text_matching expression="use_raw=False"/> + </assert_contents> + </output> + <output name="out_png" ftype="png" location="https://zenodo.org/records/12570984/files/pl.umap.png" compare="image_diff"/> + </test> + </tests> + <help><![CDATA[ +Scatter: Scatter plot along observations (.obs column) ('muon.pl.embedding') +============================================================================ + + Produce a scatter plot in the define basis (.obs), which can also be a basis inside any modality. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pl.embedding.html#muon.pl.embedding>`__ + +Scatter: Scatter plot in MOFA factor coordinates ('muon.pl.mofa') +================================================================= + + Scatter plot in MOFA factors coordinates. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pl.mofa.html#muon.pl.mofa>`__ + +Scatter: UMAP scatter plot ('muon.pl.umap') +=========================================== + + UMAP Scatter plot. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pl.umap.html#muon.pl.umap>`__ + +Histogram: Plot Histogram of Fragment lengths within specified region ('muon.pl.histogram') +=========================================================================================== + + Plot Histogram of Fragment lengths within specified region. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pl.histogram.html#muon.pl.histogram>`__ + +Ranking: Rank genes according to contributions to MOFA factors ('muon.pl.mofa_loadings') +======================================================================================== + + Rank genes according to contributions to MOFA factors. + + More details on the `muon documentation + <https://muon.readthedocs.io/en/latest/api/generated/muon.pl.mofa_loadings.html#muon.pl.mofa_loadings>`__ + ]]></help> + <expand macro="citations"/> +</tool> \ No newline at end of file