Skip to content

feat: bwameth mem and mem2 #3728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions bio/bwameth/memx/environment.linux-64.pin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
# created-by: conda 24.11.0
@EXPLICIT
https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2#d7c89558ba9fa0495403155b64376d81
https://conda.anaconda.org/conda-forge/noarch/ca-certificates-2025.4.26-hbd8a1cb_0.conda#95db94f75ba080a22eb623590993167b
https://conda.anaconda.org/conda-forge/noarch/font-ttf-dejavu-sans-mono-2.37-hab24e00_0.tar.bz2#0c96522c6bdaed4b1566d11387caaf45
https://conda.anaconda.org/conda-forge/noarch/font-ttf-inconsolata-3.000-h77eed37_0.tar.bz2#34893075a5c9e55cdafac56607368fc6
https://conda.anaconda.org/conda-forge/noarch/font-ttf-source-code-pro-2.038-h77eed37_0.tar.bz2#4d59c254e01d9cde7957100457e2d5fb
https://conda.anaconda.org/conda-forge/noarch/font-ttf-ubuntu-0.83-h77eed37_3.conda#49023d73832ef61042f6a237cb2687e7
https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.43-h712a8e2_4.conda#01f8d123c96816249efd255a31ad7712
https://conda.anaconda.org/conda-forge/linux-64/libgomp-15.1.0-h767d61c_2.conda#fbe7d535ff9d3a168c148e07358cd5b1
https://conda.anaconda.org/conda-forge/noarch/python_abi-3.13-7_cp313.conda#e84b44e6300f1703cb25d29120c5b1d8
https://conda.anaconda.org/conda-forge/noarch/tzdata-2025b-h78e105d_0.conda#4222072737ccff51314b5ece9c7d6f5a
https://conda.anaconda.org/conda-forge/linux-64/_openmp_mutex-4.5-2_gnu.tar.bz2#73aaf86a425cc6e73fcf236a5a46396d
https://conda.anaconda.org/conda-forge/noarch/fonts-conda-forge-1-0.tar.bz2#f766549260d6815b0c52253f1fb1bb29
https://conda.anaconda.org/conda-forge/noarch/fonts-conda-ecosystem-1-0.tar.bz2#fee5683a3f04bd15cbd8318b096a27ab
https://conda.anaconda.org/conda-forge/linux-64/libgcc-15.1.0-h767d61c_2.conda#ea8ac52380885ed41c1baa8f1d6d2b93
https://conda.anaconda.org/conda-forge/linux-64/alsa-lib-1.2.14-hb9d3cd8_0.conda#76df83c2a9035c54df5d04ff81bcc02d
https://conda.anaconda.org/conda-forge/linux-64/c-ares-1.34.5-hb9d3cd8_0.conda#f7f0d6cc2dc986d42ac2689ec88192be
https://conda.anaconda.org/conda-forge/linux-64/libdeflate-1.23-h86f0d12_0.conda#27fe770decaf469a53f3e3a6d593067f
https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.7.0-h5888daf_0.conda#db0bfbe7dd197b68ad5f30333bae6ce0
https://conda.anaconda.org/conda-forge/linux-64/libffi-3.4.6-h2dba641_1.conda#ede4673863426c0883c0063d853bbd85
https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-15.1.0-h69a702a_2.conda#ddca86c7040dd0e73b2b69bd7833d225
https://conda.anaconda.org/conda-forge/linux-64/libiconv-1.18-h4ce23a2_1.conda#e796ff8ddc598affdf7c173d6145f087
https://conda.anaconda.org/conda-forge/linux-64/libjpeg-turbo-3.1.0-hb9d3cd8_0.conda#9fa334557db9f63da6c9285fd2a48638
https://conda.anaconda.org/conda-forge/linux-64/liblzma-5.8.1-hb9d3cd8_1.conda#a76fd702c93cd2dfd89eff30a5fd45a8
https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-15.1.0-h8f9b012_2.conda#1cb1c67961f6dd257eae9e9691b341aa
https://conda.anaconda.org/conda-forge/linux-64/libwebp-base-1.5.0-h851e524_0.conda#63f790534398730f59e1b899c3644d4a
https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.3.1-hb9d3cd8_2.conda#edb0dca6bc32e4f4789199455a1dbeb8
https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.5-h2d0b736_3.conda#47e340acb35de30501a76c7c799c41d7
https://conda.anaconda.org/conda-forge/linux-64/openssl-3.5.0-h7b32b05_1.conda#de356753cfdbffcde5bb1e86e3aa6cd0
https://conda.anaconda.org/conda-forge/linux-64/pthread-stubs-0.4-hb9d3cd8_1002.conda#b3c17d95b5a10c6e64a21fa17573e70e
https://conda.anaconda.org/conda-forge/linux-64/xorg-libice-1.1.2-hb9d3cd8_0.conda#fb901ff28063514abb6046c9ec2c4a45
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxau-1.0.12-hb9d3cd8_0.conda#f6ebe2cb3f82ba6c057dde5d9debe4f7
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxdmcp-1.1.5-hb9d3cd8_0.conda#8035c64cb77ed555e3f150b7b3972480
https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-h4bc722e_7.conda#62ee74e96c5ebb0af99386de58cf9553
https://conda.anaconda.org/conda-forge/linux-64/giflib-5.2.2-hd590300_0.conda#3bf7b9fd5a7136126e0234db4b87c8b6
https://conda.anaconda.org/conda-forge/linux-64/keyutils-1.6.1-h166bdaf_0.tar.bz2#30186d27e2c9fa62b45fb1476b7200e3
https://conda.anaconda.org/conda-forge/linux-64/lerc-4.0.0-h0aef613_1.conda#9344155d33912347b37f0ae6c410a835
https://conda.anaconda.org/conda-forge/linux-64/libedit-3.1.20250104-pl5321h7949ede_0.conda#c277e0a4d549b03ac1e9d6cbbe3d017b
https://conda.anaconda.org/conda-forge/linux-64/libev-4.33-hd590300_2.conda#172bf1cd1ff8629f2b1179945ed45055
https://conda.anaconda.org/conda-forge/linux-64/libmpdec-4.0.0-h4bc722e_0.conda#aeb98fdeb2e8f25d43ef71fbacbeec80
https://conda.anaconda.org/conda-forge/linux-64/libpng-1.6.47-h943b412_0.conda#55199e2ae2c3651f6f9b2a447b47bdc9
https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.49.2-hee588c1_0.conda#93048463501053a00739215ea3f36324
https://conda.anaconda.org/conda-forge/linux-64/libssh2-1.11.1-hcf80075_0.conda#eecce068c7e4eddeb169591baac20ac4
https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-15.1.0-h4852527_2.conda#9d2072af184b5caa29492bf2344597bb
https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.38.1-h0b41bf4_0.conda#40b61aab5c7ba9ff276c41cfffe6b80b
https://conda.anaconda.org/conda-forge/linux-64/libxcb-1.17.0-h8a09558_0.conda#92ed62436b625154323d40d5f2f11dd7
https://conda.anaconda.org/conda-forge/linux-64/libxcrypt-4.4.36-hd590300_1.conda#5aa797f8787fe7a17d1b0821485b5adc
https://conda.anaconda.org/conda-forge/linux-64/pixman-0.46.0-h29eaf8c_0.conda#d2f1c87d4416d1e7344cf92b1aaee1c4
https://conda.anaconda.org/conda-forge/linux-64/readline-8.2-h8c095d6_2.conda#283b96675859b20a825f8fa30f311446
https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h4845f30_101.conda#d453b98d9c83e71da0741bb0ff4d76bc
https://conda.anaconda.org/conda-forge/linux-64/zlib-1.3.1-hb9d3cd8_2.conda#c9f075ab2f33b3bbee9e62d4ad0a6cd8
https://conda.anaconda.org/conda-forge/linux-64/zstd-1.5.7-hb8e6e7a_2.conda#6432cb5d4ac0046c3ac0a8a0f95842f9
https://conda.anaconda.org/bioconda/linux-64/bwa-mem2-2.2.1-he70b90d_8.tar.bz2#d29bc9a0dc59990afea47b35e3f43b83
https://conda.anaconda.org/conda-forge/linux-64/graphite2-1.3.13-h59595ed_1003.conda#f87c7b7c2cb45f323ffbce941c78ab7c
https://conda.anaconda.org/conda-forge/linux-64/icu-75.1-he02047a_0.conda#8b189310083baabfb622af68fd9d3ae3
https://conda.anaconda.org/conda-forge/linux-64/krb5-1.21.3-h659f571_0.conda#3f43953b7d3fb3aaa1d0d0723d91e368
https://conda.anaconda.org/conda-forge/linux-64/libfreetype6-2.13.3-h48d6fc4_1.conda#3c255be50a506c50765a93a6644f32fe
https://conda.anaconda.org/conda-forge/linux-64/libnghttp2-1.64.0-h161d5f1_0.conda#19e57602824042dfd0446292ef90488b
https://conda.anaconda.org/conda-forge/linux-64/libtiff-4.7.0-hd9ff511_4.conda#6c1028898cf3a2032d9af46689e1b81a
https://conda.anaconda.org/conda-forge/linux-64/pcre2-10.45-hc749103_0.conda#b90bece58b4c2bf25969b70f3be42d25
https://conda.anaconda.org/conda-forge/linux-64/perl-5.32.1-7_hd590300_perl5.conda#f2cfec9406850991f4e3d960cc9e3321
https://conda.anaconda.org/conda-forge/linux-64/python-3.13.3-hf636f53_101_cp313.conda#10622e12d649154af0bd76bcf33a7c5c
https://conda.anaconda.org/conda-forge/linux-64/xorg-libsm-1.2.6-he73a12e_0.conda#1c74ff8c35dcadf952a16f752ca5aa49
https://conda.anaconda.org/conda-forge/linux-64/xorg-libx11-1.8.12-h4f16b4b_0.conda#db038ce880f100acc74dba10302b5630
https://conda.anaconda.org/bioconda/linux-64/bwa-0.7.19-h577a1d6_1.tar.bz2#2c484db6388422f7c2d44d8bcc82f047
https://conda.anaconda.org/conda-forge/linux-64/lcms2-2.17-h717163a_0.conda#000e85703f0fd9594c81710dd5066471
https://conda.anaconda.org/conda-forge/linux-64/libcups-2.3.3-h4637d8d_4.conda#d4529f4dff3057982a7617c7ac58fde3
https://conda.anaconda.org/conda-forge/linux-64/libcurl-8.13.0-h332b0f4_0.conda#cbdc92ac0d93fe3c796e36ad65c7905c
https://conda.anaconda.org/conda-forge/linux-64/libfreetype-2.13.3-ha770c72_1.conda#51f5be229d83ecd401fb369ab96ae669
https://conda.anaconda.org/conda-forge/linux-64/libglib-2.84.1-h3618099_1.conda#714c97d4ff495ab69d1fdfcadbcae985
https://conda.anaconda.org/conda-forge/noarch/pip-25.1.1-pyh145f28c_0.conda#01384ff1639c6330a0924791413b8714
https://conda.anaconda.org/bioconda/noarch/snakemake-wrapper-utils-0.7.0-pyhdfd78af_0.tar.bz2#ec089170e6e57742c7b01fc7bac034ce
https://conda.anaconda.org/bioconda/noarch/toolshed-0.4.6-pyh864c0ab_3.tar.bz2#61065996a8b60a54d5350427f51a54f3
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxext-1.3.6-hb9d3cd8_0.conda#febbab7d15033c913d53c7a2c102309d
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxfixes-6.0.1-hb9d3cd8_0.conda#4bdb303603e9821baf5fe5fdff1dc8f8
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxrender-0.9.12-hb9d3cd8_0.conda#96d57aba173e878a2089d5638016dc5e
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxt-1.3.1-hb9d3cd8_0.conda#279b0de5f6ba95457190a1c459a64e31
https://conda.anaconda.org/conda-forge/linux-64/freetype-2.13.3-ha770c72_1.conda#9ccd736d31e0c6e41f54e704e5312811
https://conda.anaconda.org/bioconda/linux-64/htslib-1.21-h566b1c6_1.tar.bz2#944598fba531a668e8fafea92ca39bb4
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxi-1.8.2-hb9d3cd8_0.conda#17dcc85db3c7886650b8908b183d6876
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxrandr-1.5.4-hb9d3cd8_0.conda#2de7f99d6581a4a7adbff607b5c278ca
https://conda.anaconda.org/conda-forge/linux-64/fontconfig-2.15.0-h7e30c49_1.conda#8f5b0b297b59e1ac160ad4beec99dbee
https://conda.anaconda.org/bioconda/linux-64/samtools-1.21-h96c455f_1.tar.bz2#0ff9d5d48561198378ad3cb34ce830bf
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxtst-1.2.5-hb9d3cd8_3.conda#7bbe9a0cc0df0ac5f5a8ad6d6a11af2f
https://conda.anaconda.org/bioconda/noarch/bwameth-0.2.7-pyh7e72e81_1.tar.bz2#7dd4e930a6a9bf1b71ddd8b1333ee7fe
https://conda.anaconda.org/conda-forge/linux-64/cairo-1.18.4-h3394656_0.conda#09262e66b19567aff4f592fb53b28760
https://conda.anaconda.org/conda-forge/linux-64/harfbuzz-11.2.1-h3beb420_0.conda#0e6e192d4b3d95708ad192d957cf3163
https://conda.anaconda.org/conda-forge/linux-64/openjdk-23.0.2-h53dfc1b_2.conda#47eea31e0c3f960459237823e5e21a32
https://conda.anaconda.org/bioconda/noarch/picard-slim-3.3.0-hdfd78af_0.tar.bz2#fab4a4639fd22cd155b740fce3064944
9 changes: 9 additions & 0 deletions bio/bwameth/memx/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- bwameth =0.2.7
- samtools =1.21
- picard-slim =3.3.0
- snakemake-wrapper-utils =0.7.0
20 changes: 20 additions & 0 deletions bio/bwameth/memx/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: bwa-meth memx
url: https://github.com/brentp/bwa-meth?tab=readme-ov-file#align
description: >
Align BS-Seq reads on an indexed reference
authors:
- Thibault Dayris
input:
- idx: List of paths to indexed reference files
- fq: List of path to fastq files
- ref: Path to reference fasta file
output:
- Path to mapped reads (SAM/BAM/CRAM)
params:
- extra: Optional parameters passed to `bwameth.py`, besides IO and threading.
- sort: Either `none` (default), `picard`, or `samtools`.
- sort_order: Either `coordinate` (default), or `queryname`.
- sort_extra: Optional parameters provided to samtools/picard besides IO and threading.
notes: >
Both SAM sorting and compression and handled by either samtools or picard. No duplication analysis is performed by this wrapper.

