Mercurial > repos > iuc > snapatac2_plotting
changeset 0:0cfd2d2f7351 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snapatac2 commit be132b56781bede5dc6e020aa80ca315546666cd
author | iuc |
---|---|
date | Thu, 16 May 2024 13:15:05 +0000 |
parents | |
children | fecf9664c885 |
files | macros.xml plotting.xml |
diffstat | 2 files changed, 416 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/macros.xml Thu May 16 13:15:05 2024 +0000 @@ -0,0 +1,187 @@ +<macros> + <token name="@TOOL_VERSION@">2.5.3</token> + <token name="@VERSION_SUFFIX@">0</token> + <token name="@PROFILE@">23.0</token> + <xml name="requirements"> + <requirement type="package" version="@TOOL_VERSION@">snapatac2</requirement> + <requirement type="package" version="5.18.0">plotly</requirement> + <requirement type="package" version="0.2.1">python-kaleido</requirement> + <requirement type="package" version="0.19.19">polars</requirement> + <requirement type="package" version="14.0.1">pyarrow</requirement> + <requirement type="package" version="0.11.3">python-igraph</requirement> + <requirement type="package" version="0.8.33">hdbscan</requirement> + <requirement type="package" version="0.0.9">harmonypy</requirement> + <requirement type="package" version="1.7.4">scanorama</requirement> + <yield /> + </xml> + + <token name="@PREP_ADATA@"><![CDATA[ + cp '$method.adata' 'anndata.h5ad' && + ]]> + </token> + + <token name="@CMD@"><![CDATA[ + cat '$script_file' > '$hidden_output' && + python '$script_file' >> '$hidden_output' && + touch 'anndata_info.txt' && + cat 'anndata_info.txt' @CMD_prettify_stdout@ + ]]> + </token> + + <token name="@CMD_prettify_stdout@"><![CDATA[ | sed -r '1 s|AnnData 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="@CMD_imports@"><![CDATA[ +import snapatac2 as sa +import os + ]]> + </token> + <xml name="sanitize_query" token_validinitial="string.printable"> + <sanitizer> + <valid initial="@VALIDINITIAL@"> + <remove value="'" /> + </valid> + </sanitizer> + </xml> + + <xml name="inputs_anndata"> + <param name="adata" type="data" format="h5ad" label="Annotated data matrix"/> + </xml> + + <token name="@CMD_read_inputs@"><![CDATA[ + +adata = sa.read('anndata.h5ad', backed = None) +]]> + </token> + + <xml name="dimentions_plot"> + <param argument="width" type="integer" value="500" label="Width of the plot"/> + <param argument="height" type="integer" value="400" label="Height of the plot"/> + </xml> + + <xml name="param_groupby"> + <param argument="groupby" type="text" label="The key of the observation grouping to consider"> + <expand macro="sanitize_query" /> + </param> + </xml> + + <xml name="out_file"> + <param name="out_file" type="select" optional="true" label="Type of output file"> + <option value="png" selected="true">PNG</option> + <option value="svg">SVG</option> + <option value="pdf">PDF</option> + </param> + </xml> + <token name="@CMD_anndata_write_outputs@"><![CDATA[ +adata.write('anndata.h5ad') +with open('anndata_info.txt','w', encoding='utf-8') as ainfo: + print(adata, file=ainfo) +]]> + </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="params_render_plot"> + <param argument="width" type="integer" value="600" label="Width of the plot"/> + <param argument="height" type="integer" value="400" label="Height of the plot"/> + <expand macro="out_file"/> + </xml> + <xml name="param_shift"> + <param argument="shift_left" type="integer" value="4" label="Insertion site correction for the left end" help="Note this has no effect on single-end reads"/> + <param argument="shift_right" type="integer" value="-5" label="Insertion site correction for the right end" help="Note this has no effect on single-end reads"/> + </xml> + <xml name="param_chunk_size" tokens="size"> + <param argument="chunk_size" type="integer" value="@SIZE@" label="chunk size"/> + </xml> + <xml name="min_max_frag_size"> + <param argument="min_frag_size" type="integer" optional="true" value="" label="Minimum fragment size to include"/> + <param argument="max_frag_size" type="integer" optional="true" value="" label="Maximum fragment size to include"/> + </xml> + <xml name="params_data_integration"> + <param argument="use_rep" type="text" value="X_spectral" label="The key for the matrix"/> + <param argument="use_dims" type="text" optional="true" value="" label="The dimensions used for computation"> + <expand macro="sanitize_query"/> + </param> + <param argument="groupby" type="text" optional="true" value="" label="The key of the observation grouping to consider"> + <expand macro="sanitize_query" /> + </param> + <param argument="key_added" type="text" optional="true" value="" label="If specified, add the result to adata.obsm with this key"/> + </xml> + <xml name="param_n_comps"> +s <param argument="n_comps" type="integer" value="30" label="Number of dimensions to keep" help="The result is insensitive to this parameter when `weighted_by_sd` is set, as long as it is large enough, e.g. 30."/> + </xml> + <xml name="param_random_state"> + <param argument="random_state" type="integer" value="0" label="Seed of the random state generator"/> + </xml> + <xml name="param_key_added" tokens="key_added"> + <param argument="key_added" type="text" value="@KEY_ADDED@" label="`adata.obs` key under which t add cluster labels"/> + </xml> + <xml name="param_use_rep"> + <param argument="use_rep" type="text" value="X_spectral" label="Use the indicated representation in `.obsm`"/> + </xml> + <xml name="genome_fasta"> + <param argument="genome_fasta" type="text" label="A fasta file containing the genome sequences or a Genome object"/> + </xml> + <xml name="background"> + <param argument="background" type="text" optional="true" value="" label="A list of regions to be used as the background"> + <expand macro="sanitize_query"/> + </param> + </xml> + <xml name="mat"> + <param argument="peak_mat" type="data" format="h5ad" optional="true" label="AnnData or AnnDataSet object storing the cell by peak count matrix"/> + <param argument="gene_mat" type="data" format="h5ad" optional="true" label="AnnData or AnnDataSet object storing the cell by gene count matrix"/> + </xml> + <xml name="param_network"> + <param argument="network" type="text" label="network"/> + </xml> + <xml name="param_n_iterations"> + <param argument="n_iterations" type="integer" value="-1" label="How many iterations of the Leiden clustering algorithm to perform" + help="Positive values above 2 define the total number of iterations to perform, -1 has the algorithm run until it reaches its optimal clustering."/> + </xml> + + <xml name="citations"> + <citations> + <citation type="doi">10.1038/s41592-023-02139-9</citation> + </citations> + </xml> + <xml name="render_plot_test"> + <param name="width" value="650"/> + <param name="height" value="450"/> + </xml> + <xml name="render_plot_matching_text"> + <has_text_matching expression="width = 650"/> + <has_text_matching expression="height = 450"/> + </xml> + <xml name="param_counting_strategy"> + <param argument="counting_strategy" type="select" label="he strategy to compute feature counts"> + <option value="fragment">fragment</option> + <option value="insertion" selected="true">insertion</option> + <option value="paired-insertion">paired-insertion</option> + </param> + </xml> + + <token name="@CMD_params_data_integration@"><![CDATA[ +use_rep = '$method.use_rep', +#if $method.use_dims != '' +#set $dims = ([x.strip() for x in str($method.use_dims).split(',')]) +use_dims=$dims, +#end if +#if $method.groupby != '' +#set $groupby = ([x.strip() for x in str($method.groupby).split(',')]) +groupby=$groupby, +#end if +#if $method.key_added != '' +key_added = '$method.key_added', +#end if + ]]> + </token> + + <token name="@CMD_params_render_plot@"><![CDATA[ + width = $method.width, + height = $method.height, + out_file = 'plot.$method.out_file', + ]]> + </token> +</macros>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plotting.xml Thu May 16 13:15:05 2024 +0000 @@ -0,0 +1,229 @@ +<tool id="snapatac2_plotting" name="SnapATAC2 Plotting" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@"> + <macros> + <import>macros.xml</import> + </macros> + <requirements> + <expand macro="requirements"/> + </requirements> + <command detect_errors="exit_code"><![CDATA[ +@PREP_ADATA@ +@CMD@ + ]]></command> + <configfiles> + <configfile name="script_file"><![CDATA[ +@CMD_imports@ +@CMD_read_inputs@ + +#if $method.method == 'pl.frag_size_distr' + #if $method.log_scale +fig = sa.pl.frag_size_distr(adata, show=False) +fig.update_yaxes(type="log") +sa.pl.render_plot(fig, @CMD_params_render_plot@) + #else +sa.pl.frag_size_distr(adata, @CMD_params_render_plot@) + #end if +#else if $method.method == 'pl.tsse' +sa.pl.tsse( + adata, + min_fragment = $method.min_fragment, + @CMD_params_render_plot@ +) +#else if $method.method == 'pl.umap' +sa.pl.umap( + adata, + color = '$method.color', + use_rep = '$method.use_rep', + marker_size = $method.marker_size, + marker_opacity = $method.marker_opacity, + sample_size = $method.sample_size, + @CMD_params_render_plot@ +) +#else if $method.method == 'pl.regions' +sa.pl.regions( + adata, + groupby = '$method.groupby', + peaks = '$method.peaks', + @CMD_params_render_plot@ +) +#else if $method.method == 'pl.spectral_eigenvalues' +sa.pl.spectral_eigenvalues( + adata, + @CMD_params_render_plot@ +) +#end if + ]]></configfile> + </configfiles> + <inputs> + <conditional name="method"> + <param name="method" type="select" label="Method used for plotting"> + <option value="pl.frag_size_distr">Plot fragment size distribution, using 'pl.frag_size_distr'</option> + <option value="pl.tsse">Plot the TSS enrichment vs. number of fragments density figure, using 'pl.tsse'</option> + <option value="pl.umap">Plot the UMAP embedding, using 'pl.umap'</option> + <option value="pl.spectral_eigenvalues">Plot the eigenvalues of spectral embedding, using 'pl.spectral_eigenvalues'</option> + </param> + <when value="pl.frag_size_distr"> + <expand macro="inputs_anndata"/> + <param name="log_scale" type="boolean" checked="False" label="Change the y-axis (fragment counts) to log scale"/> + <expand macro="params_render_plot"/> + </when> + <when value="pl.tsse"> + <expand macro="inputs_anndata"/> + <param argument="min_fragment" type="integer" value="500" label="Minimum number of unique fragments"/> + <expand macro="params_render_plot"/> + </when> + <when value="pl.umap"> + <expand macro="inputs_anndata"/> + <param argument="color" type="text" value="" optional="true" label="Color"/> + <param argument="use_rep" type="text" value="X_umap" label="Use the indicated representation in .obsm"/> + <param argument="marker_size" type="float" value="" optional="true" label="Size of the dots"/> + <param argument="marker_opacity" type="float" value="1" label="Opactiy of the dots"/> + <param argument="sample_size" type="integer" value="" optional="true" label="Number of cells to use"/> + <expand macro="params_render_plot"/> + </when> + <when value="pl.spectral_eigenvalues"> + <expand macro="inputs_anndata"/> + <expand macro="params_render_plot"/> + </when> + </conditional> + <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>method['out_file'] == '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>method['out_file'] == '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>method['out_file'] == '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"> + <!-- pl.frag_size_distr --> + <conditional name="method"> + <param name="method" value="pl.frag_size_distr"/> + <param name="adata" location="https://zenodo.org/records/11199963/files/pp.import_data.pbmc_500_chr21.h5ad"/> + <param name="log_scale" value="True"/> + <param name="out_file" value="pdf"/> + <expand macro="render_plot_test"/> + </conditional> + <section name="advanced_common"> + <param name="show_log" value="true"/> + </section> + <output name="out_pdf" location="https://zenodo.org/records/11199963/files/pl.frag_size_distr.pdf" ftype="pdf" compare="sim_size" delta_frac="0.1"/> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="sa.pl.frag_size_distr"/> + <has_text_matching expression="fig.update_yaxes"/> + <expand macro="render_plot_matching_text"/> + </assert_contents> + </output> + </test> + <test expect_num_outputs="2"> + <!-- pl.tsse --> + <conditional name="method"> + <param name="method" value="pl.tsse"/> + <param name="adata" location="https://zenodo.org/records/11199963/files/metrics.tsse.pbmc_500_chr21.h5ad"/> + <param name="min_fragment" value="500"/> + <param name="out_file" value="png"/> + <expand macro="render_plot_test"/> + </conditional> + <section name="advanced_common"> + <param name="show_log" value="true"/> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="sa.pl.tsse"/> + <has_text_matching expression="min_fragment = 500"/> + <expand macro="render_plot_matching_text"/> + </assert_contents> + </output> + <output name="out_png" location="https://zenodo.org/records/11199963/files/pl.tsse.png" ftype="png" compare="sim_size" delta_frac="0.1"/> + </test> + <test expect_num_outputs="2"> + <!-- pl.umap --> + <conditional name="method"> + <param name="method" value="pl.umap"/> + <param name="adata" ftype="h5ad" location="https://zenodo.org/records/11199963/files/tl.leiden.pbmc_500_chr21.h5ad"/> + <param name="color" value="leiden"/> + <param name="use_rep" value="X_umap"/> + <param name="marker_size" value="1"/> + <param name="marker_opacity" value="0.8"/> + <param name="sample_size" value="100"/> + <expand macro="render_plot_test"/> + <param name="out_file" value="svg"/> + </conditional> + <section name="advanced_common"> + <param name="show_log" value="true"/> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="sa.pl.umap"/> + <has_text_matching expression="color = 'leiden'"/> + <has_text_matching expression="use_rep = 'X_umap'"/> + <has_text_matching expression="marker_size = 1"/> + <has_text_matching expression="marker_opacity = 0.8"/> + <has_text_matching expression="sample_size = 100"/> + <expand macro="render_plot_matching_text"/> + </assert_contents> + </output> + <output name="out_svg" location="https://zenodo.org/records/11199963/files/pl.umap.svg" ftype="svg" compare="sim_size" delta_frac="0.1"/> + </test> + <test expect_num_outputs="2"> + <!-- pl.spectral_eigenvalues --> + <conditional name="method"> + <param name="method" value="pl.spectral_eigenvalues"/> + <param name="adata" ftype="h5ad" location="https://zenodo.org/records/11199963/files/tl.spectral.pbmc_500_chr21.h5ad"/> + <expand macro="render_plot_test"/> + <param name="out_file" value="pdf"/> + </conditional> + <section name="advanced_common"> + <param name="show_log" value="true"/> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="sa.pl.spectral_eigenvalues"/> + <expand macro="render_plot_matching_text"/> + </assert_contents> + </output> + <output name="out_pdf" location="https://zenodo.org/records/11199963/files/pl.spectral_eigenvalues.pdf" ftype="pdf" compare="sim_size" delta_frac="0.1"/> + </test> + </tests> + <help><![CDATA[ +Plot fragment size distribution, using `pl.frag_size_distr` +=========================================================== + +Plot fragment size distribution. + +`metrics.frag_size_distr` must be ran first in order to use this function. + +Plot the TSS enrichment vs. number of fragments density figure, using `pl.tsse` +=============================================================================== + +Plot the TSS enrichment vs. number of fragments density figure. + +More details on the `SnapATAC2 documentation +<https://kzhang.org/SnapATAC2/api/_autosummary/snapatac2.pl.tsse.html>`__ + +Plot the UMAP embedding, using `pl.umap` +======================================== + +Plot the UMAP embedding. + +More details on the `SnapATAC2 documentation +<https://kzhang.org/SnapATAC2/api/_autosummary/snapatac2.pl.umap.html>`__ + +Plot the eigenvalues of spectral embedding, using `pl.spectral_eigenvalues` +=========================================================================== + +Plot the eigenvalues of spectral embedding. + +More details on the `SnapATAC2 documentation +<https://kzhang.org/SnapATAC2/api/_autosummary/snapatac2.pl.spectral_eigenvalues.html>`__ + ]]></help> + <expand macro="citations"/> +</tool>