Skip to content

Commit

Permalink
feat: Support lists in param.region, and fix typo (#2978)
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. -->

* [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).
  • Loading branch information
fgvieira authored Jun 4, 2024
1 parent a66d111 commit 1e9e511
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
27 changes: 21 additions & 6 deletions bio/samtools/faidx/test/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,31 @@ rule samtools_faidx_bgzip:
"master/bio/samtools/faidx"


rule samtools_faidx_region:
rule samtools_faidx_region_file:
input:
"{sample}.fa",
fai="idx/{sample}.fa.fai",
regions="{sample}.regions",
output:
"out/{sample}.fas",
"out/{sample}.region_file.fas",
log:
"{sample}.region.log",
"{sample}.region_file.log",
params:
region="ref",
extra="--length 5",
wrapper:
"master/bio/samtools/faidx"


rule samtools_faidx_region_array:
input:
"{sample}.fa",
fai="idx/{sample}.fa.fai",
output:
"out/{sample}.region_array.fas",
log:
"{sample}.region_array.log",
params:
region=["ref", "ref2"],
extra="--length 5",
wrapper:
"master/bio/samtools/faidx"
Expand All @@ -59,9 +74,9 @@ rule samtools_faidx_bgzip_region:
fai="idx/{sample}.fa.bgz.fai",
gzi="idx/{sample}.fa.bgz.gzi",
output:
"out/{sample}.bgz.fas",
"out/{sample}.region_bgzip.fas",
log:
"{sample}.bgzip_region.log",
"{sample}.region_bgzip.log",
params:
region="ref",
extra="--length 5",
Expand Down
1 change: 1 addition & 0 deletions bio/samtools/faidx/test/genome.regions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref
3 changes: 2 additions & 1 deletion bio/samtools/faidx/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
# Get regions (if present)
regions = snakemake.input.get("regions", "")
if regions:
regions = f"--regions-file {regions}"
regions = f"--region-file {regions}"

region = snakemake.params.get("region", "")


# Get FAI and GZI files
if region or regions:
fai = snakemake.input.get("fai", "")
Expand Down
5 changes: 3 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4242,8 +4242,9 @@ def test_samtools_faidx():
"out/genome.named.fa.fai",
"out/genome.fas.bgz.fai",
"out/genome.fas.bgz.gzi",
"out/genome.fas",
"out/genome.bgz.fas",
"out/genome.region_file.fas",
"out/genome.region_array.fas",
"out/genome.region_bgzip.fas",
"--use-conda",
"-F",
],
Expand Down

0 comments on commit 1e9e511

Please sign in to comment.