4 changes: 4 additions & 0 deletions bio/bwameth/memx/test/A.fastq
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@K00297/1
AAAAAAAAAAAAAAAAAAAAAAAAA
+
JJJJJJJJJJJJJJJJJJJJJJJJJ
106 changes: 106 additions & 0 deletions bio/bwameth/memx/test/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
rule test_bwameth_mem:
input:
ref="mem/genome.fasta",
idx=multiext(
"mem/genome.fasta.bwameth",
".c2t",
".c2t.amb",
".c2t.ann",
".c2t.bwt",
".c2t.pac",
".c2t.sa",
),
fq=["A.fastq"],
output:
"A.mem.bam",
threads: 2
params:
extra="", # Optional parameters for bwameth.py, besides IO and threading
sort="none", # Either `none` (default), `samtools`, or `picard`
sort_order="coordinate", # Either `coordinate` (default) or `queryname`
sort_extra="", # Optional parameters for sambamba/samtools/picard. Ignored if `sort` is equal to `none`.
log:
"test_bwameth_mem.log"
wrapper:
"master/bio/bwameth/memx"


rule test_bwameth_mem2:
input:
ref="mem2/genome.fasta",
idx=multiext(
"mem2/genome.fasta.bwameth",
".c2t",
".c2t.amb",
".c2t.ann",
".c2t.bwt.2bit.64",
".c2t.pac",
".c2t.0123",
),
fq=["A.fastq"],
output:
"A.mem2.bam",
threads: 2
params:
extra="", # Optional parameters for bwameth.py, besides IO and threading
sort="none", # Either `none` (default), `samtools`, or `picard`
sort_order="coordinate", # Either `coordinate` (default) or `queryname`
sort_extra="", # Optional parameters for sambamba/samtools/picard. Ignored if `sort` is equal to `none`.
log:
"test_bwameth_mem2.log"
wrapper:
"master/bio/bwameth/memx"


