-
Notifications
You must be signed in to change notification settings - Fork 4
/
evaluate_hockley_robustness_magic_seurat.py
executable file
·207 lines (181 loc) · 8.06 KB
/
evaluate_hockley_robustness_magic_seurat.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
###################################################
### ###
### Evaluation of Robustness experiment using ###
### MAGIC or Seurat pre-processed Hockley data ###
### written by Bettina Mieth, Nico Görnitz, ###
### Marina Vidovic and Alex Gutteridge ###
### ###
###################################################
# Please change all directories to yours!
import sys
sys.path.append('/home/bmieth/scRNAseq/implementations')
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
from sklearn.manifold import TSNE
if __name__ == "__main__":
# Loading data - Please change directories to yours
foo = np.load('/home/bmieth/scRNAseq/results/jims_data/magic/jimtarget_usoskinsource_magic_1000reps.npz')
foo_for_clusterident = np.load('/home/bmieth/scRNAseq/results/jims_data/final_for_pub_k7/jimtarget_usoskinsource_level3labels.npz')
num_exps = foo['reps']
# mNP and mNFa clusters
print('Counting the numbers for mNP and mNFa clusters!')
# Identify the two clusters
trg_labels_all = foo_for_clusterident['trg_labels']
res_opt_mix_ind = foo_for_clusterident['res_opt_mix_ind']
trg_labels = trg_labels_all[:, res_opt_mix_ind+2]
cl1 = (trg_labels == 6)
cell_names_target = foo_for_clusterident['cell_names_target']
cluster_1 = cell_names_target[cl1].flatten()
cl2 = (trg_labels == 4)
cluster_2 = cell_names_target[cl2].flatten()
# SC3 Mix with level 3 labels, TransferCluster
trg_labels_l3 = foo['trg_labels_reps']
data_target_preprocessed = foo['data_target']
trg_labels_SC3 = trg_labels_l3[:,0,:]
counter_SC3 = 0
successful_flag = np.ones(num_exps, dtype=bool)
# SC3 alone, TargetCluster
for i in np.arange(num_exps):
cl1_labels = trg_labels_SC3[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_SC3[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_SC3=counter_SC3+1
successful_flag[i] = False
# SC3 comb, ConcatenateCluster
trg_labels_SC3_COMB = trg_labels_l3[:,1,:]
counter_SC3_COMB = 0
for i in np.arange(num_exps):
cl1_labels = trg_labels_SC3_COMB[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_SC3_COMB[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_SC3_COMB=counter_SC3_COMB+1
else:
successful_flag[i] = False
trg_labels_l3 = trg_labels_l3[:,2,:]
counter_l3 = 0
for i in np.arange(num_exps):
cl1_labels = trg_labels_l3[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_l3[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_l3=counter_l3+1
else:
successful_flag[i] = False
# Print results (i.e. counts of successful identifications of mNP / mNFa clusters)
print('Counter SC3: ', counter_SC3)
print('Counter SC3 Comb: ', counter_SC3_COMB)
print('Counter SC3 L3: ', counter_l3)
# pNF clusters
print('Counting the numbers for pNF clusters!')
# Identify the two clusters
trg_labels_all = foo_for_clusterident['trg_labels']
res_opt_mix_ind = foo_for_clusterident['res_opt_mix_ind']
trg_labels = trg_labels_all[:, res_opt_mix_ind+2]
cl1 = (trg_labels == 0)
cell_names_target = foo_for_clusterident['cell_names_target']
cluster_1 = cell_names_target[cl1].flatten()
cl2 = (trg_labels == 3)
cluster_2 = cell_names_target[cl2].flatten()
# SC3 Mix with level 3 labels, TransferCluster
trg_labels_l3 = foo['trg_labels_reps']
data_target_preprocessed = foo['data_target']
trg_labels_SC3 = trg_labels_l3[:,0,:]
counter_SC3 = 0
# SC3 alone, TargetCluster
for i in np.arange(num_exps):
cl1_labels = trg_labels_SC3[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_SC3[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_SC3=counter_SC3+1
else:
successful_flag[i] = False
# SC3 Comb, ConcatenateCluster
trg_labels_SC3_COMB = trg_labels_l3[:,1,:]
counter_SC3_COMB = 0
for i in np.arange(num_exps):
cl1_labels = trg_labels_SC3_COMB[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_SC3_COMB[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_SC3_COMB=counter_SC3_COMB+1
else:
successful_flag[i] = False
trg_labels_l3 = trg_labels_l3[:,2,:]
counter_l3 = 0
for i in np.arange(num_exps):
cl1_labels = trg_labels_l3[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_l3[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_l3=counter_l3+1
else:
successful_flag[i] = False
# Print results (i.e. counts of successful identifications of pNF clusters)
print('Counter SC3: ', counter_SC3)
print('Counter SC3 Comb: ', counter_SC3_COMB)
print('Counter SC3 L3: ', counter_l3)
# pPEP clusters
print('Counting the numbers for pPEP clusters!')
# Identify the two clusters
trg_labels_all = foo_for_clusterident['trg_labels']
res_opt_mix_ind = foo_for_clusterident['res_opt_mix_ind']
trg_labels = trg_labels_all[:, res_opt_mix_ind+2]
cl1 = (trg_labels == 5)
cell_names_target = foo_for_clusterident['cell_names_target']
cluster_1 = cell_names_target[cl1].flatten()
cl2 = (trg_labels == 2)
cluster_2 = cell_names_target[cl2].flatten()
# SC3 Mix with level 3 labels, TransferCluster
trg_labels_l3 = foo['trg_labels_reps']
data_target_preprocessed = foo['data_target']
trg_labels_SC3 = trg_labels_l3[:,0,:]
counter_SC3 = 0
# SC3 alone, TargetCluster
for i in np.arange(num_exps):
cl1_labels = trg_labels_SC3[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_SC3[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_SC3=counter_SC3+1
else:
successful_flag[i] = False
# SC3 Comb, ConcatenateCluster
trg_labels_SC3_COMB = trg_labels_l3[:,1,:]
counter_SC3_COMB = 0
for i in np.arange(num_exps):
cl1_labels = trg_labels_SC3_COMB[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_SC3_COMB[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_SC3_COMB=counter_SC3_COMB+1
successful_flag[i] = False
trg_labels_l3 = trg_labels_l3[:,2,:]
counter_l3 = 0
for i in np.arange(num_exps):
cl1_labels = trg_labels_l3[cl1,i] .tolist()
cl1_most_common = max(set(cl1_labels), key=cl1_labels.count)
cl2_labels = trg_labels_l3[cl2,i] .tolist()
cl2_most_common = max(set(cl2_labels), key=cl2_labels.count)
if cl1_most_common != cl2_most_common:
counter_l3=counter_l3+1
else:
successful_flag[i] = False
# Print results (i.e. counts of successful identifications of pPEP clusters
print('Counter SC3: ', counter_SC3)
print('Counter SC3 Comb: ', counter_SC3_COMB)
print('Counter SC3 L3: ', counter_l3)
print(np.where(successful_flag)[0])
print('Done')