Skip to content

Instantly share code, notes, and snippets.

@dnanto
Created December 31, 2019 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnanto/c0b4ad65b70057554477822b5a6926e2 to your computer and use it in GitHub Desktop.
Save dnanto/c0b4ad65b70057554477822b5a6926e2 to your computer and use it in GitHub Desktop.
calculate the reverse complement of a BTOP string (uses tidyverse)
comp <- set_names(
as.list(str_split("TAACGRYSWMKVHDBN", "", simplify = 1)),
str_split("ATUGCYRSWKMBDHVN", "", simplify = T)
)
revcomp_btop <- function(btop)
{
str_replace_all(btop, "([A-Z-])([A-Z-])", " \\2 \\1 ") %>%
str_split(" ", simplify = T) %>%
rev() %>%
sapply(function(ele) { code <- comp[[ele]]; ifelse(is.null(code), ele, code); }, USE.NAMES = F) %>%
str_c(collapse = "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment