我正在开发一个相当简单的程序,将给定的非编码 DNA 链转换为所有对应物(编码、mRNA、tRNA 和氨基酸链)。
IndexError
但是,当我尝试对字符串进行切片时,我得到了一个:
mRNA_parts = mRNA.split(' ')
print mRNA_parts, # using for debugging purposes
for base in mRNA_parts:
print base # again, for debugging
partA = base[0]
partB = base[1]
partC = base[2]
my_acid = (amino_acids[partA][partB][partC]) + ' '
# 'amino_acids' is a 3D (thrice-nested) dictionary with the corresponding parts of mRNA to convert to the amino acid chain.
# part of the nested dictionary: amino_acids = {'U': {'U': {'U': 'Phe'}}}. This is only one part (out of 64) of it.
# Thus, if the mRNA section was 'UUU', the amino acid would be 'Phe '.
acid_strand += my_acid
这是我得到的错误:
['GAU', '']
GAU
Traceback (most recent call last):
File "D:\my_stuff\Google Drive\documents\SCHOOL\Programming\Python\DNA to RNA Converter.py", line 83, in <module>
main()
File "D:\my_stuff\Google Drive\documents\SCHOOL\Programming\Python\DNA to RNA Converter.py", line 3, in main
convert(non_coding)
File "D:\my_stuff\Google Drive\documents\SCHOOL\Programming\Python\DNA to RNA Converter.py", line 58, in convert
partA = base[0]
IndexError: string index out of range
base[0]
基地是'GAU'怎么办?
根据它打印的内容,'GAU' 不是字符串吗?它周围没有任何引用。
提前致谢!