Skip to content

Commit

Permalink
Scanpy plot new function (galaxyproject#6113)
Browse files Browse the repository at this point in the history
* update macros

* update plot.xml

* add test data

* Adding test data

* small change to filter.xml

* Update tools/scanpy/macros.xml

Co-authored-by: Björn Grüning <[email protected]>

---------

Co-authored-by: Björn Grüning <[email protected]>
  • Loading branch information
heylf and bgruening authored Aug 20, 2024
1 parent fce5664 commit 0ef475d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tools/scanpy/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ df.to_csv('marker.tsv', sep='\t', index=True)
<has_text_matching expression="adata, key, x, 1.0, 0.2, 'bulk_labels'"/>
</assert_contents>
</output>
<output name="anndata_out" file="cosg.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_1.h5ad" ftype="h5ad">
<output name="anndata_out" file="cosg.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_1_out.h5ad" ftype="h5ad">
<assert_contents>
<has_h5_keys keys="obs, var, uns" />
</assert_contents>
Expand Down
10 changes: 10 additions & 0 deletions tools/scanpy/macros.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ with open('anndata_info.txt','w', encoding='utf-8') as ainfo:
</when>
<when value="customfile">
<param argument="var_names" type="data" format="tabular" label="List of variables to plot" help="This should be a tsv where row = group (e.g. celltypes) and columns = variables."></param>
<param name="header" type="select" label="Header in the list of markers?">
<option value="included">Header incldued</option>
<option value="not_included">Header not included</option>
</param>
</when>
</conditional>
</xml>
Expand Down Expand Up @@ -471,6 +475,12 @@ with open('anndata_info.txt','w', encoding='utf-8') as ainfo:
<expand macro="param_groupby"/>
<expand macro="param_num_categories"/>
</xml>
<token name="@CMD_var_names_header_check@"><![CDATA[
header='infer'
#if $method.var_names.type == 'customfile' and $method.var_names.header == 'not_included' :
header=None
#end if
]]></token>
<token name="@CMD_params_inputs@"><![CDATA[
#if $method.var_names.type == 'custom'
#set $var_names = ([x.strip() for x in str($method.var_names.var_names).split(',')])
Expand Down
101 changes: 100 additions & 1 deletion tools/scanpy/plot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ sc.pl.scatter(
frameon=$method.plot.frameon)
#else if $method.method == 'pl.heatmap'
@CMD_var_names_header_check@
sc.pl.heatmap(
@CMD_param_plot_inputs@
#if $method.gene_symbols
Expand All @@ -89,6 +90,7 @@ sc.pl.heatmap(
@CMD_pl_heatmap@)
#else if $method.method == 'pl.dotplot'
@CMD_var_names_header_check@
sc.pl.dotplot(
@CMD_param_plot_inputs@
#if $method.gene_symbols
Expand Down Expand Up @@ -129,6 +131,7 @@ sc.pl.violin(
@CMD_params_seaborn_violinplot@)
#else if $method.method == 'pl.stacked_violin'
@CMD_var_names_header_check@
sc.pl.stacked_violin(
@CMD_param_plot_inputs@
#if $method.gene_symbols
Expand All @@ -139,6 +142,7 @@ sc.pl.stacked_violin(
@CMD_pl_stacked_violin@)
#else if $method.method == 'pl.matrixplot'
@CMD_var_names_header_check@
sc.pl.matrixplot(
@CMD_param_plot_inputs@
#if $method.gene_symbols
Expand Down Expand Up @@ -399,9 +403,26 @@ sc.pl.rank_genes_groups_violin(
scale='$method.violin_plot.scale')
#else if $method.method == 'pl.rank_genes_groups_dotplot'
@CMD_var_names_header_check@
sc.pl.rank_genes_groups_dotplot(
@CMD_param_plot_inputs@
@CMD_pl_rank_genes_groups_ext@
#if $method.var_names.type == 'custom'
#set $var_names = ([x.strip() for x in str($method.var_names.var_names).split(',')])
var_names=$var_names,
#else if $method.var_names.type == 'customfile'
var_names={key: [v for v in list(value.values()) if pd.notna(v)] for key, value in pd.read_csv('$var_names', sep='\t', index_col=0, header=header).to_dict(orient='index').items()},
#else
n_genes=$method.n_genes,
#end if
#if $method.groupby != ''
groupby='$method.groupby',
#end if
num_categories=$method.num_categories,
#if $method.key != ''
key='$method.key',
#end if
#if $method.gene_symbols
gene_symbols='$method.gene_symbols',
#end if
Expand Down Expand Up @@ -819,6 +840,7 @@ sc.pl.rank_genes_groups_stacked_violin(
</section>
</when>
<when value="pl.rank_genes_groups_dotplot">
<expand macro="params_inputs"/>
<expand macro="pl_rank_genes_groups_ext"/>
<expand macro="params_plots"/>
<expand macro="gene_symbols"/>
Expand Down Expand Up @@ -2033,6 +2055,9 @@ sc.pl.rank_genes_groups_stacked_violin(
<param name="method" value="pl.rank_genes_groups_dotplot"/>
<param name="gene_symbols" value="symbol"/>
<param name="n_genes" value="10"/>
<conditional name="var_names">
<param name="type" value="all"/>
</conditional>
<param name="log" value="False"/>
<param name="use_raw" value="False"/>
<param name="dendrogram" value="False"/>
Expand Down Expand Up @@ -2233,6 +2258,80 @@ sc.pl.rank_genes_groups_stacked_violin(
</output>
<output name="out_png" file="pl.scatter.pbmc68k_reduced.png" ftype="png" compare="sim_size"/>
</test>
<test expect_num_outputs="2">
<!-- test 35: pl.rank_genes_groups_dotplot with marker list -->
<param name="adata" value="cosg.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_1.h5ad" />
<param name="format" value="png"/>
<conditional name="method">
<param name="method" value="pl.rank_genes_groups_dotplot"/>
<conditional name="var_names">
<param name="type" value="customfile"/>
<param name="var_names" value="tl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_1.tsv"/>
</conditional>
<param name="groupby" value="bulk_labels"/>
<param name="log" value="False"/>
<param name="use_raw" value="False"/>
<param name="dendrogram" value="False"/>
<param name="color_map" value="viridis"/>
<section name="matplotlib_pyplot_scatter">
<param name="linewidths" value="0" />
<param name="edgecolors" value="face"/>
</section>
</conditional>
<section name="advanced_common">
<param name="show_log" value="true" />
</section>
<output name="hidden_output">
<assert_contents>
<has_text_matching expression="sc.pl.rank_genes_groups_dotplot"/>
<has_text_matching expression="groupby='bulk_labels'"/>
<has_text_matching expression="log=False"/>
<has_text_matching expression="use_raw=False"/>
<has_text_matching expression="dendrogram=False"/>
<has_text_matching expression="color_map='viridis'"/>
<has_text_matching expression="lw=0.0"/>
<has_text_matching expression="ec='face'"/>
</assert_contents>
</output>
<output name="out_png" file="pl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_1.png" ftype="png" compare="sim_size"/>
</test>
<test expect_num_outputs="2">
<!-- test 36: pl.rank_genes_groups_dotplot with marker list -->
<param name="adata" value="cosg.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_1.h5ad" />
<param name="format" value="png"/>
<conditional name="method">
<param name="method" value="pl.rank_genes_groups_dotplot"/>
<conditional name="var_names">
<param name="type" value="customfile"/>
<param name="var_names" value="tl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_filtered_1.tsv"/>
</conditional>
<param name="groupby" value="bulk_labels"/>
<param name="log" value="False"/>
<param name="use_raw" value="False"/>
<param name="dendrogram" value="False"/>
<param name="color_map" value="viridis"/>
<section name="matplotlib_pyplot_scatter">
<param name="linewidths" value="0" />
<param name="edgecolors" value="face"/>
</section>
</conditional>
<section name="advanced_common">
<param name="show_log" value="true" />
</section>
<output name="hidden_output">
<assert_contents>
<has_text_matching expression="sc.pl.rank_genes_groups_dotplot"/>
<has_text_matching expression="groupby='bulk_labels'"/>
<has_text_matching expression="log=False"/>
<has_text_matching expression="use_raw=False"/>
<has_text_matching expression="dendrogram=False"/>
<has_text_matching expression="color_map='viridis'"/>
<has_text_matching expression="lw=0.0"/>
<has_text_matching expression="ec='face'"/>
</assert_contents>
</output>
<output name="out_png" file="pl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_filtered_1.png" ftype="png" compare="sim_size"/>
</test>
</tests>
<help><![CDATA[
Generic: Scatter plot along observations or variables axes (`pl.scatter`)
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0ef475d

Please sign in to comment.