-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path06_02_plot_results.py
103 lines (78 loc) · 3.02 KB
/
06_02_plot_results.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
"""
It prints information about the SVM analysis (i.e., how many REACTOME pathways can predict each tissue, and how many
tissues each REACTOME pathway can predict).
"""
import pickle
from collections import defaultdict
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from mpl_toolkits.axes_grid1 import make_axes_locatable
from definitions import TISSUES
indexes = []
all_data_f1 = []
reactomes = pd.read_table("meta_data/reactomes_names.txt", header=None).iloc[:, 0].values
for react in reactomes:
dic_community = pickle.load(open("svm_results/r_" + react + ".pkl", "rb"))
# Going over each tissue
arr_f1 = []
for f_name in TISSUES:
arr_f1.append(dic_community[f_name]['f1'])
all_data_f1.append(arr_f1)
indexes.append(react)
all_f1 = pd.DataFrame(all_data_f1, index=indexes, columns=TISSUES)
##########
# Plotting it all
fig, ax = plt.subplots(figsize=(60, 120))
im = ax.imshow(all_f1.values, cmap='bwr', interpolation='none', vmin=0, vmax=1)
ax.set_xticks(np.arange(len(TISSUES)))
ax.set_xticklabels(TISSUES)
ax.set_yticks(np.arange(len(indexes)))
ax.set_yticklabels(indexes)
plt.setp(ax.get_xticklabels(), rotation=45, ha="right",
rotation_mode="anchor")
ax.set_title("F1 scores of each REACTOME predicting tissue", fontweight='bold')
ax.set_ylabel("Reactomes", fontweight='bold')
ax.set_xlabel("Tissues being predicted", fontweight='bold')
# create an axes on the right side of ax. The width of cax will be 5%
# of ax and the padding between cax and ax will be fixed at 0.5 inch.
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.5)
fig.colorbar(im, cax=cax)
fig.tight_layout()
plt.savefig("figures/f1_reactomes_tissues.png")
plt.close(fig)
##############
# Printing/plotting some other details
# enumerate here just because of order in the folder
for ind, tissue in enumerate(TISSUES):
print("***** " + tissue + " *****")
tmp = pd.DataFrame(all_f1.loc[all_f1[tissue] > 0.8, tissue].sort_values(ascending=False).round(decimals=4))
if tmp.shape[0] == 0:
print(" Not predicted by any reactome!")
print()
continue
print("Predicted by " + str(tmp.shape[0]) + " reactomes")
print()
plt.figure()
tablea = plt.table(cellText=tmp.values, loc='center', rowLabels=tmp.index.values,
colLabels=['F1 Score for ' + tissue])
tablea.properties()['celld'][(0, 0)].set_text_props(fontweight='bold')
plt.axis('off')
plt.tight_layout()
plt.savefig("figures/react_" + str(ind) + "_" + tissue + ".png", transparent=True, bbox_inches='tight')
plt.close()
print()
print()
print()
results_per_reactome = defaultdict(list)
for ind in range(all_f1.shape[0]):
row = all_f1.iloc[ind, :]
results_per_reactome[sum(row > 0.8)].append(row.name)
for no in sorted(results_per_reactome.keys(), reverse=True):
print("****** Reactomes which can predict " + str(no) + " tissues ******")
print("\n".join(sorted(results_per_reactome[no])))
print()
print()
print()
print()