Fast reverse complement of DNA and RNA sequences in R, implemented in C++ via Rcpp.
fastrc uses a static lookup table for O(1) per-base complement mapping with full IUPAC ambiguity code support. It is especially useful for reverse complementing many short sequences (e.g. primers, probes, k-mers, short reads), where per-call overhead dominates and fastrc is nearly 100x faster than the implementation
in Biostrings.
# From GitHub
# devtools::install_github("steverozen/fastrc")
install.packages("fastrc", repos = c('https://steverozen.r-universe.dev', 'https://cloud.r-project.org'))
library(fastrc)
fast_rc("ATCG")
#> [1] "CGAT"
fast_rc(c("ATCG", "AAGG", NA))
#> [1] "CGAT" "CCTT" NA
fast_rc("AUCG", type = "RNA")
#> [1] "CGAU"
Benchmarks were run on a 12th Gen Intel i7-1270P using R's default
compilation flags (-O2). See inst/benchmarks/benchmark_revc.R to
reproduce.
This is where you may really want to use fastrc: many short sequences
where per-call overhead matters most.
| Method | Median | vs fastrc |
|---|---|---|
| fastrc | 17 µs | 1x |
| spgs | 619 µs | 36x slower |
| insect | 1,031 µs | 61x slower |
| Biostrings | 1,613 µs | 95x slower |
| tktools | 3,277 µs | 193x slower |
| Method | Median | vs fastrc |
|---|---|---|
| fastrc | 1.4 ms | 1x |
| Biostrings | 3.4 ms | 2.4x slower |
| Method | Median | vs fastrc |
|---|---|---|
| fastrc | 14.2 ms | 1x |
| Biostrings | 23.8 ms | 1.7x slower |
You can get additional speed by adding optimization flags to your
~/.R/Makevars file:
CXXFLAGS += -O3 -march=native -flto
Then reinstall the package. This typically yields a 10-20% improvement on longer sequences.
GPL (>= 3)