Created
September 21, 2019 16:35
-
-
Save dnanto/e6b0bb620775ca30eab43cd0058ce0bd to your computer and use it in GitHub Desktop.
decode mutations from BTOP string in R (uses tidyverse)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not sure if it is possible to vectorize due to loop-dependency...