-
Notifications
You must be signed in to change notification settings - Fork 1
/
umap_test_new.py
1454 lines (1058 loc) · 58.9 KB
/
umap_test_new.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 19 12:38:57 2022
@author: adrian
"""
import os
import sys
# TODO: Select path wrt your system
#os.chdir('/mnt/genzel/Rat/OS_Ephys_RGS14_analysis/UMAP');
os.chdir('/mnt/genzel/Rat/OS_CBD_analysis/chronic')
#os.chdir('/home/blazkowiz47/work/UMAP/dataset');
# sys.path.append('/home/genzel/Documents/UMAP')
import scipy.io
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as cl
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sns
import cv2
import umap
#import plotly.express as px
from URC_computeIsomapDimEst import isomapDimEst
import utils.plotting_helpers as hplt
import utils.processing_helpers as hproc
from sklearn.cluster import KMeans, DBSCAN
from seaborn import kdeplot
import pickle
sns.set(style='white',context='poster', rc={'figure.figsize':(14,10)} )
# %% Load whole table and split columns
### Start Loading data
#Includes ripples from all datasets
myDict = scipy.io.loadmat('Tcell_17_01_2023.mat')
T=myDict['T_cell']
#CBD dataset
myDict = scipy.io.loadmat('Tcell_cbd_17_01_2023.mat')
T_cbd=myDict['Tcell']
#RGS dataset
myDict = scipy.io.loadmat('Tcell_RGS14_03_12_2022.mat')
T_rgs=myDict['Tcell_RGS14_03_12_2022']
#OS Basic dataset
myDict = scipy.io.loadmat('Tcell_OSBASIC_17_01_2023.mat')
T_osbasic=myDict['Tcell']
#We use T which contains data from all datasets.
#Ripples waveforms
Ripples=T[:,5]
Data = hproc.v_stack(Ripples[2:]) #Number of ripples by 127
#Dataset label
#dataset_np=T[:,0]
dataset_rip=hproc.unfold_days2ripples(Ripples,T[:,0])
#Treatment
#treatment_np=T[:,1]
treatment_rip=hproc.unfold_days2ripples(Ripples,T[:,1])
#Rat
#rat_np=T[:,2]
rat_rip=hproc.unfold_days2ripples(Ripples, T[:,2])
#StudyDay
#StudyDay_np=T[:,3]
StudyDay_rip=hproc.unfold_days2ripples(Ripples, T[:,3])
#Trial
#trial_np=T[:,4]
trial_rip=hproc.unfold_days2ripples(Ripples,T[:,4])
# %%
# #Amplitude
# amplitude_np=T[:,6];
# #Meanfreq
# meanfreq_np=T[:,7];
# #Duration
# duration_np=T[:,8];
# #Phase
# phase_np=T[:,9];
# # SO power before
# so_before_np=T[:,10];
# # SO power after
# so_after_np=T[:,11];
# # Spectral entropy
# s_entropy_np=T[:,13];
#Features per ripple
# Amp=hproc.flatcells(amplitude_np[2:]);
# Meanfreq=hproc.flatcells(meanfreq_np[2:]);
# Duration=hproc.flatcells(duration_np[2:]);
# Phase=hproc.flatcells(phase_np[2:]);
# SO_before=hproc.flatcells(so_before_np[2:]);
# SO_after=hproc.flatcells(so_after_np[2:]);
# S_entropy=hproc.flatcells(s_entropy_np[2:]);
Amp=hproc.flatcells(T[2:,6]);
Meanfreq=hproc.flatcells(T[2:,7]);
Duration=hproc.flatcells(T[2:,8]);
Phase=hproc.flatcells(T[2:,9]);
SO_before=hproc.flatcells(T[2:,10]);
SO_after=hproc.flatcells(T[2:,11]);
S_entropy=hproc.flatcells(T[2:,13]);
#Separate datasets: T_cbd, T_rgs, T_osbasic. (Split for sanite check, ideally just use T)
Ripples_cbd=T_cbd[:,5]
Ripples_cbd=Ripples_cbd[2:];
Data_cbd = hproc.v_stack(Ripples_cbd)
Ripples_rgs=T_rgs[:,5]
Data_rgs = hproc.v_stack(Ripples_rgs)
treatment_np_rgs=T_rgs[:,1]
treatment_rip_rgs=hproc.unfold_days2ripples(Ripples_rgs,treatment_np_rgs)
Ripples_osbasic=T_osbasic[:,5]
Data_osbasic = hproc.v_stack(Ripples_osbasic)
# %% Compute UMAP from Data (T)
# fit = umap.UMAP(n_components=4)
# u=fit.fit_transform(Data)
# # Compute from split datasets.
# u_cbd = fit.fit_transform(Data_cbd)
# u_rgs = fit.fit_transform(Data_rgs)
# u_osbasic = fit.fit_transform(Data_osbasic)
# %% Figures, describing embeddings.
# def cm2inch(value):
# return value/2.54
# figsize=(cm2inch(3.5), cm2inch(3.5))
# plt.figure(figsize=(cm2inch(12.8), cm2inch(9.6)))
# %% Looking for outliers
#Density
# hplt.plot3Ddensity(u_rgs[:,0],u_rgs[:,1],u_rgs[:,2], zlabel='umap 3', bins=50)
# hplt.plot3Ddensity(u_cbd[:,0],u_cbd[:,1],u_cbd[:,3], zlabel='umap 4', bins=50)
# hplt.plot3Ddensity(u_osbasic[:,0],u_osbasic[:,1],u_osbasic[:,2], zlabel='umap 3', bins=50)
# hplt.plot3Ddensity(u[:,0],u[:,1],u[:,3], zlabel='umap 4', bins=50)
# %% Remove outliers using DBSCAN clustering.
# [outliers_osbasic]=hproc.dbscan_outliers(u_osbasic, "OS_basic", eps_value=0.2, min_samples_value=10, outlier_label=1)
# [outliers_rgs]=hproc.dbscan_outliers(u_rgs, "RGS14", eps_value=0.2, min_samples_value=10, outlier_label=1)
# [outliers_cbd]=hproc.dbscan_outliers(u_cbd, "CBD", eps_value=0.10, min_samples_value=1, outlier_label=1)
# [outliers]=hproc.dbscan_outliers(u, "Combined", eps_value=0.2, min_samples_value=5, outlier_label=1)
# [np.sum(outliers_osbasic), np.sum(outliers_rgs), np.sum(outliers_cbd), np.sum(outliers)]
# # Using combined outliers from all datasets.
# outliers_combined=np.concatenate([outliers_cbd,outliers_osbasic,outliers_rgs]);
# list_outliers=[outliers_osbasic,outliers_rgs,outliers_cbd,outliers,outliers_combined];
# with open('outliers.pkl', 'wb') as f: # Python 3: open(..., 'wb')
# pickle.dump(list_outliers, f)
# # Getting back the objects:
with open('outliers.pkl','rb') as f: # Python 3: open(..., 'rb')
outliers_list= pickle.load(f)
outliers_osbasic=outliers_list[0];
outliers_rgs=outliers_list[1];
outliers_cbd=outliers_list[2];
outliers=outliers_list[3];
outliers_combined=outliers_list[4];
# %% Remove outliers from features data.
Meanfreq_combined=Meanfreq[np.logical_not(outliers_combined)];
Amp_combined=Amp[np.logical_not(outliers_combined)];
Duration_combined=Duration[np.logical_not(outliers_combined)];
Phase_combined=Phase[np.logical_not(outliers_combined)];
SO_before_combined=SO_before[np.logical_not(outliers_combined)];
SO_after_combined=SO_after[np.logical_not(outliers_combined)];
S_entropy_combined=S_entropy[np.logical_not(outliers_combined)];
# %% Re compute UMAP without outliers
fit = umap.UMAP(n_components=4)
Data_clean=Data[np.logical_not(outliers_combined)];
u_clean=fit.fit_transform(Data[np.logical_not(outliers_combined)])
# Separate datasets
u_cbd_clean = fit.fit_transform(Data_cbd[np.logical_not(outliers_cbd)])
u_rgs_clean = fit.fit_transform(Data_rgs[np.logical_not(outliers_rgs)])
u_osbasic_clean = fit.fit_transform(Data_osbasic[np.logical_not(outliers_osbasic)])
# %%
#Density
# hplt.plot3Ddensity(u_rgs_clean[:,0],u_rgs_clean[:,1],u_rgs_clean[:,2], zlabel='umap 3', bins=50)
# hplt.plot3Ddensity(u_cbd_clean[:,0],u_cbd_clean[:,1],u_cbd_clean[:,3], zlabel='umap 4', bins=50)
# hplt.plot3Ddensity(u_osbasic_clean[:,0],u_osbasic_clean[:,1],u_osbasic_clean[:,2], zlabel='umap 3', bins=50)
# hplt.plot3Ddensity(u[:,0],u[:,1],u[:,3], zlabel='umap 4', bins=50)
# %% Figures, describing embeddings. Per dataset. Without outliers
# def cm2inch(value):
# return value/2.54
# figsize=(cm2inch(3.5), cm2inch(3.5))
# plt.figure(figsize=(cm2inch(12.8), cm2inch(9.6)))
list_colours=['#0343DF','#E50000','#15B01A','black'];
list_embeddings=[u_rgs_clean,u_osbasic_clean,u_cbd_clean,u_clean];
list_names=["RGS14 dataset","OS basic dataset", "CBD dataset","Combined datasets"]
for (item,colours,names) in zip(list_embeddings, list_colours,list_names):
hplt.plot_scatter(item[:,0],item[:,1] ,title=names,s=1,xlabel='Umap 1',ylabel='Umap 2',c=colours)
plt.xlim([-1,11])
plt.ylim([-1,11])
#%% Store outliers in Dataframe
df = pd.DataFrame(dataset_rip[outliers_combined], columns = ['Dataset'])
df['Treatment'] = treatment_rip[outliers_combined]
df['Rat'] = rat_rip[outliers_combined]
df['StudyDay'] = StudyDay_rip[outliers_combined]
df['Trial'] = trial_rip[outliers_combined]
df.to_csv('outliers.csv')
#%%
#%% Split by treatment, not by dataset.
treatment_veh=hproc.strcmp(treatment_rip,"VEH") #OSBASIC #RGS14
treatment_cbd=hproc.strcmp(treatment_rip,"CBD") #OSBASIC #RGS14
treatment_rgs=hproc.strcmp(treatment_rip,"RGS") #OSBASIC #RGS14
# Data_veh_treatment=Data[np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined))]
# Data_cbd_treatment=Data[np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined))]
# Data_rgs_treatment=Data[np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined))]
# fit = umap.UMAP(n_components=4)
# u_cbd_treatment = fit.fit_transform(Data_cbd_treatment)
# u_rgs_treatment = fit.fit_transform(Data_rgs_treatment)
# u_veh_treatment = fit.fit_transform(Data_veh_treatment)
# #%%
# list_colours=['#0343DF','#E50000','#15B01A','black'];
# list_embeddings=[u_rgs_treatment,u_veh_treatment,u_cbd_treatment,u_clean];
# list_names=["RGS14 treatment","Vehicle treatment", "CBD treatment","Combined treatment"]
# for (item,colours,names) in zip(list_embeddings, list_colours,list_names):
# #ax = fig.add_subplot()
# hplt.plot_scatter(item[:,0],item[:,1] ,title=names,s=1,xlabel='Umap 1',ylabel='Umap 2',c=colours)
# plt.xlim([-1,11])
# plt.ylim([-1,11])
# # %%
# hplt.plot3Ddensity(u_rgs_treatment[:,0],u_rgs_treatment[:,1],u_rgs_treatment[:,2], zlabel='umap 3', bins=50)
# hplt.plot3Ddensity(u_cbd_treatment[:,0],u_cbd_treatment[:,1],u_cbd_treatment[:,2], zlabel='umap 3', bins=50)
# hplt.plot3Ddensity(u_veh_treatment[:,0],u_veh_treatment[:,1],u_veh_treatment[:,2], zlabel='umap 3', bins=50)
# hplt.plot3Ddensity(u_clean[:,0],u_clean[:,1],u_clean[:,2], zlabel='umap 3', bins=50)
# %% Splitting controls.
dataset_osbasic=hproc.strcmp(dataset_rip,"OSBASIC") #OSBASIC
dataset_cbd=hproc.strcmp(dataset_rip,"CBDchronic") #CBD
dataset_rgs=hproc.strcmp(dataset_rip,"RGS14") #RGS14
#Controls
Data_veh_osbasic_dataset=Data[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
Data_veh_rgs_dataset=Data[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Data_veh_cbd_dataset=Data[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
Data_rgs_rgs_dataset=Data[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Data_cbd_cbd_dataset=Data[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
# All combined except RGS.
Data_combined_no_rgs=np.concatenate([Data_veh_cbd_dataset,Data_cbd_cbd_dataset,Data_veh_osbasic_dataset]);
fit = umap.UMAP(n_components=4)
# Controls
u_veh_osbasic = fit.fit_transform(Data_veh_osbasic_dataset)
u_veh_rgs = fit.fit_transform(Data_veh_rgs_dataset)
u_veh_cbd = fit.fit_transform(Data_veh_cbd_dataset)
# Non-controls
u_rgs_rgs = fit.fit_transform(Data_rgs_rgs_dataset)
u_cbd_cbd = fit.fit_transform(Data_cbd_cbd_dataset)
#u_rgs_rgs.shape[0]+u_veh_rgs.shape[0]+u_cbd_cbd.shape[0]+u_veh_cbd.shape[0]+u_veh_osbasic.shape[0]
u_combined_no_rgs = fit.fit_transform(Data_combined_no_rgs)
# %% Plot all embeddings for controls and treatments
plt.rc('font', size=35)
plt.rc('axes', titlesize=35, labelsize=35)
list_colours=['#E50000','purple','saddlebrown','#15B01A','#0343DF','black','gold'];
list_embeddings=[u_veh_osbasic,u_veh_rgs,u_veh_cbd,u_cbd_cbd,u_rgs_rgs,u_clean,u_combined_no_rgs];
list_names=["OS Basic","VEH treatment-RGS dataset", "VEH treatment-CBD dataset","CBD treatment-CBD dataset","RGS treatment-RGS dataset","Combined","Combined (no RGS dataset)"]
for (item,colours,names) in zip(list_embeddings, list_colours,list_names):
hplt.plot_scatter(item[:,0],item[:,1] ,title=names,s=1,xlabel='Umap 1',ylabel='Umap 2',c=colours)
plt.xlim([-1,11])
plt.ylim([-1,11])
# %% Saving embeddings/ Data.
# Saving embeddings:
list_embeddings=[u_veh_osbasic,u_veh_rgs,u_veh_cbd,u_cbd_cbd,u_rgs_rgs,u_clean,u_combined_no_rgs];
with open('embeddings.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_embeddings, f)
# # Getting back the objects:
with open('embeddings.pkl','rb') as f: # Python 3: open(..., 'rb')
embeddings= pickle.load(f)
u_veh_osbasic=embeddings[0];
u_veh_rgs=embeddings[1];
u_veh_cbd=embeddings[2];
u_cbd_cbd=embeddings[3];
u_rgs_rgs=embeddings[4];
u_clean=embeddings[5];
u_combined_no_rgs=embeddings[6];
# Saving data:
list_data=[Data_veh_osbasic_dataset,Data_veh_rgs_dataset,Data_veh_cbd_dataset,Data_cbd_cbd_dataset,Data_rgs_rgs_dataset,Data_clean,Data_combined_no_rgs];
with open('Data.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_data, f)
#,u_veh_rgs,u_veh_cbd,u_cbd_cbd,u_rgs_rgs,u_clean,u_combined_no_rgs];
with open('Data.pkl','rb') as f: # Python 3: open(..., 'rb')
Data= pickle.load(f)
Data_veh_osbasic_dataset=Data[0];
Data_veh_rgs_dataset=Data[1];
Data_veh_cbd_dataset=Data[2];
Data_cbd_cbd_dataset=Data[3];
Data_rgs_rgs_dataset=Data[4];
Data_clean=Data[5];
Data_combined_no_rgs=Data[6];
# %% RGSs
# hplt.plot_umap_binary(u_veh_rgs[:,0],u_veh_rgs[:,1] ,title="VEH RGS",s=1,xlabel='Umap 1',ylabel='Umap 2',c='#0343DF')
# plt.xlim([-1,11])
# plt.ylim([-1,11])
# #u_rgs_treatment
# hplt.plot_umap_binary(u_rgs_treatment[:,0],u_rgs_treatment[:,1] ,title="RGS treatment",s=1,xlabel='Umap 1',ylabel='Umap 2',c='#0343DF')
# plt.xlim([-1,11])
# plt.ylim([-1,11])
# hplt.plot3Ddensity(u_veh_rgs[:,0],u_veh_rgs[:,1],u_veh_rgs[:,2], zlabel='umap 3', bins=50)
# hplt.plot3Ddensity(u_rgs_treatment[:,0],u_rgs_treatment[:,1],u_rgs_treatment[:,2], zlabel='umap 3', bins=50)
# %%
# D_rgs_veh=Data_rgs[np.squeeze(treatment_rip_rgs=='VEH')];
# D_rgs_rgs=Data_rgs[np.squeeze(treatment_rip_rgs=='RGS')];
# fit = umap.UMAP(n_components=4)
# u_rgs_veh = fit.fit_transform(D_rgs_veh)
# u_rgs_rgs = fit.fit_transform(D_rgs_rgs)
# hplt.plot_umap_binary(u_rgs_veh[:,0],u_rgs_veh[:,1] ,title="RGS VEH",s=1,xlabel='Umap 1',ylabel='Umap 2',c='#0343DF')
# plt.xlim([-1,11])
# plt.ylim([-1,11])
# hplt.plot_umap_binary(u_rgs_rgs[:,0],u_rgs_rgs[:,1] ,title="RGS RGS",s=1,xlabel='Umap 1',ylabel='Umap 2',c='#0343DF')
# plt.xlim([-1,11])
# plt.ylim([-1,11])
# %% Displaying features in embedding.
Meanfreq_veh_osbasic_dataset=Meanfreq[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
Meanfreq_veh_rgs_dataset=Meanfreq[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Meanfreq_veh_cbd_dataset=Meanfreq[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
Meanfreq_rgs_rgs_dataset=Meanfreq[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Meanfreq_cbd_cbd_dataset=Meanfreq[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
Meanfreq_combined_no_rgs=np.concatenate([Meanfreq_veh_cbd_dataset,Meanfreq_cbd_cbd_dataset,Meanfreq_veh_osbasic_dataset]);
hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = Meanfreq_veh_osbasic_dataset, title='Veh OS Basic',clipmin=100,clipmax=200)
hplt.plot_umap(x=u_veh_rgs[:,0],y=u_veh_rgs[:,1],feature = Meanfreq_veh_rgs_dataset, title='Veh treatment- RGS dataset',clipmin=100,clipmax=200)
hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = Meanfreq_veh_cbd_dataset, title='Veh treatment- CBD dataset',clipmin=100,clipmax=200)
hplt.plot_umap(x=u_rgs_rgs[:,0],y=u_rgs_rgs[:,1],feature = Meanfreq_rgs_rgs_dataset, title='RGS treatment- RGS dataset',clipmin=100,clipmax=200)
hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = Meanfreq_cbd_cbd_dataset,title='CBD treatment- CBD dataset',clipmin=100,clipmax=200)
hplt.plot_umap(x=u_clean[:,0],y=u_clean[:,1],feature = Meanfreq_combined,title='Combined',clipmin=100,clipmax=200)
hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = Meanfreq_combined_no_rgs,title='Combined (No RGS)',clipmin=100,clipmax=200)
# %%
# Saving embeddings:
list_Meanfreq=[Meanfreq_veh_osbasic_dataset,Meanfreq_veh_cbd_dataset,Meanfreq_cbd_cbd_dataset,Meanfreq_combined,Meanfreq_combined_no_rgs];
with open('Meanfreq.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_Meanfreq, f)
# # Getting back the objects:
with open('Meanfreq.pkl','rb') as f: # Python 3: open(..., 'rb')
Meanfreq_list= pickle.load(f)
Meanfreq_veh_osbasic_dataset=Meanfreq_list[0];
Meanfreq_veh_cbd_dataset=Meanfreq_list[1];
Meanfreq_cbd_cbd_dataset=Meanfreq_list[2];
Meanfreq_combined=Meanfreq_list[3];
Meanfreq_combined_no_rgs=Meanfreq_list[4];
# %%
Amp_veh_osbasic_dataset=Amp[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
Amp_veh_rgs_dataset=Amp[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Amp_veh_cbd_dataset=Amp[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
Amp_rgs_rgs_dataset=Amp[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Amp_cbd_cbd_dataset=Amp[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
Amp_combined_no_rgs=np.concatenate([Amp_veh_cbd_dataset,Amp_cbd_cbd_dataset,Amp_veh_osbasic_dataset]);
hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = Amp_veh_osbasic_dataset, title='Veh OS Basic',clipmin=0,clipmax=4.5)
hplt.plot_umap(x=u_veh_rgs[:,0],y=u_veh_rgs[:,1],feature = Amp_veh_rgs_dataset, title='Veh treatment- RGS dataset',clipmin=0,clipmax=4.5)
hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = Amp_veh_cbd_dataset, title='Veh treatment- CBD dataset',clipmin=0,clipmax=4.5)
hplt.plot_umap(x=u_rgs_rgs[:,0],y=u_rgs_rgs[:,1],feature = Amp_rgs_rgs_dataset, title='RGS treatment- RGS dataset',clipmin=0,clipmax=4.5)
hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = Amp_cbd_cbd_dataset,title='CBD treatment- CBD dataset',clipmin=0,clipmax=4.5)
hplt.plot_umap(x=u_clean[:,0],y=u_clean[:,1],feature = Amp_combined,title='Combined',clipmin=0,clipmax=4.5)
hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = Amp_combined_no_rgs,title='Combined (No RGS)',clipmin=0,clipmax=4.5)
# %%
# Saving embeddings:
list_Amp=[Amp_veh_osbasic_dataset,Amp_veh_cbd_dataset,Amp_cbd_cbd_dataset,Amp_combined,Amp_combined_no_rgs];
with open('Amp.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_Amp, f)
# # Getting back the objects:
with open('Amp.pkl','rb') as f: # Python 3: open(..., 'rb')
Amp_list= pickle.load(f)
Amp_veh_osbasic_dataset=Amp_list[0];
Amp_veh_cbd_dataset=Amp_list[1];
Amp_cbd_cbd_dataset=Amp_list[2];
Amp_combined=Amp_list[3];
Amp_combined_no_rgs=Amp_list[4];
# %%
Duration_veh_osbasic_dataset=Duration[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
Duration_veh_rgs_dataset=Duration[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Duration_veh_cbd_dataset=Duration[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
Duration_rgs_rgs_dataset=Duration[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Duration_cbd_cbd_dataset=Duration[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
Duration_combined_no_rgs=np.concatenate([Duration_veh_cbd_dataset,Duration_cbd_cbd_dataset,Duration_veh_osbasic_dataset]);
hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = Duration_veh_osbasic_dataset, title='Veh OS Basic',clipmin=0,clipmax=100)
#hplt.plot_umap(x=u_veh_rgs[:,0],y=u_veh_rgs[:,1],feature = Duration_veh_rgs_dataset, title='Veh treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = Duration_veh_cbd_dataset, title='Veh treatment- CBD dataset',clipmin=0,clipmax=100)
#hplt.plot_umap(x=u_rgs_rgs[:,0],y=u_rgs_rgs[:,1],feature = Duration_rgs_rgs_dataset, title='RGS treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = Duration_cbd_cbd_dataset,title='CBD treatment- CBD dataset',clipmin=0,clipmax=100)
#hplt.plot_umap(x=u_clean[:,0],y=u_clean[:,1],feature = Duration_combined,title='Combined',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = Duration_combined_no_rgs,title='Combined (No RGS)',clipmin=0,clipmax=100)
# %%
# Saving embeddings:
list_Duration=[Duration_veh_osbasic_dataset,Duration_veh_cbd_dataset,Duration_cbd_cbd_dataset,Duration_combined,Duration_combined_no_rgs];
with open('Duration.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_Duration, f)
# # Getting back the objects:
with open('Duration.pkl','rb') as f: # Python 3: open(..., 'rb')
Duration_list= pickle.load(f)
Duration_veh_osbasic_dataset=Duration_list[0];
Duration_veh_cbd_dataset=Duration_list[1];
Duration_cbd_cbd_dataset=Duration_list[2];
Duration_combined=Duration_list[3];
Duration_combined_no_rgs=Duration_list[4];
# %%
Phase_veh_osbasic_dataset=Phase[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
Phase_veh_rgs_dataset=Phase[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Phase_veh_cbd_dataset=Phase[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
Phase_rgs_rgs_dataset=Phase[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
Phase_cbd_cbd_dataset=Phase[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
Phase_combined_no_rgs=np.concatenate([Phase_veh_cbd_dataset,Phase_cbd_cbd_dataset,Phase_veh_osbasic_dataset]);
hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = Phase_veh_osbasic_dataset, title='Veh OS Basic',clipmin=0,clipmax=360,cmap='twilight')
#hplt.plot_umap(x=u_veh_rgs[:,0],y=u_veh_rgs[:,1],feature = Phase_veh_rgs_dataset, title='Veh treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = Phase_veh_cbd_dataset, title='Veh treatment- CBD dataset',clipmin=0,clipmax=360,cmap='twilight')
#hplt.plot_umap(x=u_rgs_rgs[:,0],y=u_rgs_rgs[:,1],feature = Phase_rgs_rgs_dataset, title='RGS treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = Phase_cbd_cbd_dataset,title='CBD treatment- CBD dataset',clipmin=0,clipmax=360,cmap='twilight')
#hplt.plot_umap(x=u_clean[:,0],y=u_clean[:,1],feature = Phase_combined,title='Combined',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = Phase_combined_no_rgs,title='Combined (No RGS)',clipmin=0,clipmax=360,cmap='twilight')
# %%
# Saving embeddings:
list_Phase=[Phase_veh_osbasic_dataset,Phase_veh_cbd_dataset,Phase_cbd_cbd_dataset,Phase_combined,Phase_combined_no_rgs];
with open('Phase.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_Phase, f)
# # Getting back the objects:
with open('Phase.pkl','rb') as f: # Python 3: open(..., 'rb')
Phase_list= pickle.load(f)
Phase_veh_osbasic_dataset=Phase_list[0];
Phase_veh_cbd_dataset=Phase_list[1];
Phase_cbd_cbd_dataset=Phase_list[2];
Phase_combined=Phase_list[3];
Phase_combined_no_rgs=Phase_list[4];
# %%
from scipy import stats
#SO_before=stats.zscore(SO_before)
SO_before_veh_osbasic_dataset=SO_before[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
SO_before_veh_rgs_dataset=SO_before[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
SO_before_veh_cbd_dataset=SO_before[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
SO_before_rgs_rgs_dataset=SO_before[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
SO_before_cbd_cbd_dataset=SO_before[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
SO_before_combined_no_rgs=np.concatenate([SO_before_veh_cbd_dataset,SO_before_cbd_cbd_dataset,SO_before_veh_osbasic_dataset]);
hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = stats.zscore(SO_before_veh_osbasic_dataset), title='Veh OS Basic',clipmin=-1,clipmax=1)
#hplt.plot_umap(x=u_veh_rgs[:,0],y=u_veh_rgs[:,1],feature = SO_before_veh_rgs_dataset, title='Veh treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = stats.zscore(SO_before_veh_cbd_dataset), title='Veh treatment- CBD dataset',clipmin=-1,clipmax=1)
#hplt.plot_umap(x=u_rgs_rgs[:,0],y=u_rgs_rgs[:,1],feature = SO_before_rgs_rgs_dataset, title='RGS treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = stats.zscore(SO_before_cbd_cbd_dataset),title='CBD treatment- CBD dataset',clipmin=-1,clipmax=1)
#hplt.plot_umap(x=u_clean[:,0],y=u_clean[:,1],feature = SO_before_combined,title='Combined',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = stats.zscore(SO_before_combined_no_rgs),title='Combined (No RGS)',clipmin=-1,clipmax=1)
# %%
# Saving embeddings:
list_SO_before=[SO_before_veh_osbasic_dataset,SO_before_veh_cbd_dataset,SO_before_cbd_cbd_dataset,SO_before_combined,SO_before_combined_no_rgs];
with open('SO_before.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_SO_before, f)
# # Getting back the objects:
with open('SO_before.pkl','rb') as f: # Python 3: open(..., 'rb')
SO_before_list= pickle.load(f)
SO_before_veh_osbasic_dataset=SO_before_list[0];
SO_before_veh_cbd_dataset=SO_before_list[1];
SO_before_cbd_cbd_dataset=SO_before_list[2];
SO_before_combined=SO_before_list[3];
SO_before_combined_no_rgs=SO_before_list[4];
# %%
from scipy import stats
#SO_afterz=stats.zscore(SO_after)
SO_after_veh_osbasic_dataset=SO_after[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
SO_after_veh_rgs_dataset=SO_after[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
SO_after_veh_cbd_dataset=SO_after[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
SO_after_rgs_rgs_dataset=SO_after[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
SO_after_cbd_cbd_dataset=SO_after[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
SO_after_combined_no_rgs=np.concatenate([SO_after_veh_cbd_dataset,SO_after_cbd_cbd_dataset,SO_after_veh_osbasic_dataset]);
hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = stats.zscore(SO_after_veh_osbasic_dataset), title='Veh OS Basic',clipmin=-1,clipmax=1)
#hplt.plot_umap(x=u_veh_rgs[:,0],y=u_veh_rgs[:,1],feature = SO_after_veh_rgs_dataset, title='Veh treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = stats.zscore(SO_after_veh_cbd_dataset), title='Veh treatment- CBD dataset',clipmin=-1,clipmax=1)
#hplt.plot_umap(x=u_rgs_rgs[:,0],y=u_rgs_rgs[:,1],feature = SO_after_rgs_rgs_dataset, title='RGS treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = stats.zscore(SO_after_cbd_cbd_dataset),title='CBD treatment- CBD dataset',clipmin=-1,clipmax=1)
#hplt.plot_umap(x=u_clean[:,0],y=u_clean[:,1],feature = SO_after_combined,title='Combined',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = stats.zscore(SO_after_combined_no_rgs),title='Combined (No RGS)',clipmin=-1,clipmax=1)
# %%
# Saving embeddings:
list_SO_after=[SO_after_veh_osbasic_dataset,SO_after_veh_cbd_dataset,SO_after_cbd_cbd_dataset,SO_after_combined,SO_after_combined_no_rgs];
with open('SO_after.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_SO_after, f)
# # Getting back the objects:
with open('SO_after.pkl','rb') as f: # Python 3: open(..., 'rb')
SO_after_list= pickle.load(f)
SO_after_veh_osbasic_dataset=SO_after_list[0];
SO_after_veh_cbd_dataset=SO_after_list[1];
SO_after_cbd_cbd_dataset=SO_after_list[2];
SO_after_combined=SO_after_list[3];
SO_after_combined_no_rgs=SO_after_list[4];
# %%
S_entropy_veh_osbasic_dataset=S_entropy[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
S_entropy_veh_rgs_dataset=S_entropy[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
S_entropy_veh_cbd_dataset=S_entropy[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
S_entropy_rgs_rgs_dataset=S_entropy[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
S_entropy_cbd_cbd_dataset=S_entropy[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
S_entropy_combined_no_rgs=np.concatenate([S_entropy_veh_cbd_dataset,S_entropy_cbd_cbd_dataset,S_entropy_veh_osbasic_dataset]);
hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = S_entropy_veh_osbasic_dataset, title='Veh OS Basic',clipmin=2,clipmax=4.5)
#hplt.plot_umap(x=u_veh_rgs[:,0],y=u_veh_rgs[:,1],feature = S_entropy_veh_rgs_dataset, title='Veh treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = S_entropy_veh_cbd_dataset, title='Veh treatment- CBD dataset',clipmin=2,clipmax=4.5)
#hplt.plot_umap(x=u_rgs_rgs[:,0],y=u_rgs_rgs[:,1],feature = S_entropy_rgs_rgs_dataset, title='RGS treatment- RGS dataset',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = S_entropy_cbd_cbd_dataset,title='CBD treatment- CBD dataset',clipmin=2,clipmax=4.5)
#hplt.plot_umap(x=u_clean[:,0],y=u_clean[:,1],feature = S_entropy_combined,title='Combined',clipmin=0,clipmax=130)
hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = S_entropy_combined_no_rgs,title='Combined (No RGS)',clipmin=2,clipmax=4.5)
# %%
# Saving embeddings:
list_S_entropy=[S_entropy_veh_osbasic_dataset,S_entropy_veh_cbd_dataset,S_entropy_cbd_cbd_dataset,S_entropy_combined,S_entropy_combined_no_rgs];
with open('S_entropy.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(list_S_entropy, f)
# # Getting back the objects:
with open('S_entropy.pkl','rb') as f: # Python 3: open(..., 'rb')
S_entropy_list= pickle.load(f)
S_entropy_veh_osbasic_dataset=S_entropy_list[0];
S_entropy_veh_cbd_dataset=S_entropy_list[1];
S_entropy_cbd_cbd_dataset=S_entropy_list[2];
S_entropy_combined=S_entropy_list[3];
S_entropy_combined_no_rgs=S_entropy_list[4];
# %% Splitting days.
#Controls
StudyDay_rip_osbasic=StudyDay_rip[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1)]
# L=np.logical_and( np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_osbasic)==1) , np.squeeze(StudyDay_rip)=='OR' );
# v1_cond=hplt.get_kde_contours(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
StudyDay_rip_veh_rgs=StudyDay_rip[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
StudyDay_rip_veh_cbd=StudyDay_rip[np.logical_and( np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Non-Controls:
StudyDay_rip_rgs_rgs=StudyDay_rip[np.logical_and( np.logical_and(np.squeeze(treatment_rgs)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_rgs)==1)]
StudyDay_rip_cbd_cbd=StudyDay_rip[np.logical_and( np.logical_and(np.squeeze(treatment_cbd)==1,np.logical_not(outliers_combined)) , np.squeeze(dataset_cbd)==1)]
#Data_combined_no_rgs=np.concatenate([Data_veh_cbd_dataset,Data_cbd_cbd_dataset,Data_veh_osbasic_dataset]);
StudyDay_rip_combined_no_rgs=np.concatenate([StudyDay_rip_veh_cbd,StudyDay_rip_cbd_cbd,StudyDay_rip_osbasic])
StudyDay_rip_combined=StudyDay_rip[np.logical_not(outliers_combined)];
def get_kde_contour(x, y, level_index=7,levels=10 ):
kde=kdeplot(x,y)
p = kde.collections[level_index].get_paths()[0]
v = p.vertices
return v
#OS basic
L=np.squeeze(StudyDay_rip_osbasic=='OD');
v_osbasic_OD=get_kde_contour(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
close()
L=np.squeeze(StudyDay_rip_osbasic=='OR');
v_osbasic_OR=get_kde_contour(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
close()
L=np.squeeze(StudyDay_rip_osbasic=='CN');
v_osbasic_CN=get_kde_contour(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
close()
L=np.squeeze(StudyDay_rip_osbasic=='HC');
v_osbasic_HC=get_kde_contour(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
close()
def plot_conditions(embedding,studyday_embedding,no_cn=0):
L=np.squeeze(studyday_embedding=='OD');
v_OD=get_kde_contour(x=embedding[L,0], y=embedding[L,1])
close()
L=np.squeeze(studyday_embedding=='OR');
v_OR=get_kde_contour(x=embedding[L,0], y=embedding[L,1])
close()
if no_cn==0:
L=np.squeeze(studyday_embedding=='CN');
v_CN=get_kde_contour(x=embedding[L,0], y=embedding[L,1])
close()
L=np.squeeze(studyday_embedding=='HC');
v_HC=get_kde_contour(x=embedding[L,0], y=embedding[L,1])
close()
if no_cn==0:
return (v_OD,v_OR,v_CN,v_HC)
else:
return (v_OD,v_OR,v_HC)
# %%
# OS BASIC
fig, ax = plt.subplots()
#hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = Amp_veh_osbasic_dataset, title='Veh OS Basic',clipmin=0,clipmax=4.5)
hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = Meanfreq_veh_osbasic_dataset, title='Veh OS Basic',clipmin=100,clipmax=200)
#hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = Duration_veh_osbasic_dataset, title='Veh OS Basic',clipmin=0,clipmax=100)
#hplt.plot_umap(x=u_veh_osbasic[:,0],y=u_veh_osbasic[:,1],feature = S_entropy_veh_osbasic_dataset, title='Veh OS Basic',clipmin=2,clipmax=4.5)
plt.plot(v_osbasic_OD[:,0],v_osbasic_OD[:,1],'yellow')
plt.scatter(np.mean(v_osbasic_OD[:,0]),np.mean(v_osbasic_OD[:,1]),c='yellow',s=200, marker='+')
plt.plot(v_osbasic_OR[:,0],v_osbasic_OR[:,1],'teal')
plt.scatter(np.mean(v_osbasic_OR[:,0]),np.mean(v_osbasic_OR[:,1]),c='teal',s=200, marker='+')
plt.plot(v_osbasic_CN[:,0],v_osbasic_CN[:,1],'blueviolet')
plt.scatter(np.mean(v_osbasic_CN[:,0]),np.mean(v_osbasic_CN[:,1]),c='blueviolet',s=200, marker='+')
plt.plot(v_osbasic_HC[:,0],v_osbasic_HC[:,1],'black')
plt.scatter(np.mean(v_osbasic_HC[:,0]),np.mean(v_osbasic_HC[:,1]),c='black',s=200, marker='+')
ax.legend(['Stable', 'Overlapping','Random control', 'Homecage'])
plt.xlim([-1,11])
plt.ylim([-1,11])
centroids_os_basic=[ (np.mean(v_osbasic_OD[:,0]),np.mean(v_osbasic_OD[:,1])) ,
(np.mean(v_osbasic_OR[:,0]),np.mean(v_osbasic_OR[:,1])) ,
(np.mean(v_osbasic_CN[:,0]),np.mean(v_osbasic_CN[:,1])) ,
(np.mean(v_osbasic_HC[:,0]),np.mean(v_osbasic_HC[:,1])),
]
#OD, OR, CN ,HC
# %%
# #VEH RGS
# [v_veh_rgs_OD,v_veh_rgs_OR,v_veh_rgs_CN,v_veh_rgs_HC]=plot_conditions(u_veh_rgs,StudyDay_rip_veh_rgs)
# fig, ax = plt.subplots()
# hplt.plot_umap(x=u_veh_rgs[:,0],y=u_veh_rgs[:,1],feature = Meanfreq_veh_rgs_dataset, title='Veh RGS',clipmin=100,clipmax=200)
# plt.plot(v_veh_rgs_OD[:,0],v_veh_rgs_OD[:,1],'yellow')
# plt.plot(v_veh_rgs_OR[:,0],v_veh_rgs_OR[:,1],'teal')
# plt.plot(v_veh_rgs_CN[:,0],v_veh_rgs_CN[:,1],'blueviolet')
# plt.plot(v_veh_rgs_HC[:,0],v_veh_rgs_HC[:,1],'black')
# ax.legend(['Stable', 'Overlapping','Random control', 'Homecage'])
# plt.xlim([-1,11])
# plt.ylim([-1,11])
#VEH CBD
[v_veh_cbd_OD,v_veh_cbd_OR,v_veh_cbd_HC]=plot_conditions(u_veh_cbd,StudyDay_rip_veh_cbd,no_cn=1)
fig, ax = plt.subplots()
# hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = Meanfreq_veh_cbd_dataset, title='Veh CBD',clipmin=100,clipmax=200)
#hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = Amp_veh_cbd_dataset, title='Veh CBD',clipmin=0,clipmax=4.5)
#hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = Duration_veh_cbd_dataset, title='Veh CBD',clipmin=0,clipmax=100)
hplt.plot_umap(x=u_veh_cbd[:,0],y=u_veh_cbd[:,1],feature = S_entropy_veh_cbd_dataset, title='Veh CBD',clipmin=2,clipmax=4.5)
plt.plot(v_veh_cbd_OD[:,0],v_veh_cbd_OD[:,1],'yellow')
plt.scatter(np.mean(v_veh_cbd_OD[:,0]),np.mean(v_veh_cbd_OD[:,1]),c='yellow',s=200, marker='+')
plt.plot(v_veh_cbd_OR[:,0],v_veh_cbd_OR[:,1],'teal')
plt.scatter(np.mean(v_veh_cbd_OR[:,0]),np.mean(v_veh_cbd_OR[:,1]),c='teal',s=200, marker='+')
#plt.plot(v_veh_cbd_CN[:,0],v_veh_cbd_CN[:,1],'blueviolet')
plt.plot(v_veh_cbd_HC[:,0],v_veh_cbd_HC[:,1],'black')
plt.scatter(np.mean(v_veh_cbd_HC[:,0]),np.mean(v_veh_cbd_HC[:,1]),c='black',s=200, marker='+')
ax.legend(['Stable', 'Overlapping', 'Homecage'])
plt.xlim([-1,11])
plt.ylim([-1,11])
centroids_veh_cbd=[ (np.mean(v_veh_cbd_OD[:,0]),np.mean(v_veh_cbd_OD[:,1])) ,
(np.mean(v_veh_cbd_OR[:,0]),np.mean(v_veh_cbd_OR[:,1])) ,
(np.mean(v_veh_cbd_HC[:,0]),np.mean(v_veh_cbd_HC[:,1])),
]
#OD, OR,HC
# # RGS RGS
# [v_rgs_rgs_OD,v_rgs_rgs_OR,v_rgs_rgs_CN,v_rgs_rgs_HC]=plot_conditions(u_rgs_rgs,StudyDay_rip_rgs_rgs,no_cn=0)
# fig, ax = plt.subplots()
# hplt.plot_umap(x=u_rgs_rgs[:,0],y=u_rgs_rgs[:,1],feature = Meanfreq_rgs_rgs_dataset, title='RGS RGS',clipmin=100,clipmax=200)
# plt.plot(v_rgs_rgs_OD[:,0],v_rgs_rgs_OD[:,1],'yellow')
# plt.plot(v_rgs_rgs_OR[:,0],v_rgs_rgs_OR[:,1],'teal')
# plt.plot(v_rgs_rgs_CN[:,0],v_rgs_rgs_CN[:,1],'blueviolet')
# plt.plot(v_rgs_rgs_HC[:,0],v_rgs_rgs_HC[:,1],'black')
# ax.legend(['Stable', 'Overlapping','Random control', 'Homecage'])
# plt.xlim([-1,11])
# plt.ylim([-1,11])
# %%
#CBD CBD
[v_cbd_cbd_OD,v_cbd_cbd_OR,v_cbd_cbd_HC]=plot_conditions(u_cbd_cbd,StudyDay_rip_cbd_cbd,no_cn=1)
fig, ax = plt.subplots()
#hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = Meanfreq_cbd_cbd_dataset, title='CBD CBD',clipmin=100,clipmax=200)
# hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = Amp_cbd_cbd_dataset, title='CBD CBD',clipmin=0,clipmax=4.5)
#hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = Duration_cbd_cbd_dataset, title='CBD CBD',clipmin=0,clipmax=100)
hplt.plot_umap(x=u_cbd_cbd[:,0],y=u_cbd_cbd[:,1],feature = S_entropy_cbd_cbd_dataset, title='CBD CBD',clipmin=2,clipmax=4.5)
plt.plot(v_cbd_cbd_OD[:,0],v_cbd_cbd_OD[:,1],'yellow')
plt.scatter(np.mean(v_cbd_cbd_OD[:,0]),np.mean(v_cbd_cbd_OD[:,1]),c='yellow',s=200, marker='+')
plt.plot(v_cbd_cbd_OR[:,0],v_cbd_cbd_OR[:,1],'teal')
plt.scatter(np.mean(v_cbd_cbd_OR[:,0]),np.mean(v_cbd_cbd_OR[:,1]),c='teal',s=200, marker='+')
#plt.plot(v_veh_cbd_CN[:,0],v_veh_cbd_CN[:,1],'blueviolet')
plt.plot(v_cbd_cbd_HC[:,0],v_cbd_cbd_HC[:,1],'black')
plt.scatter(np.mean(v_cbd_cbd_HC[:,0]),np.mean(v_cbd_cbd_HC[:,1]),c='black',s=200, marker='+')
ax.legend(['Stable', 'Overlapping', 'Homecage'])
plt.xlim([-1,11])
plt.ylim([-1,11])
centroids_cbd_cbd=[ (np.mean(v_cbd_cbd_OD[:,0]),np.mean(v_cbd_cbd_OD[:,1])) ,
(np.mean(v_cbd_cbd_OR[:,0]),np.mean(v_cbd_cbd_OR[:,1])) ,
(np.mean(v_cbd_cbd_HC[:,0]),np.mean(v_cbd_cbd_HC[:,1])),
]
#OD, OR,HC
# %%
#u_combined_no_rgs
[v_combined_no_rgs_OD,v_combined_no_rgs_OR,v_combined_no_rgs_CN,v_combined_no_rgs_HC]=plot_conditions(u_combined_no_rgs,StudyDay_rip_combined_no_rgs,no_cn=0)
fig, ax = plt.subplots()
#hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = Meanfreq_combined_no_rgs, title='Combined (no-RGS)',clipmin=100,clipmax=200)
#hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = Amp_combined_no_rgs, title='Combined (no-RGS)',clipmin=0,clipmax=4.5)
#hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = Duration_combined_no_rgs, title='Combined (no-RGS)',clipmin=0,clipmax=100)
hplt.plot_umap(x=u_combined_no_rgs[:,0],y=u_combined_no_rgs[:,1],feature = S_entropy_combined_no_rgs, title='Combined (no-RGS)',clipmin=2,clipmax=4.5)
plt.plot(v_combined_no_rgs_OD[:,0],v_combined_no_rgs_OD[:,1],'yellow')
plt.scatter(np.mean(v_combined_no_rgs_OD[:,0]),np.mean(v_combined_no_rgs_OD[:,1]),c='yellow',s=200, marker='+')
plt.plot(v_combined_no_rgs_OR[:,0],v_combined_no_rgs_OR[:,1],'teal')
plt.scatter(np.mean(v_combined_no_rgs_OR[:,0]),np.mean(v_combined_no_rgs_OR[:,1]),c='teal',s=200, marker='+')
plt.plot(v_combined_no_rgs_CN[:,0],v_combined_no_rgs_CN[:,1],'blueviolet')
plt.scatter(np.mean(v_combined_no_rgs_CN[:,0]),np.mean(v_combined_no_rgs_CN[:,1]),c='blueviolet',s=200, marker='+')
plt.plot(v_combined_no_rgs_HC[:,0],v_combined_no_rgs_HC[:,1],'black')
plt.scatter(np.mean(v_combined_no_rgs_HC[:,0]),np.mean(v_combined_no_rgs_HC[:,1]),c='black',s=200, marker='+')
ax.legend(['Stable', 'Overlapping','Random control', 'Homecage'])
plt.xlim([-1,11])
plt.ylim([-1,11])
centroids_combined_no_rgs=[ (np.mean(v_combined_no_rgs_OD[:,0]),np.mean(v_combined_no_rgs_OD[:,1])) ,
(np.mean(v_combined_no_rgs_OR[:,0]),np.mean(v_combined_no_rgs_OR[:,1])) ,
(np.mean(v_combined_no_rgs_CN[:,0]),np.mean(v_combined_no_rgs_CN[:,1])) ,
(np.mean(v_combined_no_rgs_HC[:,0]),np.mean(v_combined_no_rgs_HC[:,1])),
]
#OD, OR, CN ,HC
with open('centroids_cbd_cbd.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(centroids_cbd_cbd, f)
with open('centroids_os_basic.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(centroids_os_basic, f)
with open('centroids_veh_cbd.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(centroids_veh_cbd, f)
with open('centroids_combined_no_rgs.pkl', 'wb') as f: # Python 3: open(..., 'wb')
pickle.dump(centroids_combined_no_rgs, f)
import pickle
with open('centroids_os_basic.pkl','rb') as f: )
centroids_os_basic= pickle.load(f)
# %%
# #u combined.
# [v_combined_OD,v_combined_OR,v_combined_CN,v_combined_HC]=plot_conditions(u_clean,StudyDay_rip_combined,no_cn=0)
# fig, ax = plt.subplots()
# hplt.plot_umap(x=u_clean[:,0],y=u_clean[:,1],feature = Meanfreq_combined, title='Combined',clipmin=100,clipmax=200)
# plt.plot(v_combined_OD[:,0],v_combined_OD[:,1],'yellow')
# plt.plot(v_combined_OR[:,0],v_combined_OR[:,1],'teal')
# plt.plot(v_combined_CN[:,0],v_combined_CN[:,1],'blueviolet')
# plt.plot(v_combined_HC[:,0],v_combined_HC[:,1],'black')
# ax.legend(['Stable', 'Overlapping','Random control', 'Homecage'])
# plt.xlim([-1,11])
# plt.ylim([-1,11])
# ax.legend(['Stable', 'Overlapping','Random control', 'Homecage'])
# %%
# CODE ENDS HERE.
# Controls
#u_veh_osbasic = fit.fit_transform(Data_veh_osbasic_dataset)
u_veh_rgs = fit.fit_transform(Data_veh_rgs_dataset)
u_veh_cbd = fit.fit_transform(Data_veh_cbd_dataset)
# Non-controls
u_rgs_rgs = fit.fit_transform(Data_rgs_rgs_dataset)
u_cbd_cbd = fit.fit_transform(Data_cbd_cbd_dataset)
# %% Find HC ripples to establish baseline
#StudyDay
# StudyDay_rip
# #Trial
# trial_rip
#SD_hc=hproc.strcmp(StudyDay_rip,"HC") #OSBASIC #RGS14
L_veh=np.logical_and(np.squeeze(treatment_veh)==1,np.logical_not(outliers)[0]);
SD_veh=StudyDay_rip[L_veh];
trial_veh=trial_rip[L_veh];
L=np.squeeze(SD_veh=='OD');
string='OD VEH'
hplt.plot_density(u_veh_treatment[L,0],u_veh_treatment[L,1],title=string+" ripples",figsize =(10, 7),vmax=0.25)
L=np.squeeze(SD_veh=='OR');
string='OR VEH'
L=np.squeeze(StudyDay_rip_osbasic=='OD');
v_osbasic_OD=get_kde_contour(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
close()
L=np.squeeze(StudyDay_rip_osbasic=='OR');
v_osbasic_OD=get_kde_contour(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
close()
L=np.squeeze(StudyDay_rip_osbasic=='CN');
v_osbasic_CN=get_kde_contour(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
close()
L=np.squeeze(StudyDay_rip_osbasic=='HC');
v_osbasic_HC=get_kde_contour(x=u_veh_osbasic[L,0], y=u_veh_osbasic[L,1])
close()
hplt.plot_density(u_veh_treatment[L,0],u_veh_treatment[L,1],title=string+" ripples",figsize =(10, 7),vmax=0.25)
L=np.squeeze(SD_veh=='CN');
string='CN VEH'
hplt.plot_density(u_veh_treatment[L,0],u_veh_treatment[L,1],title=string+" ripples",figsize =(10, 7),vmax=0.25)
L=np.squeeze(SD_veh=='HC');
string='HC VEH'
hplt.plot_density(u_veh_treatment[L,0],u_veh_treatment[L,1],title=string+" ripples",figsize =(10, 7),vmax=0.25)
L=np.squeeze(SD_veh=='OD');
v1_cond=get_kde_contour(x=u_veh_treatment[L,0], y=u_veh_treatment[L,1])
close()
L=np.squeeze(SD_veh=='OR');
v2_cond=get_kde_contour(x=u_veh_treatment[L,0], y=u_veh_treatment[L,1],level_index=6)
close()
L=np.squeeze(SD_veh=='CN');
v3_cond=get_kde_contour(x=u_veh_treatment[L,0], y=u_veh_treatment[L,1])
close()
L=np.squeeze(SD_veh=='HC');
v4_cond=get_kde_contour(x=u_veh_treatment[L,0], y=u_veh_treatment[L,1])
close()
fig, ax = plt.subplots()
plt.plot(v1_cond[:,0],v1_cond[:,1],'orange')
plt.plot(v2_cond[:,0],v2_cond[:,1],'teal')
plt.plot(v3_cond[:,0],v3_cond[:,1],'blueviolet')
plt.plot(v4_cond[:,0],v4_cond[:,1],'black')
ax.legend(['Stable', 'Overlapping','Random control', 'Homecage'])
# %% Trial data for HC.
L=np.squeeze(SD_veh=='HC');
string='HC VEH'
hplt.plot_density(u_veh_treatment[L,0],u_veh_treatment[L,1],title=string+" ripples",figsize =(10, 7),vmax=0.25)
cm = plt.get_cmap('gist_rainbow')
NUM_COLORS=8;
L=np.logical_and(np.squeeze(SD_veh=='HC'),np.squeeze(trial_veh=='Post1'))
plt.plot(np.nanmean(u_veh_treatment[L,0]),np.nanmean(u_veh_treatment[L,1]),'o',color=cm(1.*0/NUM_COLORS))
c_hc_pt1=[np.nanmean(u_veh_treatment[L,0]), np.nanmean(u_veh_treatment[L,1])]
L=np.logical_and(np.squeeze(SD_veh=='HC'),np.squeeze(trial_veh=='Post2'))
plt.plot(np.nanmean(u_veh_treatment[L,0]),np.nanmean(u_veh_treatment[L,1]),'o',color=cm(1.*1/NUM_COLORS))
c_hc_pt2=[np.nanmean(u_veh_treatment[L,0]), np.nanmean(u_veh_treatment[L,1])]
L=np.logical_and(np.squeeze(SD_veh=='HC'),np.squeeze(trial_veh=='Post3'))
plt.plot(np.nanmean(u_veh_treatment[L,0]),np.nanmean(u_veh_treatment[L,1]),'o',color=cm(1.*2/NUM_COLORS))
c_hc_pt3=[np.nanmean(u_veh_treatment[L,0]), np.nanmean(u_veh_treatment[L,1])]
L=np.logical_and(np.squeeze(SD_veh=='HC'),np.squeeze(trial_veh=='Post4'))
plt.plot(np.nanmean(u_veh_treatment[L,0]),np.nanmean(u_veh_treatment[L,1]),'o',color=cm(1.*3/NUM_COLORS))
c_hc_pt4=[np.nanmean(u_veh_treatment[L,0]), np.nanmean(u_veh_treatment[L,1])]