在Python 3.7中,我的代码适用于页面示例数据集,但对于大型示例而言却失败了。
有什么想法我做错了吗?
amounts = {"A": "", "C": "", "G": "", "T": ""}
new = []
consensus = ""
contents = []
with open("condna.txt") as f:
oldcontents = f.readlines()
for index, letters in enumerate(oldcontents):
oldcontents[index] = oldcontents[index].rstrip()
insert = -1
for index, letters in enumerate(oldcontents):
if letters.startswith(">"):
contents.append("")
insert += 1
continue
contents[insert] += letters
for i in range(len(contents[0])):
new.append("")
for word in contents:
new[i] += word[i]
for new_word in new:
for letter in amounts:
amounts[letter] += str(new_word.count(letter)) + " "
for i in range(len(amounts["A"])):
if amounts["A"][i] == " ":
continue
find_max = -1
for k, number in amounts.items():
if int(number[i]) > find_max:
find_max = int(number[i])
store_k = k
consensus += store_k
with open("consensus answer.txt", "a") as ans:
ans.write(consensus + "\n")
for k, v in amounts.items():
ans.write("{}: {}\n".format(k, v))
print(consensus)
for k, v in amounts.items():
print("{}: {}".format(k, v))
这是给我的答案: https://pastebin.com/rZWRnKVS