rule test_bwameth_mem_sort_picard:
input:
ref="mem/genome.fasta",
idx=multiext(
"mem/genome.fasta.bwameth",
".c2t",
".c2t.amb",
".c2t.ann",
".c2t.bwt",
".c2t.pac",
".c2t.sa",
),
fq=["A.fastq"],
output:
"A.picard_sort.bam",
threads: 2
params:
extra="", # Optional parameters for bwameth.py, besides IO and threading
sort="picard", # Either `none` (default), `samtools`, or `picard`
sort_order="coordinate", # Either `coordinate` (default) or `queryname`
sort_extra="", # Optional parameters for sambamba/samtools/picard. Ignored if `sort` is equal to `none`.
log:
"test_bwameth_mem_sort_picard.log"
wrapper:
"master/bio/bwameth/memx"


rule test_bwameth_mem_sort_samtools:
input:
ref="mem/genome.fasta",
idx=multiext(
"mem/genome.fasta.bwameth",
".c2t",
".c2t.amb",
".c2t.ann",
".c2t.bwt",
".c2t.pac",
".c2t.sa",
),
fq=["A.fastq"],
output:
"A.samtools_sort.bam",
threads: 2
params:
extra="", # Optional parameters for bwameth.py, besides IO and threading
sort="samtools", # Either `none` (default), `samtools`, or `picard`
sort_order="coordinate", # Either `coordinate` (default) or `queryname`
sort_extra="", # Optional parameters for sambamba/samtools/picard. Ignored if `sort` is equal to `none`.
log:
"test_bwameth_mem_sort_samtools.log"
wrapper:
"master/bio/bwameth/memx"
1 change: 1 addition & 0 deletions bio/bwameth/memx/test/mem/genome.fasta
4 changes: 4 additions & 0 deletions bio/bwameth/memx/test/mem/genome.fasta.bwameth.c2t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
>rSheila
ACTAACTCAAAAAAAAAAAA
>fSheila
GTTAGTTTAGAAAAAAAAAA
1 change: 1 addition & 0 deletions bio/bwameth/memx/test/mem/genome.fasta.bwameth.c2t.amb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40 2 0
5 changes: 5 additions & 0 deletions bio/bwameth/memx/test/mem/genome.fasta.bwameth.c2t.ann
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
40 2 11
0 rSheila (null)
0 20 0
0 fSheila (null)
20 20 0
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions bio/bwameth/memx/test/mem2/genome.fasta
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>Sheila
GCTAGCTCAGAAAAAAAAAA
4 changes: 4 additions & 0 deletions bio/bwameth/memx/test/mem2/genome.fasta.bwameth.c2t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
>rSheila
ACTAACTCAAAAAAAAAAAA
>fSheila
GTTAGTTTAGAAAAAAAAAA
Binary file not shown.
1 change: 1 addition & 0 deletions bio/bwameth/memx/test/mem2/genome.fasta.bwameth.c2t.amb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40 2 0
5 changes: 5 additions & 0 deletions bio/bwameth/memx/test/mem2/genome.fasta.bwameth.c2t.ann
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
40 2 11
0 rSheila (null)
0 20 0
0 fSheila (null)
20 20 0
Binary file not shown.
Binary file not shown.
118 changes: 118 additions & 0 deletions bio/bwameth/memx/wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# coding: utf-8

