-
Notifications
You must be signed in to change notification settings - Fork 10
Bedtools #15
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
Bedtools #15
Changes from 5 commits
21150ae
2a8218f
b3979fb
8320ab2
f8a11e2
b53e36c
1be2782
94b49ee
61d3870
ec0b97a
e3a352e
72c1685
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #' Run bedtools | ||
| #' | ||
| #' The `bedtools` is a powerful toolset for genome arithmetic. | ||
| #' @param subcmd Sub-Command of bedtools. Details see: `r rd_help("bedtools")`. | ||
| #' @param file1 Path to bed/gff(gtf)/vcf/bam(sam) file. | ||
| #' @param file2 Path to the second file, some commands require. | ||
| #' @param ... `r rd_dots("bedtools")`. | ||
| #' @param ofile Path to the output file. | ||
| #' @param bedtools `r rd_cmd("bedtools")`. | ||
| #' @seealso | ||
| #' - <https://github.com/arq5x/bedtools2/> | ||
| #' | ||
| #' `r rd_seealso()` | ||
| #' @inherit exec return | ||
| #' @family command | ||
| #' @export | ||
| bedtools <- make_command( | ||
| "bedtools", | ||
| function( | ||
| subcmd = NULL, | ||
| file1, | ||
| ofile, | ||
| ..., | ||
| file2 = NULL, | ||
| bedtools = NULL | ||
| ) { | ||
| assert_string(subcmd, allow_empty = FALSE, allow_null = TRUE) | ||
| assert_string(bedtools, allow_empty = FALSE, allow_null = TRUE) | ||
| BEDTools$new( | ||
| cmd = bedtools, | ||
| ..., | ||
| subcmd = subcmd, | ||
| file1 = file1, | ||
| file2 = file2, | ||
| ofile = ofile | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| BEDTools <- R6Class( | ||
| "BEDTools", | ||
| inherit = Command, | ||
| private = list( | ||
| alias = function() "bedtools", | ||
| setup_help_params = function() "help", | ||
| combine_params = function(subcmd, file1, file2, ofile) { | ||
| c( | ||
| if (private$help) { | ||
| c(super$combine_params(), subcmd) | ||
| } else { | ||
| c(subcmd, super$combine_params()) | ||
| }, | ||
| arg0("-a", file1), | ||
| if (!is.null(file2)) arg0("-b", file2) else NULL, | ||
| arg0("-o", ofile), | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,254 @@ | ||
| #' Run bedtools | ||
| #' | ||
| #' The `bedtools` is a powerful toolset for genome arithmetic, | ||
| #' which includes `intersect`, `merge`, `coverage`, `getfasta`, `closest`, etc. | ||
| #' @param file1 Path to bed/gff(gtf)/vcf/bam(sam) file. | ||
| #' @param file2 Path to the second file, some commands require. | ||
| #' @param ... | ||
| #' - `bedtools intersect`: `r rd_dots("bedtools intersect")`. | ||
| #' - `bedtools merge`: `r rd_dots("bedtools merge")`. | ||
| #' - `bedtools coverage`: `r rd_dots("bedtools coverage")`. | ||
| #' - `bedtools getfasta`: `r rd_dots("bedtools getfasta")`. | ||
| #' - `bedtools closest`: `r rd_dots("bedtools closest")`. | ||
| #' @param ofile Path to the output file. | ||
| #' @param | ||
| #' - `bedtools intersect`: `r rd_cmd("bedtools intersect")`. | ||
| #' - `bedtools merge`: `r rd_cmd("bedtools merge")`. | ||
| #' - `bedtools coverage`: `r rd_cmd("bedtools coverage")`. | ||
| #' - `bedtools getfasta`: `r rd_cmd("bedtools getfasta")`. | ||
| #' - `bedtools closest`: `r rd_cmd("bedtools closest")`. | ||
| #' @seealso | ||
| #' - <https://github.com/arq5x/bedtools2/> | ||
| #' | ||
| #' `r rd_seealso()` | ||
| #' @inherit exec return | ||
| #' @family command | ||
| #' @export | ||
| # bedtools_intersect ---- | ||
| bedtools_intersect <- make_command( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你已经创建了bedtools命令后,这个函数直接调用前面创建的函数就行 bedtools_intersect <- function(...) {
bedtools(sucmd ="intersect", ...) # do your work
}
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此文件所有的函数都可以改成此形式,当然,实际上由subcmd参数,实际上这些函数不要也可
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是的,我当时上课跟他说过。只是让他提交记录下。 @Gates369 可以考虑只保留一个 clean 的简单版本,其他可以删除 commit 下。 |
||
| "bedtools_intersect", | ||
| function( | ||
| file1, | ||
| file2, | ||
| ofile, | ||
| ..., | ||
| `bedtools intersect` = NULL | ||
| ){ | ||
| assert_string(`bedtools intersect`, allow_empty = FALSE, allow_null = TRUE) | ||
| BEDTools_Intersect$new( | ||
| cmd = `bedtools intersect`, | ||
| ..., | ||
| file1 = file1, | ||
| file2 = file2, | ||
| ofile = ofile, | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| BEDTools_Intersect <- R6Class( | ||
| "BEDTools_Intersect", | ||
| inherit = Command, | ||
| private = list( | ||
| alias = function() "bedtools intersect", | ||
| setup_help_params = function() "--help", | ||
| setup_command_params = function(file1, file2, ofile){ | ||
| c( | ||
| arg0("-a", file1), | ||
| arg0("-b", file2), | ||
| arg0("-wa"), | ||
| arg0("-o", ofile), | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
|
|
||
| # bedtools_merge ---- | ||
| bedtools_merge <- make_command( | ||
| "bedtools_merge", | ||
| function( | ||
| file1, | ||
| ofile, | ||
| ..., | ||
| dist = NULL, | ||
| `bedtools merge` = NULL | ||
| ){ | ||
| assert_string(`bedtools merge`, allow_empty = FALSE, allow_null = TRUE) | ||
| `BEDTools_Merge`$new( | ||
| cmd = `bedtools merge`, | ||
| ..., | ||
| file1 = file1, | ||
| dist = dist, | ||
| ofile = ofile, | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| BEDTools_Merge <- R6Class( | ||
| "BEDTools_Merge", | ||
| inherit = Command, | ||
| private = list( | ||
| alias = function() "bedtools merge", | ||
| setup_help_params = function() "--help", | ||
| setup_command_params = function(file1, dist, ofile){ | ||
| c( | ||
| if (endsWith(file1, ".bed")|endsWith(file1, ".gff")){ | ||
| arg0("-i", file1) | ||
| } else{ | ||
| cli::cli_abort( | ||
| "{.arg file1} must be BED/GFF" | ||
| ) | ||
| }, | ||
| if (!is.null(dist)) arg0("-d", dist) else NULL, | ||
| arg0("-o", ofile), | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
|
|
||
| # bedtools_coverage ---- | ||
| bedtools_coverage <- make_command( | ||
| "bedtools_coverage", | ||
| function( | ||
| file1, | ||
| file2, | ||
| ofile, | ||
| ..., | ||
| `bedtools coverage` = NULL | ||
| ){ | ||
| assert_string(`bedtools coverage`, allow_empty = FALSE, allow_null = TRUE) | ||
| BEDTools_Coverage$new( | ||
| cmd = `bedtools coverage`, | ||
| ..., | ||
| file1 = file1, | ||
| file2 = file2, | ||
| ofile = ofile, | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| BEDTools_Coverage <- R6Class( | ||
| "BEDTools_Coverage", | ||
| inherit = Command, | ||
| private = list( | ||
| alias = function() "bedtools coverage", | ||
| setup_help_params = function() "--help", | ||
| setup_command_params = function(file1, file2, ofile){ | ||
| c( | ||
| if (endsWith(file1, ".bed")|endsWith(file1, ".gff")){ | ||
| arg0("-a", file1) | ||
| } else{ | ||
| cli::cli_abort( | ||
| "{.arg file1} must be BED/GFF" | ||
| ) | ||
| }, | ||
| if (endsWith(file2, ".bed")|endsWith(file2, ".gff")|endsWith(file2, ".bam")){ | ||
| arg0("-b", file2) | ||
| } else{ | ||
| cli::cli_abort( | ||
| "{.arg file2} must be BED/GFF/BAM" | ||
| ) | ||
| }, | ||
| arg0("-o", ofile), | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
|
|
||
| # bedtools_getfasta ---- | ||
| bedtools_getfasta <- make_command( | ||
| "bedtools_getfasta", | ||
| function( | ||
| file1, | ||
| file2, | ||
| ofile, | ||
| ..., | ||
| `bedtools getfasta` = NULL | ||
| ){ | ||
| assert_string(`bedtools getfasta`, allow_empty = FALSE, allow_null = TRUE) | ||
| BEDTools_Getfasta$new( | ||
| cmd = `bedtools getfasta`, | ||
| ..., | ||
| file1 = file1, | ||
| file2 = file2, | ||
| ofile = ofile, | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| BEDTools_Getfasta <- R6Class( | ||
| "BEDTools_Getfasta", | ||
| inherit = Command, | ||
| private = list( | ||
| alias = function() "bedtools getfasta", | ||
| setup_help_params = function() "--help", | ||
| setup_command_params = function(file1, file2, ofile){ | ||
| c( | ||
| if (endsWith(file1, ".fa")){ | ||
| arg0("-fi", file1) | ||
| } else{ | ||
| cli::cli_abort( | ||
| "{.arg file1} must be FASTA" | ||
| ) | ||
| }, | ||
| if (endsWith(file2, ".bed")|endsWith(file2, ".gff")){ | ||
| arg0("-bed", file2) | ||
| } else{ | ||
| cli::cli_abort( | ||
| "{.arg file2} must be BED/GFF" | ||
| ) | ||
| }, | ||
| arg0("-fo", ofile), | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
|
|
||
| # bedtools_closest ---- | ||
| bedtools_closest <- make_command( | ||
| "bedtools_closest", | ||
| function( | ||
| file1, | ||
| file2, | ||
| ofile, | ||
| ..., | ||
| `bedtools closest` = NULL | ||
| ){ | ||
| assert_string(`bedtools closest`, allow_empty = FALSE, allow_null = TRUE) | ||
| BEDTools_Closest$new( | ||
| cmd = `bedtools closest`, | ||
| ..., | ||
| file1 = file1, | ||
| file2 = file2, | ||
| ofile = ofile, | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| BEDTools_Closest <- R6Class( | ||
| "BEDTools_Closest", | ||
| inherit = Command, | ||
| private = list( | ||
| alias = function() "bedtools closest", | ||
| setup_help_params = function() "--help", | ||
| setup_command_params = function(file1, file2, ofile){ | ||
| c( | ||
| if (endsWith(file1, ".bed")|endsWith(file1, ".gff")|endsWith(file1, ".vcf")){ | ||
| arg0("-a", file1) | ||
| } else{ | ||
| cli::cli_abort( | ||
| "{.arg file1} must be BED/GFF/VCF" | ||
| ) | ||
| }, | ||
| if (endsWith(file2, ".bed")|endsWith(file2, ".gff")|endsWith(file2, ".vcf")){ | ||
| arg0("-b", file2) | ||
| } else{ | ||
| cli::cli_abort( | ||
| "{.arg file2} must be BED/GFF/VCF" | ||
| ) | ||
| }, | ||
| args("-D"), | ||
| arg0("-o", ofile), | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一般尽量不导致大数量的改变,这样有利于review,这个文件跟此PR功能无关,需保持原状 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我试了下,bedtools命令的帮助文档参数应该是"--help"