如何解决Rosalind Consensus and Profile 问题代码不起作用
这就是问题所在:http://rosalind.info/problems/cons/
def file_read(fname):
with open(fname,"r") as myfile:
global data
data = myfile.readlines()
print(data)
i = 0
while i < len(data):
data[i] = data[i].replace("\n","")
if ">" in data[i]:
data.remove(data[i])
else:
i += 1
file_read('rosalind_cons.txt')
res = ["".join(el) for el in zip(*data)]
print(res)
a_str = ""
c_str = ""
g_str = ""
t_str = ""
for x in range(0,len(res)):
a_str += (str(res[x].count("A"))) + " "
for x in range(0,len(res)):
c_str += (str(res[x].count("C"))) + " "
for x in range(0,len(res)):
g_str += (str(res[x].count("G"))) + " "
for x in range(0,len(res)):
t_str += (str(res[x].count("T"))) + " "
a_str_nospace = a_str.replace(" ","")
c_str_nospace = c_str.replace(" ","")
g_str_nospace = g_str.replace(" ","")
t_str_nospace = t_str.replace(" ","")
consensus_string = ""
for x in range(0,len(a_str_nospace)):
if max(a_str_nospace[x],c_str_nospace[x],g_str_nospace[x],t_str_nospace[x]) in a_str_nospace[x]:
consensus_string += "A"
elif max(a_str_nospace[x],t_str_nospace[x]) in c_str_nospace[x]:
consensus_string += "C"
elif max(a_str_nospace[x],t_str_nospace[x]) in g_str_nospace[x]:
consensus_string += "G"
elif max(a_str_nospace[x],t_str_nospace[x]) in t_str_nospace[x]:
consensus_string += "T"
print(consensus_string)
print("A: " + a_str)
print("C: " + c_str)
print("G: " + g_str)
print("T: " + t_str)
我的代码有什么问题? 对于示例输出,它有效,但对于较大的数据集则无效。 不知道怎么了,我觉得是文件读取部分不对(可能?)
编辑:那里有一些打印功能,但我不会将它们复制到答案框中,因此它们对结果无关紧要
解决方法
很高兴见到一位 Rosalind 用户。我在学习生物信息学时发现了那个页面,上个月又偶然发现了它。
回答您的问题: 您正在创建一串数字,因此如果数字都低于 10,则可以正常工作。 首先尝试构建一个整数列表,然后在最后一步将它们转换为字符串。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。