"""
Snakemake wrapper for bwameth

Proceeed according to other bwa wrappers: Align + optional sort
"""
__author__ = "Thibault Dayris"
__mail__ = "[email protected]"
__copyright__ = "Copyright 2024, Thibault Dayris"
__license__ = "MIT"

import os.path
import time

from tempfile import TemporaryDirectory
from snakemake import shell
from snakemake_wrapper_utils.java import get_java_opts
from snakemake_wrapper_utils.samtools import get_samtools_opts

# Extract arguments
extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=False, stderr=True)

sort = snakemake.params.get("sort", "none")
sort_order = snakemake.params.get("sort_order", "coordinate")
sort_extra = snakemake.params.get("sort_extra", "")
samtools_opts = get_samtools_opts(snakemake, param_name="sort_extra")
java_opts = get_java_opts(snakemake)

bwa_threads = snakemake.threads
samtools_threads = snakemake.threads - 1

# Check arguments
if sort_order not in {"coordinate", "queryname"}:
raise ValueError(f"Unexpected value for sort_order ({sort_order})")

# Determine which pipe command to use for converting to bam or sorting.
if sort == "none":
# Correctly assign number of threads according to user request
if samtools_threads >= 1:
samtools_opts += f" --threads {samtools_threads} "

if str(snakemake.output[0]).lower().endswith(("bam", "cram")):
# Simply convert to bam using samtools view.
pipe_cmd = f" | samtools view {samtools_opts} > {snakemake.output[0]}"
else:
# Do not perform any sort nor compression, output raw sam
pipe_cmd = f" > {snakemake.output[0]} "


