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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
########################
# char to string
########################
c2s <- function( chars = c("m","e","r","g","e","d") )
{
return( paste( chars, collapse = "" ) )
}
###########################
# string to char
############################
s2c <- function (string)
{
if(is.character(string) && length(string) == 1){
return(.Call("s2c", string, PACKAGE = "seqinr"))
} else {
warning("Wrong argument type in s2c(), NA returned")
return(NA)
}
}
###########################
# Conversion of the numeric encoding of a DNA sequence into
# a vector of chars
############################
n2s <- function(nseq, levels = c("a", "c", "g", "t"), base4 = TRUE)
{
if( base4 )
levels[nseq + 1]
else
levels[nseq]
}
##########################################
# Convert one-letter code to 3-letters code for amino-acids
##########################################
aaa <- function( aa )
{
aa3 <- c("Stp", "Ala", "Cys", "Asp", "Glu", "Phe", "Gly", "His", "Ile",
"Lys", "Leu", "Met", "Asn", "Pro", "Gln", "Arg", "Ser", "Thr",
"Val", "Trp", "Tyr") # One letter code order
if(missing(aa)) return(aa3)
aa1 <- a()
convert <- function( x )
{
if( all( x != aa1 ) )
{
warning("Unknown one letter code for aminoacid")
return( NA )
}
else
{
return( aa3[which( x == aa1 )] )
}
}
return( as.vector(unlist(sapply( aa, convert ) ) ) )
}
##########################################
# Conversion 3-letters code to one letter code for amino-acids
##########################################
a <- function( aa )
{
aa1 <- s2c("*ACDEFGHIKLMNPQRSTVWY")
if(missing(aa)) return(aa1)
aa3 <- aaa()
convert <- function( x )
{
if( all( x != aa3 ) )
{
warning("Unknown 3-letters code for aminoacid")
return( NA )
}
else
{
return( aa1[which( x == aa3 )] )
}
}
return( as.vector(unlist(sapply( aa, convert ) ) ) )
}
|