Skip to content

Commit

Permalink
feat: added Bellerophon wrapper (#529)
Browse files Browse the repository at this point in the history
* Added Bellerophon

* Added sorting

* Fixed log

* Added sort doc

* Fixed tests

* fix env

Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
  • Loading branch information
fgvieira and johanneskoester committed Aug 16, 2022
1 parent 8f95ddb commit 888f651
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bio/bellerophon/environment.yaml
@@ -0,0 +1,8 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- bellerophon =1.0
- samtools =1.15
- snakemake-wrapper-utils =0.4
14 changes: 14 additions & 0 deletions bio/bellerophon/meta.yaml
@@ -0,0 +1,14 @@
name: Bellerophon
description: Filter mapped reads where the mapping spans a junction, retaining the 5-prime read.
url: https://github.com/davebx/bellerophon/
authors:
- Filipe G. Vieira
input:
- Forward reads (BAM format)
- Reverse reads (BAM format)
output:
- SAM/BAM/CRAM file
notes: |
* The `sort` param allows to enable sorting ('none', 'queryname' or 'coordinate').
* The `sort_extra` allows for extra arguments for samtools.
* The `extra` param allows for additional program arguments.
32 changes: 32 additions & 0 deletions bio/bellerophon/test/Snakefile
@@ -0,0 +1,32 @@
rule bellerophon_sam:
input:
fwd="test_1500_forward.bam",
rev="test_1500_reverse.bam",
output:
bam="out.sam",
log:
"logs/bellerophon.log",
params:
extra="--quality 20",
sorting="none", # optional: Enable sorting. Possible values: 'none', 'queryname' or 'coordinate'
sort_extra="--no-PG", # optional: extra arguments for samtools/picard
threads: 2
wrapper:
"master/bio/bellerophon"


rule bellerophon_bam:
input:
fwd="test_1500_forward.bam",
rev="test_1500_reverse.bam",
output:
bam="out.bam",
log:
"logs/bellerophon.log",
params:
extra="--quality 20",
sorting="coordinate", # optional: Enable sorting. Possible values: 'none', 'queryname' or 'coordinate'
sort_extra="--no-PG", # optional: extra arguments for samtools/picard
threads: 2
wrapper:
"master/bio/bellerophon"
Binary file added bio/bellerophon/test/test_1500_forward.bam
Binary file not shown.
Binary file added bio/bellerophon/test/test_1500_reverse.bam
Binary file not shown.
43 changes: 43 additions & 0 deletions bio/bellerophon/wrapper.py
@@ -0,0 +1,43 @@
__author__ = "Filipe G. Vieira"
__copyright__ = "Copyright 2022, Filipe G. Vieira"
__license__ = "MIT"


from snakemake.shell import shell
from snakemake_wrapper_utils.samtools import get_samtools_opts


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


pipe_cmd = ""
# Determine which pipe command to use for converting to bam or sorting.
if sort == "none":
# Simply convert to output format using samtools view.
pipe_cmd = f"| samtools view -h {sort_extra} {samtools_opts}"
elif sort in ["coordinate", "queryname"]:
# Add name flag if needed.
if sort == "queryname":
sort_extra += " -n"

# Sort alignments.
pipe_cmd = f"| samtools sort {sort_extra} {samtools_opts}"
else:
raise ValueError(f"Unexpected value for params.sort: {sort}")


shell(
"(bellerophon"
" --threads {snakemake.threads}"
" --forward {snakemake.input.fwd}"
" --reverse {snakemake.input.rev}"
" {extra}"
" --output /dev/stdout"
" {pipe_cmd}"
" > {snakemake.output[0]}"
") {log}"
)
13 changes: 13 additions & 0 deletions test.py
Expand Up @@ -241,6 +241,19 @@ def test_genomescope():
)


@skip_if_not_modified
def test_bellerophon():
run(
"bio/bellerophon",
["snakemake", "--cores", "2", "out.sam", "--use-conda", "-F"],
)

run(
"bio/bellerophon",
["snakemake", "--cores", "2", "out.bam", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_mashmap():
run(
Expand Down

0 comments on commit 888f651

Please sign in to comment.