Skip to content

Commit

Permalink
feat: move pindel region bed files to input (#594)
Browse files Browse the repository at this point in the history
### Description

Recently I discovered that if you pass a non-existent bed file as a
value for the command line parameters `-j/--include` or `-J/--exclude`
in pindel, the program behaves as if empty files are being passed. Since
these are supplied in `params.extra`, no checks are done on them.

I realise that this is not an issue with the wrapper, per se, but the
pindel repo has been archived, and I think that modifying the wrapper
might be a good way to catch potential mistakes.

Not sure whether my implementation is the best way to handle things, so
thoughts and opinions are welcome.

### QC

* [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: Filipe G. Vieira <fgarrettvieira@gmail.com>
  • Loading branch information
maehler and fgvieira committed Oct 13, 2022
1 parent be5f42c commit 8f52877
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 12 deletions.
16 changes: 15 additions & 1 deletion bio/pindel/call/meta.yaml
@@ -1,4 +1,18 @@
name: pindel
description: Call variants with pindel.
url: https://gmt.genome.wustl.edu/packages/pindel
authors:
- Johannes Köster
- Johannes Köster, Niklas Mähler
input:
- reference genome fasta file
- one or more bam files
- bam configuration file, see http://gmt.genome.wustl.edu/packages/pindel/quick-start.html
- bed file of regions to include (optional)
- bed file of regions to exclude (optional)
output:
- >
One file for each variant type.
For a more detailed description of the output format, see https://gmt.genome.wustl.edu/packages/pindel/user-manual.html#example-output-record.
notes: >
The include and exclude BED file arguments are incompatible with each other.
Either supply one of them or none of them.
40 changes: 34 additions & 6 deletions bio/pindel/call/test/Snakefile
Expand Up @@ -7,15 +7,43 @@ rule pindel:
# samples to call
samples=["mapped/a.bam"],
# bam configuration file, see http://gmt.genome.wustl.edu/packages/pindel/quick-start.html
config="pindel_config.txt"
config="pindel_config.txt",
output:
expand("pindel/all_{type}", type=pindel_types)
expand("pindel/all_{type}", type=pindel_types),
params:
# prefix must be consistent with output files
prefix="pindel/all",
extra="" # optional parameters (except -i, -f, -o)
extra="", # optional parameters (except -i, -f, -o, -j, -J)
log:
"logs/pindel.log"
"logs/pindel.log",
threads: 4
wrapper:
"master/bio/pindel/call"


rule pindel_include_regions:
input:
ref="genome.fasta",
samples=["mapped/a.bam"],
config="pindel_config.txt",
include_bed="regions.bed",
output:
expand("pindel/all_included_{type}", type=pindel_types),
log:
"logs/pindel_j.log",
threads: 4
wrapper:
"master/bio/pindel/call"


rule pindel_exclude_regions:
input:
ref="genome.fasta",
samples=["mapped/a.bam"],
config="pindel_config.txt",
exclude_bed="regions.bed",
output:
expand("pindel/all_excluded_{type}", type=pindel_types),
log:
"logs/pindel_include.log",
threads: 4
wrapper:
"master/bio/pindel/call"
1 change: 1 addition & 0 deletions bio/pindel/call/test/regions.bed
@@ -0,0 +1 @@
1 1000 10000
27 changes: 24 additions & 3 deletions bio/pindel/call/wrapper.py
Expand Up @@ -3,13 +3,34 @@
__email__ = "koester@jimmy.harvard.edu"
__license__ = "MIT"

import os
from snakemake.shell import shell

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

include_bed = snakemake.input.get("include_bed", None)
exclude_bed = snakemake.input.get("exclude_bed", None)

if include_bed is not None and exclude_bed is not None:
raise Exception("supply either include_bed or exclude_bed, not both")

include_arg = ""
if include_bed is not None:
include_arg = f"-j {include_bed}"

exclude_arg = ""
if exclude_bed is not None:
exclude_arg = f"-J {exclude_bed}"

output_prefix = snakemake.output[0].rsplit("_", 1)[0]

shell(
"pindel -T {snakemake.threads} {snakemake.params.extra} -i {snakemake.input.config} "
"-f {snakemake.input.ref} -o {snakemake.params.prefix} {log}"
"pindel "
"-T {snakemake.threads} "
"{extra} "
"{include_arg} "
"{exclude_arg} "
"-i {snakemake.input.config} "
"-f {snakemake.input.ref} "
"-o {output_prefix} {log}"
)
48 changes: 46 additions & 2 deletions test.py
Expand Up @@ -2743,7 +2743,51 @@ def test_picard_createsequencedictionary():
def test_pindel_call():
run(
"bio/pindel/call",
["snakemake", "--cores", "1", "pindel/all_D", "--use-conda", "-F"],
[
"snakemake",
"--cores",
"1",
"pindel/all_D",
"--use-conda",
"-F",
],
)


@skip_if_not_modified
def test_pindel_call_include():
def check_log(log):
assert "Looking at chromosome 1 bases 1000 to 10000" in log

run(
"bio/pindel/call",
[
"snakemake",
"--cores",
"1",
"pindel/all_included_D",
"--use-conda",
"-F",
],
check_log=check_log,
)


@skip_if_not_modified
def test_pindel_call_exclude():
def check_log(log):
assert "Looking at chromosome 1 bases 1 to 1000" in log

run(
"bio/pindel/call",
[
"snakemake",
"--cores",
"1",
"pindel/all_excluded_D",
"--use-conda",
"-F",
],
)


Expand Down Expand Up @@ -4867,4 +4911,4 @@ def test_bazam_separated():
run(
"bio/bazam",
["snakemake", "--cores", "1", "--use-conda", "-F", "results/reads/a.r1.fastq.gz"],
)
)

0 comments on commit 8f52877

Please sign in to comment.