wurmlab / SBC361-programming-in-R

QMUL's programming in R course
https://wurmlab.github.io/SBC361-programming-in-R/practical1.html
5 stars 11 forks source link

Practical 2 question 16 #19

Open roddypr opened 7 years ago

roddypr commented 7 years ago

This question asks to generate the reverse complement of a sequence using "gsub". Using "gsub" is quite dangerous in this question. A better solution is to use "match", despite this not being the point of the exercise:

sequence <- "ATTACGACGCGATTCCCGGTTAATCGAATTCCCA"

# Complement of each nucleotide
dna_code               <- c("A","C","G","T")
complement_code <- c("T","G", "C","A")

# Complement of sequence
comp_seq <- complement_code[match(sequence, dna_code)]

# Reverse
rev_comp <- rev(rev_comp)

# paste together
rev_comp <- paste(rev_comp, collapse = "")
yannickwurm commented 7 years ago

Then we need a different example.

The point is for them to learn how to do regular expressions.

On 2017-Jul-20, at 18:15, Rodrigo Pracana notifications@github.com wrote:

This question asks to generate the reverse complement of a sequence using "gsub". Using "gsub" is quite dangerous in this question. A better solution is to use "match", despite this not being the point of the exercise:

sequence <- "ATTACGACGCGATTCCCGGTTAATCGAATTCCCA"

Complement of each nucleotide

dna_code <- c("A","C","G","T") complement_code <- c("T","G", "C","A")

Complement of sequence

comp_seq <- complement_code[match(sequence, dna_code)]

Reverse

rev_comp <- rev(rev_comp)

paste together

rev_comp <- paste(rev_comp, collapse = "")

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.