Skip to content

Commit

Permalink
fix: fixed some known bugs, added docs, and reformat (#469)
Browse files Browse the repository at this point in the history
* Fixed build log, added docs, and reformat

* Fixed typos

* Fixed bug

* Added missing import

* Removed trailing dot

* Removed extra from samtools pipe

* Fixed wrong extras

* Added test for large index

* Remove unnecessary dependency
  • Loading branch information
fgvieira committed Mar 28, 2022
1 parent ae5af1e commit 58247e3
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 21 deletions.
5 changes: 3 additions & 2 deletions bio/bowtie2/align/environment.yaml
Expand Up @@ -3,5 +3,6 @@ channels:
- conda-forge
- defaults
dependencies:
- bowtie2 ==2.4.4 # Keep consistent with version specified in bowtie2/build
- samtools ==1.10
- bowtie2 =2.4 # Keep consistent with version specified in bowtie2/build
- samtools =1.14
- snakemake-wrapper-utils =0.3
12 changes: 10 additions & 2 deletions bio/bowtie2/align/meta.yaml
@@ -1,6 +1,14 @@
name: "bowtie2"
description: Map reads with bowtie2.
url: http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml
authors:
- Johannes Köster
note:
This wrapper uses an inner pipe. Make sure to use at least two threads in your Snakefile.
- Filipe G. Vieira
input:
- FASTQ file(s)
- Bowtie2 indexed reference index
output:
- SAM/BAM/CRAM file
notes: |
* The `extra` param allows for additional program arguments.
* This wrapper uses an inner pipe. Make sure to use at least two threads in your Snakefile.
18 changes: 13 additions & 5 deletions bio/bowtie2/align/test/Snakefile
@@ -1,13 +1,21 @@
rule bowtie2:
input:
sample=["reads/{sample}.1.fastq", "reads/{sample}.2.fastq"]
sample=["reads/{sample}.1.fastq", "reads/{sample}.2.fastq"],
idx=multiext(
"index/genome",
".1.bt2",
".2.bt2",
".3.bt2",
".4.bt2",
".rev.1.bt2",
".rev.2.bt2",
),
output:
"mapped/{sample}.bam"
"mapped/{sample}.bam",
log:
"logs/bowtie2/{sample}.log"
"logs/bowtie2/{sample}.log",
params:
index="index/genome", # prefix of reference genome index (built with bowtie2-build)
extra="" # optional parameters
extra="", # optional parameters
threads: 8 # Use at least two threads
wrapper:
"master/bio/bowtie2/align"
21 changes: 18 additions & 3 deletions bio/bowtie2/align/wrapper.py
Expand Up @@ -4,11 +4,16 @@
__license__ = "MIT"


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


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


n = len(snakemake.input.sample)
assert (
n == 1 or n == 2
Expand All @@ -19,8 +24,18 @@
else:
reads = "-1 {} -2 {}".format(*snakemake.input.sample)


index = os.path.commonprefix(snakemake.input.idx).rstrip(".")


shell(
"(bowtie2 --threads {snakemake.threads} {extra} "
"-x {snakemake.params.index} {reads} "
"| samtools view -Sbh -o {snakemake.output[0]} -) {log}"
"(bowtie2"
" --threads {snakemake.threads}"
" {reads} "
" -x {index}"
" {extra}"
"| samtools view"
" {samtools_opts}"
" -"
") {log}"
)
3 changes: 1 addition & 2 deletions bio/bowtie2/build/environment.yaml
Expand Up @@ -3,5 +3,4 @@ channels:
- conda-forge
- defaults
dependencies:
- bowtie2 ==2.4.4 # Keep consistent with version specified in bowtie2/align
- samtools ==1.10
- bowtie2 =2.4 # Keep consistent with version specified in bowtie2/align
8 changes: 8 additions & 0 deletions bio/bowtie2/build/meta.yaml
@@ -1,4 +1,12 @@
name: "bowtie2_build"
description: Map reads with bowtie2.
url: http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml
authors:
- Daniel Standage
- Filipe G. Vieira
input:
- FASTA reference
output:
- Bowtie2 reference index
notes: |
* The `extra` param allows for additional program arguments.
36 changes: 32 additions & 4 deletions bio/bowtie2/build/test/Snakefile
@@ -1,15 +1,43 @@
rule bowtie2_build:
input:
reference="genome.fasta"
ref="genome.fasta",
output:
multiext(
"genome",
".1.bt2", ".2.bt2", ".3.bt2", ".4.bt2", ".rev.1.bt2", ".rev.2.bt2",
".1.bt2",
".2.bt2",
".3.bt2",
".4.bt2",
".rev.1.bt2",
".rev.2.bt2",
),
log:
"logs/bowtie2_build/build.log"
"logs/bowtie2_build/build.log",
params:
extra="" # optional parameters
extra="", # optional parameters
threads: 8
wrapper:
"master/bio/bowtie2/build"



rule bowtie2_build_large:
input:
ref="genome.fasta",
output:
multiext(
"genome",
".1.bt2l",
".2.bt2l",
".3.bt2l",
".4.bt2l",
".rev.1.bt2l",
".rev.2.bt2l",
),
log:
"logs/bowtie2_build/build.log",
params:
extra="--large-index", # optional parameters
threads: 8
wrapper:
"master/bio/bowtie2/build"
15 changes: 12 additions & 3 deletions bio/bowtie2/build/wrapper.py
Expand Up @@ -4,12 +4,21 @@
__license__ = "MIT"


import os
from snakemake.shell import shell

extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
indexbase = snakemake.output[0].replace(".1.bt2", "")


index = os.path.commonprefix(snakemake.output).rstrip(".")


shell(
"bowtie2-build --threads {snakemake.threads} {snakemake.params.extra} "
"{snakemake.input.reference} {indexbase}"
"bowtie2-build"
" --threads {snakemake.threads}"
" {extra}"
" {snakemake.input.ref}"
" {index}"
" {log}"
)
8 changes: 8 additions & 0 deletions test.py
Expand Up @@ -1001,6 +1001,14 @@ def test_bowtie2_build():
)


@skip_if_not_modified
def test_bowtie2_build_large():
run(
"bio/bowtie2/build",
["snakemake", "--cores", "1", "genome.1.bt2l", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_bwa_mem():
run(
Expand Down

0 comments on commit 58247e3

Please sign in to comment.