Complement a DNA sequence

后端 未结 7 1739
情书的邮戳
情书的邮戳 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:29

    Here a answer using base r. Written with a horrible formatting to make things clear and to keep it as a one-liner. It supports upper and lower cases.

    revc = function(s){
           paste0(
               rev(
                unlist(
                 strsplit(
                    chartr("ATGCatgc","TACGtacg",s)
                          , "")                        # from strsplit
                       )                               # from unlist
                   )                                   # from rev
                 , collapse='')                        # from paste0
           }
    

提交回复
热议问题