我正在编写一个程序,在该程序中我可以反转序列并全部替换为Ts,所有Cs都带有Gs,所有带有Cs的Gs以及所有Ts都带有As。该程序将读取一系列碱基并输出反向互补序列。我无法做到这一点所以任何人都请为我的代码来看看帮助我:Python结构错误
word = raw_input("Enter sequence: ")
a = word.replace('A', 'T')
b = word.replace('C', 'G')
c = word.replace('G', 'C')
d = word.replace('T', 'A')
if a == word and b == word and c == word and d == word:
print "Reverse complement sequence: ", word
而且我想这种输出:
Enter sequence: CGGTGATGCAAGG
Reverse complement sequence: CCTTGCATCACCG
问候
在您的代码中,此错误即将出现! :追溯(最近一次调用最后一次): 文件“C:\ Python26 \ python code \ week 4 \ Q9”,第3行,在 newword =''.join(swap_dict [letter] ) 文件“C:\ Python26 \ python code \ week 4 \ Q9”,第3行,在 newword =''.join(swap_dict [字母]为反向(字)字母) KeyError:'S' –
jaddy123
啊。 'KeyError'说S不在交换字典中,所以它不知道如何处理它。你想在字母S上发生什么? – DSM