jie1 commited on
Commit
a3283b1
1 Parent(s): af818c5

Upload Sort_Sco_Kcat.py

Browse files
Files changed (1) hide show
  1. Sort_Sco_Kcat.py +28 -0
Sort_Sco_Kcat.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tname import *
2
+ from Rfile import *
3
+
4
+
5
+ def Sort_Sco_Kcat(file):
6
+ dlkcats = []
7
+ contents = j_reads(file.name)
8
+
9
+ # dlkcat sort根据kcat值对文件进行排序
10
+ name = Name()
11
+ kcatname = name + r"mkcat_sort.fa" # 结果文件名称
12
+ for i in range(2, len(contents)):
13
+ content = contents[i].split()
14
+ dlkcats.append(float(content[3]))
15
+ s_dlkcat = []
16
+ s_dlkcat = sorted(range(len(dlkcats)), key=lambda k: dlkcats[k], reverse=True)
17
+
18
+ # 写入文件
19
+ with open(kcatname, "a") as f:
20
+ f.write(contents[0])
21
+ # 第一行第二行不参与排序,直接写入
22
+ f.write(contents[1])
23
+
24
+ # 写入剩下的行
25
+ for i in range(0, len(dlkcats)):
26
+ with open(kcatname, "a") as f:
27
+ f.write(contents[s_dlkcat[i]+2])
28
+ return kcatname