Skip to content

Commit

Permalink
fix: bug when renaming samples (#2293)
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-->
Fix issue #2292 and added new tests.

### 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).
  • Loading branch information
fgvieira committed Nov 8, 2023
1 parent 6c1750d commit 8c217f8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
12 changes: 9 additions & 3 deletions bio/bcftools/reheader/meta.yaml
Expand Up @@ -4,6 +4,12 @@ url: http://www.htslib.org/doc/bcftools.html#reheader
authors:
- Jan Forster
- Filipe G. Vieira
notes: |
* The `uncompressed_bcf` param allows to specify that a BCF output should be uncompressed (ignored otherwise).
* The `extra` param allows for additional program arguments (not `--threads`, `-o/--output`, `-O/--output-type`, or `-T/--temp-prefix`).
input:
- VCF/BCF file
- header: new header (optional if "samples" is set)
- samples: new sample names (optional if "header" is set)
output:
- VCF/BCF file with new header
params:
- uncompressed_bcf: specify that a BCF output should be uncompressed (ignored otherwise).
- extra: additional program arguments (not `--threads`, `-o/--output`, `-O/--output-type`, or `-T/--temp-prefix`)
15 changes: 13 additions & 2 deletions bio/bcftools/reheader/test/Snakefile
Expand Up @@ -8,11 +8,22 @@ rule bcftools_reheader:
output:
"a.reheader.bcf",
log:
"reheader.log",
"a.reheader.log",
params:
uncompressed_bcf=False,
extra="", # optional parameters for bcftools reheader
view_extra="", # optional parameters for bcftools view
threads: 2
wrapper:
"master/bio/bcftools/reheader"
"master//bio/bcftools/reheader"


use rule bcftools_reheader as bcftools_reheader_map with:
input:
vcf="a.bcf",
header="header.txt",
samples="samples_map.tsv",
output:
"a.reheader_map.bcf",
log:
"a.reheader_map.log",
1 change: 1 addition & 0 deletions bio/bcftools/reheader/test/samples_map.tsv
@@ -0,0 +1 @@
A LIB_A
8 changes: 5 additions & 3 deletions bio/bcftools/reheader/wrapper.py
Expand Up @@ -10,7 +10,9 @@
from snakemake_wrapper_utils.bcftools import get_bcftools_opts


bcftools_opts = get_bcftools_opts(snakemake, parse_ref=False, parse_memory=False)
bcftools_opts = get_bcftools_opts(
snakemake, parse_ref=False, parse_samples=False, parse_memory=False
)
extra = snakemake.params.get("extra", "")
view_extra = snakemake.params.get("view_extra", "")
log = snakemake.log_fmt_shell(stdout=False, stderr=True)
Expand All @@ -19,11 +21,11 @@
## Extract arguments
header = snakemake.input.get("header", "")
if header:
header = f"-h {header}"
header = f"--header {header}"

samples = snakemake.input.get("samples", "")
if samples:
samples = f"-s {samples}"
samples = f"--samples {samples}"


with tempfile.TemporaryDirectory() as tmpdir:
Expand Down
4 changes: 4 additions & 0 deletions test.py
Expand Up @@ -1763,6 +1763,10 @@ def test_bcftools_reheader():
"bio/bcftools/reheader",
["snakemake", "--cores", "1", "a.reheader.bcf", "--use-conda", "-F"],
)
run(
"bio/bcftools/reheader",
["snakemake", "--cores", "1", "a.reheader_map.bcf", "--use-conda", "-F"],
)


@skip_if_not_modified
Expand Down

0 comments on commit 8c217f8

Please sign in to comment.