首页 > 代码库 > 03 Complementing a Strand of DNA
03 Complementing a Strand of DNA
Problem
In DNA strings, symbols ‘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 revComSeqseq = ‘AAAACCCGGT‘print (reverse(seq))
03 Complementing a Strand of DNA
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。