elif sort == "samtools":
# Correctly assign number of threads according to user request
if samtools_threads >= 1:
samtools_opts += " --threads {samtools_threads} "

# Add name flag if needed.
if sort_order == "queryname":
sort_extra += " -n"

# Sort alignments using samtools sort.
pipe_cmd = " | samtools sort {samtools_opts} {sort_extra} -T {tmpdir} > {snakemake.output[0]}"


elif sort == "picard":
# Correctly assign number of threads according to user request
bwa_threads -= 1
if bwa_threads <= 0:
raise ValueError(
"Not enough threads requested. This wrapper requires exactly one more."
)

# Sort alignments using picard SortSam.
pipe_cmd = (
" | picard SortSam {java_opts} {sort_extra} "
"--INPUT /dev/stdin "
"--TMP_DIR {tmpdir} "
"--SORT_ORDER {sort_order} "
"--OUTPUT {snakemake.output[0]}"
)


else:
raise ValueError(f"Unexpected value for params.sort ({sort})")

# Gathering fastq files to align
fq = snakemake.input.get("fq")
fq1 = snakemake.input.get("fq1")
fq2 = snakemake.input.get("fq2")

# Single-ended case
if fq:
if isinstance(fq, list):
fastq_files = ",".join(fq)
else:
fastq_files = fq

# Pair-ended case
elif fq1 and fq2:
if isinstance(fq1, list) and isinstance(fq2, list):
if len(fq1) == len(fq2):
fastq_files = f'{",".join(fq1)} {",".join(fq2)}'
else:
raise ValueError("Please provide as many R1 and R2 files")
else:
fastq_files = f"{fq1} {fq2}"

# Missing fastq case
else:
raise ValueError("Either provide `input.fq` or both `input.fq1` and `input.fq2`")

with TemporaryDirectory() as tmpdir:
pipe_cmd = pipe_cmd.format(**locals())
shell(
"(bwameth.py --threads {snakemake.threads} "
" {extra} --reference {snakemake.input.ref} "
" {fastq_files} {pipe_cmd} ) {log}"
)
Loading
Loading