chartr: Replace letters in a sequence or set of sequences

chartrR Documentation

Replace letters in a sequence or set of sequences

Description

Replace letters in a sequence or set of sequences.

Usage

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

replaceAmbiguities(x, new="N")

Arguments

old

A character string specifying the characters to be replaced.

new

A character string specifying the replacements. It must be a single letter for replaceAmbiguities.

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.

replaceAmbiguities() is a simple wrapper around chartr() that replaces all IUPAC ambiguities with N for objects containing DNA or RNA sequence data.

Value

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

See Also

  • 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.

Examples

## ---------------------------------------------------------------------
## 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)

Bioconductor/Biostrings documentation built on Nov. 11, 2024, 12:58 a.m.