-
Notifications
You must be signed in to change notification settings - Fork 10
/
scgeatool.m
2237 lines (2069 loc) · 91.9 KB
/
scgeatool.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 = scgeatool(sce, varargin)
if usejava('jvm') && ~feature('ShowFigureWindows')
error('MATLAB is in a text mode. This function requires a GUI-mode.');
end
if ~gui.i_installed('stats'), return; end
% rng("shuffle");
% rng("default");
persistent speciestag
% speciestag = getpref('scgeatoolbox', 'preferredspecies', 'human');
import pkg.*
import gui.*
fx = [];
if nargin < 1
try
fxfun = @gui.sc_splashscreen;
[fx, v1] = fxfun();
catch
fxfun = @gui.sc_simplesplash;
[fx, v1] = fxfun();
end
sce = SingleCellExperiment;
else
if ~isa(sce, 'SingleCellExperiment')
error('requires >> sce = SingleCellExperiment(); scgeatool(sce)');
end
v1 = pkg.i_get_versionnum;
end
mfolder = fileparts(mfilename('fullpath'));
p = inputParser;
checkCS = @(x) isempty(x) | size(sce.X, 2) == length(x);
addRequired(p, 'sce', @(x) isa(x, 'SingleCellExperiment'));
addOptional(p, 'c', sce.c, checkCS);
addOptional(p, 's', [], checkCS);
addOptional(p, 'methodid', 1, @isnumeric);
addOptional(p, 'callinghandle', []);
parse(p, sce, varargin{:});
callinghandle = p.Results.callinghandle;
c_in = p.Results.c;
s_in = p.Results.s;
methodid = p.Results.methodid;
f_traj = []; % trajectory curve
ax = []; bx = [];
tmpcelltypev = cell(sce.NumCells, 1);
if ~isempty(c_in), sce.c = c_in; end
if ~isempty(s_in), sce.s = s_in; end
[c, cL] = grp2idx(sce.c);
if ~isempty(v1)
figname = sprintf('SCGEATOOL v%s', v1);
else
figname = 'SCGEATOOL';
end
FigureHandle = figure('Name', figname, ...
'position', round(1.2*[0, 0, 560, 420]), ...
'visible', 'off', 'NumberTitle', 'off', ...
'DockControls','off','MenuBar','none','ToolBar','figure');
movegui(FigureHandle, 'center');
fig_pos = get(FigureHandle, 'Position');
fig_width = fig_pos(3);
fig_height = fig_pos(4);
btn_width = 100;
btn_height = 25;
btn_x = (fig_width - btn_width) / 2;
btn_y = (fig_height - btn_height) / 1.618;
if ~isempty(fx) && isvalid(fx), fxfun(fx,0.2); end
button1 = uicontrol('Parent', FigureHandle,...
'Style', 'pushbutton',...
'Units', 'pixels',...
'Position', [btn_x btn_y btn_width btn_height],...
'String', 'Import Data...',...
'Callback', @in_sc_openscedlg,...
'ButtonDownFcn', @in_sc_openscedlg,...
'KeyPressFcn', @in_sc_openscedlg, 'Tooltip','Click or Press i');
button2 = uicontrol('style','text',...
'Parent', FigureHandle,...
'FontSize', 9,...
'position', [btn_x btn_y+25 btn_width btn_height],...
'string','Ready to explore.');
set(FigureHandle,'resizefcn',{@myResizeFun, button1, button2});
m_file = uimenu(FigureHandle, 'Text', '&File');
in_addmenu(m_file, 0, @in_sc_openscedlg, '&Import Data... ','I');
in_addmenu(m_file, 0, @in_closeRequest, '&Close','W');
in_addmenu(m_file, 1, {@gui.i_savemainfig, 3}, 'Save Figure to PowerPoint File...');
in_addmenu(m_file, 0, {@gui.i_savemainfig, 2}, 'Save Figure as Graphic File...');
in_addmenu(m_file, 0, {@gui.i_savemainfig, 1}, 'Save Figure as SVG File...');
in_addmenu(m_file, 1, @gui.callback_SaveX, 'Export && &Save Data...', 'S');
m_edit = uimenu(FigureHandle, 'Text', '&Edit');
in_addmenu(m_edit, 0, @in_SelectCellsByQC, 'Filter Genes & Cells...', 'F');
in_addmenu(m_edit, 1, @in_Brushed2NewCluster, 'Add Brushed Cells to a New Group');
in_addmenu(m_edit, 0, @in_Brushed2MergeClusters, 'Merge Brushed Cells to Same Group');
in_addmenu(m_edit, 0, @in_RenameCellTypeBatchID, 'Rename Cell Type or Batch ID...');
in_addmenu(m_edit, 1, @gui.callback_SplitAtacGex, 'Split Multiome ATAC+GEX Matrix...');
in_addmenu(m_edit, 1, {@in_MergeSCEs, 1}, 'Merge SCE Data Variables in Workspace...');
in_addmenu(m_edit, 0, {@in_MergeSCEs, 2}, 'Merge SCE Data Files...');
in_addmenu(m_edit, 1, @in_AddEditCellAttribs, 'Add/Edit Cell Attributes...');
in_addmenu(m_edit, 0, @in_ExportCellAttribTable, 'Export Cell Attribute Table...');
in_addmenu(m_edit, 1, @gui.callback_SelectCellsByMarker, 'Extract Cells by Marker (+/-) Expression...');
in_addmenu(m_edit, 0, @in_MergeSubCellTypes, 'Merge Subclusters of Same Cell Type');
in_addmenu(m_edit, 1, {@in_WorkonSelectedGenes, 'hvg'}, 'Select Highly Variable Genes (HVGs) to Work on...');
in_addmenu(m_edit, 0, {@in_WorkonSelectedGenes, 'ligandreceptor'}, 'Select Ligand Receptor Genes to Work on...');
in_addmenu(m_edit, 0, @in_SubsampleCells, 'Subsample 50% Cells to Work on...');
in_addmenu(m_edit, 1, {@in_DeleteBrushedOrUnbrushedCells, 'brushed'}, 'Delete Brushed Cells...');
in_addmenu(m_edit, 0, {@in_DeleteBrushedOrUnbrushedCells, 'unbrushed'}, 'Delete Unbrushed Cells...');
in_addmenu(m_edit, 1, @gui.callback_SelectCellsByClass, 'Select Cells by Class && Open in New Window...');
m_view = uimenu(FigureHandle, 'Text', '&View');
in_addmenu(m_view, 0, @in_EmbeddingAgain, 'Embed Cells Using tSNE, UMP, PHATE...', 'B');
in_addmenu(m_view, 0, @in_Switch2D3D, 'Switch Between 2D/3D Embeddings...');
in_addmenu(m_view, 1, @in_ClusterCellsS, "Cluster Cells Using Cell Embedding (S)", 'C');
in_addmenu(m_view, 0, @in_ClusterCellsX, "Cluster Cells Using Expression Matrix (X) 🐢 ...");
in_addmenu(m_view, 1, @gui.callback_ShowGeneExpr, 'Gene Expression...', 'E');
in_addmenu(m_view, 0, @in_ShowCellStates, 'Show Cell States...', 'T');
in_addmenu(m_view, 0, @in_labelcellgroups, 'Label Cell Groups...', 'G');
in_addmenu(m_view, 0, @in_highlightcellgroups, 'Highlight Cell Groups...');
in_addmenu(m_view, 0, @gui.callback_MultiGroupingView, 'Multi-Grouping View...');
in_addmenu(m_view, 0, @gui.callback_CrossTabulation, 'Cross Tabulation');
in_addmenu(m_view, 0, @gui.callback_ShowGeneExprGroup, 'Gene Expression in Groups');
in_addmenu(m_view, 1, @gui.callback_ViewMetaData, 'View Metadata...', 'M');
in_addmenu(m_view, 1, @gui.callback_ShowHgBGeneExpression, 'Hemoglobin (Hgb) Genes Expression...');
in_addmenu(m_view, 0, @gui.callback_ShowMtGeneExpression, 'Mitochondrial (Mt-) Genes Expression...');
in_addmenu(m_view, 0, @in_qcviolin, 'Cell QC Metrics in Violin Plots...');
in_addmenu(m_view, 1, @gui.callback_ShowClustersPop,"Show Cell Clusters/Groups Individually...");
in_addmenu(m_view, 1, @gui.callback_CloseAllOthers, 'Close All Other Figures', 'X');
in_addmenu(m_view, 0, @in_RefreshAll, 'Refresh Current View', 'R');
m_plot = uimenu(FigureHandle, 'Text', '&Plots');
in_addmenu(m_plot, 0, @gui.callback_Dotplot, 'Gene Expression Dot Plot...');
in_addmenu(m_plot, 0, @gui.callback_Heatmap, 'Gene Expression Heatmap...');
in_addmenu(m_plot, 0, @gui.callback_ScatterStemPlot,'Gene Expression/Cell State Stem Plot...');
in_addmenu(m_plot, 0, @gui.callback_Violinplot, 'Gene Expression/Cell State Violin Plot...');
in_addmenu(m_plot, 0, @gui.callback_ScatterCorrPlot,'Correlation Plot...');
in_addmenu(m_plot, 1, @gui.callback_ShowGeneExprCompr,'Side-by-Side Gene Expression...');
in_addmenu(m_plot, 0, @gui.callback_EnrichrTab2Circos,'Enrichr Result Table to Circos Plot...');
in_addmenu(m_plot, 1, @gui.callback_GetCellSignatureMatrix, 'Cell State Radar Plot...');
in_addmenu(m_plot, 0, @in_DrawKNNNetwork, 'Cell kNN Network...');
in_addmenu(m_plot, 0, @in_DrawTrajectory, 'Cell Trajectory...');
in_addmenu(m_plot, 1, @gui.callback_PickPlotMarker,'Next Marker Type');
in_addmenu(m_plot, 0 ,@gui.callback_PickColorMap,'Next Colormap');
in_addmenu(m_plot, 1 ,@in_cleanumap,'Clean tSNE/UMAP/PHATE Plot');
m_anno = uimenu(FigureHandle, 'Text', 'Ann&otate');
in_addmenu(m_anno, 0, {@in_DetermineCellTypeClustersGeneral, true}, "Annotate Cell Types Using PanglaoDB Marker Genes");
in_addmenu(m_anno, 0, {@in_DetermineCellTypeClustersGeneral, false}, 'Annotate Cell Types Using Customized Marker Genes...');
in_addmenu(m_anno, 1, {@in_MergeCellSubtypes, 1}, 'Import Cell Annotation from SCE in Workspace...');
in_addmenu(m_anno, 0, {@in_MergeCellSubtypes, 2}, 'Import Cell Annotation from SCE Data File...');
in_addmenu(m_anno, 1, @in_Brush4Celltypes, "Annotate Cell Types for Brushed Cells");
in_addmenu(m_anno, 0, @gui.callback_Brush4Markers, "Find Marker Genes for Brushed Cells");
in_addmenu(m_anno, 0, @gui.callback_FindAllMarkers, "Make Marker Gene Heatmap");
in_addmenu(m_anno, 1, {@in_CellCyclePotency, 1}, 'Estimate Cell Cycle Phase...');
in_addmenu(m_anno, 0, {@in_CellCyclePotency, 2}, 'Estimate Differentiation Potency...');
in_addmenu(m_anno, 0, {@in_CellCyclePotency, 3}, 'Estimate Stemness...');
in_addmenu(m_anno, 0, {@in_CellCyclePotency, 4}, 'Estimate Dissociation Gene Ratio...');
in_addmenu(m_anno, 1, @in_SingleClickSolution, 'Single Click Solution (from Raw Data to Annotation)...');
m_tool = uimenu(FigureHandle, 'Text', '&Analyze');
in_addmenu(m_tool, 0, @gui.callback_CalculateGeneStats, 'Gene Expression (Statistics) Analysis...');
in_addmenu(m_tool, 0, @in_CompareCellScoreBtwCls, 'Gene Program (Cell Score) Analysis...');
in_addmenu(m_tool, 0, @in_EnrichrHVGs, 'Gene Variability (HVG Function) Analysis...');
in_addmenu(m_tool, 1, @gui.callback_DEGene2Groups, 'Differential Expression (DE) Analysis...','D');
in_addmenu(m_tool, 0, @gui.callback_DVGene2Groups, 'Differential Variability (DV) Analysis...','V');
in_addmenu(m_tool, 0, @gui.callback_DPGene2Groups, 'Differential Program (DP) Analysis...','P');
in_addmenu(m_tool, 1, @gui.callback_DEGene2GroupsBatch, 'DE Analysis in Cell Type Batch Mode...');
in_addmenu(m_tool, 0, @gui.callback_DVGene2GroupsBatch, 'DV Analysis in Cell Type Batch Mode...');
in_addmenu(m_tool, 0, @gui.callback_DPGene2GroupsBatch, 'DP Analysis in Cell Type Batch Mode...');
in_addmenu(m_tool, 1, @gui.callback_RunEnrichr, 'Enrichr Analysis...');
m_ntwk = uimenu(FigureHandle, 'Text', '&Network');
in_addmenu(m_ntwk, 0, @in_Select5000Genes, 'Remove Less Informative Genes to Reduce Gene Space...');
in_addmenu(m_ntwk, 0, @gui.callback_DrawNetwork, 'Plot GRN from Edge (Gene Pair) List...');
in_addmenu(m_ntwk, 1, @gui.callback_BuildGeneNetwork, 'Build GRN with Selected Genes...');
in_addmenu(m_ntwk, 0, @gui.callback_CompareGeneNetwork, 'Build & Compare GRNs...');
in_addmenu(m_ntwk, 1, {@in_scTenifoldNet,1}, 'Construct GRN with All Genes - scTenifoldNet [PMID:33336197] 🐢...');
in_addmenu(m_ntwk, 0, {@in_scTenifoldNet,2}, 'Construct & Compare GRNs - scTenifoldNet [PMID:33336197] 🐢...');
in_addmenu(m_ntwk, 1, @gui.callback_scTenifoldKnk1, 'Virtual Gene Knockout - scTenifoldKnk [PMID:35510185] 🐢 ...');
in_addmenu(m_ntwk, 0, @gui.callback_scTenifoldCko, 'Virtual Cell-Cell Communication Knockout - scTenifoldCko/🐍 [Experimental] 🐢 ...');
%in_addmenu(m_ntwk, 0, @gui.callback_VirtualKOGenKI, 'Virtual Gene Knockout (GenKI/🐍) [PMID:37246643] 🐢 ...');
%in_addmenu(m_ntwk, 1, @gui.callback_scTenifoldXct, 'Cell-Cell Communication (scTenifoldXct/🐍) [PMID:36787742] 🐢 ...');
m_extn = uimenu(FigureHandle, 'Text', 'E&xternal');
in_addmenu(m_extn, 0, @gui.i_resetrngseed, 'Set Random Seed...');
in_addmenu(m_extn, 0, @gui.i_setextwd, 'Set External Program Working Root Directory...');
in_addmenu(m_extn, 1, @gui.i_setrenv, 'Set up R (ℝ) Environment');
in_addmenu(m_extn, 0, @gui.i_setpyenv, 'Set up Python (🐍) Environment');
in_addmenu(m_extn, 1, @in_RunSeuratWorkflow, 'Run Seurat Workflow (Seurat/ℝ) [PMID:25867923]...');
in_addmenu(m_extn, 0, @in_RunMonocle3, 'Pseudotime Analysis (Monocle3/ℝ) [PMID:28825705]...');
in_addmenu(m_extn, 0, {@in_CellCyclePotency, 5}, 'Aneuploid/Diploid Analysis (copykat/ℝ) [PMID:33462507] 🐢 ...');
in_addmenu(m_extn, 0, @in_DecontX, 'Detect Ambient RNA Contamination (DecontX/ℝ) [PMID:32138770]...');
in_addmenu(m_extn, 1, @in_RunDataMapPlot, 'Run DataMapPlot (datamapplot/🐍)...');
in_addmenu(m_extn, 0, @in_DoubletDetection, 'Detect Doublets (Scrublet/🐍) [PMID:30954476]...');
in_addmenu(m_extn, 0, @in_HarmonyPy, 'Batch Integration (Harmony/🐍) [PMID:31740819]...');
in_addmenu(m_extn, 0, @in_SCimilarity, 'Annotate Cell Types (SCimilarity/🐍) [PMID:39566551]...');
in_addmenu(m_extn, 0, {@in_SubsampleCells, 2}, 'Geometric Sketching (geosketch/🐍) [PMID:31176620]...');
in_addmenu(m_extn, 0, @gui.callback_MELDPerturbationScore, 'MELD Perturbation Score (MELD/🐍) [PMID:33558698]...');
in_addmenu(m_extn, 1, @gui.callback_scTenifoldXct, 'One-Sample Cell-Cell Communication (scTenifoldXct/🐍) [PMID:36787742]...');
in_addmenu(m_extn, 0, @gui.callback_scTenifoldXct2, 'Two-Sample Cell-Cell Communication (scTenifoldXct2/🐍) [PMID:36787742]...');
in_addmenu(m_extn, 1, @gui.callback_VirtualKOGenKI, 'Virtual Gene Knockout (GenKI/🐍) [PMID:37246643] ...');
% in_addmenu(m_extn, 1, @gui.callback_ExploreCellularCrosstalk, 'Talklr Intercellular Crosstalk [DOI:10.1101/2020.02.01.930602]...');
m_help = uimenu(FigureHandle, 'Text', '&Help ');
in_addmenu(m_help, 0, {@(~, ~) web('https://scgeatoolbox.readthedocs.io/en/latest/')}, 'Online Documentation...');
in_addmenu(m_help, 0, {@(~, ~) gui.gui_uishowrefinfo('Quick Installation',FigureHandle)}, 'Quick Installation Guide...');
in_addmenu(m_help, 0, {@(~, ~) gui.gui_uishowrefinfo('Shortcuts Guide',FigureHandle)}, 'Shortcuts User Guide...');
in_addmenu(m_help, 1, {@(~, ~) web('https://www.mathworks.com/matlabcentral/fileexchange/72917-scgeatoolbox-single-cell-gene-expression-analysis-toolbox')}, 'View scGEAToolbox on File Exchange...');
in_addmenu(m_help, 0, {@(~, ~) web('https://pubmed.ncbi.nlm.nih.gov/31697351/')}, 'Cite scGEAToolbox Paper...');
in_addmenu(m_help, 0, {@(~, ~) web('https://scholar.google.com/scholar?cites=4661048952867744439&as_sdt=5,44&sciodt=0,44&hl=en')}, 'Papers Citing scGEAToolbox...');
in_addmenu(m_help, 1, {@(~, ~) web('https://scgeatool.github.io/')}, 'Visit SCGEATOOL-Standalone Website...');
in_addmenu(m_help, 0, {@(~, ~) web('https://matlab.mathworks.com/open/github/v1?repo=jamesjcai/scGEAToolbox&file=online_landing.m')}, 'Run SCGEATOOL in MATLAB Online...');
in_addmenu(m_help, 1, @gui.callback_CheckUpdates, 'Check for Updates...');
%in_addmenu(m_help, 1, {@(~,~) gui.sc_simpleabout(FigureHandle)}, 'About SCGEATOOL');
if ~isempty(fx) && isvalid(fx), fxfun(fx, 0.4); end
hAx = axes('Parent', FigureHandle, 'Visible', 'off');
if ~isempty(sce) && sce.NumCells>0
h = gui.i_gscatter3(sce.s, c, methodid, 1, hAx);
title(hAx, sce.title);
if sce.s>2
rotate3d(hAx,'on');
else
brush(hAx,'on');
end
subtitle(hAx,'[genes x cells]');
else
h = [];
hAx.Toolbar.Visible = 'off';
end
dt = datacursormode(FigureHandle);
dt.Enable = 'off';
dt.UpdateFcn = {@i_myupdatefcnx};
% disableDefaultInteractivity(hAx);
delete(findall(FigureHandle, 'Tag', 'FigureToolBar'));
DeftToolbarHandle = uitoolbar('Parent', FigureHandle);
MainToolbarHandle = uitoolbar('Parent', FigureHandle);
UserToolbarHandle = uitoolbar('Parent', FigureHandle);
in_addbuttonpush(0, 0, [], [], "");
in_addbuttonpush(0, 0, @gui.callback_MultiGroupingView, "plotpicker-arxtimeseries.gif", "Multi-grouping View...");
in_addbuttonpush(0, 0, @gui.callback_CrossTabulation, "plotpicker-comet.gif", "Cross tabulation");
in_addbuttonpush(0, 0, @gui.callback_ShowGeneExprGroup, "NewPoints.gif", "Gene expression in groups");
in_addbuttonpush(0, 1, @gui.callback_Dotplot, "icon-mat-blur-linear-10.gif", "Gene Expression Dot Plot...");
in_addbuttonpush(0, 0, @gui.callback_Heatmap, "icon-mat-apps-20.gif", "Gene Expression Heatmap...");
in_addbuttonpush(0, 0, @gui.callback_ScatterStemPlot, "NewPoly.gif", "Gene Expression/Cell State Stem Plot...");
in_addbuttonpush(0, 0, @gui.callback_Violinplot, "violinplot.gif", "Gene Expression/Cell State Violin Plot...");
in_addbuttonpush(0, 0, @gui.callback_ScatterCorrPlot, "icon-mat-blur-off-10a.gif", "Correlation Plot...");
in_addbuttonpush(0, 0, [], [], "");
in_addbuttonpush(0, 1, @in_CompareCellScoreBtwCls, "cellscore2.gif", "Cell score analysis--obtaining gene signature score for each cell");
in_addbuttonpush(0, 0, @gui.callback_GetCellSignatureMatrix, "icon-fa-connectdevelop-20.gif", "Cell state analysis--obtaining multiple gene signature scores to reveal functional state of cells");
in_addbuttonpush(0, 1, @gui.callback_DEGene2Groups, "plotpicker-boxplot.gif", "Differential expression (DE) analysis");
in_addbuttonpush(0, 0, @gui.callback_DVGene2Groups, "plotpicker-andrewsplot.gif", "Differential variability (DV) analysis");
in_addbuttonpush(0, 0, @gui.callback_DPGene2Groups, "plotpicker_noisepsd.gif", "Differential program (DP) analysis");
in_addbuttonpush(0, 0, [], [], "");
in_addbuttonpush(0, 1, @gui.callback_BuildGeneNetwork, "noun_Network_691907.gif", "Build gene regulatory network");
in_addbuttonpush(0, 0, @gui.callback_CompareGeneNetwork, "noun_Deep_Learning_2424485.gif", "Compare two scGRNs");
in_addbuttonpush(0, 1, {@gui.i_savemainfig, 3}, "powerpoint.gif", 'Save Figure to PowerPoint File...');
gui.gui_3dcamera(DeftToolbarHandle, 'AllCells');
pt = uitoggletool(DeftToolbarHandle);
try
load(fullfile(mfolder, 'resources', 'Misc', 'colorbarcdata.mat'),'CData');
pt.CData = CData;
catch
pt.CData = in_getPtImage('aaa');
end
pt.Tooltip = 'Insert Colorbar';
pt.ClickedCallback = @in_addcolorbar;
pt.Tag = "figToglColorbar";
in_addbuttonpush(0, 0, {@gui.i_resizewin, FigureHandle}, 'HDF_pointx.gif', 'Resize Plot Window')
in_addbuttontoggle(1, 0, {@in_togglebtfun, @in_turnoffuserguiding, "icon-mat-unfold-more-10.gif", "icon-mat-unfold-less-10.gif", false, "Turn on/off user onboarding toolbar"});
in_addbuttonpush(1, 0, @gui.callback_ShowGeneExpr, "list.gif", "Select genes to show expression")
in_addbuttonpush(1, 0, @in_ShowCellStates, "list2.gif", "Show cell states")
in_addbuttonpush(1, 0, @in_SelectCellsByQC, "plotpicker-effects.gif", "Filter genes & cells")
in_addbuttonpush(1, 1, @in_labelcellgroups, "icon-fa-tags-10b.gif", "Label cell groups");
% in_addbuttontoggle(1, 1, {@in_togglebtfun, @in_labelcellgroups, "icon-fa-tag-10b.gif", "icon-fa-tags-10b.gif", false, "Label cell groups"});
in_addbuttonpush(1, 0, @in_Brushed2NewCluster, "plotpicker-glyplot-face.gif", "Add brushed cells to a new group")
in_addbuttonpush(1, 0, @in_Brushed2MergeClusters, "plotpicker-pzmap.gif", "Merge brushed cells to same group")
in_addbuttonpush(1, 0, @in_RenameCellTypeBatchID, "plotpicker-scatterhist.gif", "Rename cell type or batch ID");
in_addbuttonpush(1, 0, @in_SingleClickSolution, "icon-mat-fingerprint-10.gif", "Single-click cell type annotation")
in_addbuttonpush(1, 0, [], [], "");
in_addbuttonpush(1, 1, @in_ClusterCellsS, "plotpicker-dendrogram.gif", "Clustering using cell embedding (S)")
% in_addbuttonpush(1, 0, @in_ClusterCellsX, "icon-mw-cluster-10.gif", "Clustering using expression matrix (X)")
in_addbuttonpush(1, 0, {@in_DetermineCellTypeClustersGeneral, true}, "plotpicker-contour.gif", "Assign cell types to groups")
in_addbuttonpush(1, 0, @in_Brush4Celltypes, "brush.gif", "Assign cell type to selected cells");
in_addbuttonpush(1, 1, @gui.callback_Brush4Markers, "plotpicker-kagi.gif", "Marker genes of brushed cells");
in_addbuttonpush(1, 0, @gui.callback_FindAllMarkers, "plotpicker-plotmatrix.gif", "Marker gene heatmap");
in_addbuttonpush(1, 0, [], [], "");
in_addbuttonpush(1, 1, @gui.callback_ShowClustersPop, "plotpicker-geoscatter.gif", "Show cell clusters/groups individually");
in_addbuttonpush(1, 0, @gui.callback_SelectCellsByClass, "plotpicker-pointfig.gif", "Select cells by class/group && open in new window");
in_addbuttonpush(1, 0, @in_DeleteSelectedCells, "plotpicker-qqplot.gif", "Delete brushed/selected cells");
in_addbuttonpush(1, 0, @gui.callback_SaveX, "export.gif", "Export & save data");
in_addbuttonpush(1, 1, @in_EmbeddingAgain, "plotpicker-geobubble.gif", "Embedding (tSNE, UMP, PHATE)");
in_addbuttonpush(1, 0, @in_Switch2D3D, "plotpicker-image.gif", "Switch 2D/3D");
in_addbuttonpush(1, 1, @gui.callback_CloseAllOthers, "icon-fa-cut-10.gif", "Close all other figures");
in_addbuttonpush(1, 0, @gui.callback_PickPlotMarker, "plotpicker-rose.gif", "Switch scatter plot marker type");
in_addbuttonpush(1, 0, @gui.callback_PickColorMap, "plotpicker-compass.gif", "Pick new color map");
in_addbuttonpush(1, 0, @in_RefreshAll, "icon-mat-refresh-20.gif", "Refresh");
if ~isempty(fx) && isvalid(fx), fxfun(fx, 0.6); end
in_addbuttonpush(2, 0, @in_turnonuserguiding, "icon-fa-thumb-tack-10.gif", "Turn on user guiding toolbar");
in_addbuttontoggle(2, 0, {@in_togglebtfun, @in_SelectCellsByQC, "icon-mat-filter-1-10.gif", "plotpicker-effects.gif", true, "Filter genes & cells"});
in_addbuttontoggle(2, 0, {@in_togglebtfun, @in_EmbeddingAgain, "icon-mat-filter-2-10.gif", "plotpicker-geobubble.gif", true, "Embedding (tSNE, UMP, PHATE)"});
in_addbuttontoggle(2, 0, {@in_togglebtfun, @in_ClusterCellsS, "icon-mat-filter-3-10.gif", "plotpicker-dendrogram.gif", true, "Clustering using embedding S"});
in_addbuttontoggle(2, 0, {@in_togglebtfun, @in_DetermineCellTypeClustersGeneral, "icon-mat-filter-4-10.gif", "plotpicker-contour.gif", true, "Assign cell types to groups"});
in_addbuttontoggle(2, 0, {@in_togglebtfun, @gui.callback_SaveX, "icon-mat-filter-5-10.gif", "export.gif", true, "Export & save data"});
if ~isempty(fx) && isvalid(fx), fxfun(fx, 0.8); end
if ~isempty(c)
kc = numel(unique(c));
colormap(pkg.i_mycolorlines(kc));
end
if ~isempty(sce) && sce.NumCells>0
in_EnDisableMenu('on');
else
in_EnDisableMenu('off');
end
if ~isempty(sce) && sce.NumCells>0
hAx.Visible="on";
end
if ~isempty(fx) && isvalid(fx), fxfun(fx, 1.0); end
pause(1);
if ~isempty(fx) && isvalid(fx), set(fx, 'visible', 'off'); end
pause(0.2);
set(FigureHandle, 'visible', 'on');
delete(fx);
uicontrol(button1);
drawnow;
%{
in_fixfield('tsne','tsne3d');
in_fixfield('umap','umap3d');
in_fixfield('phate','phate3d');
in_fixfield('metaviz','metaviz3d');
avx = fieldnames(sce.struct_cell_embeddings);
bvx = fieldnames(pkg.e_makeembedstruct);
cvx = setdiff(bvx,avx);
for kx=1:length(cvx)
sce.struct_cell_embeddings = setfield(sce.struct_cell_embeddings,cvx{kx},[]);
end
sce.struct_cell_embeddings = orderfields(sce.struct_cell_embeddings);
%}
guidata(FigureHandle, sce);
set(FigureHandle, 'CloseRequestFcn', @in_closeRequest);
if nargout > 0
varargout{1} = FigureHandle;
end
if ~ispref('scgeatoolbox', 'useronboardingtoolbar')
gui.gui_userguidingpref(true);
setpref('scgeatoolbox', 'useronboardingtoolbar', true);
end
showuseronboarding = getpref('scgeatoolbox', 'useronboardingtoolbar', false);
if ~showuseronboarding, set(UserToolbarHandle, 'Visible', 'off'); end
% ----------------------------------
majneedupdate = false;
try
[majneedupdate, ~, ~, im] = pkg.i_majvercheck;
catch
end
if majneedupdate
%fprintf('There is a new version of scGEAToolbox (%s vs. %s). To install, type:\n\n', v2, v1);
%fprintf('unzip(''https://github.com/jamesjcai/scGEAToolbox/archive/main.zip'');\n');
%fprintf('addpath(''./scGEAToolbox-main'');\n');
end
in_addmenu(m_help, 1, {@(~,~) gui.sc_simpleabout(FigureHandle, im)}, 'About SCGEATOOL');
% ----------------------------------
function in_sc_openscedlg(~, event)
if strcmp(event.EventName,'KeyPress') && ~ismember(event.Key,{'return','space','i','I'}), return; end
clickType = get(FigureHandle, 'SelectionType');
if strcmp(clickType,'alt'), return; end
set(button1,'Enable','off');
if ~isempty(sce) && sce.NumCells > 0
if ~strcmp(questdlg('Current SCE will be replaced. Continue?',''),'Yes')
set(button1,'Enable','on');
return;
end
end
[sce, filename] = gui.sc_openscedlg;
if ~isempty(sce) && sce.NumCells > 0 && sce.NumGenes > 0
guidata(FigureHandle, sce);
c=[];
in_RefreshAll([], [], false, false);
else
set(button1,'Enable','on');
uicontrol(button1);
if ~isempty(sce)
uiwait(warndlg('Imported SCE contains no cells.',''));
end
end
sprintf('Read data from %s.\n', filename);
try
[~, ~, ext] = fileparts(filename);
if strcmp(ext, '.h5ad')
% if strcmp('.h5ad', extractAfter(filename, strlength(filename)-5))
switch questdlg('Read more cell info, e.g., cell type or batch id (if any) from .h5ad file')
case 'Yes'
[sce] = gui.gui_readh5adinfo(filename, sce);
end
end
catch
end
end
function in_fixfield(oldf, newf)
if ~isfield(sce.struct_cell_embeddings,newf) && isfield(sce.struct_cell_embeddings,oldf)
if ~isempty(sce.struct_cell_embeddings.(oldf))
if size(sce.struct_cell_embeddings.(oldf),2) == 3
sce.struct_cell_embeddings.(newf) = sce.struct_cell_embeddings.(oldf);
sce.struct_cell_embeddings = rmfield(sce.struct_cell_embeddings,oldf);
end
end
end
if isfield(sce.struct_cell_embeddings, oldf)
if isempty(sce.struct_cell_embeddings.(oldf))
sce.struct_cell_embeddings = rmfield(sce.struct_cell_embeddings,oldf);
end
end
end
function in_cleanumap(~, ~)
answer = questdlg('Select embedding method label.', ...
'','tSNE','UMAP','PHATE','tSNE');
if isempty(answer), return; end
a = colormap;
gui.i_baredrplot(hAx, [], answer, FigureHandle);
colormap(a);
end
function in_CompareCellScoreBtwCls(src, events)
if gui.callback_CompareCellScoreBtwCls(src, events)
sce = guidata(FigureHandle);
end
end
function in_CellCyclePotency(src, events, typeid)
if gui.callback_CellCyclePotency(src, events, typeid)
sce = guidata(FigureHandle);
end
end
function in_RunMonocle3(src, events)
if gui.callback_RunMonocle3(src, events)
sce = guidata(FigureHandle);
end
end
function in_turnonuserguiding(~, ~)
% setpref('scgeatoolbox','useronboardingtoolbar',true);
% set(UserToolbarHandle, 'Visible', 'on');
Button = gui.gui_userguidingpref(false);
switch Button
case 'Yes'
case 'No'
in_turnoffuserguiding;
case 'Cancel'
end
end
function in_turnoffuserguiding(~, ~)
if get(UserToolbarHandle, 'Visible') == "off"
askpref = true;
else
askpref = false;
end
if showuseronboarding
set(UserToolbarHandle, 'Visible', 'off');
else
set(UserToolbarHandle, 'Visible', 'on');
end
showuseronboarding = ~showuseronboarding;
if askpref
% gui.gui_userguidingpref(false);
%answer=questdlg('Show User Onboarding Toolbar again next time?','');
%switch answer
% case 'Yes'
% setpref('scgeatoolbox','useronboardingtoolbar',true);
% case 'No'
% setpref('scgeatoolbox','useronboardingtoolbar',false);
%end
end
end
function in_addmenu(menuHdl, sepTag, callbackFnc, tooltipTxt, acchar)
if nargin<5, acchar=''; end
if ischar(callbackFnc) || isstring(callbackFnc)
callbackFnc = str2func(callbackFnc);
end
if sepTag == 1
septag = 'on';
else
septag = 'off';
end
uimenu(menuHdl, 'Text', tooltipTxt, ...
'Separator', septag, ...
'Callback', callbackFnc, ...
'Accelerator', acchar, ...
'Tag', "figMenu" + matlab.lang.makeValidName(tooltipTxt));
end
function in_addbuttonpush(toolbarHdl, sepTag, callbackFnc, imgFil, tooltipTxt)
if ischar(callbackFnc) || isstring(callbackFnc)
callbackFnc = str2func(callbackFnc);
end
if toolbarHdl == 0
barhandle = DeftToolbarHandle;
elseif toolbarHdl == 1
barhandle = MainToolbarHandle;
elseif toolbarHdl == 2
barhandle = UserToolbarHandle;
end
pt = uipushtool(barhandle, 'Separator', sepTag);
if ~isempty(imgFil)
%pt.Icon = fullfile(mfolder,'..','resources','Images',imgFil);
pt.CData = in_getPtImage(imgFil);
pt.Tooltip = tooltipTxt;
pt.ClickedCallback = callbackFnc;
pt.Tag = "figPush" + matlab.lang.makeValidName(tooltipTxt);
end
end
function in_addbuttontoggle(toolbarHdl, sepTag, callbackFnc)
imgFil = callbackFnc{3};
tooltipTxt = callbackFnc{6};
%if ischar(callbackFnc{1}) || isstring(callbackFnc{1})
% callbackFnc=str2func(callbackFnc{1});
%end
if toolbarHdl == 0
barhandle = DeftToolbarHandle;
elseif toolbarHdl == 1
barhandle = MainToolbarHandle;
elseif toolbarHdl == 2
barhandle = UserToolbarHandle;
end
pt = uitoggletool(barhandle, 'Separator', sepTag);
pt.CData = in_getPtImage(imgFil);
pt.Tooltip = tooltipTxt;
pt.ClickedCallback = callbackFnc;
%callbackFnc =
% 1×6 cell array
% {function_handle} {function_handle} {["icon-mat-filt…"]} {["plotpicker-co…"]} {[1]} {["Assign cell t…"]}
pt.Tag = "figTogl" + matlab.lang.makeValidName(tooltipTxt);
end
function in_togglebtfun(src, ~, func, ~, imgFil, ...
actiondelay, tooltipTxt)
if nargin < 6, actiondelay = true; end
src.CData = in_getPtImage(imgFil);
if actiondelay
if src.State == "off"
func(src);
else
s = 'To execute the function, click the button again or locate and click the same button in the toolbar above. Hover over the button to view a description of its function.';
uiwait(helpdlg(sprintf('%s\n%s', upper(tooltipTxt), s), ''));
end
else
func(src);
end
end
function [ptImage] = in_getPtImage(imgFil)
try
[img, map] = imread(fullfile(mfolder, 'resources', 'Images', imgFil));
ptImage = ind2rgb(img, map);
catch
try
[img, map] = imread(fullfile(matlabroot,'toolbox', ...
'matlab','icons', imgFil));
ptImage = ind2rgb(img, map);
catch
ptImage = rand(16, 16, 3);
end
end
end
% ------------------------
% Callback Functions
% ------------------------
function in_addcolorbar(~,~)
% cbtogg = uigettool(FigureHandle,'figToglColorbar');
cbtogg = findall(FigureHandle, 'Tag', 'figToglColorbar');
if ~isempty(cbtogg) && isequal(cbtogg,gcbo) && strcmpi(get(cbtogg,'State'),'on')
colorbar(hAx);
else
colorbar(hAx,'off')
end
end
function in_closeRequest(hObject, ~)
if ~(ismcc || isdeployed)
if isempty(sce) || sce.NumCells==0
ButtonName = 'no';
else
ButtonName = questdlg('Save SCE before closing SCGEATOOL?');
end
switch lower(ButtonName)
case 'yes'
if ~isempty(callinghandle)
guidata(callinghandle, sce);
delete(hObject);
uiwait(helpdlg('SCE updated.',''));
else
if gui.callback_SaveX(FigureHandle,[])
pause(1);
delete(hObject);
end
end
case 'cancel'
return;
case 'no'
delete(FigureHandle);
otherwise
return;
end
else
delete(hObject);
end
end
function in_qcviolin(~, ~)
gui.i_qcviolin(sce.X, sce.g, FigureHandle);
end
function in_RunDataMapPlot(src, ~)
if ~pkg.i_checkpython
uiwait(warndlg('Python is not installed.',''));
return;
end
ndim = 2;
[vslist] = gui.i_checkexistingembed(sce, ndim);
if isempty(h.ZData) && size(sce.s,2)==2 && length(vslist) <= 1
gui.callback_RunDataMapPlot(src, []);
elseif isempty(h.ZData) && size(sce.s,2)==2 && length(vslist) > 1
switch questdlg('Using current 2D embedding?')
case 'Yes'
gui.callback_RunDataMapPlot(src, []);
case 'No'
[sx] = gui.i_pickembedvalues(sce, 2);
if ~isempty(sx) && size(sx,1) == sce.NumCells
sce.s = sx;
else
warning('Running error.');
return;
end
guidata(FigureHandle, sce);
gui.callback_RunDataMapPlot(src, []);
case 'Cancel'
return;
end
elseif ~isempty(h.ZData)
if strcmp(questdlg('This function requires 2D embedding. Continue?'), 'Yes'), in_Switch2D3D(src,[]); end
end
end
function in_SubtypeAnnotation(src, ~)
[requirerefresh] = gui.callback_SubtypeAnnotation(src, []);
if requirerefresh
sce = guidata(FigureHandle);
[c, cL] = grp2idx(sce.c_cell_type_tx);
in_RefreshAll(src, [], true, false);
ix_labelclusters(true);
end
end
function in_MergeCellSubtypes(src, ~, sourcetag, allcell)
if nargin < 4
switch questdlg('Import annotation for all cells or just cells of a subtype?', '', ...
'All Cells', 'Subtype Cells', 'Cancel', 'All Cells')
case 'All Cells'
allcell = true;
case 'Subtype Cells'
allcell = false;
case 'Cancel'
return;
otherwise
return;
end
end
[requirerefresh] = gui.callback_MergeCellSubtypes(src, [], sourcetag, allcell);
if requirerefresh
sce = guidata(FigureHandle);
[c, cL] = grp2idx(sce.c_cell_type_tx);
in_RefreshAll(src, [], true, false);
ix_labelclusters(true);
end
end
function in_MergeSCEs(src, ~, sourcetag)
[requirerefresh, s] = gui.callback_MergeSCEs(src, sourcetag);
if requirerefresh && ~isempty(s)
sce = guidata(FigureHandle);
[c, cL] = grp2idx(sce.c_batch_id);
sce.c = c;
if sce.NumCells==0
uiwait(warndlg('Merged SCE contains no cells.',''));
return;
else
in_RefreshAll(src, [], true, false);
uiwait(helpdlg(sprintf('%s SCEs merged.', upper(s)), ''));
end
end
end
function in_WorkonSelectedGenes(src, ~, type)
if nargin < 1, type = 'hvg'; end
switch type
case 'hvg'
k = gui.i_inputnumk(2000, 1, sce.NumGenes, 'the number of HVGs');
if isempty(k), return; end
answer = questdlg('Which HVG detecting method to use?', '', ...
'Splinefit Method [PMID:31697351]', ...
'Brennecke et al. (2013) [PMID:24056876]', ...
'Splinefit Method [PMID:31697351]');
switch answer
case 'Brennecke et al. (2013) [PMID:24056876]'
fw = gui.gui_waitbar;
T = sc_hvg(sce.X, sce.g);
case 'Splinefit Method [PMID:31697351]'
fw = gui.gui_waitbar;
T = sc_splinefit(sce.X, sce.g);
otherwise
return;
end
glist = T.genes(1:min([k, sce.NumGenes]));
[y, idx] = ismember(glist, sce.g);
if ~all(y)
errordlg('Runtime error.','');
return;
end
case 'ligandreceptor'
fw = gui.gui_waitbar;
load(fullfile(mfolder, 'resources', 'Ligand_Receptor', ...
'Ligand_Receptor_more.mat'), 'ligand','receptor');
idx = ismember(upper(sce.g), unique([ligand; receptor]));
if ~any(idx)
errordlg('Runtime error: No gene left after selection.','');
return;
end
if sum(idx) < 50
if ~strcmp(questdlg('Few genes (n < 50) selected. Continue?',''), 'Yes'), return; end
end
end
sce.g = sce.g(idx);
sce.X = sce.X(idx, :);
gui.gui_waitbar(fw);
guidata(FigureHandle, sce);
in_RefreshAll(src, [], true, false);
end
function in_SubsampleCells(src, ~, methodoption)
if nargin < 3, methodoption = []; end
if ~strcmp(questdlg('This function subsamples 50% of cells. Continue?',''), 'Yes'), return; end
if isempty(methodoption)
answer = questdlg('Select method:', '', ...
'Uniform Sampling', ...
'Geometric Sketching [PMID:31176620]', 'Uniform Sampling');
switch answer
case 'Uniform Sampling'
methodoption = 1;
case 'Geometric Sketching [PMID:31176620]'
if ~pkg.i_checkpython
uiwait(warndlg('Python not installed.',''));
return;
end
methodoption = 2;
otherwise
return;
end
end
tn = round(sce.NumCells/2);
if methodoption == 1
rng("shuffle");
idx = randperm(sce.NumCells);
ids = idx(1:tn);
elseif methodoption == 2
if ~gui.gui_showrefinfo('Geometric Sketching [PMID:31176620]'), return; end
fw = gui.gui_waitbar;
Xn = log1p(sc_norm(sce.X))';
[~, Xn] = pca(Xn, 'NumComponents', 300);
gui.gui_waitbar(fw);
try
ids = run.py_geosketch(Xn, tn);
catch ME
gui.gui_waitbar(fw, true);
errordlg(ME.message,'');
return;
end
end
if ~isempty(ids)
sce = sce.selectcells(ids);
c = sce.c;
in_RefreshAll(src, [], true, false);
guidata(FigureHandle, sce);
else
errordlg('Runtime error. No action is taken.','');
end
end
function in_SingleClickSolution(src, ~)
if ~all(sce.c_cell_type_tx == "undetermined")
if ~strcmp(questdlg("Your data has been embedded and annotated. Single Click Solution will re-embed and annotate cells. Current embedding and annotation will be overwritten. Continue?", ""), 'Yes'), return; end
else
if ~gui.gui_showrefinfo('Single Click Solution'), return; end
end
%if isempty(speciestag)
speciestag = gui.i_selectspecies(2);
%end
if isempty(speciestag), return; end
prompt = {
'tSNE Embedding?', ...
'Add UMAP Embedding?', ...
'Add PHATE Embedding?', ...
'Estimate Cell Cycles?', ...
'Estimate Differentiation Potency of Cells?'};
dlgtitle = '';
dims = [1, 85];
definput = {'Yes', 'No', 'No', 'Yes', 'Yes'};
answer = inputdlg(prompt, dlgtitle, dims, definput);
if isempty(answer)
return;
end
fw = gui.gui_waitbar_adv;
gui.gui_waitbar_adv(fw,1/8,'Basic QC Filtering...');
sce = sce.qcfilter;
count = 1;
if ~(strcmpi(answer{count},'Yes') || strcmpi(answer{count},'Y'))
errordlg('tSNE Embedding has to be included.','');
return;
end
count = count + 1;
if strcmpi(answer{count},'Yes') || strcmpi(answer{count},'Y')
gui.gui_waitbar_adv(fw,2/8, 'Embeding Cells Using UMAP...');
sce = sce.embedcells('umap3d', true, true, 3);
end
count = count + 1;
if strcmpi(answer{count},'Yes') || strcmpi(answer{count},'Y')
gui.gui_waitbar_adv(fw,2/8, 'Embeding Cells Using PHATE...');
sce = sce.embedcells('phate3d', true, true, 3);
end
gui.gui_waitbar_adv(fw,2/8, 'Embeding Cells Using tSNE...');
sce = sce.embedcells('tsne3d', true, true, 3);
gui.gui_waitbar_adv(fw,3/8, 'Clustering Cells Using K-means...');
sce = sce.clustercells([], [], true);
gui.gui_waitbar_adv(fw,4/8, 'Annotating Cell Types Using PanglaoDB...');
sce = sce.assigncelltype(speciestag, false);
count = count + 1;
if strcmpi(answer{count},'Yes') || strcmpi(answer{count},'Y')
gui.gui_waitbar_adv(fw,5/8, 'Estimate Cell Cycles...');
sce = sce.estimatecellcycle;
end
count = count + 1;
if strcmpi(answer{count},'Yes') || strcmpi(answer{count},'Y')
gui.gui_waitbar_adv(fw,6/8, 'Estimate Differentiation Potency of Cells...');
sce = sce.estimatepotency(speciestag);
end
gui.gui_waitbar_adv(fw,7/8);
[c,cL] = grp2idx(sce.c_cell_type_tx);
sce.c = c;
gui.gui_waitbar_adv(fw);
in_RefreshAll(src, [], true, false);
ix_labelclusters(true);
%setappdata(FigureHandle, 'cL', cL);
guidata(FigureHandle, sce);
end
function in_SelectCellsByQC(src, ~)
%oldsce = sce;
% oldn = sce.NumCells;
% oldm = sce.NumGenes;
sce.c = c;
guidata(FigureHandle, sce);
try
[requirerefresh, highlightindex] = ...
gui.callback_SelectCellsByQC(src);
catch ME
errordlg(ME.message,'');
return;
end
if requirerefresh
sce = guidata(FigureHandle);
[c, cL] = grp2idx(sce.c);
in_RefreshAll(src, [], true, false);
% newn = sce.NumCells;
% newm = sce.NumGenes;
% answer = questdlg(sprintf('%d cells removed; %d genes removed.', ...
% oldn-newn, oldm-newm),'','Accept Changes', 'Undo Changes', 'Accept Changes');
% if ~strcmp(answer, 'Accept Changes')
% sce = oldsce;
% [c, cL] = grp2idx(sce.c);
% in_RefreshAll(src, [], true, false);
% guidata(FigureHandle, sce);
% end
end
if ~isempty(highlightindex)
h.BrushData = highlightindex;
end
end
function in_Select5000Genes(src, ~)
oldm = sce.NumGenes;
oldn = sce.NumCells;
[requirerefresh, scenew] = gui.callback_Select5000Genes(src);
if requirerefresh
sce = scenew;
c=sce.c;
in_RefreshAll(src, [], true, false);
newm = sce.NumGenes;
newn = sce.NumCells;
uiwait(helpdlg(sprintf('%d cells removed; %d genes removed.', ...
oldn-newn, oldm-newm), ''));
guidata(FigureHandle, sce);
end
end
function in_RunSeuratWorkflow(src, ~)
extprogname = 'R_Seurat';
preftagname = 'externalwrkpath';
[wkdir] = gui.gui_setprgmwkdir(extprogname, preftagname);
if isempty(wkdir), return; end
[ok] = gui.i_confirmscript('Run Seurat Workflow (Seurat/R)?', ...
'R_Seurat', 'r');
if ~ok, return; end
[ndim] = gui.i_choose2d3d;
if isempty(ndim), return; end
fw = gui.gui_waitbar;
try
[sce] = run.r_seurat(sce, ndim, wkdir, true);
[c, cL] = grp2idx(sce.c);
catch
gui.gui_waitbar(fw);
return;
end
gui.gui_waitbar(fw);
guidata(FigureHandle, sce);
in_RefreshAll(src, [], true, false);
end
function in_DecontX(~, ~)
if ~gui.gui_showrefinfo('DecontX [PMID:32138770]'), return; end
extprogname = 'R_decontX';
preftagname = 'externalwrkpath';
[wkdir] = gui.gui_setprgmwkdir(extprogname, preftagname);
if isempty(wkdir), return; end
fw = gui.gui_waitbar;
try
[Xdecon, ~] = run.r_decontX(sce, wkdir);
catch ME