-
Notifications
You must be signed in to change notification settings - Fork 42
/
retrain.py
62 lines (50 loc) · 2.09 KB
/
retrain.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
from RI_precision import *
from globalConfig import *
import os
from glob import glob
import sys
import shutil
def retrain_evaluate(gtData_path, geneData_path, ratio):
'''evaluate the retrain results
Args:
--------
gtData_path: groundtruth data directory, i.e. _tail dataset path
geneData_path: generate data directory, i.e. _all results path
ratio: the split ratio of _head data
Returns:
--------
None
'''
# create temporary directory to save the _tail data from _all
tmp_dir = os.path.join(geneData_path, "tmp_dir")
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)
# split the geneData
fileNum = len(glob(os.path.join(geneData_path, "template[0-9]*.txt")))
all_line_num = 0
for i in range(fileNum):
all_line_num += len(open(os.path.join(geneData_path, "template%s.txt"%(i+1)), "r").readlines())
split_index = int(all_line_num*ratio)
for i in range(fileNum):
filename = os.path.join(geneData_path, "template%s.txt"%(i+1))
tmp_file = os.path.join(tmp_dir, "template%s.txt"%(i+1))
filtered = [str(int(k.strip().split("\t")[0])-split_index) for k in open(filename , "r").readlines() if int(k.strip().split("\t")[0])>split_index]
open(tmp_file, "w").write("\n".join(filtered))
parameters = prePara(groundTruthDataPath=gtData_path+'/', geneDataPath=tmp_dir+'/')
TP, FP, TN, FN, p, r, f, RI = process(parameters)
shutil.rmtree(tmp_dir)
if __name__ == "__main__":
# USAGE: ./retrain.py {ALGORITHM} {DATASET} {RATIO}
printLine()
assert sys.argv[1] in ALGORITHM_LIST
assert sys.argv[2] in DATASET_LIST
config = {
"algorithm":sys.argv[1],
"dataset":sys.argv[2],
"ratio":float(sys.argv[3])
}
gene_data_path = os.path.abspath(os.path.join(RESULT_PATH, "%s_results"%config["algorithm"], "%s_all"%config["dataset"]))
groundtruth_path = os.path.abspath(os.path.join(DATA_PATH, "%s_tail_%0.2f"%(config["dataset"], config["ratio"])))
retrain_evaluate(groundtruth_path, gene_data_path, config["ratio"])