-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdev_subject.tex
More file actions
2464 lines (2068 loc) · 99.1 KB
/
dev_subject.tex
File metadata and controls
2464 lines (2068 loc) · 99.1 KB
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
\documentclass{tufte-handout}
\usepackage{../braph2_dev}
%\geometry{showframe} % display margins for debugging page layout
\title{Implement, Export, and Import Groups of Subjects}
\author[The BRAPH~2 Developers]{The BRAPH~2 Developers}
\begin{document}
\maketitle
\begin{abstract}
This is the developer tutorial for implementing, importing, and exporting groups of subjects.
You will learn how to create generator files \fn{*.gen.m} for new subjects and well as to import and export them. All \fn{*.gen.m} files can then be compiled by \code{braph2genesis}.
All types of subjects are extensions of the base element \code{Subject}.
You will use as examples the subjects \code{SubjectCON} (subject with connectivity data), \code{SubjectCON\_MP} (subject with connectivity multiplex data), \code{SubjectFUN} (subject with functional data), \code{SubjectFUN\_MP} (subject with functional multiplex data), \code{SubjectST} (subject with structural data), and \code{SubjectST\_MP} (subject with structural multiplex data).
Furthermore, all importers and exporters are extensions of the base elements \code{Exporter} and \code{Importer}, respectively. Here, you will use as examples \code{ImporterGroupSubjectCON\_TXT} (importing a group of subjects with connectivity data to a series of TXT file),\code{ImporterGroupSubjectCON\_XLS} (importing a group of subjects with connectivity data to a series of XLSX file), \code{ExporterGroupSubjectCON\_TXT} (exporting a group of subjects with connectivity data to a series of TXT file), and \code{ExporterGroupSubjectCON\_XLS} (exporting a group of subjects with connectivity data to a series of XLSX file).
\end{abstract}
\tableofcontents
\clearpage
\section{Implementation of a subject with connectivity data}
\subsection{Subject with connectivity data (\code{SubjectCON})}
You will start by implementing in detail \code{SubjectCON}, which holds a connectivity matrix (for example, obtained from DTI data).
\begin{lstlisting}[
label=cd:m:SubjectCON:header,
caption={
{\bf SubjectCON element header.}
The \code{header} section of the generator code in \fn{\_SubjectCON.gen.m} provides the general information about the \code{SubjectCON} element.
}
]
%% ¡header!
SubjectCON < Subject (sub, subject with connectivity matrix) is a subject with connectivity matrix (e.g. DTI). ¥\circled{1}\circlednote{1}{ The element \code{SubjectCON} is defined as a subclass of \code{Subject}. The moniker will be \code{sub}.}¥
%%% ¡description!
Subject with a connectivity matrix (e.g. obtained from DTI).
%%% ¡seealso! ¥\circled{2}\circlednote{2}{ Other related elements.}¥
ImporterGroupSubjectFUN_TXT, ExporterGroupSubjectFUN_TXT, ImporterGroupSubjectFUN_XLS, ExporterGroupSubjectFUN_XLS
%%% ¡build!
1
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:SubjectCON:prop_update,
caption={
{\bf SubjectCON element props update.}
The \code{props\_update} section of the generator code in \fn{\_SubjectCON.gen.m} updates the properties of the \code{SubjectCON} element. This defines the core properties of the subject.
}
]
%% ¡props_update!
%%% ¡prop!
NAME (constant, string) is the name of the subject.
%%%% ¡default!
'SubjectCON'
%%% ¡prop!
DESCRIPTION (constant, string) is the description of the subject.
%%%% ¡default!
'SubjectCON with a connectivity matrix (e.g. obtained from DTI).'
%%% ¡prop!
TEMPLATE (parameter, item) is the template of the subject.
%%% ¡settings!
'SubjectCON'
%%% ¡prop!
ID (data, string) is a few-letter code for the subject.
%%%% ¡default!
'SubjectCON ID'
%%% ¡prop!
LABEL (metadata, string) is an extended label of the subject.
%%%% ¡default!
'SubjectCON label'
%%% ¡prop!
NOTES (metadata, string) are some specific notes about the subject.
%%%% ¡default!
'SubjectCON notes'
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:SubjectCON:props,
caption={
{\bf SubjectCON element props.}
The \code{props} section of the generator code in \fn{\_SubjectCON.gen.m} defines the properties specific for the \code{SubjectCON} element, including the connectivity matrix.
}
]
%% ¡props!
%%% ¡prop! ¥\circled{1}\circlednote{1}{ defines the brain atlas used for the connectivity matrix.}¥
BA (data, item) is a brain atlas.
%%%% ¡settings!
'BrainAtlas'
%%% ¡prop!
CON (data, smatrix) is an adjacency matrix.
%%%% ¡check_value!
br_number = sub.get('BA').get('BR_DICT').get('LENGTH'); ¥\circled{2}\circlednote{2}{ determines the number of brain regions from the Brain Atlas.}¥
check = isequal(size(value), [br_number, br_number]); ¥ \circled{3}\circlednote{3}{ checks that the size of \code{value} (\code{value} is the connectivity matrix) is equal to the number of brain regions.}¥
if check ¥ \circled{4}\circlednote{4}{ returns the check information \code{msg} according to the variable \code{check}.}¥
msg = 'All ok!';
else
msg = ['CON must be a square matrix with the dimension equal to the number of brain regions (' int2str(br_number) ').'];
end
%%%% ¡gui! ¥\circled{5}\circlednote{5}{ plots the panel of a property matrix-like with element \code{sub} and the property number \code{SubjectCON.CON}. \code{ROWNAME} and \code{COLUMNNAME} are the name of the brain regions obtained from brain atlas.}¥
pr = PanelPropMatrix('EL', sub, 'PROP', SubjectCON.CON, ...
'ROWNAME', sub.get('BA').get('BR_DICT').getCallback('KEYS'), ...
'COLUMNNAME', sub.get('BA').get('BR_DICT').getCallback('KEYS'), ...
varargin{:});
\end{lstlisting}
\clearpage
\begin{lstlisting}[
label=cd:m:SubjectCON:tests,
caption={
{\bf SubjectCON element tests.}
The \code{tests} section from the element generator \fn{\_SubjectCON.gen.m}.
A general test should be prepared to test the properties of the Subject when it is empty and full. Furthermore, additional tests should be prepared for the rules defined.
}
]
%% ¡tests!
%%% ¡test!
%%%% ¡name!
GUI ¥\circled{1}\circlednote{1}{ This test checks that the GUI is constructing well.}¥
%%%% ¡probability! ¥\circled{2}\circlednote{2}{ assigns a low test execution probability.}¥
.01
%%%% ¡code!
im_ba = ImporterBrainAtlasXLS('FILE', 'desikan_atlas.xlsx'); ¥\circled{3}\circlednote{3}{ imports the brain atlas \code{desikan} from the file \fn{desikan\_atlas.xlsx}.There are also other atlases in Braph2 folder \fn{atlases}, including \fn{aal90\_atlas.xlsx}, \fn{aal116\_atlas.xlsx}, \fn{bna\_atlas.xlsx}, \fn{craddock\_atlas.xlsx}, \fn{desikan\_subcortical\_atlas.xlsx}, \fn{destrieux\_atlas.xlsx}, \fn{destrieux\_subcortical\_atlas.xlsx}, \fn{schaefer200\_atlas.xlsx} and \fn{subcortical\_atlas.xlsx}.}¥
ba = im_ba.get('BA'); ¥\circled{4}\circlednote{4}{ returns the brain atlas.}¥
gr = Group('SUB_CLASS', 'SubjectCON', 'SUB_DICT', IndexedDictionary('IT_CLASS', 'SubjectCON')); ¥\circled{5}\circlednote{5}{ represents a group of subjects whose class is defined in the property \code{'SUB\_CLASS'}. \code{'SUB\_DICT'} manages the subjects as an indexed dictionary of subjects.}¥
for i = 1:1:50 ¥\circled{6}\circlednote{6}{ construts 50 subjects with random connectivity matrices.}¥
sub = SubjectCON( ... ¥\circled{7}\circlednote{7}{ defines the \code{'ID'}, \code{'LABEL'}, \code{'NOTES'}, \code{'BA'} (Brain Atlas) and \code{'CON'} (a random adjacency matrix) for a subject.}¥
'ID', ['SUB CON ' int2str(i)], ...
'LABEL', ['Subejct CON ' int2str(i)], ...
'NOTES', ['Notes on subject CON ' int2str(i)], ...
'BA', ba, ...
'CON', rand(ba.get('BR_DICT').get('LENGTH')) ...
);
sub.memorize('VOI_DICT').get('ADD', VOINumeric('ID', 'Age', 'V', 100 * rand())) ¥\circled{8}\circlednote{8}{ adds a random \code{Numeric} \code{'Age'} as the variable of interest of the subject.}¥
sub.memorize('VOI_DICT').get('ADD', VOICategoric('ID', 'Sex', 'CATEGORIES', {'Female', 'Male'}, 'V', randi(2, 1))) ¥\circled{9}\circlednote{9}{ adds a random \code{Categoric} \code{'Sex'} as the variable of interest of the subject.}¥
gr.get('SUB_DICT').get('ADD', sub) ¥\circled{10}\circlednote{10}{ adds \code{'sub'} into group.}¥
end
gui = GUIElement('PE', gr, 'CLOSEREQ', false); ¥\circled{11}\circlednote{11}{ constructs the GUI panel from \code{gr}. Setting the \code{'CLOSEREQ'} to \code{false} switched off the confirmation panel for closing the GUI.}¥
gui.get('DRAW') ¥\circled{12}\circlednote{12}{ draws the contents of a GUI before showing it.}¥
gui.get('SHOW') ¥\circled{13}\circlednote{13}{ shows the figure and its dependent figures.}¥
gui.get('CLOSE') ¥\circled{14}\circlednote{14}{ closes the figure and its dependent figures.}¥
\end{lstlisting}
\clearpage
\subsection{Subject with connectivity multiplex data (\code{SubjectCON\_MP})}
You can now use \code{SubjectCON} as the basis to implement the \code{SubjectCON\_MP}.
{%TEX
The parts of the code that are modified are highlighted.
}%TEX
While the multilayer data allows connections between any nodes across the multiple layers, the \code{SubjectCON\_MP} can also be used for ordinal multilayer data.
\begin{lstlisting}[
label=cd:m:SubjectCON_MP:header,
caption={
{\bf SubjectCON\_MP element header.}
The \code{header} section of the generator code in \fn{\_SubjectCON\_MP.gen.m} provides the general information about the \code{SubjectCON\_MP} element. \expand{cd:m:SubjectCON:header}
}
]
¤%% ¡header!
¤SubjectCON_MP¤ < Subject (sub, ¤subject with connectivity multiplex data) is a subject with connectivity multiplex data¤.
%%% ¡description!
¤Subject with L connectivity matrices¤ (e.g. obtained from DTI).
%%% ¡seealso!
¤ImporterGroupSubjectCON_MP_TXT, ExporterGroupSubjectCON_MP_TXT, ImporterGroupSubjectCON_MP_XLS, ExporterGroupSubjectCON_MP_XLS¤
%%% ¡build!
¤1
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:SubjectCON_MP:prop_update,
caption={
{\bf SubjectCON\_MP element props update.}
The \code{props\_update} section of the generator code in \fn{\_SubjectCON\_MP.gen.m} updates the properties of the \code{Subject} element. \expand{cd:m:SubjectCON:prop_update}
}
]
¤%% ¡props_update!
%%% ¡prop!
NAME (constant, string) is the name of the subject.
%%%% ¡default!
¤'SubjectCON_MP'¤
%%% ¡prop!
DESCRIPTION (constant, string) is the description of the subject.
%%%% ¡default!
'Subject with ¤L connectivity matrices¤ (e.g. obtained from DTI).'
%%% ¡prop!
TEMPLATE (parameter, item) is the template of the subject.
%%% ¡settings!
¤'SubjectCON_MP'¤
%%% ¡prop!
ID (data, string) is a few-letter code for the subject.
%%%% ¡default!
¤'SubjectCON_MP ID'¤
%%% ¡prop!
LABEL (metadata, string) is an extended label of the subject.
%%%% ¡default!
¤'SubjectCON_MP label'¤
%%% ¡prop!
NOTES (metadata, string) are some specific notes about the subject.
%%%% ¡default!
¤'SubjectCON_MP notes'
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:SubjectCON_MP:props,
caption={
{\bf SubjectCON\_MP element props.}
The \code{props} section of the generator code in \fn{\_SubjectCON\_MP.gen.m} defines the properties specific for the \code{SubjectCON\_MP} element, including the connectivity matrices for each layer. \expand{cd:m:SubjectCON:props}
}
]
¤%% ¡props!
%%% ¡prop!
BA (data, item) is a brain atlas.
%%%% ¡settings!
'BrainAtlas'
¤%%% ¡prop!
L (data, scalar) is the number of layers of subject data. ¥\circled{1}\circlednote{1}{ defines a parameter to determine the number of layers of subject data. This property must be of a scalar parameter.}¥
%%%% ¡default!
2¤ ¥\circled{2}\circlednote{2}{ defines the default option, in this case \code{2}.}¥
¤%%% ¡prop!
LAYERLABELS (metadata, stringlist) are the layer labels provided by the user.¤ ¥\circled{3}\circlednote{3}{ defines a parameter to determine the labels for each layer. This property must be of string list parameter.}¥
¤%%% ¡prop!
ALAYERLABELS (query, stringlist) returns the processed layer labels.¤ ¥\circled{4}\circlednote{4}{ defines a parameter to determine the processed labels for each layer. This property must be of string list parameter.}¥
%%%% ¡calculate!
value = sub.get('LAYERLABELS'); ¥\circled{5}\circlednote{5}{ defines the \code{value} from the property \code{'LAYERLABELS'} of SubjectCON\_MP.}¥
%%% ¡prop!
¤CON_MP (data, cell) is a cell containing L matrices corresponding connectivity matrices of each layer.¤
%%%% ¡check_value!
br_number = sub.get('BA').get('BR_DICT').get('LENGTH');
¤num_layers = sub.get('L'); ¥\circled{6}\circlednote{6}{ gets the number of layers.}¥
check = (iscell(value) && isequal(length(value), num_layers) && isequal( cellfun(@(v) size(v, 1), value), ones(1, num_layers) * br_number) && isequal( cellfun(@(v) size(v, 2), value), ones(1, num_layers) * br_number)) || (isempty(value) && br_number == 0);¤ ¥\circled{7}\circlednote{7}{ checks the size of each layer is equal to the number of brain regions.}¥
if check
msg = 'All ok!';
else
¤msg = ['CON_MP must be a cell with L square matrices with the dimension equal to the number of brain regions (' int2str(br_number) ').'];¤
end
%%%% ¡gui!
pr = PanelPropCell('EL', sub, 'PROP', ¤SubjectCON_MP.CON_MP¤, ...
¤'TABLE_HEIGHT', s(40), ... ¥\circled{8}\circlednote{8}{ defines the height of table.}¥
'XSLIDERSHOW', true, ... ¥\circled{9}\circlednote{9}{ shows the x-axis slider.}¥
'XSLIDERLABELS', sub.getCallback('ALAYERLABELS'), ... ¥\circled{10}\circlednote{10}{ shows the x-axis slider's labels.}¥
'YSLIDERSHOW', false, ...¤ ¥\circled{11}\circlednote{11}{ does not show the y-axis slider.}¥
'ROWNAME', sub.get('BA').get('BR_DICT').getCallback('KEYS'), ...
'COLUMNNAME', sub.get('BA').get('BR_DICT').getCallback('KEYS'), ...
varargin{:});¤
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:SubjectCON_MP:tests,
caption={
{\bf SubjectCON\_MP element tests.}
The \code{tests} section from the element generator \fn{\_SubjectCON\_MP.gen.m}. \expand{cd:m:SubjectCON:tests}
}
]
¤%% ¡tests!
%%% ¡test!
%%%% ¡name!
GUI
%%%% ¡probability!
.01
%%%% ¡code!
im_ba = ImporterBrainAtlasXLS('FILE', ¤'aal90_atlas.xlsx'¤);
ba = im_ba.get('BA');
gr = Group('SUB_CLASS', ¤'SubjectCON_MP'¤, 'SUB_DICT', IndexedDictionary('IT_CLASS', ¤'SubjectCON_MP'¤));
for i = 1:1:10
sub = SubjectCON_MP( ...
'ID', [¤'SUB CON_MP '¤ int2str(i)], ...
'LABEL', [¤'Subejct CON_MP '¤ int2str(i)], ...
'NOTES', [¤'Notes on subject CON_MP '¤ int2str(i)], ...
'BA', ba, ...
¤'L', 3, ... ¥\circled{1}\circlednote{1}{ defines the number of layers.}¥
'LAYERLABELS', {'L1' 'L2' 'L3'}, ... ¥\circled{2}\circlednote{2}{ defines the label of each layer.}¥
'CON_MP', {rand(ba.get('BR_DICT').get('LENGTH')), rand(ba.get('BR_DICT').get('LENGTH')), rand(ba.get('BR_DICT').get('LENGTH'))} ...¤
); ¥\circled{3}\circlednote{3}{ constructs 3 layers randomly using connectivity matrices with size of brain regions by brain regions.}¥
sub.memorize('VOI_DICT').get('ADD', VOINumeric('ID', 'Age', 'V', 100 * rand()))
sub.memorize('VOI_DICT').get('ADD', VOICategoric('ID', 'Sex', 'CATEGORIES', {'Female', 'Male'}, 'V', randi(2, 1)))
gr.get('SUB_DICT').get('ADD', sub)
end
gui = GUIElement('PE', gr, 'CLOSEREQ', false);
gui.get('DRAW')
gui.get('SHOW')
gui.get('CLOSE')
\end{lstlisting}
\clearpage
\section{Implementation of importer and exporter (for \code{SubjectCON})}
\subsection{Importer from TXT (\code{ImporterGroupSubjectCON\_TXT})}
You will start by implementing in detail \code{ImporterGroupSubjectCON\_TXT}. The data should be stored in the folder \fn{Group1} and \fn{Group2}, and the file format is \fn{.txt}.
\begin{lstlisting}[
label=cd:m:ImporterGroupSubjectCON_TXT:header,
caption={
{\bf ImporterGroupSubjectCON\_TXT element header.}
The \code{header} section of the generator code in \fn{\_ImporterGroupSubjectCON\_TXT.gen.m} provides the general information about the \code{Importer} element.
}
]
%% ¡header!
ImporterGroupSubjectCON_TXT < Importer (im, importer of CON subject group from TXT) imports a group of subjects with connectivity data from a series of TXT files. ¥\circled{1}\circlednote{1}{ The element \code{ImporterGroupSubjectCON\_TXT} is defined as a subclass of \code{Importer}. The moniker will be \code{im}.}¥
%%% ¡description!
ImporterGroupSubjectCON_XLS imports a group of subjects with connectivity data from a series of XLS/XLSX files contained in a folder named "GROUP_ID". All these files must be in the same folder; also, no other files should be in the folder. Each file contains a table of values corresponding to the adjacency matrix. The variables of interest are from another XLS/XLSX file named "GROUP_ID.vois.xlsx" (if exisitng) consisting of the following columns: Subject ID (column 1), covariates (subsequent columns). The 1st row contains the headers, the 2nd row a string with the categorical variables of interest, and each subsequent row the values for each subject.
%%% ¡seealso!
Group, SunbjectCON, ExporterGroupSubjectCON_TXT
%%% ¡build!
1
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:ImporterGroupSubjectCON_TXT:prop_update,
caption={
{\bf ImporterGroupSubjectCON\_TXT element props update.}
The \code{props\_update} section of the generator code in \fn{\_ImporterGroupSubjectCON\_TXT.gen.m} updates the properties of the \code{Importer} element.
}
]
%% ¡props_update!
%%% ¡prop!
NAME (constant, string) is the name of the CON subject group importer from TXT.
%%%% ¡default!
'ImporterGroupSubjectCON_TXT'
%%% ¡prop!
DESCRIPTION (constant, string) is the description of the CON subject group importer from TXT.
%%%% ¡default!
'ImporterGroupSubjectCON_TXT imports a group of subjects with connectivity data from a series of TXT file and their covariates (optional) from another TXT file.'
%%% ¡prop!
TEMPLATE (parameter, item) is the template of the CON subject group importer from TXT.
%%%% ¡settings!
'ImporterGroupSubjectCON_TXT'
%%% ¡prop!
ID (data, string) is a few-letter code for the CON subject group importer from TXT.
%%%% ¡default!
'ImporterGroupSubjectCON_TXT ID'
%%% ¡prop!
LABEL (metadata, string) is an extended label of the CON subject group importer from TXT.
%%%% ¡default!
'ImporterGroupSubjectCON_TXT label'
%%% ¡prop!
NOTES (metadata, string) are some specific notes about the CON subject group importer from TXT.
%%%% ¡default!
'ImporterGroupSubjectCON_TXT notes'
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:ImporterGroupSubjectCON_TXT:props,
caption={
{\bf ImporterGroupSubjectCON\_TXT element props.}
The \code{props} section of the generator code in \fn{\_ImporterGroupSubjectCON\_TXT.gen.m} defines the specific properties of the \code{ImporterGroupSubjectCON\_TXT} element.
}
]
%% ¡props!
%%% ¡prop!
DIRECTORY (data, string) is the directory containing the CON subject group files from which to load the subject group.
%%%% ¡default!
fileparts(which('test_braph2'))
%%% ¡prop!
GET_DIR (query, item) opens a dialog box to set the directory from where to load the TXT files of the CON subject group.
%%%% ¡settings!
'ImporterGroupSubjectCON_TXT'
%%%% ¡calculate!
directory = uigetdir('Select directory'); ¥\circled{1}\circlednote{1}{ selects the directory that contains the TXT data.}¥
if ischar(directory) && isfolder(directory)
im.set('DIRECTORY', directory); ¥\circled{2}\circlednote{2}{ saves the directory into the \code{'DIRECTORY'} property of \code{im}.}¥
end
value = im;
%%% ¡prop!
BA (data, item) is a brain atlas.
%%%% ¡settings!
'BrainAtlas'
%%% ¡prop!
GR (result, item) is a group of subjects with connectivity data.
%%%% ¡settings!
'Group'
%%%% ¡check_value!
check = any(strcmp(value.get(Group.SUB_CLASS_TAG), subclasses('SubjectCON', [], [], true))); ¥\circled{3}\circlednote{3}{ checks that the class of subjects of the group is \code{SubjectCON}.}¥
%%%% ¡default!
Group('SUB_CLASS', 'SubjectCON', 'SUB_DICT', IndexedDictionary('IT_CLASS', 'SubjectCON')) ¥\circled{4}\circlednote{4}{ represents a group of subjects whose class is defined in the property \code{'SUB\_CLASS'}. \code{'SUB\_DICT'} manages the subjects as an indexed dictionary of subjects.}¥
%%%% ¡calculate! ¥\circled{5}\circlednote{5}{ constructs an empty \code{Group}.}¥
gr = Group( ...
'SUB_CLASS', 'SubjectCON', ...
'SUB_DICT', IndexedDictionary('IT_CLASS', 'SubjectCON') ...
);
gr.lock('SUB_CLASS'); ¥\circled{6}\circlednote{6}{ locks the property \code{'SUB\_CLASS'} irreversibly.}¥
directory = im.get('DIRECTORY'); ¥\circled{7}\circlednote{7}{ returns the data directory that has been saved at \circled{2}.}¥
if isfolder(directory) ¥\circled{8}\circlednote{8}{ checks that directory exists.}¥
wb = braph2waitbar(im.get('WAITBAR'), 0, 'Reading directory ...'); ¥\circled{9}\circlednote{9}{ creates the waitbar with an initial progress of \code{0} displaying \code{'Reading directory ...'}.}¥
[~, name] = fileparts(directory); ¥\circled{10}\circlednote{10}{ extracts the directory name from its complete path.}¥
gr.set( ... ¥\circled{11}\circlednote{11}{ sets the properties \code{'ID'}, \code{'LABEL'} and \code{'NOTES'} for the group.}¥
'ID', name, ...
'LABEL', name, ...
'NOTES', ['Group loaded from ' directory] ...
);
try
braph2waitbar(wb, .15, 'Loading subjecy group ...')
% analyzes directory
files = dir(fullfile(directory, '*.txt')); ¥\circled{12}\circlednote{12}{ finds all \fn{.txt} files in the \code{directory}.}¥
if ~isempty(files)
% brain atlas
ba = im.get('BA'); ¥\circled{13}\circlednote{13}{ returns the brain atlas.}¥
if ba.get('BR_DICT').get('LENGTH') == 0 ¥\circled{14}\circlednote{14}{ checks that the number of nodes in brain atlas is equal to 0.}¥
br_number = size(readtable(fullfile(directory, files(1).name), 'Delimiter', '\t'), 1); ¥\circled{15}\circlednote{15}{ adds the number of regions of the first file to the brain atlas.}¥
br_dict = ba.memorize('BR_DICT');
for j = 1:1:br_number
br_dict.get('ADD', BrainRegion('ID', ['br' int2str(j)])) ¥\circled{16}\circlednote{16}{ adds the \code{'ID'} of each brain region.}¥
end
end
% adds subjects
sub_dict = gr.memorize('SUB_DICT'); ¥\circled{17}\circlednote{17}{ adds the subject to the group.}¥
for i = 1:1:length(files)
braph2waitbar(wb, .15 + .85 * i / length(files), ['Loading subject ' num2str(i) ' of ' num2str(length(files)) ' ...']) ¥\circled{18}\circlednote{18}{ updates the waitbar for each file.}¥
% read file
[~, sub_id] = fileparts(files(i).name);
CON = table2array(readtable(fullfile(directory, files(i).name), 'Delimiter', '\t')); ¥\circled{19}\circlednote{19}{ reads each file with a delimiter specified in \code{Delimiter}.}¥
if size(CON, 1) ~= ba.get('BR_DICT').get('LENGTH') || size(CON, 2) ~= ba.get('BR_DICT').get('LENGTH') ¥\circled{20}\circlednote{20}{ checks that the number of the nodes in the file is equal to the number of nodes in the brain atlas.}¥
error( ...
[BRAPH2.STR ':' class(im) ':' BRAPH2.ERR_IO], ...
[BRAPH2.STR ':' class(im) ':' BRAPH2.ERR_IO '\\n' ...
'The file ' sub_id ' should contain a matrix ' int2str(ba.get('BR_DICT').get('LENGTH')) 'x' int2str(ba.get('BR_DICT').get('LENGTH')) ', ' ...
'while it is ' int2str(size(CON, 1)) 'x' int2str(size(CON, 2)) '.'] ...
)¥\circled{21}\circlednote{21}{ outputs the error information.}¥
end
sub = SubjectCON( ...
'ID', sub_id, ...
'BA', ba, ...
'CON', CON ...
);
sub_dict.get('ADD', sub);
end
% variables of interest
if isfile([directory '.vois.txt']) ¥\circled{22}\circlednote{22}{ adds the variables of interest (\code{vois}).}¥
vois = textread([directory '.vois.txt'], '%s', 'delimiter', '\t', 'whitespace', ''); ¥\circled{23}\circlednote{23}{ reads the file \code{*.vois.txt}.}¥
vois = reshape(vois, find(strcmp('', vois), 1) - 1, [])'; ¥\circled{24}\circlednote{24}{ reshapes the \code{vois}.}¥
for i = 3:1:size(vois, 1)
sub_id = vois{i, 1};
sub = sub_dict.get('IT', sub_id);
for v = 2:1:size(vois, 2)
voi_id = vois{1, v};
if isempty(vois{2, v}) ¥\circled{25}\circlednote{25}{ checks whether the variable is is numeric.}¥
sub.memorize('VOI_DICT').get('ADD', ...
VOINumeric( ...
'ID', voi_id, ...
'V', str2num(vois{i, v}) ...
) ...
); ¥\circled{26}\circlednote{26}{ adds the variable of interest with \code{'ID'} and value \code{'V'}.}¥
elseif ~isempty(vois{2, v}) ¥\circled{27}\circlednote{27}{ checks whether the variable is categorical.}¥
categories = eval(vois{2, v});
sub.memorize('VOI_DICT').get('ADD', ...
VOICategoric( ...
'ID', voi_id, ...
'CATEGORIES', str2cell(categories), ...
'V', find(strcmp(vois{i, v}, categories)) ...
) ...
);
end
end
end
end
end
catch e
braph2waitbar(wb, 'close')
rethrow(e)
end
braph2waitbar(wb, 'close') ¥\circled{28}\circlednote{28}{ closes the waitbar.}¥
else
error([BRAPH2.STR ':ImporterGroupSubjectCON_TXT:' BRAPH2.ERR_IO], ...
[BRAPH2.STR ':ImporterGroupSubjectCON_TXT:' BRAPH2.ERR_IO '\\n' ...
'The prop DIRECTORY must be an existing directory, but it is ''' directory '''.'] ...
);
end
value = gr;
\end{lstlisting}
\begin{lstlisting}[ label=cd:m:ImporterGroupSubjectCON_TXT:tests,
caption={
{\bf ImporterGroupSubjectCON\_TXT element tests.}
The \code{tests} section from the element generator \fn{\_ImporterGroupSubjectCON\_TXT.gen.m}. In this section, some example data are created for testing.
}
]
%% ¡tests!
%%% ¡excluded_props! ¥\circled{1}\circlednote{1}{ List of properties that are excluded from testing.}¥
[ImporterGroupSubjectCON_TXT.GET_DIR]
%%% ¡test!
%%%% ¡name!
Create example files ¥\circled{2}\circlednote{2}{ creates the example files.}¥
%%%% ¡code!
data_dir = [fileparts(which('SubjectCON')) filesep 'Example data CON TXT']; ¥\circled{3}\circlednote{3}{ defines the directory \code{'Example data CON TXT'} where the example data will be contained.}¥
if ~isdir(data_dir)
mkdir(data_dir); ¥\circled{4}\circlednote{4}{ creates the directory for the example data.}¥
% Brain Atlas
im_ba = ImporterBrainAtlasTXT('FILE', 'desikan_atlas.txt'); ¥\circled{5}\circlednote{5}{ imports the brain atlas.}¥
ba = im_ba.get('BA');
ex_ba = ExporterBrainAtlasTXT( ... ¥\circled{6}\circlednote{6}{ exports the brain atlas as file 'atlas.txt'.}¥
'BA', ba, ...
'FILE', [data_dir filesep() 'atlas.txt'] ...
);
ex_ba.get('SAVE')
N = ba.get('BR_DICT').get('LENGTH'); ¥\circled{7}\circlednote{7}{ returns the number of brain regions.}¥
% saves RNG
rng_settings_ = rng(); rng('default') ¥\circled{8}\circlednote{8}{ sets the random number generator (\code{rng}) to \code{'default'}.}¥
sex_options = {'Female' 'Male'};
% Group 1 ¥\circled{9}\circlednote{9}{ generates the data for group1.}¥
K1 = 2; ¥\circled{10}\circlednote{10}{ assigns the degree (mean node degree is 2) for group 1.}¥
beta1 = 0.3; ¥\circled{11}\circlednote{11}{ assigns the rewiring probability for group 1.}¥
gr1_name = 'CON_Group_1_TXT';
gr1_dir = [data_dir filesep() gr1_name];
mkdir(gr1_dir);
vois1 = [ ¥\circled{12}\circlednote{12}{ assigns the header with \code{'Subject ID'}, \code{'Age'}, and \code{'Sex'}.}¥
{{'Subject ID'} {'Age'} {'Sex'}}
{{} {} {['{' sprintf(' ''%s'' ', sex_options{:}) '}']}}
];
for i = 1:1:50 % subject number ¥\circled{13}\circlednote{13}{ generates 50 subjects.}¥
sub_id = ['SubjectCON_MP_' num2str(i)];
h1 = WattsStrogatz(N, K1, beta1); ¥\circled{14}\circlednote{14}{ creates a Watts-Strogatz graph.}¥
A1 = full(adjacency(h1)); A1(1:length(A1)+1:numel(A1)) = 0; ¥\circled{15}\circlednote{15}{ extracts the adjacency matrix.}¥
r = 0 + (0.5 - 0)*rand(size(A1)); diffA = A1 - r; A1(A1 ~= 0) = diffA(A1 ~= 0); ¥\circled{16}\circlednote{16}{ makes the adjacency matrix weighted.}¥
A1 = max(A1, transpose(A1)); ¥\circled{17}\circlednote{17}{ makes the adjacency matrix symmetric.}¥
writetable(array2table(A1), [gr1_dir filesep() sub_id '.txt'], 'Delimiter', '\t', 'WriteVariableNames', false) ¥\circled{18}\circlednote{18}{ writes the matrix into the file.}¥
vois1 = [vois1; {sub_id, randi(90), sex_options(randi(2))}]; ¥\circled{19}\circlednote{19}{ creates the variables of interest.}¥
end
writetable(table(vois1), [data_dir filesep() gr1_name '.vois.txt'], 'Delimiter', '\t', 'WriteVariableNames', false) ¥\circled{20}\circlednote{20}{ writes the variables of interest.}¥
% Group 2 ¥\circled{21}\circlednote{21}{ generates the data for group 2.}¥
K2 = 2;
beta2 = 0.85;
gr2_name = 'CON_Group_2_TXT';
gr2_dir = [data_dir filesep() gr2_name];
mkdir(gr2_dir);
vois2 = [
{{'Subject ID'} {'Age'} {'Sex'}}
{{} {} {['{' sprintf(' ''%s'' ', sex_options{:}) '}']}}
];
for i = 51:1:100
sub_id = ['SubjectCON_MP_' num2str(i)];
h2 = WattsStrogatz(N, K2, beta2);
A2 = full(adjacency(h2)); A2(1:length(A2)+1:numel(A2)) = 0;
r = 0 + (0.5 - 0)*rand(size(A2)); diffA = A2 - r; A2(A2 ~= 0) = diffA(A2 ~= 0);
A2 = max(A2, transpose(A2));
writetable(array2table(A2), [gr2_dir filesep() 'SubjectCON_' num2str(i) '.txt'], 'Delimiter', '\t', 'WriteVariableNames', false)
% variables of interest
vois2 = [vois2; {sub_id, randi(90), sex_options(randi(2))}];
end
writetable(table(vois2), [data_dir filesep() gr2_name '.vois.txt'], 'Delimiter', '\t', 'WriteVariableNames', false)
% reset RNG
rng(rng_settings_) ¥\circled{22}\circlednote{22}{ resets random number generator.}¥
end
%%% ¡test_functions!
function h = WattsStrogatz(N,K,beta) ¥\circled{23}\circlednote{23}{ defines a function named \code{WattsStrogatz} that takes three input arguments: \code{N} (number of nodes), \code{K} (number of neighbors for each node), and \code{beta} (rewiring probability).}¥
% H = WattsStrogatz(N,K,beta) returns a Watts-Strogatz model graph with N
% nodes, N*K edges, mean node degree 2*K, and rewiring probability beta.
%
% beta = 0 is a ring lattice, and beta = 1 is a random graph.
% Connect each node to its K next and previous neighbors. This constructs
% indices for a ring lattice.
s = repelem((1:N)',1,K); ¥\circled{24}\circlednote{24}{ creates a matrix \code{s} where each row corresponds to a node, and each column contains the node's number repeated K times.}¥
t = s + repmat(1:K,N,1); ¥\circled{25}\circlednote{25}{ calculates the target nodes for each node in the ring lattice.}¥
t = mod(t-1,N)+1; ¥\circled{26}\circlednote{26}{ ensures that the indices wrap around, creating a circular lattice.}¥
for source=1:N ¥\circled{27}\circlednote{27}{ rewires the target node of each edge with probability \code{beta}.}¥
switchEdge = rand(K, 1) < beta; ¥\circled{28}\circlednote{28}{ determines which edges should be rewired based on the probability \code{beta}.}¥
newTargets = rand(N, 1); ¥\circled{29}\circlednote{29}{ to \circled{30} determines the new target nodes for the edges that are being rewired, ensuring that the new target is not the source node itself or any of its current neighbors.}¥
newTargets(source) = 0;
newTargets(s(t==source)) = 0;
newTargets(t(source, ~switchEdge)) = 0;
[~, ind] = sort(newTargets, 'descend');
t(source, switchEdge) = ind(1:nnz(switchEdge)); ¥\circled{30}¥
end
h = graph(s,t); ¥\circled{31}\circlednote{31}{ creates a graph \code{h} from the source nodes \code{s} and target nodes \code{t}.}¥
end
%%% ¡test!
%%%% ¡name!
GUI
%%%% ¡probability!
.01
%%%% ¡code!
im_ba = ImporterBrainAtlasTXT('FILE', [fileparts(which('SubjectCON')) filesep 'Example data CON TXT' filesep 'atlas.txt']);
ba = im_ba.get('BA');
im_gr = ImporterGroupSubjectCON_TXT( ... ¥\circled{32}\circlednote{32}{ imports the txt file of each subject in the group.}¥
'DIRECTORY', [fileparts(which('SubjectCON')) filesep 'Example data CON TXT' filesep 'CON_Group_1_TXT'], ...
'BA', ba, ...
'WAITBAR', true ...
);
gr = im_gr.get('GR'); ¥\circled{33}\circlednote{33}{ returns a group of subjects with connectivity data.}¥
gui = GUIElement('PE', gr, 'CLOSEREQ', false); ¥\circled{34}\circlednote{34}{ assigns the panel element without requiring close confirmation.}¥
gui.get('DRAW')
gui.get('SHOW')
gui.get('CLOSE')
\end{lstlisting}
\clearpage
\subsection{Importer from XLS/XLSX (\code{ImporterGroupSubjectCON\_XLS})}
You will now see how to implement in detail \code{ImporterGroupSubjectCON\_XLS} modifying \code{ImporterGroupSubjectCON\_TXT}. The data should be stored in the folders \fn{Group1} and \fn{Group2}, and the file format is \fn{.xls} or \fn{.xlsx}.
\begin{lstlisting}[
label=cd:m:ImporterGroupSubjectCON_XLS:header,
caption={
{\bf ImporterGroupSubjectCON\_XLS element header.}
The \code{header} section of the generator code in \fn{\_ImporterGroupSubjectCON\_XLS.gen.m} provides the general information about the \code{Importer} element. \expand{cd:m:ImporterGroupSubjectCON_TXT:header}
}
]
¤%% ¡header!
¤ImporterGroupSubjectCON_XLS¤ < Importer (im, ¤importer of CON subject group from XLS/XLSX) imports a group of subjects with connectivity data from a series of XLS/XLSX file.¤
%%% ¡description!
¤ImporterGroupSubjectCON_XLS imports a group of subjects with connectivity data from a series of XLS/XLSX files contained in a folder named "GROUP_ID". All these files must be in the same folder; also, no other files should be in the folder. Each file contains a table of values corresponding to the adjacency matrix. The variables of interest are from another XLS/XLSX file named "GROUP_ID.vois.xlsx" (if exisitng) consisting of the following columns: Subject ID (column 1), covariates (subsequent columns). The 1st row contains the headers, the 2nd row a string with the categorical variables of interest, and each subsequent row the values for each subject.¤
%%% ¡seealso!
Group, SubjectCON, ¤ExporterGroupSubjectCON_XLS¤
%%% ¡build!
¤1
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:ImporterGroupSubjectCON_XLS:prop_update,
caption={
{\bf ImporterGroupSubjectCON\_XLS element props update.}
The \code{props\_update} section of the generator code in \fn{\_ImporterGroupSubjectCON\_XLS.gen.m} updates the properties of the \code{Importer} element. \expand{cd:m:ImporterGroupSubjectCON_TXT:prop_update}
}
]
¤%% ¡props_update!
%%% ¡prop!
NAME (constant, string) is the name of the CON subject group importer from ¤XLS/XLSX¤.
%%%% ¡default!
¤'ImporterGroupSubjectCON_XLS'¤
%%% ¡prop!
DESCRIPTION (constant, string) is the description of the CON subject group importer from ¤XLS/XLSX¤.
%%%% ¡default!
¤'ImporterGroupSubjectCON_XLS imports a group of subjects with connectivity data from a series of XLS/XLSX file. The variables of interest can be loaded from another XLS/XLSX file.'¤
%%% ¡prop!
TEMPLATE (parameter, item) is the template of the CON subject group importer from ¤XLS/XLSX¤.
%%%% ¡settings!
¤'ImporterGroupSubjectCON_XLS'¤
%%% ¡prop!
ID (data, string) is a few-letter code for the CON subject group importer from ¤XLS/XLSX¤.
%%%% ¡default!
¤'ImporterGroupSubjectCON_XLS ID'¤
%%% ¡prop!
LABEL (metadata, string) is an extended label of the CON subject group importer from ¤XLS/XLSX¤.
%%%% ¡default!
¤'ImporterGroupSubjectCON_XLS label'¤
%%% ¡prop!
NOTES (metadata, string) are some specific notes about the CON subject group importer from ¤XLS/XLSX¤.
%%%% ¡default!
¤'ImporterGroupSubjectCON_XLS notes'
\end{lstlisting}
\begin{lstlisting}[
label=cd:m:ImporterGroupSubjectCON_XLS:props,
caption={
{\bf ImporterGroupSubjectCON\_XLS element props.}
The \code{props} section of the generator code in \fn{\_ImporterGroupSubjectCON\_XLS.gen.m} defined the properties specific for \code{ImporterGroupSubjectCON\_XLS}. \expand{cd:m:ImporterGroupSubjectCON_TXT:prop_update}
}
]
¤%% ¡props!
%%% ¡prop!
DIRECTORY (data, string) is the directory containing the CON subject group files from which to load the subject group.
%%%% ¡default!
fileparts(which('test_braph2'))
%%% ¡prop!
GET_DIR (query, item) opens a dialog box to set the directory from where to load the ¤XLS/XLSX¤ files of the CON subject group.
%%%% ¡settings!
¤'ImporterGroupSubjectCON_XLS'¤
%%%% ¡calculate!
directory = uigetdir('Select directory');
if ischar(directory) && isfolder(directory)
im.set('DIRECTORY', directory);
end
value = im;
%%% ¡prop!
BA (data, item) is a brain atlas.
%%%% ¡settings!
'BrainAtlas'
%%% ¡prop!
GR (result, item) is a group of subjects with connectivity data.
%%%% ¡settings!
'Group'
%%%% ¡check_value!
check = any(strcmp(value.get(Group.SUB_CLASS_TAG), subclasses('SubjectCON', [], [], true))); ¥\circled{1}\circlednote{1}{ Same as in note \circled{3} of \Coderef{cd:m:ImporterGroupSubjectCON_TXT:prop_update}.}¥
%%%% ¡default!
Group('SUB_CLASS', 'SubjectCON', 'SUB_DICT', IndexedDictionary('IT_CLASS', 'SubjectCON')) ¥\circled{2}\circlednote{2}{ Same as in note \circled{4} of \Coderef{cd:m:ImporterGroupSubjectCON_TXT:prop_update}.}¥
%%%% ¡calculate! ¥\circled{3}\circlednote{3}{ Same as in note \circled{5} to \circled{28} in \Coderef{cd:m:ImporterGroupSubjectCON_TXT:prop_update}.}¥
gr = Group( ...
'SUB_CLASS', 'SubjectCON', ...
'SUB_DICT', IndexedDictionary('IT_CLASS', 'SubjectCON') ...
);
gr.lock('SUB_CLASS');
directory = im.get('DIRECTORY');
if isfolder(directory)
wb = braph2waitbar(im.get('WAITBAR'), 0, 'Reading directory ...');
[~, gr_name] = fileparts(directory);
gr.set( ...
'ID', gr_name, ...
'LABEL', gr_name, ...
'NOTES', ['Group loaded from ' directory] ...
);
try
braph2waitbar(wb, .15, 'Loading subject group ...')
% analyzes directory
files = [dir(fullfile(directory, ¤'*.xlsx'¤)); dir(fullfile(directory, ¤'*.xls'¤))];
if ~isempty(files)
% brain atlas
ba = im.get('BA');
if ba.get('BR_DICT').get('LENGTH') == 0
br_number = size(¤xlsread(fullfile(directory, files(1).name))¤, 1);
br_dict = ba.memorize('BR_DICT');
for j = 1:1:br_number
br_dict.get('ADD', BrainRegion('ID', ['br' int2str(j)]))
end
end
% adds subjects
sub_dict = gr.memorize('SUB_DICT');
for i = 1:1:length(files)
braph2waitbar(wb, .15 + .85 * i / length(files), ['Loading subject ' num2str(i) ' of ' num2str(length(files)) ' ...'])
% read file
[~, sub_id] = fileparts(files(i).name);
¤CON = xlsread(fullfile(directory, files(i).name));¤
if size(CON, 1) ~= ba.get('BR_DICT').get('LENGTH') || size(CON, 2) ~= ba.get('BR_DICT').get('LENGTH')
error( ...
[BRAPH2.STR ':' class(im) ':' BRAPH2.ERR_IO], ...
[BRAPH2.STR ':' class(im) ':' BRAPH2.ERR_IO '\\n' ...
'The file ' sub_id ' should contain a matrix ' int2str(ba.get('BR_DICT').get('LENGTH')) 'x' int2str(ba.get('BR_DICT').get('LENGTH')) ', ' ...
'while it is ' int2str(size(CON, 1)) 'x' int2str(size(CON, 2)) '.'] ...
)
end
sub = SubjectCON( ...
'ID', sub_id, ...
'BA', ba, ...
'CON', CON ...
);
sub_dict.get('ADD', sub);
end
% variables of interest
¤vois = [];
if isfile([directory '.vois.xls'])
[~, ~, vois] = xlsread([directory '.vois.xls']);
elseif isfile([directory '.vois.xlsx'])
[~, ~, vois] = xlsread([directory '.vois.xlsx']);
end
if ~isempty(vois)¤
for i = 3:1:size(vois, 1)
sub_id = vois{i, 1};
sub = sub_dict.get('IT', sub_id);
for v = 2:1:size(vois, 2)
voi_id = vois{1, v};
if isnumeric(vois{2, v}) % VOINumeric
sub.memorize('VOI_DICT').get('ADD', ...
VOINumeric( ...
'ID', voi_id, ...
'V', vois{i, v} ...
) ...
);
elseif ischar(vois{2, v}) % VOICategoric
sub.memorize('VOI_DICT').get('ADD', ...
VOICategoric( ...
'ID', voi_id, ...
'CATEGORIES', str2cell(vois{2, v}), ...
'V', find(strcmp(vois{i, v}, str2cell(vois{2, v}))) ...
) ...
);
end
end
end
end
end
catch e
braph2waitbar(wb, 'close')
rethrow(e)
end
braph2waitbar(wb, 'close')
else
error([BRAPH2.STR ':¤ImporterGroupSubjectCON_XLS¤:' BRAPH2.ERR_IO], ...
[BRAPH2.STR ':¤ImporterGroupSubjectCON_XLS¤:' BRAPH2.ERR_IO '\\n' ...
'The prop DIRECTORY must be an existing directory, but it is ''' directory '''.'] ...
);
end
value = gr;
\end{lstlisting}
\clearpage
\begin{lstlisting}[ label=cd:m:ImporterGroupSubjectCON_XLS:tests,
caption={
{\bf ImporterGroupSubjectCON\_XLS element tests.}
The \code{tests} section from the element generator \fn{\_ImporterGroupSubjectCON\_XLS.gen.m}. \expand{cd:m:ImporterGroupSubjectCON_TXT:tests}
}
]
¤%% ¡tests!
%%% ¡excluded_props!
¤[ImporterGroupSubjectCON_XLS.GET_DIR]¤
%%% ¡test!
%%%% ¡name!
Create example files
%%%% ¡code!
¤data_dir = [fileparts(which('SubjectCON')) filesep 'Example data CON XLS'];¤
if ~isdir(data_dir)
mkdir(data_dir);
% Brain Atlas
im_ba = ImporterBrainAtlasXLS('FILE', 'desikan_atlas.xlsx');
ba = im_ba.get('BA');
ex_ba = ExporterBrainAtlasXLS( ...
'BA', ba, ...
'FILE', [data_dir filesep() 'atlas.xlsx'] ...
);
ex_ba.get('SAVE')
N = ba.get('BR_DICT').get('LENGTH');
% saves RNG
rng_settings_ = rng(); rng('default')
sex_options = {'Female' 'Male'};
% Group 1
K1 = 2;
beta1 = 0.3;
gr1_name = ¤'CON_Group_1_XLS'¤;
gr1_dir = [data_dir filesep() gr1_name];
mkdir(gr1_dir);
vois1 = [
{{'Subject ID'} {'Age'} {'Sex'}}
{{} {} cell2str(sex_options)}
];
for i = 1:1:50 % subject number
sub_id = ['SubjectCON_' num2str(i)];
h1 = WattsStrogatz(N, K1, beta1); % create two WS graph
A1 = full(adjacency(h1)); A1(1:length(A1)+1:numel(A1)) = 0;
r = 0 + (0.5 - 0)*rand(size(A1)); diffA = A1 - r; A1(A1 ~= 0) = diffA(A1 ~= 0);
A1 = max(A1, transpose(A1)); % make the adjacency matrix symmetric
writetable(array2table(A1), [gr1_dir filesep() sub_id ¤'.xlsx'¤], 'WriteVariableNames', false)
vois1 = [vois1; {sub_id, randi(90), sex_options(randi(2))}];
end
writetable(table(vois1), [data_dir filesep() gr1_name ¤'.vois.xlsx'¤], 'WriteVariableNames', false)
% Group 2
K2 = 2;
beta2 = 0.85;
gr2_name = ¤'CON_Group_2_XLS'¤;
gr2_dir = [data_dir filesep() gr2_name];
mkdir(gr2_dir);
vois2 = [
{{'Subject ID'} {'Age'} {'Sex'}}
{{} {} cell2str(sex_options)}
];
for i = 51:1:100
sub_id = ['SubjectCON_' num2str(i)];
h2 = WattsStrogatz(N, K2, beta2);
% figure(2)
% plot(h2, 'NodeColor',[1 0 0], 'EdgeColor',[0 0 0], 'EdgeAlpha',0.1, 'Layout','circle');
% title(['Group 2: Graph with $N = $ ' num2str(N_nodes) ...
% ' nodes, $K = $ ' num2str(K2) ', and $\beta = $ ' num2str(beta2)], ...
% 'Interpreter','latex')
% axis equal
A2 = full(adjacency(h2)); A2(1:length(A2)+1:numel(A2)) = 0;
r = 0 + (0.5 - 0)*rand(size(A2)); diffA = A2 - r; A2(A2 ~= 0) = diffA(A2 ~= 0);
A2 = max(A2, transpose(A2));
writetable(array2table(A2), [gr2_dir filesep() sub_id ¤'.xlsx'¤], 'WriteVariableNames', false)
% variables of interest
vois2 = [vois2; {sub_id, randi(90), sex_options(randi(2))}];
end
writetable(table(vois2), [data_dir filesep() gr2_name ¤'.vois.xlsx'¤], 'WriteVariableNames', false)
% reset RNG
rng(rng_settings_)
end
%%% ¡test_functions!
function h = WattsStrogatz(N,K,beta)
% H = WattsStrogatz(N,K,beta) returns a Watts-Strogatz model graph with N
% nodes, N*K edges, mean node degree 2*K, and rewiring probability beta.
%
% beta = 0 is a ring lattice, and beta = 1 is a random graph.
% Connect each node to its K next and previous neighbors. This constructs
% indices for a ring lattice.
s = repelem((1:N)',1,K);
t = s + repmat(1:K,N,1);