changeset 0:086d850271a2 draft

planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/tree/develop/tools/tertiary-analysis/scanpy commit 39b0809db1e17c2a24930fe8fb8ceaf3ea454a7d
author ebi-gxa
date Tue, 19 Nov 2019 13:00:14 -0500
parents
children 339d205356c6
files anndata_operations.xml scanpy_macros.xml scanpy_macros2.xml
diffstat 3 files changed, 307 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/anndata_operations.xml	Tue Nov 19 13:00:14 2019 -0500
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="utf-8"?>
+<tool id="anndata_ops" name="AnnData Operations" version="0.0.1+galaxy0">
+  <description>modifies metadata and flags genes</description>
+  <macros>
+    <import>scanpy_macros2.xml</import>
+  </macros>
+  <expand macro="requirements"/>
+  <command detect_errors="exit_code"><![CDATA[
+ln -s '${input_obj_file}' input.h5 &&
+python $operations
+]]></command>
+  <configfiles>
+    <configfile name="operations">
+import scanpy as sc
+import logging
+
+adata = sc.read('input.h5')
+
+gene_name = '${gene_symbols_field}'
+qc_vars = list()
+
+#for $i, $s in enumerate($modifications)
+adata.obs['${s.to_obs}'] = adata.obs['${s.from_obs}']
+#end for
+
+gene_names = getattr(adata.var, gene_name)
+
+#for $i, $flag in enumerate($gene_flags)
+k_cat = gene_names.str.startswith('${flag.startswith}')
+if k_cat.sum() > 0:
+    adata.var['${flag.flag}'] = k_cat
+    qc_vars.append('${flag.flag}')
+else:
+    logging.warning('No genes starting with {} found, skip calculating expression of {} genes'.format('${flag.startswith}', '${flag.flag}'))
+#end for
+
+
+if len(qc_vars) > 0:
+    pct_top = [${top_genes}]
+    sc.pp.calculate_qc_metrics(adata, qc_vars=qc_vars, percent_top=pct_top, inplace=True)
+
+if 'n_genes' not in adata.obs.columns:
+    sc.pp.filter_cells(adata, min_genes=0)
+if 'n_counts' not in adata.obs.columns:
+    sc.pp.filter_cells(adata, min_counts=0)
+if 'n_cells' not in adata.var.columns:
+    sc.pp.filter_genes(adata, min_cells=0)
+if 'n_counts' not in adata.var.columns:
+    sc.pp.filter_genes(adata, min_counts=0)
+
+adata.write('output.h5', compression='gzip')
+    </configfile>
+</configfiles>
+
+  <inputs>
+    <param name="input_obj_file" argument="input-object-file" type="data" format="h5" label="Input object in hdf5 AnnData format"/>
+    <repeat name="modifications" title="Change field names in AnnData observations" min="0">
+      <param name="from_obs" type="text" label="Original name" help="Name in observations that you want to change">
+        <sanitizer>
+          <valid initial="string.printable"/>
+        </sanitizer>
+      </param>
+      <param name="to_obs" type="text" label="New name" help="New name in observations that you want to change"/>
+    </repeat>
+    <param name="gene_symbols_field" value='index' type="text" label="Gene symbols field in AnnData" help="Field inside var.params where the gene symbols are, normally 'index' or 'gene_symbols'"/>
+    <repeat name="gene_flags" title="Flag genes that start with these names">
+      <param name="startswith" type="text" label="Starts with" help="Text that you expect the genes to be flagged to start with, such as 'MT-' for mito genes"/>
+      <param name="flag" type="text" label="Var name" help="Name of the column in var.names where this boolean flag is stored, for example 'mito' for mitochondrial genes."/>
+    </repeat>
+    <param name="top_genes" label="Number of top genes" value='50' help="to calculate percentage of the flagged genes in that number of top genes. Used by sc.pp.calculate_qc_metrics (integer)." type="integer"/>
+  </inputs>
+
+  <outputs>
+    <data name="output" format="h5" from_work_dir="output.h5" label="${tool.name} on ${on_string}: anndata with metadata changes."/>
+  </outputs>
+
+  <tests>
+    <test>
+      <param name="input_obj_file" value="find_cluster.h5"/>
+      <param name="input_format" value="anndata"/>
+      <param name="color_by" value="louvain"/>
+      <output name="output" file="output.h5" ftype="h5" compare="sim_size"/>
+    </test>
+  </tests>
+
+  <help><![CDATA[
+=============================
+Operations on AnnData objects
+=============================
+
+Performs the following operations:
+
+* Change observation fields, mostly for downstreaming processes convenience. Multiple fields can be changed as one.
+* Flag genes that start with a certain text: useful for flagging mitochondrial, spikes or other groups of genes.
+* For the flags created, calculates qc metrics (pct_<flag>_counts).
+* Calculates `n_genes`, `n_counts` for cells and `n_cells`, `n_counts` for genes.
+* For top <N> genes specified, calculate qc metrics (pct_counts_in_top_<N>_genes).
+
+This functionality will probably be added in the future to a larger package.
+]]></help>
+  <expand macro="citations"/>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scanpy_macros.xml	Tue Nov 19 13:00:14 2019 -0500
@@ -0,0 +1,109 @@
+<macros>
+  <token name="@TOOL_VERSION@">1.3.2</token>
+  <token name="@HELP@">More information can be found at https://scanpy.readthedocs.io</token>
+  <token name="@PLOT_OPTS@">
+#if $do_plotting.plot
+                  -P output.png
+                  --projectio $do_plotting.projection
+                  --components $do_plotting.components
+    #if $do_plotting.color_by
+                  --color-by $do_plotting.color_by
+    #end if
+    #if $do_plotting.groups
+                  --group $do_plotting.groups
+    #end if
+    #if $do_plotting.use_raw
+                  --use-raw
+    #end if
+    #if $do_plotting.palette
+                  --palette $do_plotting.palette
+    #end if
+    #if $do_plotting.edges
+                  --edges
+    #end if
+    #if $do_plotting.arrows
+                  --arrows
+    #end if
+    #if not $do_plotting.sort_order
+                  --no-sort-order
+    #end if
+    #if $do_plotting.frameoff
+                  --frameoff
+    #end if
+#end if
+  </token>
+  <xml name="requirements">
+    <requirements>
+      <requirement type="package" version="0.0.5">scanpy-scripts</requirement>
+      <yield/>
+    </requirements>
+  </xml>
+  <token name="@EXPORT_MTX_OPTS@">
+      ${export_mtx}
+  </token>
+  <token name="@VERSION_HISTORY@"><![CDATA[
+**Version history**
+
+1.3.2+galaxy1: Normalise-data and filter-genes: Exposes ability to output 10x files.
+
+1.3.2+galaxy0: Initial contribution. Ni Huang and Pablo Moreno, Expression Atlas team https://www.ebi.ac.uk/gxa/home  at
+EMBL-EBI https://www.ebi.ac.uk/ and Teichmann Lab at Wellcome Sanger Institute.
+    ]]></token>
+  <xml name="citations">
+    <citations>
+      <citation type="doi">10.1186/s13059-017-1382-0</citation>
+      <citation type="bibtex">
+	@misc{githubscanpy-scripts,
+	author = {Ni Huang, EBI Gene Expression Team},
+	year = {2018},
+	title = {Scanpy-scripts: command line interface for Scanpy},
+	publisher = {GitHub},
+	journal = {GitHub repository},
+	url = {https://github.com/ebi-gene-expression-group/scanpy-scripts},
+      }</citation>
+      <yield />
+    </citations>
+  </xml>
+  <xml name="input_object_params">
+    <param name="input_obj_file" argument="--input-object-file" type="data" format="h5" label="Input object in hdf5 format"/>
+    <param name="input_format" argument="--input-format" type="select" label="Format of input object">
+      <option value="anndata" selected="true">AnnData format hdf5</option>
+      <option value="loom">Loom format hdf5, current support is incomplete</option>
+    </param>
+  </xml>
+  <xml name="output_object_params">
+    <param name="output_format" argument="--output-format" type="select" label="Format of output object">
+      <option value="anndata" selected="true">AnnData format hdf5</option>
+      <option value="loom">Loom format hdf5, current support is defective</option>
+    </param>
+  </xml>
+  <xml name="output_plot_params">
+    <param name="color_by" argument="--color-by" type="text" value="n_genes" label="Color by attributes, comma separated strings"/>
+    <param name="groups" argument="--groups" type="text" optional="ture" label="Restrict plotting to named groups, comma separated strings"/>
+    <param name="projection" argument="--projection" type="select" label="Plot projection">
+      <option value="2d" selected="true">2D</option>
+      <option value="3d">3D</option>
+    </param>
+    <param name="components" argument="--components" type="text" value="1,2" label="Components to plot, comma separated integers"/>
+    <param name="palette" argument="--palette" type="text" optional="true" label="Palette"/>
+    <param name="use_raw" argument="--use-raw" type="boolean" checked="false" label="Use raw attributes if present"/>
+    <param name="edges" argument="--edges" type="boolean" checked="false" label="Show edges"/>
+    <param name="arrows" argument="--arrows" type="boolean" checked="false" label="Show arrows"/>
+    <param name="sort_order" argument="--no-sort-order" type="boolean" checked="true" label="Element with high color-by value plot on top"/>
+    <param name="frameoff" argument="--frameoff" type="boolean" checked="false" label="Omit frame"/>
+  </xml>
+  <xml name="export_mtx_params">
+    <param name="export_mtx" argument="--export-mtx" type="boolean" truevalue="--export-mtx ./" falsevalue="" checked="false" label="Save normalised data to 10x format" help="If enabled, it will generate in addition to the main output in Loom or AnnData an export in 10x format of the normalised data."/>
+  </xml>
+  <xml name="export_mtx_outputs">
+    <data name="matrix_10x" format="txt" from_work_dir="matrix.mtx" label="${tool.name} on ${on_string}: 10x matrix">
+      <filter>export_mtx</filter>
+    </data>
+    <data name="genes_10x" format="tsv" from_work_dir="genes.tsv" label="${tool.name} on ${on_string}: 10x genes">
+      <filter>export_mtx</filter>
+    </data>
+    <data name="barcodes_10x" format="tsv" from_work_dir="barcodes.tsv" label="${tool.name} on ${on_string}: 10x barcodes">
+      <filter>export_mtx</filter>
+    </data>
+  </xml>
+</macros>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scanpy_macros2.xml	Tue Nov 19 13:00:14 2019 -0500
@@ -0,0 +1,96 @@
+<macros>
+  <token name="@TOOL_VERSION@">1.4.3</token>
+  <token name="@HELP@">More information can be found at https://scanpy.readthedocs.io</token>
+  <token name="@VERSION_HISTORY@"><![CDATA[
+**Version history**
+
+1.4.3+galaxy0: Update to scanpy-scripts 0.2.5 (running scanpy ==1.4.3).
+
+1.4.2+galaxy0: Update to scanpy-scripts 0.2.4 (requires scanpy >=1.4.2).
+
+1.3.2+galaxy1: Normalise-data and filter-genes: Exposes ability to output 10x files.
+
+1.3.2+galaxy0: Initial contribution. Ni Huang and Pablo Moreno, Expression Atlas team https://www.ebi.ac.uk/gxa/home  at
+EMBL-EBI https://www.ebi.ac.uk/ and Teichmann Lab at Wellcome Sanger Institute.
+    ]]></token>
+  <token name="@INPUT_OPTS@">
+    --input-format '${input_format}' input.h5
+  </token>
+  <token name="@OUTPUT_OPTS@">
+    --show-obj stdout --output-format '${output_format}' output.h5
+  </token>
+  <token name="@PLOT_OPTS@">
+#if $fig_title
+    --title '${fig_title}'
+#end if
+    --fig-size '${fig_size}'
+    --fig-dpi ${fig_dpi}
+    --fig-fontsize ${fig_fontsize}
+    ${fig_frame}
+    ./output.png
+  </token>
+  <token name="@EXPORT_MTX_OPTS@">${export_mtx}</token>
+
+  <xml name="requirements">
+    <requirements>
+      <requirement type="package" version="0.2.5.post1">scanpy-scripts</requirement>
+      <yield/>
+    </requirements>
+  </xml>
+
+  <xml name="citations">
+    <citations>
+      <yield />
+      <citation type="doi">10.1186/s13059-017-1382-0</citation>
+      <citation type="bibtex">
+	@misc{githubscanpy-scripts,
+	author = {Ni Huang, EBI Gene Expression Team},
+	year = {2018},
+	title = {Scanpy-scripts: command line interface for Scanpy},
+	publisher = {GitHub},
+	journal = {GitHub repository},
+	url = {https://github.com/ebi-gene-expression-group/scanpy-scripts},
+      }</citation>
+    </citations>
+  </xml>
+
+  <xml name="input_object_params">
+    <param name="input_obj_file" argument="input-object-file" type="data" format="h5" label="Input object in hdf5 format"/>
+    <param name="input_format" argument="--input-format" type="select" label="Format of input object">
+      <option value="anndata" selected="true">AnnData format hdf5</option>
+      <option value="loom">Loom format hdf5</option>
+    </param>
+  </xml>
+
+  <xml name="output_object_params">
+    <param name="output_format" argument="--output-format" type="select" label="Format of output object">
+      <option value="anndata" selected="true">AnnData format hdf5</option>
+      <option value="loom">Loom format hdf5</option>
+    </param>
+  </xml>
+
+  <xml name="output_plot_params">
+    <param name="fig_title" argument="--title" type="text" label="Figure title"/>
+    <param name="fig_size" argument="--fig-size" type="text" value="4,4" label="Figure size as 'width,height', e.g, '7,7'"/>
+    <param name="fig_dpi" argument="--fig-dpi" type="integer" min="1" value="80" label="Figure dpi"/>
+    <param name="fig_fontsize" argument="--fig-fontsize" type="integer" min="0" value="10" label="Figure font size"/>
+    <param name="fig_frame" type="boolean" truevalue="--frameon" falsevalue="--frameoff" checked="false"
+           label="Show plot frame"/>
+  </xml>
+
+  <xml name="export_mtx_params">
+    <param name="export_mtx" argument="--export-mtx" type="boolean" truevalue="--export-mtx ./" falsevalue="" checked="false" label="Save to 10x mtx format" help="If enabled, it will generate in addition to the main output in Loom or AnnData an export in 10x format."/>
+  </xml>
+
+  <xml name="export_mtx_outputs">
+    <data name="matrix_10x" format="txt" from_work_dir="matrix.mtx" label="${tool.name} on ${on_string}: 10x matrix">
+      <filter>export_mtx</filter>
+    </data>
+    <data name="genes_10x" format="tsv" from_work_dir="genes.tsv" label="${tool.name} on ${on_string}: 10x genes">
+      <filter>export_mtx</filter>
+    </data>
+    <data name="barcodes_10x" format="tsv" from_work_dir="barcodes.tsv" label="${tool.name} on ${on_string}: 10x barcodes">
+      <filter>export_mtx</filter>
+    </data>
+  </xml>
+</macros>