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