File size: 808 Bytes
a3283b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from tname import *
from Rfile import *


def Sort_Sco_Kcat(file):
    dlkcats = []
    contents = j_reads(file.name)

    # dlkcat sort根据kcat值对文件进行排序
    name = Name()
    kcatname = name + r"mkcat_sort.fa"  # 结果文件名称
    for i in range(2, len(contents)):
        content = contents[i].split()
        dlkcats.append(float(content[3]))
    s_dlkcat = []
    s_dlkcat = sorted(range(len(dlkcats)), key=lambda k: dlkcats[k], reverse=True)

    # 写入文件
    with open(kcatname, "a") as f:
        f.write(contents[0])
        # 第一行第二行不参与排序,直接写入
        f.write(contents[1])

    # 写入剩下的行
    for i in range(0, len(dlkcats)):
        with open(kcatname, "a") as f:
            f.write(contents[s_dlkcat[i]+2])
    return kcatname