Skip to content

Commit

Permalink
feat: auto infer run mode (#2937)
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
-->

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

### QC
<!-- Make sure that you can tick the boxes below. -->
Auto infers if it should compress or decompress.

* [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),
* the `environment.yaml` pinning has been updated by running
`snakedeploy pin-conda-envs environment.yaml` on a linux machine,
* 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: Christian Meesters <cmeesters@users.noreply.github.com>
  • Loading branch information
fgvieira and cmeesters committed May 17, 2024
1 parent 498c67f commit 08bd3cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion bio/bgzip/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ description: Block compression/decompression utility
url: https://github.com/samtools/htslib
authors:
- William Rowell
- Filipe G. Vieira
input:
- file to be compressed or decompressed
output:
- compressed or decompressed output
- compressed or decompressed output
params:
- extra: additional bgzip parameters
notes: |
* Run mode (compression/decompression) is automatically inferred from the extension of the input file.
10 changes: 6 additions & 4 deletions bio/bgzip/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)


if snakemake.input[0].endswith(".gz"):
extra += " --decompress"


shell(
"""
(bgzip -c {extra} --threads {snakemake.threads} \
{snakemake.input} > {snakemake.output}) {log}
"""
"bgzip --threads {snakemake.threads} {extra} --output {snakemake.output[0]} {snakemake.input[0]} {log}"
)

0 comments on commit 08bd3cd

Please sign in to comment.