R/translate.R

Defines functions translate

Documented in translate

#' Translate Amino Acid Sequences to Topology Sequences
#'
#' @param x an amino acid sequence to be translated to a topology sequence
#'
#' @return a topology sequence (I = inside, M = membrane, O = outside)
#' @export
#'
#' @examples
#' translate("AAA")
#'
#' @importFrom stringr str_replace_all
#' @importFrom stringr str_replace
#' @importFrom stringr str_split
#' @importFrom HMM viterbi
translate <- function(x) {
    x <-
        stringr::str_replace_all(x, "([aA-zZ])", " \\1") %>%
        stringr::str_replace(" ([aA-zZ])", "\\1") %>%
        stringr::str_split(" ") %>%
        base::unlist()

    HMM::viterbi(HMM, x) %>%
        base::paste(sep = "", collapse = "")
}
schifferl/TMHMM documentation built on Dec. 16, 2019, 12:46 a.m.