-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp_cross_prediction.py
136 lines (114 loc) · 4.66 KB
/
exp_cross_prediction.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from venv import create
import models.train_and_evaluate
import json
import copy
import os
import figure_cross_prediction
import pandas as pd
def load_spec(path):
with open(path, 'r') as f:
return json.load(f)
def main():
mn_spec = load_spec("cfgs/gi_mn_model.json")
mn_spec['target_col'] = 'is_neutral'
run_cv_on_spec(mn_spec, "mn")
evaluate_cv_on_spec(mn_spec, "mn", "rel_not_ppc")
evaluate_cv_on_spec(mn_spec, "mn", "rel_not_phospho")
evaluate_cv_on_spec(mn_spec, "mn", "rel_not_trans")
strict_spec = create_strict_spec()
run_cv_on_spec(strict_spec, "mn_strict")
evaluate_cv_on_spec(strict_spec, "mn_strict", "rel_not_ppc")
evaluate_cv_on_spec(strict_spec, "mn_strict", "rel_not_phospho")
evaluate_cv_on_spec(strict_spec, "mn_strict", "rel_not_trans")
generate_figures()
def run_cv_on_spec(model_spec, name):
sg_path = "../generated-data/dataset_yeast_allppc.feather"
models.train_and_evaluate.cv(model_spec,
"../generated-data/dataset_yeast_gi_hybrid_mn.feather",
"../generated-data/splits/dataset_yeast_gi_hybrid.npz",
"cv",
"../results/exp_cross_prediction/%s" % name,
n_workers=16,
no_train=False,
sg_path=sg_path)
def evaluate_cv_on_spec(model_spec, name, target_col):
sg_path = "../generated-data/dataset_yeast_allppc.feather"
model_spec['target_col'] = target_col
models.train_and_evaluate.cv(model_spec,
"../generated-data/dataset_yeast_gi_hybrid_mn.feather",
"../generated-data/splits/dataset_yeast_gi_hybrid.npz",
"cv",
"../results/exp_cross_prediction/%s" % name,
n_workers=16,
no_train=True,
sg_path=sg_path,
results_path="../results/exp_cross_prediction/%s_%s.json" % (name, target_col))
def create_strict_spec():
mn_spec = load_spec("cfgs/gi_mn_model.json")
mn_spec['target_col'] = 'is_neutral'
exclude = ['GO:0016791', 'GO:0016301', 'GO:0008134']
df = pd.read_feather("../generated-data/dataset_yeast_gi_hybrid_mn.feather")
sgo_cols = df.columns[df.columns.str.startswith('sgo-')]
included_cols = [c for c in sgo_cols if c.replace('sgo-','') not in exclude]
mn_spec['features'] = included_cols + ['smf-']
return mn_spec
def generate_figures():
output_dir = "../results/exp_cross_prediction/figures/"
os.makedirs(output_dir, exist_ok=True)
spec = {
"models": [
{
"title": "GI",
"color": "#1f77b4",
"cm_color": "#1f77b4",
"results_paths" : [
"../results/exp_cross_prediction/mn/results.json",
"../results/exp_cross_prediction/mn_strict/results.json",
],
"name" : "gi"
},
{
"title": "Coprecipitation",
"color": "#ff7f0e",
"cm_color": "#ff7f0e",
"results_paths" : [
"../results/exp_cross_prediction/mn_rel_not_ppc.json",
"../results/exp_cross_prediction/mn_strict_rel_not_ppc.json"
],
"fsize" : 50,
"name" : "ppc"
},
{
"title": "Phopshorylation",
"color": "#2ca02c",
"results_paths" : [
"../results/exp_cross_prediction/mn_rel_not_phospho.json",
"../results/exp_cross_prediction/mn_strict_rel_not_phospho.json"
],
"name" : "phospho"
},
{
"title": "Transcription",
"color": "#d62728",
"results_paths" : [
"../results/exp_cross_prediction/mn_rel_not_trans.json",
"../results/exp_cross_prediction/mn_strict_rel_not_trans.json",
],
"fsize" : 50,
"name" : "trans"
}
],
"classes": [
"Interacting",
"Neutral"
],
"short_classes": [
"I",
"N"
],
"ylim" : [0,0.8],
"aspect" : 1
}
figure_cross_prediction.generate_figures(spec, "../results/exp_cross_prediction", "../results/exp_cross_prediction/figures/overall_bacc.png")
if __name__ == "__main__":
main()