美文网首页
2022-09-13 ROSALIND_10: Consensu

2022-09-13 ROSALIND_10: Consensu

作者: 小孟在充电 | 来源:发表于2022-09-21 17:20 被阅读0次
# ----ROSLIND_10: ---- 
# Consensus and Profile

with open("10_Consensus and Profile.txt") as f:
    DNA_strings = f.readlines()
    DNA_strings = [x.strip("\n") for x in DNA_strings]
def myConPro(sample_File): 
    newDNA_strings = []
    DNA_matrix = []
    DNA_profile = []
    DNA_profile_t = []
    
    
   
    # 获取ROSname
    ROSname = [x for x in DNA_strings if "Rosalind" in x]
    ROSindex = [DNA_strings.index(x) for x in ROSname]     

    
    for i in range(0, len(DNA_strings), int(ROSindex[1]) - int(ROSindex[0])):
        
        newDNA_strings.append(DNA_strings[i: i + (int(ROSindex[1]) - int(ROSindex[0]))])        
        
            
    DNA_matrix = ["".join( x[1:] ) for x in newDNA_strings]
    # DNA_matrix = ["".join(x) for x in DNA_matrix] # 合并子集中的字符串,并不是所有字符串都是单行
    
     #转置
    for i in range(len(DNA_matrix[0])):
        for j in range(len(DNA_matrix)):
        
            DNA_profile.append(DNA_matrix[j][i])
            
    DNA_profile_t = [DNA_profile[i: i+len(DNA_matrix[0])] for i in range(0, len(DNA_profile), len(DNA_matrix[0]))]
        
    count_a = []
    count_t = []
    count_c = []
    count_g = []
    
    for i in range(len(DNA_profile_t)):
        count_a.append(DNA_profile_t[i].count("A"))
        count_t.append(DNA_profile_t[i].count("T"))
        count_c.append(DNA_profile_t[i].count("C"))
        count_g.append(DNA_profile_t[i].count("G"))
    # 返回ATCG在每一列的count
    res = [count_a, count_t, count_c, count_g]
    # 返回ATCG在每一列的count
    
    base = "ATCG"
    
    rowcount = {base[i]: res[i] for i in range(len(base))}
    # 返回ATCG所在列的count数
    for k, v in rowcount.items():
        print(k, v)
    
    
    #遍历字典根据每一列最大值返回键值
    Consensus = []
    for i in range(len(list(rowcount.values())[0])):
        Consensus.append({"A": list(rowcount.values())[0][i],
                          "T": list(rowcount.values())[1][i],
                          "C": list(rowcount.values())[2][i],
                          "G": list(rowcount.values())[3][i]})
    # 最大值返回键值   
    result = []
    for i in range(len(Consensus)):
        result.append( max(Consensus[i], key = Consensus[i].get))

    return "".join(result)
image.png

相关文章

  • 2022-09-13 ROSALIND_10: Consensu

  • Paxos 协议 & Multi-Paxos

    Distributed Consensus AlgorithmThere is only one consensu...

  • 2022-09-13

    Ann. Oncol 丨 大数据分析免疫检查点阻断反应以提高治疗效果 原创珍奇图灵基因2022-09-13 10:...

  • 字慧乐园真有趣

    字慧乐园真有趣 原创 林老师 部编版大语文 2022-09-13 22:58 发表于福建 这节字慧乐园来了40位同...

  • 闲言碎语(7)(外三篇)

    1、《仲秋的乌镇》时间:2022-09-13 有一个地方叫乌镇,它是: ——典型的江南名镇。地处长三角杭嘉湖平原嘉...

  • 猫中极品(Marry和她的大白)

    2022-09-13 Marry是楼下我车位上的流浪猫,是一只母猫,是一只患了口炎非常厉害猫,2020年秋季来到这...

  • 0316|我是自己的教练试验品

    2022-09-13 北京 晴天一昨天是最后一天在上海,微风细雨,很浪漫的一天。大鱼,一个自信有才华的姑娘,诺言...

  • 收假返园

    2022-09-13 周二 阵雨 收假了,心心念念返园的反应没有我想象的严重。虽然心心从起床就一直强调不要上幼儿园...

  • 105|臭臭的新反应

    2022-09-13 星期二 雨 臭臭最近迷恋上喝妈妈的奶了,他妈妈一抱起来就开始找奶,找到了就拼命往上爬,真是够...

  • 2022-09-13

    这一个月痛苦并煎熬着

网友评论

      本文标题:2022-09-13 ROSALIND_10: Consensu

      本文链接:https://www.haomeiwen.com/subject/ezwhortx.html