├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── R ├── bt.annotate.R ├── bt.bamtobed.R ├── bt.bamtofastq.R ├── bt.bed12tobed6.R ├── bt.bedpetobam.R ├── bt.bedtobam.R ├── bt.closest.R ├── bt.cluster.R ├── bt.complement.R ├── bt.coverage.R ├── bt.expand.R ├── bt.fisher.R ├── bt.flank.R ├── bt.genomecov.R ├── bt.getfasta.R ├── bt.groupby.R ├── bt.igv.R ├── bt.intersect.R ├── bt.jaccard.R ├── bt.links.R ├── bt.makewindows.R ├── bt.map.R ├── bt.maskfasta.R ├── bt.merge.R ├── bt.multicov.R ├── bt.multiinter.R ├── bt.nuc.R ├── bt.overlap.R ├── bt.pairtobed.R ├── bt.pairtopair.R ├── bt.random.R ├── bt.reldist.R ├── bt.sample.R ├── bt.shift.R ├── bt.shuffle.R ├── bt.slop.R ├── bt.sort.R ├── bt.spacing.R ├── bt.split.R ├── bt.subtract.R ├── bt.summary.R ├── bt.tag.R ├── bt.unionbedg.R ├── bt.window.R ├── createOptions.R ├── deleteTempFiles.R ├── establishPaths.R └── zzz.R ├── README.md ├── bedtoolsr.Rproj ├── dev ├── anomalies.json ├── createOptions.R ├── deleteTempFiles.R ├── document.R ├── establishPaths.R ├── makePackage.py └── zzz.R ├── extdata ├── dm6 ├── hg19 ├── hg38 ├── mm10 └── mm9 ├── img └── exampleResults.png ├── inst ├── extdata │ ├── dm6 │ ├── hg19 │ ├── hg38 │ ├── mm10 │ └── mm9 └── tests │ ├── testthat.R │ └── testthat │ ├── test-bt.annotate.R │ ├── test-bt.closest.R │ ├── test-bt.cluster.R │ ├── test-bt.complement.R │ ├── test-bt.coverage.R │ ├── test-bt.expand.R │ ├── test-bt.fisher.R │ ├── test-bt.flank.R │ ├── test-bt.genomecov.R │ ├── test-bt.groupby.R │ ├── test-bt.intersect.R │ ├── test-bt.jaccard.R │ ├── test-bt.makewindows.R │ ├── test-bt.map.R │ ├── test-bt.merge.R │ ├── test-bt.overlap.R │ ├── test-bt.shift.R │ ├── test-bt.shuffle.R │ ├── test-bt.slop.R │ ├── test-bt.sort.R │ ├── test-bt.spacing.R │ ├── test-bt.subtract.R │ ├── test-bt.unionbedg.R │ └── test-bt.window.R ├── man ├── bt.annotate.Rd ├── bt.bamtobed.Rd ├── bt.bamtofastq.Rd ├── bt.bed12tobed6.Rd ├── bt.bedpetobam.Rd ├── bt.bedtobam.Rd ├── bt.closest.Rd ├── bt.cluster.Rd ├── bt.complement.Rd ├── bt.coverage.Rd ├── bt.expand.Rd ├── bt.fisher.Rd ├── bt.flank.Rd ├── bt.genomecov.Rd ├── bt.getfasta.Rd ├── bt.groupby.Rd ├── bt.igv.Rd ├── bt.intersect.Rd ├── bt.jaccard.Rd ├── bt.links.Rd ├── bt.makewindows.Rd ├── bt.map.Rd ├── bt.maskfasta.Rd ├── bt.merge.Rd ├── bt.multicov.Rd ├── bt.multiinter.Rd ├── bt.nuc.Rd ├── bt.overlap.Rd ├── bt.pairtobed.Rd ├── bt.pairtopair.Rd ├── bt.random.Rd ├── bt.reldist.Rd ├── bt.sample.Rd ├── bt.shift.Rd ├── bt.shuffle.Rd ├── bt.slop.Rd ├── bt.sort.Rd ├── bt.spacing.Rd ├── bt.split.Rd ├── bt.subtract.Rd ├── bt.summary.Rd ├── bt.tag.Rd ├── bt.unionbedg.Rd ├── bt.window.Rd ├── createOptions.Rd ├── deleteTempFiles.Rd └── establishPaths.Rd ├── paper ├── paper.bib └── paper.md └── tests ├── testthat.R └── testthat ├── test-bt.annotate.R ├── test-bt.closest.R ├── test-bt.cluster.R ├── test-bt.complement.R ├── test-bt.coverage.R ├── test-bt.expand.R ├── test-bt.fisher.R ├── test-bt.flank.R ├── test-bt.genomecov.R ├── test-bt.groupby.R ├── test-bt.intersect.R ├── test-bt.jaccard.R ├── test-bt.makewindows.R ├── test-bt.map.R ├── test-bt.merge.R ├── test-bt.overlap.R ├── test-bt.shift.R ├── test-bt.shuffle.R ├── test-bt.slop.R ├── test-bt.sort.R ├── test-bt.spacing.R ├── test-bt.subtract.R ├── test-bt.unionbedg.R └── test-bt.window.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^[.].*$ 4 | ^.*/[.].*$ 5 | LICENSE.md 6 | ^\.github$ 7 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/master/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macOS-latest, r: 'release'} 22 | # - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 23 | # - {os: ubuntu-latest, r: 'release'} 24 | # - {os: ubuntu-latest, r: 'oldrel-1'} 25 | 26 | env: 27 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 28 | R_KEEP_PKG_SOURCE: yes 29 | 30 | steps: 31 | # - name: Install bedtools on Linux 32 | # if: runner.os == 'Linux' 33 | # run: sudo apt-get install -y bedtools 34 | 35 | - name: Install bedtools on macOS 36 | if: runner.os == 'macOS' 37 | run: brew install bedtools 38 | 39 | - uses: actions/checkout@v2 40 | 41 | - uses: r-lib/actions/setup-pandoc@v1 42 | 43 | - uses: r-lib/actions/setup-r@v1 44 | with: 45 | r-version: ${{ matrix.config.r }} 46 | http-user-agent: ${{ matrix.config.http-user-agent }} 47 | use-public-rspm: true 48 | 49 | - uses: r-lib/actions/setup-r-dependencies@v1 50 | with: 51 | extra-packages: rcmdcheck 52 | 53 | - uses: r-lib/actions/check-r-package@v1 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .Rproj.user 3 | .Rhistory 4 | .RData 5 | .Ruserdata 6 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: bedtoolsr 2 | Encoding: UTF-8 3 | Type: Package 4 | Title: Bedtools Wrapper 5 | Version: 2.30.0-7 6 | Date: 2025-02-18 7 | Author: Mayura Patwardhan, Craig Wenger, Eric Davis, Doug Phanstiel 8 | Maintainer: Doug Phanstiel 9 | Description: Wrapper library for the bedtools utilities for genome arithmetic. 10 | Imports: 11 | utils 12 | Suggests: 13 | testthat 14 | License: MIT + file LICENSE 15 | RoxygenNote: 7.3.2 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2019 2 | COPYRIGHT HOLDER: Mayura Patwardhan, Craig Wenger, Eric Davis, Doug Phanstiel -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019, Mayura Patwardhan, Craig Wenger, Eric Davis, Doug Phanstiel 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | export(bt.intersect, bt.window, bt.closest, bt.coverage, bt.map, bt.genomecov, bt.merge, bt.cluster, bt.complement, bt.shift, bt.subtract, bt.slop, bt.flank, bt.sort, bt.random, bt.shuffle, bt.sample, bt.spacing, bt.annotate, bt.multiinter, bt.unionbedg, bt.pairtobed, bt.pairtopair, bt.bamtobed, bt.bedtobam, bt.bamtofastq, bt.bedpetobam, bt.bed12tobed6, bt.getfasta, bt.maskfasta, bt.nuc, bt.multicov, bt.tag, bt.jaccard, bt.reldist, bt.fisher, bt.overlap, bt.igv, bt.links, bt.makewindows, bt.groupby, bt.expand, bt.split, bt.summary) 2 | -------------------------------------------------------------------------------- /R/bt.annotate.R: -------------------------------------------------------------------------------- 1 | #' Annotates the depth & breadth of coverage of features from mult. files 2 | #' on the intervals in -i. 3 | #' 4 | #' @param i 5 | #' @param files FILE1 FILE2..FILEn 6 | #' @param names A list of names (one / file) to describe each file in -i. 7 | #' These names will be printed as a header line. 8 | #' 9 | #' @param counts Report the count of features in each file that overlap -i. 10 | #' - Default is to report the fraction of -i covered by each file. 11 | #' 12 | #' @param both Report the counts followed by the percent coverage. 13 | #' - Default is to report the fraction of -i covered by each file. 14 | #' 15 | #' @param s Require same strandedness. That is, only counts overlaps 16 | #' on the _same_ strand. 17 | #' - By default, overlaps are counted without respect to strand. 18 | #' 19 | #' @param S Require different strandedness. That is, only count overlaps 20 | #' on the _opposite_ strand. 21 | #' - By default, overlaps are counted without respect to strand. 22 | #' 23 | #' @param output Output filepath instead of returning output in R. 24 | #' 25 | bt.annotate <- function(i, files, names = NULL, counts = NULL, both = NULL, s = NULL, S = NULL, output = NULL) 26 | { 27 | # Required Inputs 28 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 29 | files <- establishPaths(input=files, name="files", allowRobjects=TRUE) 30 | 31 | options <- "" 32 | 33 | # Options 34 | options <- createOptions(names=c("names", "counts", "both", "s", "S"), values=list(names, counts, both, s, S)) 35 | 36 | # establish output file 37 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 38 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 39 | bedtools.path <- getOption("bedtools.path") 40 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 41 | cmd <- paste0(bedtools.path, "bedtools annotate ", options, " -i ", i[[1]], " -files ", files[[1]], " > ", tempfile) 42 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 43 | if(!is.null(output)) { 44 | if(file.info(tempfile)$size > 0) 45 | file.copy(tempfile, output) 46 | } else { 47 | if(file.info(tempfile)$size > 0) 48 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 49 | else 50 | results <- data.frame() 51 | } 52 | 53 | # Delete temp files 54 | temp.files <- c(tempfile, i[[2]], files[[2]]) 55 | deleteTempFiles(temp.files) 56 | 57 | if(is.null(output)) 58 | return(results) 59 | } -------------------------------------------------------------------------------- /R/bt.bamtobed.R: -------------------------------------------------------------------------------- 1 | #' Converts BAM alignments to BED6 or BEDPE format. 2 | #' 3 | #' @param i 4 | #' @param bedpe Write BEDPE format. 5 | #' - Requires BAM to be grouped or sorted by query. 6 | #' 7 | #' @param mate1 When writing BEDPE (-bedpe) format, 8 | #' always report mate one as the first BEDPE "block". 9 | #' 10 | #' @param bed12 Write "blocked" BED format (aka "BED12"). Forces -split. 11 | #' http://genome-test.cse.ucsc.edu/FAQ/FAQformat#format1 12 | #' 13 | #' @param split Report "split" BAM alignments as separate BED entries. 14 | #' Splits only on N CIGAR operations. 15 | #' 16 | #' @param splitD Split alignments based on N and D CIGAR operators. 17 | #' Forces -split. 18 | #' 19 | #' @param ed Use BAM edit distance (NM tag) for BED score. 20 | #' - Default for BED is to use mapping quality. 21 | #' - Default for BEDPE is to use the minimum of 22 | #' the two mapping qualities for the pair. 23 | #' - When -ed is used with -bedpe, the total edit 24 | #' distance from the two mates is reported. 25 | #' 26 | #' @param tag Use other NUMERIC BAM alignment tag for BED score. 27 | #' - Default for BED is to use mapping quality. 28 | #' Disallowed with BEDPE output. 29 | #' 30 | #' @param color An R,G,B string for the color used with BED12 format. 31 | #' Default is (255,0,0). 32 | #' 33 | #' @param cigar Add the CIGAR string to the BED entry as a 7th column. 34 | #' 35 | #' @param output Output filepath instead of returning output in R. 36 | #' 37 | bt.bamtobed <- function(i, bedpe = NULL, mate1 = NULL, bed12 = NULL, split = NULL, splitD = NULL, ed = NULL, tag = NULL, color = NULL, cigar = NULL, output = NULL) 38 | { 39 | # Required Inputs 40 | i <- establishPaths(input=i, name="i", allowRobjects=FALSE) 41 | 42 | options <- "" 43 | 44 | # Options 45 | options <- createOptions(names=c("bedpe", "mate1", "bed12", "split", "splitD", "ed", "tag", "color", "cigar"), values=list(bedpe, mate1, bed12, split, splitD, ed, tag, color, cigar)) 46 | 47 | # establish output file 48 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 49 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 50 | bedtools.path <- getOption("bedtools.path") 51 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 52 | cmd <- paste0(bedtools.path, "bedtools bamtobed ", options, " -i ", i[[1]], " > ", tempfile) 53 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 54 | if(!is.null(output)) { 55 | if(file.info(tempfile)$size > 0) 56 | file.copy(tempfile, output) 57 | } else { 58 | if(file.info(tempfile)$size > 0) 59 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 60 | else 61 | results <- data.frame() 62 | } 63 | 64 | # Delete temp files 65 | temp.files <- c(tempfile, i[[2]]) 66 | deleteTempFiles(temp.files) 67 | 68 | if(is.null(output)) 69 | return(results) 70 | } -------------------------------------------------------------------------------- /R/bt.bamtofastq.R: -------------------------------------------------------------------------------- 1 | #' Convert BAM alignments to FASTQ files. 2 | #' 3 | #' @param i 4 | #' @param fq 5 | #' @param fq2 FASTQ for second end. Used if BAM contains paired-end data. 6 | #' BAM should be sorted by query name is creating paired FASTQ. 7 | #' 8 | #' @param tags Create FASTQ based on the mate info 9 | #' in the BAM R2 and Q2 tags. 10 | #' 11 | #' @param output Output filepath instead of returning output in R. 12 | #' 13 | bt.bamtofastq <- function(i, fq, fq2 = NULL, tags = NULL, output = NULL) 14 | { 15 | # Required Inputs 16 | i <- establishPaths(input=i, name="i", allowRobjects=FALSE) 17 | fq <- establishPaths(input=fq, name="fq", allowRobjects=FALSE) 18 | 19 | options <- "" 20 | 21 | # Options 22 | options <- createOptions(names=c("fq2", "tags"), values=list(fq2, tags)) 23 | 24 | # establish output file 25 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 26 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 27 | bedtools.path <- getOption("bedtools.path") 28 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 29 | cmd <- paste0(bedtools.path, "bedtools bamtofastq ", options, " -i ", i[[1]], " -fq ", fq[[1]], " > ", tempfile) 30 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 31 | if(!is.null(output)) { 32 | if(file.info(tempfile)$size > 0) 33 | file.copy(tempfile, output) 34 | } else { 35 | if(file.info(tempfile)$size > 0) 36 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 37 | else 38 | results <- data.frame() 39 | } 40 | 41 | # Delete temp files 42 | temp.files <- c(tempfile, i[[2]], fq[[2]]) 43 | deleteTempFiles(temp.files) 44 | 45 | if(is.null(output)) 46 | return(results) 47 | } -------------------------------------------------------------------------------- /R/bt.bed12tobed6.R: -------------------------------------------------------------------------------- 1 | #' Splits BED12 features into discrete BED6 features. 2 | #' 3 | #' @param i 4 | #' @param n Force the score to be the (1-based) block number from the BED12. 5 | #' 6 | #' @param output Output filepath instead of returning output in R. 7 | #' 8 | bt.bed12tobed6 <- function(i, n = NULL, output = NULL) 9 | { 10 | # Required Inputs 11 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 12 | 13 | options <- "" 14 | 15 | # Options 16 | options <- createOptions(names=c("n"), values=list(n)) 17 | 18 | # establish output file 19 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 20 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 21 | bedtools.path <- getOption("bedtools.path") 22 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 23 | cmd <- paste0(bedtools.path, "bedtools bed12tobed6 ", options, " -i ", i[[1]], " > ", tempfile) 24 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 25 | if(!is.null(output)) { 26 | if(file.info(tempfile)$size > 0) 27 | file.copy(tempfile, output) 28 | } else { 29 | if(file.info(tempfile)$size > 0) 30 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 31 | else 32 | results <- data.frame() 33 | } 34 | 35 | # Delete temp files 36 | temp.files <- c(tempfile, i[[2]]) 37 | deleteTempFiles(temp.files) 38 | 39 | if(is.null(output)) 40 | return(results) 41 | } -------------------------------------------------------------------------------- /R/bt.bedpetobam.R: -------------------------------------------------------------------------------- 1 | #' Converts feature records to BAM format. 2 | #' 3 | #' @param i 4 | #' @param g 5 | #' @param mapq Set the mappinq quality for the BAM records. 6 | #' (INT) Default: 255 7 | #' 8 | #' @param ubam Write uncompressed BAM output. Default writes compressed BAM. 9 | #' 10 | #' @param output Output filepath instead of returning output in R. 11 | #' 12 | bt.bedpetobam <- function(i, g, mapq = NULL, ubam = NULL, output = NULL) 13 | { 14 | # Required Inputs 15 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 16 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 17 | 18 | options <- "" 19 | 20 | # Options 21 | options <- createOptions(names=c("mapq", "ubam"), values=list(mapq, ubam)) 22 | 23 | # establish output file 24 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 25 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 26 | bedtools.path <- getOption("bedtools.path") 27 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 28 | cmd <- paste0(bedtools.path, "bedtools bedpetobam ", options, " -i ", i[[1]], " -g ", g[[1]], " > ", tempfile) 29 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 30 | if(!is.null(output)) { 31 | if(file.info(tempfile)$size > 0) 32 | file.copy(tempfile, output) 33 | } else { 34 | if(file.info(tempfile)$size > 0) 35 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 36 | else 37 | results <- data.frame() 38 | } 39 | 40 | # Delete temp files 41 | temp.files <- c(tempfile, i[[2]], g[[2]]) 42 | deleteTempFiles(temp.files) 43 | 44 | if(is.null(output)) 45 | return(results) 46 | } -------------------------------------------------------------------------------- /R/bt.bedtobam.R: -------------------------------------------------------------------------------- 1 | #' Converts feature records to BAM format. 2 | #' 3 | #' @param i 4 | #' @param g 5 | #' @param mapq Set the mappinq quality for the BAM records. 6 | #' (INT) Default: 255 7 | #' 8 | #' @param bed12 The BED file is in BED12 format. The BAM CIGAR 9 | #' string will reflect BED "blocks". 10 | #' 11 | #' @param ubam Write uncompressed BAM output. Default writes compressed BAM. 12 | #' 13 | #' @param output Output filepath instead of returning output in R. 14 | #' 15 | bt.bedtobam <- function(i, g, mapq = NULL, bed12 = NULL, ubam = NULL, output = NULL) 16 | { 17 | # Required Inputs 18 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 19 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 20 | 21 | options <- "" 22 | 23 | # Options 24 | options <- createOptions(names=c("mapq", "bed12", "ubam"), values=list(mapq, bed12, ubam)) 25 | 26 | # establish output file 27 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 28 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 29 | bedtools.path <- getOption("bedtools.path") 30 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 31 | cmd <- paste0(bedtools.path, "bedtools bedtobam ", options, " -i ", i[[1]], " -g ", g[[1]], " > ", tempfile) 32 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 33 | if(!is.null(output)) { 34 | if(file.info(tempfile)$size > 0) 35 | file.copy(tempfile, output) 36 | } else { 37 | if(file.info(tempfile)$size > 0) 38 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 39 | else 40 | results <- data.frame() 41 | } 42 | 43 | # Delete temp files 44 | temp.files <- c(tempfile, i[[2]], g[[2]]) 45 | deleteTempFiles(temp.files) 46 | 47 | if(is.null(output)) 48 | return(results) 49 | } -------------------------------------------------------------------------------- /R/bt.cluster.R: -------------------------------------------------------------------------------- 1 | #' Clusters overlapping/nearby BED/GFF/VCF intervals. 2 | #' 3 | #' @param i 4 | #' @param s Force strandedness. That is, only merge features 5 | #' that are the same strand. 6 | #' - By default, merging is done without respect to strand. 7 | #' 8 | #' @param d Maximum distance between features allowed for features 9 | #' to be merged. 10 | #' - Def. 0. That is, overlapping & book-ended features are merged. 11 | #' - (INTEGER) 12 | #' 13 | #' @param output Output filepath instead of returning output in R. 14 | #' 15 | bt.cluster <- function(i, s = NULL, d = NULL, output = NULL) 16 | { 17 | # Required Inputs 18 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 19 | 20 | options <- "" 21 | 22 | # Options 23 | options <- createOptions(names=c("s", "d"), values=list(s, d)) 24 | 25 | # establish output file 26 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 27 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 28 | bedtools.path <- getOption("bedtools.path") 29 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 30 | cmd <- paste0(bedtools.path, "bedtools cluster ", options, " -i ", i[[1]], " > ", tempfile) 31 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 32 | if(!is.null(output)) { 33 | if(file.info(tempfile)$size > 0) 34 | file.copy(tempfile, output) 35 | } else { 36 | if(file.info(tempfile)$size > 0) 37 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 38 | else 39 | results <- data.frame() 40 | } 41 | 42 | # Delete temp files 43 | temp.files <- c(tempfile, i[[2]]) 44 | deleteTempFiles(temp.files) 45 | 46 | if(is.null(output)) 47 | return(results) 48 | } -------------------------------------------------------------------------------- /R/bt.complement.R: -------------------------------------------------------------------------------- 1 | #' Returns the base pair complement of a feature file. 2 | #' 3 | #' @param i 4 | #' @param g 5 | #' @param L Limit output to solely the chromosomes with records in the input file. 6 | #' 7 | #' @param output Output filepath instead of returning output in R. 8 | #' 9 | bt.complement <- function(i, g, L = NULL, output = NULL) 10 | { 11 | # Required Inputs 12 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 13 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 14 | 15 | options <- "" 16 | 17 | # Options 18 | options <- createOptions(names=c("L"), values=list(L)) 19 | 20 | # establish output file 21 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 22 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 23 | bedtools.path <- getOption("bedtools.path") 24 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 25 | cmd <- paste0(bedtools.path, "bedtools complement ", options, " -i ", i[[1]], " -g ", g[[1]], " > ", tempfile) 26 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 27 | if(!is.null(output)) { 28 | if(file.info(tempfile)$size > 0) 29 | file.copy(tempfile, output) 30 | } else { 31 | if(file.info(tempfile)$size > 0) 32 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 33 | else 34 | results <- data.frame() 35 | } 36 | 37 | # Delete temp files 38 | temp.files <- c(tempfile, i[[2]], g[[2]]) 39 | deleteTempFiles(temp.files) 40 | 41 | if(is.null(output)) 42 | return(results) 43 | } -------------------------------------------------------------------------------- /R/bt.coverage.R: -------------------------------------------------------------------------------- 1 | #' Returns the depth and breadth of coverage of features from B 2 | #' on the intervals in A. 3 | #' 4 | #' @param a 5 | #' @param b 6 | #' @param hist Report a histogram of coverage for each feature in A 7 | #' as well as a summary histogram for _all_ features in A. 8 | #' Output (tab delimited) after each feature in A: 9 | #' 1) depth 10 | #' 2) # bases at depth 11 | #' 3) size of A 12 | #' 4) percent of A at depth 13 | #' 14 | #' @param d Report the depth at each position in each A feature. 15 | #' Positions reported are one based. Each position 16 | #' and depth follow the complete A feature. 17 | #' 18 | #' @param counts Only report the count of overlaps, don't compute fraction, etc. 19 | #' 20 | #' @param mean Report the mean depth of all positions in each A feature. 21 | #' 22 | #' @param s Require same strandedness. That is, only report hits in B 23 | #' that overlap A on the _same_ strand. 24 | #' - By default, overlaps are reported without respect to strand. 25 | #' 26 | #' @param S Require different strandedness. That is, only report hits in B 27 | #' that overlap A on the _opposite_ strand. 28 | #' - By default, overlaps are reported without respect to strand. 29 | #' 30 | #' @param f Minimum overlap required as a fraction of A. 31 | #' - Default is 1E-9 (i.e., 1bp). 32 | #' - FLOAT (e.g. 0.50) 33 | #' 34 | #' @param F Minimum overlap required as a fraction of B. 35 | #' - Default is 1E-9 (i.e., 1bp). 36 | #' - FLOAT (e.g. 0.50) 37 | #' 38 | #' @param r Require that the fraction overlap be reciprocal for A AND B. 39 | #' - In other words, if -f is 0.90 and -r is used, this requires 40 | #' that B overlap 90 percent of A and A _also_ overlaps 90 percent of B. 41 | #' 42 | #' @param e Require that the minimum fraction be satisfied for A OR B. 43 | #' - In other words, if -e is used with -f 0.90 and -F 0.10 this requires 44 | #' that either 90 percent of A is covered OR 10 percent of B is covered. 45 | #' Without -e, both fractions would have to be satisfied. 46 | #' 47 | #' @param split Treat "split" BAM or BED12 entries as distinct BED intervals. 48 | #' 49 | #' @param g Provide a genome file to enforce consistent chromosome sort order 50 | #' across input files. Only applies when used with -sorted option. 51 | #' 52 | #' @param nonamecheck For sorted data, don't throw an error if the file has different naming conventions 53 | #' for the same chromosome. ex. "chr1" vs "chr01". 54 | #' 55 | #' @param sorted Use the "chromsweep" algorithm for sorted (-k1,1 -k2,2n) input. 56 | #' 57 | #' @param bed If using BAM input, write output as BED. 58 | #' 59 | #' @param header Print the header from the A file prior to results. 60 | #' 61 | #' @param nobuf Disable buffered output. Using this option will cause each line 62 | #' of output to be printed as it is generated, rather than saved 63 | #' in a buffer. This will make printing large output files 64 | #' noticeably slower, but can be useful in conjunction with 65 | #' other software tools and scripts that need to process one 66 | #' line of bedtools output at a time. 67 | #' 68 | #' @param iobuf Specify amount of memory to use for input buffer. 69 | #' Takes an integer argument. Optional suffixes K/M/G supported. 70 | #' Note: currently has no effect with compressed files. 71 | #' 72 | #' @param output Output filepath instead of returning output in R. 73 | #' 74 | bt.coverage <- function(a, b, hist = NULL, d = NULL, counts = NULL, mean = NULL, s = NULL, S = NULL, f = NULL, F = NULL, r = NULL, e = NULL, split = NULL, g = NULL, nonamecheck = NULL, sorted = NULL, bed = NULL, header = NULL, nobuf = NULL, iobuf = NULL, output = NULL) 75 | { 76 | # Required Inputs 77 | a <- establishPaths(input=a, name="a", allowRobjects=TRUE) 78 | b <- establishPaths(input=b, name="b", allowRobjects=TRUE) 79 | 80 | options <- "" 81 | 82 | # Options 83 | options <- createOptions(names=c("hist", "d", "counts", "mean", "s", "S", "f", "F", "r", "e", "split", "g", "nonamecheck", "sorted", "bed", "header", "nobuf", "iobuf"), values=list(hist, d, counts, mean, s, S, f, F, r, e, split, g, nonamecheck, sorted, bed, header, nobuf, iobuf)) 84 | 85 | # establish output file 86 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 87 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 88 | bedtools.path <- getOption("bedtools.path") 89 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 90 | cmd <- paste0(bedtools.path, "bedtools coverage ", options, " -a ", a[[1]], " -b ", b[[1]], " > ", tempfile) 91 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 92 | if(!is.null(output)) { 93 | if(file.info(tempfile)$size > 0) 94 | file.copy(tempfile, output) 95 | } else { 96 | if(file.info(tempfile)$size > 0) 97 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 98 | else 99 | results <- data.frame() 100 | } 101 | 102 | # Delete temp files 103 | temp.files <- c(tempfile, a[[2]], b[[2]]) 104 | deleteTempFiles(temp.files) 105 | 106 | if(is.null(output)) 107 | return(results) 108 | } -------------------------------------------------------------------------------- /R/bt.expand.R: -------------------------------------------------------------------------------- 1 | #' Replicate lines in a file based on columns of comma-separated values. 2 | #' 3 | #' @param i 4 | #' @param c Specify the column (1-based) that should be summarized. 5 | #' - Required. 6 | #' 7 | #' @param output Output filepath instead of returning output in R. 8 | #' 9 | bt.expand <- function(i, c = NULL, output = NULL) 10 | { 11 | # Required Inputs 12 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 13 | 14 | options <- "" 15 | 16 | # Options 17 | options <- createOptions(names=c("c"), values=list(c)) 18 | 19 | # establish output file 20 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 21 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 22 | bedtools.path <- getOption("bedtools.path") 23 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 24 | cmd <- paste0(bedtools.path, "bedtools expand ", options, " -i ", i[[1]], " > ", tempfile) 25 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 26 | if(!is.null(output)) { 27 | if(file.info(tempfile)$size > 0) 28 | file.copy(tempfile, output) 29 | } else { 30 | if(file.info(tempfile)$size > 0) 31 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 32 | else 33 | results <- data.frame() 34 | } 35 | 36 | # Delete temp files 37 | temp.files <- c(tempfile, i[[2]]) 38 | deleteTempFiles(temp.files) 39 | 40 | if(is.null(output)) 41 | return(results) 42 | } -------------------------------------------------------------------------------- /R/bt.fisher.R: -------------------------------------------------------------------------------- 1 | #' Calculate Fisher statistic b/w two feature files. 2 | #' 3 | #' @param a 4 | #' @param b 5 | #' @param g 6 | #' @param m Merge overlapping intervals before 7 | #' - looking at overlap. 8 | #' 9 | #' @param s Require same strandedness. That is, only report hits in B 10 | #' that overlap A on the _same_ strand. 11 | #' - By default, overlaps are reported without respect to strand. 12 | #' 13 | #' @param S Require different strandedness. That is, only report hits in B 14 | #' that overlap A on the _opposite_ strand. 15 | #' - By default, overlaps are reported without respect to strand. 16 | #' 17 | #' @param f Minimum overlap required as a fraction of A. 18 | #' - Default is 1E-9 (i.e., 1bp). 19 | #' - FLOAT (e.g. 0.50) 20 | #' 21 | #' @param F Minimum overlap required as a fraction of B. 22 | #' - Default is 1E-9 (i.e., 1bp). 23 | #' - FLOAT (e.g. 0.50) 24 | #' 25 | #' @param r Require that the fraction overlap be reciprocal for A AND B. 26 | #' - In other words, if -f is 0.90 and -r is used, this requires 27 | #' that B overlap 90 percent of A and A _also_ overlaps 90 percent of B. 28 | #' 29 | #' @param e Require that the minimum fraction be satisfied for A OR B. 30 | #' - In other words, if -e is used with -f 0.90 and -F 0.10 this requires 31 | #' that either 90 percent of A is covered OR 10 percent of B is covered. 32 | #' Without -e, both fractions would have to be satisfied. 33 | #' 34 | #' @param split Treat "split" BAM or BED12 entries as distinct BED intervals. 35 | #' 36 | #' @param nonamecheck For sorted data, don't throw an error if the file has different naming conventions 37 | #' for the same chromosome. ex. "chr1" vs "chr01". 38 | #' 39 | #' @param bed If using BAM input, write output as BED. 40 | #' 41 | #' @param header Print the header from the A file prior to results. 42 | #' 43 | #' @param nobuf Disable buffered output. Using this option will cause each line 44 | #' of output to be printed as it is generated, rather than saved 45 | #' in a buffer. This will make printing large output files 46 | #' noticeably slower, but can be useful in conjunction with 47 | #' other software tools and scripts that need to process one 48 | #' line of bedtools output at a time. 49 | #' 50 | #' @param iobuf Specify amount of memory to use for input buffer. 51 | #' Takes an integer argument. Optional suffixes K/M/G supported. 52 | #' Note: currently has no effect with compressed files. 53 | #' 54 | #' @param output Output filepath instead of returning output in R. 55 | #' 56 | bt.fisher <- function(a, b, g, m = NULL, s = NULL, S = NULL, f = NULL, F = NULL, r = NULL, e = NULL, split = NULL, nonamecheck = NULL, bed = NULL, header = NULL, nobuf = NULL, iobuf = NULL, output = NULL) 57 | { 58 | # Required Inputs 59 | a <- establishPaths(input=a, name="a", allowRobjects=TRUE) 60 | b <- establishPaths(input=b, name="b", allowRobjects=TRUE) 61 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 62 | 63 | options <- "" 64 | 65 | # Options 66 | options <- createOptions(names=c("m", "s", "S", "f", "F", "r", "e", "split", "nonamecheck", "bed", "header", "nobuf", "iobuf"), values=list(m, s, S, f, F, r, e, split, nonamecheck, bed, header, nobuf, iobuf)) 67 | 68 | # establish output file 69 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 70 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 71 | bedtools.path <- getOption("bedtools.path") 72 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 73 | cmd <- paste0(bedtools.path, "bedtools fisher ", options, " -a ", a[[1]], " -b ", b[[1]], " -g ", g[[1]], " > ", tempfile) 74 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 75 | if(!is.null(output)) { 76 | if(file.info(tempfile)$size > 0) 77 | file.copy(tempfile, output) 78 | } else { 79 | if(file.info(tempfile)$size > 0) 80 | results <- utils::read.table(tempfile, header=TRUE, sep="\t", quote='') 81 | else 82 | results <- data.frame() 83 | } 84 | 85 | # Delete temp files 86 | temp.files <- c(tempfile, a[[2]], b[[2]], g[[2]]) 87 | deleteTempFiles(temp.files) 88 | 89 | if(is.null(output)) 90 | return(results) 91 | } -------------------------------------------------------------------------------- /R/bt.flank.R: -------------------------------------------------------------------------------- 1 | #' Creates flanking interval(s) for each BED/GFF/VCF feature. 2 | #' 3 | #' @param i 4 | #' @param g 5 | #' @param b Create flanking interval(s) using -b base pairs in each direction. 6 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 7 | #' 8 | #' @param l The number of base pairs that a flank should start from 9 | #' orig. start coordinate. 10 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 11 | #' 12 | #' @param r The number of base pairs that a flank should end from 13 | #' orig. end coordinate. 14 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 15 | #' 16 | #' @param s Define -l and -r based on strand. 17 | #' E.g. if used, -l 500 for a negative-stranded feature, 18 | #' it will start the flank 500 bp downstream. Default = false. 19 | #' 20 | #' @param pct Define -l and -r as a fraction of the feature's length. 21 | #' E.g. if used on a 1000bp feature, -l 0.50, 22 | #' will add 500 bp "upstream". Default = false. 23 | #' 24 | #' @param header Print the header from the input file prior to results. 25 | #' 26 | #' @param output Output filepath instead of returning output in R. 27 | #' 28 | bt.flank <- function(i, g, b = NULL, l = NULL, r = NULL, s = NULL, pct = NULL, header = NULL, output = NULL) 29 | { 30 | # Required Inputs 31 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 32 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 33 | 34 | options <- "" 35 | 36 | # Options 37 | options <- createOptions(names=c("b", "l", "r", "s", "pct", "header"), values=list(b, l, r, s, pct, header)) 38 | 39 | # establish output file 40 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 41 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 42 | bedtools.path <- getOption("bedtools.path") 43 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 44 | cmd <- paste0(bedtools.path, "bedtools flank ", options, " -i ", i[[1]], " -g ", g[[1]], " > ", tempfile) 45 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 46 | if(!is.null(output)) { 47 | if(file.info(tempfile)$size > 0) 48 | file.copy(tempfile, output) 49 | } else { 50 | if(file.info(tempfile)$size > 0) 51 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 52 | else 53 | results <- data.frame() 54 | } 55 | 56 | # Delete temp files 57 | temp.files <- c(tempfile, i[[2]], g[[2]]) 58 | deleteTempFiles(temp.files) 59 | 60 | if(is.null(output)) 61 | return(results) 62 | } -------------------------------------------------------------------------------- /R/bt.getfasta.R: -------------------------------------------------------------------------------- 1 | #' Extract DNA sequences from a fasta file based on feature coordinates. 2 | #' 3 | #' @param fi 4 | #' @param bed 5 | #' @param fo Output file (opt., default is STDOUT 6 | #' 7 | #' @param name Use the name field and coordinates for the FASTA header 8 | #' 9 | #' @param nameplus (deprecated) Use the name field and coordinates for the FASTA header 10 | #' 11 | #' @param nameOnly Use the name field for the FASTA header 12 | #' 13 | #' @param split Given BED12 fmt., extract and concatenate the sequences 14 | #' from the BED "blocks" (e.g., exons) 15 | #' 16 | #' @param tab Write output in TAB delimited format. 17 | #' 18 | #' @param bedOut Report extract sequences in a tab-delimited BED format instead of in FASTA format. 19 | #' - Default is FASTA format. 20 | #' 21 | #' @param s Force strandedness. If the feature occupies the antisense, 22 | #' strand, the sequence will be reverse complemented. 23 | #' - By default, strand information is ignored. 24 | #' 25 | #' @param fullHeader Use full fasta header. 26 | #' - By default, only the word before the first space or tab 27 | #' is used. 28 | #' 29 | #' @param rna The FASTA is RNA not DNA. Reverse complementation handled accordingly. 30 | #' 31 | #' @param output Output filepath instead of returning output in R. 32 | #' 33 | bt.getfasta <- function(fi, bed, fo = NULL, name = NULL, nameplus = NULL, nameOnly = NULL, split = NULL, tab = NULL, bedOut = NULL, s = NULL, fullHeader = NULL, rna = NULL, output = NULL) 34 | { 35 | # Required Inputs 36 | fi <- establishPaths(input=fi, name="fi", allowRobjects=TRUE) 37 | bed <- establishPaths(input=bed, name="bed", allowRobjects=TRUE) 38 | 39 | options <- "" 40 | 41 | # Options 42 | options <- createOptions(names=c("fo", "name", "name+", "nameOnly", "split", "tab", "bedOut", "s", "fullHeader", "rna"), values=list(fo, name, nameplus, nameOnly, split, tab, bedOut, s, fullHeader, rna)) 43 | 44 | # establish output file 45 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 46 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 47 | bedtools.path <- getOption("bedtools.path") 48 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 49 | cmd <- paste0(bedtools.path, "bedtools getfasta ", options, " -fi ", fi[[1]], " -bed ", bed[[1]], " > ", tempfile) 50 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 51 | if(!is.null(output)) { 52 | if(file.info(tempfile)$size > 0) 53 | file.copy(tempfile, output) 54 | } else { 55 | if(file.info(tempfile)$size > 0) 56 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 57 | else 58 | results <- data.frame() 59 | } 60 | 61 | # Delete temp files 62 | temp.files <- c(tempfile, fi[[2]], bed[[2]]) 63 | deleteTempFiles(temp.files) 64 | 65 | if(is.null(output)) 66 | return(results) 67 | } -------------------------------------------------------------------------------- /R/bt.groupby.R: -------------------------------------------------------------------------------- 1 | #' Summarizes a dataset column based upon 2 | #' common column groupings. Akin to the SQL "group by" command. 3 | #' 4 | #' @param i 5 | #' @param g 6 | #' @param c 7 | #' @param o 8 | #' @param full Print all columns from input file. The first line in the group is used. 9 | #' Default: print only grouped columns. 10 | #' 11 | #' @param inheader Input file has a header line - the first line will be ignored. 12 | #' 13 | #' @param outheader Print header line in the output, detailing the column names. 14 | #' If the input file has headers (-inheader), the output file 15 | #' will use the input's column names. 16 | #' If the input file has no headers, the output file 17 | #' will use "col_1", "col_2", etc. as the column names. 18 | #' 19 | #' @param header same as '-inheader -outheader' 20 | #' 21 | #' @param ignorecase Group values regardless of upper/lower case. 22 | #' 23 | #' @param prec Sets the decimal precision for output (Default: 5) 24 | #' 25 | #' @param delim Specify a custom delimiter for the collapse operations. 26 | #' - Example: -delim "|" 27 | #' - Default: ",". 28 | #' 29 | #' @param output Output filepath instead of returning output in R. 30 | #' 31 | bt.groupby <- function(i, g = NULL, c = NULL, o = NULL, full = NULL, inheader = NULL, outheader = NULL, header = NULL, ignorecase = NULL, prec = NULL, delim = NULL, output = NULL) 32 | { 33 | # Required Inputs 34 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 35 | 36 | options <- "" 37 | 38 | # Options 39 | options <- createOptions(names=c("g", "c", "o", "full", "inheader", "outheader", "header", "ignorecase", "prec", "delim"), values=list(g, c, o, full, inheader, outheader, header, ignorecase, prec, delim)) 40 | 41 | # establish output file 42 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 43 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 44 | bedtools.path <- getOption("bedtools.path") 45 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 46 | cmd <- paste0(bedtools.path, "bedtools groupby ", options, " -i ", i[[1]], " > ", tempfile) 47 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 48 | if(!is.null(output)) { 49 | if(file.info(tempfile)$size > 0) 50 | file.copy(tempfile, output) 51 | } else { 52 | if(file.info(tempfile)$size > 0) 53 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 54 | else 55 | results <- data.frame() 56 | } 57 | 58 | # Delete temp files 59 | temp.files <- c(tempfile, i[[2]]) 60 | deleteTempFiles(temp.files) 61 | 62 | if(is.null(output)) 63 | return(results) 64 | } -------------------------------------------------------------------------------- /R/bt.igv.R: -------------------------------------------------------------------------------- 1 | #' Creates a batch script to create IGV images 2 | #' at each interval defined in a BED/GFF/VCF file. 3 | #' 4 | #' @param i 5 | #' @param path The full path to which the IGV snapshots should be written. 6 | #' (STRING) Default: ./ 7 | #' 8 | #' @param sess The full path to an existing IGV session file to be 9 | #' loaded prior to taking snapshots. 10 | #' (STRING) Default is for no session to be loaded. 11 | #' 12 | #' @param sort The type of BAM sorting you would like to apply to each image. 13 | #' Options: base, position, strand, quality, sample, and readGroup 14 | #' Default is to apply no sorting at all. 15 | #' 16 | #' @param clps Collapse the aligned reads prior to taking a snapshot. 17 | #' Default is to no collapse. 18 | #' 19 | #' @param name Use the "name" field (column 4) for each image's filename. 20 | #' Default is to use the "chr:start-pos.ext". 21 | #' 22 | #' @param slop Number of flanking base pairs on the left & right of the image. 23 | #' - (INT) Default = 0. 24 | #' 25 | #' @param img The type of image to be created. 26 | #' Options: png, eps, svg 27 | #' Default is png. 28 | #' 29 | #' @param output Output filepath instead of returning output in R. 30 | #' 31 | bt.igv <- function(i, path = NULL, sess = NULL, sort = NULL, clps = NULL, name = NULL, slop = NULL, img = NULL, output = NULL) 32 | { 33 | # Required Inputs 34 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 35 | 36 | options <- "" 37 | 38 | # Options 39 | options <- createOptions(names=c("path", "sess", "sort", "clps", "name", "slop", "img"), values=list(path, sess, sort, clps, name, slop, img)) 40 | 41 | # establish output file 42 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 43 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 44 | bedtools.path <- getOption("bedtools.path") 45 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 46 | cmd <- paste0(bedtools.path, "bedtools igv ", options, " -i ", i[[1]], " > ", tempfile) 47 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 48 | if(!is.null(output)) { 49 | if(file.info(tempfile)$size > 0) 50 | file.copy(tempfile, output) 51 | } else { 52 | if(file.info(tempfile)$size > 0) 53 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 54 | else 55 | results <- data.frame() 56 | } 57 | 58 | # Delete temp files 59 | temp.files <- c(tempfile, i[[2]]) 60 | deleteTempFiles(temp.files) 61 | 62 | if(is.null(output)) 63 | return(results) 64 | } -------------------------------------------------------------------------------- /R/bt.jaccard.R: -------------------------------------------------------------------------------- 1 | #' Calculate Jaccard statistic b/w two feature files. 2 | #' Jaccard is the length of the intersection over the union. 3 | #' Values range from 0 (no intersection) to 1 (self intersection). 4 | #' 5 | #' @param a 6 | #' @param b 7 | #' @param s Require same strandedness. That is, only report hits in B 8 | #' that overlap A on the _same_ strand. 9 | #' - By default, overlaps are reported without respect to strand. 10 | #' 11 | #' @param S Require different strandedness. That is, only report hits in B 12 | #' that overlap A on the _opposite_ strand. 13 | #' - By default, overlaps are reported without respect to strand. 14 | #' 15 | #' @param f Minimum overlap required as a fraction of A. 16 | #' - Default is 1E-9 (i.e., 1bp). 17 | #' - FLOAT (e.g. 0.50) 18 | #' 19 | #' @param F Minimum overlap required as a fraction of B. 20 | #' - Default is 1E-9 (i.e., 1bp). 21 | #' - FLOAT (e.g. 0.50) 22 | #' 23 | #' @param r Require that the fraction overlap be reciprocal for A AND B. 24 | #' - In other words, if -f is 0.90 and -r is used, this requires 25 | #' that B overlap 90 percent of A and A _also_ overlaps 90 percent of B. 26 | #' 27 | #' @param e Require that the minimum fraction be satisfied for A OR B. 28 | #' - In other words, if -e is used with -f 0.90 and -F 0.10 this requires 29 | #' that either 90 percent of A is covered OR 10 percent of B is covered. 30 | #' Without -e, both fractions would have to be satisfied. 31 | #' 32 | #' @param split Treat "split" BAM or BED12 entries as distinct BED intervals. 33 | #' 34 | #' @param g Provide a genome file to enforce consistent chromosome sort order 35 | #' across input files. Only applies when used with -sorted option. 36 | #' 37 | #' @param nonamecheck For sorted data, don't throw an error if the file has different naming conventions 38 | #' for the same chromosome. ex. "chr1" vs "chr01". 39 | #' 40 | #' @param bed If using BAM input, write output as BED. 41 | #' 42 | #' @param header Print the header from the A file prior to results. 43 | #' 44 | #' @param nobuf Disable buffered output. Using this option will cause each line 45 | #' of output to be printed as it is generated, rather than saved 46 | #' in a buffer. This will make printing large output files 47 | #' noticeably slower, but can be useful in conjunction with 48 | #' other software tools and scripts that need to process one 49 | #' line of bedtools output at a time. 50 | #' 51 | #' @param iobuf Specify amount of memory to use for input buffer. 52 | #' Takes an integer argument. Optional suffixes K/M/G supported. 53 | #' Note: currently has no effect with compressed files. 54 | #' 55 | #' @param output Output filepath instead of returning output in R. 56 | #' 57 | bt.jaccard <- function(a, b, s = NULL, S = NULL, f = NULL, F = NULL, r = NULL, e = NULL, split = NULL, g = NULL, nonamecheck = NULL, bed = NULL, header = NULL, nobuf = NULL, iobuf = NULL, output = NULL) 58 | { 59 | # Required Inputs 60 | a <- establishPaths(input=a, name="a", allowRobjects=TRUE) 61 | b <- establishPaths(input=b, name="b", allowRobjects=TRUE) 62 | 63 | options <- "" 64 | 65 | # Options 66 | options <- createOptions(names=c("s", "S", "f", "F", "r", "e", "split", "g", "nonamecheck", "bed", "header", "nobuf", "iobuf"), values=list(s, S, f, F, r, e, split, g, nonamecheck, bed, header, nobuf, iobuf)) 67 | 68 | # establish output file 69 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 70 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 71 | bedtools.path <- getOption("bedtools.path") 72 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 73 | cmd <- paste0(bedtools.path, "bedtools jaccard ", options, " -a ", a[[1]], " -b ", b[[1]], " > ", tempfile) 74 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 75 | if(!is.null(output)) { 76 | if(file.info(tempfile)$size > 0) 77 | file.copy(tempfile, output) 78 | } else { 79 | if(file.info(tempfile)$size > 0) 80 | results <- utils::read.table(tempfile, header=TRUE, sep="\t", quote='') 81 | else 82 | results <- data.frame() 83 | } 84 | 85 | # Delete temp files 86 | temp.files <- c(tempfile, a[[2]], b[[2]]) 87 | deleteTempFiles(temp.files) 88 | 89 | if(is.null(output)) 90 | return(results) 91 | } -------------------------------------------------------------------------------- /R/bt.links.R: -------------------------------------------------------------------------------- 1 | #' Creates HTML links to an UCSC Genome Browser from a feature file. 2 | #' 3 | #' @param i > out.html 4 | #' @param base The browser basename. Default: http://genome.ucsc.edu 5 | #' 6 | #' @param org The organism. Default: human 7 | #' 8 | #' @param db The build. Default: hg18 9 | #' 10 | #' @param output Output filepath instead of returning output in R. 11 | #' 12 | bt.links <- function(i, base = NULL, org = NULL, db = NULL, output = NULL) 13 | { 14 | # Required Inputs 15 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 16 | 17 | options <- "" 18 | 19 | # Options 20 | options <- createOptions(names=c("base", "org", "db"), values=list(base, org, db)) 21 | 22 | # establish output file 23 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 24 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 25 | bedtools.path <- getOption("bedtools.path") 26 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 27 | cmd <- paste0(bedtools.path, "bedtools links ", options, " -i ", i[[1]], " > ", tempfile) 28 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 29 | if(!is.null(output)) { 30 | if(file.info(tempfile)$size > 0) 31 | file.copy(tempfile, output) 32 | } else { 33 | if(file.info(tempfile)$size > 0) 34 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 35 | else 36 | results <- data.frame() 37 | } 38 | 39 | # Delete temp files 40 | temp.files <- c(tempfile, i[[2]]) 41 | deleteTempFiles(temp.files) 42 | 43 | if(is.null(output)) 44 | return(results) 45 | } -------------------------------------------------------------------------------- /R/bt.makewindows.R: -------------------------------------------------------------------------------- 1 | #' Makes adjacent or sliding windows across a genome or BED file. 2 | #' 3 | #' @param g OR 4 | #' @param b 5 | #' @param w OR 6 | #' @param s 7 | #' Step size: i.e., how many base pairs to step before 8 | #' creating a new window. Used to create "sliding" windows. 9 | #' - Defaults to window size (non-sliding windows). 10 | #' 11 | #' @param n 12 | #' @param reverse 13 | #' Reverse numbering of windows in the output, i.e. report 14 | #' windows in decreasing order 15 | #' 16 | #' @param i src|winnum|srcwinnum 17 | #' The default output is 3 columns: chrom, start, end . 18 | #' With this option, a name column will be added. 19 | #' "-i src" - use the source interval's name. 20 | #' "-i winnum" - use the window number as the ID (e.g. 1,2,3,4...). 21 | #' "-i srcwinnum" - use the source interval's name with the window number. 22 | #' See below for usage examples. 23 | #' 24 | #' @param output Output filepath instead of returning output in R. 25 | #' 26 | bt.makewindows <- function(g = NULL, b = NULL, w = NULL, s = NULL, n = NULL, reverse = NULL, i = NULL, output = NULL) 27 | { 28 | # Required Inputs 29 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 30 | b <- establishPaths(input=b, name="b", allowRobjects=TRUE) 31 | 32 | options <- "" 33 | 34 | # Options 35 | options <- createOptions(names=c("w", "s", "n", "reverse", "i"), values=list(w, s, n, reverse, i)) 36 | 37 | # establish output file 38 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 39 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 40 | bedtools.path <- getOption("bedtools.path") 41 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 42 | cmd <- paste0(bedtools.path, "bedtools makewindows ", options, ifelse(!is.null(g), paste0(" -g ", g[[1]]), ""), ifelse(!is.null(b), paste0(" -b ", b[[1]]), ""), " > ", tempfile) 43 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 44 | if(!is.null(output)) { 45 | if(file.info(tempfile)$size > 0) 46 | file.copy(tempfile, output) 47 | } else { 48 | if(file.info(tempfile)$size > 0) 49 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 50 | else 51 | results <- data.frame() 52 | } 53 | 54 | # Delete temp files 55 | temp.files <- c(tempfile, g[[2]], b[[2]]) 56 | deleteTempFiles(temp.files) 57 | 58 | if(is.null(output)) 59 | return(results) 60 | } -------------------------------------------------------------------------------- /R/bt.maskfasta.R: -------------------------------------------------------------------------------- 1 | #' Mask a fasta file based on feature coordinates. 2 | #' 3 | #' @param fi 4 | #' @param fo 5 | #' @param bed 6 | #' @param soft Enforce "soft" masking. 7 | #' Mask with lower-case bases, instead of masking with Ns. 8 | #' 9 | #' @param mc Replace masking character. 10 | #' Use another character, instead of masking with Ns. 11 | #' 12 | #' @param fullHeader Use full fasta header. 13 | #' By default, only the word before the first space or tab 14 | #' is used. 15 | #' 16 | #' @param output Output filepath instead of returning output in R. 17 | #' 18 | bt.maskfasta <- function(fi, fo, bed, soft = NULL, mc = NULL, fullHeader = NULL, output = NULL) 19 | { 20 | # Required Inputs 21 | fi <- establishPaths(input=fi, name="fi", allowRobjects=TRUE) 22 | fo <- establishPaths(input=fo, name="fo", allowRobjects=TRUE) 23 | bed <- establishPaths(input=bed, name="bed", allowRobjects=TRUE) 24 | 25 | options <- "" 26 | 27 | # Options 28 | options <- createOptions(names=c("soft", "mc", "fullHeader"), values=list(soft, mc, fullHeader)) 29 | 30 | # establish output file 31 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 32 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 33 | bedtools.path <- getOption("bedtools.path") 34 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 35 | cmd <- paste0(bedtools.path, "bedtools maskfasta ", options, " -fi ", fi[[1]], " -fo ", fo[[1]], " -bed ", bed[[1]], " > ", tempfile) 36 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 37 | if(!is.null(output)) { 38 | if(file.info(tempfile)$size > 0) 39 | file.copy(tempfile, output) 40 | } else { 41 | if(file.info(tempfile)$size > 0) 42 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 43 | else 44 | results <- data.frame() 45 | } 46 | 47 | # Delete temp files 48 | temp.files <- c(tempfile, fi[[2]], fo[[2]], bed[[2]]) 49 | deleteTempFiles(temp.files) 50 | 51 | if(is.null(output)) 52 | return(results) 53 | } -------------------------------------------------------------------------------- /R/bt.merge.R: -------------------------------------------------------------------------------- 1 | #' Merges overlapping BED/GFF/VCF entries into a single interval. 2 | #' 3 | #' @param i 4 | #' @param s Force strandedness. That is, only merge features 5 | #' that are on the same strand. 6 | #' - By default, merging is done without respect to strand. 7 | #' 8 | #' @param S Force merge for one specific strand only. 9 | #' Follow with + or - to force merge from only 10 | #' the forward or reverse strand, respectively. 11 | #' - By default, merging is done without respect to strand. 12 | #' 13 | #' @param d Maximum distance between features allowed for features 14 | #' to be merged. 15 | #' - Def. 0. That is, overlapping & book-ended features are merged. 16 | #' - (INTEGER) 17 | #' - Note: negative values enforce the number of b.p. required for overlap. 18 | #' 19 | #' @param c Specify columns from the B file to map onto intervals in A. 20 | #' Default: 5. 21 | #' Multiple columns can be specified in a comma-delimited list. 22 | #' 23 | #' @param o Specify the operation that should be applied to -c. 24 | #' Valid operations: 25 | #' sum, min, max, absmin, absmax, 26 | #' mean, median, mode, antimode 27 | #' stdev, sstdev 28 | #' collapse (i.e., print a delimited list (duplicates allowed)), 29 | #' distinct (i.e., print a delimited list (NO duplicates allowed)), 30 | #' distinct_sort_num (as distinct, sorted numerically, ascending), 31 | #' distinct_sort_num_desc (as distinct, sorted numerically, desscending), 32 | #' distinct_only (delimited list of only unique values), 33 | #' count 34 | #' count_distinct (i.e., a count of the unique values in the column), 35 | #' first (i.e., just the first value in the column), 36 | #' last (i.e., just the last value in the column), 37 | #' Default: sum 38 | #' Multiple operations can be specified in a comma-delimited list. 39 | #' If there is only column, but multiple operations, all operations will be 40 | #' applied on that column. Likewise, if there is only one operation, but 41 | #' multiple columns, that operation will be applied to all columns. 42 | #' Otherwise, the number of columns must match the the number of operations, 43 | #' and will be applied in respective order. 44 | #' E.g., "-c 5,4,6 -o sum,mean,count" will give the sum of column 5, 45 | #' the mean of column 4, and the count of column 6. 46 | #' The order of output columns will match the ordering given in the command. 47 | #' 48 | #' @param delim Specify a custom delimiter for the collapse operations. 49 | #' - Example: -delim "|" 50 | #' - Default: ",". 51 | #' 52 | #' @param prec Sets the decimal precision for output (Default: 5) 53 | #' 54 | #' @param bed If using BAM input, write output as BED. 55 | #' 56 | #' @param header Print the header from the A file prior to results. 57 | #' 58 | #' @param nobuf Disable buffered output. Using this option will cause each line 59 | #' of output to be printed as it is generated, rather than saved 60 | #' in a buffer. This will make printing large output files 61 | #' noticeably slower, but can be useful in conjunction with 62 | #' other software tools and scripts that need to process one 63 | #' line of bedtools output at a time. 64 | #' 65 | #' @param iobuf Specify amount of memory to use for input buffer. 66 | #' Takes an integer argument. Optional suffixes K/M/G supported. 67 | #' Note: currently has no effect with compressed files. 68 | #' 69 | #' @param output Output filepath instead of returning output in R. 70 | #' 71 | bt.merge <- function(i, s = NULL, S = NULL, d = NULL, c = NULL, o = NULL, delim = NULL, prec = NULL, bed = NULL, header = NULL, nobuf = NULL, iobuf = NULL, output = NULL) 72 | { 73 | # Required Inputs 74 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 75 | 76 | options <- "" 77 | 78 | # Options 79 | options <- createOptions(names=c("s", "S", "d", "c", "o", "delim", "prec", "bed", "header", "nobuf", "iobuf"), values=list(s, S, d, c, o, delim, prec, bed, header, nobuf, iobuf)) 80 | 81 | # establish output file 82 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 83 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 84 | bedtools.path <- getOption("bedtools.path") 85 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 86 | cmd <- paste0(bedtools.path, "bedtools merge ", options, " -i ", i[[1]], " > ", tempfile) 87 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 88 | if(!is.null(output)) { 89 | if(file.info(tempfile)$size > 0) 90 | file.copy(tempfile, output) 91 | } else { 92 | if(file.info(tempfile)$size > 0) 93 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 94 | else 95 | results <- data.frame() 96 | } 97 | 98 | # Delete temp files 99 | temp.files <- c(tempfile, i[[2]]) 100 | deleteTempFiles(temp.files) 101 | 102 | if(is.null(output)) 103 | return(results) 104 | } -------------------------------------------------------------------------------- /R/bt.multicov.R: -------------------------------------------------------------------------------- 1 | #' Counts sequence coverage for multiple bams at specific loci. 2 | #' 3 | #' @param bams aln.1.bam aln.2.bam ... aln.n.bam 4 | #' @param bed 5 | #' @param split Treat "split" BAM or BED12 entries as distinct BED intervals. 6 | #' 7 | #' @param s Require same strandedness. That is, only report hits in B 8 | #' that overlap A on the _same_ strand. 9 | #' - By default, overlaps are reported without respect to strand. 10 | #' 11 | #' @param S Require different strandedness. That is, only report hits in B 12 | #' that overlap A on the _opposite_ strand. 13 | #' - By default, overlaps are reported without respect to strand. 14 | #' 15 | #' @param f Minimum overlap required as a fraction of each -bed record. 16 | #' - Default is 1E-9 (i.e., 1bp). 17 | #' - FLOAT (e.g. 0.50) 18 | #' 19 | #' @param r Require that the fraction overlap be reciprocal for each -bed and B. 20 | #' - In other words, if -f is 0.90 and -r is used, this requires 21 | #' that B overlap 90 percent of each -bed and the -bed record _also_ overlaps 90 percent of B. 22 | #' 23 | #' @param q Minimum mapping quality allowed. Default is 0. 24 | #' 25 | #' @param D Include duplicate reads. Default counts non-duplicates only 26 | #' 27 | #' @param F Include failed-QC reads. Default counts pass-QC reads only 28 | #' 29 | #' @param p Only count proper pairs. Default counts all alignments with 30 | #' MAPQ > -q argument, regardless of the BAM FLAG field. 31 | #' 32 | #' @param output Output filepath instead of returning output in R. 33 | #' 34 | bt.multicov <- function(bams, bed, split = NULL, s = NULL, S = NULL, f = NULL, r = NULL, q = NULL, D = NULL, F = NULL, p = NULL, output = NULL) 35 | { 36 | # Required Inputs 37 | bams <- establishPaths(input=bams, name="bams", allowRobjects=TRUE) 38 | bed <- establishPaths(input=bed, name="bed", allowRobjects=TRUE) 39 | 40 | options <- "" 41 | 42 | # Options 43 | options <- createOptions(names=c("split", "s", "S", "f", "r", "q", "D", "F", "p"), values=list(split, s, S, f, r, q, D, F, p)) 44 | 45 | # establish output file 46 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 47 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 48 | bedtools.path <- getOption("bedtools.path") 49 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 50 | cmd <- paste0(bedtools.path, "bedtools multicov ", options, " -bams ", bams[[1]], " -bed ", bed[[1]], " > ", tempfile) 51 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 52 | if(!is.null(output)) { 53 | if(file.info(tempfile)$size > 0) 54 | file.copy(tempfile, output) 55 | } else { 56 | if(file.info(tempfile)$size > 0) 57 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 58 | else 59 | results <- data.frame() 60 | } 61 | 62 | # Delete temp files 63 | temp.files <- c(tempfile, bams[[2]], bed[[2]]) 64 | deleteTempFiles(temp.files) 65 | 66 | if(is.null(output)) 67 | return(results) 68 | } -------------------------------------------------------------------------------- /R/bt.multiinter.R: -------------------------------------------------------------------------------- 1 | #' Identifies common intervals among multiple 2 | #' BED/GFF/VCF files. 3 | #' 4 | #' @param i FILE1 FILE2 .. FILEn 5 | #' Requires that each interval file is sorted by chrom/start. 6 | #' @param cluster Invoke Ryan Layers's clustering algorithm. 7 | #' 8 | #' @param header Print a header line. 9 | #' (chrom/start/end + names of each file). 10 | #' 11 | #' @param names A list of names (one/file) to describe each file in -i. 12 | #' These names will be printed in the header line. 13 | #' 14 | #' @param g Use genome file to calculate empty regions. 15 | #' - STRING. 16 | #' 17 | #' @param empty Report empty regions (i.e., start/end intervals w/o 18 | #' values in all files). 19 | #' - Requires the '-g FILE' parameter. 20 | #' 21 | #' @param filler Use TEXT when representing intervals having no value. 22 | #' - Default is '0', but you can use 'N/A' or any text. 23 | #' 24 | #' @param examples Show detailed usage examples. 25 | #' 26 | #' @param output Output filepath instead of returning output in R. 27 | #' 28 | bt.multiinter <- function(i, cluster = NULL, header = NULL, names = NULL, g = NULL, empty = NULL, filler = NULL, examples = NULL, output = NULL) 29 | { 30 | # Required Inputs 31 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 32 | 33 | options <- "" 34 | 35 | # Options 36 | options <- createOptions(names=c("cluster", "header", "names", "g", "empty", "filler", "examples"), values=list(cluster, header, names, g, empty, filler, examples)) 37 | 38 | # establish output file 39 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 40 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 41 | bedtools.path <- getOption("bedtools.path") 42 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 43 | cmd <- paste0(bedtools.path, "bedtools multiinter ", options, " -i ", i[[1]], " > ", tempfile) 44 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 45 | if(!is.null(output)) { 46 | if(file.info(tempfile)$size > 0) 47 | file.copy(tempfile, output) 48 | } else { 49 | if(file.info(tempfile)$size > 0) 50 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 51 | else 52 | results <- data.frame() 53 | } 54 | 55 | # Delete temp files 56 | temp.files <- c(tempfile, i[[2]]) 57 | deleteTempFiles(temp.files) 58 | 59 | if(is.null(output)) 60 | return(results) 61 | } -------------------------------------------------------------------------------- /R/bt.nuc.R: -------------------------------------------------------------------------------- 1 | #' Profiles the nucleotide content of intervals in a fasta file. 2 | #' 3 | #' @param fi 4 | #' @param bed 5 | #' @param s Profile the sequence according to strand. 6 | #' 7 | #' @param seq Print the extracted sequence 8 | #' 9 | #' @param pattern Report the number of times a user-defined sequence 10 | #' is observed (case-sensitive). 11 | #' 12 | #' @param C Ignore case when matching -pattern. By defaulty, case matters. 13 | #' 14 | #' @param fullHeader Use full fasta header. 15 | #' - By default, only the word before the first space or tab is used. 16 | #' 17 | #' @param output Output filepath instead of returning output in R. 18 | #' 19 | bt.nuc <- function(fi, bed, s = NULL, seq = NULL, pattern = NULL, C = NULL, fullHeader = NULL, output = NULL) 20 | { 21 | # Required Inputs 22 | fi <- establishPaths(input=fi, name="fi", allowRobjects=TRUE) 23 | bed <- establishPaths(input=bed, name="bed", allowRobjects=TRUE) 24 | 25 | options <- "" 26 | 27 | # Options 28 | options <- createOptions(names=c("s", "seq", "pattern", "C", "fullHeader"), values=list(s, seq, pattern, C, fullHeader)) 29 | 30 | # establish output file 31 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 32 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 33 | bedtools.path <- getOption("bedtools.path") 34 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 35 | cmd <- paste0(bedtools.path, "bedtools nuc ", options, " -fi ", fi[[1]], " -bed ", bed[[1]], " > ", tempfile) 36 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 37 | if(!is.null(output)) { 38 | if(file.info(tempfile)$size > 0) 39 | file.copy(tempfile, output) 40 | } else { 41 | if(file.info(tempfile)$size > 0) 42 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 43 | else 44 | results <- data.frame() 45 | } 46 | 47 | # Delete temp files 48 | temp.files <- c(tempfile, fi[[2]], bed[[2]]) 49 | deleteTempFiles(temp.files) 50 | 51 | if(is.null(output)) 52 | return(results) 53 | } -------------------------------------------------------------------------------- /R/bt.overlap.R: -------------------------------------------------------------------------------- 1 | #' Computes the amount of overlap (positive values) 2 | #' or distance (negative values) between genome features 3 | #' and reports the result at the end of the same line. 4 | #' 5 | #' @param i 6 | #' @param cols 7 | #' @param output Output filepath instead of returning output in R. 8 | #' 9 | bt.overlap <- function(i, cols = NULL, output = NULL) 10 | { 11 | # Required Inputs 12 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 13 | 14 | options <- "" 15 | 16 | # Options 17 | options <- createOptions(names=c("cols"), values=list(cols)) 18 | 19 | # establish output file 20 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 21 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 22 | bedtools.path <- getOption("bedtools.path") 23 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 24 | cmd <- paste0(bedtools.path, "bedtools overlap ", options, " -i ", i[[1]], " > ", tempfile) 25 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 26 | if(!is.null(output)) { 27 | if(file.info(tempfile)$size > 0) 28 | file.copy(tempfile, output) 29 | } else { 30 | if(file.info(tempfile)$size > 0) 31 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 32 | else 33 | results <- data.frame() 34 | } 35 | 36 | # Delete temp files 37 | temp.files <- c(tempfile, i[[2]]) 38 | deleteTempFiles(temp.files) 39 | 40 | if(is.null(output)) 41 | return(results) 42 | } -------------------------------------------------------------------------------- /R/bt.pairtobed.R: -------------------------------------------------------------------------------- 1 | #' Report overlaps between a BEDPE file and a BED/GFF/VCF file. 2 | #' 3 | #' @param a 4 | #' @param b 5 | #' @param abam The A input file is in BAM format. Output will be BAM as well. Replaces -a. 6 | #' - Requires BAM to be grouped or sorted by query. 7 | #' 8 | #' @param ubam Write uncompressed BAM output. Default writes compressed BAM. 9 | #' is to write output in BAM when using -abam. 10 | #' 11 | #' @param bedpe When using BAM input (-abam), write output as BEDPE. The default 12 | #' is to write output in BAM when using -abam. 13 | #' 14 | #' @param ed Use BAM total edit distance (NM tag) for BEDPE score. 15 | #' - Default for BEDPE is to use the minimum of 16 | #' of the two mapping qualities for the pair. 17 | #' - When -ed is used the total edit distance 18 | #' from the two mates is reported as the score. 19 | #' 20 | #' @param f Minimum overlap required as fraction of A (e.g. 0.05). 21 | #' Default is 1E-9 (effectively 1bp). 22 | #' 23 | #' @param s Require same strandedness when finding overlaps. 24 | #' Default is to ignore stand. 25 | #' Not applicable with -type inspan or -type outspan. 26 | #' 27 | #' @param S Require different strandedness when finding overlaps. 28 | #' Default is to ignore stand. 29 | #' Not applicable with -type inspan or -type outspan. 30 | #' 31 | #' @param type Approach to reporting overlaps between BEDPE and BED. 32 | #' either Report overlaps if either end of A overlaps B. 33 | #' - Default. 34 | #' neither Report A if neither end of A overlaps B. 35 | #' both Report overlaps if both ends of A overlap B. 36 | #' xor Report overlaps if one and only one end of A overlaps B. 37 | #' notboth Report overlaps if neither end or one and only one 38 | #' end of A overlap B. That is, xor + neither. 39 | #' ispan Report overlaps between [end1, start2] of A and B. 40 | #' - Note: If chrom1 <> chrom2, entry is ignored. 41 | #' ospan Report overlaps between [start1, end2] of A and B. 42 | #' - Note: If chrom1 <> chrom2, entry is ignored. 43 | #' notispan Report A if ispan of A doesn't overlap B. 44 | #' - Note: If chrom1 <> chrom2, entry is ignored. 45 | #' notospan Report A if ospan of A doesn't overlap B. 46 | #' - Note: If chrom1 <> chrom2, entry is ignored. 47 | #' 48 | #' @param output Output filepath instead of returning output in R. 49 | #' 50 | bt.pairtobed <- function(a, b, abam = NULL, ubam = NULL, bedpe = NULL, ed = NULL, f = NULL, s = NULL, S = NULL, type = NULL, output = NULL) 51 | { 52 | # Required Inputs 53 | a <- establishPaths(input=a, name="a", allowRobjects=TRUE) 54 | b <- establishPaths(input=b, name="b", allowRobjects=TRUE) 55 | 56 | options <- "" 57 | 58 | # Options 59 | options <- createOptions(names=c("abam", "ubam", "bedpe", "ed", "f", "s", "S", "type"), values=list(abam, ubam, bedpe, ed, f, s, S, type)) 60 | 61 | # establish output file 62 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 63 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 64 | bedtools.path <- getOption("bedtools.path") 65 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 66 | cmd <- paste0(bedtools.path, "bedtools pairtobed ", options, " -a ", a[[1]], " -b ", b[[1]], " > ", tempfile) 67 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 68 | if(!is.null(output)) { 69 | if(file.info(tempfile)$size > 0) 70 | file.copy(tempfile, output) 71 | } else { 72 | if(file.info(tempfile)$size > 0) 73 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 74 | else 75 | results <- data.frame() 76 | } 77 | 78 | # Delete temp files 79 | temp.files <- c(tempfile, a[[2]], b[[2]]) 80 | deleteTempFiles(temp.files) 81 | 82 | if(is.null(output)) 83 | return(results) 84 | } -------------------------------------------------------------------------------- /R/bt.pairtopair.R: -------------------------------------------------------------------------------- 1 | #' Report overlaps between two paired-end BED files (BEDPE). 2 | #' 3 | #' @param a 4 | #' @param b 5 | #' @param f Minimum overlap required as fraction of A (e.g. 0.05). 6 | #' Default is 1E-9 (effectively 1bp). 7 | #' 8 | #' @param type Approach to reporting overlaps between A and B. 9 | #' neither Report overlaps if neither end of A overlaps B. 10 | #' either Report overlaps if either ends of A overlap B. 11 | #' both Report overlaps if both ends of A overlap B. 12 | #' notboth Report overlaps if one or neither of A's overlap B. 13 | #' - Default = both. 14 | #' 15 | #' @param slop The amount of slop (in b.p.). to be added to each footprint of A. 16 | #' *Note*: Slop is subtracted from start1 and start2 17 | #' and added to end1 and end2. 18 | #' - Default = 0. 19 | #' 20 | #' @param ss Add slop based to each BEDPE footprint based on strand. 21 | #' - If strand is "+", slop is only added to the end coordinates. 22 | #' - If strand is "-", slop is only added to the start coordinates. 23 | #' - By default, slop is added in both directions. 24 | #' 25 | #' @param is Ignore strands when searching for overlaps. 26 | #' - By default, strands are enforced. 27 | #' 28 | #' @param rdn Require the hits to have different names (i.e. avoid self-hits). 29 | #' - By default, same names are allowed. 30 | #' 31 | #' @param output Output filepath instead of returning output in R. 32 | #' 33 | bt.pairtopair <- function(a, b, f = NULL, type = NULL, slop = NULL, ss = NULL, is = NULL, rdn = NULL, output = NULL) 34 | { 35 | # Required Inputs 36 | a <- establishPaths(input=a, name="a", allowRobjects=TRUE) 37 | b <- establishPaths(input=b, name="b", allowRobjects=TRUE) 38 | 39 | options <- "" 40 | 41 | # Options 42 | options <- createOptions(names=c("f", "type", "slop", "ss", "is", "rdn"), values=list(f, type, slop, ss, is, rdn)) 43 | 44 | # establish output file 45 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 46 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 47 | bedtools.path <- getOption("bedtools.path") 48 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 49 | cmd <- paste0(bedtools.path, "bedtools pairtopair ", options, " -a ", a[[1]], " -b ", b[[1]], " > ", tempfile) 50 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 51 | if(!is.null(output)) { 52 | if(file.info(tempfile)$size > 0) 53 | file.copy(tempfile, output) 54 | } else { 55 | if(file.info(tempfile)$size > 0) 56 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 57 | else 58 | results <- data.frame() 59 | } 60 | 61 | # Delete temp files 62 | temp.files <- c(tempfile, a[[2]], b[[2]]) 63 | deleteTempFiles(temp.files) 64 | 65 | if(is.null(output)) 66 | return(results) 67 | } -------------------------------------------------------------------------------- /R/bt.random.R: -------------------------------------------------------------------------------- 1 | #' Generate random intervals among a genome. 2 | #' 3 | #' @param g 4 | #' @param l The length of the intervals to generate. 5 | #' - Default = 100. 6 | #' - (INTEGER) 7 | #' 8 | #' @param n The number of intervals to generate. 9 | #' - Default = 1,000,000. 10 | #' - (INTEGER) 11 | #' 12 | #' @param seed Supply an integer seed for the shuffling. 13 | #' - By default, the seed is chosen automatically. 14 | #' - (INTEGER) 15 | #' 16 | #' @param output Output filepath instead of returning output in R. 17 | #' 18 | bt.random <- function(g, l = NULL, n = NULL, seed = NULL, output = NULL) 19 | { 20 | # Required Inputs 21 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 22 | 23 | options <- "" 24 | 25 | # Options 26 | options <- createOptions(names=c("l", "n", "seed"), values=list(l, n, seed)) 27 | 28 | # establish output file 29 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 30 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 31 | bedtools.path <- getOption("bedtools.path") 32 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 33 | cmd <- paste0(bedtools.path, "bedtools random ", options, " -g ", g[[1]], " > ", tempfile) 34 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 35 | if(!is.null(output)) { 36 | if(file.info(tempfile)$size > 0) 37 | file.copy(tempfile, output) 38 | } else { 39 | if(file.info(tempfile)$size > 0) 40 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 41 | else 42 | results <- data.frame() 43 | } 44 | 45 | # Delete temp files 46 | temp.files <- c(tempfile, g[[2]]) 47 | deleteTempFiles(temp.files) 48 | 49 | if(is.null(output)) 50 | return(results) 51 | } -------------------------------------------------------------------------------- /R/bt.reldist.R: -------------------------------------------------------------------------------- 1 | #' Calculate the relative distance distribution b/w two feature files. 2 | #' 3 | #' @param a 4 | #' @param b 5 | #' @param detail Report the relativedistance for each interval in A 6 | #' 7 | #' @param output Output filepath instead of returning output in R. 8 | #' 9 | bt.reldist <- function(a, b, detail = NULL, output = NULL) 10 | { 11 | # Required Inputs 12 | a <- establishPaths(input=a, name="a", allowRobjects=TRUE) 13 | b <- establishPaths(input=b, name="b", allowRobjects=TRUE) 14 | 15 | options <- "" 16 | 17 | # Options 18 | options <- createOptions(names=c("detail"), values=list(detail)) 19 | 20 | # establish output file 21 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 22 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 23 | bedtools.path <- getOption("bedtools.path") 24 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 25 | cmd <- paste0(bedtools.path, "bedtools reldist ", options, " -a ", a[[1]], " -b ", b[[1]], " > ", tempfile) 26 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 27 | if(!is.null(output)) { 28 | if(file.info(tempfile)$size > 0) 29 | file.copy(tempfile, output) 30 | } else { 31 | if(file.info(tempfile)$size > 0) 32 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 33 | else 34 | results <- data.frame() 35 | } 36 | 37 | # Delete temp files 38 | temp.files <- c(tempfile, a[[2]], b[[2]]) 39 | deleteTempFiles(temp.files) 40 | 41 | if(is.null(output)) 42 | return(results) 43 | } -------------------------------------------------------------------------------- /R/bt.sample.R: -------------------------------------------------------------------------------- 1 | #' Take sample of input file(s) using reservoir sampling algorithm. 2 | #' 3 | #' @param i 4 | #' @param n The number of records to generate. 5 | #' - Default = 1,000,000. 6 | #' - (INTEGER) 7 | #' 8 | #' @param seed Supply an integer seed for the shuffling. 9 | #' - By default, the seed is chosen automatically. 10 | #' - (INTEGER) 11 | #' 12 | #' @param ubam Write uncompressed BAM output. Default writes compressed BAM. 13 | #' 14 | #' @param s Require same strandedness. That is, only give records 15 | #' that have the same strand. Use '-s forward' or '-s reverse' 16 | #' for forward or reverse strand records, respectively. 17 | #' - By default, records are reported without respect to strand. 18 | #' 19 | #' @param header Print the header from the A file prior to results. 20 | #' 21 | #' @param bed If using BAM input, write output as BED. 22 | #' 23 | #' @param nobuf Disable buffered output. Using this option will cause each line 24 | #' of output to be printed as it is generated, rather than saved 25 | #' in a buffer. This will make printing large output files 26 | #' noticeably slower, but can be useful in conjunction with 27 | #' other software tools and scripts that need to process one 28 | #' line of bedtools output at a time. 29 | #' 30 | #' @param iobuf Specify amount of memory to use for input buffer. 31 | #' Takes an integer argument. Optional suffixes K/M/G supported. 32 | #' Note: currently has no effect with compressed files. 33 | #' 34 | #' @param output Output filepath instead of returning output in R. 35 | #' 36 | bt.sample <- function(i, n = NULL, seed = NULL, ubam = NULL, s = NULL, header = NULL, bed = NULL, nobuf = NULL, iobuf = NULL, output = NULL) 37 | { 38 | # Required Inputs 39 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 40 | 41 | options <- "" 42 | 43 | # Options 44 | options <- createOptions(names=c("n", "seed", "ubam", "s", "header", "bed", "nobuf", "iobuf"), values=list(n, seed, ubam, s, header, bed, nobuf, iobuf)) 45 | 46 | # establish output file 47 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 48 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 49 | bedtools.path <- getOption("bedtools.path") 50 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 51 | cmd <- paste0(bedtools.path, "bedtools sample ", options, " -i ", i[[1]], " > ", tempfile) 52 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 53 | if(!is.null(output)) { 54 | if(file.info(tempfile)$size > 0) 55 | file.copy(tempfile, output) 56 | } else { 57 | if(file.info(tempfile)$size > 0) 58 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 59 | else 60 | results <- data.frame() 61 | } 62 | 63 | # Delete temp files 64 | temp.files <- c(tempfile, i[[2]]) 65 | deleteTempFiles(temp.files) 66 | 67 | if(is.null(output)) 68 | return(results) 69 | } -------------------------------------------------------------------------------- /R/bt.shift.R: -------------------------------------------------------------------------------- 1 | #' Shift each feature by requested number of base pairs. 2 | #' 3 | #' @param i 4 | #' @param g 5 | #' @param s Shift the BED/GFF/VCF entry -s base pairs. 6 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 7 | #' 8 | #' @param p Shift features on the + strand by -p base pairs. 9 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 10 | #' 11 | #' @param m Shift features on the - strand by -m base pairs. 12 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 13 | #' 14 | #' @param pct Define -s, -m and -p as a fraction of the feature's length. 15 | #' E.g. if used on a 1000bp feature, -s 0.50, 16 | #' will shift the feature 500 bp "upstream". Default = false. 17 | #' 18 | #' @param header Print the header from the input file prior to results. 19 | #' 20 | #' @param output Output filepath instead of returning output in R. 21 | #' 22 | bt.shift <- function(i, g, s = NULL, p = NULL, m = NULL, pct = NULL, header = NULL, output = NULL) 23 | { 24 | # Required Inputs 25 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 26 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 27 | 28 | options <- "" 29 | 30 | # Options 31 | options <- createOptions(names=c("s", "p", "m", "pct", "header"), values=list(s, p, m, pct, header)) 32 | 33 | # establish output file 34 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 35 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 36 | bedtools.path <- getOption("bedtools.path") 37 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 38 | cmd <- paste0(bedtools.path, "bedtools shift ", options, " -i ", i[[1]], " -g ", g[[1]], " > ", tempfile) 39 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 40 | if(!is.null(output)) { 41 | if(file.info(tempfile)$size > 0) 42 | file.copy(tempfile, output) 43 | } else { 44 | if(file.info(tempfile)$size > 0) 45 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 46 | else 47 | results <- data.frame() 48 | } 49 | 50 | # Delete temp files 51 | temp.files <- c(tempfile, i[[2]], g[[2]]) 52 | deleteTempFiles(temp.files) 53 | 54 | if(is.null(output)) 55 | return(results) 56 | } -------------------------------------------------------------------------------- /R/bt.shuffle.R: -------------------------------------------------------------------------------- 1 | #' Randomly permute the locations of a feature file among a genome. 2 | #' 3 | #' @param i 4 | #' @param g 5 | #' @param excl A BED/GFF/VCF file of coordinates in which features in -i 6 | #' should not be placed (e.g. gaps.bed). 7 | #' 8 | #' @param incl Instead of randomly placing features in a genome, the -incl 9 | #' options defines a BED/GFF/VCF file of coordinates in which 10 | #' features in -i should be randomly placed (e.g. genes.bed). 11 | #' Larger -incl intervals will contain more shuffled regions. 12 | #' This method DISABLES -chromFirst. 13 | #' 14 | #' @param chrom Keep features in -i on the same chromosome. 15 | #' - By default, the chrom and position are randomly chosen. 16 | #' - NOTE: Forces use of -chromFirst (see below). 17 | #' 18 | #' @param seed Supply an integer seed for the shuffling. 19 | #' - By default, the seed is chosen automatically. 20 | #' - (INTEGER) 21 | #' 22 | #' @param f Maximum overlap (as a fraction of the -i feature) with an -excl 23 | #' feature that is tolerated before searching for a new, 24 | #' randomized locus. For example, -f 0.10 allows up to 10 percent 25 | #' of a randomized feature to overlap with a given feature 26 | #' in the -excl file. **Cannot be used with -incl file.** 27 | #' - Default is 1E-9 (i.e., 1bp). 28 | #' - FLOAT (e.g. 0.50) 29 | #' 30 | #' @param chromFirst 31 | #' Instead of choosing a position randomly among the entire 32 | #' genome (the default), first choose a chrom randomly, and then 33 | #' choose a random start coordinate on that chrom. This leads 34 | #' to features being ~uniformly distributed among the chroms, 35 | #' as opposed to features being distribute as a function of chrom size. 36 | #' 37 | #' @param bedpe Indicate that the A file is in BEDPE format. 38 | #' 39 | #' @param maxTries 40 | #' Max. number of attempts to find a home for a shuffled interval 41 | #' in the presence of -incl or -excl. 42 | #' Default = 1000. 43 | #' 44 | #' @param noOverlapping 45 | #' Don't allow shuffled intervals to overlap. 46 | #' 47 | #' @param allowBeyondChromEnd 48 | #' Allow shuffled intervals to be relocated to a position 49 | #' in which the entire original interval cannot fit w/o exceeding 50 | #' the end of the chromosome. In this case, the end coordinate of the 51 | #' shuffled interval will be set to the chromosome's length. 52 | #' By default, an interval's original length must be fully-contained 53 | #' within the chromosome. 54 | #' 55 | #' @param output Output filepath instead of returning output in R. 56 | #' 57 | bt.shuffle <- function(i, g, excl = NULL, incl = NULL, chrom = NULL, seed = NULL, f = NULL, chromFirst = NULL, bedpe = NULL, maxTries = NULL, noOverlapping = NULL, allowBeyondChromEnd = NULL, output = NULL) 58 | { 59 | # Required Inputs 60 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 61 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 62 | 63 | options <- "" 64 | 65 | # Options 66 | if(!is.null(excl)) 67 | excl <- establishPaths(input=excl, name="excl", allowRobjects=TRUE) 68 | if(!is.null(incl)) 69 | incl <- establishPaths(input=incl, name="incl", allowRobjects=TRUE) 70 | options <- createOptions(names=c("excl", "incl", "chrom", "seed", "f", "chromFirst", "bedpe", "maxTries", "noOverlapping", "allowBeyondChromEnd"), values=list(excl, incl, chrom, seed, f, chromFirst, bedpe, maxTries, noOverlapping, allowBeyondChromEnd)) 71 | 72 | # establish output file 73 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 74 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 75 | bedtools.path <- getOption("bedtools.path") 76 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 77 | cmd <- paste0(bedtools.path, "bedtools shuffle ", options, " -i ", i[[1]], " -g ", g[[1]], " > ", tempfile) 78 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 79 | if(!is.null(output)) { 80 | if(file.info(tempfile)$size > 0) 81 | file.copy(tempfile, output) 82 | } else { 83 | if(file.info(tempfile)$size > 0) 84 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 85 | else 86 | results <- data.frame() 87 | } 88 | 89 | # Delete temp files 90 | temp.files <- c(tempfile, i[[2]], g[[2]]) 91 | if(!is.null(excl)) 92 | temp.files <- c(temp.files, excl[[2]]) 93 | if(!is.null(incl)) 94 | temp.files <- c(temp.files, incl[[2]]) 95 | deleteTempFiles(temp.files) 96 | 97 | if(is.null(output)) 98 | return(results) 99 | } -------------------------------------------------------------------------------- /R/bt.slop.R: -------------------------------------------------------------------------------- 1 | #' Add requested base pairs of "slop" to each feature. 2 | #' 3 | #' @param i 4 | #' @param g 5 | #' @param b Increase the BED/GFF/VCF entry -b base pairs in each direction. 6 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 7 | #' 8 | #' @param l The number of base pairs to subtract from the start coordinate. 9 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 10 | #' 11 | #' @param r The number of base pairs to add to the end coordinate. 12 | #' - (Integer) or (Float, e.g. 0.1) if used with -pct. 13 | #' 14 | #' @param s Define -l and -r based on strand. 15 | #' E.g. if used, -l 500 for a negative-stranded feature, 16 | #' it will add 500 bp downstream. Default = false. 17 | #' 18 | #' @param pct Define -l and -r as a fraction of the feature's length. 19 | #' E.g. if used on a 1000bp feature, -l 0.50, 20 | #' will add 500 bp "upstream". Default = false. 21 | #' 22 | #' @param header Print the header from the input file prior to results. 23 | #' 24 | #' @param output Output filepath instead of returning output in R. 25 | #' 26 | bt.slop <- function(i, g, b = NULL, l = NULL, r = NULL, s = NULL, pct = NULL, header = NULL, output = NULL) 27 | { 28 | # Required Inputs 29 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 30 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 31 | 32 | options <- "" 33 | 34 | # Options 35 | options <- createOptions(names=c("b", "l", "r", "s", "pct", "header"), values=list(b, l, r, s, pct, header)) 36 | 37 | # establish output file 38 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 39 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 40 | bedtools.path <- getOption("bedtools.path") 41 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 42 | cmd <- paste0(bedtools.path, "bedtools slop ", options, " -i ", i[[1]], " -g ", g[[1]], " > ", tempfile) 43 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 44 | if(!is.null(output)) { 45 | if(file.info(tempfile)$size > 0) 46 | file.copy(tempfile, output) 47 | } else { 48 | if(file.info(tempfile)$size > 0) 49 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 50 | else 51 | results <- data.frame() 52 | } 53 | 54 | # Delete temp files 55 | temp.files <- c(tempfile, i[[2]], g[[2]]) 56 | deleteTempFiles(temp.files) 57 | 58 | if(is.null(output)) 59 | return(results) 60 | } -------------------------------------------------------------------------------- /R/bt.sort.R: -------------------------------------------------------------------------------- 1 | #' Sorts a feature file in various and useful ways. 2 | #' 3 | #' @param i 4 | #' @param sizeA Sort by feature size in ascending order. 5 | #' 6 | #' @param sizeD Sort by feature size in descending order. 7 | #' 8 | #' @param chrThenSizeA Sort by chrom (asc), then feature size (asc). 9 | #' 10 | #' @param chrThenSizeD Sort by chrom (asc), then feature size (desc). 11 | #' 12 | #' @param chrThenScoreA Sort by chrom (asc), then score (asc). 13 | #' 14 | #' @param chrThenScoreD Sort by chrom (asc), then score (desc). 15 | #' 16 | #' @param g Sort according to the chromosomes declared in "genome.txt" 17 | #' 18 | #' @param faidx Sort according to the chromosomes declared in "names.txt" 19 | #' 20 | #' @param header Print the header from the A file prior to results. 21 | #' 22 | #' @param output Output filepath instead of returning output in R. 23 | #' 24 | bt.sort <- function(i, sizeA = NULL, sizeD = NULL, chrThenSizeA = NULL, chrThenSizeD = NULL, chrThenScoreA = NULL, chrThenScoreD = NULL, g = NULL, faidx = NULL, header = NULL, output = NULL) 25 | { 26 | # Required Inputs 27 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 28 | 29 | options <- "" 30 | 31 | # Options 32 | options <- createOptions(names=c("sizeA", "sizeD", "chrThenSizeA", "chrThenSizeD", "chrThenScoreA", "chrThenScoreD", "g", "faidx", "header"), values=list(sizeA, sizeD, chrThenSizeA, chrThenSizeD, chrThenScoreA, chrThenScoreD, g, faidx, header)) 33 | 34 | # establish output file 35 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 36 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 37 | bedtools.path <- getOption("bedtools.path") 38 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 39 | cmd <- paste0(bedtools.path, "bedtools sort ", options, " -i ", i[[1]], " > ", tempfile) 40 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 41 | if(!is.null(output)) { 42 | if(file.info(tempfile)$size > 0) 43 | file.copy(tempfile, output) 44 | } else { 45 | if(file.info(tempfile)$size > 0) 46 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 47 | else 48 | results <- data.frame() 49 | } 50 | 51 | # Delete temp files 52 | temp.files <- c(tempfile, i[[2]]) 53 | deleteTempFiles(temp.files) 54 | 55 | if(is.null(output)) 56 | return(results) 57 | } -------------------------------------------------------------------------------- /R/bt.spacing.R: -------------------------------------------------------------------------------- 1 | #' Report (last col.) the gap lengths between intervals in a file. 2 | #' 3 | #' @param i 4 | #' @param output Output filepath instead of returning output in R. 5 | #' 6 | bt.spacing <- function(i, output = NULL) 7 | { 8 | # Required Inputs 9 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 10 | 11 | options <- "" 12 | 13 | # Options 14 | options <- createOptions(names=c(), values=list()) 15 | 16 | # establish output file 17 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 18 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 19 | bedtools.path <- getOption("bedtools.path") 20 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 21 | cmd <- paste0(bedtools.path, "bedtools spacing ", options, " -i ", i[[1]], " > ", tempfile) 22 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 23 | if(!is.null(output)) { 24 | if(file.info(tempfile)$size > 0) 25 | file.copy(tempfile, output) 26 | } else { 27 | if(file.info(tempfile)$size > 0) 28 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 29 | else 30 | results <- data.frame() 31 | } 32 | 33 | # Delete temp files 34 | temp.files <- c(tempfile, i[[2]]) 35 | deleteTempFiles(temp.files) 36 | 37 | if(is.null(output)) 38 | return(results) 39 | } -------------------------------------------------------------------------------- /R/bt.split.R: -------------------------------------------------------------------------------- 1 | #' Split a Bed file. 2 | #' 3 | #' @param i 4 | #' @param n number-of-files 5 | #' @param p Output BED file prefix. 6 | #' 7 | #' @param a Algorithm used to split data. 8 | #' * size (default): uses a heuristic algorithm to group the items 9 | #' so all files contain the ~ same number of bases 10 | #' * simple : route records such that each split file has 11 | #' approximately equal records (like Unix split). 12 | #' 13 | bt.split <- function(i, n = NULL, p = NULL, a = NULL) 14 | { 15 | # Required Inputs 16 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 17 | 18 | options <- "" 19 | 20 | # Options 21 | options <- createOptions(names=c("n", "p", "a"), values=list(n, p, a)) 22 | 23 | # establish output file 24 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 25 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 26 | bedtools.path <- getOption("bedtools.path") 27 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 28 | cmd <- paste0(bedtools.path, "bedtools split ", options, " -i ", i[[1]]) 29 | console.output <- system(cmd, intern=TRUE) 30 | print(console.output) 31 | 32 | # Delete temp files 33 | temp.files <- c(tempfile, i[[2]]) 34 | deleteTempFiles(temp.files) 35 | } -------------------------------------------------------------------------------- /R/bt.summary.R: -------------------------------------------------------------------------------- 1 | #' Report summary statistics of the intervals in a file 2 | #' 3 | #' @param i 4 | #' @param g 5 | #' @param output Output filepath instead of returning output in R. 6 | #' 7 | bt.summary <- function(i, g, output = NULL) 8 | { 9 | # Required Inputs 10 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 11 | g <- establishPaths(input=g, name="g", allowRobjects=TRUE) 12 | 13 | options <- "" 14 | 15 | # Options 16 | options <- createOptions(names=c(), values=list()) 17 | 18 | # establish output file 19 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 20 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 21 | bedtools.path <- getOption("bedtools.path") 22 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 23 | cmd <- paste0(bedtools.path, "bedtools summary ", options, " -i ", i[[1]], " -g ", g[[1]], " > ", tempfile) 24 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 25 | if(!is.null(output)) { 26 | if(file.info(tempfile)$size > 0) 27 | file.copy(tempfile, output) 28 | } else { 29 | if(file.info(tempfile)$size > 0) 30 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 31 | else 32 | results <- data.frame() 33 | } 34 | 35 | # Delete temp files 36 | temp.files <- c(tempfile, i[[2]], g[[2]]) 37 | deleteTempFiles(temp.files) 38 | 39 | if(is.null(output)) 40 | return(results) 41 | } -------------------------------------------------------------------------------- /R/bt.tag.R: -------------------------------------------------------------------------------- 1 | #' Annotates a BAM file based on overlaps with multiple BED/GFF/VCF files 2 | #' on the intervals in -i. 3 | #' 4 | #' @param i 5 | #' @param files FILE1 .. FILEn 6 | #' @param s Require overlaps on the same strand. That is, only tag alignments that have the same 7 | #' strand as a feature in the annotation file(s). 8 | #' 9 | #' @param S Require overlaps on the opposite strand. That is, only tag alignments that have the opposite 10 | #' strand as a feature in the annotation file(s). 11 | #' 12 | #' @param f Minimum overlap required as a fraction of the alignment. 13 | #' - Default is 1E-9 (i.e., 1bp). 14 | #' - FLOAT (e.g. 0.50) 15 | #' 16 | #' @param tag Dictate what the tag should be. Default is YB. 17 | #' - STRING (two characters, e.g., YK) 18 | #' 19 | #' @param names Use the name field from the annotation files to populate tags. 20 | #' By default, the -labels values are used. 21 | #' 22 | #' @param scores Use the score field from the annotation files to populate tags. 23 | #' By default, the -labels values are used. 24 | #' 25 | #' @param intervals Use the full interval (including name, score, and strand) to populate tags. 26 | #' Requires the -labels option to identify from which file the interval came. 27 | #' 28 | #' @param labels LAB1 .. LABn 29 | #' @param output Output filepath instead of returning output in R. 30 | #' 31 | bt.tag <- function(i, files, s = NULL, S = NULL, f = NULL, tag = NULL, names = NULL, scores = NULL, intervals = NULL, labels = NULL, output = NULL) 32 | { 33 | # Required Inputs 34 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 35 | files <- establishPaths(input=files, name="files", allowRobjects=TRUE) 36 | 37 | options <- "" 38 | 39 | # Options 40 | options <- createOptions(names=c("s", "S", "f", "tag", "names", "scores", "intervals", "labels"), values=list(s, S, f, tag, names, scores, intervals, labels)) 41 | 42 | # establish output file 43 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 44 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 45 | bedtools.path <- getOption("bedtools.path") 46 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 47 | cmd <- paste0(bedtools.path, "bedtools tag ", options, " -i ", i[[1]], " -files ", files[[1]], " > ", tempfile) 48 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 49 | if(!is.null(output)) { 50 | if(file.info(tempfile)$size > 0) 51 | file.copy(tempfile, output) 52 | } else { 53 | if(file.info(tempfile)$size > 0) 54 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 55 | else 56 | results <- data.frame() 57 | } 58 | 59 | # Delete temp files 60 | temp.files <- c(tempfile, i[[2]], files[[2]]) 61 | deleteTempFiles(temp.files) 62 | 63 | if(is.null(output)) 64 | return(results) 65 | } -------------------------------------------------------------------------------- /R/bt.unionbedg.R: -------------------------------------------------------------------------------- 1 | #' Combines multiple BedGraph files into a single file, 2 | #' allowing coverage comparisons between them. 3 | #' 4 | #' @param i FILE1 FILE2 .. FILEn 5 | #' Assumes that each BedGraph file is sorted by chrom/start 6 | #' and that the intervals in each are non-overlapping. 7 | #' @param header Print a header line. 8 | #' (chrom/start/end + names of each file). 9 | #' 10 | #' @param names A list of names (one/file) to describe each file in -i. 11 | #' These names will be printed in the header line. 12 | #' 13 | #' @param g Use genome file to calculate empty regions. 14 | #' - STRING. 15 | #' 16 | #' @param empty Report empty regions (i.e., start/end intervals w/o 17 | #' values in all files). 18 | #' - Requires the '-g FILE' parameter. 19 | #' 20 | #' @param filler Use TEXT when representing intervals having no value. 21 | #' - Default is '0', but you can use 'N/A' or any text. 22 | #' 23 | #' @param examples Show detailed usage examples. 24 | #' 25 | #' @param output Output filepath instead of returning output in R. 26 | #' 27 | bt.unionbedg <- function(i, header = NULL, names = NULL, g = NULL, empty = NULL, filler = NULL, examples = NULL, output = NULL) 28 | { 29 | # Required Inputs 30 | i <- establishPaths(input=i, name="i", allowRobjects=TRUE) 31 | 32 | options <- "" 33 | 34 | # Options 35 | options <- createOptions(names=c("header", "names", "g", "empty", "filler", "examples"), values=list(header, names, g, empty, filler, examples)) 36 | 37 | # establish output file 38 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 39 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 40 | bedtools.path <- getOption("bedtools.path") 41 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 42 | cmd <- paste0(bedtools.path, "bedtools unionbedg ", options, " -i ", i[[1]], " > ", tempfile) 43 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 44 | if(!is.null(output)) { 45 | if(file.info(tempfile)$size > 0) 46 | file.copy(tempfile, output) 47 | } else { 48 | if(file.info(tempfile)$size > 0) 49 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 50 | else 51 | results <- data.frame() 52 | } 53 | 54 | # Delete temp files 55 | temp.files <- c(tempfile, i[[2]]) 56 | deleteTempFiles(temp.files) 57 | 58 | if(is.null(output)) 59 | return(results) 60 | } -------------------------------------------------------------------------------- /R/bt.window.R: -------------------------------------------------------------------------------- 1 | #' Examines a "window" around each feature in A and 2 | #' reports all features in B that overlap the window. For each 3 | #' overlap the entire entry in A and B are reported. 4 | #' 5 | #' @param a 6 | #' @param b 7 | #' @param abam The A input file is in BAM format. Output will be BAM as well. Replaces -a. 8 | #' 9 | #' @param ubam Write uncompressed BAM output. Default writes compressed BAM. 10 | #' 11 | #' @param bed When using BAM input (-abam), write output as BED. The default 12 | #' is to write output in BAM when using -abam. 13 | #' 14 | #' @param w Base pairs added upstream and downstream of each entry 15 | #' in A when searching for overlaps in B. 16 | #' - Creates symmetrical "windows" around A. 17 | #' - Default is 1000 bp. 18 | #' - (INTEGER) 19 | #' 20 | #' @param l Base pairs added upstream (left of) of each entry 21 | #' in A when searching for overlaps in B. 22 | #' - Allows one to define asymmetrical "windows". 23 | #' - Default is 1000 bp. 24 | #' - (INTEGER) 25 | #' 26 | #' @param r Base pairs added downstream (right of) of each entry 27 | #' in A when searching for overlaps in B. 28 | #' - Allows one to define asymmetrical "windows". 29 | #' - Default is 1000 bp. 30 | #' - (INTEGER) 31 | #' 32 | #' @param sw Define -l and -r based on strand. For example if used, -l 500 33 | #' for a negative-stranded feature will add 500 bp downstream. 34 | #' - Default = disabled. 35 | #' 36 | #' @param sm Only report hits in B that overlap A on the _same_ strand. 37 | #' - By default, overlaps are reported without respect to strand. 38 | #' 39 | #' @param Sm Only report hits in B that overlap A on the _opposite_ strand. 40 | #' - By default, overlaps are reported without respect to strand. 41 | #' 42 | #' @param u Write the original A entry _once_ if _any_ overlaps found in B. 43 | #' - In other words, just report the fact >=1 hit was found. 44 | #' 45 | #' @param c For each entry in A, report the number of overlaps with B. 46 | #' - Reports 0 for A entries that have no overlap with B. 47 | #' - Overlaps restricted by -w, -l, and -r. 48 | #' 49 | #' @param v Only report those entries in A that have _no overlaps_ with B. 50 | #' - Similar to "grep -v." 51 | #' 52 | #' @param header Print the header from the A file prior to results. 53 | #' 54 | #' @param output Output filepath instead of returning output in R. 55 | #' 56 | bt.window <- function(a, b, abam = NULL, ubam = NULL, bed = NULL, w = NULL, l = NULL, r = NULL, sw = NULL, sm = NULL, Sm = NULL, u = NULL, c = NULL, v = NULL, header = NULL, output = NULL) 57 | { 58 | # Required Inputs 59 | a <- establishPaths(input=a, name="a", allowRobjects=TRUE) 60 | b <- establishPaths(input=b, name="b", allowRobjects=TRUE) 61 | 62 | options <- "" 63 | 64 | # Options 65 | options <- createOptions(names=c("abam", "ubam", "bed", "w", "l", "r", "sw", "sm", "Sm", "u", "c", "v", "header"), values=list(abam, ubam, bed, w, l, r, sw, sm, Sm, u, c, v, header)) 66 | 67 | # establish output file 68 | tempfile <- tempfile("bedtoolsr", fileext=".txt") 69 | tempfile <- gsub("\\", "/", tempfile, fixed=TRUE) 70 | bedtools.path <- getOption("bedtools.path") 71 | if(!is.null(bedtools.path) && !grepl("wsl", bedtools.path, ignore.case=TRUE)) bedtools.path <- paste0(bedtools.path, "/") 72 | cmd <- paste0(bedtools.path, "bedtools window ", options, " -a ", a[[1]], " -b ", b[[1]], " > ", tempfile) 73 | if(.Platform$OS.type == "windows") shell(cmd) else system(cmd) 74 | if(!is.null(output)) { 75 | if(file.info(tempfile)$size > 0) 76 | file.copy(tempfile, output) 77 | } else { 78 | if(file.info(tempfile)$size > 0) 79 | results <- utils::read.table(tempfile, header=FALSE, sep="\t", quote='') 80 | else 81 | results <- data.frame() 82 | } 83 | 84 | # Delete temp files 85 | temp.files <- c(tempfile, a[[2]], b[[2]]) 86 | deleteTempFiles(temp.files) 87 | 88 | if(is.null(output)) 89 | return(results) 90 | } -------------------------------------------------------------------------------- /R/createOptions.R: -------------------------------------------------------------------------------- 1 | #' Creates options based on user input 2 | #' 3 | #' @param names vector of names of options 4 | #' @param values vector of values of options 5 | #' 6 | #' ### Define a function that determines establishes files and paths for bedtools functions 7 | createOptions <- function(names, values) 8 | { 9 | options <- "" 10 | if(length(names) > 0) 11 | for(i in 1:length(names)) 12 | if(!is.null(values[[i]])&&(!is.logical(values[[i]])||values[[i]])) 13 | { 14 | options <- paste(options, paste(" -", names[i], sep="")) 15 | if(is.character(values[[i]]) || is.numeric(values[[i]])) 16 | options <- paste(options, " ", values[i]) 17 | else if(is.list(values[[i]])) 18 | options <- paste(options, " ", values[i][[1]]) 19 | } 20 | 21 | # return the two items 22 | return(options) 23 | } 24 | -------------------------------------------------------------------------------- /R/deleteTempFiles.R: -------------------------------------------------------------------------------- 1 | #' Deletes temp files 2 | #' 3 | #' @param tempfiles a vector of tempfiles for deletion 4 | #' 5 | #' ### Define a function that determines establishes files and paths for bedtools functions 6 | deleteTempFiles <- function(tempfiles) 7 | { 8 | for(tempfile in tempfiles) 9 | if(exists(tempfile)) 10 | file.remove (tempfile) 11 | } -------------------------------------------------------------------------------- /R/establishPaths.R: -------------------------------------------------------------------------------- 1 | #' Determines if arguments are paths or R objects. Makes temp files when 2 | #' neccesary. Makes a list of files to use in bedtools call. Makes a list 3 | #' of temp files to delete at end of function. 4 | #' 5 | #' @param input the input for an argument. Could be a path to a file, an R object (data frame), or a list of any combination thereof 6 | #' @param name the name of the argument 7 | #' @param allowRobjects boolean whether or not to allow R objects as inputs 8 | #' 9 | #' ### Define a function that determines establishes files and paths for bedtools functions 10 | establishPaths <- function(input, name="", allowRobjects=TRUE) 11 | { 12 | oo <- options(scipen = 999) 13 | on.exit(options(oo)) 14 | 15 | if(is.null(input)) 16 | return(NULL) 17 | 18 | bedtools.path <- getOption("bedtools.path") 19 | 20 | # convert to list if necessary 21 | if(!inherits(input, "list")) 22 | input <- list(input) 23 | 24 | # iterate through list making files where necessary and recording tmp files for deletion 25 | inputpaths <- c() 26 | inputtmps <- c() 27 | for(item in input) 28 | { 29 | filepath <- item 30 | # if it is an R object 31 | if(!is.character(item) && !is.numeric(item)) 32 | { 33 | if(allowRobjects == FALSE) 34 | stop("R objects are not permitted as arguments for",name) 35 | 36 | # write a temp file 37 | filepath <- tempfile(name, fileext=".txt") 38 | utils::write.table(item, filepath, append = FALSE, sep = " ", quote = FALSE, col.names = FALSE, row.names = FALSE) 39 | 40 | # record temp file for deletion 41 | inputtmps <- c(inputtmps, filepath) 42 | } 43 | else if(!file.exists(item) && file.exists(system.file("data", item, package = "bedtoolsr"))) 44 | { 45 | filepath <- system.file("data", item, package = "bedtoolsr") 46 | } 47 | 48 | # record file path for use 49 | if(!is.null(bedtools.path) && grepl("wsl", bedtools.path, ignore.case=TRUE)) 50 | filepath <- system(paste0("wsl wslpath -a -u \"", filepath, "\""), intern=TRUE) 51 | inputpaths <- c(inputpaths, filepath) 52 | } 53 | 54 | # join them by spaces 55 | finalargument <- paste(inputpaths, collapse=" ") 56 | 57 | # return the two items 58 | return(list(finalargument, inputtmps)) 59 | } 60 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname) { 2 | bedtoolsr_version<-utils::packageVersion("bedtoolsr") 3 | response<-tryCatch( 4 | { 5 | bedtools.path <- getOption("bedtools.path") 6 | if(!is.null(bedtools.path)) bedtools.path <- paste0(bedtools.path, "/") 7 | system(paste0(bedtools.path, "bedtools --version"), intern=TRUE) 8 | }, 9 | error = function(e) 10 | { 11 | warning("bedtools does not appear to be installed or not in your PATH. If it is installed, please add it to your PATH or run:\noptions(bedtools.path = \"/path/to/\")") 12 | return(NULL) 13 | }) 14 | if(!is.null(response)) { 15 | installed_bedtools_version<-substr(response, 11, nchar(response)) 16 | package_bedtools_version<-substr(bedtoolsr_version, 1, nchar(installed_bedtools_version)) 17 | if(installed_bedtools_version != package_bedtools_version) { 18 | warning(paste("bedtoolsr was built with bedtools version", package_bedtools_version, "but you have version", installed_bedtools_version, "installed. Function syntax may have changed and wrapper will not function correctly. To fix this, please install bedtools version", package_bedtools_version, "and either add it to your PATH or run:\noptions(bedtools.path = \"[bedtools path]\")")) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /bedtoolsr.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | -------------------------------------------------------------------------------- /dev/anomalies.json: -------------------------------------------------------------------------------- 1 | { 2 | "allowNullEvenIfFile": 3 | { 4 | "makewindows": ["g", "b"] 5 | }, 6 | "alternativeUsage": 7 | { 8 | "expand": "bedtools expand -i ", 9 | "groupby": "bedtools groupby [OPTIONS] -i -g -c -o ", 10 | "makewindows": "bedtools makewindows [OPTIONS] -g OR -b -w OR -n ", 11 | "overlap": "bedtools overlap -i -cols " 12 | }, 13 | "fileOptions": ["bed", "BEDPE", "gff", "vcf", "bam", "BAM", "fasta", "FQ", "genome", "FILE"], 14 | "hasHeader": ["fisher", "jaccard"], 15 | "ignoreOptions": 16 | { 17 | "split": ["h", "v"] 18 | }, 19 | "noRinput": ["bamtobed", "bamtofastq"], 20 | "noRoutput": ["split"], 21 | "optionalFileArgs": ["excl", "incl"], 22 | "optionConverter": 23 | { 24 | "3": "three", 25 | "5": "five", 26 | "name+": "nameplus" 27 | }, 28 | "skipFunctions": [] 29 | } 30 | -------------------------------------------------------------------------------- /dev/createOptions.R: -------------------------------------------------------------------------------- 1 | #' Creates options based on user input 2 | #' 3 | #' @param names vector of names of options 4 | #' @param values vector of values of options 5 | #' 6 | #' ### Define a function that determines establishes files and paths for bedtools functions 7 | createOptions <- function(names, values) 8 | { 9 | options <- "" 10 | if(length(names) > 0) 11 | for(i in 1:length(names)) 12 | if(!is.null(values[[i]])&&(!is.logical(values[[i]])||values[[i]])) 13 | { 14 | options <- paste(options, paste(" -", names[i], sep="")) 15 | if(is.character(values[[i]]) || is.numeric(values[[i]])) 16 | options <- paste(options, " ", values[i]) 17 | else if(is.list(values[[i]])) 18 | options <- paste(options, " ", values[i][[1]]) 19 | } 20 | 21 | # return the two items 22 | return(options) 23 | } 24 | -------------------------------------------------------------------------------- /dev/deleteTempFiles.R: -------------------------------------------------------------------------------- 1 | #' Deletes temp files 2 | #' 3 | #' @param tempfiles a vector of tempfiles for deletion 4 | #' 5 | #' ### Define a function that determines establishes files and paths for bedtools functions 6 | deleteTempFiles <- function(tempfiles) 7 | { 8 | for(tempfile in tempfiles) 9 | if(exists(tempfile)) 10 | file.remove (tempfile) 11 | } -------------------------------------------------------------------------------- /dev/document.R: -------------------------------------------------------------------------------- 1 | args <- commandArgs(trailingOnly = TRUE) 2 | 3 | print ("Building man files") 4 | library('devtools') 5 | library('roxygen2') 6 | library('testthat') 7 | devtools::document(args[1]) 8 | 9 | # Test Functions 10 | library("bedtoolsr") 11 | print ("Testing functions") 12 | test_package(package = 'bedtoolsr') 13 | -------------------------------------------------------------------------------- /dev/establishPaths.R: -------------------------------------------------------------------------------- 1 | #' Determines if arguments are paths or R objects. Makes temp files when 2 | #' neccesary. Makes a list of files to use in bedtools call. Makes a list 3 | #' of temp files to delete at end of function. 4 | #' 5 | #' @param input the input for an argument. Could be a path to a file, an R object (data frame), or a list of any combination thereof 6 | #' @param name the name of the argument 7 | #' @param allowRobjects boolean whether or not to allow R objects as inputs 8 | #' 9 | #' ### Define a function that determines establishes files and paths for bedtools functions 10 | establishPaths <- function(input, name="", allowRobjects=TRUE) 11 | { 12 | oo <- options(scipen = 999) 13 | on.exit(options(oo)) 14 | 15 | if(is.null(input)) 16 | return(NULL) 17 | 18 | bedtools.path <- getOption("bedtools.path") 19 | 20 | # convert to list if necessary 21 | if(!inherits(input, "list")) 22 | input <- list(input) 23 | 24 | # iterate through list making files where necessary and recording tmp files for deletion 25 | inputpaths <- c() 26 | inputtmps <- c() 27 | for(item in input) 28 | { 29 | filepath <- item 30 | # if it is an R object 31 | if(!is.character(item) && !is.numeric(item)) 32 | { 33 | if(allowRobjects == FALSE) 34 | stop("R objects are not permitted as arguments for",name) 35 | 36 | # write a temp file 37 | filepath <- tempfile(name, fileext=".txt") 38 | utils::write.table(item, filepath, append = FALSE, sep = " ", quote = FALSE, col.names = FALSE, row.names = FALSE) 39 | 40 | # record temp file for deletion 41 | inputtmps <- c(inputtmps, filepath) 42 | } 43 | else if(!file.exists(item) && file.exists(system.file("data", item, package = "bedtoolsr"))) 44 | { 45 | filepath <- system.file("data", item, package = "bedtoolsr") 46 | } 47 | 48 | # record file path for use 49 | if(!is.null(bedtools.path) && grepl("wsl", bedtools.path, ignore.case=TRUE)) 50 | filepath <- system(paste0("wsl wslpath -a -u \"", filepath, "\""), intern=TRUE) 51 | inputpaths <- c(inputpaths, filepath) 52 | } 53 | 54 | # join them by spaces 55 | finalargument <- paste(inputpaths, collapse=" ") 56 | 57 | # return the two items 58 | return(list(finalargument, inputtmps)) 59 | } 60 | -------------------------------------------------------------------------------- /dev/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname) { 2 | bedtoolsr_version<-utils::packageVersion("bedtoolsr") 3 | response<-tryCatch( 4 | { 5 | bedtools.path <- getOption("bedtools.path") 6 | if(!is.null(bedtools.path)) bedtools.path <- paste0(bedtools.path, "/") 7 | system(paste0(bedtools.path, "bedtools --version"), intern=TRUE) 8 | }, 9 | error = function(e) 10 | { 11 | warning("bedtools does not appear to be installed or not in your PATH. If it is installed, please add it to your PATH or run:\noptions(bedtools.path = \"/path/to/\")") 12 | return(NULL) 13 | }) 14 | if(!is.null(response)) { 15 | installed_bedtools_version<-substr(response, 11, nchar(response)) 16 | package_bedtools_version<-substr(bedtoolsr_version, 1, nchar(installed_bedtools_version)) 17 | if(installed_bedtools_version != package_bedtools_version) { 18 | warning(paste("bedtoolsr was built with bedtools version", package_bedtools_version, "but you have version", installed_bedtools_version, "installed. Function syntax may have changed and wrapper will not function correctly. To fix this, please install bedtools version", package_bedtools_version, "and either add it to your PATH or run:\noptions(bedtools.path = \"[bedtools path]\")")) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /extdata/hg19: -------------------------------------------------------------------------------- 1 | chr1 249250621 2 | chr10 135534747 3 | chr11 135006516 4 | chr11_gl000202_random 40103 5 | chr12 133851895 6 | chr13 115169878 7 | chr14 107349540 8 | chr15 102531392 9 | chr16 90354753 10 | chr17 81195210 11 | chr17_ctg5_hap1 1680828 12 | chr17_gl000203_random 37498 13 | chr17_gl000204_random 81310 14 | chr17_gl000205_random 174588 15 | chr17_gl000206_random 41001 16 | chr18 78077248 17 | chr18_gl000207_random 4262 18 | chr19 59128983 19 | chr19_gl000208_random 92689 20 | chr19_gl000209_random 159169 21 | chr1_gl000191_random 106433 22 | chr1_gl000192_random 547496 23 | chr2 243199373 24 | chr20 63025520 25 | chr21 48129895 26 | chr21_gl000210_random 27682 27 | chr22 51304566 28 | chr3 198022430 29 | chr4 191154276 30 | chr4_ctg9_hap1 590426 31 | chr4_gl000193_random 189789 32 | chr4_gl000194_random 191469 33 | chr5 180915260 34 | chr6 171115067 35 | chr6_apd_hap1 4622290 36 | chr6_cox_hap2 4795371 37 | chr6_dbb_hap3 4610396 38 | chr6_mann_hap4 4683263 39 | chr6_mcf_hap5 4833398 40 | chr6_qbl_hap6 4611984 41 | chr6_ssto_hap7 4928567 42 | chr7 159138663 43 | chr7_gl000195_random 182896 44 | chr8 146364022 45 | chr8_gl000196_random 38914 46 | chr8_gl000197_random 37175 47 | chr9 141213431 48 | chr9_gl000198_random 90085 49 | chr9_gl000199_random 169874 50 | chr9_gl000200_random 187035 51 | chr9_gl000201_random 36148 52 | chrM 16571 53 | chrUn_gl000211 166566 54 | chrUn_gl000212 186858 55 | chrUn_gl000213 164239 56 | chrUn_gl000214 137718 57 | chrUn_gl000215 172545 58 | chrUn_gl000216 172294 59 | chrUn_gl000217 172149 60 | chrUn_gl000218 161147 61 | chrUn_gl000219 179198 62 | chrUn_gl000220 161802 63 | chrUn_gl000221 155397 64 | chrUn_gl000222 186861 65 | chrUn_gl000223 180455 66 | chrUn_gl000224 179693 67 | chrUn_gl000225 211173 68 | chrUn_gl000226 15008 69 | chrUn_gl000227 128374 70 | chrUn_gl000228 129120 71 | chrUn_gl000229 19913 72 | chrUn_gl000230 43691 73 | chrUn_gl000231 27386 74 | chrUn_gl000232 40652 75 | chrUn_gl000233 45941 76 | chrUn_gl000234 40531 77 | chrUn_gl000235 34474 78 | chrUn_gl000236 41934 79 | chrUn_gl000237 45867 80 | chrUn_gl000238 39939 81 | chrUn_gl000239 33824 82 | chrUn_gl000240 41933 83 | chrUn_gl000241 42152 84 | chrUn_gl000242 43523 85 | chrUn_gl000243 43341 86 | chrUn_gl000244 39929 87 | chrUn_gl000245 36651 88 | chrUn_gl000246 38154 89 | chrUn_gl000247 36422 90 | chrUn_gl000248 39786 91 | chrUn_gl000249 38502 92 | chrX 155270560 93 | chrY 59373566 94 | -------------------------------------------------------------------------------- /extdata/mm10: -------------------------------------------------------------------------------- 1 | chr1 195471971 2 | chr10 130694993 3 | chr11 122082543 4 | chr12 120129022 5 | chr13 120421639 6 | chr14 124902244 7 | chr15 104043685 8 | chr16 98207768 9 | chr17 94987271 10 | chr18 90702639 11 | chr19 61431566 12 | chr1_GL456210_random 169725 13 | chr1_GL456211_random 241735 14 | chr1_GL456212_random 153618 15 | chr1_GL456213_random 39340 16 | chr1_GL456221_random 206961 17 | chr2 182113224 18 | chr3 160039680 19 | chr4 156508116 20 | chr4_GL456216_random 66673 21 | chr4_GL456350_random 227966 22 | chr4_JH584292_random 14945 23 | chr4_JH584293_random 207968 24 | chr4_JH584294_random 191905 25 | chr4_JH584295_random 1976 26 | chr5 151834684 27 | chr5_GL456354_random 195993 28 | chr5_JH584296_random 199368 29 | chr5_JH584297_random 205776 30 | chr5_JH584298_random 184189 31 | chr5_JH584299_random 953012 32 | chr6 149736546 33 | chr7 145441459 34 | chr7_GL456219_random 175968 35 | chr8 129401213 36 | chr9 124595110 37 | chrM 16299 38 | chrUn_GL456239 40056 39 | chrUn_GL456359 22974 40 | chrUn_GL456360 31704 41 | chrUn_GL456366 47073 42 | chrUn_GL456367 42057 43 | chrUn_GL456368 20208 44 | chrUn_GL456370 26764 45 | chrUn_GL456372 28664 46 | chrUn_GL456378 31602 47 | chrUn_GL456379 72385 48 | chrUn_GL456381 25871 49 | chrUn_GL456382 23158 50 | chrUn_GL456383 38659 51 | chrUn_GL456385 35240 52 | chrUn_GL456387 24685 53 | chrUn_GL456389 28772 54 | chrUn_GL456390 24668 55 | chrUn_GL456392 23629 56 | chrUn_GL456393 55711 57 | chrUn_GL456394 24323 58 | chrUn_GL456396 21240 59 | chrUn_JH584304 114452 60 | chrX 171031299 61 | chrX_GL456233_random 336933 62 | chrY 91744698 63 | chrY_JH584300_random 182347 64 | chrY_JH584301_random 259875 65 | chrY_JH584302_random 155838 66 | chrY_JH584303_random 158099 67 | -------------------------------------------------------------------------------- /extdata/mm9: -------------------------------------------------------------------------------- 1 | chr1 197195432 2 | chr10 129993255 3 | chr11 121843856 4 | chr12 121257530 5 | chr13 120284312 6 | chr13_random 400311 7 | chr14 125194864 8 | chr15 103494974 9 | chr16 98319150 10 | chr16_random 3994 11 | chr17 95272651 12 | chr17_random 628739 13 | chr18 90772031 14 | chr19 61342430 15 | chr1_random 1231697 16 | chr2 181748087 17 | chr3 159599783 18 | chr3_random 41899 19 | chr4 155630120 20 | chr4_random 160594 21 | chr5 152537259 22 | chr5_random 357350 23 | chr6 149517037 24 | chr7 152524553 25 | chr7_random 362490 26 | chr8 131738871 27 | chr8_random 849593 28 | chr9 124076172 29 | chr9_random 449403 30 | chrM 16299 31 | chrUn_random 5900358 32 | chrX 166650296 33 | chrX_random 1785075 34 | chrY 15902555 35 | chrY_random 58682461 36 | -------------------------------------------------------------------------------- /img/exampleResults.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhanstielLab/bedtoolsr/b601e51ba12bae66618707b389d9d7287561877b/img/exampleResults.png -------------------------------------------------------------------------------- /inst/extdata/dm6: -------------------------------------------------------------------------------- 1 | ../../extdata/dm6 -------------------------------------------------------------------------------- /inst/extdata/hg19: -------------------------------------------------------------------------------- 1 | ../../extdata/hg19 -------------------------------------------------------------------------------- /inst/extdata/hg38: -------------------------------------------------------------------------------- 1 | ../../extdata/hg38 -------------------------------------------------------------------------------- /inst/extdata/mm10: -------------------------------------------------------------------------------- 1 | ../../extdata/mm10 -------------------------------------------------------------------------------- /inst/extdata/mm9: -------------------------------------------------------------------------------- 1 | ../../extdata/mm9 -------------------------------------------------------------------------------- /inst/tests/testthat.R: -------------------------------------------------------------------------------- 1 | ../../tests/testthat.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.annotate.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.annotate.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.closest.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.closest.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.cluster.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.cluster.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.complement.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.complement.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.coverage.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.coverage.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.expand.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.expand.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.fisher.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.fisher.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.flank.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.flank.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.genomecov.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.genomecov.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.groupby.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.groupby.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.intersect.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.intersect.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.jaccard.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.jaccard.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.makewindows.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.makewindows.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.map.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.map.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.merge.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.merge.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.overlap.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.overlap.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.shift.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.shift.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.shuffle.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.shuffle.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.slop.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.slop.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.sort.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.sort.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.spacing.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.spacing.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.subtract.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.subtract.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.unionbedg.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.unionbedg.R -------------------------------------------------------------------------------- /inst/tests/testthat/test-bt.window.R: -------------------------------------------------------------------------------- 1 | ../../../tests/testthat/test-bt.window.R -------------------------------------------------------------------------------- /man/bt.annotate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.annotate.R 3 | \name{bt.annotate} 4 | \alias{bt.annotate} 5 | \title{Annotates the depth & breadth of coverage of features from mult. files 6 | on the intervals in -i.} 7 | \usage{ 8 | bt.annotate( 9 | i, 10 | files, 11 | names = NULL, 12 | counts = NULL, 13 | both = NULL, 14 | s = NULL, 15 | S = NULL, 16 | output = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{i}{} 21 | 22 | \item{files}{FILE1 FILE2..FILEn} 23 | 24 | \item{names}{A list of names (one / file) to describe each file in -i. 25 | These names will be printed as a header line.} 26 | 27 | \item{counts}{Report the count of features in each file that overlap -i. 28 | - Default is to report the fraction of -i covered by each file.} 29 | 30 | \item{both}{Report the counts followed by the percent coverage. 31 | - Default is to report the fraction of -i covered by each file.} 32 | 33 | \item{s}{Require same strandedness. That is, only counts overlaps 34 | on the _same_ strand. 35 | - By default, overlaps are counted without respect to strand.} 36 | 37 | \item{S}{Require different strandedness. That is, only count overlaps 38 | on the _opposite_ strand. 39 | - By default, overlaps are counted without respect to strand.} 40 | 41 | \item{output}{Output filepath instead of returning output in R.} 42 | } 43 | \description{ 44 | Annotates the depth & breadth of coverage of features from mult. files 45 | on the intervals in -i. 46 | } 47 | -------------------------------------------------------------------------------- /man/bt.bamtobed.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.bamtobed.R 3 | \name{bt.bamtobed} 4 | \alias{bt.bamtobed} 5 | \title{Converts BAM alignments to BED6 or BEDPE format.} 6 | \usage{ 7 | bt.bamtobed( 8 | i, 9 | bedpe = NULL, 10 | mate1 = NULL, 11 | bed12 = NULL, 12 | split = NULL, 13 | splitD = NULL, 14 | ed = NULL, 15 | tag = NULL, 16 | color = NULL, 17 | cigar = NULL, 18 | output = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{i}{} 23 | 24 | \item{bedpe}{Write BEDPE format. 25 | - Requires BAM to be grouped or sorted by query.} 26 | 27 | \item{mate1}{When writing BEDPE (-bedpe) format, 28 | always report mate one as the first BEDPE "block".} 29 | 30 | \item{bed12}{Write "blocked" BED format (aka "BED12"). Forces -split. 31 | http://genome-test.cse.ucsc.edu/FAQ/FAQformat#format1} 32 | 33 | \item{split}{Report "split" BAM alignments as separate BED entries. 34 | Splits only on N CIGAR operations.} 35 | 36 | \item{splitD}{Split alignments based on N and D CIGAR operators. 37 | Forces -split.} 38 | 39 | \item{ed}{Use BAM edit distance (NM tag) for BED score. 40 | - Default for BED is to use mapping quality. 41 | - Default for BEDPE is to use the minimum of 42 | the two mapping qualities for the pair. 43 | - When -ed is used with -bedpe, the total edit 44 | distance from the two mates is reported.} 45 | 46 | \item{tag}{Use other NUMERIC BAM alignment tag for BED score. 47 | - Default for BED is to use mapping quality. 48 | Disallowed with BEDPE output.} 49 | 50 | \item{color}{An R,G,B string for the color used with BED12 format. 51 | Default is (255,0,0).} 52 | 53 | \item{cigar}{Add the CIGAR string to the BED entry as a 7th column.} 54 | 55 | \item{output}{Output filepath instead of returning output in R.} 56 | } 57 | \description{ 58 | Converts BAM alignments to BED6 or BEDPE format. 59 | } 60 | -------------------------------------------------------------------------------- /man/bt.bamtofastq.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.bamtofastq.R 3 | \name{bt.bamtofastq} 4 | \alias{bt.bamtofastq} 5 | \title{Convert BAM alignments to FASTQ files.} 6 | \usage{ 7 | bt.bamtofastq(i, fq, fq2 = NULL, tags = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{fq}{} 13 | 14 | \item{fq2}{FASTQ for second end. Used if BAM contains paired-end data. 15 | BAM should be sorted by query name is creating paired FASTQ.} 16 | 17 | \item{tags}{Create FASTQ based on the mate info 18 | in the BAM R2 and Q2 tags.} 19 | 20 | \item{output}{Output filepath instead of returning output in R.} 21 | } 22 | \description{ 23 | Convert BAM alignments to FASTQ files. 24 | } 25 | -------------------------------------------------------------------------------- /man/bt.bed12tobed6.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.bed12tobed6.R 3 | \name{bt.bed12tobed6} 4 | \alias{bt.bed12tobed6} 5 | \title{Splits BED12 features into discrete BED6 features.} 6 | \usage{ 7 | bt.bed12tobed6(i, n = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{n}{Force the score to be the (1-based) block number from the BED12.} 13 | 14 | \item{output}{Output filepath instead of returning output in R.} 15 | } 16 | \description{ 17 | Splits BED12 features into discrete BED6 features. 18 | } 19 | -------------------------------------------------------------------------------- /man/bt.bedpetobam.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.bedpetobam.R 3 | \name{bt.bedpetobam} 4 | \alias{bt.bedpetobam} 5 | \title{Converts feature records to BAM format.} 6 | \usage{ 7 | bt.bedpetobam(i, g, mapq = NULL, ubam = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{g}{} 13 | 14 | \item{mapq}{Set the mappinq quality for the BAM records. 15 | (INT) Default: 255} 16 | 17 | \item{ubam}{Write uncompressed BAM output. Default writes compressed BAM.} 18 | 19 | \item{output}{Output filepath instead of returning output in R.} 20 | } 21 | \description{ 22 | Converts feature records to BAM format. 23 | } 24 | -------------------------------------------------------------------------------- /man/bt.bedtobam.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.bedtobam.R 3 | \name{bt.bedtobam} 4 | \alias{bt.bedtobam} 5 | \title{Converts feature records to BAM format.} 6 | \usage{ 7 | bt.bedtobam(i, g, mapq = NULL, bed12 = NULL, ubam = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{g}{} 13 | 14 | \item{mapq}{Set the mappinq quality for the BAM records. 15 | (INT) Default: 255} 16 | 17 | \item{bed12}{The BED file is in BED12 format. The BAM CIGAR 18 | string will reflect BED "blocks".} 19 | 20 | \item{ubam}{Write uncompressed BAM output. Default writes compressed BAM.} 21 | 22 | \item{output}{Output filepath instead of returning output in R.} 23 | } 24 | \description{ 25 | Converts feature records to BAM format. 26 | } 27 | -------------------------------------------------------------------------------- /man/bt.cluster.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.cluster.R 3 | \name{bt.cluster} 4 | \alias{bt.cluster} 5 | \title{Clusters overlapping/nearby BED/GFF/VCF intervals.} 6 | \usage{ 7 | bt.cluster(i, s = NULL, d = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{s}{Force strandedness. That is, only merge features 13 | that are the same strand. 14 | - By default, merging is done without respect to strand.} 15 | 16 | \item{d}{Maximum distance between features allowed for features 17 | to be merged. 18 | - Def. 0. That is, overlapping & book-ended features are merged. 19 | - (INTEGER)} 20 | 21 | \item{output}{Output filepath instead of returning output in R.} 22 | } 23 | \description{ 24 | Clusters overlapping/nearby BED/GFF/VCF intervals. 25 | } 26 | -------------------------------------------------------------------------------- /man/bt.complement.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.complement.R 3 | \name{bt.complement} 4 | \alias{bt.complement} 5 | \title{Returns the base pair complement of a feature file.} 6 | \usage{ 7 | bt.complement(i, g, L = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{g}{} 13 | 14 | \item{L}{Limit output to solely the chromosomes with records in the input file.} 15 | 16 | \item{output}{Output filepath instead of returning output in R.} 17 | } 18 | \description{ 19 | Returns the base pair complement of a feature file. 20 | } 21 | -------------------------------------------------------------------------------- /man/bt.coverage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.coverage.R 3 | \name{bt.coverage} 4 | \alias{bt.coverage} 5 | \title{Returns the depth and breadth of coverage of features from B 6 | on the intervals in A.} 7 | \usage{ 8 | bt.coverage( 9 | a, 10 | b, 11 | hist = NULL, 12 | d = NULL, 13 | counts = NULL, 14 | mean = NULL, 15 | s = NULL, 16 | S = NULL, 17 | f = NULL, 18 | F = NULL, 19 | r = NULL, 20 | e = NULL, 21 | split = NULL, 22 | g = NULL, 23 | nonamecheck = NULL, 24 | sorted = NULL, 25 | bed = NULL, 26 | header = NULL, 27 | nobuf = NULL, 28 | iobuf = NULL, 29 | output = NULL 30 | ) 31 | } 32 | \arguments{ 33 | \item{a}{} 34 | 35 | \item{b}{} 36 | 37 | \item{hist}{Report a histogram of coverage for each feature in A 38 | as well as a summary histogram for _all_ features in A. 39 | Output (tab delimited) after each feature in A: 40 | 1) depth 41 | 2) # bases at depth 42 | 3) size of A 43 | 4) percent of A at depth} 44 | 45 | \item{d}{Report the depth at each position in each A feature. 46 | Positions reported are one based. Each position 47 | and depth follow the complete A feature.} 48 | 49 | \item{counts}{Only report the count of overlaps, don't compute fraction, etc.} 50 | 51 | \item{mean}{Report the mean depth of all positions in each A feature.} 52 | 53 | \item{s}{Require same strandedness. That is, only report hits in B 54 | that overlap A on the _same_ strand. 55 | - By default, overlaps are reported without respect to strand.} 56 | 57 | \item{S}{Require different strandedness. That is, only report hits in B 58 | that overlap A on the _opposite_ strand. 59 | - By default, overlaps are reported without respect to strand.} 60 | 61 | \item{f}{Minimum overlap required as a fraction of A. 62 | - Default is 1E-9 (i.e., 1bp). 63 | - FLOAT (e.g. 0.50)} 64 | 65 | \item{F}{Minimum overlap required as a fraction of B. 66 | - Default is 1E-9 (i.e., 1bp). 67 | - FLOAT (e.g. 0.50)} 68 | 69 | \item{r}{Require that the fraction overlap be reciprocal for A AND B. 70 | - In other words, if -f is 0.90 and -r is used, this requires 71 | that B overlap 90 percent of A and A _also_ overlaps 90 percent of B.} 72 | 73 | \item{e}{Require that the minimum fraction be satisfied for A OR B. 74 | - In other words, if -e is used with -f 0.90 and -F 0.10 this requires 75 | that either 90 percent of A is covered OR 10 percent of B is covered. 76 | Without -e, both fractions would have to be satisfied.} 77 | 78 | \item{split}{Treat "split" BAM or BED12 entries as distinct BED intervals.} 79 | 80 | \item{g}{Provide a genome file to enforce consistent chromosome sort order 81 | across input files. Only applies when used with -sorted option.} 82 | 83 | \item{nonamecheck}{For sorted data, don't throw an error if the file has different naming conventions 84 | for the same chromosome. ex. "chr1" vs "chr01".} 85 | 86 | \item{sorted}{Use the "chromsweep" algorithm for sorted (-k1,1 -k2,2n) input.} 87 | 88 | \item{bed}{If using BAM input, write output as BED.} 89 | 90 | \item{header}{Print the header from the A file prior to results.} 91 | 92 | \item{nobuf}{Disable buffered output. Using this option will cause each line 93 | of output to be printed as it is generated, rather than saved 94 | in a buffer. This will make printing large output files 95 | noticeably slower, but can be useful in conjunction with 96 | other software tools and scripts that need to process one 97 | line of bedtools output at a time.} 98 | 99 | \item{iobuf}{Specify amount of memory to use for input buffer. 100 | Takes an integer argument. Optional suffixes K/M/G supported. 101 | Note: currently has no effect with compressed files.} 102 | 103 | \item{output}{Output filepath instead of returning output in R.} 104 | } 105 | \description{ 106 | Returns the depth and breadth of coverage of features from B 107 | on the intervals in A. 108 | } 109 | -------------------------------------------------------------------------------- /man/bt.expand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.expand.R 3 | \name{bt.expand} 4 | \alias{bt.expand} 5 | \title{Replicate lines in a file based on columns of comma-separated values.} 6 | \usage{ 7 | bt.expand(i, c = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{c}{Specify the column (1-based) that should be summarized. 13 | - Required.} 14 | 15 | \item{output}{Output filepath instead of returning output in R.} 16 | } 17 | \description{ 18 | Replicate lines in a file based on columns of comma-separated values. 19 | } 20 | -------------------------------------------------------------------------------- /man/bt.fisher.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.fisher.R 3 | \name{bt.fisher} 4 | \alias{bt.fisher} 5 | \title{Calculate Fisher statistic b/w two feature files.} 6 | \usage{ 7 | bt.fisher( 8 | a, 9 | b, 10 | g, 11 | m = NULL, 12 | s = NULL, 13 | S = NULL, 14 | f = NULL, 15 | F = NULL, 16 | r = NULL, 17 | e = NULL, 18 | split = NULL, 19 | nonamecheck = NULL, 20 | bed = NULL, 21 | header = NULL, 22 | nobuf = NULL, 23 | iobuf = NULL, 24 | output = NULL 25 | ) 26 | } 27 | \arguments{ 28 | \item{a}{} 29 | 30 | \item{b}{} 31 | 32 | \item{g}{} 33 | 34 | \item{m}{Merge overlapping intervals before 35 | - looking at overlap.} 36 | 37 | \item{s}{Require same strandedness. That is, only report hits in B 38 | that overlap A on the _same_ strand. 39 | - By default, overlaps are reported without respect to strand.} 40 | 41 | \item{S}{Require different strandedness. That is, only report hits in B 42 | that overlap A on the _opposite_ strand. 43 | - By default, overlaps are reported without respect to strand.} 44 | 45 | \item{f}{Minimum overlap required as a fraction of A. 46 | - Default is 1E-9 (i.e., 1bp). 47 | - FLOAT (e.g. 0.50)} 48 | 49 | \item{F}{Minimum overlap required as a fraction of B. 50 | - Default is 1E-9 (i.e., 1bp). 51 | - FLOAT (e.g. 0.50)} 52 | 53 | \item{r}{Require that the fraction overlap be reciprocal for A AND B. 54 | - In other words, if -f is 0.90 and -r is used, this requires 55 | that B overlap 90 percent of A and A _also_ overlaps 90 percent of B.} 56 | 57 | \item{e}{Require that the minimum fraction be satisfied for A OR B. 58 | - In other words, if -e is used with -f 0.90 and -F 0.10 this requires 59 | that either 90 percent of A is covered OR 10 percent of B is covered. 60 | Without -e, both fractions would have to be satisfied.} 61 | 62 | \item{split}{Treat "split" BAM or BED12 entries as distinct BED intervals.} 63 | 64 | \item{nonamecheck}{For sorted data, don't throw an error if the file has different naming conventions 65 | for the same chromosome. ex. "chr1" vs "chr01".} 66 | 67 | \item{bed}{If using BAM input, write output as BED.} 68 | 69 | \item{header}{Print the header from the A file prior to results.} 70 | 71 | \item{nobuf}{Disable buffered output. Using this option will cause each line 72 | of output to be printed as it is generated, rather than saved 73 | in a buffer. This will make printing large output files 74 | noticeably slower, but can be useful in conjunction with 75 | other software tools and scripts that need to process one 76 | line of bedtools output at a time.} 77 | 78 | \item{iobuf}{Specify amount of memory to use for input buffer. 79 | Takes an integer argument. Optional suffixes K/M/G supported. 80 | Note: currently has no effect with compressed files.} 81 | 82 | \item{output}{Output filepath instead of returning output in R.} 83 | } 84 | \description{ 85 | Calculate Fisher statistic b/w two feature files. 86 | } 87 | -------------------------------------------------------------------------------- /man/bt.flank.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.flank.R 3 | \name{bt.flank} 4 | \alias{bt.flank} 5 | \title{Creates flanking interval(s) for each BED/GFF/VCF feature.} 6 | \usage{ 7 | bt.flank( 8 | i, 9 | g, 10 | b = NULL, 11 | l = NULL, 12 | r = NULL, 13 | s = NULL, 14 | pct = NULL, 15 | header = NULL, 16 | output = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{i}{} 21 | 22 | \item{g}{} 23 | 24 | \item{b}{Create flanking interval(s) using -b base pairs in each direction. 25 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 26 | 27 | \item{l}{The number of base pairs that a flank should start from 28 | orig. start coordinate. 29 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 30 | 31 | \item{r}{The number of base pairs that a flank should end from 32 | orig. end coordinate. 33 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 34 | 35 | \item{s}{Define -l and -r based on strand. 36 | E.g. if used, -l 500 for a negative-stranded feature, 37 | it will start the flank 500 bp downstream. Default = false.} 38 | 39 | \item{pct}{Define -l and -r as a fraction of the feature's length. 40 | E.g. if used on a 1000bp feature, -l 0.50, 41 | will add 500 bp "upstream". Default = false.} 42 | 43 | \item{header}{Print the header from the input file prior to results.} 44 | 45 | \item{output}{Output filepath instead of returning output in R.} 46 | } 47 | \description{ 48 | Creates flanking interval(s) for each BED/GFF/VCF feature. 49 | } 50 | -------------------------------------------------------------------------------- /man/bt.genomecov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.genomecov.R 3 | \name{bt.genomecov} 4 | \alias{bt.genomecov} 5 | \title{Compute the coverage of a feature file among a genome.} 6 | \usage{ 7 | bt.genomecov( 8 | i, 9 | g, 10 | ibam = NULL, 11 | d = NULL, 12 | dz = NULL, 13 | bg = NULL, 14 | bga = NULL, 15 | split = NULL, 16 | ignoreD = NULL, 17 | strand = NULL, 18 | pc = NULL, 19 | fs = NULL, 20 | du = NULL, 21 | five = NULL, 22 | three = NULL, 23 | max = NULL, 24 | scale = NULL, 25 | trackline = NULL, 26 | trackopts = NULL, 27 | output = NULL 28 | ) 29 | } 30 | \arguments{ 31 | \item{i}{} 32 | 33 | \item{g}{} 34 | 35 | \item{ibam}{The input file is in BAM format. 36 | Note: BAM _must_ be sorted by position} 37 | 38 | \item{d}{Report the depth at each genome position (with one-based coordinates). 39 | Default behavior is to report a histogram.} 40 | 41 | \item{dz}{Report the depth at each genome position (with zero-based coordinates). 42 | Reports only non-zero positions. 43 | Default behavior is to report a histogram.} 44 | 45 | \item{bg}{Report depth in BedGraph format. For details, see: 46 | genome.ucsc.edu/goldenPath/help/bedgraph.html} 47 | 48 | \item{bga}{Report depth in BedGraph format, as above (-bg). 49 | However with this option, regions with zero 50 | coverage are also reported. This allows one to 51 | quickly extract all regions of a genome with 0 52 | coverage by applying: "grep -w 0$" to the output.} 53 | 54 | \item{split}{Treat "split" BAM or BED12 entries as distinct BED intervals. 55 | when computing coverage. 56 | For BAM files, this uses the CIGAR "N" and "D" operations 57 | to infer the blocks for computing coverage. 58 | For BED12 files, this uses the BlockCount, BlockStarts, and BlockEnds 59 | fields (i.e., columns 10,11,12).} 60 | 61 | \item{ignoreD}{Ignore local deletions (CIGAR "D" operations) in BAM entries 62 | when computing coverage.} 63 | 64 | \item{strand}{Calculate coverage of intervals from a specific strand. 65 | With BED files, requires at least 6 columns (strand is column 6). 66 | - (STRING): can be + or -} 67 | 68 | \item{pc}{Calculate coverage of pair-end fragments. 69 | Works for BAM files only} 70 | 71 | \item{fs}{Force to use provided fragment size instead of read length 72 | Works for BAM files only} 73 | 74 | \item{du}{Change strand af the mate read (so both reads from the same strand) useful for strand specific 75 | Works for BAM files only} 76 | 77 | \item{five}{Calculate coverage of 5" positions (instead of entire interval).} 78 | 79 | \item{three}{Calculate coverage of 3" positions (instead of entire interval).} 80 | 81 | \item{max}{Combine all positions with a depth >= max into 82 | a single bin in the histogram. Irrelevant 83 | for -d and -bedGraph 84 | - (INTEGER)} 85 | 86 | \item{scale}{Scale the coverage by a constant factor. 87 | Each coverage value is multiplied by this factor before being reported. 88 | Useful for normalizing coverage by, e.g., reads per million (RPM). 89 | - Default is 1.0; i.e., unscaled. 90 | - (FLOAT)} 91 | 92 | \item{trackline}{Adds a UCSC/Genome-Browser track line definition in the first line of the output. 93 | - See here for more details about track line definition: 94 | http://genome.ucsc.edu/goldenPath/help/bedgraph.html 95 | - NOTE: When adding a trackline definition, the output BedGraph can be easily 96 | uploaded to the Genome Browser as a custom track, 97 | BUT CAN NOT be converted into a BigWig file (w/o removing the first line).} 98 | 99 | \item{trackopts}{Writes additional track line definition parameters in the first line. 100 | - Example: 101 | -trackopts 'name="My Track" visibility=2 color=255,30,30' 102 | Note the use of single-quotes if you have spaces in your parameters. 103 | - (TEXT)} 104 | 105 | \item{output}{Output filepath instead of returning output in R.} 106 | } 107 | \description{ 108 | Compute the coverage of a feature file among a genome. 109 | } 110 | -------------------------------------------------------------------------------- /man/bt.getfasta.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.getfasta.R 3 | \name{bt.getfasta} 4 | \alias{bt.getfasta} 5 | \title{Extract DNA sequences from a fasta file based on feature coordinates.} 6 | \usage{ 7 | bt.getfasta( 8 | fi, 9 | bed, 10 | fo = NULL, 11 | name = NULL, 12 | nameplus = NULL, 13 | nameOnly = NULL, 14 | split = NULL, 15 | tab = NULL, 16 | bedOut = NULL, 17 | s = NULL, 18 | fullHeader = NULL, 19 | rna = NULL, 20 | output = NULL 21 | ) 22 | } 23 | \arguments{ 24 | \item{fi}{} 25 | 26 | \item{bed}{} 27 | 28 | \item{fo}{Output file (opt., default is STDOUT} 29 | 30 | \item{name}{Use the name field and coordinates for the FASTA header} 31 | 32 | \item{nameplus}{(deprecated) Use the name field and coordinates for the FASTA header} 33 | 34 | \item{nameOnly}{Use the name field for the FASTA header} 35 | 36 | \item{split}{Given BED12 fmt., extract and concatenate the sequences 37 | from the BED "blocks" (e.g., exons)} 38 | 39 | \item{tab}{Write output in TAB delimited format.} 40 | 41 | \item{bedOut}{Report extract sequences in a tab-delimited BED format instead of in FASTA format. 42 | - Default is FASTA format.} 43 | 44 | \item{s}{Force strandedness. If the feature occupies the antisense, 45 | strand, the sequence will be reverse complemented. 46 | - By default, strand information is ignored.} 47 | 48 | \item{fullHeader}{Use full fasta header. 49 | - By default, only the word before the first space or tab 50 | is used.} 51 | 52 | \item{rna}{The FASTA is RNA not DNA. Reverse complementation handled accordingly.} 53 | 54 | \item{output}{Output filepath instead of returning output in R.} 55 | } 56 | \description{ 57 | Extract DNA sequences from a fasta file based on feature coordinates. 58 | } 59 | -------------------------------------------------------------------------------- /man/bt.groupby.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.groupby.R 3 | \name{bt.groupby} 4 | \alias{bt.groupby} 5 | \title{Summarizes a dataset column based upon 6 | common column groupings. Akin to the SQL "group by" command.} 7 | \usage{ 8 | bt.groupby( 9 | i, 10 | g = NULL, 11 | c = NULL, 12 | o = NULL, 13 | full = NULL, 14 | inheader = NULL, 15 | outheader = NULL, 16 | header = NULL, 17 | ignorecase = NULL, 18 | prec = NULL, 19 | delim = NULL, 20 | output = NULL 21 | ) 22 | } 23 | \arguments{ 24 | \item{i}{} 25 | 26 | \item{g}{} 27 | 28 | \item{c}{} 29 | 30 | \item{o}{} 31 | 32 | \item{full}{Print all columns from input file. The first line in the group is used. 33 | Default: print only grouped columns.} 34 | 35 | \item{inheader}{Input file has a header line - the first line will be ignored.} 36 | 37 | \item{outheader}{Print header line in the output, detailing the column names. 38 | If the input file has headers (-inheader), the output file 39 | will use the input's column names. 40 | If the input file has no headers, the output file 41 | will use "col_1", "col_2", etc. as the column names.} 42 | 43 | \item{header}{same as '-inheader -outheader'} 44 | 45 | \item{ignorecase}{Group values regardless of upper/lower case.} 46 | 47 | \item{prec}{Sets the decimal precision for output (Default: 5)} 48 | 49 | \item{delim}{Specify a custom delimiter for the collapse operations. 50 | - Example: -delim "|" 51 | - Default: ",".} 52 | 53 | \item{output}{Output filepath instead of returning output in R.} 54 | } 55 | \description{ 56 | Summarizes a dataset column based upon 57 | common column groupings. Akin to the SQL "group by" command. 58 | } 59 | -------------------------------------------------------------------------------- /man/bt.igv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.igv.R 3 | \name{bt.igv} 4 | \alias{bt.igv} 5 | \title{Creates a batch script to create IGV images 6 | at each interval defined in a BED/GFF/VCF file.} 7 | \usage{ 8 | bt.igv( 9 | i, 10 | path = NULL, 11 | sess = NULL, 12 | sort = NULL, 13 | clps = NULL, 14 | name = NULL, 15 | slop = NULL, 16 | img = NULL, 17 | output = NULL 18 | ) 19 | } 20 | \arguments{ 21 | \item{i}{} 22 | 23 | \item{path}{The full path to which the IGV snapshots should be written. 24 | (STRING) Default: ./} 25 | 26 | \item{sess}{The full path to an existing IGV session file to be 27 | loaded prior to taking snapshots. 28 | (STRING) Default is for no session to be loaded.} 29 | 30 | \item{sort}{The type of BAM sorting you would like to apply to each image. 31 | Options: base, position, strand, quality, sample, and readGroup 32 | Default is to apply no sorting at all.} 33 | 34 | \item{clps}{Collapse the aligned reads prior to taking a snapshot. 35 | Default is to no collapse.} 36 | 37 | \item{name}{Use the "name" field (column 4) for each image's filename. 38 | Default is to use the "chr:start-pos.ext".} 39 | 40 | \item{slop}{Number of flanking base pairs on the left & right of the image. 41 | - (INT) Default = 0.} 42 | 43 | \item{img}{The type of image to be created. 44 | Options: png, eps, svg 45 | Default is png.} 46 | 47 | \item{output}{Output filepath instead of returning output in R.} 48 | } 49 | \description{ 50 | Creates a batch script to create IGV images 51 | at each interval defined in a BED/GFF/VCF file. 52 | } 53 | -------------------------------------------------------------------------------- /man/bt.jaccard.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.jaccard.R 3 | \name{bt.jaccard} 4 | \alias{bt.jaccard} 5 | \title{Calculate Jaccard statistic b/w two feature files. 6 | Jaccard is the length of the intersection over the union. 7 | Values range from 0 (no intersection) to 1 (self intersection).} 8 | \usage{ 9 | bt.jaccard( 10 | a, 11 | b, 12 | s = NULL, 13 | S = NULL, 14 | f = NULL, 15 | F = NULL, 16 | r = NULL, 17 | e = NULL, 18 | split = NULL, 19 | g = NULL, 20 | nonamecheck = NULL, 21 | bed = NULL, 22 | header = NULL, 23 | nobuf = NULL, 24 | iobuf = NULL, 25 | output = NULL 26 | ) 27 | } 28 | \arguments{ 29 | \item{a}{} 30 | 31 | \item{b}{} 32 | 33 | \item{s}{Require same strandedness. That is, only report hits in B 34 | that overlap A on the _same_ strand. 35 | - By default, overlaps are reported without respect to strand.} 36 | 37 | \item{S}{Require different strandedness. That is, only report hits in B 38 | that overlap A on the _opposite_ strand. 39 | - By default, overlaps are reported without respect to strand.} 40 | 41 | \item{f}{Minimum overlap required as a fraction of A. 42 | - Default is 1E-9 (i.e., 1bp). 43 | - FLOAT (e.g. 0.50)} 44 | 45 | \item{F}{Minimum overlap required as a fraction of B. 46 | - Default is 1E-9 (i.e., 1bp). 47 | - FLOAT (e.g. 0.50)} 48 | 49 | \item{r}{Require that the fraction overlap be reciprocal for A AND B. 50 | - In other words, if -f is 0.90 and -r is used, this requires 51 | that B overlap 90 percent of A and A _also_ overlaps 90 percent of B.} 52 | 53 | \item{e}{Require that the minimum fraction be satisfied for A OR B. 54 | - In other words, if -e is used with -f 0.90 and -F 0.10 this requires 55 | that either 90 percent of A is covered OR 10 percent of B is covered. 56 | Without -e, both fractions would have to be satisfied.} 57 | 58 | \item{split}{Treat "split" BAM or BED12 entries as distinct BED intervals.} 59 | 60 | \item{g}{Provide a genome file to enforce consistent chromosome sort order 61 | across input files. Only applies when used with -sorted option.} 62 | 63 | \item{nonamecheck}{For sorted data, don't throw an error if the file has different naming conventions 64 | for the same chromosome. ex. "chr1" vs "chr01".} 65 | 66 | \item{bed}{If using BAM input, write output as BED.} 67 | 68 | \item{header}{Print the header from the A file prior to results.} 69 | 70 | \item{nobuf}{Disable buffered output. Using this option will cause each line 71 | of output to be printed as it is generated, rather than saved 72 | in a buffer. This will make printing large output files 73 | noticeably slower, but can be useful in conjunction with 74 | other software tools and scripts that need to process one 75 | line of bedtools output at a time.} 76 | 77 | \item{iobuf}{Specify amount of memory to use for input buffer. 78 | Takes an integer argument. Optional suffixes K/M/G supported. 79 | Note: currently has no effect with compressed files.} 80 | 81 | \item{output}{Output filepath instead of returning output in R.} 82 | } 83 | \description{ 84 | Calculate Jaccard statistic b/w two feature files. 85 | Jaccard is the length of the intersection over the union. 86 | Values range from 0 (no intersection) to 1 (self intersection). 87 | } 88 | -------------------------------------------------------------------------------- /man/bt.links.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.links.R 3 | \name{bt.links} 4 | \alias{bt.links} 5 | \title{Creates HTML links to an UCSC Genome Browser from a feature file.} 6 | \usage{ 7 | bt.links(i, base = NULL, org = NULL, db = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{ > out.html} 11 | 12 | \item{base}{The browser basename. Default: http://genome.ucsc.edu} 13 | 14 | \item{org}{The organism. Default: human} 15 | 16 | \item{db}{The build. Default: hg18} 17 | 18 | \item{output}{Output filepath instead of returning output in R.} 19 | } 20 | \description{ 21 | Creates HTML links to an UCSC Genome Browser from a feature file. 22 | } 23 | -------------------------------------------------------------------------------- /man/bt.makewindows.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.makewindows.R 3 | \name{bt.makewindows} 4 | \alias{bt.makewindows} 5 | \title{Makes adjacent or sliding windows across a genome or BED file.} 6 | \usage{ 7 | bt.makewindows( 8 | g = NULL, 9 | b = NULL, 10 | w = NULL, 11 | s = NULL, 12 | n = NULL, 13 | reverse = NULL, 14 | i = NULL, 15 | output = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{g}{ OR} 20 | 21 | \item{b}{} 22 | 23 | \item{w}{ OR} 24 | 25 | \item{s}{ 26 | Step size: i.e., how many base pairs to step before 27 | creating a new window. Used to create "sliding" windows. 28 | - Defaults to window size (non-sliding windows).} 29 | 30 | \item{n}{} 31 | 32 | \item{reverse}{Reverse numbering of windows in the output, i.e. report 33 | windows in decreasing order} 34 | 35 | \item{i}{src|winnum|srcwinnum 36 | The default output is 3 columns: chrom, start, end . 37 | With this option, a name column will be added. 38 | "-i src" - use the source interval's name. 39 | "-i winnum" - use the window number as the ID (e.g. 1,2,3,4...). 40 | "-i srcwinnum" - use the source interval's name with the window number. 41 | See below for usage examples.} 42 | 43 | \item{output}{Output filepath instead of returning output in R.} 44 | } 45 | \description{ 46 | Makes adjacent or sliding windows across a genome or BED file. 47 | } 48 | -------------------------------------------------------------------------------- /man/bt.map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.map.R 3 | \name{bt.map} 4 | \alias{bt.map} 5 | \title{Apply a function to a column from B intervals that overlap A.} 6 | \usage{ 7 | bt.map( 8 | a, 9 | b, 10 | c = NULL, 11 | o = NULL, 12 | delim = NULL, 13 | prec = NULL, 14 | s = NULL, 15 | S = NULL, 16 | f = NULL, 17 | F = NULL, 18 | r = NULL, 19 | e = NULL, 20 | split = NULL, 21 | g = NULL, 22 | nonamecheck = NULL, 23 | bed = NULL, 24 | header = NULL, 25 | nobuf = NULL, 26 | iobuf = NULL, 27 | output = NULL 28 | ) 29 | } 30 | \arguments{ 31 | \item{a}{} 32 | 33 | \item{b}{} 34 | 35 | \item{c}{Specify columns from the B file to map onto intervals in A. 36 | Default: 5. 37 | Multiple columns can be specified in a comma-delimited list.} 38 | 39 | \item{o}{Specify the operation that should be applied to -c. 40 | Valid operations: 41 | sum, min, max, absmin, absmax, 42 | mean, median, mode, antimode 43 | stdev, sstdev 44 | collapse (i.e., print a delimited list (duplicates allowed)), 45 | distinct (i.e., print a delimited list (NO duplicates allowed)), 46 | distinct_sort_num (as distinct, sorted numerically, ascending), 47 | distinct_sort_num_desc (as distinct, sorted numerically, desscending), 48 | distinct_only (delimited list of only unique values), 49 | count 50 | count_distinct (i.e., a count of the unique values in the column), 51 | first (i.e., just the first value in the column), 52 | last (i.e., just the last value in the column), 53 | Default: sum 54 | Multiple operations can be specified in a comma-delimited list. 55 | If there is only column, but multiple operations, all operations will be 56 | applied on that column. Likewise, if there is only one operation, but 57 | multiple columns, that operation will be applied to all columns. 58 | Otherwise, the number of columns must match the the number of operations, 59 | and will be applied in respective order. 60 | E.g., "-c 5,4,6 -o sum,mean,count" will give the sum of column 5, 61 | the mean of column 4, and the count of column 6. 62 | The order of output columns will match the ordering given in the command.} 63 | 64 | \item{delim}{Specify a custom delimiter for the collapse operations. 65 | - Example: -delim "|" 66 | - Default: ",".} 67 | 68 | \item{prec}{Sets the decimal precision for output (Default: 5)} 69 | 70 | \item{s}{Require same strandedness. That is, only report hits in B 71 | that overlap A on the _same_ strand. 72 | - By default, overlaps are reported without respect to strand.} 73 | 74 | \item{S}{Require different strandedness. That is, only report hits in B 75 | that overlap A on the _opposite_ strand. 76 | - By default, overlaps are reported without respect to strand.} 77 | 78 | \item{f}{Minimum overlap required as a fraction of A. 79 | - Default is 1E-9 (i.e., 1bp). 80 | - FLOAT (e.g. 0.50)} 81 | 82 | \item{F}{Minimum overlap required as a fraction of B. 83 | - Default is 1E-9 (i.e., 1bp). 84 | - FLOAT (e.g. 0.50)} 85 | 86 | \item{r}{Require that the fraction overlap be reciprocal for A AND B. 87 | - In other words, if -f is 0.90 and -r is used, this requires 88 | that B overlap 90 percent of A and A _also_ overlaps 90 percent of B.} 89 | 90 | \item{e}{Require that the minimum fraction be satisfied for A OR B. 91 | - In other words, if -e is used with -f 0.90 and -F 0.10 this requires 92 | that either 90 percent of A is covered OR 10 percent of B is covered. 93 | Without -e, both fractions would have to be satisfied.} 94 | 95 | \item{split}{Treat "split" BAM or BED12 entries as distinct BED intervals.} 96 | 97 | \item{g}{Provide a genome file to enforce consistent chromosome sort order 98 | across input files. Only applies when used with -sorted option.} 99 | 100 | \item{nonamecheck}{For sorted data, don't throw an error if the file has different naming conventions 101 | for the same chromosome. ex. "chr1" vs "chr01".} 102 | 103 | \item{bed}{If using BAM input, write output as BED.} 104 | 105 | \item{header}{Print the header from the A file prior to results.} 106 | 107 | \item{nobuf}{Disable buffered output. Using this option will cause each line 108 | of output to be printed as it is generated, rather than saved 109 | in a buffer. This will make printing large output files 110 | noticeably slower, but can be useful in conjunction with 111 | other software tools and scripts that need to process one 112 | line of bedtools output at a time.} 113 | 114 | \item{iobuf}{Specify amount of memory to use for input buffer. 115 | Takes an integer argument. Optional suffixes K/M/G supported. 116 | Note: currently has no effect with compressed files.} 117 | 118 | \item{output}{Output filepath instead of returning output in R.} 119 | } 120 | \description{ 121 | Apply a function to a column from B intervals that overlap A. 122 | } 123 | -------------------------------------------------------------------------------- /man/bt.maskfasta.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.maskfasta.R 3 | \name{bt.maskfasta} 4 | \alias{bt.maskfasta} 5 | \title{Mask a fasta file based on feature coordinates.} 6 | \usage{ 7 | bt.maskfasta( 8 | fi, 9 | fo, 10 | bed, 11 | soft = NULL, 12 | mc = NULL, 13 | fullHeader = NULL, 14 | output = NULL 15 | ) 16 | } 17 | \arguments{ 18 | \item{fi}{} 19 | 20 | \item{fo}{} 21 | 22 | \item{bed}{} 23 | 24 | \item{soft}{Enforce "soft" masking. 25 | Mask with lower-case bases, instead of masking with Ns.} 26 | 27 | \item{mc}{Replace masking character. 28 | Use another character, instead of masking with Ns.} 29 | 30 | \item{fullHeader}{Use full fasta header. 31 | By default, only the word before the first space or tab 32 | is used.} 33 | 34 | \item{output}{Output filepath instead of returning output in R.} 35 | } 36 | \description{ 37 | Mask a fasta file based on feature coordinates. 38 | } 39 | -------------------------------------------------------------------------------- /man/bt.merge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.merge.R 3 | \name{bt.merge} 4 | \alias{bt.merge} 5 | \title{Merges overlapping BED/GFF/VCF entries into a single interval.} 6 | \usage{ 7 | bt.merge( 8 | i, 9 | s = NULL, 10 | S = NULL, 11 | d = NULL, 12 | c = NULL, 13 | o = NULL, 14 | delim = NULL, 15 | prec = NULL, 16 | bed = NULL, 17 | header = NULL, 18 | nobuf = NULL, 19 | iobuf = NULL, 20 | output = NULL 21 | ) 22 | } 23 | \arguments{ 24 | \item{i}{} 25 | 26 | \item{s}{Force strandedness. That is, only merge features 27 | that are on the same strand. 28 | - By default, merging is done without respect to strand.} 29 | 30 | \item{S}{Force merge for one specific strand only. 31 | Follow with + or - to force merge from only 32 | the forward or reverse strand, respectively. 33 | - By default, merging is done without respect to strand.} 34 | 35 | \item{d}{Maximum distance between features allowed for features 36 | to be merged. 37 | - Def. 0. That is, overlapping & book-ended features are merged. 38 | - (INTEGER) 39 | - Note: negative values enforce the number of b.p. required for overlap.} 40 | 41 | \item{c}{Specify columns from the B file to map onto intervals in A. 42 | Default: 5. 43 | Multiple columns can be specified in a comma-delimited list.} 44 | 45 | \item{o}{Specify the operation that should be applied to -c. 46 | Valid operations: 47 | sum, min, max, absmin, absmax, 48 | mean, median, mode, antimode 49 | stdev, sstdev 50 | collapse (i.e., print a delimited list (duplicates allowed)), 51 | distinct (i.e., print a delimited list (NO duplicates allowed)), 52 | distinct_sort_num (as distinct, sorted numerically, ascending), 53 | distinct_sort_num_desc (as distinct, sorted numerically, desscending), 54 | distinct_only (delimited list of only unique values), 55 | count 56 | count_distinct (i.e., a count of the unique values in the column), 57 | first (i.e., just the first value in the column), 58 | last (i.e., just the last value in the column), 59 | Default: sum 60 | Multiple operations can be specified in a comma-delimited list. 61 | If there is only column, but multiple operations, all operations will be 62 | applied on that column. Likewise, if there is only one operation, but 63 | multiple columns, that operation will be applied to all columns. 64 | Otherwise, the number of columns must match the the number of operations, 65 | and will be applied in respective order. 66 | E.g., "-c 5,4,6 -o sum,mean,count" will give the sum of column 5, 67 | the mean of column 4, and the count of column 6. 68 | The order of output columns will match the ordering given in the command.} 69 | 70 | \item{delim}{Specify a custom delimiter for the collapse operations. 71 | - Example: -delim "|" 72 | - Default: ",".} 73 | 74 | \item{prec}{Sets the decimal precision for output (Default: 5)} 75 | 76 | \item{bed}{If using BAM input, write output as BED.} 77 | 78 | \item{header}{Print the header from the A file prior to results.} 79 | 80 | \item{nobuf}{Disable buffered output. Using this option will cause each line 81 | of output to be printed as it is generated, rather than saved 82 | in a buffer. This will make printing large output files 83 | noticeably slower, but can be useful in conjunction with 84 | other software tools and scripts that need to process one 85 | line of bedtools output at a time.} 86 | 87 | \item{iobuf}{Specify amount of memory to use for input buffer. 88 | Takes an integer argument. Optional suffixes K/M/G supported. 89 | Note: currently has no effect with compressed files.} 90 | 91 | \item{output}{Output filepath instead of returning output in R.} 92 | } 93 | \description{ 94 | Merges overlapping BED/GFF/VCF entries into a single interval. 95 | } 96 | -------------------------------------------------------------------------------- /man/bt.multicov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.multicov.R 3 | \name{bt.multicov} 4 | \alias{bt.multicov} 5 | \title{Counts sequence coverage for multiple bams at specific loci.} 6 | \usage{ 7 | bt.multicov( 8 | bams, 9 | bed, 10 | split = NULL, 11 | s = NULL, 12 | S = NULL, 13 | f = NULL, 14 | r = NULL, 15 | q = NULL, 16 | D = NULL, 17 | F = NULL, 18 | p = NULL, 19 | output = NULL 20 | ) 21 | } 22 | \arguments{ 23 | \item{bams}{aln.1.bam aln.2.bam ... aln.n.bam} 24 | 25 | \item{bed}{} 26 | 27 | \item{split}{Treat "split" BAM or BED12 entries as distinct BED intervals.} 28 | 29 | \item{s}{Require same strandedness. That is, only report hits in B 30 | that overlap A on the _same_ strand. 31 | - By default, overlaps are reported without respect to strand.} 32 | 33 | \item{S}{Require different strandedness. That is, only report hits in B 34 | that overlap A on the _opposite_ strand. 35 | - By default, overlaps are reported without respect to strand.} 36 | 37 | \item{f}{Minimum overlap required as a fraction of each -bed record. 38 | - Default is 1E-9 (i.e., 1bp). 39 | - FLOAT (e.g. 0.50)} 40 | 41 | \item{r}{Require that the fraction overlap be reciprocal for each -bed and B. 42 | - In other words, if -f is 0.90 and -r is used, this requires 43 | that B overlap 90 percent of each -bed and the -bed record _also_ overlaps 90 percent of B.} 44 | 45 | \item{q}{Minimum mapping quality allowed. Default is 0.} 46 | 47 | \item{D}{Include duplicate reads. Default counts non-duplicates only} 48 | 49 | \item{F}{Include failed-QC reads. Default counts pass-QC reads only} 50 | 51 | \item{p}{Only count proper pairs. Default counts all alignments with 52 | MAPQ > -q argument, regardless of the BAM FLAG field.} 53 | 54 | \item{output}{Output filepath instead of returning output in R.} 55 | } 56 | \description{ 57 | Counts sequence coverage for multiple bams at specific loci. 58 | } 59 | -------------------------------------------------------------------------------- /man/bt.multiinter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.multiinter.R 3 | \name{bt.multiinter} 4 | \alias{bt.multiinter} 5 | \title{Identifies common intervals among multiple 6 | BED/GFF/VCF files.} 7 | \usage{ 8 | bt.multiinter( 9 | i, 10 | cluster = NULL, 11 | header = NULL, 12 | names = NULL, 13 | g = NULL, 14 | empty = NULL, 15 | filler = NULL, 16 | examples = NULL, 17 | output = NULL 18 | ) 19 | } 20 | \arguments{ 21 | \item{i}{FILE1 FILE2 .. FILEn 22 | Requires that each interval file is sorted by chrom/start.} 23 | 24 | \item{cluster}{Invoke Ryan Layers's clustering algorithm.} 25 | 26 | \item{header}{Print a header line. 27 | (chrom/start/end + names of each file).} 28 | 29 | \item{names}{A list of names (one/file) to describe each file in -i. 30 | These names will be printed in the header line.} 31 | 32 | \item{g}{Use genome file to calculate empty regions. 33 | - STRING.} 34 | 35 | \item{empty}{Report empty regions (i.e., start/end intervals w/o 36 | values in all files). 37 | - Requires the '-g FILE' parameter.} 38 | 39 | \item{filler}{Use TEXT when representing intervals having no value. 40 | - Default is '0', but you can use 'N/A' or any text.} 41 | 42 | \item{examples}{Show detailed usage examples.} 43 | 44 | \item{output}{Output filepath instead of returning output in R.} 45 | } 46 | \description{ 47 | Identifies common intervals among multiple 48 | BED/GFF/VCF files. 49 | } 50 | -------------------------------------------------------------------------------- /man/bt.nuc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.nuc.R 3 | \name{bt.nuc} 4 | \alias{bt.nuc} 5 | \title{Profiles the nucleotide content of intervals in a fasta file.} 6 | \usage{ 7 | bt.nuc( 8 | fi, 9 | bed, 10 | s = NULL, 11 | seq = NULL, 12 | pattern = NULL, 13 | C = NULL, 14 | fullHeader = NULL, 15 | output = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{fi}{} 20 | 21 | \item{bed}{} 22 | 23 | \item{s}{Profile the sequence according to strand.} 24 | 25 | \item{seq}{Print the extracted sequence} 26 | 27 | \item{pattern}{Report the number of times a user-defined sequence 28 | is observed (case-sensitive).} 29 | 30 | \item{C}{Ignore case when matching -pattern. By defaulty, case matters.} 31 | 32 | \item{fullHeader}{Use full fasta header. 33 | - By default, only the word before the first space or tab is used.} 34 | 35 | \item{output}{Output filepath instead of returning output in R.} 36 | } 37 | \description{ 38 | Profiles the nucleotide content of intervals in a fasta file. 39 | } 40 | -------------------------------------------------------------------------------- /man/bt.overlap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.overlap.R 3 | \name{bt.overlap} 4 | \alias{bt.overlap} 5 | \title{Computes the amount of overlap (positive values) 6 | or distance (negative values) between genome features 7 | and reports the result at the end of the same line.} 8 | \usage{ 9 | bt.overlap(i, cols = NULL, output = NULL) 10 | } 11 | \arguments{ 12 | \item{i}{} 13 | 14 | \item{cols}{} 15 | 16 | \item{output}{Output filepath instead of returning output in R.} 17 | } 18 | \description{ 19 | Computes the amount of overlap (positive values) 20 | or distance (negative values) between genome features 21 | and reports the result at the end of the same line. 22 | } 23 | -------------------------------------------------------------------------------- /man/bt.pairtobed.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.pairtobed.R 3 | \name{bt.pairtobed} 4 | \alias{bt.pairtobed} 5 | \title{Report overlaps between a BEDPE file and a BED/GFF/VCF file.} 6 | \usage{ 7 | bt.pairtobed( 8 | a, 9 | b, 10 | abam = NULL, 11 | ubam = NULL, 12 | bedpe = NULL, 13 | ed = NULL, 14 | f = NULL, 15 | s = NULL, 16 | S = NULL, 17 | type = NULL, 18 | output = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{a}{} 23 | 24 | \item{b}{} 25 | 26 | \item{abam}{The A input file is in BAM format. Output will be BAM as well. Replaces -a. 27 | - Requires BAM to be grouped or sorted by query.} 28 | 29 | \item{ubam}{Write uncompressed BAM output. Default writes compressed BAM. 30 | is to write output in BAM when using -abam.} 31 | 32 | \item{bedpe}{When using BAM input (-abam), write output as BEDPE. The default 33 | is to write output in BAM when using -abam.} 34 | 35 | \item{ed}{Use BAM total edit distance (NM tag) for BEDPE score. 36 | - Default for BEDPE is to use the minimum of 37 | of the two mapping qualities for the pair. 38 | - When -ed is used the total edit distance 39 | from the two mates is reported as the score.} 40 | 41 | \item{f}{Minimum overlap required as fraction of A (e.g. 0.05). 42 | Default is 1E-9 (effectively 1bp).} 43 | 44 | \item{s}{Require same strandedness when finding overlaps. 45 | Default is to ignore stand. 46 | Not applicable with -type inspan or -type outspan.} 47 | 48 | \item{S}{Require different strandedness when finding overlaps. 49 | Default is to ignore stand. 50 | Not applicable with -type inspan or -type outspan.} 51 | 52 | \item{type}{Approach to reporting overlaps between BEDPE and BED. 53 | either Report overlaps if either end of A overlaps B. 54 | - Default. 55 | neither Report A if neither end of A overlaps B. 56 | both Report overlaps if both ends of A overlap B. 57 | xor Report overlaps if one and only one end of A overlaps B. 58 | notboth Report overlaps if neither end or one and only one 59 | end of A overlap B. That is, xor + neither. 60 | ispan Report overlaps between [end1, start2] of A and B. 61 | - Note: If chrom1 <> chrom2, entry is ignored. 62 | ospan Report overlaps between [start1, end2] of A and B. 63 | - Note: If chrom1 <> chrom2, entry is ignored. 64 | notispan Report A if ispan of A doesn't overlap B. 65 | - Note: If chrom1 <> chrom2, entry is ignored. 66 | notospan Report A if ospan of A doesn't overlap B. 67 | - Note: If chrom1 <> chrom2, entry is ignored.} 68 | 69 | \item{output}{Output filepath instead of returning output in R.} 70 | } 71 | \description{ 72 | Report overlaps between a BEDPE file and a BED/GFF/VCF file. 73 | } 74 | -------------------------------------------------------------------------------- /man/bt.pairtopair.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.pairtopair.R 3 | \name{bt.pairtopair} 4 | \alias{bt.pairtopair} 5 | \title{Report overlaps between two paired-end BED files (BEDPE).} 6 | \usage{ 7 | bt.pairtopair( 8 | a, 9 | b, 10 | f = NULL, 11 | type = NULL, 12 | slop = NULL, 13 | ss = NULL, 14 | is = NULL, 15 | rdn = NULL, 16 | output = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{a}{} 21 | 22 | \item{b}{} 23 | 24 | \item{f}{Minimum overlap required as fraction of A (e.g. 0.05). 25 | Default is 1E-9 (effectively 1bp).} 26 | 27 | \item{type}{Approach to reporting overlaps between A and B. 28 | neither Report overlaps if neither end of A overlaps B. 29 | either Report overlaps if either ends of A overlap B. 30 | both Report overlaps if both ends of A overlap B. 31 | notboth Report overlaps if one or neither of A's overlap B. 32 | - Default = both.} 33 | 34 | \item{slop}{The amount of slop (in b.p.). to be added to each footprint of A. 35 | *Note*: Slop is subtracted from start1 and start2 36 | and added to end1 and end2. 37 | - Default = 0.} 38 | 39 | \item{ss}{Add slop based to each BEDPE footprint based on strand. 40 | - If strand is "+", slop is only added to the end coordinates. 41 | - If strand is "-", slop is only added to the start coordinates. 42 | - By default, slop is added in both directions.} 43 | 44 | \item{is}{Ignore strands when searching for overlaps. 45 | - By default, strands are enforced.} 46 | 47 | \item{rdn}{Require the hits to have different names (i.e. avoid self-hits). 48 | - By default, same names are allowed.} 49 | 50 | \item{output}{Output filepath instead of returning output in R.} 51 | } 52 | \description{ 53 | Report overlaps between two paired-end BED files (BEDPE). 54 | } 55 | -------------------------------------------------------------------------------- /man/bt.random.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.random.R 3 | \name{bt.random} 4 | \alias{bt.random} 5 | \title{Generate random intervals among a genome.} 6 | \usage{ 7 | bt.random(g, l = NULL, n = NULL, seed = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{g}{} 11 | 12 | \item{l}{The length of the intervals to generate. 13 | - Default = 100. 14 | - (INTEGER)} 15 | 16 | \item{n}{The number of intervals to generate. 17 | - Default = 1,000,000. 18 | - (INTEGER)} 19 | 20 | \item{seed}{Supply an integer seed for the shuffling. 21 | - By default, the seed is chosen automatically. 22 | - (INTEGER)} 23 | 24 | \item{output}{Output filepath instead of returning output in R.} 25 | } 26 | \description{ 27 | Generate random intervals among a genome. 28 | } 29 | -------------------------------------------------------------------------------- /man/bt.reldist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.reldist.R 3 | \name{bt.reldist} 4 | \alias{bt.reldist} 5 | \title{Calculate the relative distance distribution b/w two feature files.} 6 | \usage{ 7 | bt.reldist(a, b, detail = NULL, output = NULL) 8 | } 9 | \arguments{ 10 | \item{a}{} 11 | 12 | \item{b}{} 13 | 14 | \item{detail}{Report the relativedistance for each interval in A} 15 | 16 | \item{output}{Output filepath instead of returning output in R.} 17 | } 18 | \description{ 19 | Calculate the relative distance distribution b/w two feature files. 20 | } 21 | -------------------------------------------------------------------------------- /man/bt.sample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.sample.R 3 | \name{bt.sample} 4 | \alias{bt.sample} 5 | \title{Take sample of input file(s) using reservoir sampling algorithm.} 6 | \usage{ 7 | bt.sample( 8 | i, 9 | n = NULL, 10 | seed = NULL, 11 | ubam = NULL, 12 | s = NULL, 13 | header = NULL, 14 | bed = NULL, 15 | nobuf = NULL, 16 | iobuf = NULL, 17 | output = NULL 18 | ) 19 | } 20 | \arguments{ 21 | \item{i}{} 22 | 23 | \item{n}{The number of records to generate. 24 | - Default = 1,000,000. 25 | - (INTEGER)} 26 | 27 | \item{seed}{Supply an integer seed for the shuffling. 28 | - By default, the seed is chosen automatically. 29 | - (INTEGER)} 30 | 31 | \item{ubam}{Write uncompressed BAM output. Default writes compressed BAM.} 32 | 33 | \item{s}{Require same strandedness. That is, only give records 34 | that have the same strand. Use '-s forward' or '-s reverse' 35 | for forward or reverse strand records, respectively. 36 | - By default, records are reported without respect to strand.} 37 | 38 | \item{header}{Print the header from the A file prior to results.} 39 | 40 | \item{bed}{If using BAM input, write output as BED.} 41 | 42 | \item{nobuf}{Disable buffered output. Using this option will cause each line 43 | of output to be printed as it is generated, rather than saved 44 | in a buffer. This will make printing large output files 45 | noticeably slower, but can be useful in conjunction with 46 | other software tools and scripts that need to process one 47 | line of bedtools output at a time.} 48 | 49 | \item{iobuf}{Specify amount of memory to use for input buffer. 50 | Takes an integer argument. Optional suffixes K/M/G supported. 51 | Note: currently has no effect with compressed files.} 52 | 53 | \item{output}{Output filepath instead of returning output in R.} 54 | } 55 | \description{ 56 | Take sample of input file(s) using reservoir sampling algorithm. 57 | } 58 | -------------------------------------------------------------------------------- /man/bt.shift.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.shift.R 3 | \name{bt.shift} 4 | \alias{bt.shift} 5 | \title{Shift each feature by requested number of base pairs.} 6 | \usage{ 7 | bt.shift( 8 | i, 9 | g, 10 | s = NULL, 11 | p = NULL, 12 | m = NULL, 13 | pct = NULL, 14 | header = NULL, 15 | output = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{i}{} 20 | 21 | \item{g}{} 22 | 23 | \item{s}{Shift the BED/GFF/VCF entry -s base pairs. 24 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 25 | 26 | \item{p}{Shift features on the + strand by -p base pairs. 27 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 28 | 29 | \item{m}{Shift features on the - strand by -m base pairs. 30 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 31 | 32 | \item{pct}{Define -s, -m and -p as a fraction of the feature's length. 33 | E.g. if used on a 1000bp feature, -s 0.50, 34 | will shift the feature 500 bp "upstream". Default = false.} 35 | 36 | \item{header}{Print the header from the input file prior to results.} 37 | 38 | \item{output}{Output filepath instead of returning output in R.} 39 | } 40 | \description{ 41 | Shift each feature by requested number of base pairs. 42 | } 43 | -------------------------------------------------------------------------------- /man/bt.shuffle.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.shuffle.R 3 | \name{bt.shuffle} 4 | \alias{bt.shuffle} 5 | \title{Randomly permute the locations of a feature file among a genome.} 6 | \usage{ 7 | bt.shuffle( 8 | i, 9 | g, 10 | excl = NULL, 11 | incl = NULL, 12 | chrom = NULL, 13 | seed = NULL, 14 | f = NULL, 15 | chromFirst = NULL, 16 | bedpe = NULL, 17 | maxTries = NULL, 18 | noOverlapping = NULL, 19 | allowBeyondChromEnd = NULL, 20 | output = NULL 21 | ) 22 | } 23 | \arguments{ 24 | \item{i}{} 25 | 26 | \item{g}{} 27 | 28 | \item{excl}{A BED/GFF/VCF file of coordinates in which features in -i 29 | should not be placed (e.g. gaps.bed).} 30 | 31 | \item{incl}{Instead of randomly placing features in a genome, the -incl 32 | options defines a BED/GFF/VCF file of coordinates in which 33 | features in -i should be randomly placed (e.g. genes.bed). 34 | Larger -incl intervals will contain more shuffled regions. 35 | This method DISABLES -chromFirst.} 36 | 37 | \item{chrom}{Keep features in -i on the same chromosome. 38 | - By default, the chrom and position are randomly chosen. 39 | - NOTE: Forces use of -chromFirst (see below).} 40 | 41 | \item{seed}{Supply an integer seed for the shuffling. 42 | - By default, the seed is chosen automatically. 43 | - (INTEGER)} 44 | 45 | \item{f}{Maximum overlap (as a fraction of the -i feature) with an -excl 46 | feature that is tolerated before searching for a new, 47 | randomized locus. For example, -f 0.10 allows up to 10 percent 48 | of a randomized feature to overlap with a given feature 49 | in the -excl file. **Cannot be used with -incl file.** 50 | - Default is 1E-9 (i.e., 1bp). 51 | - FLOAT (e.g. 0.50)} 52 | 53 | \item{chromFirst}{Instead of choosing a position randomly among the entire 54 | genome (the default), first choose a chrom randomly, and then 55 | choose a random start coordinate on that chrom. This leads 56 | to features being ~uniformly distributed among the chroms, 57 | as opposed to features being distribute as a function of chrom size.} 58 | 59 | \item{bedpe}{Indicate that the A file is in BEDPE format.} 60 | 61 | \item{maxTries}{Max. number of attempts to find a home for a shuffled interval 62 | in the presence of -incl or -excl. 63 | Default = 1000.} 64 | 65 | \item{noOverlapping}{Don't allow shuffled intervals to overlap.} 66 | 67 | \item{allowBeyondChromEnd}{Allow shuffled intervals to be relocated to a position 68 | in which the entire original interval cannot fit w/o exceeding 69 | the end of the chromosome. In this case, the end coordinate of the 70 | shuffled interval will be set to the chromosome's length. 71 | By default, an interval's original length must be fully-contained 72 | within the chromosome.} 73 | 74 | \item{output}{Output filepath instead of returning output in R.} 75 | } 76 | \description{ 77 | Randomly permute the locations of a feature file among a genome. 78 | } 79 | -------------------------------------------------------------------------------- /man/bt.slop.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.slop.R 3 | \name{bt.slop} 4 | \alias{bt.slop} 5 | \title{Add requested base pairs of "slop" to each feature.} 6 | \usage{ 7 | bt.slop( 8 | i, 9 | g, 10 | b = NULL, 11 | l = NULL, 12 | r = NULL, 13 | s = NULL, 14 | pct = NULL, 15 | header = NULL, 16 | output = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{i}{} 21 | 22 | \item{g}{} 23 | 24 | \item{b}{Increase the BED/GFF/VCF entry -b base pairs in each direction. 25 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 26 | 27 | \item{l}{The number of base pairs to subtract from the start coordinate. 28 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 29 | 30 | \item{r}{The number of base pairs to add to the end coordinate. 31 | - (Integer) or (Float, e.g. 0.1) if used with -pct.} 32 | 33 | \item{s}{Define -l and -r based on strand. 34 | E.g. if used, -l 500 for a negative-stranded feature, 35 | it will add 500 bp downstream. Default = false.} 36 | 37 | \item{pct}{Define -l and -r as a fraction of the feature's length. 38 | E.g. if used on a 1000bp feature, -l 0.50, 39 | will add 500 bp "upstream". Default = false.} 40 | 41 | \item{header}{Print the header from the input file prior to results.} 42 | 43 | \item{output}{Output filepath instead of returning output in R.} 44 | } 45 | \description{ 46 | Add requested base pairs of "slop" to each feature. 47 | } 48 | -------------------------------------------------------------------------------- /man/bt.sort.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.sort.R 3 | \name{bt.sort} 4 | \alias{bt.sort} 5 | \title{Sorts a feature file in various and useful ways.} 6 | \usage{ 7 | bt.sort( 8 | i, 9 | sizeA = NULL, 10 | sizeD = NULL, 11 | chrThenSizeA = NULL, 12 | chrThenSizeD = NULL, 13 | chrThenScoreA = NULL, 14 | chrThenScoreD = NULL, 15 | g = NULL, 16 | faidx = NULL, 17 | header = NULL, 18 | output = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{i}{} 23 | 24 | \item{sizeA}{Sort by feature size in ascending order.} 25 | 26 | \item{sizeD}{Sort by feature size in descending order.} 27 | 28 | \item{chrThenSizeA}{Sort by chrom (asc), then feature size (asc).} 29 | 30 | \item{chrThenSizeD}{Sort by chrom (asc), then feature size (desc).} 31 | 32 | \item{chrThenScoreA}{Sort by chrom (asc), then score (asc).} 33 | 34 | \item{chrThenScoreD}{Sort by chrom (asc), then score (desc).} 35 | 36 | \item{g}{Sort according to the chromosomes declared in "genome.txt"} 37 | 38 | \item{faidx}{Sort according to the chromosomes declared in "names.txt"} 39 | 40 | \item{header}{Print the header from the A file prior to results.} 41 | 42 | \item{output}{Output filepath instead of returning output in R.} 43 | } 44 | \description{ 45 | Sorts a feature file in various and useful ways. 46 | } 47 | -------------------------------------------------------------------------------- /man/bt.spacing.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.spacing.R 3 | \name{bt.spacing} 4 | \alias{bt.spacing} 5 | \title{Report (last col.) the gap lengths between intervals in a file.} 6 | \usage{ 7 | bt.spacing(i, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{output}{Output filepath instead of returning output in R.} 13 | } 14 | \description{ 15 | Report (last col.) the gap lengths between intervals in a file. 16 | } 17 | -------------------------------------------------------------------------------- /man/bt.split.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.split.R 3 | \name{bt.split} 4 | \alias{bt.split} 5 | \title{Split a Bed file.} 6 | \usage{ 7 | bt.split(i, n = NULL, p = NULL, a = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{n}{number-of-files} 13 | 14 | \item{p}{Output BED file prefix.} 15 | 16 | \item{a}{Algorithm used to split data. 17 | * size (default): uses a heuristic algorithm to group the items 18 | so all files contain the ~ same number of bases 19 | * simple : route records such that each split file has 20 | approximately equal records (like Unix split).} 21 | } 22 | \description{ 23 | Split a Bed file. 24 | } 25 | -------------------------------------------------------------------------------- /man/bt.subtract.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.subtract.R 3 | \name{bt.subtract} 4 | \alias{bt.subtract} 5 | \title{Removes the portion(s) of an interval that is overlapped 6 | by another feature(s).} 7 | \usage{ 8 | bt.subtract( 9 | a, 10 | b, 11 | A = NULL, 12 | N = NULL, 13 | wb = NULL, 14 | wo = NULL, 15 | s = NULL, 16 | S = NULL, 17 | f = NULL, 18 | F = NULL, 19 | r = NULL, 20 | e = NULL, 21 | split = NULL, 22 | g = NULL, 23 | nonamecheck = NULL, 24 | sorted = NULL, 25 | bed = NULL, 26 | header = NULL, 27 | nobuf = NULL, 28 | iobuf = NULL, 29 | output = NULL 30 | ) 31 | } 32 | \arguments{ 33 | \item{a}{} 34 | 35 | \item{b}{} 36 | 37 | \item{A}{Remove entire feature if any overlap. That is, by default, 38 | only subtract the portion of A that overlaps B. Here, if 39 | any overlap is found (or -f amount), the entire feature is removed.} 40 | 41 | \item{N}{Same as -A except when used with -f, the amount is the sum 42 | of all features (not any single feature).} 43 | 44 | \item{wb}{Write the original entry in B for each overlap. 45 | - Useful for knowing _what_ A overlaps. Restricted by -f and -r.} 46 | 47 | \item{wo}{Write the original A and B entries plus the number of base 48 | pairs of overlap between the two features. 49 | - Overlaps restricted by -f and -r. 50 | Only A features with overlap are reported.} 51 | 52 | \item{s}{Require same strandedness. That is, only report hits in B 53 | that overlap A on the _same_ strand. 54 | - By default, overlaps are reported without respect to strand.} 55 | 56 | \item{S}{Require different strandedness. That is, only report hits in B 57 | that overlap A on the _opposite_ strand. 58 | - By default, overlaps are reported without respect to strand.} 59 | 60 | \item{f}{Minimum overlap required as a fraction of A. 61 | - Default is 1E-9 (i.e., 1bp). 62 | - FLOAT (e.g. 0.50)} 63 | 64 | \item{F}{Minimum overlap required as a fraction of B. 65 | - Default is 1E-9 (i.e., 1bp). 66 | - FLOAT (e.g. 0.50)} 67 | 68 | \item{r}{Require that the fraction overlap be reciprocal for A AND B. 69 | - In other words, if -f is 0.90 and -r is used, this requires 70 | that B overlap 90 percent of A and A _also_ overlaps 90 percent of B.} 71 | 72 | \item{e}{Require that the minimum fraction be satisfied for A OR B. 73 | - In other words, if -e is used with -f 0.90 and -F 0.10 this requires 74 | that either 90 percent of A is covered OR 10 percent of B is covered. 75 | Without -e, both fractions would have to be satisfied.} 76 | 77 | \item{split}{Treat "split" BAM or BED12 entries as distinct BED intervals.} 78 | 79 | \item{g}{Provide a genome file to enforce consistent chromosome sort order 80 | across input files. Only applies when used with -sorted option.} 81 | 82 | \item{nonamecheck}{For sorted data, don't throw an error if the file has different naming conventions 83 | for the same chromosome. ex. "chr1" vs "chr01".} 84 | 85 | \item{sorted}{Use the "chromsweep" algorithm for sorted (-k1,1 -k2,2n) input.} 86 | 87 | \item{bed}{If using BAM input, write output as BED.} 88 | 89 | \item{header}{Print the header from the A file prior to results.} 90 | 91 | \item{nobuf}{Disable buffered output. Using this option will cause each line 92 | of output to be printed as it is generated, rather than saved 93 | in a buffer. This will make printing large output files 94 | noticeably slower, but can be useful in conjunction with 95 | other software tools and scripts that need to process one 96 | line of bedtools output at a time.} 97 | 98 | \item{iobuf}{Specify amount of memory to use for input buffer. 99 | Takes an integer argument. Optional suffixes K/M/G supported. 100 | Note: currently has no effect with compressed files.} 101 | 102 | \item{output}{Output filepath instead of returning output in R.} 103 | } 104 | \description{ 105 | Removes the portion(s) of an interval that is overlapped 106 | by another feature(s). 107 | } 108 | -------------------------------------------------------------------------------- /man/bt.summary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.summary.R 3 | \name{bt.summary} 4 | \alias{bt.summary} 5 | \title{Report summary statistics of the intervals in a file} 6 | \usage{ 7 | bt.summary(i, g, output = NULL) 8 | } 9 | \arguments{ 10 | \item{i}{} 11 | 12 | \item{g}{} 13 | 14 | \item{output}{Output filepath instead of returning output in R.} 15 | } 16 | \description{ 17 | Report summary statistics of the intervals in a file 18 | } 19 | -------------------------------------------------------------------------------- /man/bt.tag.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.tag.R 3 | \name{bt.tag} 4 | \alias{bt.tag} 5 | \title{Annotates a BAM file based on overlaps with multiple BED/GFF/VCF files 6 | on the intervals in -i.} 7 | \usage{ 8 | bt.tag( 9 | i, 10 | files, 11 | s = NULL, 12 | S = NULL, 13 | f = NULL, 14 | tag = NULL, 15 | names = NULL, 16 | scores = NULL, 17 | intervals = NULL, 18 | labels = NULL, 19 | output = NULL 20 | ) 21 | } 22 | \arguments{ 23 | \item{i}{} 24 | 25 | \item{files}{FILE1 .. FILEn} 26 | 27 | \item{s}{Require overlaps on the same strand. That is, only tag alignments that have the same 28 | strand as a feature in the annotation file(s).} 29 | 30 | \item{S}{Require overlaps on the opposite strand. That is, only tag alignments that have the opposite 31 | strand as a feature in the annotation file(s).} 32 | 33 | \item{f}{Minimum overlap required as a fraction of the alignment. 34 | - Default is 1E-9 (i.e., 1bp). 35 | - FLOAT (e.g. 0.50)} 36 | 37 | \item{tag}{Dictate what the tag should be. Default is YB. 38 | - STRING (two characters, e.g., YK)} 39 | 40 | \item{names}{Use the name field from the annotation files to populate tags. 41 | By default, the -labels values are used.} 42 | 43 | \item{scores}{Use the score field from the annotation files to populate tags. 44 | By default, the -labels values are used.} 45 | 46 | \item{intervals}{Use the full interval (including name, score, and strand) to populate tags. 47 | Requires the -labels option to identify from which file the interval came.} 48 | 49 | \item{labels}{LAB1 .. LABn} 50 | 51 | \item{output}{Output filepath instead of returning output in R.} 52 | } 53 | \description{ 54 | Annotates a BAM file based on overlaps with multiple BED/GFF/VCF files 55 | on the intervals in -i. 56 | } 57 | -------------------------------------------------------------------------------- /man/bt.unionbedg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.unionbedg.R 3 | \name{bt.unionbedg} 4 | \alias{bt.unionbedg} 5 | \title{Combines multiple BedGraph files into a single file, 6 | allowing coverage comparisons between them.} 7 | \usage{ 8 | bt.unionbedg( 9 | i, 10 | header = NULL, 11 | names = NULL, 12 | g = NULL, 13 | empty = NULL, 14 | filler = NULL, 15 | examples = NULL, 16 | output = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{i}{FILE1 FILE2 .. FILEn 21 | Assumes that each BedGraph file is sorted by chrom/start 22 | and that the intervals in each are non-overlapping.} 23 | 24 | \item{header}{Print a header line. 25 | (chrom/start/end + names of each file).} 26 | 27 | \item{names}{A list of names (one/file) to describe each file in -i. 28 | These names will be printed in the header line.} 29 | 30 | \item{g}{Use genome file to calculate empty regions. 31 | - STRING.} 32 | 33 | \item{empty}{Report empty regions (i.e., start/end intervals w/o 34 | values in all files). 35 | - Requires the '-g FILE' parameter.} 36 | 37 | \item{filler}{Use TEXT when representing intervals having no value. 38 | - Default is '0', but you can use 'N/A' or any text.} 39 | 40 | \item{examples}{Show detailed usage examples.} 41 | 42 | \item{output}{Output filepath instead of returning output in R.} 43 | } 44 | \description{ 45 | Combines multiple BedGraph files into a single file, 46 | allowing coverage comparisons between them. 47 | } 48 | -------------------------------------------------------------------------------- /man/bt.window.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bt.window.R 3 | \name{bt.window} 4 | \alias{bt.window} 5 | \title{Examines a "window" around each feature in A and 6 | reports all features in B that overlap the window. For each 7 | overlap the entire entry in A and B are reported.} 8 | \usage{ 9 | bt.window( 10 | a, 11 | b, 12 | abam = NULL, 13 | ubam = NULL, 14 | bed = NULL, 15 | w = NULL, 16 | l = NULL, 17 | r = NULL, 18 | sw = NULL, 19 | sm = NULL, 20 | Sm = NULL, 21 | u = NULL, 22 | c = NULL, 23 | v = NULL, 24 | header = NULL, 25 | output = NULL 26 | ) 27 | } 28 | \arguments{ 29 | \item{a}{} 30 | 31 | \item{b}{} 32 | 33 | \item{abam}{The A input file is in BAM format. Output will be BAM as well. Replaces -a.} 34 | 35 | \item{ubam}{Write uncompressed BAM output. Default writes compressed BAM.} 36 | 37 | \item{bed}{When using BAM input (-abam), write output as BED. The default 38 | is to write output in BAM when using -abam.} 39 | 40 | \item{w}{Base pairs added upstream and downstream of each entry 41 | in A when searching for overlaps in B. 42 | - Creates symmetrical "windows" around A. 43 | - Default is 1000 bp. 44 | - (INTEGER)} 45 | 46 | \item{l}{Base pairs added upstream (left of) of each entry 47 | in A when searching for overlaps in B. 48 | - Allows one to define asymmetrical "windows". 49 | - Default is 1000 bp. 50 | - (INTEGER)} 51 | 52 | \item{r}{Base pairs added downstream (right of) of each entry 53 | in A when searching for overlaps in B. 54 | - Allows one to define asymmetrical "windows". 55 | - Default is 1000 bp. 56 | - (INTEGER)} 57 | 58 | \item{sw}{Define -l and -r based on strand. For example if used, -l 500 59 | for a negative-stranded feature will add 500 bp downstream. 60 | - Default = disabled.} 61 | 62 | \item{sm}{Only report hits in B that overlap A on the _same_ strand. 63 | - By default, overlaps are reported without respect to strand.} 64 | 65 | \item{Sm}{Only report hits in B that overlap A on the _opposite_ strand. 66 | - By default, overlaps are reported without respect to strand.} 67 | 68 | \item{u}{Write the original A entry _once_ if _any_ overlaps found in B. 69 | - In other words, just report the fact >=1 hit was found.} 70 | 71 | \item{c}{For each entry in A, report the number of overlaps with B. 72 | - Reports 0 for A entries that have no overlap with B. 73 | - Overlaps restricted by -w, -l, and -r.} 74 | 75 | \item{v}{Only report those entries in A that have _no overlaps_ with B. 76 | - Similar to "grep -v."} 77 | 78 | \item{header}{Print the header from the A file prior to results.} 79 | 80 | \item{output}{Output filepath instead of returning output in R.} 81 | } 82 | \description{ 83 | Examines a "window" around each feature in A and 84 | reports all features in B that overlap the window. For each 85 | overlap the entire entry in A and B are reported. 86 | } 87 | -------------------------------------------------------------------------------- /man/createOptions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/createOptions.R 3 | \name{createOptions} 4 | \alias{createOptions} 5 | \title{Creates options based on user input} 6 | \usage{ 7 | createOptions(names, values) 8 | } 9 | \arguments{ 10 | \item{names}{vector of names of options} 11 | 12 | \item{values}{vector of values of options 13 | 14 | ### Define a function that determines establishes files and paths for bedtools functions} 15 | } 16 | \description{ 17 | Creates options based on user input 18 | } 19 | -------------------------------------------------------------------------------- /man/deleteTempFiles.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deleteTempFiles.R 3 | \name{deleteTempFiles} 4 | \alias{deleteTempFiles} 5 | \title{Deletes temp files} 6 | \usage{ 7 | deleteTempFiles(tempfiles) 8 | } 9 | \arguments{ 10 | \item{tempfiles}{a vector of tempfiles for deletion 11 | 12 | ### Define a function that determines establishes files and paths for bedtools functions} 13 | } 14 | \description{ 15 | Deletes temp files 16 | } 17 | -------------------------------------------------------------------------------- /man/establishPaths.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/establishPaths.R 3 | \name{establishPaths} 4 | \alias{establishPaths} 5 | \title{Determines if arguments are paths or R objects. Makes temp files when 6 | neccesary. Makes a list of files to use in bedtools call. Makes a list 7 | of temp files to delete at end of function.} 8 | \usage{ 9 | establishPaths(input, name = "", allowRobjects = TRUE) 10 | } 11 | \arguments{ 12 | \item{input}{the input for an argument. Could be a path to a file, an R object (data frame), or a list of any combination thereof} 13 | 14 | \item{name}{the name of the argument} 15 | 16 | \item{allowRobjects}{boolean whether or not to allow R objects as inputs 17 | 18 | ### Define a function that determines establishes files and paths for bedtools functions} 19 | } 20 | \description{ 21 | Determines if arguments are paths or R objects. Makes temp files when 22 | neccesary. Makes a list of files to use in bedtools call. Makes a list 23 | of temp files to delete at end of function. 24 | } 25 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(bedtoolsr) 3 | 4 | test_check("bedtoolsr") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.annotate.R: -------------------------------------------------------------------------------- 1 | context("test-annotate") 2 | 3 | test_that("annotate works", { 4 | variants.bed <- read.table(text= 5 | "chr1 100 200 nasty 1 - 6 | chr2 500 1000 ugly 2 + 7 | chr3 1000 5000 big 3 -") 8 | genes.bed <- read.table(text= 9 | "chr1 150 200 geneA 1 + 10 | chr1 175 250 geneB 2 + 11 | chr3 0 10000 geneC 3 -") 12 | conserve.bed <- read.table(text= 13 | "chr1 0 10000 cons1 1 + 14 | chr2 700 10000 cons2 2 - 15 | chr3 4000 10000 cons3 3 +") 16 | known_var.bed <- read.table(text= 17 | "chr1 0 120 known1 - 18 | chr1 150 160 known2 - 19 | chr2 0 10000 known3 +") 20 | results <- read.table(text= 21 | "chr1 100 200 nasty 1 - 0.500000 1.000000 0.300000 22 | chr2 500 1000 ugly 2 + 0.000000 0.600000 1.000000 23 | chr3 1000 5000 big 3 - 1.000000 0.250000 0.000000") 24 | expect_equal(bedtoolsr::bt.annotate(variants.bed, list(genes.bed, conserve.bed, known_var.bed)), results) 25 | }) 26 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.closest.R: -------------------------------------------------------------------------------- 1 | context("test-closest") 2 | 3 | test_that("closest works", { 4 | A.bed <- read.table(text= 5 | "chr1 10 20 a1 1 -") 6 | B.bed <- read.table(text= 7 | "chr1 7 8 b1 1 - 8 | chr1 15 25 b2 2 +") 9 | results <- read.table(text= 10 | "chr1 10 20 a1 1 - chr1 15 25 b2 2 +") 11 | expect_equal(bedtoolsr::bt.closest(A.bed, B.bed), results) 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.cluster.R: -------------------------------------------------------------------------------- 1 | context("test-cluster") 2 | 3 | test_that("cluster works", { 4 | A.bed <- read.table(text= 5 | "chr1 100 200 6 | chr1 180 250 7 | chr1 250 500 8 | chr1 501 1000") 9 | results <- read.table(text= 10 | "chr1 100 200 1 11 | chr1 180 250 1 12 | chr1 250 500 1 13 | chr1 501 1000 2") 14 | expect_equal(bedtoolsr::bt.cluster(A.bed), results) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.complement.R: -------------------------------------------------------------------------------- 1 | context("test-complement") 2 | 3 | test_that("complement works", { 4 | A.bed <- read.table(text= 5 | "chr1 100 200 6 | chr1 400 500 7 | chr1 500 800") 8 | my.genome <- read.table(text= 9 | "chr1 1000 10 | chr2 800") 11 | results <- read.table(text= 12 | "chr1 0 100 13 | chr1 200 400 14 | chr1 800 1000 15 | chr2 0 800") 16 | expect_equal(bedtoolsr::bt.complement(A.bed, my.genome), results) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.coverage.R: -------------------------------------------------------------------------------- 1 | context("test-coverage") 2 | 3 | test_that("coverage works", { 4 | A.bed <- read.table(text= 5 | "chr1 0 100 6 | chr1 100 200 7 | chr2 0 100") 8 | B.bed <- read.table(text= 9 | "chr1 10 20 10 | chr1 20 30 11 | chr1 30 40 12 | chr1 100 200") 13 | results <- read.table(text= 14 | "chr1 0 100 3 30 100 0.3000000 15 | chr1 100 200 1 100 100 1.0000000 16 | chr2 0 100 0 0 100 0.0000000") 17 | expect_equal(bedtoolsr::bt.coverage(A.bed, B.bed), results) 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.expand.R: -------------------------------------------------------------------------------- 1 | context("test-expand") 2 | 3 | test_that("expand works", { 4 | test.bed <- read.table(text= 5 | "chr1 10 20 1,2,3 10,20,30 6 | chr1 40 50 4,5,6 40,50,60") 7 | results <- read.table(text= 8 | "chr1 10 20 1,2,3 10 9 | chr1 10 20 1,2,3 20 10 | chr1 10 20 1,2,3 30 11 | chr1 40 50 4,5,6 40 12 | chr1 40 50 4,5,6 50 13 | chr1 40 50 4,5,6 60") 14 | expect_equal(bedtoolsr::bt.expand(test.bed, c=5), results) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.fisher.R: -------------------------------------------------------------------------------- 1 | context("test-fisher") 2 | 3 | test_that("fisher works", { 4 | a.bed <- read.table(text= 5 | "chr1 10 20 6 | chr1 30 40 7 | chr1 51 52") 8 | b.bed <- read.table(text= 9 | "chr1 15 25 10 | chr1 51 52") 11 | write("chr1\t500", "t.genome") 12 | results <- read.table(header=TRUE, text= 13 | "left right two-tail ratio 14 | 1 0.0053476 0.0053476 inf") 15 | expect_equal(bedtoolsr::bt.fisher(a.bed, b.bed, "t.genome"), results) 16 | file.remove("t.genome") 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.flank.R: -------------------------------------------------------------------------------- 1 | context("test-flank") 2 | 3 | test_that("flank works", { 4 | A.bed <- read.table(text= 5 | "chr1 100 200 6 | chr1 500 600") 7 | my.genome <- read.table(text= 8 | "chr1 1000") 9 | results <- read.table(text= 10 | "chr1 95 100 11 | chr1 200 205 12 | chr1 495 500 13 | chr1 600 605") 14 | expect_equal(bedtoolsr::bt.flank(A.bed, my.genome, b=5), results) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.genomecov.R: -------------------------------------------------------------------------------- 1 | context("test-genomecov") 2 | 3 | test_that("genomecov works", { 4 | A.bed <- read.table(text= 5 | "chr1 10 20 6 | chr1 20 30 7 | chr2 0 500") 8 | my.genome <- read.table(text= 9 | "chr1 1000 10 | chr2 500") 11 | results <- read.table(text= 12 | "chr1 0 980 1000 0.98 13 | chr1 1 20 1000 0.02 14 | chr2 1 500 500 1 15 | genome 0 980 1500 0.653333 16 | genome 1 520 1500 0.346667") 17 | expect_equal(bedtoolsr::bt.genomecov(A.bed, my.genome), results) 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.groupby.R: -------------------------------------------------------------------------------- 1 | context("test-groupby") 2 | 3 | test_that("groupby works", { 4 | variantsToRepeats.bed <- read.table(text= 5 | "chr21 9719758 9729320 variant1 chr21 9719768 9721892 ALR/Alpha 1004 + 6 | chr21 9719758 9729320 variant1 chr21 9721905 9725582 ALR/Alpha 1010 + 7 | chr21 9719758 9729320 variant1 chr21 9725582 9725977 L1PA3 3288 + 8 | chr21 9719758 9729320 variant1 chr21 9726021 9729309 ALR/Alpha 1051 + 9 | chr21 9729310 9757478 variant2 chr21 9729320 9729809 L1PA3 3897 - 10 | chr21 9729310 9757478 variant2 chr21 9729809 9730866 L1P1 8367 + 11 | chr21 9729310 9757478 variant2 chr21 9730866 9734026 ALR/Alpha 1036 - 12 | chr21 9729310 9757478 variant2 chr21 9734037 9757471 ALR/Alpha 1182 - 13 | chr21 9795588 9796685 variant3 chr21 9795589 9795713 (GAATG)n 308 + 14 | chr21 9795588 9796685 variant3 chr21 9795736 9795894 (GAATG)n 683 + 15 | chr21 9795588 9796685 variant3 chr21 9795911 9796007 (GAATG)n 345 + 16 | chr21 9795588 9796685 variant3 chr21 9796028 9796187 (GAATG)n 756 + 17 | chr21 9795588 9796685 variant3 chr21 9796202 9796615 (GAATG)n 891 + 18 | chr21 9795588 9796685 variant3 chr21 9796637 9796824 (GAATG)n 621 +") 19 | results <- read.table(text= 20 | "chr21 9719758 9729320 6353 21 | chr21 9729310 9757478 14482 22 | chr21 9795588 9796685 3604") 23 | expect_equal(bedtoolsr::bt.groupby(variantsToRepeats.bed, g="1,2,3", c=9), results) 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.intersect.R: -------------------------------------------------------------------------------- 1 | context("test-intersect") 2 | 3 | test_that("intersect works", { 4 | A.bed <- read.table(text= 5 | "chr1 10 20 6 | chr1 30 40") 7 | B.bed <- read.table(text= 8 | "chr1 15 20") 9 | results <- read.table(text= 10 | "chr1 15 20") 11 | expect_equal(bedtoolsr::bt.intersect(A.bed, B.bed), results) 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.jaccard.R: -------------------------------------------------------------------------------- 1 | context("test-jaccard") 2 | 3 | test_that("jaccard works", { 4 | A.bed <- read.table(text= 5 | "chr1 10 20 6 | chr1 30 40") 7 | B.bed <- read.table(text= 8 | "chr1 15 20") 9 | results <- read.table(header=TRUE, text= 10 | "intersection union jaccard n_intersections 11 | 5 20 0.25 1") 12 | expect_equal(bedtoolsr::bt.jaccard(A.bed, B.bed), results) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.makewindows.R: -------------------------------------------------------------------------------- 1 | context("test-makewindows") 2 | 3 | test_that("makewindows works", { 4 | input.bed <- read.table(text= 5 | "chr5 60000 70000") 6 | results <- read.table(text= 7 | "chr5 60000 61000 8 | chr5 61000 62000 9 | chr5 62000 63000 10 | chr5 63000 64000 11 | chr5 64000 65000 12 | chr5 65000 66000 13 | chr5 66000 67000 14 | chr5 67000 68000 15 | chr5 68000 69000 16 | chr5 69000 70000") 17 | expect_equal(bedtoolsr::bt.makewindows(b=input.bed, n=10), results) 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.map.R: -------------------------------------------------------------------------------- 1 | context("test-map") 2 | 3 | test_that("map works", { 4 | a.bed <- read.table(text= 5 | "chr1 10 20 a1 1 + 6 | chr1 50 60 a2 2 - 7 | chr1 80 90 a3 3 -") 8 | b.bed <- read.table(text= 9 | "chr1 12 14 b1 2 + 10 | chr1 13 15 b2 5 - 11 | chr1 16 18 b3 5 + 12 | chr1 82 85 b4 2 - 13 | chr1 85 87 b5 3 +") 14 | results <- read.table(text= 15 | "chr1 10 20 a1 1 + 12 16 | chr1 50 60 a2 2 - . 17 | chr1 80 90 a3 3 - 5") 18 | expect_equal(bedtoolsr::bt.map(a.bed, b.bed), results) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.merge.R: -------------------------------------------------------------------------------- 1 | context("test-merge") 2 | 3 | test_that("merge works", { 4 | A.bed <- read.table(text= 5 | "chr1 100 200 6 | chr1 180 250 7 | chr1 250 500 8 | chr1 501 1000") 9 | results <- read.table(text= 10 | "chr1 100 500 11 | chr1 501 1000") 12 | expect_equal(bedtoolsr::bt.merge(A.bed), results) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.overlap.R: -------------------------------------------------------------------------------- 1 | context("test-overlap") 2 | 3 | test_that("overlap works", { 4 | input <- read.table(text= 5 | "chr1 10 20 A chr1 15 25 B 6 | chr1 10 20 C chr1 25 35 D") 7 | results <- read.table(text= 8 | "chr1 10 20 A chr1 15 25 B 5 9 | chr1 10 20 C chr1 25 35 D -5") 10 | expect_equal(bedtoolsr::bt.overlap(input, cols="2,3,6,7"), results) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.shift.R: -------------------------------------------------------------------------------- 1 | context("test-shift") 2 | 3 | test_that("shift works", { 4 | A.bed <- read.table(text= 5 | "chr1 5 100 + 6 | chr1 800 980 -") 7 | my.genome <- read.table(text= 8 | "chr1 1000") 9 | results <- read.table(text= 10 | "chr1 10 105 + 11 | chr1 805 985 -") 12 | expect_equal(bedtoolsr::bt.shift(A.bed, my.genome, s=5), results) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.shuffle.R: -------------------------------------------------------------------------------- 1 | context("test-shuffle") 2 | 3 | test_that("shuffle works", { 4 | A.bed <- read.table(text= 5 | "chr1 0 100 a1 1 + 6 | chr1 0 1000 a2 2 -") 7 | my.genome <- read.table(text= 8 | "chr1 10000 9 | chr2 8000 10 | chr3 5000 11 | chr4 2000") 12 | results <- read.table(text= 13 | "chr1 5518 5618 a1 1 + 14 | chr2 1091 2091 a2 2 -") 15 | expect_equal(bedtoolsr::bt.shuffle(A.bed, my.genome, seed=100), results) 16 | }) 17 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.slop.R: -------------------------------------------------------------------------------- 1 | context("test-slop") 2 | 3 | test_that("slop works", { 4 | A.bed <- read.table(text= 5 | "chr1 5 100 6 | chr1 800 980") 7 | my.genome <- read.table(text= 8 | "chr1 1000") 9 | results <- read.table(text= 10 | "chr1 0 105 11 | chr1 795 985") 12 | expect_equal(bedtoolsr::bt.slop(A.bed, my.genome, b=5), results) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.sort.R: -------------------------------------------------------------------------------- 1 | context("test-sort") 2 | 3 | test_that("sort works", { 4 | A.bed <- read.table(text= 5 | "chr1 800 1000 6 | chr1 80 180 7 | chr1 1 10 8 | chr1 750 10000") 9 | results <- read.table(text= 10 | "chr1 750 10000 11 | chr1 800 1000 12 | chr1 80 180 13 | chr1 1 10") 14 | expect_equal(bedtoolsr::bt.sort(A.bed, sizeD=TRUE), results) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.spacing.R: -------------------------------------------------------------------------------- 1 | context("test-spacing") 2 | 3 | test_that("spacing works", { 4 | test.bed <- read.table(text= 5 | "chr1 0 10 6 | chr1 10 20 7 | chr1 19 30 8 | chr1 35 45 9 | chr1 100 200") 10 | results <- read.table(text= 11 | "chr1 0 10 . 12 | chr1 10 20 0 13 | chr1 19 30 -1 14 | chr1 35 45 5 15 | chr1 100 200 55") 16 | expect_equal(bedtoolsr::bt.spacing(test.bed), results) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.subtract.R: -------------------------------------------------------------------------------- 1 | context("test-subtract") 2 | 3 | test_that("subtract works", { 4 | A.bed <- read.table(text= 5 | "chr1 10 20 6 | chr1 100 200") 7 | B.bed <- read.table(text= 8 | "chr1 0 30 9 | chr1 180 300") 10 | results <- read.table(text= 11 | "chr1 100 180") 12 | expect_equal(bedtoolsr::bt.subtract(A.bed, B.bed), results) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.unionbedg.R: -------------------------------------------------------------------------------- 1 | context("test-unionbedg") 2 | 3 | test_that("unionbedg works", { 4 | one.bg <- read.table(text= 5 | "chr1 1000 1500 10 6 | chr1 2000 2100 20") 7 | two.bg <- read.table(text= 8 | "chr1 900 1600 60 9 | chr1 1700 2050 50") 10 | three.bg <- read.table(text= 11 | "chr1 1980 2070 80 12 | chr1 2090 2100 20") 13 | results <- read.table(text= 14 | "chr1 900 1000 0 60 0 15 | chr1 1000 1500 10 60 0 16 | chr1 1500 1600 0 60 0 17 | chr1 1700 1980 0 50 0 18 | chr1 1980 2000 0 50 80 19 | chr1 2000 2050 20 50 80 20 | chr1 2050 2070 20 0 80 21 | chr1 2070 2090 20 0 0 22 | chr1 2090 2100 20 0 20") 23 | expect_equal(bedtoolsr::bt.unionbedg(list(one.bg, two.bg, three.bg)), results) 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-bt.window.R: -------------------------------------------------------------------------------- 1 | context("test-window") 2 | 3 | test_that("window works", { 4 | A.bed <- read.table(text= 5 | "chr1 100 200") 6 | B.bed <- read.table(text= 7 | "chr1 500 1000 8 | chr1 1300 2000") 9 | results <- read.table(text= 10 | "chr1 100 200 chr1 500 1000") 11 | expect_equal(bedtoolsr::bt.window(A.bed, B.bed), results) 12 | }) 13 | --------------------------------------------------------------------------------