Translating letters of a sequence

Share:

Description

Translate letters of a sequence.

Usage

1
2
## S4 method for signature 'ANY,ANY,XString'
chartr(old, new, x)

Arguments

old

A character string specifying the characters to be translated.

new

A character string specifying the translations.

x

The sequence or set of sequences to translate. If x is an XString, XStringSet, XStringViews or MaskedXString object, then the appropriate chartr method is called, otherwise the standard chartr R function is called.

Details

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.

Value

An object of the same class and length as the original object.

See Also

chartr, replaceLetterAt, XString-class, XStringSet-class, XStringViews-class, MaskedXString-class, alphabetFrequency, matchPattern, reverseComplement

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  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)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.