I have been tasked with writing an R function capable of taking a DNA string (s) as input and returning the complementary string on the reverse strand (e.g. "ACGT" returns "TGCA"). The result should look something like this:
> s <- "CCCTTAG"
> reverse.dna(s)
[1] "CTAAGGG"
I currently have the following functions for converting a string to a vector and vice versa, however any attempts I have made to use the replace() or switch() commands to substitute the complementary bases into either the string or vector have been unsuccessful.
string.to.vec <- function(s) {
strsplit(s,"") [[1]]
vec.to.string <- function(v) {
paste(v,collapse="")
As I have very limited experience using R I was wondering if anyone would be able to help me by suggesting the simplest method to implement this functionality into my function. Thanks!