首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rosalind共识和配置文件问题代码不起作用

Rosalind共识和配置文件问题代码不起作用
EN

Stack Overflow用户
提问于 2021-01-04 07:43:01
回答 1查看 44关注 0票数 0

这是问题所在:http://rosalind.info/problems/cons/

代码语言:javascript
复制
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], c_str_nospace[x], g_str_nospace[x], t_str_nospace[x]) in c_str_nospace[x]:
        consensus_string += "C"
    elif max(a_str_nospace[x], c_str_nospace[x], g_str_nospace[x], t_str_nospace[x]) in g_str_nospace[x]:
        consensus_string += "G"
    elif max(a_str_nospace[x], c_str_nospace[x], g_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)

我的代码出了什么问题?对于样本输出,它可以工作,但对于较大的数据集,它不能工作。我不知道哪里出了问题,我认为是文件读取部分不正确(可能?)

编辑:这里有一些打印功能,但我没有在答案框中复制它们,所以它们在结果中无关紧要

EN

回答 1

Stack Overflow用户

发布于 2021-01-04 08:25:12

很高兴见到一位Rosalind的用户。我在学习生物信息学时发现了这个页面,上个月我又偶然发现了它。

回答您的问题:您正在创建一个数字字符串,因此如果所有数字都小于10,则可以很好地工作。尝试首先构建一个整数列表,并在最后一步中仅将其转换为字符串。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65556085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档