R/Modstrings-replaceLetterAt.R
replaceLetterAt.Rd
replaceLetterAt
replaces a letter in a ModString
objects
with a new letter. In contrast to modifyNucleotides
it does not
check the letter to be replaced for its identity, it just replaces it and
behaves exactly like the
# S4 method for ModString
replaceLetterAt(x, at, letter, verbose = FALSE)
# S4 method for ModStringSet
replaceLetterAt(x, at, letter, verbose = FALSE)
a ModString
or ModStringSet
object
the location where the replacement should be made.
The same input as in replaceLetterAt
are expected:
If x is a ModString
object, then at is typically an integer
vector with no NAs but a logical vector or Rle object is valid too. Locations
can be repeated and in this case the last replacement to occur at a given
location prevails.
If x is a rectangular ModStringSet
object, then at
must
be a matrix of logicals with the same dimensions as x. If the
ModStringSet
is not rectangular, at
must be a list of
logical vectors.
The new letters.
The same input as in replaceLetterAt
are expected:
If x is a ModString
object, then letter must be a
ModString
object or a character vector (with no NAs) with a
total number of letters (sum(nchar(letter))) equal to the number of locations
specified in at.
If x is a rectangular ModStringSet
object, then letter must be
a ModStringSet
object or a character vector of the same length
as x. In addition, the number of letters in each element of letter must match
the number of locations specified in the corresponding row of at
(all(width(letter) == rowSums(at))).
See replaceLetterAt
.
# Replacing the last two letters in a ModDNAString
seq1 <- ModDNAString("AGTC")
seq
#> function (...)
#> UseMethod("seq")
#> <bytecode: 0x55e2989327a8>
#> <environment: namespace:base>
seq2 <- replaceLetterAt(seq1,c(3,4),"CT")
seq2
#> 4-letter ModDNAString object
#> seq: AGCT
# Now containg and m3C
seq2 <- replaceLetterAt(seq1,c(3,4),ModDNAString("/T"))
seq2
#> 4-letter ModDNAString object
#> seq: AG/T
# Replacing the last two letters in a set of sequences
set1 <- ModDNAStringSet(c("AGTC","AGTC"))
set1
#> A ModDNAStringSet instance of length 2
#> width seq
#> [1] 4 AGTC
#> [2] 4 AGTC
set2 <- replaceLetterAt(set1,
matrix(rep(c(FALSE,FALSE,TRUE,TRUE),2),
nrow = 2,
byrow = TRUE),
c("CT","CT"))
set2
#> A ModDNAStringSet instance of length 2
#> width seq
#> [1] 4 AGCT
#> [2] 4 AGCT