1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
##########################################
# complements a sequence
###########################################
comp <- function(seq, forceToLower = TRUE, ambiguous = FALSE){
if(all(seq %in% LETTERS)){
isUpper <- TRUE
} else {
isUpper <- FALSE
}
seq <- tolower(seq)
result <- as.vector(n2s((3-s2n(seq))))
#
# More work is required if ambiguous bases are taken into account
#
if(ambiguous){
result[which(seq == "b")] <- "v"
result[which(seq == "d")] <- "h"
result[which(seq == "h")] <- "d"
result[which(seq == "k")] <- "m"
result[which(seq == "m")] <- "k"
result[which(seq == "s")] <- "s"
result[which(seq == "v")] <- "b"
result[which(seq == "w")] <- "w"
result[which(seq == "n")] <- "n"
result[which(seq == "y")] <- "r"
result[which(seq == "r")] <- "y"
}
# Checking for N in the sequence, thanks to Jeremy Shearman.
result[which(seq == "n")] <- "n"
if(isUpper && !forceToLower){
result <- toupper(result)
}
return(result)
}
|