码迷,mamicode.com
首页 > 其他好文 > 详细

03 Complementing a Strand of DNA

时间:2017-07-29 15:11:38      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:letter   eve   pre   original   put   class   string   bond   sub   

Problem

In DNA stringssymbols ‘A‘ and ‘T‘ are complements of each other, as are ‘C‘ and ‘G‘.

The reverse complement of a DNA string ss is the string scsc formed by reversing the symbols of ss, then taking the complement of each symbol (e.g., the reverse complement of "GTCA" is "TGAC").

Given: A DNA string ss of length at most 1000 bp.

Return: The reverse complement scsc of ss.

Sample Dataset

AAAACCCGGT

Sample Output

ACCGGGTTTT

方法一
def reverse(seq):
    dict = {‘A‘: ‘T‘, ‘C‘: ‘G‘, ‘T‘: ‘A‘, ‘G‘: ‘C‘}

    revSeqList = list(reversed(seq))                #[‘T‘, ‘G‘, ‘G‘, ‘C‘, ‘C‘, ‘C‘, ‘A‘, ‘A‘, ‘A‘, ‘A‘]
    revComSeqList = [dict[k] for k in revSeqList]  # [‘A‘, ‘C‘, ‘C‘, ‘G‘, ‘G‘, ‘G‘, ‘T‘, ‘T‘, ‘T‘, ‘T‘]
    revComSeq = ‘‘.join(revComSeqList)             # ACCGGGTTTT
    return revComSeq


seq = ‘AAAACCCGGT‘


print (reverse(seq))

  



03 Complementing a Strand of DNA

标签:letter   eve   pre   original   put   class   string   bond   sub   

原文地址:http://www.cnblogs.com/think-and-do/p/7255726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!