rosalind-计算CG占比

2019-10-24  本文已影响0人  heliping_peter

输入数据

>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT

需要输出CG最大的占比

Rosalind_0808
60.919540

代码

f = open("gg.txt")
lines = f.readlines()
dict = {}
#if ">", get the line to key
#if not, get the line to value
for line in lines:
    index = lines.index(line)
    line = line.strip('\n')
    if line[0] == ">" :
        name = line.split(">")[1]
        dict[name] = []
    else:
        dict[name].append(line)
#join the value to a string, and sum the C and G
for key in dict.keys():
    value = ''.join(dict[key])
    cg = 0
    for i in value:
        if i == "C" or i == "G":
            cg = cg +1
    value = cg / len(value) * 100
    dict[key] = value
#max the value
resultkey = max(dict,key=dict.get)
print(resultkey)
print(format(dict[resultkey],'.6f'))      
上一篇下一篇

猜你喜欢

热点阅读