This is a test version of Biostars. For the public version, visit https://www.biostars.org.
script in R to convert DNA to RNA sequence

Assume you have the following DNA sequence ACAGTCGACTAGCTTGCACGTAC,how to write an R function script called “DNA_to_RNA.R” to convert this sequence to an RNA sequence, assuming perfect transcription process without any loss in the DNA sequence bases. You have to loop over the whole sequence and check each character in the DNA sequence separately before converting to an RNA sequence.

sequencing

Just change T to U no ? Why would you do that ? Homework ?

yes but i think i need to do a loop

Please show some effort. What did you try?

i am trying with the "for loop" now

 x="ACAGTCGACTAGCTTGCACGTAC"
> for (variable in x) {
+     gsub("T", "U", x)
+ }

this does not work

That is not how for-loops work. Please spend some time on baic R. gsub already operates on the entire DNA string. The string, or x is a single element so you cannot loop through it.

1 answer

> DNA <- c("TGGATTTCCCCGATCGA")
> gsub("T", "U", DNA)
[1] "UGGAUUUCCCCGAUCGA"

Log in to answer this question.