-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_result_rsi.py
111 lines (95 loc) · 5.12 KB
/
process_result_rsi.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
# -*- coding: utf-8 -*-
"""
Created on Fri May 5 20:09:05 2023
@author: yutah
"""
import os
import numpy as np
from codes.constructOutpath import constructCCPpathResults, constructPCApathResults, constructNMFpathResults
from codes.constructOutpath import constructCCPpathResultsClassification, constructPCApathResultsClassification, constructNMFpathResultsClassification
from codes.constructOutpath import constructCCPpathResultsRSI, constructPCApathResultsRSI
from codes.computeRSI import computeRSIclustering, computeRSItrue, computeRSI5fold
def makeFolder(outpath):
try:
os.makedirs(outpath)
except:
return
return
def writeCSV(outpath, lines):
file = open(outpath, 'w')
for line in lines:
outline = ''
for l in line:
outline = outline + str(l) + ','
outline = outline[:-1] + '\n'
file.write(outline)
file.close()
return
data_vec = ['GSE45719', 'GSE67835', 'GSE75748cell', 'GSE75748time', 'GSE82187', 'GSE84133human1', 'GSE84133human2', 'GSE84133human3', 'GSE84133human4', 'GSE84133mouse1', 'GSE84133mouse2', 'GSE89232', 'GSE94820']
max_state = 20
n_components_vec = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300]
#CCP
for data in data_vec:
outpath = './results/%s_results/'%(data); makeFolder(outpath)
outpath_ccp_results = constructCCPpathResultsRSI(data)
outfile = outpath + '%s_ccp_rsi.csv'%(data)
lines = [['n_components,R clustering,S clustering,RS clustering,R 5fold,S 5fold,RS 5fold,R true,S true,RS true']]
for n_components in n_components_vec:
r_clustering_nc = []; s_clustering_nc = []; rs_clustering_nc = []
r_5fold_nc = []; s_5fold_nc = []; rs_5fold_nc = []
r_true_nc = []; s_true_nc = []; rs_true_nc = []
for state in range(1, max_state + 1):
infile = '%s_ccp_n%d_state%d'%(data, n_components, state)
rsi_clustering = np.load(outpath_ccp_results + infile + '_clustering_rsi.npy');
rsi_clustering = np.mean(rsi_clustering, axis = 1)
rsi_clustering = np.mean(rsi_clustering, axis = 0)
r, s, rs = rsi_clustering
r_clustering_nc.append(r); s_clustering_nc.append(s); rs_clustering_nc.append(rs)
rsi_5fold = np.load(outpath_ccp_results + infile + '_5fold_rsi.npy');
rsi_5fold = np.mean(rsi_5fold, axis = 1)
rsi_5fold = np.mean(rsi_5fold, axis = 0)
r, s, rs = rsi_5fold
r_5fold_nc.append(r); s_5fold_nc.append(s); rs_5fold_nc.append(rs)
rsi_true = np.load(outpath_ccp_results + infile + '_true_rsi.npy');
rsi_true = np.mean(rsi_true, axis = 1)
rsi_true = np.mean(rsi_true, axis = 0)
r, s, rs = rsi_5fold
r_true_nc.append(r); s_true_nc.append(s); rs_true_nc.append(rs)
line = [n_components, np.mean(r_clustering_nc), np.mean(s_clustering_nc), np.mean(rs_clustering_nc),
np.mean(r_5fold_nc), np.mean(s_5fold_nc), np.mean(rs_5fold_nc),
np.mean(r_true_nc), np.mean(s_true_nc), np.mean(rs_true_nc)]
print(line)
lines.append(line)
writeCSV(outfile, lines)
#PCA
for data in data_vec:
outpath = './results/%s_results/'%(data); makeFolder(outpath)
outpath_pca_results = constructPCApathResultsRSI(data)
outfile = outpath + '%s_pca_rsi.csv'%(data)
lines = [['n_components,R clustering,S clustering,RS clustering,R 5fold,S 5fold,RS 5fold,R true,S true,RS true']]
for n_components in n_components_vec:
r_clustering_nc = []; s_clustering_nc = []; rs_clustering_nc = []
r_5fold_nc = []; s_5fold_nc = []; rs_5fold_nc = []
for state in range(1, max_state + 1):
infile = '%s_pca_n%d_state%d'%(data, n_components, state)
rsi_clustering = np.load(outpath_pca_results + infile + '_clustering_rsi.npy');
rsi_clustering = np.mean(rsi_clustering, axis = 1)
rsi_clustering = np.mean(rsi_clustering, axis = 0)
r, s, rs = rsi_clustering
r_clustering_nc.append(r); s_clustering_nc.append(s); rs_clustering_nc.append(rs)
rsi_5fold = np.load(outpath_pca_results + infile + '_5fold_rsi.npy');
rsi_5fold = np.mean(rsi_5fold, axis = 1)
rsi_5fold = np.mean(rsi_5fold, axis = 0)
r, s, rs = rsi_5fold
r_5fold_nc.append(r); s_5fold_nc.append(s); rs_5fold_nc.append(rs)
rsi_true = np.load(outpath_pca_results + infile + '_true_rsi.npy');
rsi_true = np.mean(rsi_true, axis = 1)
rsi_true = np.mean(rsi_true, axis = 0)
r, s, rs = rsi_5fold
r_true_nc.append(r); s_true_nc.append(s); rs_true_nc.append(rs)
line = [n_components, np.mean(r_clustering_nc), np.mean(s_clustering_nc), np.mean(rs_clustering_nc),
np.mean(r_5fold_nc), np.mean(s_5fold_nc), np.mean(rs_5fold_nc),
np.mean(r_true_nc), np.mean(s_true_nc), np.mean(rs_true_nc)]
print(line)
lines.append(line)
writeCSV(outfile, lines)