首页 > 编程语言 >python 中统计不同scafflod的GC含量并输出GC含量最高的scafflod

python 中统计不同scafflod的GC含量并输出GC含量最高的scafflod

时间:2022-08-18 08:22:12浏览次数:49  
标签:scafflod PC1 含量 GC result file test home root

 

001、方法1

root@PC1:/home/test# ls
a.fasta  test.py
root@PC1:/home/test# cat a.fasta                                   ## 测试fasta文件
>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT
root@PC1:/home/test# cat test.py                                   ## 测试程序
#!/usr/bin/python
in_file = open("a.fasta", "r")
out_file = open("result.txt", "w")
dict1 = {}
dict2 = {}

for i in in_file:
    i = i.strip()
    if i.startswith(">"):
        key = i.split(">")[1]
        dict1[key] = []
    else:
        dict1[key].append(i)
for i,j in dict1.items():
    j = "".join(j).upper()
    dict2[i] = (j.count("C") + j.count("G"))/len(j)

result = max(dict2.items(), key = lambda x: x[1])
print(result[0] + "\n" +  str(result[1]), file = out_file, end = "\n")

in_file.close()
out_file.close()
root@PC1:/home/test# python test.py                             ## 运行程序
root@PC1:/home/test# ls
a.fasta  result.txt  test.py
root@PC1:/home/test# cat result.txt                              ## 运行结果
Rosalind_0808
0.6091954022988506

 

标签:scafflod,PC1,含量,GC,result,file,test,home,root
From: https://www.cnblogs.com/liujiaxin2018/p/16597481.html

相关文章