In R, what is the best way of finding dots flanked by asterisks and replace them with asterisks?
input:
"AG**...**GG*.*.G.*C.C"
desired output:
"AG*******GG***.G.*C.C"
I tried the following function, but it is not elegant to say the least.
    library(stringr)
    replac <- function(my_string) {
        m <- str_locate_all(my_string, "\\*\\.+\\*")[[1]]
        if (nrow(m) == 0) return(my_string)
        split_s <- unlist(str_split(my_string, "")) 
        for (i in 1:nrow(m)) {
            st <- m[i, 1]
            en <- m[i, 2] 
            split_s[st:en] <- rep("*", length(st:en))
        }
        paste(split_s, collapse = "")
    }
- I've have edited the input string and expected output after @TheForthBird answer below to make clear that dots not flanked by asterisks should not be changed, and that other letters other and "A" and "G" may occur.
 
     
    