Skip to content

Instantly share code, notes, and snippets.

@dnanto
Created September 21, 2019 16:35
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/e6b0bb620775ca30eab43cd0058ce0bd to your computer and use it in GitHub Desktop.
Save dnanto/e6b0bb620775ca30eab43cd0058ce0bd to your computer and use it in GitHub Desktop.
decode mutations from BTOP string in R (uses tidyverse)
decode_btop <- function(btop)
{
matches <- as.integer(str_extract_all(btop, "\\d+", simplify = T))
matches <- if (str_starts(btop, "\\d", negate = T)) c(0, matches) else matches
pos <- 0; n <- 0; m <- 0; muts <- list();
for (ele in Filter(nchar, str_split(btop, "\\d+", simplify = T)))
{
pos <- pos + matches[n<-n+1]
for (i in seq(1, nchar(ele), 2)) muts[[m<-m+1]] <- list(pos = pos<-pos+1, mut = substr(ele, i, i+1))
}
muts
}
@dnanto
Copy link
Author

dnanto commented Sep 21, 2019

not sure if it is possible to vectorize due to loop-dependency...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment