forked from somponnat/Somponnat_SingleCellAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignalClustering.m
2620 lines (2109 loc) · 110 KB
/
SignalClustering.m
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
function varargout = SignalClustering(varargin)
% SIGNALCLUSTERING MATLAB code for SignalClustering.fig
% SIGNALCLUSTERING, by itself, creates a new SIGNALCLUSTERING or raises the existing
% singleton*.
%
% H = SIGNALCLUSTERING returns the handle to a new SIGNALCLUSTERING or the handle to
% the existing singleton*.
%
% SIGNALCLUSTERING('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIGNALCLUSTERING.M with the given input arguments.
%
% SIGNALCLUSTERING('Property','Value',...) creates a new SIGNALCLUSTERING or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SignalClustering_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SignalClustering_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help SignalClustering
% Last Modified by GUIDE v2.5 26-Sep-2013 16:02:41
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SignalClustering_OpeningFcn, ...
'gui_OutputFcn', @SignalClustering_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before SignalClustering is made visible.
function SignalClustering_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to SignalClustering (see VARARGIN)
% Choose default command line output for SignalClustering
handles.output = hObject;
handles.alldata = [];
handles.originData = [];
handles.cellFate = [];
handles.groupNo = [];
handles.timestamp = [];
handles.score = [];
handles.selectedcellIndices = [];
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SignalClustering wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = SignalClustering_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in popupmenu_posCtrl.
function popupmenu_posCtrl_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu_posCtrl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu_posCtrl contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu_posCtrl
plot_populationlevel(handles);
plot_populationhistogram(handles,1);
% --- Executes during object creation, after setting all properties.
function popupmenu_posCtrl_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu_posCtrl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu_y_pca.
function popupmenu_y_pca_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu_y_pca (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu_y_pca contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu_y_pca
[plot_h,plotInd,grayInd] = plotPCA(handles.plottype,handles,handles.selectedcellIndices);
handles.plot_h = plot_h;
handles.plotInd = plotInd;
handles.grayInd = grayInd;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function popupmenu_y_pca_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu_y_pca (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_ndfilename_Callback(hObject, eventdata, handles)
% hObject handle to edit_ndfilename (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_ndfilename as text
% str2double(get(hObject,'String')) returns contents of edit_ndfilename as a double
handles.ndfilename = get(hObject,'String');
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit_ndfilename_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_ndfilename (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_locatendfile.
function pushbutton_locatendfile_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_locatendfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,PathName,FilterIndex] = uigetfile('*.nd', 'Choose metamorph ND file','Z:\Somponnat\FOXO3a dynamics\Images and Data\130722.nd');
if FilterIndex~=0
set(handles.edit_ndfilename,'String',filename);
handles.ndfilename = filename;
handles.ndpathname = PathName;
set(handles.edit_sourceF,'String',PathName);
end
guidata(hObject, handles);
% --- Executes on button press in pushbutton_initialize.
function pushbutton_initialize_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_initialize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.ndpathname)
set(handles.edit_commu,'String','Please first choose ND file');
return;
end
searchInd(1,:)= str2num(get(handles.edit_selectedRows,'String'));
searchInd(2,:)= str2num(get(handles.edit_selectedCols,'String'));
searchInd(3,:)= str2num(get(handles.edit_selectedFields,'String'));
searchInd(4,:)= str2num(get(handles.edit_selectedcolors,'String'));
phenotypeList = {'Dead(-4)';'Dead,Divided 3 times(-3)';'Dead,Divided twice(-2)';'Dead,Divided once(-1)';'Quiescent(0)';'Divided once(1)';'Divided twice(2)';'Divided 3 times(3)'};
outputsignalNo = str2num(get(handles.edit_outputsignalno,'String'));
sequenceNo = str2num(get(handles.edit_sequenceNo,'String'));
alldata=[];
groupNo=[];
originData=[];
cellFate=[];
selectedColor = [];
for i = 1:size(searchInd,2)
switch mod(i,3)
case 1
set(handles.edit_commu,'String','Processing.');
case 2
set(handles.edit_commu,'String','Processing..');
otherwise
set(handles.edit_commu,'String','Processing...');
end
pause(0.01);
row = searchInd(1,i);
col = searchInd(2,i);
field = searchInd(3,i);
sColor = searchInd(4,i);
H5filename = ['H5OUT_r' num2str(row) '_c' num2str(col) '.h5'];
param_name = ['/field' num2str(field) '/clusterparams' num2str(outputsignalNo)];
signal_name = ['/field' num2str(field) '/outputsignal' num2str(outputsignalNo)];
timestamp_name = ['/field' num2str(field) '/timestamp' num2str(outputsignalNo)];
fid = H5F.open(fullfile(handles.ndpathname,H5filename),'H5F_ACC_RDWR','H5P_DEFAULT');
if H5L.exists(fid,param_name,'H5P_DEFAULT')
H5F.close(fid);
paraminfo = h5info(fullfile(handles.ndpathname,H5filename), param_name);
startind = double([1 1]);
countind = [paraminfo.Dataspace.Size(1) paraminfo.Dataspace.Size(2)];
param_mat = double(h5read(fullfile(handles.ndpathname,H5filename),param_name,startind, countind));
alldata = [alldata;param_mat];
groupNo = [groupNo;i*ones(size(param_mat,1),1)];
selectedColor = [selectedColor;sColor*ones(size(param_mat,1),1)];
signalinfo = h5info(fullfile(handles.ndpathname,H5filename), signal_name);
%sisterListinfo = h5info(fullfile(handles.SourceF,H5filename), sisterList_name);
%sisterList = h5read(fullfile(handles.SourceF,H5filename),sisterList_name,[1 1 1],...
% [sisterListinfo.Dataspace.Size(1) sisterListinfo.Dataspace.Size(2) sisterListinfo.Dataspace.Size(3)]);
startind = double([1 1 sequenceNo]);
countind = [signalinfo.Dataspace.Size(1) signalinfo.Dataspace.Size(2) 1];
signal = permute(h5read(fullfile(handles.ndpathname,H5filename),signal_name,startind, countind),[2 1 3]);
for c_cell=1:size(param_mat,1)
originData = [originData;signal(:,param_mat(c_cell,4))'];
cellFate = [cellFate;param_mat(c_cell,5)];
end
if i==1
timestamp = h5read(fullfile(handles.ndpathname,H5filename),timestamp_name);
table_data = cell(size(param_mat,2),5);
for j = 1:size(param_mat,2)
table_data{j,1} = h5readatt(fullfile(handles.ndpathname,H5filename),param_name,['param' num2str(j)]);
end
end
clear param_mat;
else
H5F.close(fid);
end
end
[R C] = find(originData==0);
for i=1:length(R)
originData(R(i),C(i)) = NaN;
end
set(handles.togglebutton_populationMean,'Value',1);
handles.ytype = 1;
set(handles.togglebutton_showselectedpolygon,'Value',0);
handles.plottype = 1;
set(handles.togglebutton_scatter2D,'Value',1);
handles.selectedcellIndices = [];
handles.selectedPolygon = [];
handles.alldata = alldata;
handles.originData = originData;
handles.phenotypeList = phenotypeList;
Phenolabel{1} = 'All';
PhenotypeID = unique(cellFate);
for i=1:length(PhenotypeID)
Phenolabel{i+1} = [phenotypeList{PhenotypeID(i)+5}];
end
Groupnolabel{1} = 'All';
groupNoID = unique(groupNo);
for i=1:length(groupNoID)
Groupnolabel{i+1} = ['r' num2str(searchInd(1,groupNoID(i))) 'c' num2str(searchInd(2,groupNoID(i)))];
end
Clusterlabel{1} = 'All';
ClusterNo = str2num(get(handles.edit_clusterno,'String'));
for i=1:ClusterNo
Clusterlabel{i+1} = [num2str(i)];
end
AssignedColorlabel{1} = 'All';
AssignedColor = unique(selectedColor);
for i=1:length(AssignedColor)
AssignedColorlabel{i+1} = [num2str(AssignedColor(i))];
end
set(handles.popupmenu_phenotype,'String',Phenolabel);
set(handles.popupmenu_wellposition,'String',Groupnolabel);
set(handles.popupmenu_cluster,'String',Clusterlabel);
set(handles.popupmenu_assignedC,'String',AssignedColorlabel);
handles.cellFate = cellFate;
choiceInput = sort(unique(cellFate))';
set(handles.edit_phetype_list,'String',num2str(choiceInput));
handles.groupNo = groupNo;
choiceInput = sort(unique(groupNo))';
set(handles.edit_position_list,'String',num2str(choiceInput));
choiceInput = 1:str2num(get(handles.edit_clusterno,'String'));
set(handles.edit_cluster_list,'String',num2str(choiceInput));
handles.selectedColor = selectedColor;
choiceInput = sort(unique(selectedColor))';
set(handles.edit_assignedC_list,'String',num2str(choiceInput));
handles.timestamp = timestamp;
handles.plotInd = 1:size(alldata,1);
handles.grayInd = [];
guidata(hObject, handles);
handles = guidata(hObject);
set(handles.uitable_params,'Data',table_data);
plot_populationlevel(handles);
plot_populationlevel(handles);
plot_populationlevel(handles);
plot_populationhistogram(handles,1);
plot_populationhistogram(handles,2);
plot_populationhistogram(handles,3);
set(handles.edit_commu,'String','Finished initializing parameters');
guidata(hObject, handles);
selectedparams = str2num(get(handles.edit_selectedparams,'String'));
param_names = [];
for i=1:size(table_data,1)
param_names{i} = table_data{i,1};
end
Ind=1;
for i=selectedparams
selectedparams_name{Ind} = param_names{i};
Ind = Ind+1;
end
set(handles.popupmenu_selectedparams,'String',selectedparams_name);
function edit_sourceF_Callback(hObject, eventdata, handles)
% hObject handle to edit_sourceF (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_sourceF as text
% str2double(get(hObject,'String')) returns contents of edit_sourceF as a double
handles.ndpathname = get(hObject,'String');
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit_sourceF_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_sourceF (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_selectedRows_Callback(hObject, eventdata, handles)
% hObject handle to edit_selectedRows (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_selectedRows as text
% str2double(get(hObject,'String')) returns contents of edit_selectedRows as a double
% --- Executes during object creation, after setting all properties.
function edit_selectedRows_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_selectedRows (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_selectedCols_Callback(hObject, eventdata, handles)
% hObject handle to edit_selectedCols (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_selectedCols as text
% str2double(get(hObject,'String')) returns contents of edit_selectedCols as a double
% --- Executes during object creation, after setting all properties.
function edit_selectedCols_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_selectedCols (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu_group.
function popupmenu_group_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu_group (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu_group contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu_group
plot_populationlevel(handles);
plot_populationhistogram(handles,3);
% --- Executes during object creation, after setting all properties.
function popupmenu_group_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu_group (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function plot_populationlevel(handles)
invertLogic = get(handles.togglebutton_signalInvert,'Value');
if isempty(handles.originData)
set(handles.edit_commu,'String','No data. Please first initialize dataset.');
return;
else
axes(handles.axes_individual);
switch handles.ytype
case 1
if invertLogic
plot(handles.timestamp,1./nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_negCtrl,'Value'),:),1),'r'); hold on;
plot(handles.timestamp,1./nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_posCtrl,'Value'),:),1),'g');
plot(handles.timestamp,1./nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_group,'Value'),:),1),'b');hold off;
else
plot(handles.timestamp,nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_negCtrl,'Value'),:),1),'r'); hold on;
plot(handles.timestamp,nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_posCtrl,'Value'),:),1),'g');
plot(handles.timestamp,nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_group,'Value'),:),1),'b');hold off;
end
case 2
plot(handles.timestamp,nanstd(handles.originData(handles.groupNo==get(handles.popupmenu_negCtrl,'Value'),:),0,1)./nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_negCtrl,'Value'),:),1),'r'); hold on;
plot(handles.timestamp,nanstd(handles.originData(handles.groupNo==get(handles.popupmenu_posCtrl,'Value'),:),0,1)./nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_posCtrl,'Value'),:),1),'g');
plot(handles.timestamp,nanstd(handles.originData(handles.groupNo==get(handles.popupmenu_group, 'Value'),:),0,1)./nanmean(handles.originData(handles.groupNo==get(handles.popupmenu_group,'Value'),:),1),'b');hold off;
end
table_data = get(handles.uitable_params,'Data');
for i=[1:3 5:size(table_data,1)]
table_data{i,3} = nanmean(handles.alldata(handles.groupNo==get(handles.popupmenu_posCtrl,'Value'),i));
end
table_data{4,3} = [];
for i=[1:3 5:size(table_data,1)]
table_data{i,4} = nanmean(handles.alldata(handles.groupNo==get(handles.popupmenu_negCtrl,'Value'),i));
end
table_data{4,4} = [];
for i=[1:3 5:size(table_data,1)]
table_data{i,5} = nanmean(handles.alldata(handles.groupNo==get(handles.popupmenu_group,'Value'),i));
end
table_data{4,5} = [];
set(handles.uitable_params,'Data',table_data);
end
function plot_populationhistogram(handles,plotno)
if ~isempty(handles.score)
switch plotno
case 1
axes(handles.axes_posctrl);
ptChoice = get(handles.popupmenu_posCtrl,'Value');
case 2
axes(handles.axes_negctrl);
ptChoice = get(handles.popupmenu_negCtrl,'Value');
case 3
axes(handles.axes_group);
ptChoice = get(handles.popupmenu_group,'Value');
end
countInd=1;
binSize=[];
for j=handles.newList
binSize(countInd) = numel(handles.binning{ptChoice,j});
countInd=countInd+1;
end
bar(1:str2num(get(handles.edit_clusterno,'String')),binSize);
switch plotno
case 1
set(handles.axes_posctrl,'XTickLabel',[]);
case 2
set(handles.axes_negctrl,'XTickLabel',[]);
case 3
set(handles.axes_group,'XTickLabel',[]);
end
end
% --- Executes on selection change in popupmenu_negCtrl.
function popupmenu_negCtrl_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu_negCtrl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu_negCtrl contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu_negCtrl
plot_populationlevel(handles);
plot_populationhistogram(handles,2);
% --- Executes during object creation, after setting all properties.
function popupmenu_negCtrl_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu_negCtrl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_clusterno_Callback(hObject, eventdata, handles)
% hObject handle to edit_clusterno (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_clusterno as text
% str2double(get(hObject,'String')) returns contents of edit_clusterno as a double
% --- Executes during object creation, after setting all properties.
function edit_clusterno_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_clusterno (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function [notp stagePos stageName waveName] = readndfile(pathname,filename)
% Search for number of string matches per line.
notp=-1;
stagePos = [];
stageName = [];
waveName = [];
currentF = pwd;
if exist(fullfile(pathname,filename),'file')
fid = fopen(fullfile(pathname,filename));
y = 0;
tline = fgetl(fid);
sind = 1;
wind = 1;
notp=0;
while ischar(tline)
% Find number of time points
testInd = regexp(tline,'NTimePoints');
num = length(testInd);
if num > 0
tp = regexp(tline, '(?<="NTimePoints", )\d+', 'match');
notp = str2num(tp{1});
end
% Find stage naming
testInd = regexp(tline,'Stage\d+');
num = length(testInd);
if num > 0
stage = regexp(tline, '(?<=")\w+(?=",)', 'match');
stagePos{sind,1} = stage{1};
stagename = regexp(tline, '(?<="Stage\d+", ").+(?=")', 'match');
stageName{sind,1} = stagename{1};
sind=sind+1;
end
% Find stage naming
testInd = regexp(tline,'WaveName\d+');
num = length(testInd);
if num > 0
wavename1 = regexp(tline, '(?<="WaveName\d+", ")\w+(?=_)', 'match');
wavename2 = regexp(tline, '(?<="WaveName\d+", "\w+_)\w+(?=")', 'match');
waveName{wind} = ['w' num2str(wind) wavename1{1} '-' wavename2{1}];
wind=wind+1;
end
tline = fgetl(fid);
end
fclose(fid);
end
% --- Executes on button press in pushbutton_loadbyndfile.
function pushbutton_loadbyndfile_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_loadbyndfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
stageName = [];
searchInd(1,:)= str2num(get(handles.edit_selectedRows,'String'));
searchInd(2,:)= str2num(get(handles.edit_selectedCols,'String'));
searchInd(3,:)= str2num(get(handles.edit_selectedFields,'String'));
for i=1:size(searchInd,2)
stageName{i} = ['r' num2str(searchInd(1,i)) 'c' num2str(searchInd(2,i)) 'f' num2str(searchInd(3,i))];
end
set(handles.popupmenu_posCtrl,'String',stageName);
set(handles.popupmenu_posCtrl,'Value',1);
set(handles.popupmenu_negCtrl,'String',stageName);
set(handles.popupmenu_negCtrl,'Value',1);
set(handles.popupmenu_group,'String',stageName);
set(handles.popupmenu_group,'Value',1);
guidata(hObject, handles);
set(handles.edit_commu,'String',['Assigned source folder to ' handles.ndpathname]);
% --- Executes on button press in pushbutton_selectPoints.
function pushbutton_selectPoints_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_selectPoints (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
searchInd(1,:)= str2num(get(handles.edit_selectedRows,'String'));
searchInd(2,:)= str2num(get(handles.edit_selectedCols,'String'));
searchInd(3,:)= str2num(get(handles.edit_selectedFields,'String'));
old_xlim = get(handles.axes_pca,'XLim');
old_ylim = get(handles.axes_pca,'YLim');
warning off;
[plot_h,plotInd,grayInd] = plotPCA(0,handles,handles.selectedcellIndices);
handles.plot_h = plot_h;
handles.plotInd = plotInd;
handles.grayInd = grayInd;
set(handles.axes_pca,'XLim',old_xlim);
set(handles.axes_pca,'YLim',old_ylim);
guidata(hObject, handles);
handles = guidata(hObject);
hold on
% Initially, the list of points is empty.
xy = [];
n = 0;
% Loop, picking up the points.
set(handles.edit_commu,'String','Draw polygon to choose cells. Click last point with Right mouse button.');
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
n = n+1;
xy(n,:) = [xi yi];
if n==1
plot(xi,yi,'k-');
else
plot(xy([n-1 n],1),xy([n-1 n],2),'k-');
end
end
plot(xy([1 n],1),xy([1 n],2),'k-');
for i=1:length(handles.plot_h)
c_X = get(handles.plot_h,'XData')';
c_Y = get(handles.plot_h,'YData')';
IN= inpolygon(c_X,c_Y,xy(:,1),xy(:,2));
end
hold off
insideInd = find(IN==1);
mycolor = jet(size(searchInd,2));
axes(handles.axes_individual);
for i=1:length(insideInd)
plot(handles.timestamp(handles.originData(handles.plotInd(insideInd(i)),:)~=0),handles.originData(handles.plotInd(insideInd(i)),handles.originData(handles.plotInd(insideInd(i)),:)~=0),'Color',mycolor(handles.groupNo(handles.plotInd(insideInd(i))),:));hold on;
end
hold off;
drawnow;
warning on;
handles.selectedcellIndices = handles.plotInd(insideInd);
handles.selectedPolygon = xy;
guidata(hObject, handles);
handles = guidata(hObject);
table_data = get(handles.uitable_params,'Data');
for i=1:size(table_data,1)
table_data{i,2} = nanmean(handles.alldata(handles.plotInd(insideInd),i));
end
set(handles.uitable_params,'Data',table_data);
[plot_h,plotInd,grayInd] = plotPCA(handles.plottype,handles,handles.selectedcellIndices);
handles.plot_h = plot_h;
handles.plotInd = plotInd;
handles.grayInd = grayInd;
hold on;
plot(xy([1:n 1],1),xy([1:n 1],2),'k-');hold off;
set(handles.axes_pca,'XLim',old_xlim );
set(handles.axes_pca,'YLim',old_ylim );
noCluster = str2num(get(handles.edit_clusterno,'String'));
binSize=[];
for j=1:noCluster
binSize(j) = numel(find(handles.T(handles.plotInd(insideInd))==j));
end
axes(handles.axes_selected);
bar(1:str2num(get(handles.edit_clusterno,'String')),binSize);
set(handles.axes_selected,'XTickLabel',[]);
set(handles.togglebutton_showselectedpolygon,'Value',1);
set(handles.edit_commu,'String',['Cells in polygon: ' num2str(length(handles.plotInd(insideInd))) ' of ' num2str(length(handles.plotInd))]);
guidata(hObject, handles);
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton_removepoints.
function pushbutton_removepoints_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_removepoints (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in popupmenu10.
function popupmenu10_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu10 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu10
% --- Executes during object creation, after setting all properties.
function popupmenu10_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function [plotInd,grayInd] = determinePlotInd(handles)
allInd = 1:size(handles.alldata,1);
PhenoInd = str2num(get(handles.edit_phetype_list,'String'));
WellInd = str2num(get(handles.edit_position_list,'String'));
CInd = str2num(get(handles.edit_cluster_list,'String'));
SCInd = str2num(get(handles.edit_assignedC_list,'String'));
SInd = get(handles.popupmenu_selection,'Value');
if SInd == 2
selectedCells = handles.selectedcellIndices;
else
selectedCells = allInd;
end
selectedPheno = [];
for i=1:length(PhenoInd)
selectedPheno = [selectedPheno;find(handles.cellFate == PhenoInd(i))];
end
selectedPheno = sort(selectedPheno);
selectedWell = [];
for i=1:length(WellInd)
selectedWell = [selectedWell;find(handles.groupNo == WellInd(i))];
end
selectedWell = sort(selectedWell);
selectedC = [];
for i=1:length(CInd)
selectedC = [selectedC;find(handles.T == CInd(i))];
end
selectedC = sort(selectedC);
selectedSC = [];
for i=1:length(SCInd)
selectedSC = [selectedSC;find(handles.selectedColor == SCInd(i))];
end
selectedSC = sort(selectedSC);
plotInd = sort(intersect(intersect(intersect(intersect(selectedPheno,selectedWell),selectedC),selectedSC),selectedCells));
grayInd = sort(setdiff(1:size(handles.alldata,1),plotInd));
set(handles.edit_totalcellcount,'String',num2str(length(plotInd)));
set(handles.edit_commu,'String',['Total cell selected: ' num2str(length(plotInd))]);
function [plot_h,plotInd,grayInd]= plotPCA(plottype,handles,selectedcellInd)
[plotInd,grayInd] = determinePlotInd(handles);
x = get(handles.popupmenu_x_pca,'Value');
y = get(handles.popupmenu_y_pca,'Value');
z = get(handles.popupmenu_z_pca,'Value');
c = get(handles.popupmenu_c_pca,'Value');
p = get(handles.popupmenu_selectedparams,'Value');
selectedparams = str2num(get(handles.edit_selectedparams,'String'));
if get(handles.togglebutton_orthorotate,'Value')==0
myplotdata = handles.score;
else
myplotdata = handles.rotated_score;
end
msize = str2num(get(handles.edit_markersize,'String'));
mtype = get(handles.edit_markertype,'String');
plot_h=[];
searchInd(1,:)= str2num(get(handles.edit_selectedRows,'String'));
searchInd(2,:)= str2num(get(handles.edit_selectedCols,'String'));
searchInd(3,:)= str2num(get(handles.edit_selectedFields,'String'));
if ~isempty(myplotdata)
if get(handles.togglebutton_newplot,'Value')
figure(1);
else
axes(handles.axes_pca);
end
switch plottype
case 1 % scatter-2D
if ~isempty(selectedcellInd) && get(handles.togglebutton_showselectedpolygon,'Value')==1;
scatter(myplotdata(intersect(plotInd,selectedcellInd),x),myplotdata(intersect(plotInd,selectedcellInd),y),msize,'k','o','fill');hold on;
end
if ~isempty(grayInd)
scatter(myplotdata(grayInd,x),myplotdata(grayInd,y),msize,[0.7 0.7 0.7],'x');hold on;
end
if ~isempty(plotInd)
switch c
case 1 % well position
c_groupNo = unique(handles.groupNo(plotInd));
for i=1:length(c_groupNo)
myLegend{i} = ['r' num2str(searchInd(1,c_groupNo(i))) 'c' num2str(searchInd(2,c_groupNo(i)))];
end
plot_h = gscatter(myplotdata(plotInd,x),myplotdata(plotInd,y),nominal(handles.groupNo(plotInd),myLegend),jet(length(unique(handles.groupNo(plotInd)))),mtype,msize-6,'on');
set(handles.togglebutton_legendLogic,'Value',1);
case 2 % phenotype
c_phenotype = unique(handles.cellFate(plotInd));
mymarkertype = [];
mymarkercolor = [];
for i=1:length(c_phenotype)
myLegend{i} = handles.phenotypeList{c_phenotype(i)+5};
switch c_phenotype(i)
case -4
mymarkertype = [mymarkertype 'v'];
case {-3,-2,-1}
mymarkertype = [mymarkertype 'v'];
case 0
mymarkertype = [mymarkertype 'o'];
case {1,2,3}
mymarkertype = [mymarkertype 'x'];
end
switch c_phenotype(i)
case -4
mymarkercolor = [mymarkercolor 'k'];
case {-3,3}
mymarkercolor = [mymarkercolor 'b'];
case {-2,2}
mymarkercolor = [mymarkercolor 'g'];
case {-1,1}
mymarkercolor = [mymarkercolor 'r'];
case 0
mymarkercolor = [mymarkercolor 'c'];
end
end
plot_h = gscatter(myplotdata(plotInd,x),myplotdata(plotInd,y),nominal(handles.cellFate(plotInd),myLegend),mymarkercolor,mymarkertype,msize-6,'on');
set(handles.togglebutton_legendLogic,'Value',1);
%legend(myLegend);
case 3 % cluster
plot_h = gscatter(myplotdata(plotInd,x),myplotdata(plotInd,y),handles.T(plotInd),hsv(length(unique(handles.T(plotInd)))),mtype,msize-6,'on');
set(handles.togglebutton_legendLogic,'Value',1);
case 4 % plot params
chosen_param = selectedparams(p);
alldataset = handles.alldata(:,chosen_param);
myx = [min(alldataset):(max(alldataset)-min(alldataset))/31:max(alldataset)];
[~,bin] = histc(handles.alldata(plotInd,chosen_param),myx);
mycolor = hot(32);
if bin~=0
for i=1:length(bin)
cellcolor(i,:) = mycolor(bin(i),:);
end
else
for i=1:length(bin)
cellcolor(i,:) = mycolor(1,:);
end
end
plot_h = scatter(myplotdata(plotInd,x),myplotdata(plotInd,y),msize,cellcolor,mtype);
set(handles.togglebutton_legendLogic,'Value',0);
case 5 % assigned color
c_sColor = unique(handles.selectedColor(plotInd));
for i=1:length(c_sColor)
myLegend{i} = [num2str(c_sColor(i))];
end
plot_h = gscatter(myplotdata(plotInd,x),myplotdata(plotInd,y),nominal(handles.selectedColor(plotInd),myLegend),hsv(length(unique(handles.selectedColor(plotInd)))),mtype,msize-6,'on');
set(handles.togglebutton_legendLogic,'Value',1);
end
hold off;
colorbar('off');
end
case 2 %Plot 3D
if ~isempty(selectedcellInd) && get(handles.togglebutton_showselectedpolygon,'Value')==1;
scatter3(myplotdata(intersect(plotInd,selectedcellInd),x),myplotdata(intersect(plotInd,selectedcellInd),y),myplotdata(intersect(plotInd,selectedcellInd),z),msize,'k','o','fill');hold on;
end
if ~isempty(grayInd)
scatter3(myplotdata(grayInd,x),myplotdata(grayInd,y),myplotdata(grayInd,z),msize,[0.7 0.7 0.7],'x');hold on;
end
if ~isempty(plotInd)
switch c
case 1 % well position
set(handles.edit_commu,'String','Plot colors show well positions.');
cellcolor = [];
groupList = unique(handles.groupNo(plotInd));
colorsize = length(groupList);
mycolor = jet(colorsize);
mydata = handles.groupNo(plotInd);
for i=1:length(mydata)
cellcolor(i,:) = mycolor(find(groupList==mydata(i)),:);
end
plot_h=scatter3(myplotdata(plotInd,x),myplotdata(plotInd,y),myplotdata(plotInd,z),msize,cellcolor,mtype);
set(handles.togglebutton_legendLogic,'Value',0);
case 2 % phenotype
set(handles.edit_commu,'String','Plot colors show cell decision.');
plot_h=scatter3(myplotdata(intersect(plotInd,find(handles.cellFate==-4)),x),myplotdata(intersect(plotInd,find(handles.cellFate==-4)),y),myplotdata(intersect(plotInd,find(handles.cellFate==-4)),z),msize,'v','k');hold on;
plot_h=scatter3(myplotdata(intersect(plotInd,find(handles.cellFate==-3)),x),myplotdata(intersect(plotInd,find(handles.cellFate==-3)),y),myplotdata(intersect(plotInd,find(handles.cellFate==-3)),z),msize,'v','b');
plot_h=scatter3(myplotdata(intersect(plotInd,find(handles.cellFate==-2)),x),myplotdata(intersect(plotInd,find(handles.cellFate==-2)),y),myplotdata(intersect(plotInd,find(handles.cellFate==-2)),z),msize,'v','g');
plot_h=scatter3(myplotdata(intersect(plotInd,find(handles.cellFate==-1)),x),myplotdata(intersect(plotInd,find(handles.cellFate==-1)),y),myplotdata(intersect(plotInd,find(handles.cellFate==-1)),z),msize,'v','r');
plot_h=scatter3(myplotdata(intersect(plotInd,find(handles.cellFate==0)),x),myplotdata(intersect(plotInd,find(handles.cellFate==0)),y),myplotdata(intersect(plotInd,find(handles.cellFate==0)),z),msize,'o','c');
plot_h=scatter3(myplotdata(intersect(plotInd,find(handles.cellFate==1)),x),myplotdata(intersect(plotInd,find(handles.cellFate==1)),y),myplotdata(intersect(plotInd,find(handles.cellFate==1)),z),msize,'x','r');