File: amb.R

package info (click to toggle)
r-cran-seqinr 3.4-5-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,876 kB
  • sloc: ansic: 1,987; makefile: 14
file content (30 lines) | stat: -rw-r--r-- 1,047 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
21
22
23
24
25
26
27
28
29
30
amb <- function(base, forceToLower = TRUE, checkBase = TRUE,
IUPAC = s2c("acgturymkswbdhvn"), u2t = TRUE){
  if(missing(base)) return(IUPAC)
  if(!is.character(base)) stop("Character expected")
  if(nchar(base) != 1) stop("Single character expected")
  if(forceToLower) base <- tolower(base)
  if(checkBase) if(!(base %in% IUPAC)) stop("IUPAC base expected")

  if(base == "r") return(s2c("ag")) # puRine
  if(base == "y") return(s2c("ct")) # pYrimidine

  if(base == "m") return(s2c("ac")) # aMino
  if(base == "k") return(s2c("gt")) # Keto

  if(base == "s") return(s2c("cg")) # Strong (3 H bonds)
  if(base == "w") return(s2c("at")) # Weak (2 H bonds)

  if(base == "b") return(s2c("cgt")) # Not A (A->B)
  if(base == "d") return(s2c("agt")) # Not C (C->D)
  if(base == "h") return(s2c("act")) # Not G (G->H)
  if(base == "v") return(s2c("acg")) # Not T (T->V)

  if(base == "n") return(s2c("acgt")) # aNy base
#
# Uracil case: Uracil in RNA instead of Thymine in DNA
#  
  if(base == "u") if(u2t) return("t") else return("u")

  return(base)
}