Complement a DNA sequence

后端 未结 7 1744
情书的邮戳
情书的邮戳 2020-12-31 12:07

Suppose I have a DNA sequence. I want to get the complement of it. I used the following code but I am not getting it. What am I doing wrong ?

s=readline()
AT         


        
7条回答
  •  既然无缘
    2020-12-31 12:17

    sapply(p, switch,  "A"="T", "T"="A","G"="C","C"="G")
      A   T   C   T   C   G   G   C   G   C   G   C   A   T   C   G   C   G   T 
    "T" "A" "G" "A" "G" "C" "C" "G" "C" "G" "C" "G" "T" "A" "G" "C" "G" "C" "A" 
      A   C   G   C   T   A   C   T   A   G   C 
    "T" "G" "C" "G" "A" "T" "G" "A" "T" "C" "G" 
    

    If you do not want the complementary names, you can always strip them with unname.

    unname(sapply(p, switch,  "A"="T", "T"="A","G"="C","C"="G") )
     [1] "T" "A" "G" "A" "G" "C" "C" "G" "C" "G" "C" "G" "T" "A" "G" "C" "G" "C"
    [19] "A" "T" "G" "C" "G" "A" "T" "G" "A" "T" "C" "G"
    > 
    

提交回复
热议问题