From feb710ab538d1bf67ece3617739be738e7eb0663 Mon Sep 17 00:00:00 2001 From: roc-002 <3507755728@qq.com> Date: Wed, 4 Jun 2025 16:00:05 +0800 Subject: [PATCH 01/10] init --- R/cmd-bwa.R | 53 +++++++++++++++++++++++++++++++++++++++ tests/testthat/test-bwa.R | 3 +++ 2 files changed, 56 insertions(+) create mode 100644 R/cmd-bwa.R create mode 100644 tests/testthat/test-bwa.R diff --git a/R/cmd-bwa.R b/R/cmd-bwa.R new file mode 100644 index 0000000..17273b4 --- /dev/null +++ b/R/cmd-bwa.R @@ -0,0 +1,53 @@ +#' Run fastp +#' +#' The `fastp` is a tool designed to provide ultrafast all-in-one preprocessing +#' and quality control for FastQ data. +#' @param fq1,fq2 A string of fastq file path. +#' @param ... `r rd_dots("fastp")`. +#' @param ofile1,ofile2 A string of path to the output fastq file. +#' @param fastp `r rd_cmd("fastp")`. +#' @family command +#' @inherit exec return +#' @seealso +#' - +#' +#' `r rd_seealso()` +#' @export +fastp <- make_command( + "fastp", + function( + fq1, + ofile1, + ..., + fq2 = NULL, + ofile2 = NULL, + fastp = NULL + ){ + assert_string(fastp, allow_empty = FALSE, allow_null = TRUE) + Fastp$new( + cmd = fastp, + ..., + fq1 = fq1, + fq2 = fq2, + ofile1 = ofile1, + ofile2 = ofile2 + ) + } +) + +Fastp <- R6Class( + "Fastp", + inherit = Command, + private = list( + alias = function() "fastp", + setup_help_params = function() "--help", + setup_command_params = function(fq1, fq2, ofile1, ofile2){ + c( + arg0("-i", fq1), + if (!is.null(fq2)) arg0("-I", fq2) else NULL, + arg0("-o", ofile1), + if (!is.null(ofile2)) arg0("-O", ofile2) else NULL + ) + } + ) +) diff --git a/tests/testthat/test-bwa.R b/tests/testthat/test-bwa.R new file mode 100644 index 0000000..1eaff3b --- /dev/null +++ b/tests/testthat/test-bwa.R @@ -0,0 +1,3 @@ +testthat::test_that("`BlitProcess` stdin works well", { + +}) From dfe8f87f536d269fac5d3488415a7d9c040ccb67 Mon Sep 17 00:00:00 2001 From: roc-002 <3507755728@qq.com> Date: Wed, 4 Jun 2025 16:09:51 +0800 Subject: [PATCH 02/10] rename fastp to bwa for a test --- R/cmd-bwa.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cmd-bwa.R b/R/cmd-bwa.R index 17273b4..21e2823 100644 --- a/R/cmd-bwa.R +++ b/R/cmd-bwa.R @@ -1,4 +1,4 @@ -#' Run fastp +#' Run bwa #' #' The `fastp` is a tool designed to provide ultrafast all-in-one preprocessing #' and quality control for FastQ data. From 4c27cf3e3710487d3b5859870585a97a48ac94d8 Mon Sep 17 00:00:00 2001 From: roc-002 <3507755728@qq.com> Date: Tue, 10 Jun 2025 18:43:08 +0800 Subject: [PATCH 03/10] add bwa --- R/cmd-bwa.R | 71 +++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/R/cmd-bwa.R b/R/cmd-bwa.R index 21e2823..000e90c 100644 --- a/R/cmd-bwa.R +++ b/R/cmd-bwa.R @@ -1,53 +1,48 @@ -#' Run bwa +#' Run BWA #' -#' The `fastp` is a tool designed to provide ultrafast all-in-one preprocessing -#' and quality control for FastQ data. -#' @param fq1,fq2 A string of fastq file path. -#' @param ... `r rd_dots("fastp")`. -#' @param ofile1,ofile2 A string of path to the output fastq file. -#' @param fastp `r rd_cmd("fastp")`. -#' @family command +#' @param subcmd Sub-Command of BWA (e.g., "index", "mem"). +#' @param ... `r rd_dots("bwa")`. +#' @param bwa `r rd_cmd("bwa")`. #' @inherit exec return #' @seealso -#' - +#' - #' #' `r rd_seealso()` +#' @examples# 索引参考基因组 +#bwa("index", "-a", "bwtsw", "reference.fa")$run() + +# 序列比对 +#bwa("mem", +# "-t", "4" +# "reference.fa" +# "read1.fq" +# "read2.fq")$run(stdout = "output.sam") +#' \dontrun{ +#' # 建立索引 +#' bwa("index", "-a", "bwtsw", "reference.fa")$run() +#' +#' # 双端序列比对 +#' bwa("mem", "-t", "4", "reference.fa", "read1.fq", "read2.fq")$run(stdout = "output.sam") +#' } +#' @family command #' @export -fastp <- make_command( - "fastp", - function( - fq1, - ofile1, - ..., - fq2 = NULL, - ofile2 = NULL, - fastp = NULL - ){ - assert_string(fastp, allow_empty = FALSE, allow_null = TRUE) - Fastp$new( - cmd = fastp, - ..., - fq1 = fq1, - fq2 = fq2, - ofile1 = ofile1, - ofile2 = ofile2 - ) +bwa <- make_command( + "bwa", + function(subcmd = NULL, ..., bwa = NULL) { + assert_string(subcmd, allow_empty = FALSE, allow_null = TRUE) + assert_string(bwa, allow_empty = FALSE, allow_null = TRUE) + BWA$new(cmd = bwa, ..., subcmd = subcmd) } ) -Fastp <- R6Class( - "Fastp", +BWA <- R6Class( + "BWA", inherit = Command, private = list( - alias = function() "fastp", + alias = function() "bwa", setup_help_params = function() "--help", - setup_command_params = function(fq1, fq2, ofile1, ofile2){ - c( - arg0("-i", fq1), - if (!is.null(fq2)) arg0("-I", fq2) else NULL, - arg0("-o", ofile1), - if (!is.null(ofile2)) arg0("-O", ofile2) else NULL - ) + combine_params = function(subcmd) { + c(subcmd, super$combine_params()) } ) ) From 3fbeef12203acc8bae754bc1c1dc7875a9c6900d Mon Sep 17 00:00:00 2001 From: roc-002 <3507755728@qq.com> Date: Thu, 12 Jun 2025 21:59:28 +0800 Subject: [PATCH 04/10] add discription --- R/cmd-bwa.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/cmd-bwa.R b/R/cmd-bwa.R index 000e90c..4fc5adf 100644 --- a/R/cmd-bwa.R +++ b/R/cmd-bwa.R @@ -1,8 +1,11 @@ #' Run BWA #' +#'BWA is a software package that aligns low-divergence sequences to a +#'large reference genome, such as the human genome #' @param subcmd Sub-Command of BWA (e.g., "index", "mem"). #' @param ... `r rd_dots("bwa")`. #' @param bwa `r rd_cmd("bwa")`. +#' @family command #' @inherit exec return #' @seealso #' - From 7e652cf8877e67addd49d9b6576b586c4c2a94f2 Mon Sep 17 00:00:00 2001 From: roc-002 <3507755728@qq.com> Date: Fri, 13 Jun 2025 15:05:37 +0800 Subject: [PATCH 05/10] add test --- tests/testthat/test-bwa.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-bwa.R b/tests/testthat/test-bwa.R index 1eaff3b..376ef5d 100644 --- a/tests/testthat/test-bwa.R +++ b/tests/testthat/test-bwa.R @@ -1,3 +1,7 @@ -testthat::test_that("`BlitProcess` stdin works well", { +testthat::test_that("`bwa()` works as expected", { + testthat::skip_if_not(nzchar(Sys.which("bwa"))) # 确保系统安装了BWA + bwa() |> cmd_help() + bwa("index") |> cmd_help() + bwa("mem") |> cmd_help() }) From e46bd537f17a4af6d9ea463a0dfa74148de1f846 Mon Sep 17 00:00:00 2001 From: roc-002 <3507755728@qq.com> Date: Fri, 13 Jun 2025 22:24:56 +0800 Subject: [PATCH 06/10] test --- blit.Rproj | 5 +++++ tests/testthat/test-bwa.R | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/blit.Rproj b/blit.Rproj index aaa62a5..69fafd4 100644 --- a/blit.Rproj +++ b/blit.Rproj @@ -5,8 +5,13 @@ SaveWorkspace: No AlwaysSaveHistory: Default EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 Encoding: UTF-8 +RnwWeave: Sweave +LaTeX: pdfLaTeX + AutoAppendNewline: Yes StripTrailingWhitespace: Yes LineEndingConversion: Posix diff --git a/tests/testthat/test-bwa.R b/tests/testthat/test-bwa.R index 376ef5d..301c576 100644 --- a/tests/testthat/test-bwa.R +++ b/tests/testthat/test-bwa.R @@ -1,5 +1,5 @@ testthat::test_that("`bwa()` works as expected", { - testthat::skip_if_not(nzchar(Sys.which("bwa"))) # 确保系统安装了BWA + testthat::skip_if_not(nzchar(Sys.which("bwa"))) bwa() |> cmd_help() bwa("index") |> cmd_help() From 9281884f0cdfa7dfc850b60b3d0c027288a68eff Mon Sep 17 00:00:00 2001 From: roc-002 <3507755728@qq.com> Date: Fri, 13 Jun 2025 22:29:56 +0800 Subject: [PATCH 07/10] test --- tests/testthat/test-bwa.R | 7 ------- tests/testthat/test-exec.R | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 tests/testthat/test-bwa.R diff --git a/tests/testthat/test-bwa.R b/tests/testthat/test-bwa.R deleted file mode 100644 index 301c576..0000000 --- a/tests/testthat/test-bwa.R +++ /dev/null @@ -1,7 +0,0 @@ -testthat::test_that("`bwa()` works as expected", { - testthat::skip_if_not(nzchar(Sys.which("bwa"))) - bwa() |> cmd_help() - - bwa("index") |> cmd_help() - bwa("mem") |> cmd_help() -}) diff --git a/tests/testthat/test-exec.R b/tests/testthat/test-exec.R index acda33e..b6dcc5e 100644 --- a/tests/testthat/test-exec.R +++ b/tests/testthat/test-exec.R @@ -3,6 +3,14 @@ testthat::test_that("`allele_counter()` works as expected", { allele_counter() |> cmd_help() }) +testthat::test_that("`bwa()` works as expected", { + testthat::skip_if_not(nzchar(Sys.which("bwa"))) + bwa() |> cmd_help() + + bwa("index") |> cmd_help() + bwa("mem") |> cmd_help() +}) + testthat::test_that("`cellranger()` works as expected", { testthat::skip_if_not(nzchar(Sys.which("cellranger"))) cellranger() |> cmd_help() From 316ac05351c4b686e993f4656bc56d7182b4a26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E5=8A=A0?= Date: Mon, 8 Sep 2025 13:11:09 +0800 Subject: [PATCH 08/10] Update cmd-bwa.R --- R/cmd-bwa.R | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/R/cmd-bwa.R b/R/cmd-bwa.R index 4fc5adf..41701da 100644 --- a/R/cmd-bwa.R +++ b/R/cmd-bwa.R @@ -1,7 +1,7 @@ #' Run BWA #' -#'BWA is a software package that aligns low-divergence sequences to a -#'large reference genome, such as the human genome +#' BWA is a software package that aligns low-divergence sequences to a +#' large reference genome, such as the human genome #' @param subcmd Sub-Command of BWA (e.g., "index", "mem"). #' @param ... `r rd_dots("bwa")`. #' @param bwa `r rd_cmd("bwa")`. @@ -11,21 +11,16 @@ #' - #' #' `r rd_seealso()` -#' @examples# 索引参考基因组 -#bwa("index", "-a", "bwtsw", "reference.fa")$run() - -# 序列比对 -#bwa("mem", -# "-t", "4" -# "reference.fa" -# "read1.fq" -# "read2.fq")$run(stdout = "output.sam") +#' @examples #' \dontrun{ -#' # 建立索引 +#' # Index reference genome #' bwa("index", "-a", "bwtsw", "reference.fa")$run() #' -#' # 双端序列比对 +#' # Paired-end sequence alignment #' bwa("mem", "-t", "4", "reference.fa", "read1.fq", "read2.fq")$run(stdout = "output.sam") +#' +#' # Single-end alignment (generate sai file) +#' bwa("aln", "-t", "4", "reference.fa", "read.fq")$run(stdout = "read.sai") #' } #' @family command #' @export From 5685498c6f169118bf7841089f48abf220859fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E5=8A=A0?= Date: Mon, 8 Sep 2025 13:12:14 +0800 Subject: [PATCH 09/10] Update test-exec.R --- tests/testthat/test-exec.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-exec.R b/tests/testthat/test-exec.R index b6dcc5e..98129a2 100644 --- a/tests/testthat/test-exec.R +++ b/tests/testthat/test-exec.R @@ -6,7 +6,6 @@ testthat::test_that("`allele_counter()` works as expected", { testthat::test_that("`bwa()` works as expected", { testthat::skip_if_not(nzchar(Sys.which("bwa"))) bwa() |> cmd_help() - bwa("index") |> cmd_help() bwa("mem") |> cmd_help() }) From 3c7f1639495c4e7373667bf2b9980ad2b655e2e2 Mon Sep 17 00:00:00 2001 From: Yunuuuu Date: Fri, 19 Sep 2025 20:38:23 +0800 Subject: [PATCH 10/10] docs: use cmd_run() to execute commands --- R/cmd-bwa.R | 10 ++++++---- man/bwa.Rd | 30 ++++++------------------------ 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/R/cmd-bwa.R b/R/cmd-bwa.R index 41701da..d83b343 100644 --- a/R/cmd-bwa.R +++ b/R/cmd-bwa.R @@ -5,7 +5,6 @@ #' @param subcmd Sub-Command of BWA (e.g., "index", "mem"). #' @param ... `r rd_dots("bwa")`. #' @param bwa `r rd_cmd("bwa")`. -#' @family command #' @inherit exec return #' @seealso #' - @@ -14,13 +13,16 @@ #' @examples #' \dontrun{ #' # Index reference genome -#' bwa("index", "-a", "bwtsw", "reference.fa")$run() +#' bwa("index", "-a", "bwtsw", "reference.fa") |> +#' cmd_run() #' #' # Paired-end sequence alignment -#' bwa("mem", "-t", "4", "reference.fa", "read1.fq", "read2.fq")$run(stdout = "output.sam") +#' bwa("mem", "-t", "4", "reference.fa", "read1.fq", "read2.fq") |> +#' cmd_run(stdout = "output.sam") #' #' # Single-end alignment (generate sai file) -#' bwa("aln", "-t", "4", "reference.fa", "read.fq")$run(stdout = "read.sai") +#' bwa("aln", "-t", "4", "reference.fa", "read.fq") |> +#' cmd_run(stdout = "read.sai") #' } #' @family command #' @export diff --git a/man/bwa.Rd b/man/bwa.Rd index dd8038b..908161b 100644 --- a/man/bwa.Rd +++ b/man/bwa.Rd @@ -23,13 +23,16 @@ large reference genome, such as the human genome \examples{ \dontrun{ # Index reference genome -bwa("index", "-a", "bwtsw", "reference.fa")$run() +bwa("index", "-a", "bwtsw", "reference.fa") |> + cmd_run() # Paired-end sequence alignment -bwa("mem", "-t", "4", "reference.fa", "read1.fq", "read2.fq")$run(stdout = "output.sam") +bwa("mem", "-t", "4", "reference.fa", "read1.fq", "read2.fq") |> + cmd_run(stdout = "output.sam") # Single-end alignment (generate sai file) -bwa("aln", "-t", "4", "reference.fa", "read.fq")$run(stdout = "read.sai") +bwa("aln", "-t", "4", "reference.fa", "read.fq") |> + cmd_run(stdout = "read.sai") } } \seealso{ @@ -41,27 +44,6 @@ bwa("aln", "-t", "4", "reference.fa", "read.fq")$run(stdout = "read.sai") \item \code{\link[=cmd_parallel]{cmd_parallel()}} } -Other \code{commands}: -\code{\link{allele_counter}()}, -\code{\link{bcftools}()}, -\code{\link{bedtools}()}, -\code{\link{bowtie2}()}, -\code{\link{cellranger}()}, -\code{\link{conda}()}, -\code{\link{fastp}()}, -\code{\link{fastq_pair}()}, -\code{\link{gistic2}()}, -\code{\link{kraken2}()}, -\code{\link{kraken_tools}()}, -\code{\link{perl}()}, -\code{\link{pyscenic}()}, -\code{\link{python}()}, -\code{\link{samtools}()}, -\code{\link{seqkit}()}, -\code{\link{snpEff}()}, -\code{\link{trust4}()}, -\code{\link{varscan}()} - Other \code{commands}: \code{\link{allele_counter}()}, \code{\link{bcftools}()},