Skip to content

Commit

Permalink
fix: bug with -O being used for gap opening penalty and samtools outp…
Browse files Browse the repository at this point in the history
…ut directory (#1450)

<!-- 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

Gap penalty of minimap2 is done via "-O" option and the very same option
also exists for samtools, but to indicate output directory. Using "-O"
in the "extra" leads to the following error because of using snakemake
utils for samtools
(https://github.com/snakemake/snakemake-wrapper-utils/blob/f9cba17cb380dc7e6729a845ae37f26972c3d1dd/snakemake_wrapper_utils/samtools.py#LL76C23-L76C23):

```
You have specified output format (`-O/--output-fmt`) in params.extra; this is automatically inferred from output file extension.
```

The fastest and not over-engineered solution to me was to add the
gap_opening variable to params, but I feel that it's also not very
elegant especially when it comes to modifying the other penalty scores,
but they can still be set in the extra.

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

* [ ] 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
huzuner and dlaehnemann committed Jun 30, 2023
1 parent 143a9c8 commit c3f227f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bio/bwa-mem2/mem/environment.yaml
Expand Up @@ -6,4 +6,4 @@ dependencies:
- bwa-mem2 =2.2.1
- samtools =1.17
- picard-slim =3.0.0
- snakemake-wrapper-utils =0.5.3
- snakemake-wrapper-utils =0.6.1
2 changes: 1 addition & 1 deletion bio/bwa-mem2/mem/wrapper.py
Expand Up @@ -19,7 +19,7 @@
sort = snakemake.params.get("sort", "none")
sort_order = snakemake.params.get("sort_order", "coordinate")
sort_extra = snakemake.params.get("sort_extra", "")
samtools_opts = get_samtools_opts(snakemake)
samtools_opts = get_samtools_opts(snakemake, param_name="sort_extra")
java_opts = get_java_opts(snakemake)


Expand Down
2 changes: 1 addition & 1 deletion bio/bwa/mem/environment.yaml
Expand Up @@ -6,4 +6,4 @@ dependencies:
- bwa =0.7.17
- samtools =1.16.1
- picard-slim =2.27.4
- snakemake-wrapper-utils =0.5.2
- snakemake-wrapper-utils =0.6.1
4 changes: 2 additions & 2 deletions bio/bwa/mem/test/Snakefile_samtools
Expand Up @@ -23,14 +23,14 @@ rule bwa_mem_write_index:
idx=multiext("genome", ".amb", ".ann", ".bwt", ".pac", ".sa"),
output:
"mapped_with_index/{sample}.bam",
"mapped_with_index/{sample}.bam.csi",
idx="mapped_with_index/{sample}.bam.csi",
log:
"logs/bwa_mem/{sample}.log",
params:
extra=r"-R '@RG\tID:{sample}\tSM:{sample}'",
sorting="samtools", # Can be 'none', 'samtools' or 'picard'.
sort_order="coordinate", # Can be 'queryname' or 'coordinate'.
sort_extra="--write-index", # Extra args for samtools/picard.
sort_extra="", # Extra args for samtools/picard.
tmp_dir="/tmp/", # Path to temp dir. (optional)
threads: 8
wrapper:
Expand Down
2 changes: 1 addition & 1 deletion bio/bwa/mem/wrapper.py
Expand Up @@ -17,7 +17,7 @@
sort = snakemake.params.get("sorting", "none")
sort_order = snakemake.params.get("sort_order", "coordinate")
sort_extra = snakemake.params.get("sort_extra", "")
samtools_opts = get_samtools_opts(snakemake)
samtools_opts = get_samtools_opts(snakemake, param_name="sort_extra")
java_opts = get_java_opts(snakemake)


Expand Down
2 changes: 1 addition & 1 deletion bio/minimap2/aligner/meta.yaml
Expand Up @@ -13,4 +13,4 @@ output:
notes: |
* The `extra` param allows for additional arguments for minimap2.
* The `sort` param allows to enable sorting (if output not PAF), and can be either 'none', 'queryname' or 'coordinate'.
* The `sort_extra` allows for extra arguments for samtools/picard
* The `sort_extra` allows for extra arguments for samtools/picard
4 changes: 3 additions & 1 deletion bio/minimap2/aligner/wrapper.py
Expand Up @@ -10,7 +10,9 @@
from snakemake_wrapper_utils.samtools import get_samtools_opts


samtools_opts = get_samtools_opts(snakemake, parse_output=False)
samtools_opts = get_samtools_opts(
snakemake, parse_output=False, param_name="sort_extra"
)
extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=False, stderr=True)
sort = snakemake.params.get("sorting", "none")
Expand Down

0 comments on commit c3f227f

Please sign in to comment.