File: bma.R

package info (click to toggle)
r-cran-seqinr 3.3-3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,844 kB
  • ctags: 69
  • sloc: ansic: 1,955; makefile: 13
file content (20 lines) | stat: -rw-r--r-- 580 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
bma <- function(nucl, warn.non.IUPAC = TRUE, type = c("DNA", "RNA")){
  if(nchar(nucl[1]) != 1) stop("vector of single chars expected")
  type <- match.arg(type)
  nucl <- tolower(nucl)
  nucl <- unlist(sapply(nucl, amb, checkBase = FALSE))
  iupac <- sapply(amb(), amb)
  if(type == "DNA"){
    iupac$u <- NULL
  } else {
    iupac$t <- NULL
  }
  idx <- unlist(lapply(iupac, setequal, nucl))
  if(all(idx == FALSE)){
    if(warn.non.IUPAC){
      warning(paste("Undefined IUPAC symbol with:", paste(nucl, collapse = " ")))
    }
    return(NA)
  }
  return(names(iupac)[idx])
}