Skip to content

Commit

Permalink
Implement optional arguments for bedtools in filter_bed (closes #72)
Browse files Browse the repository at this point in the history
  • Loading branch information
bodkan committed Aug 2, 2022
1 parent a734bb9 commit d846043
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 46 deletions.
8 changes: 5 additions & 3 deletions R/eigenstrat.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ merge_eigenstrat <- function(merged, a, b, strandcheck = "NO") {
#' @param remove Remove sites falling inside the BED file regions? By default,
#' sites that do not overlap BED regions are removed.
#' @param outfile Path to an output snp file with coordinates of excluded sites.
#' @param bedtools_args Optional arguments to `bedtools intersect` such as \code{"-sorted"}
#' or \code{"-sorted -nonamecheck"}.
#'
#' @return Updated S3 EIGENSTRAT data object.
#'
Expand All @@ -147,7 +149,7 @@ merge_eigenstrat <- function(merged, a, b, strandcheck = "NO") {
#' }
#'
#' @export
filter_bed <- function(data, bed, remove = FALSE, outfile = tempfile(fileext = ".snp")) {
filter_bed <- function(data, bed, remove = FALSE, outfile = tempfile(fileext = ".snp"), bedtools_args = "") {
check_type(data, "EIGENSTRAT")

if (file.exists(outfile)) {
Expand Down Expand Up @@ -175,8 +177,8 @@ filter_bed <- function(data, bed, remove = FALSE, outfile = tempfile(fileext = "
# for our purposes, this means either 0 (no overlap) or 1 (overlap)
output <- tempfile()
# run bedtools
sprintf("bedtools intersect %s -c -a %s -b %s > %s",
ifelse(remove, "-v", ""), tmpbed, bed, output) %>% system()
sprintf("bedtools intersect %s -c -a %s -b %s %s > %s",
ifelse(remove, "-v", ""), tmpbed, bed, bedtools_args, output) %>% system()
# collect the results
snp_hits <- readr::read_tsv(output,
col_names = c("chrom", "start", "end", "hit"),
Expand Down
18 changes: 9 additions & 9 deletions docs/articles/qpAdm.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 30 additions & 30 deletions docs/articles/tutorial.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pkgdown_sha: ~
articles:
qpAdm: qpAdm.html
tutorial: tutorial.html
last_built: 2022-08-01T19:54Z
last_built: 2022-08-02T12:29Z

11 changes: 10 additions & 1 deletion docs/reference/filter_bed.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d846043

Please sign in to comment.