|
import re |
|
from tname import * |
|
from Rfile import * |
|
|
|
|
|
def Sort_Scores(file): |
|
scores = [] |
|
contents = j_reads(file.name) |
|
|
|
for i in range(2, len(contents)): |
|
if i % 2 == 0: |
|
|
|
content = re.match('.*score=(\d.\d+?),', contents[i]) |
|
if content: |
|
score = content.group(1) |
|
scores.append(float(score)) |
|
|
|
na = Name() |
|
na = na + r"scores_sort.tsv" |
|
|
|
|
|
sorted_id = [] |
|
sorted_id = sorted(range(len(scores)), key=lambda k: scores[k], reverse=True) |
|
|
|
|
|
with open(na, "a") as f1: |
|
f1.write(contents[0]) |
|
f1.write(contents[1]) |
|
|
|
for i in range(0, len(scores)): |
|
with open(na, "a") as f: |
|
f.write(contents[sorted_id[i] * 2 + 2]) |
|
|
|
f.write(contents[sorted_id[i] * 2 + 2 + 1]) |
|
results = j_reads(na) |
|
return str(results) |
|
|