加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

for-loop – 互补DNA序列

发布时间:2020-12-20 11:29:46 所属栏目:Python 来源:网络整理
导读:我在写这个循环时遇到了问题;它似乎在第二个序列后停止. 我想将互补的DNA序列返回到给定的DNA序列. 例如. (‘AGATTC’) – (‘TCTAAG’),其中A:T和C:G def get_complementary_sequence(dna): """(str) - str Return the DNA sequence that is complementar
我在写这个循环时遇到了问题;它似乎在第二个序列后停止.

我想将互补的DNA序列返回到给定的DNA序列.

例如. (‘AGATTC’) – > (‘TCTAAG’),其中A:T和C:G

def get_complementary_sequence(dna):
    """(str) -> str

> Return the DNA sequence that is complementary to the given DNA sequence

    >>> get_complementary_sequence('AT')
    ('TA')
    >>> get_complementary_sequence('AGATTC')
    ('TCTAAG')

    """

    x = 0
    complementary_sequence = ''

    for char in dna:
            complementary_sequence = (get_complement(dna))

    return complementary_sequence + (dna[x:x+1])

谁能发现循环不能继续的原因?

解决方法

以下是我将如何做的示例 – 实际上只有两行代码:

from string import maketrans

DNA="CCAGCTTATCGGGGTACCTAAATACAGAGATAT" #example DNA fragment

def complement(sequence):
  reverse = sequence[::-1]
  return reverse.translate(maketrans('ATCG','TAGC'))

print complement(DNA)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读