R/color_else.R

Defines functions color_scheme

Documented in color_scheme

##'  Assigning colors to sequence alignment.
##'
##'
##' @param y sequence alignment with data frame, generated by tidy_msa().
##' @param color a Color scheme. One of 'Clustal', 'Chemistry_AA', 'Shapely_AA', 'Zappo_AA', 'Taylor_AA', 'LETTER', 'CN6', 'Chemistry_NT', 'Shapely_NT', 'Zappo_NT', 'Taylor_NT'. Defaults is 'Chemistry_AA'.
##' @param custom_color A data frame with two cloumn called "names" and "color".Customize the color scheme.

color_scheme <- function(y, color = "Chemistry_AA", custom_color = NULL) {
    if (!is.null(custom_color)){
        custom_color[["names"]] <- as.character(custom_color[["names"]]) #Elimination factor interference
        custom_color[["color"]] <- as.character(custom_color$col) #Fuzzy matching the string "colors" or "colours"
        row.names(custom_color) <- custom_color[["names"]]
        scheme_AA$custom_color <- custom_color[row.names(scheme_AA), "color"] %>% as.character()
        y$color <- scheme_AA[y$character, "custom_color"]
    }else{
        if(grepl("NT", color)){
            y$color <- scheme_NT[y$character, color]
        } else{
            y$color <- scheme_AA[y$character, color]
        }
    }
    return(y)
}

Try the ggmsa package in your browser

Any scripts or data that you put into this service are public.

ggmsa documentation built on Aug. 3, 2021, 9:06 a.m.