chartr | R Documentation |
Replace letters in a sequence or set of sequences.
## S4 method for signature 'ANY,ANY,XString'
chartr(old, new, x)
replaceAmbiguities(x, new="N")
old |
A character string specifying the characters to be replaced. |
new |
A character string specifying the replacements. It must be a single
letter for |
x |
The sequence or set of sequences to translate.
If |
See ?chartr
for the details.
Note that, unlike the standard chartr
R function,
the methods for XString, XStringSet, XStringViews
and MaskedXString objects do NOT support character ranges in the
specifications.
replaceAmbiguities()
is a simple wrapper around chartr()
that replaces all IUPAC ambiguities with N for objects containing DNA
or RNA sequence data.
An object of the same class and length as the original object.
chartr
in the base package.
The replaceAt
function for extracting or replacing
arbitrary subsequences from/in a sequence or set of sequences.
The replaceLetterAt
function for a DNA-specific
single-letter replacement functions useful for SNP injections.
IUPAC_CODE_MAP
for the mapping between IUPAC
nucleotide ambiguity codes and their meaning.
alphabetFrequency
(and uniqueLetters
)
for tabulating letters in (and extracting the unique letters from)
a sequence or set of sequences.
The XString, XStringSet, XStringViews, and MaskedXString classes.
## ---------------------------------------------------------------------
## A BASIC chartr() EXAMPLE
## ---------------------------------------------------------------------
x <- BString("MiXeD cAsE 123")
chartr("iXs", "why", x)
## ---------------------------------------------------------------------
## TRANSFORMING DNA WITH BISULFITE (AND SEARCHING IT...)
## ---------------------------------------------------------------------
library(BSgenome.Celegans.UCSC.ce2)
chrII <- Celegans[["chrII"]]
alphabetFrequency(chrII)
pattern <- DNAString("TGGGTGTATTTA")
## Transforming and searching the + strand
plus_strand <- chartr("C", "T", chrII)
alphabetFrequency(plus_strand)
matchPattern(pattern, plus_strand)
matchPattern(pattern, chrII)
## Transforming and searching the - strand
minus_strand <- chartr("G", "A", chrII)
alphabetFrequency(minus_strand)
matchPattern(reverseComplement(pattern), minus_strand)
matchPattern(reverseComplement(pattern), chrII)
## ---------------------------------------------------------------------
## replaceAmbiguities()
## ---------------------------------------------------------------------
dna <- DNAStringSet(c("TTTKYTT-GR", "", "NAASACVT"))
dna
replaceAmbiguities(dna)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.