├── .Rbuildignore ├── .github ├── .gitignore ├── sync.sh └── workflows │ ├── R-CMD-check.yaml │ ├── file-sync.yml │ ├── pr-commands.yaml │ └── render-rmarkdown.yaml ├── .gitignore ├── DESCRIPTION ├── LICENSE.md ├── LICENSE.note ├── NAMESPACE ├── NEWS.md ├── R ├── app-.R ├── appmamba.R ├── argument.R ├── blit-package.R ├── cmd-.R ├── cmd-alleleCounter.R ├── cmd-cellranger.R ├── cmd-conda.R ├── cmd-exec.R ├── cmd-fastp.R ├── cmd-fastq_pair.R ├── cmd-gistic2.R ├── cmd-kraken2-tools.R ├── cmd-kraken2.R ├── cmd-parallel.R ├── cmd-perl.R ├── cmd-pyscenic.R ├── cmd-python.R ├── cmd-run.R ├── cmd-samtools.R ├── cmd-schedule.R ├── cmd-seqkit.R ├── cmd-setup.R ├── cmd-trust4.R ├── import-standalone-assert.R ├── import-standalone-obj-type.R ├── import-standalone-pkg.R ├── import-standalone-stringr.R ├── processx.R ├── utils-Rd.R ├── utils-file.R └── utils.R ├── README.Rmd ├── README.md ├── blit.Rproj ├── codecov.yml ├── cran-comments.md ├── data-raw ├── DATASET.R └── christmas.png ├── inst └── extdata │ ├── KrakenTools │ ├── combine_kreports.py │ ├── combine_mpa.py │ ├── extract_kraken_reads.py │ ├── filter_bracken_out.py │ ├── fix_unmapped.py │ ├── kreport2krona.py │ ├── kreport2mpa.py │ ├── make_kreport.py │ └── make_ktaxonomy.py │ ├── TRUST4 │ ├── BuildDatabaseFa.pl │ └── BuildImgtAnnot.pl │ └── kraken2 │ └── kreport2mpa.py ├── man ├── Command.Rd ├── allele_counter.Rd ├── appmamba.Rd ├── arg.Rd ├── blit-package.Rd ├── cellranger.Rd ├── cmd_conda.Rd ├── cmd_on_start.Rd ├── cmd_parallel.Rd ├── cmd_run.Rd ├── cmd_wd.Rd ├── conda.Rd ├── exec.Rd ├── fastp.Rd ├── fastq_pair.Rd ├── figures │ └── logo.png ├── gistic2.Rd ├── kraken2.Rd ├── kraken_tools.Rd ├── make_command.Rd ├── perl.Rd ├── pyscenic.Rd ├── python.Rd ├── roxygen │ └── meta.R ├── samtools.Rd ├── seqkit.Rd └── trust4.Rd ├── revdep ├── .gitignore ├── README.md ├── cran.md ├── failures.md └── problems.md └── tests ├── testthat.R └── testthat ├── test-exec.R ├── test-processx.R └── test-utils.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^blit\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.radian_history$ 4 | ^Scratch\.RConsole$ 5 | ^LICENSE\.md$ 6 | ^\.github$ 7 | ^cran-comments\.md$ 8 | ^CRAN-SUBMISSION$ 9 | ^README\.Rmd$ 10 | README.html 11 | ^data-raw$ 12 | ^codecov\.yml$ 13 | ^revdep$ 14 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/sync.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | tmp=$(mktemp -d) 3 | 4 | repo=$1 # source repo 5 | 6 | if [[ "$2" =~ ^@ ]]; then 7 | branch=$2 # repo branch 8 | from=$3 # used files 9 | to=$4 10 | else 11 | from=$2 12 | to=$3 13 | fi 14 | 15 | echo "$branch" 16 | 17 | if [ ! $to ]; then 18 | to=$from 19 | fi 20 | 21 | if [[ $branch == '@gist' ]]; then 22 | curl -o "$tmp/$from" "https://gist.githubusercontent.com/$repo/raw/$from" 23 | else 24 | if [ ! $branch ]; then 25 | git clone --depth 1 https://github.com/$repo $tmp 26 | else 27 | git clone --depth 1 --branch ${branch:1} https://github.com/$repo $tmp 28 | fi 29 | fi 30 | 31 | if [[ $to == */ ]]; then 32 | mkdir -p $to 33 | else 34 | mkdir -p $(dirname $to) 35 | fi 36 | 37 | cp $tmp/$from $to 38 | 39 | rm -rf $tmp 40 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/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 | workflow_dispatch: 9 | 10 | name: R-CMD-check 11 | 12 | permissions: read-all 13 | 14 | jobs: 15 | R-CMD-check: 16 | runs-on: ${{ matrix.config.os }} 17 | 18 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | config: 24 | - {os: macos-latest, r: 'release'} 25 | - {os: windows-latest, r: 'release'} 26 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 27 | - {os: ubuntu-latest, r: 'release'} 28 | - {os: ubuntu-latest, r: 'oldrel-1'} 29 | 30 | env: 31 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 32 | R_KEEP_PKG_SOURCE: yes 33 | 34 | steps: 35 | - uses: actions/checkout@v4 36 | 37 | - uses: r-lib/actions/setup-pandoc@v2 38 | 39 | - uses: r-lib/actions/setup-r@v2 40 | with: 41 | r-version: ${{ matrix.config.r }} 42 | http-user-agent: ${{ matrix.config.http-user-agent }} 43 | use-public-rspm: true 44 | 45 | - uses: r-lib/actions/setup-r-dependencies@v2 46 | with: 47 | extra-packages: any::rcmdcheck 48 | needs: check 49 | 50 | - uses: r-lib/actions/check-r-package@v2 51 | with: 52 | upload-snapshots: true 53 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' 54 | -------------------------------------------------------------------------------- /.github/workflows/file-sync.yml: -------------------------------------------------------------------------------- 1 | name: update scripts with file-sync 2 | on: 3 | workflow_dispatch: 4 | schedule: 5 | # At 03:03 on Tuesday 6 | - cron: '3 3 * * 2' 7 | 8 | jobs: 9 | sync: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | 14 | - run: ./.github/sync.sh liulab-dfci/TRUST4 BuildImgtAnnot.pl inst/extdata/TRUST4/ 15 | 16 | - uses: stefanzweifel/git-auto-commit-action@v5 17 | with: 18 | commit_message: "update TRUST4: BuildImgtAnnot.pl" 19 | 20 | - run: ./.github/sync.sh liulab-dfci/TRUST4 BuildDatabaseFa.pl inst/extdata/TRUST4/ 21 | 22 | - uses: stefanzweifel/git-auto-commit-action@v5 23 | with: 24 | commit_message: "update TRUST4: BuildDatabaseFa.pl" 25 | 26 | - run: ./.github/sync.sh sjdlabgroup/SAHMI functions/kreport2mpa.py inst/extdata/kraken2/ 27 | 28 | - uses: stefanzweifel/git-auto-commit-action@v5 29 | with: 30 | commit_message: "update kraken2: kreport2mpa.py" 31 | 32 | - run: ./.github/sync.sh jenniferlu717/KrakenTools combine_kreports.py inst/extdata/KrakenTools/ 33 | 34 | - uses: stefanzweifel/git-auto-commit-action@v5 35 | with: 36 | commit_message: "update KrakenTools: combine_kreports.py" 37 | 38 | - run: ./.github/sync.sh jenniferlu717/KrakenTools combine_mpa.py inst/extdata/KrakenTools/ 39 | 40 | - uses: stefanzweifel/git-auto-commit-action@v5 41 | with: 42 | commit_message: "update KrakenTools: combine_mpa.py" 43 | 44 | - run: ./.github/sync.sh jenniferlu717/KrakenTools extract_kraken_reads.py inst/extdata/KrakenTools/ 45 | 46 | - uses: stefanzweifel/git-auto-commit-action@v5 47 | with: 48 | commit_message: "update KrakenTools: extract_kraken_reads.py" 49 | 50 | - run: ./.github/sync.sh jenniferlu717/KrakenTools filter_bracken.out.py inst/extdata/KrakenTools/filter_bracken_out.py 51 | 52 | - uses: stefanzweifel/git-auto-commit-action@v5 53 | with: 54 | commit_message: "update KrakenTools: filter_bracken.out.py" 55 | 56 | - run: ./.github/sync.sh jenniferlu717/KrakenTools fix_unmapped.py inst/extdata/KrakenTools/ 57 | 58 | - uses: stefanzweifel/git-auto-commit-action@v5 59 | with: 60 | commit_message: "update KrakenTools: fix_unmapped.py" 61 | 62 | - run: ./.github/sync.sh jenniferlu717/KrakenTools kreport2krona.py inst/extdata/KrakenTools/ 63 | 64 | - uses: stefanzweifel/git-auto-commit-action@v5 65 | with: 66 | commit_message: "update KrakenTools: kreport2krona.py" 67 | 68 | - run: ./.github/sync.sh jenniferlu717/KrakenTools kreport2mpa.py inst/extdata/KrakenTools/ 69 | 70 | - uses: stefanzweifel/git-auto-commit-action@v5 71 | with: 72 | commit_message: "update KrakenTools: kreport2mpa.py" 73 | 74 | - run: ./.github/sync.sh jenniferlu717/KrakenTools make_kreport.py inst/extdata/KrakenTools/ 75 | 76 | - uses: stefanzweifel/git-auto-commit-action@v5 77 | with: 78 | commit_message: "update KrakenTools: make_kreport.py" 79 | 80 | - run: ./.github/sync.sh jenniferlu717/KrakenTools make_ktaxonomy.py inst/extdata/KrakenTools/ 81 | 82 | - uses: stefanzweifel/git-auto-commit-action@v5 83 | with: 84 | commit_message: "update KrakenTools: make_ktaxonomy.py" 85 | -------------------------------------------------------------------------------- /.github/workflows/pr-commands.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | issue_comment: 5 | types: [created] 6 | 7 | name: Commands 8 | 9 | permissions: read-all 10 | 11 | jobs: 12 | document: 13 | if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }} 14 | name: document 15 | runs-on: ubuntu-latest 16 | env: 17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - uses: r-lib/actions/pr-fetch@v2 22 | with: 23 | repo-token: ${{ secrets.GITHUB_TOKEN }} 24 | 25 | - uses: r-lib/actions/setup-r@v2 26 | with: 27 | use-public-rspm: true 28 | 29 | - uses: r-lib/actions/setup-r-dependencies@v2 30 | with: 31 | extra-packages: any::roxygen2 32 | needs: pr-document 33 | 34 | - name: Document 35 | run: roxygen2::roxygenise() 36 | shell: Rscript {0} 37 | 38 | - name: commit 39 | run: | 40 | git config --local user.name "$GITHUB_ACTOR" 41 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 42 | git add man/\* NAMESPACE 43 | git commit -m 'Document' 44 | 45 | - uses: r-lib/actions/pr-push@v2 46 | with: 47 | repo-token: ${{ secrets.GITHUB_TOKEN }} 48 | 49 | style: 50 | if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }} 51 | name: style 52 | runs-on: ubuntu-latest 53 | env: 54 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 55 | steps: 56 | - uses: actions/checkout@v4 57 | 58 | - uses: r-lib/actions/pr-fetch@v2 59 | with: 60 | repo-token: ${{ secrets.GITHUB_TOKEN }} 61 | 62 | - uses: r-lib/actions/setup-r@v2 63 | 64 | - name: Install dependencies 65 | run: install.packages("styler") 66 | shell: Rscript {0} 67 | 68 | - name: Style 69 | run: styler::style_pkg() 70 | shell: Rscript {0} 71 | 72 | - name: commit 73 | run: | 74 | git config --local user.name "$GITHUB_ACTOR" 75 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 76 | git add \*.R 77 | git commit -m 'Style' 78 | 79 | - uses: r-lib/actions/pr-push@v2 80 | with: 81 | repo-token: ${{ secrets.GITHUB_TOKEN }} 82 | -------------------------------------------------------------------------------- /.github/workflows/render-rmarkdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | release: 5 | types: [published] 6 | workflow_dispatch: 7 | 8 | name: render-rmarkdown.yaml 9 | 10 | jobs: 11 | render-rmarkdown: 12 | runs-on: ubuntu-latest 13 | env: 14 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 15 | permissions: 16 | contents: write 17 | steps: 18 | - name: Checkout repo 19 | uses: actions/checkout@v4 20 | with: 21 | fetch-depth: 0 22 | ssh-key: ${{ secrets.DEPLOY_KEY }} 23 | 24 | - uses: r-lib/actions/setup-pandoc@v2 25 | 26 | - uses: r-lib/actions/setup-r@v2 27 | with: 28 | use-public-rspm: true 29 | 30 | - uses: r-lib/actions/setup-r-dependencies@v2 31 | with: 32 | extra-packages: | 33 | any::rmarkdown 34 | local::. 35 | 36 | - name: Render Rmarkdown files 37 | run: | 38 | Rscript -e 'rmarkdown::render("README.Rmd")' 39 | 40 | - name: Commit to Github 41 | if: github.event_name != 'pull_request' 42 | run: | 43 | git config --local user.name "$GITHUB_ACTOR" 44 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 45 | git commit README.md -m 'Re-build README.Rmd' || echo "No changes to commit" 46 | git push origin || echo "No changes to commit" 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .radian_history 3 | Scratch.RConsole 4 | 5 | /.quarto/ 6 | README.html -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: blit 2 | Title: Bioinformatics Library for Integrated Tools 3 | Version: 0.2.0.9000 4 | Authors@R: c( 5 | person("Yun", "Peng", , "yunyunp96@163.com", role = c("aut", "cre"), 6 | comment = c(ORCID = "0000-0003-2801-3332")), 7 | person("Shixiang", "Wang", , "w_shixiang@163.com", role = c("aut"), 8 | comment = c(ORCID = "0000-0001-9855-7357")), 9 | person("Jia", "Ding", , "jiading682@qq.com", role = c("ctb"), 10 | comment = c(ORCID = "0009-0002-2530-0897")), 11 | person("Jennifer", "Lu", , "jennifer.lu717@gmail.com", 12 | role = c("cph"), comment = "Author of the included scripts from Kraken2 and KrakenTools libraries"), 13 | person("Li", "Song", , "Li.Song@dartmouth.edu", 14 | role = c("cph"), comment = "Author of included scripts from TRUST4 library"), 15 | person("X. Shirley", "Liu", , "xsliu@ds.dfci.harvard.edu", 16 | role = c("cph"), comment = "Author of included scripts from TRUST4 library") 17 | ) 18 | Description: An all-encompassing R toolkit designed to streamline the 19 | process of calling various bioinformatics software and then performing data 20 | analysis and visualization in R. With 'blit', users can easily integrate a 21 | wide array of bioinformatics command line tools into their workflows, 22 | leveraging the power of R for sophisticated data manipulation and graphical 23 | representation. 24 | License: GPL (>= 3) 25 | Imports: 26 | cli, 27 | lifecycle, 28 | processx, 29 | R6 (>= 2.4.0), 30 | rlang (>= 1.1.0), 31 | utils 32 | Suggests: 33 | testthat (>= 3.0.0) 34 | Config/testthat/edition: 3 35 | Encoding: UTF-8 36 | Roxygen: list(markdown = TRUE) 37 | RoxygenNote: 7.3.2 38 | URL: https://github.com/WangLabCSU/blit 39 | BugReports: https://github.com/WangLabCSU/blit/issues 40 | -------------------------------------------------------------------------------- /LICENSE.note: -------------------------------------------------------------------------------- 1 | The blit package as a whole is distributed under GPL 3.0. The blit package includes other open source software components. The following is a list of these components: 2 | 3 | * kraken2/kreport2mpa.py: GPL 3.0 4 | * kraken2Tools: GPL 3.0 5 | * TRUST4: MIT 6 | 7 | Full copies of the license agreements used by these components are included in `inst/extdata`. 8 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,command) 4 | export(Command) 5 | export(allele_counter) 6 | export(appmamba) 7 | export(appmamba_rc) 8 | export(arg) 9 | export(arg0) 10 | export(cellranger) 11 | export(cmd_background) 12 | export(cmd_conda) 13 | export(cmd_condaenv) 14 | export(cmd_envpath) 15 | export(cmd_envvar) 16 | export(cmd_help) 17 | export(cmd_on_exit) 18 | export(cmd_on_fail) 19 | export(cmd_on_start) 20 | export(cmd_on_succeed) 21 | export(cmd_parallel) 22 | export(cmd_run) 23 | export(cmd_wd) 24 | export(conda) 25 | export(exec) 26 | export(fastp) 27 | export(fastq_pair) 28 | export(fastq_read_pair) 29 | export(gistic2) 30 | export(install_appmamba) 31 | export(kraken2) 32 | export(kraken_tools) 33 | export(make_command) 34 | export(perl) 35 | export(pyscenic) 36 | export(python) 37 | export(samtools) 38 | export(seqkit) 39 | export(trust4) 40 | export(trust4_gene_names) 41 | export(trust4_imgt_annot) 42 | export(uninstall_appmamba) 43 | importFrom(R6,R6Class) 44 | importFrom(rlang,":=") 45 | importFrom(rlang,.data) 46 | importFrom(rlang,.env) 47 | importFrom(rlang,abort) 48 | importFrom(rlang,caller_arg) 49 | importFrom(rlang,caller_call) 50 | importFrom(rlang,caller_env) 51 | importFrom(rlang,ffi_standalone_check_number_1.0.7) 52 | importFrom(rlang,ffi_standalone_is_bool_1.0.7) 53 | importFrom(rlang,is_missing) 54 | importFrom(rlang,is_string) 55 | importFrom(rlang,is_vector) 56 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # blit (development version) 2 | 3 | * Rename `cmd_conda` to `cmd_codnaenv()`. 4 | 5 | # blit 0.2.0 6 | 7 | ## New features 8 | 9 | * new function `cmd_conda` to define the `PATH` environment variables with conda environment. 10 | 11 | * new function `appmamba` to install software and manage Environment with `micromamba`. 12 | 13 | * new function `cmd_on_fail` to define the expression to be evaluated when the command failed. 14 | 15 | * new function `cmd_on_succeed`to define the expression to be evaluated when the command succeeded. 16 | 17 | * new function `cmd_on_start()` to define the expressions which will be run when command started 18 | 19 | * new function `cmd_on_exit()` to define the expressions which will be run when command finished 20 | 21 | * new command `samtools` 22 | 23 | * new function `cmd_parallel()` to run multiple commands meanwhile 24 | 25 | * use `processx` package to execute the command and remove the `sys` and `withr` package from dependencies 26 | 27 | # blit 0.1.0 28 | 29 | * Initial CRAN submission. 30 | -------------------------------------------------------------------------------- /R/app-.R: -------------------------------------------------------------------------------- 1 | app_dir <- function(app = NULL, create = FALSE, dir = data_dir()) { 2 | path <- dir_create(file.path(dir, "apps")) 3 | if (is.null(app)) { 4 | path 5 | } else { 6 | path <- file.path(path, app) 7 | if (create) dir_create(path) else path 8 | } 9 | } 10 | 11 | bin_dir <- function(dir = data_dir()) dir_create(file.path(dir, "bin")) 12 | -------------------------------------------------------------------------------- /R/appmamba.R: -------------------------------------------------------------------------------- 1 | #' Manage Environment with `micromamba` 2 | #' 3 | #' @describeIn appmamba `blit` utilizes `micromamba` to manage environments. 4 | #' This function simply executes the specified `micromamba` command. 5 | #' 6 | #' @param ... <[dynamic dots][rlang::dyn-dots]> Additional arguments passed to 7 | #' `micromamba`. Run `appmamba()` for more details. 8 | #' @examples 9 | #' \donttest{ 10 | #' install_appmamba() 11 | #' appmamba() 12 | #' appmamba("env", "list") 13 | #' # uninstall_appmamba() # Uninstall the `micromamba` 14 | #' } 15 | #' @export 16 | appmamba <- function(...) { 17 | path <- app_dir("appmamba") 18 | if (!dir.exists(path)) { 19 | if (interactive()) { 20 | cli::cli_inform("Would you like to install {.pkg appmamba}?") 21 | if (utils::menu(c("Yes", "No")) == 1L) { 22 | install_appmamba() 23 | } 24 | } else { 25 | cli::cli_abort(c( 26 | "{.pkg appmamba} is not installed", 27 | i = "Please install it with {.fn install_appmamba}" 28 | )) 29 | } 30 | } 31 | command <- if (is_windows()) { 32 | file.path(path, "Library", "bin", "micromamba.exe") 33 | } else { 34 | file.path(path, "bin", "micromamba") 35 | } 36 | if (!file.exists(command)) { 37 | cli::cli_abort(c( 38 | "Invalid installation of {.pkg appmamba}", 39 | i = paste( 40 | "Please reinstall {.pkg appmamba} with", 41 | "{.code install_appmamba(force = TRUE)}" 42 | ) 43 | )) 44 | } 45 | command <- normalizePath(command, winslash = "/", mustWork = FALSE) 46 | args <- rlang::dots_list(..., .ignore_empty = "all") 47 | args <- as.character(unlist(args, FALSE, FALSE)) 48 | if (length(args) == 0L) args <- "--help" 49 | root <- dir_create(appmamba_root()) 50 | args <- c( 51 | "--root-prefix", 52 | normalizePath(root, winslash = "/", mustWork = FALSE), 53 | args 54 | ) 55 | command <- exec(command, args) 56 | proc <- processx_command( 57 | command, 58 | help = FALSE, 59 | stdout = TRUE, 60 | stderr = TRUE, 61 | stdin = TRUE, 62 | verbose = FALSE, 63 | echo_command = TRUE 64 | ) 65 | proc$.blit_run(spinner = FALSE) 66 | invisible(proc$get_exit_status()) 67 | } 68 | 69 | #' @describeIn appmamba Install appmamba (`micromamba`). 70 | #' 71 | #' @param force A logical value indicating whether to reinstall `appmamba` 72 | #' if it is already installed. 73 | #' @export 74 | install_appmamba <- function(force = FALSE) { 75 | path <- app_dir("appmamba") 76 | if (dir.exists(path)) { 77 | if (isTRUE(force)) { 78 | cli::cli_inform("Removing previous installed {.pkg appmamba}") 79 | status <- unlink(path, recursive = TRUE, force = TRUE) 80 | if (status != 0L) { 81 | cli::cli_abort( 82 | "Cannot uninstall {.pkg appmamba} [status = {status}]" 83 | ) 84 | } 85 | } else { 86 | cli::cli_inform("{.pkg appmamba} is already installed") 87 | return(invisible()) 88 | } 89 | } 90 | cli::cli_inform("Installing {.pkg appmamba}") 91 | dir_create(path, recursive = TRUE) 92 | installer <- appmamba_installer_download(appmamba_installer_url()) 93 | status <- utils::untar(installer, exdir = path) 94 | if (status != 0L) { 95 | cli::cli_abort( 96 | "Cannot decompress {.path {installer}} [status = {status}]" 97 | ) 98 | } 99 | cli::cli_inform("Install {.pkg appmamba} successfully!") 100 | invisible() 101 | } 102 | 103 | #' @describeIn appmamba Remove appmamba (`micromamba`). 104 | #' @export 105 | uninstall_appmamba <- function() { 106 | path <- app_dir("appmamba") 107 | if (dir.exists(path)) { 108 | status <- unlink(path, recursive = TRUE, force = TRUE) 109 | if (status != 0L) { 110 | cli::cli_abort( 111 | "Cannot uninstall {.pkg appmamba} [status = {status}]" 112 | ) 113 | } 114 | cli::cli_inform("{.pkg appmamba} is uninstalled") 115 | } else { 116 | cli::cli_inform("{.pkg appmamba} is not installed") 117 | } 118 | invisible() 119 | } 120 | 121 | #' @describeIn appmamba Get the `run commands` config file of the `micromamba`. 122 | #' @param edit A logical value indicating whether to open the config file for 123 | #' editing. 124 | #' @export 125 | appmamba_rc <- function(edit = FALSE) { 126 | if (!appmamba_installed()) { 127 | cli::cli_abort(c( 128 | "{.pkg appmamba} is not installed", 129 | i = "Please install it with {.fn install_appmamba}" 130 | )) 131 | } 132 | root <- appmamba_root() 133 | rc_file <- file.path(root, ".mambarc") 134 | if (isTRUE(edit)) { 135 | if (!file.exists(rc_file)) { 136 | dir_create(root) 137 | write_lines(c( 138 | "# For more information about this file see:", 139 | "# https://conda.io/docs/user-guide/configuration/use-condarc.html" 140 | ), rc_file) 141 | } 142 | utils::file.edit(rc_file, title = "appmamba", fileEncoding = "UTF-8") 143 | return(invisible(rc_file)) 144 | } 145 | rc_file 146 | } 147 | 148 | appmamba_installed <- function() dir.exists(app_dir("appmamba")) 149 | 150 | appmamba_root <- function() file.path(data_dir(), "appmamba") 151 | 152 | appmamba_use_system <- function() { 153 | system <- Sys.getenv("BLIT_APPMAMBA_SYSTEM", NA_character_) 154 | !is.na(system) && ( 155 | identical(system, "1") || 156 | identical(system, "TRUE") || 157 | identical(system, "True") || 158 | identical(system, "true") 159 | ) 160 | } 161 | 162 | appmamba_installer_download <- function(url) { 163 | # reuse an already-existing installer 164 | installer <- file.path(cache_dir(), "appmamba") 165 | download_file(url, 166 | installer, 167 | method = "libcurl", 168 | mode = if (is_windows()) "wb" else "w" 169 | ) 170 | } 171 | 172 | appmamba_installer_url <- function() { 173 | url <- getOption("blit.appmamba.url") 174 | if (!is.null(url)) { 175 | return(url) 176 | } 177 | base <- "https://micro.mamba.pm/api/micromamba" 178 | if (is_windows()) { 179 | name <- "win-64" 180 | } else { 181 | info <- Sys.info() 182 | if (is_linux()) { 183 | if (info["machine"] == "ppc64le") { 184 | name <- "linux-ppc64le" 185 | } else if (info["machine"] == "arm64") { 186 | name <- "linux-aarch64" 187 | } else { 188 | name <- "linux-64" 189 | } 190 | } else if (is_osx()) { 191 | if (info["machine"] == "x86_64") { 192 | name <- "osx-64" 193 | } else { 194 | name <- "osx-arm64" 195 | } 196 | } else { 197 | cli::cli_abort("unsupported platform {.field {info[\"sysname\"]}}") 198 | } 199 | } 200 | file.path(base, name, "latest") 201 | } 202 | -------------------------------------------------------------------------------- /R/argument.R: -------------------------------------------------------------------------------- 1 | #' Deliver arguments of command 2 | #' 3 | #' `arg()` is intended for user use, while `arg0()` is for developers and does 4 | #' not perform argument validation. 5 | #' 6 | #' @param tag A string specifying argument tag, like "-i", "-o". 7 | #' @param value Value passed to the argument. 8 | #' @param indicator A logical value specifying whether value should be an 9 | #' indicator of tag. If `TRUE`, logical value will explain the set or unset of 10 | #' tag. 11 | #' @param lgl2int A logical value indicates whether transfrom value `TRUE` to 12 | #' `1` or `FALSE` to `0`. If `TRUE`, format will always be set to `"%d"`. 13 | #' @param format The format of the value, details see [`sprintf`]. 14 | #' @param sep A character string used to separate `"tag"` and `"value"`, usually 15 | #' `" "` or `"="`. 16 | #' @return A string. 17 | #' @export 18 | arg <- function(tag, value, indicator = FALSE, 19 | lgl2int = FALSE, format = "%s", sep = " ") { 20 | assert_string(tag, allow_empty = FALSE) 21 | assert_bool(lgl2int) 22 | assert_bool(indicator) 23 | assert_string(format, allow_empty = FALSE) 24 | assert_string(sep) 25 | arg0( 26 | tag = tag, value = value, 27 | indicator = indicator, lgl2int = lgl2int, 28 | format = format, sep = sep 29 | ) 30 | } 31 | 32 | #' @param allow_null A single logical value indicates whether `value` can be 33 | #' `NULL`. 34 | #' @param arg An argument name as a string. This argument will be mentioned in 35 | #' error messages as the input that is at the origin of a problem. 36 | #' @param call The execution environment of a currently running function. 37 | #' @importFrom rlang caller_arg caller_call 38 | #' @export 39 | #' @rdname arg 40 | arg0 <- function(tag, value, 41 | indicator = FALSE, lgl2int = FALSE, 42 | format = "%s", sep = " ", allow_null = FALSE, 43 | arg = caller_arg(value), call = caller_call()) { 44 | if (is.null(value)) { 45 | if (allow_null) { 46 | return(NULL) 47 | } 48 | cli::cli_abort("{.arg {arg}} cannot be {.code NULL}", call = call) 49 | } 50 | if (indicator) { 51 | assert_bool(value, arg = arg, call = call) 52 | if (value) { 53 | return(tag) 54 | } else { 55 | return(NULL) 56 | } 57 | } 58 | assert_string(sep, call = call) 59 | if (lgl2int) { 60 | assert_bool(value, arg = arg, call = call) 61 | format <- "%d" 62 | value <- as.integer(value) 63 | } else { 64 | assert_string(format, allow_empty = FALSE, call = call) 65 | if (format == "%d") { 66 | assert_(value, is_number, "a number", arg = arg, call = call) 67 | } else { 68 | assert_(value, 69 | function(x) is_scalar(x) && !is.na(x), 70 | "a single value", 71 | arg = arg, call = call 72 | ) 73 | } 74 | } 75 | sprintf(paste(tag, format, sep = sep), value) 76 | } 77 | -------------------------------------------------------------------------------- /R/blit-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | ## usethis namespace: start 5 | #' @importFrom rlang .data 6 | #' @importFrom rlang .env 7 | #' @importFrom R6 R6Class 8 | ## usethis namespace: end 9 | NULL 10 | -------------------------------------------------------------------------------- /R/cmd-alleleCounter.R: -------------------------------------------------------------------------------- 1 | #' Run alleleCount 2 | #' 3 | #' The `alleleCount` program primarily exists to prevent code duplication 4 | #' between some other projects, specifically `AscatNGS` and `Battenberg`. 5 | #' 6 | #' @param hts_file A string of path to sample HTS file. 7 | #' @param loci_file A string of path to loci file. 8 | #' @param ofile A string of path to the output file. 9 | #' @param odir A string of path to the output directory. 10 | #' @param ... `r rd_dots("alleleCounter")`. 11 | #' @param alleleCounter `r rd_cmd("alleleCounter")`. 12 | #' @family command 13 | #' @inherit exec return 14 | #' @seealso 15 | #' - 16 | #' 17 | #' `r rd_seealso()` 18 | #' @export 19 | allele_counter <- make_command( 20 | "allele_counter", 21 | function( 22 | hts_file, 23 | loci_file, 24 | ofile, 25 | ..., 26 | odir = getwd(), 27 | alleleCounter = NULL 28 | ) { 29 | assert_string(alleleCounter, allow_empty = FALSE, allow_null = TRUE) 30 | AlleleCounter$new(, 31 | cmd = alleleCounter, 32 | ..., 33 | hts_file = hts_file, 34 | loci_file = loci_file, 35 | ofile = ofile, 36 | odir = odir 37 | ) 38 | } 39 | ) 40 | 41 | AlleleCounter <- R6Class( 42 | "AlleleCounter", 43 | inherit = Command, 44 | private = list( 45 | alias = function() "alleleCounter", 46 | setup_help_params = function() "--help", 47 | setup_command_params = function(hts_file, loci_file, ofile, odir) { 48 | opath <- build_opath(odir, ofile) 49 | c( 50 | arg0("-l", loci_file), 51 | arg0("-b", hts_file), 52 | arg0("-o", opath) 53 | ) 54 | } 55 | ) 56 | ) 57 | -------------------------------------------------------------------------------- /R/cmd-cellranger.R: -------------------------------------------------------------------------------- 1 | #' Run cellranger 2 | #' @param subcmd Sub-Command of cellranger. 3 | #' @param ... `r rd_dots("cellranger")`. 4 | #' @param cellranger `r rd_cmd("cellranger")`. 5 | #' @inherit exec return 6 | #' @seealso 7 | #' - 8 | #' - 9 | #' - 10 | #' 11 | #' `r rd_seealso()` 12 | #' @examples 13 | #' \dontrun{ 14 | #' fastq_dir # 10x raw fastq files directory 15 | #' genome_ref # Please download the transcriptome reference data 16 | #' cellranger( 17 | #' "count", 18 | #' sprintf("--fastqs=%s", fastq_dir), 19 | #' sprintf("--id=%s", basename(fastq_dir)), 20 | #' sprintf("--sample=%s", basename(fastq_dir)), 21 | #' sprintf("--localcores=%s", parallel::detectCores()), 22 | #' sprintf("--transcriptome=%s", genome_ref), 23 | #' sprintf("--chemistry=%s", shQuote("auto")), 24 | #' "--nosecondary" 25 | #' ) 26 | #' } 27 | #' @family command 28 | #' @export 29 | cellranger <- make_command( 30 | "cellranger", 31 | function(subcmd = NULL, ..., cellranger = NULL) { 32 | assert_string(subcmd, allow_empty = FALSE, allow_null = TRUE) 33 | assert_string(cellranger, allow_empty = FALSE, allow_null = TRUE) 34 | CellRanger$new(cmd = cellranger, ..., subcmd = subcmd) 35 | } 36 | ) 37 | 38 | CellRanger <- R6Class( 39 | "CellRanger", 40 | inherit = Command, 41 | private = list( 42 | alias = function() "cellranger", 43 | setup_help_params = function() "--help", 44 | combine_params = function(subcmd) { 45 | c(subcmd, super$combine_params()) 46 | } 47 | ) 48 | ) 49 | -------------------------------------------------------------------------------- /R/cmd-conda.R: -------------------------------------------------------------------------------- 1 | #' Run conda 2 | #' @param subcmd Sub-Command of conda. 3 | #' @param ... `r rd_dots("conda")`. 4 | #' @param conda `r rd_cmd("conda")`. 5 | #' @inherit exec return 6 | #' @seealso 7 | #' `r rd_seealso()` 8 | #' @family command 9 | #' @export 10 | conda <- make_command( 11 | "conda", 12 | function(subcmd = NULL, ..., conda = NULL) { 13 | assert_string(subcmd, allow_empty = FALSE, allow_null = TRUE) 14 | assert_string(conda, allow_empty = FALSE, allow_null = TRUE) 15 | Conda$new(cmd = conda, ..., subcmd = subcmd) 16 | } 17 | ) 18 | 19 | Conda <- R6Class( 20 | "Conda", 21 | inherit = Command, 22 | private = list( 23 | command_name = function() "conda", 24 | alias = function() c("micromamba", "mamba", "conda"), 25 | setup_help_params = function() "--help", 26 | combine_params = function(subcmd) c(subcmd, super$combine_params()) 27 | ) 28 | ) 29 | -------------------------------------------------------------------------------- /R/cmd-exec.R: -------------------------------------------------------------------------------- 1 | #' Invoke a System Command 2 | #' 3 | #' @param cmd Command to be invoked, as a character string. 4 | #' @param ... `r rd_dots("cmd", FALSE)`. 5 | #' @examples 6 | #' cmd_run(exec("echo", "$PATH")) 7 | #' @return A `command` object. 8 | #' @eval rd_collect_family("command", "`command` collections") 9 | #' @seealso 10 | #' `r rd_seealso()` 11 | #' @export 12 | exec <- make_command("exec", function(cmd, ...) { 13 | assert_string(cmd, allow_empty = FALSE) 14 | Execute$new(cmd = cmd, ...) 15 | }) 16 | 17 | Execute <- R6Class( 18 | "Execute", 19 | inherit = Command, 20 | private = list( 21 | command_name = function() .subset2(private$.core_params, "cmd"), 22 | object_name = function() { 23 | sprintf("", private$command_name()) 24 | }, 25 | setup_help_params = function() { 26 | cli::cli_abort(c( 27 | paste( 28 | "Don't know how to show the help document for", 29 | private$object_name() 30 | ), 31 | i = paste( 32 | "Please manually set the help document argument with", 33 | "{.code cmd_run(exec(\"{private$command_name()}\", ...))}", 34 | "instead." 35 | ) 36 | )) 37 | } 38 | ) 39 | ) 40 | -------------------------------------------------------------------------------- /R/cmd-fastp.R: -------------------------------------------------------------------------------- 1 | #' Run fastp 2 | #' 3 | #' The `fastp` is a tool designed to provide ultrafast all-in-one preprocessing 4 | #' and quality control for FastQ data. 5 | #' @param fq1,fq2 A string of fastq file path. 6 | #' @param ... `r rd_dots("fastp")`. 7 | #' @param ofile1,ofile2 A string of path to the output fastq file. 8 | #' @param fastp `r rd_cmd("fastp")`. 9 | #' @family command 10 | #' @inherit exec return 11 | #' @seealso 12 | #' - 13 | #' 14 | #' `r rd_seealso()` 15 | #' @export 16 | fastp <- make_command( 17 | "fastp", 18 | function( 19 | fq1, 20 | ofile1, 21 | ..., 22 | fq2 = NULL, 23 | ofile2 = NULL, 24 | fastp = NULL 25 | ){ 26 | assert_string(fastp, allow_empty = FALSE, allow_null = TRUE) 27 | Fastp$new( 28 | cmd = fastp, 29 | ..., 30 | fq1 = fq1, 31 | fq2 = fq2, 32 | ofile1 = ofile1, 33 | ofile2 = ofile2 34 | ) 35 | } 36 | ) 37 | 38 | Fastp <- R6Class( 39 | "Fastp", 40 | inherit = Command, 41 | private = list( 42 | alias = function() "fastp", 43 | setup_help_params = function() "--help", 44 | setup_command_params = function(fq1, fq2, ofile1, ofile2){ 45 | c( 46 | arg0("-i", fq1), 47 | if (!is.null(fq2)) arg0("-I", fq2) else NULL, 48 | arg0("-o", ofile1), 49 | if (!is.null(ofile2)) arg0("-O", ofile2) else NULL 50 | ) 51 | } 52 | ) 53 | ) 54 | -------------------------------------------------------------------------------- /R/cmd-fastq_pair.R: -------------------------------------------------------------------------------- 1 | #' FASTQ PAIR 2 | #' 3 | #' @description 4 | #' Rewrite paired end fastq files to make sure that all reads have a mate and to 5 | #' separate out singletons. 6 | #' 7 | #' Usually when you get paired end read files you have two files with a /1 8 | #' sequence in one and a /2 sequence in the other (or a /f and /r or just two 9 | #' reads with the same ID). However, often when working with files from a third 10 | #' party source (e.g. the SRA) there are different numbers of reads in each file 11 | #' (because some reads fail QC). Spades, bowtie2 and other tools break because 12 | #' they demand paired end files have the same number of reads. 13 | #' 14 | #' @param fq1,fq2 A string of fastq file path. 15 | #' @param ... `r rd_dots("fastq_pair")`. 16 | #' @param hash_table_size Size of hash table to use. 17 | #' @param max_hash_table_size Maximal hash table size to use. 18 | #' @param fastq_pair `r rd_cmd("fastq_pair")`. 19 | #' @seealso 20 | #' - 21 | #' 22 | #' `r rd_seealso()` 23 | #' @inherit exec return 24 | #' @family command 25 | #' @export 26 | fastq_pair <- make_command( 27 | "fastq_pair", 28 | function( 29 | fq1, 30 | fq2, 31 | ..., 32 | hash_table_size = NULL, 33 | max_hash_table_size = NULL, 34 | fastq_pair = NULL 35 | ) { 36 | assert_string(fastq_pair, allow_empty = FALSE, allow_null = TRUE) 37 | FastqPair$new( 38 | cmd = fastq_pair, 39 | ..., 40 | fq1 = fq1, 41 | fq2 = fq2, 42 | hash_table_size = hash_table_size, 43 | max_hash_table_size = max_hash_table_size 44 | ) 45 | } 46 | ) 47 | 48 | FastqPair <- R6Class( 49 | "FastqPair", 50 | inherit = Command, 51 | private = list( 52 | alias = function() "fastq_pair", 53 | setup_help_params = function() "--help", 54 | setup_command_params = function( 55 | fq1, 56 | fq2, 57 | hash_table_size, 58 | max_hash_table_size 59 | ) { 60 | assert_string(fq1, allow_empty = FALSE) 61 | assert_string(fq2, allow_empty = FALSE) 62 | if (is.null(hash_table_size)) { 63 | nlines_file <- tempfile() 64 | if (private$verbose) { 65 | cli::cli_inform( 66 | "counting the number of lines of {.path {fq1}}" 67 | ) 68 | } 69 | on.exit(file.remove(nlines_file), add = TRUE) 70 | cmd_run( 71 | exec("wc", "-l", fq1), 72 | stdout = nlines_file, 73 | verbose = FALSE 74 | ) 75 | hash_table_size <- strsplit( 76 | read_lines(nlines_file, n = 1L), 77 | " ", 78 | fixed = TRUE 79 | )[[c(1L, 1L)]] 80 | hash_table_size <- ceiling(as.integer(hash_table_size) / 4L) 81 | if (private$verbose) { 82 | cli::cli_inform("Using -t {.val {hash_table_size}}") 83 | } 84 | } 85 | if (!is.null(max_hash_table_size)) { 86 | hash_table_size <- min(hash_table_size, max_hash_table_size) 87 | } 88 | c( 89 | arg0("-t", hash_table_size, format = "%d"), 90 | fq1, 91 | fq2, 92 | ">", 93 | nullfile() 94 | ) 95 | } 96 | ) 97 | ) 98 | 99 | #' @param fastq_files A character of the fastq file paths. 100 | #' @rdname fastq_pair 101 | #' @export 102 | fastq_read_pair <- function(fastq_files) { 103 | header_list <- lapply(fastq_files, function(file) { 104 | header <- read_lines2(file, n = 1L) 105 | strsplit(header, ":| ", perl = TRUE)[[1L]] 106 | }) 107 | # @HWI-ST1276:71:C1162ACXX:1:1101:1208:2458 2:N:0:CGATGT 108 | # HWI-ST1276 <- Unique instrument name 109 | # 71 <- Run ID 110 | # C1162ACXX <- Flowcell ID 111 | # 1 <- Flowcell lane 112 | # 1101 <- Tile number within the flowcell lane 113 | # 1208 <- 'x'-coordinate of the cluster within the tile 114 | # 2458 <- 'y'-coordinate of the cluster within the tile 115 | 116 | # 2 <- Member of a pair,1 or 2 (paired-end or mate-pair reads only) 117 | # N <- Y if the read fails filter (read is bad), N otherwise 118 | # 0 <- 0 when none of the control bits are on,otherwise it is an even number 119 | # CGATGT -> Index sequence 120 | 121 | # In Illumina data, read group IDs are composed using the flowcell name and 122 | # lane number, making them a globally unique identifier across all 123 | # sequencing data in the world. 124 | # Use for BQSR: ID is the lowest denominator that differentiates factors 125 | # contributing to technical batch effects: therefore, a read group is 126 | # effectively treated as a separate run of the instrument in data processing 127 | # steps such as base quality score recalibration (unless you have PU 128 | # defined), since they are assumed to share the same error model. 129 | 130 | # https://gatk.broadinstitute.org/hc/en-us/articles/360035890671-Read-groups 131 | # https://samtools.github.io/hts-specs/SAMv1.pdf 132 | # https://angus.readthedocs.io/en/2017/Read_group_info.html 133 | # header <- header_list[[1L]] 134 | # id <- sub("^@", "", paste(header[3:4], collapse = "."), perl = TRUE) 135 | # flowcell_id <- header[[3L]] 136 | # lane_id <- header[[4L]] 137 | 138 | # Platform/technology used to produce the reads. Valid values: CAPILLARY, 139 | # DNBSEQ (MGI/BGI), ELEMENT, HELICOS, ILLUMINA, IONTORRENT, LS454, ONT 140 | # (Oxford Nanopore), PACBIO (Pacific Bio-sciences), SOLID, and ULTIMA. This 141 | # field should be omitted when the technology is not in this list (though 142 | # the PM field may still be present in this case) or is unknown 143 | # platform_id <- "ILLUMINA" 144 | 145 | # extract pair_id ---------------------------- 146 | vapply( 147 | header_list, 148 | function(header) as.integer(header[[8L]]), 149 | integer(1L), 150 | USE.NAMES = FALSE 151 | ) 152 | } 153 | -------------------------------------------------------------------------------- /R/cmd-gistic2.R: -------------------------------------------------------------------------------- 1 | #' Run GISTIC2 2 | #' 3 | #' @description The GISTIC module identifies regions of the genome that are 4 | #' significantly amplified or deleted across a set of samples. Each aberration 5 | #' is assigned a G-score that considers the amplitude of the aberration as well 6 | #' as the frequency of its occurrence across samples. False Discovery Rate 7 | #' q-values are then calculated for the aberrant regions, and regions with 8 | #' q-values below a user-defined threshold are considered significant. For each 9 | #' significant region, a "peak region" is identified, which is the part of the 10 | #' aberrant region with greatest amplitude and frequency of alteration. In 11 | #' addition, a "wide peak" is determined using a leave-one-out algorithm to 12 | #' allow for errors in the boundaries in a single sample. The "wide peak" 13 | #' boundaries are more robust for identifying the most likely gene targets in 14 | #' the region. Each significantly aberrant region is also tested to determine 15 | #' whether it results primarily from broad events (longer than half a chromosome 16 | #' arm), focal events, or significant levels of both. The GISTIC module reports 17 | #' the genomic locations and calculated q-values for the aberrant regions. It 18 | #' identifies the samples that exhibit each significant amplification or 19 | #' deletion, and it lists genes found in each "wide peak" region. 20 | #' 21 | #' @param seg A data.frame of segmented data. 22 | #' @param refgene Path to reference genome data input file (REQUIRED, see below 23 | #' for file description). 24 | #' @param ... `r rd_dots("gistic2")`. 25 | #' @inheritParams allele_counter 26 | #' @param gistic2 `r rd_cmd("gistic2")`. 27 | #' @seealso 28 | #' - 29 | #' 30 | #' `r rd_seealso()` 31 | #' @inherit exec return 32 | #' @family command 33 | #' @export 34 | gistic2 <- make_command( 35 | "gistic2", 36 | function(seg, refgene, ..., odir = getwd(), gistic2 = NULL) { 37 | assert_string(gistic2, allow_empty = FALSE, allow_null = TRUE) 38 | Gistic2$new( 39 | cmd = gistic2, 40 | ..., 41 | odir = odir, 42 | seg = seg, 43 | refgene = refgene 44 | ) 45 | } 46 | ) 47 | 48 | Gistic2 <- R6Class( 49 | "Gistic2", 50 | inherit = Command, 51 | private = list( 52 | alias = function() "gistic2", 53 | setup_command_params = function(seg, refgene, odir) { 54 | assert_s3_class(seg, "data.frame", "a data frame") 55 | odir <- build_opath(odir) 56 | seg_file <- tempfile("gistic2") 57 | write_table(seg, seg_file) 58 | private$setup_on_exit(file.remove(seg_file)) 59 | c( 60 | arg0("-seg", seg_file), 61 | arg0("-refgene", refgene), 62 | arg0("-b", odir) 63 | ) 64 | } 65 | ) 66 | ) 67 | -------------------------------------------------------------------------------- /R/cmd-kraken2-tools.R: -------------------------------------------------------------------------------- 1 | #' KrakenTools is a suite of scripts to be used alongside the Kraken, 2 | #' KrakenUniq, Kraken 2, or Bracken programs. 3 | #' 4 | #' @description These scripts are designed to help Kraken users with downstream 5 | #' analysis of Kraken results. 6 | #' 7 | #' @param script Name of the kraken2 script. One of 8 | #' `r oxford_comma(code_quote(KrakenToolsScripts))`. 9 | #' @param ... `r rd_dots("kraken_tools")`. 10 | #' @inheritParams python 11 | #' @seealso 12 | #' - 13 | #' 14 | #' `r rd_seealso()` 15 | #' @inherit exec return 16 | #' @family command 17 | #' @export 18 | kraken_tools <- make_command( 19 | "kraken_tools", 20 | function(script, ..., python = NULL) { 21 | script <- rlang::arg_match0(script, KrakenToolsScripts) 22 | KrakenTools$new(cmd = python, ..., script = script) 23 | } 24 | ) 25 | 26 | KrakenTools <- R6Class( 27 | "KrakenTools", 28 | inherit = Python, 29 | private = list( 30 | combine_params = function(script) { 31 | script <- pkg_extdata("KrakenTools", paste0(script, ".py")) 32 | file_executable(script) 33 | c(script, super$combine_params()) 34 | } 35 | ) 36 | ) 37 | 38 | KrakenToolsScripts <- c( 39 | "combine_kreports", "combine_mpa", "extract_kraken_reads", 40 | "filter_bracken_out", "fix_unmapped", "kreport2krona", 41 | "kreport2mpa", "make_kreport", "make_ktaxonomy" 42 | ) 43 | -------------------------------------------------------------------------------- /R/cmd-kraken2.R: -------------------------------------------------------------------------------- 1 | #' Running Kraken2 2 | #' 3 | #' Kraken is a taxonomic sequence classifier that assigns taxonomic labels to 4 | #' DNA sequences. Kraken examines the k-mers within a query sequence and uses 5 | #' the information within those k-mers to query a database. That database maps 6 | #' k-mers to the lowest common ancestor (LCA) of all genomes known to contain a 7 | #' given k-mer. 8 | #' 9 | #' @param fq1,fq2 A string of fastq file path. 10 | #' @param ... `r rd_dots("kraken2")`. 11 | #' @param ofile A string of path to save kraken2 output. 12 | #' @param report A string of path to save kraken2 report. 13 | #' @param classified_out A string of path to save classified sequences, which 14 | #' should be a fastq file. 15 | #' @param unclassified_out A string of path to save unclassified sequences, 16 | #' which should be a fastq file. 17 | #' @inheritParams allele_counter 18 | #' @param kraken2 `r rd_cmd("kraken2")`. 19 | #' @seealso 20 | #' - 21 | #' - 22 | #' 23 | #' `r rd_seealso()` 24 | #' @family command 25 | #' @inherit exec return 26 | #' @export 27 | kraken2 <- make_command( 28 | "kraken2", 29 | function( 30 | fq1, 31 | ..., 32 | fq2 = NULL, 33 | ofile = "kraken_output.txt", 34 | report = "kraken_report.txt", 35 | classified_out = NULL, 36 | unclassified_out = NULL, 37 | odir = getwd(), 38 | kraken2 = NULL 39 | ) { 40 | assert_string(kraken2, allow_empty = FALSE, allow_null = TRUE) 41 | Kraken2$new( 42 | cmd = kraken2, 43 | ..., 44 | fq1 = fq1, 45 | fq2 = fq2, 46 | ofile = ofile, 47 | report = report, 48 | classified_out = classified_out, 49 | unclassified_out = unclassified_out, 50 | odir = odir, 51 | ) 52 | } 53 | ) 54 | 55 | Kraken2 <- R6Class( 56 | "Kraken2", 57 | inherit = Command, 58 | private = list( 59 | alias = function() "kraken2", 60 | setup_help_params = function() "--help", 61 | setup_command_params = function( 62 | fq1, 63 | fq2, 64 | ofile, 65 | report, 66 | classified_out, 67 | unclassified_out, 68 | odir 69 | ) { 70 | assert_string(ofile, allow_null = TRUE) 71 | assert_string(report, allow_null = TRUE) 72 | assert_string(classified_out, allow_null = TRUE) 73 | # https://github.com/DerrickWood/kraken2/wiki/Manual 74 | # Usage of --paired also affects the --classified-out and 75 | # --unclassified-out options; users should provide a # character in 76 | # the filenames provided to those options, which will be replaced by 77 | # kraken2 with "_1" and "_2" with mates spread across the two files 78 | # appropriately. For example: 79 | odir <- build_opath(odir) 80 | if (!is.null(classified_out)) { 81 | if (!is.null(fq2)) { 82 | classified_out <- sprintf("%s#", classified_out) 83 | } 84 | classified_out <- file_path(odir, classified_out) 85 | } 86 | if (!is.null(unclassified_out)) { 87 | if (!is.null(fq2)) { 88 | unclassified_out <- sprintf("%s#", unclassified_out) 89 | } 90 | unclassified_out <- file_path(odir, unclassified_out) 91 | } 92 | if (!is.null(ofile)) ofile <- file_path(odir, ofile) 93 | if (!is.null(report)) report <- file_path(odir, report) 94 | opath <- c(ofile, report) 95 | c( 96 | arg0( 97 | "--classified-out", 98 | classified_out, 99 | allow_null = TRUE 100 | ), 101 | arg0( 102 | "--unclassified-out", 103 | classified_out, 104 | allow_null = TRUE 105 | ), 106 | arg0("--output", ofile, allow_null = TRUE), 107 | arg0("--report", report, allow_null = TRUE), 108 | if (!is.null(fq2)) "--paired", 109 | fq1, 110 | fq2 111 | ) 112 | } 113 | ) 114 | ) 115 | -------------------------------------------------------------------------------- /R/cmd-perl.R: -------------------------------------------------------------------------------- 1 | #' Perl is a highly capable, feature-rich programming language with over 36 2 | #' years of development. 3 | #' 4 | #' @param ... `r rd_dots("perl")`. 5 | #' @param perl `r rd_cmd("perl")`. 6 | #' @seealso 7 | #' - 8 | #' 9 | #' `r rd_seealso()` 10 | #' @inherit exec return 11 | #' @family command 12 | #' @export 13 | perl <- make_command( 14 | "perl", 15 | function(..., perl = NULL) { 16 | assert_string(perl, allow_empty = FALSE, allow_null = TRUE) 17 | Perl$new(cmd = perl, ...) 18 | } 19 | ) 20 | 21 | Perl <- R6Class( 22 | "Perl", 23 | inherit = Command, 24 | private = list( 25 | alias = function() "perl", 26 | setup_help_params = function() "--help" 27 | ) 28 | ) 29 | -------------------------------------------------------------------------------- /R/cmd-pyscenic.R: -------------------------------------------------------------------------------- 1 | #' Run pyscenic 2 | #' 3 | #' @param subcmd Sub-Command of pyscenic. 4 | #' @param ... `r rd_dots("pyscenic subcmd")`. 5 | #' @param pyscenic `r rd_cmd("pyscenic")`. 6 | #' @inherit exec return 7 | #' @seealso 8 | #' - 9 | #' 10 | #' `r rd_seealso()` 11 | #' @family command 12 | #' @export 13 | pyscenic <- make_command( 14 | "pyscenic", 15 | function(subcmd = NULL, ..., pyscenic = NULL) { 16 | assert_string(subcmd, allow_empty = FALSE, allow_null = TRUE) 17 | assert_string(pyscenic, allow_empty = FALSE, allow_null = TRUE) 18 | Pyscenic$new(cmd = pyscenic, ..., subcmd = subcmd) 19 | } 20 | ) 21 | 22 | Pyscenic <- R6Class( 23 | "Pyscenic", 24 | inherit = Command, 25 | private = list( 26 | alias = function() "pyscenic", 27 | setup_help_params = function() "--help", 28 | combine_params = function(subcmd) { 29 | c(subcmd, super$combine_params()) 30 | } 31 | ) 32 | ) 33 | -------------------------------------------------------------------------------- /R/cmd-python.R: -------------------------------------------------------------------------------- 1 | #' Python is a programming language that lets you work quickly and integrate 2 | #' systems more effectively. 3 | #' 4 | #' @param ... `r rd_dots("python")`. 5 | #' @param python `r rd_cmd("python")`. 6 | #' @seealso 7 | #' - 8 | #' 9 | #' `r rd_seealso()` 10 | #' @inherit exec return 11 | #' @family command 12 | #' @export 13 | python <- make_command( 14 | "python", 15 | function(..., python = NULL) { 16 | assert_string(python, allow_empty = FALSE, allow_null = TRUE) 17 | Python$new(cmd = python, ...) 18 | } 19 | ) 20 | 21 | Python <- R6Class( 22 | "Python", 23 | inherit = Command, 24 | private = list( 25 | alias = function() c("python", "python3", "python2"), 26 | setup_help_params = function() "--help" 27 | ) 28 | ) 29 | -------------------------------------------------------------------------------- /R/cmd-samtools.R: -------------------------------------------------------------------------------- 1 | #' Python is a programming language that lets you work quickly and integrate 2 | #' systems more effectively. 3 | #' 4 | #' @param subcmd Sub-Command of samtools. Details see: `r rd_help("samtools")`. 5 | #' @param ... `r rd_dots("samtools")`. 6 | #' @param samtools `r rd_cmd("samtools")`. 7 | #' @seealso 8 | #' - 9 | #' 10 | #' `r rd_seealso()` 11 | #' @inherit exec return 12 | #' @family command 13 | #' @export 14 | samtools <- make_command( 15 | "samtools", 16 | function(subcmd = NULL, ..., samtools = NULL) { 17 | assert_string(subcmd, allow_empty = FALSE, allow_null = TRUE) 18 | assert_string(samtools, allow_empty = FALSE, allow_null = TRUE) 19 | Samtools$new(cmd = samtools, ..., subcmd = subcmd) 20 | } 21 | ) 22 | 23 | Samtools <- R6Class( 24 | "Samtools", 25 | inherit = Command, 26 | private = list( 27 | alias = function() "samtools", 28 | setup_help_params = function() "help", 29 | combine_params = function(subcmd) { 30 | if (private$help) { 31 | c(super$combine_params(), subcmd) 32 | } else { 33 | c(subcmd, super$combine_params()) 34 | } 35 | } 36 | ) 37 | ) 38 | -------------------------------------------------------------------------------- /R/cmd-schedule.R: -------------------------------------------------------------------------------- 1 | #' Schedule expressions to run 2 | #' 3 | #' @describeIn cmd_on_start define the startup code of the command 4 | #' @inheritParams cmd_wd 5 | #' @param ... The expressions input will be captured with 6 | #' [`enquos()`][rlang::enquos]. If your expressions depend on global data, you 7 | #' may want to unquote objects with [`!!`][rlang::injection-operator] to prevent 8 | #' unintended changes due to delayed evaluation. 9 | #' - `cmd_on_start`: Expression to be evaluated when the command started. 10 | #' - `cmd_on_exit`: Expression to be evaluated when the command finished. 11 | #' - `cmd_on_fail`: Expression to be evaluated when the command failed. 12 | #' - `cmd_on_succeed`: Expression to be evaluated when the command succeeded. 13 | #' @return 14 | #' - `cmd_on_start`: The `command` object itself, with the start code updated. 15 | #' @export 16 | cmd_on_start <- function(command, ...) { 17 | assert_s3_class(command, "command") 18 | command$on_start <- c(.subset2(command, "on_start"), rlang::enquos(...)) 19 | command 20 | } 21 | 22 | #' @describeIn cmd_on_start define the exit code of the command 23 | #' @return 24 | #' - `cmd_on_exit`: The `command` object itself, with the exit code updated. 25 | #' @export 26 | cmd_on_exit <- function(command, ...) { 27 | assert_s3_class(command, "command") 28 | command$on_exit <- c(.subset2(command, "on_exit"), rlang::enquos(...)) 29 | command 30 | } 31 | 32 | #' @describeIn cmd_on_start define the failure code of the command 33 | #' @return 34 | #' - `cmd_on_fail`: The `command` object itself, with the failure code updated. 35 | #' @export 36 | cmd_on_fail <- function(command, ...) { 37 | assert_s3_class(command, "command") 38 | command$on_fail <- c(.subset2(command, "on_fail"), rlang::enquos(...)) 39 | command 40 | } 41 | 42 | #' @describeIn cmd_on_start define the successful code of the command 43 | #' @return 44 | #' - `cmd_on_succeed`: The `command` object itself, with the successful code 45 | #' updated. 46 | #' @export 47 | cmd_on_succeed <- function(command, ...) { 48 | assert_s3_class(command, "command") 49 | command$on_succeed <- c(.subset2(command, "on_succeed"), rlang::enquos(...)) 50 | command 51 | } 52 | -------------------------------------------------------------------------------- /R/cmd-seqkit.R: -------------------------------------------------------------------------------- 1 | #' Run seqkit 2 | #' @param subcmd Sub-Command of seqkit. 3 | #' @param ... `r rd_dots("seqkit subcmd")`. 4 | #' @param seqkit `r rd_cmd("seqkit")`. 5 | #' @seealso 6 | #' - 7 | #' 8 | #' `r rd_seealso()` 9 | #' @inherit exec return 10 | #' @family command 11 | #' @export 12 | seqkit <- make_command( 13 | "seqkit", 14 | function(subcmd = NULL, ..., seqkit = NULL) { 15 | assert_string(subcmd, allow_empty = FALSE, allow_null = TRUE) 16 | assert_string(seqkit, allow_empty = FALSE, allow_null = TRUE) 17 | SeqKit$new(cmd = seqkit, ..., subcmd = subcmd) 18 | } 19 | ) 20 | 21 | SeqKit <- R6Class( 22 | "SeqKit", 23 | inherit = Command, 24 | private = list( 25 | alias = function() "seqkit", 26 | setup_help_params = function() "--help", 27 | combine_params = function(subcmd) { 28 | c(subcmd, super$combine_params()) 29 | } 30 | ) 31 | ) 32 | -------------------------------------------------------------------------------- /R/cmd-setup.R: -------------------------------------------------------------------------------- 1 | #' Setup the context for the command 2 | #' 3 | #' @describeIn cmd_wd define the working directory. 4 | #' @inheritParams cmd_help 5 | #' @param wd A string or `NULL` define the working directory of the command. 6 | #' @return 7 | #' - `cmd_wd`: The `command` object itself, with working directory updated. 8 | #' @seealso 9 | #' - [`cmd_run()`]/[`cmd_help()`]/[`cmd_background()`] 10 | #' - [`cmd_on_start()`]/[`cmd_on_exit()`] 11 | #' - [`cmd_on_succeed()`]/[`cmd_on_fail()`] 12 | #' - [`cmd_parallel()`] 13 | #' @export 14 | cmd_wd <- function(command, wd = NULL) { 15 | assert_s3_class(command, "command") 16 | assert_string(wd, allow_empty = FALSE, allow_null = TRUE) 17 | command["wd"] <- list(wd) 18 | command 19 | } 20 | 21 | #' @describeIn cmd_wd define the environment variables. 22 | #' @inheritParams cmd_wd 23 | #' @param ... <[dynamic dots][rlang::dyn-dots]>: 24 | #' - `cmd_envvar`: Named character define the environment variables. 25 | #' - `cmd_envpath`: Unnamed character to define the `PATH`-like environment 26 | #' variables `name`. 27 | #' - `cmd_condaenv`: Unnamed character to specify the name of conda 28 | #' environment. 29 | #' @param action Should the new values `"replace"`, `"prefix"` or `"suffix"` 30 | #' existing environment variables? 31 | #' @param sep A string to separate new and old value when `action` is `"prefix"` 32 | #' or `"suffix"`. By default, `" "` will be used. 33 | #' @return 34 | #' - `cmd_envvar`: The `command` object itself, with running environment 35 | #' variable updated. 36 | #' @export 37 | cmd_envvar <- function(command, ..., action = "replace", sep = NULL) { 38 | assert_s3_class(command, "command") 39 | action <- rlang::arg_match0(action, c("replace", "prefix", "suffix")) 40 | assert_string(sep, allow_null = TRUE) 41 | dots <- rlang::dots_list(..., .ignore_empty = "all") 42 | if (!rlang::is_named2(dots)) { 43 | cli::cli_abort("All input in {.arg ...} must be named") 44 | } 45 | dots[vapply(dots, is.null, logical(1L), USE.NAMES = FALSE)] <- NA_character_ 46 | if (any(lengths(dots) != 1L)) { 47 | cli::cli_abort(paste( 48 | "All input in {.arg ...} must be of length 1", 49 | "or {.val NULL}" 50 | )) 51 | } 52 | for (nm in names(dots)) { 53 | command$envvar[[nm]] <- envvar_add( 54 | new = .subset2(dots, nm), 55 | old = .subset2(.subset2(command, "envvar"), nm), 56 | action = action, 57 | sep = sep 58 | ) 59 | } 60 | command 61 | } 62 | 63 | #' @describeIn cmd_wd define the `PATH`-like environment variables. 64 | #' @param name A string define the PATH environment variable name. You 65 | #' can use this to define other `PATH`-like environment variable such as 66 | #' `PYTHONPATH`. 67 | #' @return 68 | #' - `cmd_envpath`: The `command` object itself, with running environment 69 | #' variable specified in `name` updated. 70 | #' @importFrom rlang := 71 | #' @export 72 | cmd_envpath <- function(command, ..., action = "prefix", name = "PATH") { 73 | assert_s3_class(command, "command") 74 | rlang::check_dots_unnamed() 75 | assert_string(name, allow_empty = FALSE) 76 | envpath <- rlang::dots_list(..., .ignore_empty = "all") 77 | envpath <- as.character(unlist(envpath, use.names = FALSE)) 78 | if (anyNA(envpath)) { 79 | cli::cli_warn("Missing value will be ignored") 80 | envpath <- envpath[!is.na(envpath)] 81 | } 82 | if (length(envpath) == 0L) { 83 | return(command) 84 | } 85 | envpath <- normalizePath(envpath, "/", mustWork = FALSE) 86 | envpath <- rev(envpath) 87 | envpath <- paste0(envpath, collapse = .Platform$path.sep) 88 | cmd_envvar( 89 | command, 90 | !!name := envpath, # nolint 91 | action = action, 92 | sep = .Platform$path.sep 93 | ) 94 | } 95 | 96 | #' @describeIn cmd_wd Set `conda-like` environment prefix to the `PATH` 97 | #' environment variables. 98 | #' @param root A string specifying the path to the conda root prefix. If not 99 | #' provided, the function searches for the root in the following order: 100 | #' 1. the [option] `blit.conda.root`. 101 | #' 2. the [environment variable][Sys.getenv()] `BLIT_CONDA_ROOT`. 102 | #' 3. the root prefix of [`appmamba()`]. 103 | #' @return 104 | #' - `cmd_condaenv`: The `command` object itself, with running environment 105 | #' variable `PATH` updated. 106 | #' @export 107 | cmd_condaenv <- function(command, ..., root = NULL, action = "prefix") { 108 | assert_s3_class(command, "command") 109 | rlang::check_dots_unnamed() 110 | envs <- rlang::dots_list(..., .ignore_empty = "all") 111 | envs <- as.character(unlist(envs, FALSE, FALSE)) 112 | if (anyNA(envs)) { 113 | cli::cli_abort("Cannot use missing value in {.arg ...}") 114 | } 115 | assert_string(root, allow_null = TRUE) 116 | root <- root %||% conda_root() 117 | if (is.null(root)) { 118 | cli::cli_warn("No conda environment found") 119 | return(command) 120 | } 121 | envs_dir <- file.path(root, "envs", envs, fsep = "/") 122 | envs_exists <- dir.exists(envs_dir) 123 | if (length(missing <- envs_dir[!envs_exists])) { # nolint 124 | cli::cli_warn("Cannot find environment {.envvar {missing}}") 125 | } 126 | envs_dir <- envs_dir[envs_exists] 127 | if (length(envs_dir) == 0L) { 128 | return(command) 129 | } 130 | cmd_envpath(command, 131 | file.path(envs_dir, "bin", fsep = "/"), 132 | action = action 133 | ) 134 | } 135 | 136 | conda_root <- function() { 137 | root <- getOption("blit.conda.root") 138 | if (is.null(root)) { 139 | root <- Sys.getenv("BLIT_CONDA_ROOT", unset = NA_character_) 140 | } 141 | if (!rlang::is_string(root) || !nzchar(root)) { 142 | root <- appmamba_root() 143 | if (!dir.exists(root)) root <- NULL 144 | } 145 | root 146 | } 147 | 148 | #' Set `conda-like` environment prefix to the `PATH` environment variables 149 | #' 150 | #' @description 151 | #' `r lifecycle::badge("deprecated")` Set `conda-like` environment prefix to the 152 | #' `PATH` environment variables. 153 | #' 154 | #' @param ... Additional arguments passed to [`cmd_condaenv()`]. 155 | #' @export 156 | cmd_conda <- function(...) { 157 | lifecycle::deprecate_warn("0.2.0.9999", "cmd_conda()", "cmd_condaenv()") 158 | cmd_condaenv(...) 159 | } 160 | 161 | envvar_add <- function(new, old, action, sep) { 162 | sep <- sep %||% attr(old, "sep", exact = FALSE) 163 | if (!is.na(new) && !identical(action, "replace")) { 164 | # `NA_character_` as a holder for the environment variable 165 | # and will be replaced with `Sys.getenv()` when executing the command 166 | # See `envvar_parse()` 167 | old <- old %||% NA_character_ 168 | new <- switch(action, 169 | prefix = c(new, old), 170 | suffix = c(old, new) 171 | ) 172 | } 173 | # if we should update the `sep` string? 174 | if (!is.null(sep)) attr(new, "sep") <- sep 175 | new 176 | } 177 | 178 | envvar_parse <- function(envvar) { 179 | envs <- vapply(names(envvar), function(nm) { 180 | value <- .subset2(envvar, nm) 181 | # for single NA value, we unset this environment variable 182 | if (is.null(value) || (length(value) == 1L && is.na(value))) { 183 | NA_character_ 184 | } else { 185 | na <- Sys.getenv(nm, unset = NA_character_, names = FALSE) 186 | # By default, we use `sep = " "` 187 | # if the environment variable is not set 188 | if (is.na(na)) { 189 | value <- value[!is.na(value)] 190 | } else { 191 | value[is.na(value)] <- na 192 | } 193 | sep <- attr(value, "sep", exact = TRUE) %||% " " 194 | paste(value, collapse = sep) 195 | } 196 | }, character(1L), USE.NAMES = FALSE) 197 | names(envs) <- names(envvar) 198 | envs 199 | } 200 | 201 | set_envvar <- function(envs) { 202 | unset <- vapply(envs, is.na, logical(1L), USE.NAMES = FALSE) 203 | if (any(!unset)) { 204 | rlang::inject(Sys.setenv(!!!envs[!unset])) 205 | } 206 | if (any(unset)) { 207 | Sys.unsetenv(names(envs)[unset]) 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /R/cmd-trust4.R: -------------------------------------------------------------------------------- 1 | #' TRUST4: immune repertoire reconstruction from bulk and single-cell RNA-seq 2 | #' data 3 | #' 4 | #' @param file1 Path to bam file or fastq file. 5 | #' @param file2 Path to the second paired-end read fastq file, only used for 6 | #' `mode = "fastq"`. 7 | #' @param mode One of "bam" or "fastq". If `NULL`, will be inferred from 8 | #' `file1`. 9 | #' @param ref_coordinate Path to the fasta file coordinate and sequence of 10 | #' V/D/J/C genes. 11 | #' @param ref_annot Path to detailed V/D/J/C gene reference file, such as from 12 | #' IMGT database. (default: not used). (recommended). 13 | #' @param ofile 14 | #' - `trust4`: Prefix of output files. (default: inferred from file prefix). 15 | #' - `trust4_imgt_annot`: Output file name. 16 | #' - `trust4_gene_names`: Output file name. 17 | #' @param ... 18 | #' - `trust4`: `r rd_dots("run-trust4")`. 19 | #' - `trust4_imgt_annot`: `r rd_dots("trust4_imgt_annot")`. 20 | #' @inheritParams allele_counter 21 | #' @param trust4 `r rd_cmd("run-trust4")`. 22 | #' @seealso 23 | #' - 24 | #' 25 | #' `r rd_seealso()` 26 | #' @inherit exec return 27 | #' @family command 28 | #' @export 29 | trust4 <- make_command( 30 | "trust4", 31 | function(file1, ref_coordinate, ..., file2 = NULL, 32 | mode = NULL, ref_annot = NULL, 33 | ofile = NULL, odir = getwd(), 34 | trust4 = NULL) { 35 | assert_string(trust4, allow_empty = FALSE, allow_null = TRUE) 36 | Trust4$new( 37 | cmd = trust4, 38 | ..., file1 = file1, ref_coordinate = ref_coordinate, 39 | file2 = file2, mode = mode, ref_annot = ref_annot, 40 | ofile = ofile, odir = odir 41 | ) 42 | } 43 | ) 44 | 45 | Trust4 <- R6Class( 46 | "Trust4", 47 | inherit = Command, 48 | private = list( 49 | alias = function() "run-trust4", 50 | setup_command_params = function(file1, file2, mode, ref_annot, 51 | ref_coordinate, ofile, odir) { 52 | assert_string(file1, allow_empty = FALSE) 53 | if (is.null(mode)) { 54 | if (grepl("(fastq|fq)(\\.gz)?$", file1)) { 55 | mode <- "fastq" 56 | } else if (endsWith(file1, ".bam")) { 57 | mode <- "bam" 58 | } else { 59 | cli::cli_abort(c( 60 | "Cannot infer {.arg mode} from {.arg file1}", 61 | i = "Please specify {.arg mode} manually" 62 | )) 63 | } 64 | } else { 65 | mode <- rlang::arg_match0(mode, c("bam", "fastq")) 66 | } 67 | if (mode == "bam") { 68 | if (!is.null(file2)) { 69 | cli::cli_abort( 70 | "{.arg file2} must be {.code NULL} for {.code mode = \"bam\"}" 71 | ) 72 | } 73 | params <- arg0("-b", file1) 74 | } else { 75 | if (is.null(file2)) { 76 | params <- arg0("-u", file1) 77 | } else { 78 | params <- c( 79 | arg0("-1", file1), 80 | arg0("-2", file2) 81 | ) 82 | } 83 | } 84 | odir <- build_opath(odir) 85 | c( 86 | params, 87 | arg0("-f", ref_coordinate), 88 | arg0("-ref", ref_annot, allow_null = TRUE), 89 | arg0("-o", ofile, allow_null = TRUE), 90 | arg0("--od", odir) 91 | ) 92 | } 93 | ) 94 | ) 95 | 96 | # Normally, the file specified by "--ref" is downloaded from IMGT website, For 97 | # example, for human, you can use command 98 | # `perl BuildImgtAnnot.pl Homo_sapien > IMGT+C.fa` 99 | #' @param species Species to extract IMGT annotation, details see 100 | #' . 101 | #' @inheritParams perl 102 | #' @export 103 | #' @rdname trust4 104 | trust4_imgt_annot <- make_command( 105 | "trust4_imgt_annot", 106 | function(species = "Homo_sapien", ..., 107 | ofile = "IMGT+C.fa", odir = getwd(), 108 | perl = NULL) { 109 | assert_string(perl, allow_empty = FALSE, allow_null = TRUE) 110 | Trust4ImgtAnnot$new( 111 | cmd = perl, ..., species = species, ofile = ofile, odir = odir 112 | ) 113 | } 114 | ) 115 | 116 | Trust4ImgtAnnot <- R6Class( 117 | "Trust4ImgtAnnot", 118 | inherit = Perl, 119 | private = list( 120 | setup_help_params = function() { 121 | cli::cli_abort("No help document for ") 122 | }, 123 | setup_command_params = function(species, ofile, odir) { 124 | assert_string(species, allow_empty = FALSE) 125 | opath <- build_opath(odir, ofile, abs = TRUE) 126 | c(shQuote(species), ">", opath) 127 | }, 128 | combine_params = function() { 129 | script <- pkg_extdata("TRUST4", "BuildImgtAnnot.pl") 130 | file_executable(script) 131 | c(script, super$combine_params()) 132 | }, 133 | collect_dots = FALSE 134 | ) 135 | ) 136 | 137 | #' @param imgt_annot Path of IMGT annotation file, created via 138 | #' `trust4_imgt_annot`. 139 | #' @export 140 | #' @rdname trust4 141 | trust4_gene_names <- function(imgt_annot, ofile = "bcr_tcr_gene_name.txt", 142 | odir = getwd()) { 143 | assert_string(imgt_annot, allow_empty = FALSE) 144 | opath <- build_opath(odir, ofile) 145 | lines <- read_lines(imgt_annot) 146 | gene_lines <- grep("^>", lines, value = TRUE, perl = TRUE) 147 | genes <- sub("^>", "", gene_lines, perl = TRUE) 148 | genes <- vapply(strsplit(genes, "*", fixed = TRUE), 149 | `[[`, character(1L), 1L, 150 | USE.NAMES = FALSE 151 | ) 152 | write_lines(genes, opath) 153 | } 154 | -------------------------------------------------------------------------------- /R/import-standalone-pkg.R: -------------------------------------------------------------------------------- 1 | # Standalone file: do not edit by hand 2 | # Source: https://github.com/Yunuuuu/standalone/blob/HEAD/R/standalone-pkg.R 3 | # Generated by: usethis::use_standalone("Yunuuuu/standalone", "pkg") 4 | # ---------------------------------------------------------------------- 5 | # 6 | # --- 7 | # repo: Yunuuuu/standalone 8 | # file: standalone-pkg.R 9 | # last-updated: 2025-03-30 10 | # license: https://unlicense.org 11 | # imports: [utils] 12 | # --- 13 | 14 | # This file contains various helper utilities, including common functions 15 | # used across multiple packages I have developed. Some functions depend on 16 | # other packages that are not listed in Imports, so use them with caution. 17 | 18 | # ## Changelog 19 | # 2025-03-30 20 | # - Add `use_github_release` 21 | # 22 | # 2025-03-12 23 | # - Add `from_namespace` 24 | # 25 | # 2025-03-10: 26 | # - Add `on_exit` 27 | # 28 | # 2025-03-08: 29 | # - Add `pkg_extdata` 30 | # - Add `defer` 31 | # 32 | # 2025-03-04: 33 | # - Add `%||%` 34 | # 35 | # 2025-03-03: 36 | # - Add `rd_collect_family` 37 | # - Add `oxford_and` 38 | # - Add `oxford_or` 39 | # - Add `code_quote` 40 | # - Add `oxford_comma` 41 | # 42 | # 2025-02-26: 43 | # - Add `is_installed` 44 | # - Add `install_pkgs` 45 | # - Add `pkg_nm` 46 | # - Add `pkg_namespace` 47 | # 48 | # nocov start 49 | 50 | `%||%` <- function(x, y) if (is.null(x)) y else x 51 | 52 | is_installed <- local({ 53 | cache <- new.env(parent = emptyenv()) 54 | function(pkg, version = NULL) { 55 | id <- if (is.null(version)) pkg else paste(pkg, version, sep = ":") 56 | out <- cache[[id]] 57 | if (is.null(out)) { 58 | if (is.null(version)) { 59 | out <- requireNamespace(pkg, quietly = TRUE) 60 | } else { 61 | out <- requireNamespace(pkg, quietly = TRUE) && 62 | utils::packageVersion(pkg) >= version 63 | } 64 | assign(id, out, envir = cache, inherits = FALSE) 65 | } 66 | out 67 | } 68 | }) 69 | 70 | install_pkgs <- function(pkgs) { 71 | if (is_installed("pak")) { 72 | getExportedValue("pak", "pkg_install")(pkgs, ask = FALSE) 73 | } else { 74 | utils::install.packages(pkgs) 75 | } 76 | } 77 | 78 | pkg_nm <- function() utils::packageName(environment()) 79 | 80 | pkg_namespace <- function() topenv(environment()) 81 | 82 | pkg_extdata <- function(..., mustWork = TRUE) { 83 | system.file("extdata", ..., package = pkg_nm(), mustWork = mustWork) 84 | } 85 | 86 | ############################################################ 87 | # I’m having trouble connecting to GitHub, and it seems that `gert` does not 88 | # respect the proxy settings in my Git config. To work around this, I modified 89 | # `usethis::use_github_release()` to skip the check that relies on the `gert` 90 | # package. 91 | use_github_release <- function(publish = TRUE) { 92 | usethis_ns <- getNamespace("usethis") 93 | usethis <- function(fun, ...) { 94 | get(x = fun, envir = usethis_ns, inherits = FALSE, ...) 95 | } 96 | usethis("check_is_package")("use_github_release()") 97 | tr <- usethis("target_repo")( 98 | github_get = TRUE, 99 | ok_configs = c("ours", "fork") 100 | ) 101 | usethis("check_can_push")(tr = tr, "to create a release") 102 | dat <- usethis("get_release_data")(tr) 103 | release_name <- paste(dat$Package, dat$Version) 104 | tag_name <- sprintf("v%s", dat$Version) 105 | usethis("kv_line")("Release name", release_name) 106 | usethis("kv_line")("Tag name", tag_name) 107 | usethis("kv_line")("SHA", dat$SHA) 108 | usethis("check_github_has_SHA")(SHA = dat$SHA, tr = tr) 109 | on_cran <- !is.null(usethis("cran_version")()) 110 | news <- usethis("get_release_news")( 111 | SHA = dat$SHA, tr = tr, on_cran = on_cran 112 | ) 113 | gh <- usethis("gh_tr")(tr) 114 | usethis("ui_bullets")("Publishing {tag_name} release to GitHub") 115 | release <- gh( # nolint 116 | "POST /repos/{owner}/{repo}/releases", 117 | name = release_name, 118 | tag_name = tag_name, 119 | target_commitish = dat$SHA, 120 | body = news, 121 | draft = !publish 122 | ) 123 | usethis("ui_bullets")("Release at {.url {release$html_url}}") 124 | if (!is.null(dat$file)) { 125 | usethis("ui_bullets")("Deleting {.path {dat$file}}") 126 | getExportedValue("fs", "file_delete")(dat$file) 127 | } 128 | invisible() 129 | } 130 | 131 | ############################################################ 132 | #' @param ... The last argument must be a string representing the variable name. 133 | #' For all others, provide a list of formulas where: 134 | #' - The left-hand side should return a single boolean value and may reference a 135 | #' variable named `"version"`, which represents the current package version. 136 | #' - The right-hand side should be a string specifying the variable name. 137 | #' @examples 138 | #' from_namespace( 139 | #' "ggplot2", 140 | #' version < "3.5.1" ~ "complete_theme", 141 | #' "plot_theme" 142 | #' ) 143 | #' @noRd 144 | from_namespace <- local({ 145 | namespace <- NULL 146 | function(package, ..., mode = "any") { 147 | if (is.null(namespace)) { 148 | namespace <<- getNamespace(package) 149 | } 150 | envir <- parent.frame() 151 | dots <- as.list(substitute(...())) 152 | # The last one should be a string 153 | name <- eval(.subset2(dots, length(dots)), envir = envir) 154 | if (length(dots) > 1L) { 155 | version_envir <- new.env(parent = envir) 156 | version_envir$version <- utils::packageVersion(package) 157 | for (dot in dots[-length(dots)]) { 158 | # evaluate in the version environemnt 159 | if (eval(.subset2(dot, 2L), envir = version_envir)) { 160 | name <- eval(.subset2(dot, 3L), envir = envir) 161 | break 162 | } 163 | } 164 | } 165 | get(name, envir = namespace, inherits = FALSE, mode = mode) 166 | } 167 | }) 168 | 169 | # Need `rlang` package, can support `quosure` 170 | on_exit <- function(expr, envir = parent.frame(), after = TRUE, add = TRUE) { 171 | expr <- getExportedValue("rlang", "enquo")(expr) 172 | defer( 173 | getExportedValue("rlang", "eval_tidy")(expr), 174 | envir = envir, 175 | after = after, 176 | add 177 | ) 178 | } 179 | 180 | # Just like `withr::defer()`, don't depend on `rlang` package 181 | defer <- function(expr, envir = parent.frame(), after = TRUE, add = TRUE) { 182 | thunk <- as.call(list(function() expr)) 183 | do.call(base::on.exit, list(thunk, add = add, after = after), envir = envir) 184 | } 185 | 186 | # utils function to collapse characters --------------------------- 187 | oxford_and <- function(x, code = TRUE, quote = TRUE, sep = ", ") { 188 | oxford_comma(code_quote(x, code, quote), sep = sep, final = "and") 189 | } 190 | 191 | oxford_or <- function(x, code = TRUE, quote = TRUE, sep = ", ") { 192 | oxford_comma(code_quote(x, code, quote), sep = sep, final = "or") 193 | } 194 | 195 | code_quote <- function(x, code = TRUE, quote = TRUE) { 196 | if (quote) x <- paste0("\"", x, "\"") 197 | if (code) x <- paste0("`", x, "`") 198 | x 199 | } 200 | 201 | oxford_comma <- function(x, sep = ", ", final = "and") { 202 | n <- length(x) 203 | 204 | if (n < 2L) return(x) # styler: off 205 | 206 | head <- x[seq_len(n - 1L)] 207 | last <- x[n] 208 | 209 | head <- paste(head, collapse = sep) 210 | 211 | # Write a or b. But a, b, or c. 212 | if (n > 2L) { 213 | paste0(head, sep, final, " ", last) 214 | } else { 215 | paste0(head, " ", final, " ", last) 216 | } 217 | } 218 | 219 | # Need `roxygen2` package 220 | #' @description add `@eval rd_collect_family("myfamily")` to the functions in 221 | #' your package. This will automatically generate a section listing all 222 | #' functions tagged with `@family myfamily`. 223 | #' @param family A string specifying the family name. 224 | #' @param section_title A string specifying the section title. 225 | #' @param code_style A boolean indicating whether to apply code formatting 226 | #' to function names. 227 | #' @noRd 228 | rd_collect_family <- function( 229 | family, 230 | section_title = paste(family, "family"), 231 | code_style = TRUE) { 232 | # get blocks objects from the roxygenize function 233 | blocks <- NULL 234 | pos <- sys.nframe() 235 | while (pos > 0L) { 236 | if (!is.null(call <- sys.call(-pos))) { 237 | fn <- eval(.subset2(call, 1L), sys.frame(-(pos + 1L))) 238 | env <- sys.frame(-pos) 239 | if ( 240 | identical(fn, getExportedValue("roxygen2", "roxygenize")) && 241 | exists("blocks", envir = env, inherits = FALSE) 242 | ) { 243 | blocks <- get("blocks", envir = env, inherits = FALSE) 244 | break 245 | } 246 | } 247 | pos <- pos - 1L 248 | } 249 | 250 | # identify the blocks with family of the same tag specified in `family` 251 | blocks <- blocks[ 252 | vapply( 253 | blocks, 254 | function(block) { 255 | getExportedValue("roxygen2", "block_has_tags")( 256 | block, 257 | "family" 258 | ) && 259 | identical( 260 | getExportedValue("roxygen2", "block_get_tag_value")( 261 | block, 262 | "family" 263 | ), 264 | family 265 | ) 266 | }, 267 | logical(1L), 268 | USE.NAMES = FALSE 269 | ) 270 | ] 271 | if (length(blocks) == 0L) return(character()) # styler: off 272 | 273 | # extracted the function name 274 | funs <- vapply( 275 | blocks, 276 | function(block) { 277 | as.character(.subset2(block$call, 2L)) 278 | }, 279 | character(1L), 280 | USE.NAMES = FALSE 281 | ) 282 | if (code_style) { 283 | items <- sprintf("\\code{\\link[=%s]{%s()}}", funs, funs) 284 | } else { 285 | items <- sprintf("\\link[=%s]{%s()}", funs, funs) 286 | } 287 | c( 288 | sprintf("@section %s:", section_title), 289 | "\\itemize{", 290 | sprintf(" \\item %s", items), 291 | "}" 292 | ) 293 | } 294 | 295 | # nocov end 296 | -------------------------------------------------------------------------------- /R/import-standalone-stringr.R: -------------------------------------------------------------------------------- 1 | # Standalone file: do not edit by hand 2 | # Source: 3 | # ---------------------------------------------------------------------- 4 | # 5 | # --- 6 | # repo: Yunuuuu/standalone 7 | # file: standalone-stringr.R 8 | # last-updated: 2024-11-11 9 | # license: https://unlicense.org 10 | # --- 11 | 12 | # when developing R package, instead of depending on `stringr` 13 | # we prefer use the base function 14 | # 15 | # Note: 16 | # 1. these functions won't check arguments 17 | # 2. Please use `perl`, `fixed` argument to control the pattern instead of using 18 | # regex(), fixed() function. 19 | 20 | # ## Changelog 21 | # 2024-11-11: 22 | # First release 23 | # 24 | # nocov start 25 | 26 | str_which <- function(string, pattern, ...) { 27 | grep(pattern = pattern, x = string, ..., value = FALSE) 28 | } 29 | 30 | str_c <- function(..., sep = "", collapse = NULL) { 31 | na_values <- rowSums(is.na(do.call("cbind", list(...)))) > 0L 32 | if (!is.null(collapse) && any(na_values)) { 33 | return(NA_character_) 34 | } 35 | out <- paste(..., sep = sep, collapse = collapse) 36 | if (any(na_values)) out[na_values] <- NA_character_ 37 | out 38 | } 39 | 40 | str_detect <- function(string, pattern, ...) { 41 | grepl(pattern = pattern, x = string, ...) 42 | } 43 | 44 | str_subset <- function(string, pattern, ...) { 45 | grep(pattern = pattern, x = string, ..., value = TRUE) 46 | } 47 | 48 | str_replace <- function(string, pattern, replacement, ...) { 49 | sub(pattern = pattern, replacement = replacement, x = string, ...) 50 | } 51 | 52 | str_remove <- function(string, pattern, ...) { 53 | sub(pattern = pattern, replacement = "", x = string, ...) 54 | } 55 | 56 | str_replace_all <- function(string, pattern, replacement, ...) { 57 | gsub(pattern = pattern, replacement = replacement, x = string, ...) 58 | } 59 | 60 | str_remove_all <- function(string, pattern, ...) { 61 | gsub(pattern = pattern, replacement = "", x = string, ...) 62 | } 63 | 64 | str_extract <- function(string, pattern, ...) { 65 | matches <- regexpr(pattern, string, ...) 66 | start <- as.vector(matches) 67 | end <- start + attr(matches, "match.length") - 1L 68 | start[start == -1L] <- NA_integer_ 69 | substr(string, start, end) 70 | } 71 | 72 | str_extract_all <- function(string, pattern, ...) { 73 | regmatches( 74 | string, 75 | m = gregexpr(pattern = pattern, text = string, ...) 76 | ) 77 | } 78 | 79 | # split string based on pattern, Only split once, Return a list of character, 80 | # the length of every element is two 81 | str_split_fixed <- function(string, pattern, ...) { 82 | regmatches( 83 | string, 84 | regexpr(pattern = pattern, text = string, ...), 85 | invert = TRUE 86 | ) 87 | } 88 | 89 | str_split <- function(string, pattern, ...) { 90 | strsplit(x = string, split = pattern, ...) 91 | } 92 | 93 | str_match <- function(string, pattern, ...) { 94 | out <- regmatches( 95 | string, 96 | regexec(pattern = pattern, text = string, ...), 97 | invert = FALSE 98 | ) 99 | out <- lapply(out, function(x) { 100 | if (!length(x)) "" else x 101 | }) 102 | out <- do.call("rbind", out) 103 | out[out == ""] <- NA_character_ 104 | out 105 | } 106 | 107 | str_match_all <- function(string, pattern, ...) { 108 | regmatches( 109 | string, 110 | gregexec(pattern = pattern, text = string, ...), 111 | invert = FALSE 112 | ) 113 | } 114 | 115 | str_count <- function(string, pattern, ...) { 116 | # This information can be gleaned from gregexpr() in base A list of the same 117 | # length as text each element of which is an integer vector giving all 118 | # starting position of the match or −1 if there is none. 119 | loc <- gregexpr(pattern = pattern, text = string, ...) 120 | vapply(loc, function(x) sum(x > 0L), integer(1L), USE.NAMES = FALSE) 121 | } 122 | 123 | str_trim <- function(string, which = "both") { 124 | trimws(string, which = which, whitespace = "[\\h\\v]") 125 | } 126 | 127 | # nocov end 128 | -------------------------------------------------------------------------------- /R/utils-Rd.R: -------------------------------------------------------------------------------- 1 | rd_cmd <- function(cmd) { 2 | sprintf("A string of path to `%s` command", cmd) 3 | } 4 | 5 | rd_dots <- function(cmd, details = TRUE) { 6 | doc <- sprintf( 7 | paste( 8 | "<[dynamic dots][rlang::dyn-dots]>", 9 | "Additional arguments passed to `%s` command.", 10 | "Empty arguments are automatically trimmed.", 11 | "If a single argument, such as a file path, contains spaces,", 12 | "it must be quoted, for example using [`shQuote()`]" 13 | ), 14 | cmd 15 | ) 16 | if (details) { 17 | doc <- sprintf("%s. Details see: %s", doc, rd_help(cmd)) 18 | } 19 | doc 20 | } 21 | 22 | rd_help <- function(cmd) sprintf("`cmd_help(%s())`", cmd) 23 | 24 | rd_seealso <- function() { 25 | paste( 26 | "- [`cmd_wd()`]/[`cmd_envvar()`]/[`cmd_envpath()`]/[`cmd_condaenv()`]", 27 | "- [`cmd_on_start()`]/[`cmd_on_exit()`]", 28 | "- [`cmd_on_succeed()`]/[`cmd_on_fail()`]", 29 | "- [`cmd_parallel()`]", 30 | sep = "\n" 31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /R/utils-file.R: -------------------------------------------------------------------------------- 1 | blit_dir <- function(which) { 2 | dir_create(tools::R_user_dir(pkg_nm(), which), recursive = TRUE) 3 | } 4 | 5 | data_dir <- function() blit_dir("data") 6 | 7 | cache_dir <- function() blit_dir("cache") 8 | 9 | config_dir <- function() blit_dir("config") 10 | 11 | path_ext_remove <- function(path) { 12 | sub("\\.[[:alnum:]]*$", "", path, perl = TRUE) 13 | } 14 | 15 | path_ext_set <- function(path, ext) { 16 | if (!is.null(ext) && nzchar(ext)) { 17 | path <- paste(path_ext_remove(path), ext, sep = ".") 18 | } 19 | path 20 | } 21 | 22 | path_ext <- function(path) { 23 | matches <- regexpr("\\.([[:alnum:]]+)$", path, perl = TRUE) 24 | start <- as.vector(matches) 25 | end <- start + attr(matches, "match.length") - 1L 26 | ifelse(start == -1L, "", substr(path, start + 1L, end)) 27 | } 28 | 29 | path_trim <- function(path) { 30 | # remove trailing backslash or slash 31 | sub("(\\\\+|/+)$", "", path, perl = TRUE) 32 | } 33 | 34 | path_equal <- function(path1, path2) { 35 | normalizePath(path1, "/", FALSE) == normalizePath(path2, "/", FALSE) 36 | } 37 | 38 | file_executable <- function(file) { 39 | if (file.access(file, mode = 1L)) { 40 | if (!Sys.chmod(file, "755")) { 41 | cli::cli_abort("{.path {file}} is not executable") 42 | } 43 | } 44 | } 45 | 46 | file_path <- function(..., ext = NULL) { 47 | path <- file.path(..., fsep = "/") 48 | if (!is.null(ext)) path <- paste(path, ext, sep = ".") 49 | path 50 | } 51 | 52 | file_delete <- function(path) { 53 | if (file.exists(path) && unlink(x = path, force = TRUE)) { 54 | cli::cli_abort("Canno remove {.path {path}}") 55 | } 56 | invisible(path) 57 | } 58 | 59 | dir_create <- function(path, ...) { 60 | if (!dir.exists(path) && 61 | !dir.create(path = path, showWarnings = FALSE, ...)) { 62 | cli::cli_abort("Cannot create directory {.path {path}}") 63 | } 64 | invisible(path) 65 | } 66 | 67 | dir_delete <- function(path) { 68 | if (dir.exists(path) && unlink(x = path, recursive = TRUE, force = TRUE)) { 69 | cli::cli_abort("Canno remove {.path {path}}") 70 | } 71 | invisible(path) 72 | } 73 | 74 | #' Will always add the basename of file into the exdir 75 | #' @noRd 76 | unzip2 <- function(path, exdir, ..., basename = TRUE, overwrite = TRUE) { 77 | dir_create(exdir) 78 | if (basename) { 79 | exdir <- dir_create(file.path(exdir, base::basename(path))) 80 | } 81 | if (is.null(utils::unzip(path, exdir = exdir, ..., overwrite = overwrite))) { 82 | cli::cli_abort("Cannot unzip {.path {path}}") 83 | } 84 | exdir 85 | } 86 | 87 | download_file <- function(url, path, ...) { 88 | if (file.exists(path)) { 89 | cli::cli_inform("Using cached file: {.path {path}}") 90 | return(path) 91 | } 92 | cli::cli_inform("Downloading from {.path {url}}") 93 | status <- utils::download.file(url = url, destfile = path, ...) 94 | if (status > 0L) { 95 | cli::cli_abort("Cannot download {.path {url}} [status = {status}]") 96 | } 97 | invisible(path) 98 | } 99 | 100 | read_lines <- function(path, n = Inf) { 101 | if (is_installed("data.table")) { 102 | if (n < 0L) n <- Inf 103 | getExportedValue("data.table", "fread")( 104 | file = path, sep = "", header = FALSE, 105 | colClasses = "character", 106 | showProgress = FALSE, 107 | nrows = n 108 | )[[1L]] 109 | } else if (is_installed("brio")) { 110 | if (is.infinite(n) || n < 0L) n <- -1L 111 | out <- getExportedValue("brio", "read_lines")(path, n = n) 112 | out[out == "NA"] <- NA_character_ 113 | out 114 | } else if (is_installed("vroom")) { 115 | if (n < 0L) n <- Inf 116 | getExportedValue("vroom", "vroom_lines")(path, n_max = n, na = "NA") 117 | } else if (is_installed("readr")) { 118 | if (n < 0L) n <- Inf 119 | getExportedValue("readr", "read_lines")(path, n_max = n, na = "NA") 120 | } else { 121 | if (is.infinite(n) || n < 0L) n <- -1L 122 | out <- readLines(path, n = n, warn = FALSE) 123 | out[out == "NA"] <- NA_character_ 124 | out 125 | } 126 | } 127 | 128 | # To write a file with windows line endings use write_lines(eol = "\r\n") 129 | write_lines <- function(text, path, eol = if (.Platform$OS.type == "windows") { 130 | "\r\n" 131 | } else { 132 | "\n" 133 | }) { 134 | if (is_installed("data.table")) { 135 | getExportedValue("data.table", "fwrite")( 136 | x = list(text), 137 | file = path, 138 | append = FALSE, 139 | quote = FALSE, 140 | eol = eol, 141 | na = "NA", 142 | col.names = FALSE, 143 | logical01 = FALSE, 144 | showProgress = FALSE, 145 | verbose = FALSE, 146 | compress = "auto" 147 | ) 148 | } else if (is_installed("brio")) { 149 | getExportedValue("brio", "write_lines")(text, path, eol = eol) 150 | } else if (is_installed("vroom")) { 151 | getExportedValue("vroom", "vroom_write_lines")(text, path, sep = eol) 152 | } else if (is_installed("readr")) { 153 | getExportedValue("readr", "write_lines")(text, path, sep = eol) 154 | } else { 155 | writeLines(text, path, sep = eol) 156 | } 157 | invisible(text) 158 | } 159 | 160 | write_table <- function(data, path, sep = "\t") { 161 | if (is_installed("data.table")) { 162 | getExportedValue("data.table", "fwrite")(data, file = path, sep = sep) 163 | } else if (is_installed("vroom")) { 164 | getExportedValue("vroom", "vroom_write")(data, file = path, delim = sep) 165 | } else if (is_installed("readr")) { 166 | getExportedValue("readr", "write_delim")(data, file = path, delim = sep) 167 | } else { 168 | utils::write.table(data, file = path, sep = sep, row.names = FALSE) 169 | } 170 | } 171 | 172 | # Can handle compressed files 173 | read_lines2 <- function(path, n = Inf) { 174 | if (is_gzip_suffix(path) || is_gzip_signature(path)) { 175 | path <- gzfile(path, open = "r") 176 | on.exit(close(path)) 177 | } else if (is_bz2_suffix(path) || is_bz2_signature(path)) { 178 | path <- bzfile(path, open = "r") 179 | on.exit(close(path)) 180 | } else if (is_xz_suffix(path)) { 181 | path <- xzfile(path, open = "r") 182 | on.exit(close(path)) 183 | } 184 | if (is.infinite(n) || n < 0L) n <- -1L 185 | readLines(path, n = n) 186 | } 187 | 188 | # https://github.com/Rdatatable/data.table/blob/15c127e99f8d6aab599c590d4aec346a850f1334/R/fread.R#L90 189 | is_tar <- function(file) endsWith(file, ".tar") 190 | 191 | is_gzip_suffix <- function(file, tar = FALSE) { 192 | if (endsWith(file, ".z") || endsWith(file, ".gz")) { 193 | return(TRUE) 194 | } else if (tar && (endsWith(file, ".tgz") || endsWith(file, ".taz"))) { 195 | return(TRUE) 196 | } 197 | FALSE 198 | } 199 | 200 | is_gzip_signature <- function(file, file_signature = NULL) { 201 | match_file_signature(file, file_signature, as.raw(c(0x1F, 0x8B))) 202 | } 203 | 204 | is_bz2_suffix <- function(file, tar = FALSE) { 205 | if (endsWith(file, ".bz2") || endsWith(file, ".bz")) { 206 | return(TRUE) 207 | } else if (tar && (endsWith(file, ".tbz2") || endsWith(file, ".tbz"))) { 208 | return(TRUE) 209 | } 210 | FALSE 211 | } 212 | 213 | is_bz2_signature <- function(file, file_signature = NULL) { 214 | match_file_signature(file, file_signature, as.raw(c(0x42, 0x5A, 0x68))) 215 | } 216 | 217 | is_xz_suffix <- function(file, tar = FALSE) { 218 | if (endsWith(file, ".xz") || endsWith(file, ".lzma")) { 219 | return(TRUE) 220 | } else if (tar && (endsWith(file, ".txz") || endsWith(file, ".tlz"))) { 221 | return(TRUE) 222 | } 223 | FALSE 224 | } 225 | 226 | is_zip <- function(file, file_signature = NULL) { 227 | endsWith(file, ".zip") || 228 | match_file_signature(file, file_signature, charToRaw("PK\x03\x04")) 229 | } 230 | 231 | match_file_signature <- function(file, file_signature, match) { 232 | n <- length(match) 233 | file_signature <- file_signature %||% readBin(file, raw(), n) 234 | identical(file_signature[seq_len(n)], match) 235 | } 236 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | `%||%` <- function(x, y) if (is.null(x)) y else x 2 | 3 | is_scalar <- function(x) { 4 | length(x) == 1L 5 | } 6 | 7 | is_scalar_numeric <- function(x) { 8 | is_scalar(x) && is.numeric(x) 9 | } 10 | 11 | is_number <- function(x) is_scalar_numeric(x) && !is.na(x) 12 | 13 | fclass <- function(x) .subset(class(x), 1L) 14 | 15 | switch_os <- function(windows, osx, linux, call = rlang::caller_call()) { 16 | if (is_windows()) { 17 | windows 18 | } else { 19 | sysname <- Sys.info()["sysname"] 20 | if (sysname == "Darwin") { 21 | osx 22 | } else if (tolower(sysname) == "linux") { 23 | linux 24 | } else { 25 | cli::cli_abort( 26 | "unsupported platform {.field {sysname}}", 27 | call = call 28 | ) 29 | } 30 | } 31 | } 32 | 33 | is_windows <- function() identical(.Platform$OS.type, "windows") 34 | 35 | is_osx <- function() Sys.info()["sysname"] == "Darwin" 36 | 37 | is_linux <- function() tolower(Sys.info()["sysname"]) == "linux" 38 | -------------------------------------------------------------------------------- /blit.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | Encoding: UTF-8 9 | 10 | AutoAppendNewline: Yes 11 | StripTrailingWhitespace: Yes 12 | LineEndingConversion: Posix 13 | 14 | BuildType: Package 15 | PackageUseDevtools: Yes 16 | PackageInstallArgs: --no-multiarch --with-keep.source 17 | PackageRoxygenize: rd,collate,namespace 18 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | 16 | codecov: 17 | token: 22b021db-1f68-4e13-bab4-a52a9aa4197e 18 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | This release is a minor update that includes lots of new features (some will break the old behaviour) and bug fix. 2 | 3 | ## R CMD check results 4 | 5 | 0 errors | 0 warnings | 1 note 6 | 7 | ## revdepcheck results 8 | 9 | We checked 1 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 10 | 11 | * We saw 0 new problems 12 | * We failed to check 0 packages 13 | -------------------------------------------------------------------------------- /data-raw/DATASET.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `DATASET` dataset goes here 2 | 3 | # Deer icons created by amoghdesign - Flaticon 4 | # 5 | 6 | hexSticker::sticker( 7 | "data-raw/christmas.png", 8 | package = "blit", 9 | p_size = 20, s_x = 0.95, s_y = 0.83, s_width = .6, p_y = 1.5, 10 | h_fill = "#fceeb9", h_color = "#5f7c4b", p_color = "#5f7c4b", 11 | spotlight = TRUE, l_x = 0.8, l_y = 1, l_alpha = 0.1, 12 | url = "https://github.com/WangLabCSU/blit", u_size = 4, u_color = "#aaa", 13 | filename = "man/figures/logo.png" 14 | ) 15 | -------------------------------------------------------------------------------- /data-raw/christmas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WangLabCSU/blit/576fea4b23e411523e0109d417c5e17abfb0078e/data-raw/christmas.png -------------------------------------------------------------------------------- /inst/extdata/KrakenTools/combine_mpa.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #################################################################### 3 | #combine_mpa.py converts multiple outputs from kreport2mpa.py 4 | #Copyright (C) 2020 Jennifer Lu, jennifer.lu717@gmail.com 5 | 6 | #This file is part of KrakenTools. 7 | #KrakenTools is free software; you can redistribute it and/or modify 8 | #it under the terms of the GNU General Public License as published by 9 | #the Free Software Foundation; either version 3 of the license, or 10 | #(at your option) any later version. 11 | 12 | #This program is distributed in the hope that it will be useful, 13 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | #GNU General Public License for more details. 16 | 17 | #You should have received a copy of the GNU General Public License 18 | #along with this program; if not, see . 19 | 20 | #################################################################### 21 | #Jennifer Lu, jlu26@jhmi.edu 22 | #Updated: 07/12/2020 23 | # 24 | #This program reads multiple files in the 25 | #an mpa-format (MetaPhlAn) style report (as output from kreport2mpa.py). 26 | #Each line represents a possible taxon classification. The first column is lists the 27 | #domain, kingdom, phyla, etc, leading up to each taxon. 28 | #The levels are separated by the | delimiter, with the type of 29 | #level specified before each name with a single letter and underscore 30 | #(d_ for domain, k_ for kingdom, etc). 31 | #The second column is the number of reads classified within 32 | #that taxon's subtree. 33 | # 34 | #Input files: 35 | # - MetaPhlAn format (mpa-format) files with two columns 36 | # - All files must be generated from the same database, with the same 37 | # options from kreport2krona.py or errors may occur 38 | # 39 | #Input Parameters to Specify [OPTIONAL]: 40 | # - header_line = prints a header line in mpa-report 41 | # [Default: no header] 42 | # - intermediate-ranks = includes non-traditional taxon levels 43 | # (traditional levels: domain, kingdom, phylum, class, order, 44 | # family, genus, species) 45 | # [Default: no intermediate ranks] 46 | #Output file format (tab-delimited) 47 | # - Taxonomy tree levels |-delimited, with level type [d,k,p,c,o,f,g,s,x] 48 | # - Number of reads within subtree of the specified level 49 | # 50 | #Methods 51 | # - main 52 | # 53 | import os, sys, argparse 54 | 55 | #Main method 56 | def main(): 57 | #Parse arguments 58 | parser = argparse.ArgumentParser() 59 | parser.add_argument('-i', '--input', required=True, 60 | nargs='+', dest='in_files', 61 | help='Input files for this program (files generated by kreport2mpa.py)') 62 | parser.add_argument('-o', '--output', required=True, 63 | dest='o_file', help='Single mpa-report file name') 64 | args=parser.parse_args() 65 | 66 | #Process each file 67 | samples = {} #Map number to name 68 | sample_count = 0 69 | values = {} #Map taxon tree to sample to number 70 | parent2child = {} 71 | toparse = [] 72 | sys.stdout.write(" Number of files to parse: %i\n" % len(args.in_files)) 73 | for in_file in args.in_files: 74 | i_file = open(in_file,'r') 75 | sample_count += 1 76 | sample_name = "Sample #" + str(sample_count) 77 | for line in i_file: 78 | #Check for header line 79 | if line[0] == "#": 80 | sample_name = line.strip().split('\t')[-1] 81 | continue 82 | #Otherwise 83 | [classification, val] = line.strip().split('\t') 84 | #Check for parents 85 | split_vals = classification.split("|") 86 | curr_parent = '' 87 | for i in range(0,len(split_vals)): 88 | test_val = "|".join(split_vals[0:i]) 89 | if test_val in values: 90 | curr_parent = test_val 91 | #No parent 92 | if curr_parent == '': 93 | if classification not in values: 94 | toparse.append(classification) 95 | #Most specific parent found 96 | if curr_parent != '': 97 | if curr_parent not in parent2child: 98 | parent2child[curr_parent] = [] 99 | if classification not in parent2child[curr_parent]: 100 | parent2child[curr_parent].append(classification) 101 | #Save classification to value map 102 | if classification not in values: 103 | values[classification] = {} 104 | values[classification][sample_count] = val 105 | #Save sample name 106 | samples[sample_count] = sample_name 107 | 108 | sys.stdout.write(" Number of classifications to write: %i\n" % len(values)) 109 | sys.stdout.write("\t%i classifications printed" % 0) 110 | #Write header 111 | o_file = open(args.o_file, 'w') 112 | o_file.write("#Classification") 113 | for i in range(1, sample_count+1): 114 | o_file.write("\t" + samples[i]) 115 | o_file.write("\n") 116 | 117 | #Write each line 118 | parsed = {} 119 | count_c = 0 120 | while len(toparse) > 0: 121 | curr_c = toparse.pop(0) 122 | #Add all children to stack 123 | if curr_c in parent2child: 124 | for child in parent2child[curr_c]: 125 | toparse.insert(0, child) 126 | #For the current classification, print per sample 127 | o_file.write(curr_c) 128 | for i in range(1,sample_count + 1): 129 | if i in values[curr_c]: 130 | o_file.write("\t" + values[curr_c][i]) 131 | else: 132 | o_file.write("\t0") 133 | o_file.write("\n") 134 | count_c += 1 135 | sys.stdout.write("\r\t%i classifications printed" % count_c) 136 | sys.stdout.flush() 137 | o_file.close() 138 | sys.stdout.write("\r\t%i classifications printed\n" % count_c) 139 | sys.stdout.flush() 140 | 141 | if __name__ == "__main__": 142 | main() 143 | -------------------------------------------------------------------------------- /inst/extdata/KrakenTools/filter_bracken_out.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ################################################################# 3 | #filter_bracken_out.py allows users to filter Bracken output files 4 | #Copyright (C) 2019-2020 Jennifer Lu, jennifer.lu717@gmail.com 5 | # 6 | #This file is part of Kraken-Tools. 7 | #Kraken-Tools is free software; you can redistribute it and/or modify 8 | #it under the terms of the GNU General Public License as published by 9 | #the Free Software Foundation; either version 3 of the license, or 10 | #(at your option) any later version. 11 | # 12 | #This program is distributed in the hope that it will be useful, 13 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | #GNU General Public License for more details. 16 | # 17 | #You should have received a copy of the GNU General Public License 18 | #along with this program; if not, see . 19 | # 20 | #################################################################### 21 | #Jennifer Lu, jlu26@jhmi.edu 22 | #Updated: 07/25/2019 23 | # 24 | #This program reads in a Bracken output file and user-provided taxids 25 | #to either extract or exclude those taxids. Total fractions will be 26 | #recalculated for read counts for the remaining taxids 27 | # 28 | #Parameters: 29 | # -h, --help...............show help message 30 | # -i X, --input-file X.....input bracken output filename 31 | # -o X, --output X.........output bracken-style output filename 32 | # --include X..............include the specified taxids 33 | # --exclude X..............exclude the specified taxids 34 | #Input/Output file format (tab-delimited) 35 | # - name 36 | # - taxonomy ID 37 | # - level ID (S = species, G = genus, etc) 38 | # - Kraken assigned reads 39 | # - added reads with abundance reestimation 40 | # - total reads after abundance reestimation 41 | # - fraction of total reads 42 | ####################################################################### 43 | import os, sys, argparse 44 | def main(): 45 | parser = argparse.ArgumentParser() 46 | parser.add_argument('-i', '--input-file', dest='in_file', required=True, 47 | help='Input bracken OUTPUT file. [NOT the report file]') 48 | parser.add_argument('-o','--output','--output-file', dest='out_file', required=True, 49 | help='Output bracken OUTPUT file.') 50 | parser.add_argument('--include', dest='t_include',nargs='*', type=str, required=False, 51 | help='List of taxonomy IDs to include in output [space-delimited] - default=All', default=[]) 52 | parser.add_argument('--exclude', dest='t_exclude',nargs='*', type=str, required=False, 53 | help='List of taxonomy IDs to exclude in output [space-delimited] - default=None',default=[]) 54 | args = parser.parse_args() 55 | 56 | #CHECK#1: either taxonomy IDs are included or excluded 57 | if len(args.t_include) == 0 and len(args.t_exclude) == 0: 58 | sys.stderr.write("User must include at least one taxonomy ID to include or exclude\n") 59 | sys.stderr.write("Please specify either --include or --exclude\n") 60 | sys.exit(1) 61 | #CHECK#2: if both are specified, make sure none exists in both lists 62 | if len(args.t_include) > 0 and len(args.t_exclude) > 0: 63 | for val in args.t_include: 64 | if val in args.t_exclude: 65 | sys.stderr.write("%s cannot be in include AND exclude lists\n" % val) 66 | sys.exit(1) 67 | include = False 68 | exclude = False 69 | if len(args.t_include) > 0: 70 | include = True 71 | if len(args.t_exclude) > 0: 72 | exclude = True 73 | #Process input file 74 | sys.stdout.write(">> Reading Bracken output file: %s\n" % args.in_file) 75 | i_file = open(args.in_file,'r') 76 | tot_reads = 0 77 | excl_reads = 0 78 | first = True 79 | first_line = "" 80 | save_taxid2all = {} 81 | save_taxid2reads = {} 82 | for line in i_file: 83 | line = line.strip() 84 | #Check format 85 | if first: 86 | if line.split("\t") != ["name","taxonomy_id","taxonomy_lvl","kraken_assigned_reads","added_reads","new_est_reads","fraction_total_reads"]: 87 | sys.stderr.write("\t%s not in Bracken output format\n" % args.in_file) 88 | sys.exit(1) 89 | first = False 90 | firstline = line + "\n" 91 | continue 92 | #Get reads 93 | l_vals = line.split("\t") 94 | if include: 95 | if l_vals[1] in args.t_include: 96 | save_taxid2all[l_vals[1]] = l_vals[0:6] 97 | save_taxid2reads[l_vals[1]] = int(l_vals[5]) 98 | tot_reads += int(l_vals[5]) 99 | else: 100 | excl_reads += int(l_vals[5]) 101 | elif exclude: 102 | if l_vals[1] not in args.t_exclude: 103 | save_taxid2all[l_vals[1]] = l_vals[0:6] 104 | save_taxid2reads[l_vals[1]] = int(l_vals[5]) 105 | tot_reads += int(l_vals[5]) 106 | else: 107 | excl_reads += int(l_vals[5]) 108 | sys.stdout.write("\t%i reads remaining (%i reads excluded)\n" % (tot_reads, excl_reads)) 109 | i_file.close() 110 | 111 | #Write output file with updated fractions 112 | sys.stdout.write(">> Writing filtered Bracken output to %s\n" % args.out_file) 113 | o_file = open(args.out_file,'w') 114 | o_file.write(firstline) 115 | for [taxid, reads] in sorted(save_taxid2reads.items(), key=lambda kv: kv[1], reverse=True): 116 | new_fraction = float(reads) / float(tot_reads) 117 | for val in save_taxid2all[taxid]: 118 | o_file.write(val + "\t") 119 | o_file.write("%0.10f\n" % new_fraction) 120 | o_file.close() 121 | 122 | ####################################################################### 123 | if __name__ == "__main__": 124 | main() 125 | #######################END OF PROGRAM################################## 126 | -------------------------------------------------------------------------------- /inst/extdata/KrakenTools/fix_unmapped.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #################################################################### 3 | #fix_unmapped.py analyzes a text file of accession IDs and maps them 4 | #to their respective taxonomy IDs given accession2taxid files. 5 | #Copyright (C) 2020 Jennifer Lu, jennifer.lu717@gmail.com 6 | # 7 | #This file is part of KrakenTools 8 | #KrakenTools is free software; you can redistribute it and/or modify 9 | #it under the terms of the GNU General Public License as published by 10 | #the Free Software Foundation; either version 3 of the license, or 11 | #(at your option) any later version. 12 | # 13 | #This program is distributed in the hope that it will be useful, 14 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | #GNU General Public License for more details. 17 | # 18 | #You should have received a copy of the GNU General Public License 19 | #along with this program; if not, see . 20 | # 21 | #################################################################### 22 | #Jennifer Lu, jlu26@jhmi.edu 23 | #Updated: 06/13/2019 24 | # 25 | #This program takes in a text file of accession IDs and maps them 26 | #to their respective taxonomy IDs given accession2taxid files. 27 | # 28 | #Parameters: 29 | # -h, --help......................show help message 30 | # -i X, --input X, --input_file X.....input file with accessions 31 | # --accession2taxid X.........list all accession2taxid files 32 | # :: list any number of files separated by spaces 33 | # :: files can be gzipped (with extension *.gz) or not 34 | # -o X, --output X, --output_file X...output file with accession/taxid mapping 35 | # :: output format: two tab-delimited columns, no header 36 | #################################################################### 37 | import os, sys, argparse 38 | import gzip 39 | 40 | def main(): 41 | parser = argparse.ArgumentParser() 42 | parser.add_argument('-i','--input','--input_file', 43 | type=str, dest='in_file', required=True, 44 | help='Input file containing accession IDs to map. \ 45 | Multi-column files accepted. Only accessions in \ 46 | the first column will be mapped.') 47 | parser.add_argument('--accession2taxid', dest='ref_files', type=str, required=True, 48 | nargs='+', help='Accession2taxid reference mappings to search. \ 49 | NCBI accession2taxid format required: 4 columns with accessions \ 50 | in column 1 and taxonomy IDs in column 3.') 51 | parser.add_argument('-o','--output','--output_file', 52 | type=str, dest='out_file', required=True, 53 | help='Output file with 2 tab-delimited columns for accessions and taxids') 54 | parser.add_argument('-r','--remaining',required=False, 55 | default='still_unmapped.txt',dest='rem_file', 56 | help='Name of text file containing non-found accessions from input file') 57 | args = parser.parse_args() 58 | 59 | #STEP 1: READ IN ACCESSIONS 60 | count_a = 0 61 | seq2taxid = {} 62 | i_file = open(args.in_file,'r') 63 | sys.stdout.write(">> STEP 1: READING %s FOR ACCESSIONS\n" % args.in_file) 64 | sys.stdout.write("\t%i accessions read" % count_a) 65 | sys.stdout.flush() 66 | for line in i_file: 67 | line = line.strip() 68 | curr_a = line.split("\t")[0] #if file has more than one column 69 | #Dont save duplicates 70 | if curr_a not in seq2taxid: 71 | count_a += 1 72 | seq2taxid[curr_a] = -1 73 | sys.stdout.write("\r\t%i accessions read" % count_a) 74 | sys.stdout.flush() 75 | sys.stdout.write("\r\t%i accessions read\n" % count_a) 76 | sys.stdout.flush() 77 | i_file.close() 78 | 79 | #STEP 2: READ IN REFERENCE MAPS 80 | count_found = 0 81 | sys.stdout.write(">> STEP 2: SEARCHING %i ACCESSION2TAXID FILES\n" % len(args.ref_files)) 82 | sys.stdout.flush() 83 | for ref in args.ref_files: 84 | #gzipped file 85 | if ref[-3:] == ".gz": 86 | r_file = gzip.open(ref,'r') 87 | else: 88 | r_file = open(ref,'r') 89 | sys.stdout.write("\tReading %s\n" % ref) 90 | sys.stdout.write("\t\t%i / %i accessions found" % (count_found, count_a)) 91 | sys.stdout.flush() 92 | for line in r_file: 93 | line = line.strip() 94 | l_vals = line.split("\t") 95 | curr_a = l_vals[0] 96 | #Found accession - save 97 | if curr_a in seq2taxid and seq2taxid[curr_a] == -1: 98 | seq2taxid[curr_a] = int(l_vals[2]) 99 | count_found += 1 100 | sys.stdout.write("\r\t\t%i / %i accessions found" % (count_found, count_a)) 101 | sys.stdout.flush() 102 | if count_found == count_a: 103 | break 104 | sys.stdout.write("\r\t\t%i / %i accessions found\n" % (count_found, count_a)) 105 | sys.stdout.flush() 106 | if count_found == count_a: 107 | break 108 | sys.stdout.write("\tfinished reading provided accession2taxid files\n") 109 | sys.stdout.flush() 110 | 111 | #STEP 3: OUTPUT FOUND ACCESSIONS AND REMAINING ACCESSIONS 112 | sys.stdout.write(">> STEP 3: PRINTING ACCESSION2TAXIDS TO %s\n" % args.out_file) 113 | sys.stdout.flush() 114 | if count_found < count_a: 115 | r_file = open(args.rem_file,'w') 116 | o_file = open(args.out_file,'w') 117 | for seq in seq2taxid: 118 | if seq2taxid[seq] == -1: 119 | r_file.write("%s\n" % seq) 120 | else: 121 | o_file.write("%s\t%i\n" % (seq, seq2taxid[seq])) 122 | o_file.close() 123 | r_file.close() 124 | if __name__ == "__main__": 125 | main() 126 | -------------------------------------------------------------------------------- /inst/extdata/KrakenTools/kreport2mpa.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #################################################################### 3 | #kreport2mpa.py converts a Kraken-style report into mpa [MetaPhlAn) format 4 | #Copyright (C) 2017-2020 Jennifer Lu, jennifer.lu717@gmail.com 5 | 6 | #This file is part of KrakenTools. 7 | #KrakenTools is free software; you can redistribute it and/or modify 8 | #it under the terms of the GNU General Public License as published by 9 | #the Free Software Foundation; either version 3 of the license, or 10 | #(at your option) any later version. 11 | 12 | #This program is distributed in the hope that it will be useful, 13 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | #GNU General Public License for more details. 16 | 17 | #You should have received a copy of the GNU General Public License 18 | #along with this program; if not, see . 19 | 20 | #################################################################### 21 | #Jennifer Lu, jlu26@jhmi.edu 22 | #11/06/2017 23 | #Updated: 07/12/2020 24 | # 25 | #This program reads in a Kraken report file and generates 26 | #an mpa-format (MetaPhlAn) style report. Each line represents 27 | #a possible taxon classification. The first column is lists the 28 | #domain, kingdom, phyla, etc, leading up to each taxon. 29 | #The levels are separated by the | delimiter, with the type of 30 | #level specified before each name with a single letter and underscore 31 | #(d_ for domain, k_ for kingdom, etc). 32 | #The second column is the number of reads classified within 33 | #that taxon's subtree. 34 | # 35 | #Input file: 36 | # - Kraken report file generates from the kraken raw output file 37 | #Input Parameters to Specify [OPTIONAL]: 38 | # - header_line = prints a header line in mpa-report 39 | # [Default: no header] 40 | # - intermediate-ranks = includes non-traditional taxon levels 41 | # (traditional levels: domain, kingdom, phylum, class, order, 42 | # family, genus, species) 43 | # [Default: no intermediate ranks] 44 | #Output file format (tab-delimited) 45 | # - Taxonomy tree levels |-delimited, with level type [d,k,p,c,o,f,g,s,x] 46 | # - Number of reads within subtree of the specified level 47 | # 48 | #Methods 49 | # - main 50 | # - process_kraken_report 51 | # 52 | import os, sys, argparse 53 | 54 | #process_kraken_report 55 | #usage: parses a single line in the kraken report and extracts relevant information 56 | #input: kraken report file with the following tab delimited lines 57 | # - percent of total reads 58 | # - number of reads (including at lower levels) 59 | # - number of reads (only at this level) 60 | # - taxonomy classification of level 61 | # (U, D, P, C, O, F, G, S, -) 62 | # - taxonomy ID (0 = unclassified, 1 = root, 2 = Bacteria,...etc) 63 | # - spaces + name 64 | #returns: 65 | # - classification/genome name 66 | # - level name (U, -, D, P, C, O, F, G, S) 67 | # - reads classified at this level and below in the tree 68 | def process_kraken_report(curr_str, remove_spaces): 69 | split_str = curr_str.strip().split('\t') 70 | if len(split_str) < 4: 71 | return [] 72 | try: 73 | int(split_str[1]) 74 | except ValueError: 75 | return [] 76 | percents = float(split_str[0]) 77 | all_reads = int(split_str[1]) 78 | #Extract relevant information 79 | try: 80 | taxid = int(split_str[-3]) 81 | level_type = split_str[-2] 82 | map_kuniq = {'species':'S', 'genus':'G','family':'F', 83 | 'order':'O','class':'C','phylum':'P','superkingdom':'D', 84 | 'kingdom':'K'} 85 | if level_type not in map_kuniq: 86 | level_type = '-' 87 | else: 88 | level_type = map_kuniq[level_type] 89 | except ValueError: 90 | taxid = int(split_str[-2]) 91 | level_type = split_str[-3] 92 | #Get name and spaces 93 | spaces = 0 94 | name = split_str[-1] 95 | for char in name: 96 | if char == ' ': 97 | name = name[1:] 98 | spaces += 1 99 | else: 100 | break 101 | if remove_spaces == True: 102 | name = name.replace(' ','_') 103 | #Determine level based on number of spaces 104 | level_num = spaces/2 105 | return [name, level_num, level_type, all_reads, percents] 106 | 107 | #Main method 108 | def main(): 109 | #Parse arguments 110 | parser = argparse.ArgumentParser() 111 | parser.add_argument('-r', '--report-file', '--report', required=True, 112 | dest='r_file', help='Input kraken report file for converting') 113 | parser.add_argument('-o', '--output', required=True, 114 | dest='o_file', help='Output mpa-report file name') 115 | parser.add_argument('--display-header', action='store_true', 116 | dest='add_header', default=False, required=False, 117 | help='Include header [Kraken report filename] in mpa-report file [default: no header]') 118 | parser.add_argument('--read_count', action='store_true', 119 | dest='use_reads', default=True, required=False, 120 | help='Use read count for output [default]') 121 | parser.add_argument('--percentages', action='store_false', 122 | dest='use_reads', default=True, required=False, 123 | help='Use percentages for output [instead of reads]') 124 | parser.add_argument('--intermediate-ranks', action='store_true', 125 | dest='x_include', default=False, required=False, 126 | help='Include non-traditional taxonomic ranks in output') 127 | parser.add_argument('--no-intermediate-ranks', action='store_false', 128 | dest='x_include', default=False, required=False, 129 | help='Do not include non-traditional taxonomic ranks in output [default]') 130 | group = parser.add_mutually_exclusive_group() 131 | group.add_argument('--remove-spaces', action='store_true', 132 | dest='remove_spaces', default=True, required=False, 133 | help='Replace space with underscore in taxon name [default]') 134 | group.add_argument('--keep-spaces', action='store_false', 135 | dest='remove_spaces', default=False, required=False, 136 | help='Do not replace space with underscore in taxon name') 137 | args=parser.parse_args() 138 | 139 | #Process report file and output 140 | curr_path = [] 141 | prev_lvl_num = -1 142 | r_file = open(args.r_file, 'r') 143 | o_file = open(args.o_file, 'w') 144 | #Print header 145 | if args.add_header: 146 | o_file.write("#Classification\t" + os.path.basename(args.r_file) + "\n") 147 | 148 | #Read through report file 149 | main_lvls = ['R','K','D','P','C','O','F','G','S'] 150 | for line in r_file: 151 | report_vals = process_kraken_report(line, args.remove_spaces) 152 | #If header line, skip 153 | if len(report_vals) < 5: 154 | continue 155 | #Get relevant information from the line 156 | [name, level_num, level_type, all_reads, percents] = report_vals 157 | if level_type == 'U': 158 | continue 159 | #Create level name 160 | if level_type not in main_lvls: 161 | level_type = "x" 162 | elif level_type == "K": 163 | level_type = "k" 164 | elif level_type == "D": 165 | level_type = "d" 166 | level_str = level_type.lower() + "__" + name 167 | #Determine full string to add 168 | if prev_lvl_num == -1: 169 | #First level 170 | prev_lvl_num = level_num 171 | curr_path.append(level_str) 172 | else: 173 | #Move back if needed 174 | while level_num != (prev_lvl_num + 1): 175 | prev_lvl_num -= 1 176 | curr_path.pop() 177 | #Print if at non-traditional level and that is requested 178 | if (level_type == "x" and args.x_include) or level_type != "x": 179 | #Print all ancestors of current level followed by | 180 | for string in curr_path: 181 | if (string[0] == "x" and args.x_include) or string[0] != "x": 182 | if string[0] != "r": 183 | o_file.write(string + "|") 184 | #Print final level and then number of reads 185 | if args.use_reads: 186 | o_file.write(level_str + "\t" + str(all_reads) + "\n") 187 | else: 188 | o_file.write(level_str + "\t" + str(percents) + "\n") 189 | #Update 190 | curr_path.append(level_str) 191 | prev_lvl_num = level_num 192 | o_file.close() 193 | r_file.close() 194 | 195 | if __name__ == "__main__": 196 | main() 197 | -------------------------------------------------------------------------------- /inst/extdata/KrakenTools/make_kreport.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ###################################################################### 3 | #make_kreport.py takes in the kraken output file and the make_ktaxonomy.py 4 | #output file to generate a kraken report file 5 | #Copyright (C) 2020 Jennifer Lu, jennifer.lu717@gmail.com 6 | # 7 | #This file is part of KrakenTools 8 | #KrakenTools is free software; oyu can redistribute it and/or modify 9 | #it under the terms of the GNU General Public License as published by 10 | #the Free Software Foundation; either version 3 of the license, or 11 | #(at your option) any later version. 12 | # 13 | #This program is distributed in the hope that it will be useful, 14 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | #GNU General Public License for more details. 17 | # 18 | #You should have received a copy of the GNU General Public License 19 | #along with this program; if not, see . 20 | # 21 | ###################################################################### 22 | #Jennifer Lu, jlu26@jhmi.edu 23 | #Updated: 04/15/2020 24 | # 25 | #This program creates the kraken report file from 26 | #the make_ktaxonomy.py output and the kraken output file 27 | # 28 | #Required Parameters: 29 | # -i,-k,--kraken X....................kraken output file 30 | # -t,--taxonomy X.....................taxonomy file 31 | # -o, --output X......................output kraken report file 32 | #Optional Parameters: 33 | # -h, --help..........................show help message. 34 | ################################################################################# 35 | import os, sys, argparse 36 | import operator 37 | from time import gmtime 38 | from time import strftime 39 | ################################################################################# 40 | #Tree Class 41 | #usage: tree node used in constructing taxonomy tree 42 | class Tree(object): 43 | 'Tree node.' 44 | def __init__(self, taxid, name, level_rank, level_num, p_taxid, parent=None,children=None): 45 | self.taxid = taxid 46 | self.name = name 47 | self.level_rank= level_rank 48 | self.level_num = int(level_num) 49 | self.p_taxid = p_taxid 50 | self.all_reads = 0 51 | self.lvl_reads = 0 52 | #Parent/children attributes 53 | self.children = [] 54 | self.parent = parent 55 | if children is not None: 56 | for child in children: 57 | self.add_child(child) 58 | def add_child(self, node): 59 | assert isinstance(node,Tree) 60 | self.children.append(node) 61 | ################################################################################# 62 | #Main method 63 | def main(): 64 | #Parse arguments 65 | parser = argparse.ArgumentParser() 66 | parser.add_argument('-i','--input', '-k','--kraken', dest='kraken_file', required=True, 67 | help='Kraken output file (5 tab-delimited columns, taxid in 3rd column)') 68 | parser.add_argument('-t','--taxonomy', dest='tax_file', required=True, 69 | help='Output taxonomy file from make_ktaxonomy.py') 70 | parser.add_argument('-o','--output',dest='out_file', required=True, 71 | help='Output kraken report file') 72 | parser.add_argument('--use-read-len',dest='use_read_len', 73 | action='store_true',default=False, required=False, 74 | help='Make report file using sum of read lengths [default: read counts]') 75 | args = parser.parse_args() 76 | 77 | #Start Program 78 | time = strftime("%m-%d-%Y %H:%M:%S", gmtime()) 79 | sys.stdout.write("PROGRAM START TIME: " + time + '\n') 80 | 81 | #STEP 1/4: READ TAXONOMY FILE 82 | count_nodes = 0 83 | sys.stdout.write(">> STEP 1/4: Reading taxonomy %s...\n" % args.tax_file) 84 | sys.stdout.write("\t%i nodes saved" % (count_nodes)) 85 | #Parse taxonomy file 86 | root_node = -1 87 | taxid2node = {} 88 | t_file = open(args.tax_file,'r') 89 | for line in t_file: 90 | count_nodes += 1 91 | sys.stdout.write("\r\t%i nodes saved" % (count_nodes)) 92 | sys.stdout.flush() 93 | [taxid, p_tid, rank, lvl_num, name] = line.strip().split('\t|\t') 94 | curr_node = Tree(taxid, name, rank, lvl_num, p_tid) 95 | taxid2node[taxid] = curr_node 96 | #set parent/kids 97 | if taxid == "1": 98 | root_node = curr_node 99 | else: 100 | curr_node.parent = taxid2node[p_tid] 101 | taxid2node[p_tid].add_child(curr_node) 102 | t_file.close() 103 | sys.stdout.write("\r\t%i nodes saved\n" % (count_nodes)) 104 | sys.stdout.flush() 105 | #STEP 2/4: READ KRAKEN FILE FOR COUNTS PER TAXID 106 | read_count = 0 107 | sys.stdout.write(">> STEP 2/4: Reading kraken file %s...\n" % args.kraken_file) 108 | sys.stdout.write("\t%i million reads processed" % read_count) 109 | sys.stdout.flush() 110 | #Save counts per taxid 111 | taxid2counts = {} 112 | taxid2allcounts = {} 113 | k_file = open(args.kraken_file,'r') 114 | for line in k_file: 115 | read_count += 1 116 | if read_count % 1000 == 0: 117 | sys.stdout.write('\r\t%0.3f million reads processed' % float(read_count/1000000.)) 118 | sys.stdout.flush() 119 | l_vals = line.strip().split('\t') 120 | taxid = l_vals[2] 121 | count = 1 122 | #If using read length instead of read counts 123 | if args.use_read_len: 124 | if '|' in l_vals[3]: 125 | [len1,len2] = l_vals[3].split('|') 126 | count = int(len1)+int(len2) 127 | else: 128 | count = int(l_vals[3]) 129 | #add to dictionaries 130 | if taxid not in taxid2counts: 131 | taxid2counts[taxid] = count 132 | taxid2allcounts[taxid] = count 133 | else: 134 | taxid2counts[taxid] += count 135 | taxid2allcounts[taxid] += count 136 | k_file.close() 137 | sys.stdout.write('\r\t%0.3f million reads processed\n' % float(read_count/1000000.)) 138 | sys.stdout.flush() 139 | #STEP 3/4: FOR EVERY TAXID PARSED, ADD UP TOTAL READS 140 | sys.stdout.write(">> STEP 3/4: Creating final tree...\n") 141 | for curr_tid in taxid2counts: 142 | #Skip unclassified 143 | if curr_tid == '0': 144 | continue 145 | p_node = taxid2node[curr_tid].parent 146 | add_counts = taxid2counts[curr_tid] 147 | #Assign reads for node 148 | taxid2node[curr_tid].lvl_reads += add_counts 149 | taxid2node[curr_tid].all_reads += add_counts 150 | while (p_node != None): 151 | #Add child reads to parent node 152 | p_taxid = p_node.taxid 153 | if p_taxid not in taxid2allcounts: 154 | taxid2allcounts[p_taxid] = add_counts 155 | else: 156 | taxid2allcounts[p_taxid] += add_counts 157 | p_node.all_reads += add_counts 158 | #Get next parent node 159 | p_node = p_node.parent 160 | #STEP 4/4: PRINT REPORT FILE 161 | sys.stdout.write(">> STEP 4/4: Printing report file to %s...\n" % args.out_file) 162 | o_file = open(args.out_file,'w') 163 | #Write line for unclassified reads: 164 | if '0' in taxid2counts: 165 | o_file.write("%6.2f\t" % (float(taxid2counts['0'])/float(read_count)*100)) 166 | o_file.write("%i\t%i\t" % (taxid2counts['0'],taxid2counts['0'])) 167 | o_file.write('U\t0\tunclassified\n') 168 | #Get remaining lines 169 | parse_nodes = [root_node] 170 | while len(parse_nodes) > 0: 171 | curr_node = parse_nodes.pop(0) 172 | curr_tid = curr_node.taxid 173 | #Print information for this level 174 | o_file.write("%6.2f\t" % (float(taxid2allcounts[curr_tid])/float(read_count)*100)) 175 | o_file.write("%i\t" % taxid2allcounts[curr_tid]) 176 | if curr_tid not in taxid2counts: 177 | o_file.write("0\t") 178 | else: 179 | o_file.write("%i\t" % taxid2counts[curr_tid]) 180 | o_file.write("%s\t" % curr_node.level_rank) 181 | o_file.write("%s\t" % curr_tid) 182 | o_file.write(" "*curr_node.level_num*2 + curr_node.name + "\n") 183 | #Add children to list 184 | for child in sorted(curr_node.children, key=operator.attrgetter('all_reads')): 185 | if child.taxid not in taxid2allcounts: 186 | continue 187 | if taxid2allcounts[child.taxid] == 0: 188 | continue 189 | #Add to list 190 | parse_nodes.insert(0,child) 191 | o_file.close() 192 | #End of program 193 | time = strftime("%m-%d-%Y %H:%M:%S", gmtime()) 194 | sys.stdout.write("PROGRAM END TIME: " + time + '\n') 195 | sys.exit(0) 196 | 197 | ################################################################################# 198 | if __name__ == "__main__": 199 | main() 200 | ################################################################################# 201 | ##################################END OF PROGRAM################################# 202 | ################################################################################# 203 | 204 | -------------------------------------------------------------------------------- /inst/extdata/TRUST4/BuildDatabaseFa.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use warnings ; 4 | use strict ; 5 | 6 | die "usage: perl BuildDatabaseFa.pl reference.fa annotation.gtf interested_gene_name_list > output.fa\n" if ( @ARGV != 3 ) ; 7 | 8 | my %genome ; 9 | my %interestedGeneName ; 10 | 11 | 12 | # Read in the reference genome. 13 | open FP1, $ARGV[0] ; 14 | my $chrom = "" ; 15 | my $seq = "" ; 16 | my $hasChrPrefix = 0 ; 17 | while ( ) 18 | { 19 | if ( /^>/ ) 20 | { 21 | $genome{ $chrom } = $seq if ( $chrom ne "" ) ; 22 | $seq = "" ; 23 | $chrom = substr( ( split )[0], 1 ) ; 24 | if ( $chrom =~ /^c/ ) 25 | { 26 | $hasChrPrefix = 1 ; 27 | } 28 | } 29 | else 30 | { 31 | chomp ; 32 | $seq .= $_ ; 33 | } 34 | } 35 | $genome{ $chrom } = $seq if ( $chrom ne "" ) ; 36 | close FP1 ; 37 | 38 | # Read in the gene name we interested in. 39 | open FP1, $ARGV[2] ; 40 | while ( ) 41 | { 42 | chomp ; 43 | $interestedGeneName{ $_ } = 1 ; 44 | } 45 | close FP1 ; 46 | 47 | # Read in the gtf file and output interested sequences. 48 | open FP1, $ARGV[1] ; 49 | $seq = 0 ; 50 | #chr14 HAVANA UTR 21712321 21712330 . + . gene_id "ENSG00000211776.2"; transcript_id "ENST00000390424.2"; gene_type "TR_V_gene"; gene_name "TRAV2"; transcript_type "TR_V_gene"; transcript_name "TRAV2-201"; exon_number 1; exon_id "ENSE00001508005.2"; level 2; protein_id "ENSP00000438195.1"; transcript_support_level "NA"; tag "mRNA_end_NF"; tag "cds_end_NF"; tag "basic"; tag "appris_principal_1"; havana_gene "OTTHUMG00000168980.2"; havana_transcript "OTTHUMT00000401875.2"; 51 | my $prevTname = "" ; 52 | my $gname = "" ; 53 | my $strand = "." ; 54 | my @range ; 55 | 56 | sub OutputGene 57 | { 58 | my $i ; 59 | 60 | $chrom = $range[0] ; 61 | my $start = $range[1] ; 62 | my $end = $range[-1] ; 63 | 64 | my $output = "" ; 65 | 66 | if ($strand eq "-" ) 67 | { 68 | $start = $range[-2] ; 69 | $end = $range[2] ; 70 | } 71 | die "Unknown chrom id $chrom " if ( !defined $genome{ $chrom } ) ; 72 | 73 | print ">$gname $chrom $start $end $strand\n" ; 74 | for ( $i = 0 ; $i < scalar( @range ) ; $i += 3 ) 75 | { 76 | my $tmp = uc( substr( $genome{ $range[$i] }, $range[$i + 1] - 1, $range[$i + 2] - $range[$i + 1] + 1 ) ) ; 77 | if ( $strand eq "-" ) 78 | { 79 | $tmp = reverse( $tmp ) ; 80 | $tmp =~ tr/ACGT/TGCA/ ; 81 | } 82 | $output .= $tmp ; 83 | } 84 | print( "$output\n" ) ; 85 | } 86 | 87 | while ( ) 88 | { 89 | next if ( /^#/ ) ; 90 | chomp ; 91 | my @cols = split /\t/ ; 92 | next if ( $cols[2] ne "exon" ) ; 93 | 94 | my $tname ; 95 | if ( $cols[8] =~ /transcript_name \"(.*?)\"/ ) 96 | { 97 | #print $1, "\n" ; 98 | $tname = $1 ; 99 | } 100 | else 101 | { 102 | die "No transcript_name", $_, "\n" ; 103 | } 104 | 105 | 106 | if ( $tname ne $prevTname ) 107 | { 108 | if ( (defined $interestedGeneName{ $gname } ) && @range > 0 ) 109 | { 110 | OutputGene() ; 111 | } 112 | 113 | $prevTname = $tname ; 114 | if ( $cols[8] =~ /gene_name \"(.*?)\"/ ) 115 | { 116 | #print $1, "\n" ; 117 | $gname = uc($1) ; 118 | } 119 | else 120 | { 121 | die "No gene_name: ", $_, "\n" ; 122 | } 123 | $strand = $cols[6] ; 124 | undef @range ; 125 | } 126 | 127 | if ( $hasChrPrefix == 1 && !( $cols[0] =~ /^c/) ) 128 | { 129 | $cols[0] = "chr".$cols[0] ; 130 | } 131 | elsif ( $hasChrPrefix == 0 && $cols[0] =~ /^c/ ) 132 | { 133 | $cols[0] = substr( $cols[0], 3 ) ; 134 | } 135 | push @range, $cols[0], $cols[3], $cols[4] ; 136 | } 137 | 138 | if ( (defined $interestedGeneName{ $gname } ) && @range > 0 ) 139 | { 140 | OutputGene() ; 141 | } 142 | 143 | 144 | close FP1 ; 145 | -------------------------------------------------------------------------------- /inst/extdata/TRUST4/BuildImgtAnnot.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict ; 4 | use warnings ; 5 | 6 | die "usage: a.pl species_name(Homo_sapiens or others) > output.fa\n" if ( @ARGV == 0 ) ; 7 | 8 | sub system_call 9 | { 10 | print STDERR "SYSTEM CALL: ".join(" ",@_)."\n"; 11 | system(@_) == 0 12 | or die "system @_ failed: $?"; 13 | #print STDERR " finished\n"; 14 | } 15 | 16 | my $species = $ARGV[0] ; 17 | # Download 18 | #system_call( "wget -np -nd -r -A fasta -P tmp_download http://www.imgt.org//download/V-QUEST/IMGT_V-QUEST_reference_directory/".$species."/" ) ; 19 | #system_call( "cat tmp_download/*.fasta > tmp_download/vquest.fa") ; 20 | system_call( "wget -O IMGT_download.fa https://www.imgt.org/download/GENE-DB/IMGTGENEDB-ReferenceSequences.fasta-nt-WithGaps-F+ORF+inframeP" ) ; 21 | 22 | # Reformat 23 | #>J00256|IGHJ1*01|Homo sapiens|F|J-REGION|723..774|52 nt|1| | | | |52+0=52| | | 24 | # 25 | open FP1, "IMGT_download.fa" ; 26 | my $prevId = "" ; 27 | my $prevGeneName = "" ; 28 | my $output = 0 ; 29 | my $skipHeader = 0 ; # For the genes that are split into pieces in the database. 30 | 31 | while ( ) 32 | { 33 | if ( /^>/ ) 34 | { 35 | my @cols = split /\|/, substr( $_, 1 ) ; 36 | my $s = $cols[2] ; 37 | $s =~ tr/ /_/ ; 38 | if ( !($s =~ /$species/) ) 39 | { 40 | $output = 0 ; 41 | } 42 | elsif ( !( $cols[1] =~ /^IG/ ) && !($cols[1] =~ /^TR/) ) 43 | { 44 | $output = 0 ; 45 | } 46 | else 47 | { 48 | $output = 1 ; 49 | if ( $cols[1] eq $prevGeneName ) 50 | { 51 | $output = 0 if ( $cols[0] ne $prevId ) ; # Could be some middle part of a gene. 52 | $skipHeader = 1 ; 53 | } 54 | else 55 | { 56 | $skipHeader = 0 ; 57 | } 58 | } 59 | $prevId = $cols[0] ; 60 | $prevGeneName = $cols[1] ; 61 | } 62 | next if ( $output == 0) ; 63 | if ( !/^>/ ) 64 | { 65 | $_ =~ tr/acgtn/ACGTN/ ; 66 | print $_ ; 67 | } 68 | elsif ( $skipHeader == 0 ) 69 | { 70 | print ">".(split /\|/ )[1]."\n" ; 71 | } 72 | } 73 | close FP1 ; 74 | 75 | unlink "IMGT_download.fa" ; 76 | -------------------------------------------------------------------------------- /inst/extdata/kraken2/kreport2mpa.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #################################################################### 3 | #kreport2mpa.py converts a Kraken-style report into mpa [MetaPhlAn) format 4 | #Copyright (C) 2017-2020 Jennifer Lu, jennifer.lu717@gmail.com 5 | 6 | #This file is part of KrakenTools. 7 | #KrakenTools is free software; you can redistribute it and/or modify 8 | #it under the terms of the GNU General Public License as published by 9 | #the Free Software Foundation; either version 3 of the license, or 10 | #(at your option) any later version. 11 | 12 | #This program is distributed in the hope that it will be useful, 13 | #but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | #GNU General Public License for more details. 16 | 17 | #You should have received a copy of the GNU General Public License 18 | #along with this program; if not, see . 19 | 20 | #################################################################### 21 | #Jennifer Lu, jlu26@jhmi.edu 22 | #11/06/2017 23 | #Updated: 07/12/2020 24 | # 25 | #This program reads in a Kraken report file and generates 26 | #an mpa-format (MetaPhlAn) style report. Each line represents 27 | #a possible taxon classification. The first column is lists the 28 | #domain, kingdom, phyla, etc, leading up to each taxon. 29 | #The levels are separated by the | delimiter, with the type of 30 | #level specified before each name with a single letter and underscore 31 | #(d_ for domain, k_ for kingdom, etc). 32 | #The second column is the number of reads classified within 33 | #that taxon's subtree. 34 | # 35 | #Input file: 36 | # - Kraken report file generates from the kraken raw output file 37 | #Input Parameters to Specify [OPTIONAL]: 38 | # - header_line = prints a header line in mpa-report 39 | # [Default: no header] 40 | # - intermediate-ranks = includes non-traditional taxon levels 41 | # (traditional levels: domain, kingdom, phylum, class, order, 42 | # family, genus, species) 43 | # [Default: no intermediate ranks] 44 | #Output file format (tab-delimited) 45 | # - Taxonomy tree levels |-delimited, with level type [d,k,p,c,o,f,g,s,x] 46 | # - Number of reads within subtree of the specified level 47 | # 48 | #Methods 49 | # - main 50 | # - process_kraken_report 51 | # 52 | import os, sys, argparse 53 | 54 | #process_kraken_report 55 | #usage: parses a single line in the kraken report and extracts relevant information 56 | #input: kraken report file with the following tab delimited lines 57 | # - percent of total reads 58 | # - number of reads (including at lower levels) 59 | # - number of reads (only at this level) 60 | # - taxonomy classification of level 61 | # (U, D, P, C, O, F, G, S, -) 62 | # - taxonomy ID (0 = unclassified, 1 = root, 2 = Bacteria,...etc) 63 | # - spaces + name 64 | #returns: 65 | # - classification/genome name 66 | # - level name (U, -, D, P, C, O, F, G, S) 67 | # - reads classified at this level and below in the tree 68 | def process_kraken_report(curr_str): 69 | split_str = curr_str.strip().split('\t') 70 | try: 71 | int(split_str[1]) 72 | except ValueError: 73 | return [] 74 | percents = float(split_str[0]) 75 | all_reads = int(split_str[1]) 76 | level_type = split_str[3] 77 | #Get name and spaces 78 | spaces = 0 79 | name = split_str[-1] 80 | for char in name: 81 | if char == ' ': 82 | name = name[1:] 83 | spaces += 1 84 | else: 85 | break 86 | name = name.replace(' ','_') 87 | #Determine level based on number of spaces 88 | level_num = spaces/2 89 | return [name, level_num, level_type, all_reads, percents] 90 | 91 | #Main method 92 | def main(): 93 | #Parse arguments 94 | parser = argparse.ArgumentParser() 95 | parser.add_argument('-r', '--report-file', '--report', required=True, 96 | dest='r_file', help='Input kraken report file for converting') 97 | parser.add_argument('-o', '--output', required=True, 98 | dest='o_file', help='Output mpa-report file name') 99 | parser.add_argument('--display-header', action='store_true', 100 | dest='add_header', default=False, required=False, 101 | help='Include header [Kraken report filename] in mpa-report file [default: no header]') 102 | parser.add_argument('--read_count', action='store_true', 103 | dest='use_reads', default=True, required=False, 104 | help='Use read count for output [default]') 105 | parser.add_argument('--percentages', action='store_false', 106 | dest='use_reads', default=True, required=False, 107 | help='Use percentages for output [instead of reads]') 108 | parser.add_argument('--intermediate-ranks', action='store_true', 109 | dest='x_include', default=False, required=False, 110 | help='Include non-traditional taxonomic ranks in output') 111 | parser.add_argument('--no-intermediate-ranks', action='store_false', 112 | dest='x_include', default=False, required=False, 113 | help='Do not include non-traditional taxonomic ranks in output [default]') 114 | args=parser.parse_args() 115 | 116 | #Process report file and output 117 | curr_path = [] 118 | prev_lvl_num = -1 119 | r_file = open(args.r_file, 'r') 120 | o_file = open(args.o_file, 'w') 121 | #Print header 122 | if args.add_header: 123 | o_file.write("#Classification\t" + os.path.basename(args.r_file) + "\n") 124 | 125 | #Read through report file 126 | main_lvls = ['R','K','D','P','C','O','F','G','S'] 127 | for line in r_file: 128 | report_vals = process_kraken_report(line) 129 | #If header line, skip 130 | if len(report_vals) < 5: 131 | continue 132 | #Get relevant information from the line 133 | [name, level_num, level_type, all_reads, percents] = report_vals 134 | if level_type == 'U': 135 | continue 136 | #Create level name 137 | if level_type not in main_lvls: 138 | level_type = "x" 139 | elif level_type == "K": 140 | level_type = "k" 141 | elif level_type == "D": 142 | level_type = "k" 143 | level_str = level_type.lower() + "__" + name 144 | #Determine full string to add 145 | if prev_lvl_num == -1: 146 | #First level 147 | prev_lvl_num = level_num 148 | curr_path.append(level_str) 149 | else: 150 | #Move back if needed 151 | while level_num != (prev_lvl_num + 1): 152 | prev_lvl_num -= 1 153 | curr_path.pop() 154 | #Print if at non-traditional level and that is requested 155 | if (level_type == "x" and args.x_include) or level_type != "x": 156 | #Print all ancestors of current level followed by | 157 | for string in curr_path: 158 | if (string[0] == "x" and args.x_include) or string[0] != "x": 159 | if string[0] != "r": 160 | o_file.write(string + "|") 161 | #Print final level and then number of reads 162 | if args.use_reads: 163 | o_file.write(level_str + "\t" + str(all_reads) + "\n") 164 | else: 165 | o_file.write(level_str + "\t" + str(percents) + "\n") 166 | #Update 167 | curr_path.append(level_str) 168 | prev_lvl_num = level_num 169 | o_file.close() 170 | r_file.close() 171 | 172 | if __name__ == "__main__": 173 | main() 174 | 175 | -------------------------------------------------------------------------------- /man/Command.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-.R 3 | \name{Command} 4 | \alias{Command} 5 | \title{R6 Class to prepare command parameters.} 6 | \description{ 7 | \code{Command} is an R6 class used by developers to create new command. It should 8 | not be used by end users. 9 | } 10 | \seealso{ 11 | make_command 12 | } 13 | \section{Methods}{ 14 | \subsection{Public methods}{ 15 | \itemize{ 16 | \item \href{#method-Command-new}{\code{Command$new()}} 17 | \item \href{#method-Command-build_command}{\code{Command$build_command()}} 18 | \item \href{#method-Command-get_on_start}{\code{Command$get_on_start()}} 19 | \item \href{#method-Command-get_on_exit}{\code{Command$get_on_exit()}} 20 | \item \href{#method-Command-get_on_fail}{\code{Command$get_on_fail()}} 21 | \item \href{#method-Command-get_on_succeed}{\code{Command$get_on_succeed()}} 22 | \item \href{#method-Command-print}{\code{Command$print()}} 23 | \item \href{#method-Command-clone}{\code{Command$clone()}} 24 | } 25 | } 26 | \if{html}{\out{
}} 27 | \if{html}{\out{}} 28 | \if{latex}{\out{\hypertarget{method-Command-new}{}}} 29 | \subsection{Method \code{new()}}{ 30 | Create a new \code{Command} object. 31 | \subsection{Usage}{ 32 | \if{html}{\out{
}}\preformatted{Command$new(...)}\if{html}{\out{
}} 33 | } 34 | 35 | \subsection{Arguments}{ 36 | \if{html}{\out{
}} 37 | \describe{ 38 | \item{\code{...}}{Additional argument passed into command.} 39 | } 40 | \if{html}{\out{
}} 41 | } 42 | } 43 | \if{html}{\out{
}} 44 | \if{html}{\out{}} 45 | \if{latex}{\out{\hypertarget{method-Command-build_command}{}}} 46 | \subsection{Method \code{build_command()}}{ 47 | Build the command line 48 | \subsection{Usage}{ 49 | \if{html}{\out{
}}\preformatted{Command$build_command(help = FALSE, verbose = TRUE)}\if{html}{\out{
}} 50 | } 51 | 52 | \subsection{Arguments}{ 53 | \if{html}{\out{
}} 54 | \describe{ 55 | \item{\code{help}}{A boolean value indicating whether to build parameters 56 | for help document or not.} 57 | 58 | \item{\code{verbose}}{A boolean value indicating whether the command 59 | execution should be verbose.} 60 | 61 | \item{\code{envir}}{An environment used to Execute command.} 62 | } 63 | \if{html}{\out{
}} 64 | } 65 | \subsection{Returns}{ 66 | An atomic character combine the command and parameters. 67 | } 68 | } 69 | \if{html}{\out{
}} 70 | \if{html}{\out{}} 71 | \if{latex}{\out{\hypertarget{method-Command-get_on_start}{}}} 72 | \subsection{Method \code{get_on_start()}}{ 73 | Get the command startup code 74 | \subsection{Usage}{ 75 | \if{html}{\out{
}}\preformatted{Command$get_on_start()}\if{html}{\out{
}} 76 | } 77 | 78 | \subsection{Returns}{ 79 | A list of \code{\link[rlang:defusing-advanced]{quosures}}. 80 | } 81 | } 82 | \if{html}{\out{
}} 83 | \if{html}{\out{}} 84 | \if{latex}{\out{\hypertarget{method-Command-get_on_exit}{}}} 85 | \subsection{Method \code{get_on_exit()}}{ 86 | Get the command exit code 87 | \subsection{Usage}{ 88 | \if{html}{\out{
}}\preformatted{Command$get_on_exit()}\if{html}{\out{
}} 89 | } 90 | 91 | \subsection{Returns}{ 92 | A list of \code{\link[rlang:defusing-advanced]{quosures}}. 93 | } 94 | } 95 | \if{html}{\out{
}} 96 | \if{html}{\out{}} 97 | \if{latex}{\out{\hypertarget{method-Command-get_on_fail}{}}} 98 | \subsection{Method \code{get_on_fail()}}{ 99 | Get the command failure code 100 | \subsection{Usage}{ 101 | \if{html}{\out{
}}\preformatted{Command$get_on_fail()}\if{html}{\out{
}} 102 | } 103 | 104 | \subsection{Returns}{ 105 | A list of \code{\link[rlang:defusing-advanced]{quosures}}. 106 | } 107 | } 108 | \if{html}{\out{
}} 109 | \if{html}{\out{}} 110 | \if{latex}{\out{\hypertarget{method-Command-get_on_succeed}{}}} 111 | \subsection{Method \code{get_on_succeed()}}{ 112 | Get the command succeessful code 113 | \subsection{Usage}{ 114 | \if{html}{\out{
}}\preformatted{Command$get_on_succeed()}\if{html}{\out{
}} 115 | } 116 | 117 | \subsection{Returns}{ 118 | A list of \code{\link[rlang:defusing-advanced]{quosures}}. 119 | } 120 | } 121 | \if{html}{\out{
}} 122 | \if{html}{\out{}} 123 | \if{latex}{\out{\hypertarget{method-Command-print}{}}} 124 | \subsection{Method \code{print()}}{ 125 | Build parameters to run command. 126 | \subsection{Usage}{ 127 | \if{html}{\out{
}}\preformatted{Command$print(indent = NULL)}\if{html}{\out{
}} 128 | } 129 | 130 | \subsection{Arguments}{ 131 | \if{html}{\out{
}} 132 | \describe{ 133 | \item{\code{indent}}{A single integer number giving the space of indent.} 134 | } 135 | \if{html}{\out{
}} 136 | } 137 | \subsection{Returns}{ 138 | The object itself. 139 | } 140 | } 141 | \if{html}{\out{
}} 142 | \if{html}{\out{}} 143 | \if{latex}{\out{\hypertarget{method-Command-clone}{}}} 144 | \subsection{Method \code{clone()}}{ 145 | The objects of this class are cloneable with this method. 146 | \subsection{Usage}{ 147 | \if{html}{\out{
}}\preformatted{Command$clone(deep = FALSE)}\if{html}{\out{
}} 148 | } 149 | 150 | \subsection{Arguments}{ 151 | \if{html}{\out{
}} 152 | \describe{ 153 | \item{\code{deep}}{Whether to make a deep clone.} 154 | } 155 | \if{html}{\out{
}} 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /man/allele_counter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-alleleCounter.R 3 | \name{allele_counter} 4 | \alias{allele_counter} 5 | \title{Run alleleCount} 6 | \usage{ 7 | allele_counter( 8 | hts_file, 9 | loci_file, 10 | ofile, 11 | ..., 12 | odir = getwd(), 13 | alleleCounter = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{hts_file}{A string of path to sample HTS file.} 18 | 19 | \item{loci_file}{A string of path to loci file.} 20 | 21 | \item{ofile}{A string of path to the output file.} 22 | 23 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{alleleCounter} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(alleleCounter())}.} 24 | 25 | \item{odir}{A string of path to the output directory.} 26 | 27 | \item{alleleCounter}{A string of path to \code{alleleCounter} command.} 28 | } 29 | \value{ 30 | A \code{command} object. 31 | } 32 | \description{ 33 | The \code{alleleCount} program primarily exists to prevent code duplication 34 | between some other projects, specifically \code{AscatNGS} and \code{Battenberg}. 35 | } 36 | \seealso{ 37 | \itemize{ 38 | \item \url{https://github.com/cancerit/alleleCount} 39 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 40 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 41 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 42 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 43 | } 44 | 45 | Other \code{commands}: 46 | \code{\link{cellranger}()}, 47 | \code{\link{conda}()}, 48 | \code{\link{fastp}()}, 49 | \code{\link{fastq_pair}()}, 50 | \code{\link{gistic2}()}, 51 | \code{\link{kraken2}()}, 52 | \code{\link{kraken_tools}()}, 53 | \code{\link{perl}()}, 54 | \code{\link{pyscenic}()}, 55 | \code{\link{python}()}, 56 | \code{\link{samtools}()}, 57 | \code{\link{seqkit}()}, 58 | \code{\link{trust4}()} 59 | } 60 | \concept{command} 61 | -------------------------------------------------------------------------------- /man/appmamba.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/appmamba.R 3 | \name{appmamba} 4 | \alias{appmamba} 5 | \alias{install_appmamba} 6 | \alias{uninstall_appmamba} 7 | \alias{appmamba_rc} 8 | \title{Manage Environment with \code{micromamba}} 9 | \usage{ 10 | appmamba(...) 11 | 12 | install_appmamba(force = FALSE) 13 | 14 | uninstall_appmamba() 15 | 16 | appmamba_rc(edit = FALSE) 17 | } 18 | \arguments{ 19 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to 20 | \code{micromamba}. Run \code{appmamba()} for more details.} 21 | 22 | \item{force}{A logical value indicating whether to reinstall \code{appmamba} 23 | if it is already installed.} 24 | 25 | \item{edit}{A logical value indicating whether to open the config file for 26 | editing.} 27 | } 28 | \description{ 29 | Manage Environment with \code{micromamba} 30 | } 31 | \section{Functions}{ 32 | \itemize{ 33 | \item \code{appmamba()}: \code{blit} utilizes \code{micromamba} to manage environments. 34 | This function simply executes the specified \code{micromamba} command. 35 | 36 | \item \code{install_appmamba()}: Install appmamba (\code{micromamba}). 37 | 38 | \item \code{uninstall_appmamba()}: Remove appmamba (\code{micromamba}). 39 | 40 | \item \code{appmamba_rc()}: Get the \verb{run commands} config file of the \code{micromamba}. 41 | 42 | }} 43 | \examples{ 44 | \donttest{ 45 | install_appmamba() 46 | appmamba() 47 | appmamba("env", "list") 48 | # uninstall_appmamba() # Uninstall the `micromamba` 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /man/arg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/argument.R 3 | \name{arg} 4 | \alias{arg} 5 | \alias{arg0} 6 | \title{Deliver arguments of command} 7 | \usage{ 8 | arg(tag, value, indicator = FALSE, lgl2int = FALSE, format = "\%s", sep = " ") 9 | 10 | arg0( 11 | tag, 12 | value, 13 | indicator = FALSE, 14 | lgl2int = FALSE, 15 | format = "\%s", 16 | sep = " ", 17 | allow_null = FALSE, 18 | arg = caller_arg(value), 19 | call = caller_call() 20 | ) 21 | } 22 | \arguments{ 23 | \item{tag}{A string specifying argument tag, like "-i", "-o".} 24 | 25 | \item{value}{Value passed to the argument.} 26 | 27 | \item{indicator}{A logical value specifying whether value should be an 28 | indicator of tag. If \code{TRUE}, logical value will explain the set or unset of 29 | tag.} 30 | 31 | \item{lgl2int}{A logical value indicates whether transfrom value \code{TRUE} to 32 | \code{1} or \code{FALSE} to \code{0}. If \code{TRUE}, format will always be set to \code{"\%d"}.} 33 | 34 | \item{format}{The format of the value, details see \code{\link{sprintf}}.} 35 | 36 | \item{sep}{A character string used to separate \code{"tag"} and \code{"value"}, usually 37 | \code{" "} or \code{"="}.} 38 | 39 | \item{allow_null}{A single logical value indicates whether \code{value} can be 40 | \code{NULL}.} 41 | 42 | \item{arg}{An argument name as a string. This argument will be mentioned in 43 | error messages as the input that is at the origin of a problem.} 44 | 45 | \item{call}{The execution environment of a currently running function.} 46 | } 47 | \value{ 48 | A string. 49 | } 50 | \description{ 51 | \code{arg()} is intended for user use, while \code{arg0()} is for developers and does 52 | not perform argument validation. 53 | } 54 | -------------------------------------------------------------------------------- /man/blit-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/blit-package.R 3 | \docType{package} 4 | \name{blit-package} 5 | \alias{blit} 6 | \alias{blit-package} 7 | \title{blit: Bioinformatics Library for Integrated Tools} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} 10 | 11 | An all-encompassing R toolkit designed to streamline the process of calling various bioinformatics software and then performing data analysis and visualization in R. With 'blit', users can easily integrate a wide array of bioinformatics command line tools into their workflows, leveraging the power of R for sophisticated data manipulation and graphical representation. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item \url{https://github.com/WangLabCSU/blit} 17 | \item Report bugs at \url{https://github.com/WangLabCSU/blit/issues} 18 | } 19 | 20 | } 21 | \author{ 22 | \strong{Maintainer}: Yun Peng \email{yunyunp96@163.com} (\href{https://orcid.org/0000-0003-2801-3332}{ORCID}) 23 | 24 | Authors: 25 | \itemize{ 26 | \item Shixiang Wang \email{w_shixiang@163.com} (\href{https://orcid.org/0000-0001-9855-7357}{ORCID}) 27 | } 28 | 29 | Other contributors: 30 | \itemize{ 31 | \item Jia Ding \email{jiading682@qq.com} (\href{https://orcid.org/0009-0002-2530-0897}{ORCID}) [contributor] 32 | \item Jennifer Lu \email{jennifer.lu717@gmail.com} (Author of the included scripts from Kraken2 and KrakenTools libraries) [copyright holder] 33 | \item Li Song \email{Li.Song@dartmouth.edu} (Author of included scripts from TRUST4 library) [copyright holder] 34 | \item X. Shirley Liu \email{xsliu@ds.dfci.harvard.edu} (Author of included scripts from TRUST4 library) [copyright holder] 35 | } 36 | 37 | } 38 | \keyword{internal} 39 | -------------------------------------------------------------------------------- /man/cellranger.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-cellranger.R 3 | \name{cellranger} 4 | \alias{cellranger} 5 | \title{Run cellranger} 6 | \usage{ 7 | cellranger(subcmd = NULL, ..., cellranger = NULL) 8 | } 9 | \arguments{ 10 | \item{subcmd}{Sub-Command of cellranger.} 11 | 12 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{cellranger} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(cellranger())}.} 13 | 14 | \item{cellranger}{A string of path to \code{cellranger} command.} 15 | } 16 | \value{ 17 | A \code{command} object. 18 | } 19 | \description{ 20 | Run cellranger 21 | } 22 | \examples{ 23 | \dontrun{ 24 | fastq_dir # 10x raw fastq files directory 25 | genome_ref # Please download the transcriptome reference data 26 | cellranger( 27 | "count", 28 | sprintf("--fastqs=\%s", fastq_dir), 29 | sprintf("--id=\%s", basename(fastq_dir)), 30 | sprintf("--sample=\%s", basename(fastq_dir)), 31 | sprintf("--localcores=\%s", parallel::detectCores()), 32 | sprintf("--transcriptome=\%s", genome_ref), 33 | sprintf("--chemistry=\%s", shQuote("auto")), 34 | "--nosecondary" 35 | ) 36 | } 37 | } 38 | \seealso{ 39 | \itemize{ 40 | \item \url{https://github.com/10XGenomics/cellranger} 41 | \item \url{https://www.10xgenomics.com/support/software/cell-ranger/latest} 42 | \item \url{https://www.10xgenomics.com/support/software/cell-ranger/downloads#reference-downloads} 43 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 44 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 45 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 46 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 47 | } 48 | 49 | Other \code{commands}: 50 | \code{\link{allele_counter}()}, 51 | \code{\link{conda}()}, 52 | \code{\link{fastp}()}, 53 | \code{\link{fastq_pair}()}, 54 | \code{\link{gistic2}()}, 55 | \code{\link{kraken2}()}, 56 | \code{\link{kraken_tools}()}, 57 | \code{\link{perl}()}, 58 | \code{\link{pyscenic}()}, 59 | \code{\link{python}()}, 60 | \code{\link{samtools}()}, 61 | \code{\link{seqkit}()}, 62 | \code{\link{trust4}()} 63 | } 64 | \concept{command} 65 | -------------------------------------------------------------------------------- /man/cmd_conda.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-setup.R 3 | \name{cmd_conda} 4 | \alias{cmd_conda} 5 | \title{Set \code{conda-like} environment prefix to the \code{PATH} environment variables} 6 | \usage{ 7 | cmd_conda(...) 8 | } 9 | \arguments{ 10 | \item{...}{Additional arguments passed to \code{\link[=cmd_condaenv]{cmd_condaenv()}}.} 11 | } 12 | \description{ 13 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Set \code{conda-like} environment prefix to the 14 | \code{PATH} environment variables. 15 | } 16 | -------------------------------------------------------------------------------- /man/cmd_on_start.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-schedule.R 3 | \name{cmd_on_start} 4 | \alias{cmd_on_start} 5 | \alias{cmd_on_exit} 6 | \alias{cmd_on_fail} 7 | \alias{cmd_on_succeed} 8 | \title{Schedule expressions to run} 9 | \usage{ 10 | cmd_on_start(command, ...) 11 | 12 | cmd_on_exit(command, ...) 13 | 14 | cmd_on_fail(command, ...) 15 | 16 | cmd_on_succeed(command, ...) 17 | } 18 | \arguments{ 19 | \item{command}{A \code{command} object.} 20 | 21 | \item{...}{The expressions input will be captured with 22 | \code{\link[rlang:enquo]{enquos()}}. If your expressions depend on global data, you 23 | may want to unquote objects with \code{\link[rlang:injection-operator]{!!}} to prevent 24 | unintended changes due to delayed evaluation. 25 | \itemize{ 26 | \item \code{cmd_on_start}: Expression to be evaluated when the command started. 27 | \item \code{cmd_on_exit}: Expression to be evaluated when the command finished. 28 | \item \code{cmd_on_fail}: Expression to be evaluated when the command failed. 29 | \item \code{cmd_on_succeed}: Expression to be evaluated when the command succeeded. 30 | }} 31 | } 32 | \value{ 33 | \itemize{ 34 | \item \code{cmd_on_start}: The \code{command} object itself, with the start code updated. 35 | } 36 | 37 | \itemize{ 38 | \item \code{cmd_on_exit}: The \code{command} object itself, with the exit code updated. 39 | } 40 | 41 | \itemize{ 42 | \item \code{cmd_on_fail}: The \code{command} object itself, with the failure code updated. 43 | } 44 | 45 | \itemize{ 46 | \item \code{cmd_on_succeed}: The \code{command} object itself, with the successful code 47 | updated. 48 | } 49 | } 50 | \description{ 51 | Schedule expressions to run 52 | } 53 | \section{Functions}{ 54 | \itemize{ 55 | \item \code{cmd_on_start()}: define the startup code of the command 56 | 57 | \item \code{cmd_on_exit()}: define the exit code of the command 58 | 59 | \item \code{cmd_on_fail()}: define the failure code of the command 60 | 61 | \item \code{cmd_on_succeed()}: define the successful code of the command 62 | 63 | }} 64 | -------------------------------------------------------------------------------- /man/cmd_parallel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-parallel.R 3 | \name{cmd_parallel} 4 | \alias{cmd_parallel} 5 | \title{Execute a list of commands} 6 | \usage{ 7 | cmd_parallel( 8 | ..., 9 | stdouts = FALSE, 10 | stderrs = FALSE, 11 | stdins = NULL, 12 | stdout_callbacks = NULL, 13 | stderr_callbacks = NULL, 14 | timeouts = NULL, 15 | threads = NULL, 16 | verbose = TRUE 17 | ) 18 | } 19 | \arguments{ 20 | \item{...}{A list of \code{command} object.} 21 | 22 | \item{stdouts, stderrs}{Specifies how the output/error streams of the child 23 | process are handled. One of or a list of following values: 24 | \itemize{ 25 | \item \code{FALSE}/\code{NULL}: Suppresses the output/error stream. 26 | \item \code{TRUE}: Prints the child process output/error to the R console. If a 27 | standard output/error stream exists, \code{""} is used; otherwise, \code{"|"} is 28 | used. 29 | \item \strong{string}: An empty string \code{""} inherits the standard output/error stream 30 | from the main R process (Printing in the R console). If the main R process 31 | lacks a standard output/error stream, such as in \code{RGui} on Windows, an 32 | error is thrown. A string \code{"|"} prints to the standard output connection 33 | of R process (Using \code{\link[=cat]{cat()}}). Alternative, a file name or path to 34 | redirect the output/error. If a relative path is specified, it remains 35 | relative to the current working directory, even if a different directory 36 | is set using \code{\link[=cmd_wd]{cmd_wd()}}. 37 | \item \code{connection}: A writable R \code{\link{connection}} object. If the connection is not 38 | \code{\link[=open]{open()}}, it will be automatically opened. 39 | } 40 | 41 | For \code{stderrs}, use string \code{"2>&1"} to redirect it to the same connection 42 | (i.e. pipe or file) as \code{stdout}. 43 | 44 | When a single file path is specified, the stdout/stderr of all commands will 45 | be merged into this single file.} 46 | 47 | \item{stdins}{should the input be diverted? One of or a list of following 48 | values: 49 | \itemize{ 50 | \item \code{FALSE}/\code{NULL}: no standard input. 51 | \item \code{TRUE}: If a standard input stream exists, \code{""} is used; otherwise, \code{NULL} 52 | is used. 53 | \item \strong{string}: An empty string \code{""} inherits the standard input stream from 54 | the main R process. If the main R process lacks a standard input stream, 55 | such as in \code{RGui} on Windows, an error is thrown. Alternative, a file name 56 | or path to redirect the input. If a relative path is specified, it remains 57 | relative to the current working directory, even if a different directory 58 | is set using \code{\link[=cmd_wd]{cmd_wd()}}. 59 | }} 60 | 61 | \item{stdout_callbacks, stderr_callbacks}{One of or a list of following 62 | values: 63 | \itemize{ 64 | \item \code{NULL}: no callback function. 65 | \item \code{function}: A function invoked for each line of standard output or error. 66 | Non-text (non-character) output will be ignored. The function should accept 67 | two arguments: one for the standard output or error and another for the 68 | running \code{\link[processx:process]{process}} object. 69 | }} 70 | 71 | \item{timeouts}{Timeout in seconds. Can be a single value or a list, 72 | specifying the maximum elapsed time for running the command in the separate 73 | process.} 74 | 75 | \item{threads}{Number of threads to use.} 76 | 77 | \item{verbose}{A single boolean value indicating whether the command 78 | execution should be verbose.} 79 | } 80 | \value{ 81 | A list of exit status invisiblely. 82 | } 83 | \description{ 84 | Execute a list of commands 85 | } 86 | \seealso{ 87 | \itemize{ 88 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 89 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 90 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 91 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /man/cmd_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-run.R 3 | \name{cmd_run} 4 | \alias{cmd_run} 5 | \alias{cmd_help} 6 | \alias{cmd_background} 7 | \title{Execute command} 8 | \usage{ 9 | cmd_run( 10 | command, 11 | stdout = TRUE, 12 | stderr = TRUE, 13 | stdin = TRUE, 14 | stdout_callback = NULL, 15 | stderr_callback = NULL, 16 | timeout = NULL, 17 | spinner = FALSE, 18 | verbose = TRUE 19 | ) 20 | 21 | cmd_help( 22 | command, 23 | stdout = TRUE, 24 | stderr = TRUE, 25 | stdout_callback = NULL, 26 | stderr_callback = NULL, 27 | verbose = TRUE 28 | ) 29 | 30 | cmd_background( 31 | command, 32 | stdout = FALSE, 33 | stderr = FALSE, 34 | stdin = NULL, 35 | verbose = TRUE 36 | ) 37 | } 38 | \arguments{ 39 | \item{command}{A \code{command} object.} 40 | 41 | \item{stdout, stderr}{Specifies how the output/error streams of the child 42 | process are handled. Possible values include: 43 | \itemize{ 44 | \item \code{FALSE}/\code{NULL}: Suppresses the output/error stream. 45 | \item \code{TRUE}: Prints the child process output/error to the R console. If a 46 | standard output/error stream exists, \code{""} is used; otherwise, \code{"|"} is 47 | used. 48 | \item \strong{string}: An empty string \code{""} inherits the standard output/error stream 49 | from the main R process (Printing in the R console). If the main R process 50 | lacks a standard output/error stream, such as in \code{RGui} on Windows, an 51 | error is thrown. A string \code{"|"} prints to the standard output connection 52 | of R process (Using \code{\link[=cat]{cat()}}). Alternative, a file name or path to 53 | redirect the output/error. If a relative path is specified, it remains 54 | relative to the current working directory, even if a different directory 55 | is set using \code{\link[=cmd_wd]{cmd_wd()}}. 56 | \item \code{connection}: A writable R \code{\link{connection}} object. If the connection is not 57 | \code{\link[=open]{open()}}, it will be automatically opened. 58 | } 59 | 60 | For \code{stderr}, use string \code{"2>&1"} to redirect it to the same connection (i.e. 61 | pipe or file) as \code{stdout}. 62 | 63 | For \code{cmd_help()}, use \code{FALSE}/\code{NULL} will do nothing, since it always want to 64 | display the help document. 65 | 66 | For \code{cmd_background()}, \code{connection} cannot be used, and \code{TRUE} and \code{"|"} 67 | will fallback to the empty string \code{""}. 68 | 69 | When using a \code{connection} (if not already open) or a \code{string}, wrapping it 70 | with \code{\link[=I]{I()}} prevents overwriting existing content.} 71 | 72 | \item{stdin}{should the input be diverted? Possible values include: 73 | \itemize{ 74 | \item \code{FALSE}/\code{NULL}: no standard input. 75 | \item \code{TRUE}: If a standard input stream exists, \code{""} is used; otherwise, \code{NULL} 76 | is used. 77 | \item \strong{string}: An empty string \code{""} inherits the standard input stream from 78 | the main R process. If the main R process lacks a standard input stream, 79 | such as in \code{RGui} on Windows, an error is thrown. Alternative, a file name 80 | or path to redirect the input. If a relative path is specified, it remains 81 | relative to the current working directory, even if a different directory 82 | is set using \code{\link[=cmd_wd]{cmd_wd()}}. 83 | }} 84 | 85 | \item{stdout_callback, stderr_callback}{Possible values include: 86 | \itemize{ 87 | \item \code{NULL}: no callback function. 88 | \item \code{function}: A function invoked for each line of standard output or error. 89 | Non-text (non-character) output will be ignored. The function should accept 90 | two arguments: one for the standard output or error and another for the 91 | running \code{\link[processx:process]{process}} object. 92 | }} 93 | 94 | \item{timeout}{Timeout in seconds. This is a limit for the elapsed time 95 | running command in the separate process.} 96 | 97 | \item{spinner}{Whether to show a reassuring spinner while the process 98 | is running.} 99 | 100 | \item{verbose}{A single boolean value indicating whether the command 101 | execution should be verbose.} 102 | } 103 | \value{ 104 | \itemize{ 105 | \item \code{cmd_run}: Exit status invisiblely. 106 | } 107 | 108 | \itemize{ 109 | \item \code{cmd_help}: The input \code{command} invisiblely. 110 | } 111 | 112 | \itemize{ 113 | \item \code{cmd_background}: A \code{\link[processx:process]{process}} object. 114 | } 115 | } 116 | \description{ 117 | \itemize{ 118 | \item \code{cmd_run}: Run the command. 119 | \item \code{cmd_help}: Print the help document for this command. 120 | \item \code{cmd_background}: Run the command in the background. This function is 121 | provided for completeness. Instead of using this function, we recommend 122 | using \code{\link[=cmd_parallel]{cmd_parallel()}}, which can run multiple commands in the background 123 | while ensuring that all processes are properly cleaned up when the process 124 | exits. 125 | } 126 | } 127 | \seealso{ 128 | \itemize{ 129 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 130 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 131 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 132 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /man/cmd_wd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-setup.R 3 | \name{cmd_wd} 4 | \alias{cmd_wd} 5 | \alias{cmd_envvar} 6 | \alias{cmd_envpath} 7 | \alias{cmd_condaenv} 8 | \title{Setup the context for the command} 9 | \usage{ 10 | cmd_wd(command, wd = NULL) 11 | 12 | cmd_envvar(command, ..., action = "replace", sep = NULL) 13 | 14 | cmd_envpath(command, ..., action = "prefix", name = "PATH") 15 | 16 | cmd_condaenv(command, ..., root = NULL, action = "prefix") 17 | } 18 | \arguments{ 19 | \item{command}{A \code{command} object.} 20 | 21 | \item{wd}{A string or \code{NULL} define the working directory of the command.} 22 | 23 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}>: 24 | \itemize{ 25 | \item \code{cmd_envvar}: Named character define the environment variables. 26 | \item \code{cmd_envpath}: Unnamed character to define the \code{PATH}-like environment 27 | variables \code{name}. 28 | \item \code{cmd_condaenv}: Unnamed character to specify the name of conda 29 | environment. 30 | }} 31 | 32 | \item{action}{Should the new values \code{"replace"}, \code{"prefix"} or \code{"suffix"} 33 | existing environment variables?} 34 | 35 | \item{sep}{A string to separate new and old value when \code{action} is \code{"prefix"} 36 | or \code{"suffix"}. By default, \code{" "} will be used.} 37 | 38 | \item{name}{A string define the PATH environment variable name. You 39 | can use this to define other \code{PATH}-like environment variable such as 40 | \code{PYTHONPATH}.} 41 | 42 | \item{root}{A string specifying the path to the conda root prefix. If not 43 | provided, the function searches for the root in the following order: 44 | \enumerate{ 45 | \item the \link{option} \code{blit.conda.root}. 46 | \item the \link[=Sys.getenv]{environment variable} \code{BLIT_CONDA_ROOT}. 47 | \item the root prefix of \code{\link[=appmamba]{appmamba()}}. 48 | }} 49 | } 50 | \value{ 51 | \itemize{ 52 | \item \code{cmd_wd}: The \code{command} object itself, with working directory updated. 53 | } 54 | 55 | \itemize{ 56 | \item \code{cmd_envvar}: The \code{command} object itself, with running environment 57 | variable updated. 58 | } 59 | 60 | \itemize{ 61 | \item \code{cmd_envpath}: The \code{command} object itself, with running environment 62 | variable specified in \code{name} updated. 63 | } 64 | 65 | \itemize{ 66 | \item \code{cmd_condaenv}: The \code{command} object itself, with running environment 67 | variable \code{PATH} updated. 68 | } 69 | } 70 | \description{ 71 | Setup the context for the command 72 | } 73 | \section{Functions}{ 74 | \itemize{ 75 | \item \code{cmd_wd()}: define the working directory. 76 | 77 | \item \code{cmd_envvar()}: define the environment variables. 78 | 79 | \item \code{cmd_envpath()}: define the \code{PATH}-like environment variables. 80 | 81 | \item \code{cmd_condaenv()}: Set \code{conda-like} environment prefix to the \code{PATH} 82 | environment variables. 83 | 84 | }} 85 | \seealso{ 86 | \itemize{ 87 | \item \code{\link[=cmd_run]{cmd_run()}}/\code{\link[=cmd_help]{cmd_help()}}/\code{\link[=cmd_background]{cmd_background()}} 88 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 89 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 90 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /man/conda.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-conda.R 3 | \name{conda} 4 | \alias{conda} 5 | \title{Run conda} 6 | \usage{ 7 | conda(subcmd = NULL, ..., conda = NULL) 8 | } 9 | \arguments{ 10 | \item{subcmd}{Sub-Command of conda.} 11 | 12 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{conda} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(conda())}.} 13 | 14 | \item{conda}{A string of path to \code{conda} command.} 15 | } 16 | \value{ 17 | A \code{command} object. 18 | } 19 | \description{ 20 | Run conda 21 | } 22 | \seealso{ 23 | \itemize{ 24 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 25 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 26 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 27 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 28 | } 29 | 30 | Other \code{commands}: 31 | \code{\link{allele_counter}()}, 32 | \code{\link{cellranger}()}, 33 | \code{\link{fastp}()}, 34 | \code{\link{fastq_pair}()}, 35 | \code{\link{gistic2}()}, 36 | \code{\link{kraken2}()}, 37 | \code{\link{kraken_tools}()}, 38 | \code{\link{perl}()}, 39 | \code{\link{pyscenic}()}, 40 | \code{\link{python}()}, 41 | \code{\link{samtools}()}, 42 | \code{\link{seqkit}()}, 43 | \code{\link{trust4}()} 44 | } 45 | \concept{command} 46 | -------------------------------------------------------------------------------- /man/exec.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-exec.R 3 | \name{exec} 4 | \alias{exec} 5 | \title{Invoke a System Command} 6 | \usage{ 7 | exec(cmd, ...) 8 | } 9 | \arguments{ 10 | \item{cmd}{Command to be invoked, as a character string.} 11 | 12 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{cmd} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}.} 13 | } 14 | \value{ 15 | A \code{command} object. 16 | } 17 | \description{ 18 | Invoke a System Command 19 | } 20 | \section{\code{command} collections}{ 21 | 22 | \itemize{ 23 | \item \code{\link[=allele_counter]{allele_counter()}} 24 | \item \code{\link[=cellranger]{cellranger()}} 25 | \item \code{\link[=conda]{conda()}} 26 | \item \code{\link[=fastp]{fastp()}} 27 | \item \code{\link[=fastq_pair]{fastq_pair()}} 28 | \item \code{\link[=gistic2]{gistic2()}} 29 | \item \code{\link[=kraken_tools]{kraken_tools()}} 30 | \item \code{\link[=kraken2]{kraken2()}} 31 | \item \code{\link[=perl]{perl()}} 32 | \item \code{\link[=pyscenic]{pyscenic()}} 33 | \item \code{\link[=python]{python()}} 34 | \item \code{\link[=samtools]{samtools()}} 35 | \item \code{\link[=seqkit]{seqkit()}} 36 | \item \code{\link[=trust4]{trust4()}} 37 | } 38 | } 39 | 40 | \examples{ 41 | cmd_run(exec("echo", "$PATH")) 42 | } 43 | \seealso{ 44 | \itemize{ 45 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 46 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 47 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 48 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /man/fastp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-fastp.R 3 | \name{fastp} 4 | \alias{fastp} 5 | \title{Run fastp} 6 | \usage{ 7 | fastp(fq1, ofile1, ..., fq2 = NULL, ofile2 = NULL, fastp = NULL) 8 | } 9 | \arguments{ 10 | \item{fq1, fq2}{A string of fastq file path.} 11 | 12 | \item{ofile1, ofile2}{A string of path to the output fastq file.} 13 | 14 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{fastp} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(fastp())}.} 15 | 16 | \item{fastp}{A string of path to \code{fastp} command.} 17 | } 18 | \value{ 19 | A \code{command} object. 20 | } 21 | \description{ 22 | The \code{fastp} is a tool designed to provide ultrafast all-in-one preprocessing 23 | and quality control for FastQ data. 24 | } 25 | \seealso{ 26 | \itemize{ 27 | \item \url{https://github.com/OpenGene/fastp} 28 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 29 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 30 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 31 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 32 | } 33 | 34 | Other \code{commands}: 35 | \code{\link{allele_counter}()}, 36 | \code{\link{cellranger}()}, 37 | \code{\link{conda}()}, 38 | \code{\link{fastq_pair}()}, 39 | \code{\link{gistic2}()}, 40 | \code{\link{kraken2}()}, 41 | \code{\link{kraken_tools}()}, 42 | \code{\link{perl}()}, 43 | \code{\link{pyscenic}()}, 44 | \code{\link{python}()}, 45 | \code{\link{samtools}()}, 46 | \code{\link{seqkit}()}, 47 | \code{\link{trust4}()} 48 | } 49 | \concept{command} 50 | -------------------------------------------------------------------------------- /man/fastq_pair.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-fastq_pair.R 3 | \name{fastq_pair} 4 | \alias{fastq_pair} 5 | \alias{fastq_read_pair} 6 | \title{FASTQ PAIR} 7 | \usage{ 8 | fastq_pair( 9 | fq1, 10 | fq2, 11 | ..., 12 | hash_table_size = NULL, 13 | max_hash_table_size = NULL, 14 | fastq_pair = NULL 15 | ) 16 | 17 | fastq_read_pair(fastq_files) 18 | } 19 | \arguments{ 20 | \item{fq1, fq2}{A string of fastq file path.} 21 | 22 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{fastq_pair} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(fastq_pair())}.} 23 | 24 | \item{hash_table_size}{Size of hash table to use.} 25 | 26 | \item{max_hash_table_size}{Maximal hash table size to use.} 27 | 28 | \item{fastq_pair}{A string of path to \code{fastq_pair} command.} 29 | 30 | \item{fastq_files}{A character of the fastq file paths.} 31 | } 32 | \value{ 33 | A \code{command} object. 34 | } 35 | \description{ 36 | Rewrite paired end fastq files to make sure that all reads have a mate and to 37 | separate out singletons. 38 | 39 | Usually when you get paired end read files you have two files with a /1 40 | sequence in one and a /2 sequence in the other (or a /f and /r or just two 41 | reads with the same ID). However, often when working with files from a third 42 | party source (e.g. the SRA) there are different numbers of reads in each file 43 | (because some reads fail QC). Spades, bowtie2 and other tools break because 44 | they demand paired end files have the same number of reads. 45 | } 46 | \seealso{ 47 | \itemize{ 48 | \item \url{https://github.com/linsalrob/fastq-pair} 49 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 50 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 51 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 52 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 53 | } 54 | 55 | Other \code{commands}: 56 | \code{\link{allele_counter}()}, 57 | \code{\link{cellranger}()}, 58 | \code{\link{conda}()}, 59 | \code{\link{fastp}()}, 60 | \code{\link{gistic2}()}, 61 | \code{\link{kraken2}()}, 62 | \code{\link{kraken_tools}()}, 63 | \code{\link{perl}()}, 64 | \code{\link{pyscenic}()}, 65 | \code{\link{python}()}, 66 | \code{\link{samtools}()}, 67 | \code{\link{seqkit}()}, 68 | \code{\link{trust4}()} 69 | } 70 | \concept{command} 71 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WangLabCSU/blit/576fea4b23e411523e0109d417c5e17abfb0078e/man/figures/logo.png -------------------------------------------------------------------------------- /man/gistic2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-gistic2.R 3 | \name{gistic2} 4 | \alias{gistic2} 5 | \title{Run GISTIC2} 6 | \usage{ 7 | gistic2(seg, refgene, ..., odir = getwd(), gistic2 = NULL) 8 | } 9 | \arguments{ 10 | \item{seg}{A data.frame of segmented data.} 11 | 12 | \item{refgene}{Path to reference genome data input file (REQUIRED, see below 13 | for file description).} 14 | 15 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{gistic2} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(gistic2())}.} 16 | 17 | \item{odir}{A string of path to the output directory.} 18 | 19 | \item{gistic2}{A string of path to \code{gistic2} command.} 20 | } 21 | \value{ 22 | A \code{command} object. 23 | } 24 | \description{ 25 | The GISTIC module identifies regions of the genome that are 26 | significantly amplified or deleted across a set of samples. Each aberration 27 | is assigned a G-score that considers the amplitude of the aberration as well 28 | as the frequency of its occurrence across samples. False Discovery Rate 29 | q-values are then calculated for the aberrant regions, and regions with 30 | q-values below a user-defined threshold are considered significant. For each 31 | significant region, a "peak region" is identified, which is the part of the 32 | aberrant region with greatest amplitude and frequency of alteration. In 33 | addition, a "wide peak" is determined using a leave-one-out algorithm to 34 | allow for errors in the boundaries in a single sample. The "wide peak" 35 | boundaries are more robust for identifying the most likely gene targets in 36 | the region. Each significantly aberrant region is also tested to determine 37 | whether it results primarily from broad events (longer than half a chromosome 38 | arm), focal events, or significant levels of both. The GISTIC module reports 39 | the genomic locations and calculated q-values for the aberrant regions. It 40 | identifies the samples that exhibit each significant amplification or 41 | deletion, and it lists genes found in each "wide peak" region. 42 | } 43 | \seealso{ 44 | \itemize{ 45 | \item \url{https://broadinstitute.github.io/gistic2/} 46 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 47 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 48 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 49 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 50 | } 51 | 52 | Other \code{commands}: 53 | \code{\link{allele_counter}()}, 54 | \code{\link{cellranger}()}, 55 | \code{\link{conda}()}, 56 | \code{\link{fastp}()}, 57 | \code{\link{fastq_pair}()}, 58 | \code{\link{kraken2}()}, 59 | \code{\link{kraken_tools}()}, 60 | \code{\link{perl}()}, 61 | \code{\link{pyscenic}()}, 62 | \code{\link{python}()}, 63 | \code{\link{samtools}()}, 64 | \code{\link{seqkit}()}, 65 | \code{\link{trust4}()} 66 | } 67 | \concept{command} 68 | -------------------------------------------------------------------------------- /man/kraken2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-kraken2.R 3 | \name{kraken2} 4 | \alias{kraken2} 5 | \title{Running Kraken2} 6 | \usage{ 7 | kraken2( 8 | fq1, 9 | ..., 10 | fq2 = NULL, 11 | ofile = "kraken_output.txt", 12 | report = "kraken_report.txt", 13 | classified_out = NULL, 14 | unclassified_out = NULL, 15 | odir = getwd(), 16 | kraken2 = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{fq1, fq2}{A string of fastq file path.} 21 | 22 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{kraken2} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(kraken2())}.} 23 | 24 | \item{ofile}{A string of path to save kraken2 output.} 25 | 26 | \item{report}{A string of path to save kraken2 report.} 27 | 28 | \item{classified_out}{A string of path to save classified sequences, which 29 | should be a fastq file.} 30 | 31 | \item{unclassified_out}{A string of path to save unclassified sequences, 32 | which should be a fastq file.} 33 | 34 | \item{odir}{A string of path to the output directory.} 35 | 36 | \item{kraken2}{A string of path to \code{kraken2} command.} 37 | } 38 | \value{ 39 | A \code{command} object. 40 | } 41 | \description{ 42 | Kraken is a taxonomic sequence classifier that assigns taxonomic labels to 43 | DNA sequences. Kraken examines the k-mers within a query sequence and uses 44 | the information within those k-mers to query a database. That database maps 45 | k-mers to the lowest common ancestor (LCA) of all genomes known to contain a 46 | given k-mer. 47 | } 48 | \seealso{ 49 | \itemize{ 50 | \item \url{https://github.com/DerrickWood/kraken2/wiki/Manual} 51 | \item \url{https://benlangmead.github.io/aws-indexes/k2} 52 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 53 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 54 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 55 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 56 | } 57 | 58 | Other \code{commands}: 59 | \code{\link{allele_counter}()}, 60 | \code{\link{cellranger}()}, 61 | \code{\link{conda}()}, 62 | \code{\link{fastp}()}, 63 | \code{\link{fastq_pair}()}, 64 | \code{\link{gistic2}()}, 65 | \code{\link{kraken_tools}()}, 66 | \code{\link{perl}()}, 67 | \code{\link{pyscenic}()}, 68 | \code{\link{python}()}, 69 | \code{\link{samtools}()}, 70 | \code{\link{seqkit}()}, 71 | \code{\link{trust4}()} 72 | } 73 | \concept{command} 74 | -------------------------------------------------------------------------------- /man/kraken_tools.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-kraken2-tools.R 3 | \name{kraken_tools} 4 | \alias{kraken_tools} 5 | \title{KrakenTools is a suite of scripts to be used alongside the Kraken, 6 | KrakenUniq, Kraken 2, or Bracken programs.} 7 | \usage{ 8 | kraken_tools(script, ..., python = NULL) 9 | } 10 | \arguments{ 11 | \item{script}{Name of the kraken2 script. One of 12 | \code{"combine_kreports"}, \code{"combine_mpa"}, \code{"extract_kraken_reads"}, \code{"filter_bracken_out"}, \code{"fix_unmapped"}, \code{"kreport2krona"}, \code{"kreport2mpa"}, \code{"make_kreport"}, and \code{"make_ktaxonomy"}.} 13 | 14 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{kraken_tools} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(kraken_tools())}.} 15 | 16 | \item{python}{A string of path to \code{python} command.} 17 | } 18 | \value{ 19 | A \code{command} object. 20 | } 21 | \description{ 22 | These scripts are designed to help Kraken users with downstream 23 | analysis of Kraken results. 24 | } 25 | \seealso{ 26 | \itemize{ 27 | \item \url{https://github.com/jenniferlu717/KrakenTools} 28 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 29 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 30 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 31 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 32 | } 33 | 34 | Other \code{commands}: 35 | \code{\link{allele_counter}()}, 36 | \code{\link{cellranger}()}, 37 | \code{\link{conda}()}, 38 | \code{\link{fastp}()}, 39 | \code{\link{fastq_pair}()}, 40 | \code{\link{gistic2}()}, 41 | \code{\link{kraken2}()}, 42 | \code{\link{perl}()}, 43 | \code{\link{pyscenic}()}, 44 | \code{\link{python}()}, 45 | \code{\link{samtools}()}, 46 | \code{\link{seqkit}()}, 47 | \code{\link{trust4}()} 48 | } 49 | \concept{command} 50 | -------------------------------------------------------------------------------- /man/make_command.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-.R 3 | \name{make_command} 4 | \alias{make_command} 5 | \title{Helper function to create new command.} 6 | \usage{ 7 | make_command(name, fun, envir = caller_env()) 8 | } 9 | \arguments{ 10 | \item{name}{A string of the function name.} 11 | 12 | \item{fun}{A function used to initialize the \code{\link{Command}} object.} 13 | 14 | \item{envir}{A environment used to bind the created function.} 15 | } 16 | \value{ 17 | A function. 18 | } 19 | \description{ 20 | \code{make_command} is a helper function used by developers to create function for 21 | a new \code{\link{Command}} object. It should not be used by end users. 22 | } 23 | \seealso{ 24 | \code{\link{Command}} 25 | } 26 | -------------------------------------------------------------------------------- /man/perl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-perl.R 3 | \name{perl} 4 | \alias{perl} 5 | \title{Perl is a highly capable, feature-rich programming language with over 36 6 | years of development.} 7 | \usage{ 8 | perl(..., perl = NULL) 9 | } 10 | \arguments{ 11 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{perl} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(perl())}.} 12 | 13 | \item{perl}{A string of path to \code{perl} command.} 14 | } 15 | \value{ 16 | A \code{command} object. 17 | } 18 | \description{ 19 | Perl is a highly capable, feature-rich programming language with over 36 20 | years of development. 21 | } 22 | \seealso{ 23 | \itemize{ 24 | \item \url{https://www.perl.org/} 25 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 26 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 27 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 28 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 29 | } 30 | 31 | Other \code{commands}: 32 | \code{\link{allele_counter}()}, 33 | \code{\link{cellranger}()}, 34 | \code{\link{conda}()}, 35 | \code{\link{fastp}()}, 36 | \code{\link{fastq_pair}()}, 37 | \code{\link{gistic2}()}, 38 | \code{\link{kraken2}()}, 39 | \code{\link{kraken_tools}()}, 40 | \code{\link{pyscenic}()}, 41 | \code{\link{python}()}, 42 | \code{\link{samtools}()}, 43 | \code{\link{seqkit}()}, 44 | \code{\link{trust4}()} 45 | } 46 | \concept{command} 47 | -------------------------------------------------------------------------------- /man/pyscenic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-pyscenic.R 3 | \name{pyscenic} 4 | \alias{pyscenic} 5 | \title{Run pyscenic} 6 | \usage{ 7 | pyscenic(subcmd = NULL, ..., pyscenic = NULL) 8 | } 9 | \arguments{ 10 | \item{subcmd}{Sub-Command of pyscenic.} 11 | 12 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \verb{pyscenic subcmd} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \verb{cmd_help(pyscenic subcmd())}.} 13 | 14 | \item{pyscenic}{A string of path to \code{pyscenic} command.} 15 | } 16 | \value{ 17 | A \code{command} object. 18 | } 19 | \description{ 20 | Run pyscenic 21 | } 22 | \seealso{ 23 | \itemize{ 24 | \item \url{https://github.com/aertslab/pySCENIC} 25 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 26 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 27 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 28 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 29 | } 30 | 31 | Other \code{commands}: 32 | \code{\link{allele_counter}()}, 33 | \code{\link{cellranger}()}, 34 | \code{\link{conda}()}, 35 | \code{\link{fastp}()}, 36 | \code{\link{fastq_pair}()}, 37 | \code{\link{gistic2}()}, 38 | \code{\link{kraken2}()}, 39 | \code{\link{kraken_tools}()}, 40 | \code{\link{perl}()}, 41 | \code{\link{python}()}, 42 | \code{\link{samtools}()}, 43 | \code{\link{seqkit}()}, 44 | \code{\link{trust4}()} 45 | } 46 | \concept{command} 47 | -------------------------------------------------------------------------------- /man/python.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-python.R 3 | \name{python} 4 | \alias{python} 5 | \title{Python is a programming language that lets you work quickly and integrate 6 | systems more effectively.} 7 | \usage{ 8 | python(..., python = NULL) 9 | } 10 | \arguments{ 11 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{python} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(python())}.} 12 | 13 | \item{python}{A string of path to \code{python} command.} 14 | } 15 | \value{ 16 | A \code{command} object. 17 | } 18 | \description{ 19 | Python is a programming language that lets you work quickly and integrate 20 | systems more effectively. 21 | } 22 | \seealso{ 23 | \itemize{ 24 | \item \url{https://www.python.org/} 25 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 26 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 27 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 28 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 29 | } 30 | 31 | Other \code{commands}: 32 | \code{\link{allele_counter}()}, 33 | \code{\link{cellranger}()}, 34 | \code{\link{conda}()}, 35 | \code{\link{fastp}()}, 36 | \code{\link{fastq_pair}()}, 37 | \code{\link{gistic2}()}, 38 | \code{\link{kraken2}()}, 39 | \code{\link{kraken_tools}()}, 40 | \code{\link{perl}()}, 41 | \code{\link{pyscenic}()}, 42 | \code{\link{samtools}()}, 43 | \code{\link{seqkit}()}, 44 | \code{\link{trust4}()} 45 | } 46 | \concept{command} 47 | -------------------------------------------------------------------------------- /man/roxygen/meta.R: -------------------------------------------------------------------------------- 1 | list( 2 | rd_family_title = list(command = "Other \\code{commands}:") 3 | ) 4 | -------------------------------------------------------------------------------- /man/samtools.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-samtools.R 3 | \name{samtools} 4 | \alias{samtools} 5 | \title{Python is a programming language that lets you work quickly and integrate 6 | systems more effectively.} 7 | \usage{ 8 | samtools(subcmd = NULL, ..., samtools = NULL) 9 | } 10 | \arguments{ 11 | \item{subcmd}{Sub-Command of samtools. Details see: \code{cmd_help(samtools())}.} 12 | 13 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{samtools} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(samtools())}.} 14 | 15 | \item{samtools}{A string of path to \code{samtools} command.} 16 | } 17 | \value{ 18 | A \code{command} object. 19 | } 20 | \description{ 21 | Python is a programming language that lets you work quickly and integrate 22 | systems more effectively. 23 | } 24 | \seealso{ 25 | \itemize{ 26 | \item \url{https://www.htslib.org/} 27 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 28 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 29 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 30 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 31 | } 32 | 33 | Other \code{commands}: 34 | \code{\link{allele_counter}()}, 35 | \code{\link{cellranger}()}, 36 | \code{\link{conda}()}, 37 | \code{\link{fastp}()}, 38 | \code{\link{fastq_pair}()}, 39 | \code{\link{gistic2}()}, 40 | \code{\link{kraken2}()}, 41 | \code{\link{kraken_tools}()}, 42 | \code{\link{perl}()}, 43 | \code{\link{pyscenic}()}, 44 | \code{\link{python}()}, 45 | \code{\link{seqkit}()}, 46 | \code{\link{trust4}()} 47 | } 48 | \concept{command} 49 | -------------------------------------------------------------------------------- /man/seqkit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-seqkit.R 3 | \name{seqkit} 4 | \alias{seqkit} 5 | \title{Run seqkit} 6 | \usage{ 7 | seqkit(subcmd = NULL, ..., seqkit = NULL) 8 | } 9 | \arguments{ 10 | \item{subcmd}{Sub-Command of seqkit.} 11 | 12 | \item{...}{<\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \verb{seqkit subcmd} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \verb{cmd_help(seqkit subcmd())}.} 13 | 14 | \item{seqkit}{A string of path to \code{seqkit} command.} 15 | } 16 | \value{ 17 | A \code{command} object. 18 | } 19 | \description{ 20 | Run seqkit 21 | } 22 | \seealso{ 23 | \itemize{ 24 | \item \url{https://bioinf.shenwei.me/seqkit/} 25 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 26 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 27 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 28 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 29 | } 30 | 31 | Other \code{commands}: 32 | \code{\link{allele_counter}()}, 33 | \code{\link{cellranger}()}, 34 | \code{\link{conda}()}, 35 | \code{\link{fastp}()}, 36 | \code{\link{fastq_pair}()}, 37 | \code{\link{gistic2}()}, 38 | \code{\link{kraken2}()}, 39 | \code{\link{kraken_tools}()}, 40 | \code{\link{perl}()}, 41 | \code{\link{pyscenic}()}, 42 | \code{\link{python}()}, 43 | \code{\link{samtools}()}, 44 | \code{\link{trust4}()} 45 | } 46 | \concept{command} 47 | -------------------------------------------------------------------------------- /man/trust4.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmd-trust4.R 3 | \name{trust4} 4 | \alias{trust4} 5 | \alias{trust4_imgt_annot} 6 | \alias{trust4_gene_names} 7 | \title{TRUST4: immune repertoire reconstruction from bulk and single-cell RNA-seq 8 | data} 9 | \usage{ 10 | trust4( 11 | file1, 12 | ref_coordinate, 13 | ..., 14 | file2 = NULL, 15 | mode = NULL, 16 | ref_annot = NULL, 17 | ofile = NULL, 18 | odir = getwd(), 19 | trust4 = NULL 20 | ) 21 | 22 | trust4_imgt_annot( 23 | species = "Homo_sapien", 24 | ..., 25 | ofile = "IMGT+C.fa", 26 | odir = getwd(), 27 | perl = NULL 28 | ) 29 | 30 | trust4_gene_names(imgt_annot, ofile = "bcr_tcr_gene_name.txt", odir = getwd()) 31 | } 32 | \arguments{ 33 | \item{file1}{Path to bam file or fastq file.} 34 | 35 | \item{ref_coordinate}{Path to the fasta file coordinate and sequence of 36 | V/D/J/C genes.} 37 | 38 | \item{...}{\itemize{ 39 | \item \code{trust4}: <\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{run-trust4} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(run-trust4())}. 40 | \item \code{trust4_imgt_annot}: <\link[rlang:dyn-dots]{dynamic dots}> Additional arguments passed to \code{trust4_imgt_annot} command. Empty arguments are automatically trimmed. If a single argument, such as a file path, contains spaces, it must be quoted, for example using \code{\link[=shQuote]{shQuote()}}. Details see: \code{cmd_help(trust4_imgt_annot())}. 41 | }} 42 | 43 | \item{file2}{Path to the second paired-end read fastq file, only used for 44 | \code{mode = "fastq"}.} 45 | 46 | \item{mode}{One of "bam" or "fastq". If \code{NULL}, will be inferred from 47 | \code{file1}.} 48 | 49 | \item{ref_annot}{Path to detailed V/D/J/C gene reference file, such as from 50 | IMGT database. (default: not used). (recommended).} 51 | 52 | \item{ofile}{\itemize{ 53 | \item \code{trust4}: Prefix of output files. (default: inferred from file prefix). 54 | \item \code{trust4_imgt_annot}: Output file name. 55 | \item \code{trust4_gene_names}: Output file name. 56 | }} 57 | 58 | \item{odir}{A string of path to the output directory.} 59 | 60 | \item{trust4}{A string of path to \code{run-trust4} command.} 61 | 62 | \item{species}{Species to extract IMGT annotation, details see 63 | \url{https://www.imgt.org//download/V-QUEST/IMGT_V-QUEST_reference_directory/}.} 64 | 65 | \item{perl}{A string of path to \code{perl} command.} 66 | 67 | \item{imgt_annot}{Path of IMGT annotation file, created via 68 | \code{trust4_imgt_annot}.} 69 | } 70 | \value{ 71 | A \code{command} object. 72 | } 73 | \description{ 74 | TRUST4: immune repertoire reconstruction from bulk and single-cell RNA-seq 75 | data 76 | } 77 | \seealso{ 78 | \itemize{ 79 | \item \url{https://github.com/liulab-dfci/TRUST4} 80 | \item \code{\link[=cmd_wd]{cmd_wd()}}/\code{\link[=cmd_envvar]{cmd_envvar()}}/\code{\link[=cmd_envpath]{cmd_envpath()}}/\code{\link[=cmd_condaenv]{cmd_condaenv()}} 81 | \item \code{\link[=cmd_on_start]{cmd_on_start()}}/\code{\link[=cmd_on_exit]{cmd_on_exit()}} 82 | \item \code{\link[=cmd_on_succeed]{cmd_on_succeed()}}/\code{\link[=cmd_on_fail]{cmd_on_fail()}} 83 | \item \code{\link[=cmd_parallel]{cmd_parallel()}} 84 | } 85 | 86 | Other \code{commands}: 87 | \code{\link{allele_counter}()}, 88 | \code{\link{cellranger}()}, 89 | \code{\link{conda}()}, 90 | \code{\link{fastp}()}, 91 | \code{\link{fastq_pair}()}, 92 | \code{\link{gistic2}()}, 93 | \code{\link{kraken2}()}, 94 | \code{\link{kraken_tools}()}, 95 | \code{\link{perl}()}, 96 | \code{\link{pyscenic}()}, 97 | \code{\link{python}()}, 98 | \code{\link{samtools}()}, 99 | \code{\link{seqkit}()} 100 | } 101 | \concept{command} 102 | -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | checks.noindex 4 | library.noindex 5 | cloud.noindex 6 | data.sqlite 7 | *.html 8 | -------------------------------------------------------------------------------- /revdep/README.md: -------------------------------------------------------------------------------- 1 | # Platform 2 | 3 | |field |value | 4 | |:--------|:----------------------------| 5 | |version |R version 4.4.2 (2024-10-31) | 6 | |os |Ubuntu 24.04.1 LTS | 7 | |system |x86_64, linux-gnu | 8 | |ui |X11 | 9 | |language |en | 10 | |collate |C.UTF-8 | 11 | |ctype |C.UTF-8 | 12 | |tz |Asia/Shanghai | 13 | |date |2025-03-29 | 14 | |pandoc |3.1.3 @ /usr/bin/pandoc | 15 | 16 | # Dependencies 17 | 18 | |package |old |new |Δ | 19 | |:----------|:------|:----------|:--| 20 | |blit |0.1.0 |0.1.0.9000 |* | 21 | |cli |3.6.4 |3.6.4 | | 22 | |data.table |1.17.0 |NA |* | 23 | |processx |NA |3.8.6 |* | 24 | |ps |NA |1.9.0 |* | 25 | |R6 |2.6.1 |2.6.1 | | 26 | |rlang |1.1.5 |1.1.5 | | 27 | |sys |3.4.3 |NA |* | 28 | |withr |3.0.2 |NA |* | 29 | 30 | # Revdeps 31 | 32 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 1 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 4 | 5 | * We saw 0 new problems 6 | * We failed to check 0 packages 7 | 8 | -------------------------------------------------------------------------------- /revdep/failures.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /revdep/problems.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/tests.html 7 | # * https://testthat.r-lib.org/reference/test_package.html#special-files 8 | 9 | library(testthat) 10 | library(blit) 11 | 12 | test_check("blit") 13 | -------------------------------------------------------------------------------- /tests/testthat/test-exec.R: -------------------------------------------------------------------------------- 1 | testthat::test_that("`allele_counter()` works as expected", { 2 | testthat::skip_if_not(nzchar(Sys.which("alleleCounter"))) 3 | allele_counter() |> cmd_help() 4 | }) 5 | 6 | testthat::test_that("`cellranger()` works as expected", { 7 | testthat::skip_if_not(nzchar(Sys.which("cellranger"))) 8 | cellranger() |> cmd_help() 9 | }) 10 | 11 | testthat::test_that("`fastq_pair()` works as expected", { 12 | testthat::skip_if_not(nzchar(Sys.which("fastq_pair"))) 13 | fastq_pair() |> cmd_help() 14 | }) 15 | 16 | testthat::test_that("`gistic2()` works as expected", { 17 | testthat::skip_if_not(nzchar(Sys.which("gistic2"))) 18 | gistic2() |> cmd_help() 19 | }) 20 | 21 | testthat::test_that("`kraken_tools()` works as expected", { 22 | testthat::skip_if_not( 23 | nzchar(Sys.which("python2")) || nzchar(Sys.which("python3")) 24 | ) 25 | for (script in KrakenToolsScripts) { 26 | kraken_tools(script) |> cmd_help() 27 | } 28 | }) 29 | 30 | testthat::test_that("`kraken2()` works as expected", { 31 | testthat::skip_if_not(nzchar(Sys.which("kraken2"))) 32 | kraken2() |> cmd_help() 33 | }) 34 | 35 | testthat::test_that("`perl()` works as expected", { 36 | testthat::skip_if_not(nzchar(Sys.which("perl"))) 37 | perl() |> cmd_help() 38 | }) 39 | 40 | testthat::test_that("`python()` works as expected", { 41 | testthat::skip_if_not( 42 | nzchar(Sys.which("python2")) || nzchar(Sys.which("python3")) 43 | ) 44 | python() |> cmd_help() 45 | }) 46 | 47 | testthat::test_that("`seqkit()` works as expected", { 48 | testthat::skip_if_not(nzchar(Sys.which("seqkit"))) 49 | seqkit() |> cmd_help() 50 | }) 51 | 52 | testthat::test_that("`trust4()` works as expected", { 53 | testthat::skip_if_not(nzchar(Sys.which("run-trust4"))) 54 | trust4() |> cmd_help() 55 | }) 56 | 57 | testthat::test_that("`pipe()` method works well", { 58 | tmpdir <- tempdir() 59 | file <- tempfile(tmpdir = tmpdir) 60 | write_lines(letters, path = file) 61 | on.exit(file.remove(file)) 62 | file2 <- tempfile() 63 | on.exit(file.remove(file2), add = TRUE) 64 | exec("gzip", "-c", file) |> 65 | exec("gzip", "-d", ">", file2) |> 66 | cmd_run() 67 | testthat::expect_identical(read_lines(file), read_lines(file2)) 68 | }) 69 | -------------------------------------------------------------------------------- /tests/testthat/test-processx.R: -------------------------------------------------------------------------------- 1 | testthat::test_that("`BlitProcess` stdin works well", { 2 | proc <- BlitProcess$new("echo", "blit is awesome", stdin = FALSE) 3 | on.exit(proc$.blit_kill(), add = TRUE) 4 | testthat::expect_identical(proc$get_input_file(), NULL) 5 | proc2 <- BlitProcess$new("echo", "blit is awesome", stdin = TRUE) 6 | on.exit(proc2$.blit_kill(), add = TRUE) 7 | if (processx::is_valid_fd(0L)) { 8 | testthat::expect_identical(proc2$get_input_file(), "") 9 | } else { 10 | testthat::expect_identical(proc2$get_input_file(), NULL) 11 | } 12 | }) 13 | 14 | testthat::test_that("`BlitProcess` stdout works well", { 15 | # FALSE 16 | proc <- BlitProcess$new("echo", "blit is awesome", stdout = FALSE) 17 | on.exit(proc$.blit_kill(), add = TRUE) 18 | testthat::expect_identical(proc$get_output_file(), NULL) 19 | 20 | # TRUE 21 | proc2 <- BlitProcess$new("echo", "blit is awesome", stdout = TRUE) 22 | on.exit(proc2$.blit_kill(), add = TRUE) 23 | if (processx::is_valid_fd(1L)) { 24 | testthat::expect_identical(proc2$get_output_file(), "") 25 | } else { 26 | testthat::expect_identical(proc2$get_output_file(), NULL) 27 | } 28 | 29 | # `TRUE` and `callback` 30 | proc3 <- BlitProcess$new( 31 | "echo", "blit is awesome", 32 | stdout = TRUE, 33 | .blit_stdout_callback = function(lines, proc) lines 34 | ) 35 | on.exit(proc3$.blit_kill(), add = TRUE) 36 | testthat::expect_identical(proc3$get_output_file(), "|") 37 | 38 | # `file` and `callback` 39 | tmp <- tempfile() 40 | proc4 <- BlitProcess$new( 41 | "echo", "blit is awesome", 42 | stdout = tmp, 43 | .blit_stdout_callback = function(lines, proc) lines 44 | ) 45 | on.exit(proc4$.blit_kill(), add = TRUE) 46 | on.exit(file.remove(tmp), add = TRUE) 47 | testthat::expect_identical(proc4$get_output_file(), "|") 48 | proc4$.blit_run() 49 | testthat::expect_identical(readLines(tmp), "blit is awesome") 50 | }) 51 | 52 | testthat::test_that("`BlitProcess` stderr works well", { 53 | # FALSE 54 | proc <- BlitProcess$new("echo", "blit is awesome", stderr = FALSE) 55 | on.exit(proc$.blit_kill(), add = TRUE) 56 | testthat::expect_identical(proc$get_error_file(), NULL) 57 | 58 | # TRUE 59 | proc2 <- BlitProcess$new("echo", "blit is awesome", stderr = TRUE) 60 | on.exit(proc2$.blit_kill(), add = TRUE) 61 | if (processx::is_valid_fd(2L)) { 62 | testthat::expect_identical(proc2$get_error_file(), "") 63 | } else { 64 | testthat::expect_identical(proc2$get_error_file(), NULL) 65 | } 66 | 67 | # `TRUE` and `callback` 68 | proc3 <- BlitProcess$new( 69 | "echo", "blit is awesome", 70 | stderr = TRUE, 71 | .blit_stderr_callback = function(lines, proc) lines 72 | ) 73 | on.exit(proc3$.blit_kill(), add = TRUE) 74 | testthat::expect_identical(proc3$get_error_file(), "|") 75 | 76 | # `file` and `callback` 77 | tmp <- tempfile() 78 | proc4 <- BlitProcess$new( 79 | "echo", "blit is awesome", 80 | stderr = tmp, 81 | .blit_stderr_callback = function(lines, proc) lines 82 | ) 83 | on.exit(proc4$.blit_kill(), add = TRUE) 84 | on.exit(file.remove(tmp), add = TRUE) 85 | testthat::expect_identical(proc4$get_error_file(), "|") 86 | proc4$.blit_run() 87 | testthat::expect_identical(readLines(tmp), character()) 88 | }) 89 | -------------------------------------------------------------------------------- /tests/testthat/test-utils.R: -------------------------------------------------------------------------------- 1 | testthat::test_that("`utils-file` works well", { 2 | # remove extension 3 | testthat::expect_identical(path_ext_remove("a.b"), "a") 4 | testthat::expect_identical(path_ext_remove("a.b.c"), "a.b") 5 | testthat::expect_identical(path_ext_remove("a."), "a") 6 | 7 | # set extension 8 | testthat::expect_identical(path_ext_set("a", "b"), "a.b") 9 | testthat::expect_identical(path_ext_set("a.b", "c"), "a.c") 10 | testthat::expect_identical(path_ext_set("a.", "b"), "a.b") 11 | 12 | # extract extension 13 | testthat::expect_identical(path_ext("a.b"), "b") 14 | testthat::expect_identical(path_ext("a.b.c"), "c") 15 | testthat::expect_identical(path_ext("a."), "") 16 | }) 17 | 18 | testthat::test_that("`read_lines2()` workds as expected", { 19 | # prepare file 20 | testthat::skip_if(.Platform$OS.type == "windows") 21 | tmpdir <- tempdir() 22 | file <- tempfile(tmpdir = tmpdir) 23 | write_lines(letters, path = file) 24 | on.exit(file.remove(file)) 25 | # gzip compressed file 26 | gzip_file <- paste(file, "gz", sep = ".") 27 | exec("gzip", "-c", file, ">", gzip_file) |> cmd_run() 28 | testthat::expect_identical(read_lines2(gzip_file), letters) 29 | file.remove(gzip_file) 30 | 31 | # bzip2 compressed file 32 | bzip2_file <- paste(file, "bz", sep = ".") 33 | exec("gzip", "-c", file, ">", bzip2_file) |> cmd_run() 34 | testthat::expect_identical(read_lines2(bzip2_file), letters) 35 | file.remove(bzip2_file) 36 | 37 | # xz compressed file 38 | xz_file <- paste(file, "xz", sep = ".") 39 | exec("gzip", "-c", file, ">", xz_file) |> cmd_run() 40 | testthat::expect_identical(read_lines2(xz_file), letters) 41 | file.remove(xz_file) 42 | }) 43 | --------------------------------------------------------------------------------