本文介绍了互补DNA序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写这个循环时遇到了问题。它似乎在第二个序列后停止。我想将互补的DNA序列返回给定的DNA序列。
('AGATTC') - >('TCTAAG'),其中A:T和C:G
def get_complementary_sequence(dna) :
(str) - > str
>返回与给定DNA序列互补的DNA序列
>>> ; 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])$ b $ b
循环不会继续?
解决方案
这是一个例子,我将如何做 - 只有两行代码:
从串进口maketrans
DNA = CCAGCTTATCGGGGTACCTAAATACAGAGATAT #示例DNA片段
def complement(序列):
reverse = sequence [:: - 1]
return reverse.translate(maketrans('ATCG','TAGC'))
print complement(DNA)
I'm having a problem writing this loop; it seems to stop after the second sequence.
I want to return the complementary DNA sequence to the given DNA sequence.
E.g. ('AGATTC') -> ('TCTAAG'), where A:T and 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])
Can anyone spot why the loop does not continue?
解决方案
Here is an example how I would do it - only two lines of code really:
from string import maketrans
DNA="CCAGCTTATCGGGGTACCTAAATACAGAGATAT" #example DNA fragment
def complement(sequence):
reverse = sequence[::-1]
return reverse.translate(maketrans('ATCG','TAGC'))
print complement(DNA)
这篇关于互补DNA序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!