Skip to content

Commit

Permalink
feat: add galah wrapper (#1754)
Browse files Browse the repository at this point in the history
<!-- Ensure that the PR title follows conventional commit style (<type>:
<description>)-->
<!-- Possible types are here:
https://github.com/commitizen/conventional-commit-types/blob/master/index.json
-->

### Description

<!-- Add a description of your PR here-->

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] I confirm that:

For all wrappers added by this PR, 

* there is a test case which covers any introduced changes,
* `input:` and `output:` file paths in the resulting rule can be changed
arbitrarily,
* either the wrapper can only use a single core, or the example rule
contains a `threads: x` statement with `x` being a reasonable default,
* rule names in the test case are in
[snake_case](https://en.wikipedia.org/wiki/Snake_case) and somehow tell
what the rule is about or match the tools purpose or name (e.g.,
`map_reads` for a step that maps reads),
* all `environment.yaml` specifications follow [the respective best
practices](https://stackoverflow.com/a/64594513/2352071),
* wherever possible, command line arguments are inferred and set
automatically (e.g. based on file extensions in `input:` or `output:`),
* all fields of the example rules in the `Snakefile`s and their entries
are explained via comments (`input:`/`output:`/`params:` etc.),
* `stderr` and/or `stdout` are logged correctly (`log:`), depending on
the wrapped tool,
* temporary files are either written to a unique hidden folder in the
working directory, or (better) stored where the Python function
`tempfile.gettempdir()` points to (see
[here](https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir);
this also means that using any Python `tempfile` default behavior
works),
* the `meta.yaml` contains a link to the documentation of the respective
tool or command,
* `Snakefile`s pass the linting (`snakemake --lint`),
* `Snakefile`s are formatted with
[snakefmt](https://github.com/snakemake/snakefmt),
* Python wrapper scripts are formatted with
[black](https://black.readthedocs.io).
* Conda environments use a minimal amount of channels, in recommended
ordering. E.g. for bioconda, use (conda-forge, bioconda, nodefaults, as
conda-forge should have highest priority and defaults channels are
usually not needed because most packages are in conda-forge nowadays).

---------

Co-authored-by: David Laehnemann <david.laehnemann@hhu.de>
  • Loading branch information
fgvieira and dlaehnemann committed Aug 24, 2023
1 parent 3895af2 commit 083688a
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bio/galah/environment.yaml
@@ -0,0 +1,6 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- galah =0.3.1
12 changes: 12 additions & 0 deletions bio/galah/meta.yaml
@@ -0,0 +1,12 @@
name: galah
description: More scalable dereplication for metagenome assembled genomes
url: https://github.com/wwood/galah
authors:
- Filipe G. Vieira
input:
- FASTA files
output:
- clusters: representative FASTA<TAB>member lines
- repres: paths to representative FAS files
params:
- extra: additional program arguments
25 changes: 25 additions & 0 deletions bio/galah/test/Snakefile
@@ -0,0 +1,25 @@
rule galah_fas:
input:
fas=["fas/a.fa", "fas/b.fas.bz2", "fas/c.fasta.gz"],
output:
clusters="results.fas.tsv",
repres="results.fas.list",
log:
"logs/out.fas.log",
params:
extra="--precluster-ani 0.9 --ani 0.95",
threads: 2
resources:
mem_mb=50,
wrapper:
"master/bio/galah"


use rule galah_fas as galah_fas_list with:
input:
fas_list="fas/a.fas_list",
output:
clusters="results.fas_list.tsv",
repres="results.fas_list.list",
log:
"logs/out.fas_list.log",
30 changes: 30 additions & 0 deletions bio/galah/test/fas/a.fa
@@ -0,0 +1,30 @@
>1
ACGGCAT
>2
ACGGCAT
>3
ACGGCAT
>4
ACGGCAT
>5
ACGGCAT
>6
ACGGCAT
>7
ACGGCAT
>8
ACGGCAT
>9
ACGGCAT
>10
ACGGCAT
>11
ACGGCAT
>12
ACGGCAT
>13
ACGGCAT
>14
ACGGCAT
>15
ACGGCAT
3 changes: 3 additions & 0 deletions bio/galah/test/fas/a.fas_list
@@ -0,0 +1,3 @@
fas/a.fa
fas/b.fas.bz2
fas/c.fasta.gz
Binary file added bio/galah/test/fas/b.fas.bz2
Binary file not shown.
Binary file added bio/galah/test/fas/c.fasta.gz
Binary file not shown.
41 changes: 41 additions & 0 deletions bio/galah/wrapper.py
@@ -0,0 +1,41 @@
__author__ = "Filipe G. Vieira"
__copyright__ = "Copyright 2023, Filipe G. Vieira"
__license__ = "MIT"

from snakemake.shell import shell


log = snakemake.log_fmt_shell(stdout=True, stderr=True)
extra = snakemake.params.get("extra", "")


fas = snakemake.input.get("fas", "")
if fas:
fas = f"--genome-fasta-files {' '.join(fas)}"


fas_list = snakemake.input.get("fas_list", "")
if fas_list:
fas_list = f"--genome-fasta-list {fas_list}"


clusters = snakemake.output.get("clusters", "")
if clusters:
clusters = f"--output-cluster-definition {clusters}"


repres = snakemake.output.get("repres", "")
if repres:
repres = f"--output-representative-list {repres}"


shell(
"galah cluster"
" --threads {snakemake.threads}"
" {fas}"
" {fas_list}"
" {extra}"
" {clusters}"
" {repres}"
" {log}"
)
18 changes: 18 additions & 0 deletions test.py
Expand Up @@ -139,6 +139,24 @@ def run(wrapper, cmd, check_log=None):
os.chdir(origdir)


@skip_if_not_modified
def test_galah():
run(
"bio/galah",
[
"snakemake",
"--cores",
"1",
"--use-conda",
"-F",
"results.fas.tsv",
"results.fas.list",
"results.fas_list.tsv",
"results.fas_list.list",
],
)


@skip_if_not_modified
def test_nonpareil():
run(
Expand Down

0 comments on commit 083688a

Please sign in to comment.