-
Notifications
You must be signed in to change notification settings - Fork 5
/
cat_conf_tools.m
4755 lines (4233 loc) · 204 KB
/
cat_conf_tools.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 tools = cat_conf_tools(expert)
% wrapper for calling CAT utilities
%
% tools = cat_conf_tools(expert)
% ______________________________________________________________________
%
% Christian Gaser, Robert Dahnke
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$
if ~exist('expert','var'), expert = 1; end
% multi use fields
% -----------------------------------------------------------------------
% just used once
data_xml = cfg_files;
data_xml.name = 'Quality measures';
data_xml.tag = 'data_xml';
data_xml.filter = 'xml';
data_xml.ufilter = '^cat_.*\.xml$';
data_xml.val = {{''}};
data_xml.num = [0 Inf];
data_xml.help = {
'Select the quality measures that are saved during segmentation as xml-files in the report folder.'
'Please note, that the order of the xml-files should be the same as the other data files.'
};
outdir = cfg_files;
outdir.tag = 'outdir';
outdir.name = 'Output directory';
outdir.filter = 'dir';
outdir.ufilter = '.*';
outdir.num = [0 1];
outdir.help = {'Select a directory where files are written.'};
outdir.val{1} = {''};
subdir = cfg_entry;
subdir.tag = 'subdir';
subdir.name = 'Additional output directory';
subdir.strtype = 's';
subdir.num = [0 Inf];
subdir.val = {'EVA_volmod'};
subdir.help = {
'The directory is created within the choosen output directory. If no name is given no subdirecty is created. ' ''};
data = cfg_files;
data.tag = 'data';
data.name = 'Volumes';
data.filter = 'image';
data.ufilter = '.*';
data.num = [1 Inf];
data.help = {''};
% Do not process, if result already exists and is younger than the
% original image, i.e., if the original was changed then it will be
% processed again. The function is quite helpful to develop and test
% SPM batches and avoid reprocessing of slow steps.
lazy = cfg_menu;
lazy.tag = 'lazy';
lazy.name = 'Lazy processing';
lazy.labels = {'Yes','No'};
lazy.values = {1,0};
lazy.val = {0};
lazy.help = {
'Do not process data if the result already exists. '
};
% CHECK USE
data_vol = cfg_files;
data_vol.name = 'Sample data';
data_vol.tag = 'data_vol';
data_vol.filter = 'image';
data_vol.num = [1 Inf];
data_vol.help = {'These are the (spatially registered) data. They must all have the same image dimensions, orientation, voxel size etc. Furthermore, it is recommended to use unsmoothed files.'};
% also this is a separate function that is used for the results
spm_type = cfg_menu; %
spm_type.tag = 'spm_type';
spm_type.name = 'Data type of the output images';
spm_type.labels = {'same','uint8','int8','uint16','int16','single'};
spm_type.values = {0 2 256 512 4 16};
spm_type.val = {16};
spm_type.help = {
'SPM data type of the output image. Single precision is recommended, but uint16 also provides good results. Internal scaling supports a relative high accuracy for the limited number of bits, special values such as NAN and INF (e.g. in the background) will be lost and NAN is converted to 0, -INF to the minimum, and INF to the maximum value. '
''
};
% also this limit is a separate function that is used for the noise filter
% and therefore included here
intlim = cfg_entry;
intlim.tag = 'intlim';
intlim.name = 'Global intensity limitation';
intlim.strtype = 'r';
intlim.num = [1 inf];
intlim.val = {100};
intlim.help = {
'General intensity limitation to remove strong outliers by using 100% of the original histogram values. '
'You can also specify the lower and upper boundary seperatlym, e.g. [80 99], what will keep only 80% of the (many) low (background values) but 99% of the (rew) high intensity (skull) values. '
''
};
prefix = cfg_entry;
prefix.tag = 'prefix';
prefix.name = 'Filename prefix';
prefix.strtype = 's';
prefix.num = [0 Inf];
prefix.val = {''};
prefix.help = {''};
suffix = cfg_entry;
suffix.tag = 'suffix';
suffix.name = 'Filename suffix';
suffix.strtype = 's';
suffix.num = [0 Inf];
suffix.val = {''};
suffix.help = {''};
fname = prefix;
fname.name = 'Filename';
fname.tag = 'fname';
fname.val = {'CATcheckdesign_'};
fname.help = {'Basic filename to save figures.'};
save = cfg_menu;
save.name = 'Save & close windows';
save.tag = 'save';
save.labels = {'Save & close','Save only','No'};
save.values = {2,1,0};
save.val = {0};
save.help = {'Save and close figures for batch processing.'};
verb = cfg_menu;
verb.tag = 'verb';
verb.name = 'Verbose output';
verb.labels = {'No' 'Yes' 'Yes (Details)'};
verb.values = {0 1 2};
verb.val = {1};
verb.hidden = expert<1;
verb.help = {
'Be more or less verbose. '
''
};
globals = cfg_menu;
globals.tag = 'globals';
globals.name = 'Global scaling with TIV';
globals.labels = {'Yes', 'No'};
globals.values = {1 0};
globals.val = {0};
globals.help = {
'This option is to correct mean Z-scores for TIV by global scaling. It is only meaningful for VBM data.'
''
};
% get subbatches
% -------------------------------------------------------------------------
[T2x,T2x_surf,F2x,F2x_surf] = conf_T2x;
[check_cov_old, check_cov] = conf_check_cov(data_xml,outdir,fname,save,globals,expert);
quality_measures = conf_quality_measures(globals);
[defs,defs2] = conf_vol_defs;
nonlin_coreg = cat_conf_nonlin_coreg;
createTPM = conf_createTPM(data_vol,expert,suffix,outdir);
createTPMlong = conf_createTPMlong(data_vol,expert);
long_report = conf_long_report(data_vol,data_xml,expert);
headtrimming = conf_vol_headtrimming(intlim,spm_type,prefix,suffix,verb,lazy,expert);
check_SPM = conf_stat_check_SPM(outdir,fname,save,expert);
showslice = conf_stat_showslice_all(data_vol);
maskimg = conf_vol_maskimage(data,prefix);
calcvol = conf_stat_TIV;
spmtype = conf_io_volctype(data,intlim,spm_type,prefix,suffix,verb,expert,lazy);
calcroi = conf_roi_fun(outdir);
[~,~,ROIsum] = cat_conf_ROI(expert);
resize = conf_vol_resize(data,prefix,expert,outdir);
avg_img = conf_vol_average(data,outdir);
realign = conf_vol_series_align(data);
shootlong = conf_shoot(expert);
[sanlm,sanlm2] = conf_vol_sanlm(data,intlim,spm_type,prefix,suffix,lazy,expert);
biascorrlong = conf_longBiasCorr(data,expert,prefix);
data2mat = conf_io_data2mat(data,outdir);
boxplot = conf_io_boxplot(outdir,subdir,prefix,expert);
[getCSVXML,getXML,getCSV] = cat_cfg_getCSVXML(outdir,expert);
xml2csv = conf_io_xml2csv(outdir);
file_move = conf_io_file_move;
mp2rage = conf_vol_mp2rage(prefix,verb,expert);
%urqio = conf_vol_urqio; % this cause problems
iqr = conf_stat_IQR(data_xml);
qa = conf_vol_qa(expert,outdir);
catreport = conf_main_report(data_xml,outdir,expert);
multi_subject_imcalc = conf_vol_imcalc(prefix,expert);
% create main batch
% -------------------------------------------------------------------------
tools = cfg_choice;
tools.name = 'Tools';
tools.tag = 'tools';
tools.values = { ...
showslice, ... cat.stat.pre
check_cov, ... cat.stat.pre
check_cov_old, ... cat.stat.pre
quality_measures, ... cat.stat.pre
qa, ... cat.stat.pre
check_SPM, ... cat.stat.pre
...
calcvol, ... cat.stat.pre
calcroi, ... cat.stat.pre
ROIsum, ...
iqr, ... cat.stat.pre
...
T2x, F2x, T2x_surf, F2x_surf, ... cat.stat.models?
...
... SPLIT THIS FILE ?!
...
sanlm, ... cat.pre.vtools.
sanlm2, ...
maskimg, ... cat.pre.vtools.
spmtype, ... cat.pre.vtools.
headtrimming, ... cat.pre.vtools.
resize, ... cat.pre.vtools.
multi_subject_imcalc, ... cat.pre.vtools.
mp2rage, ...
...
realign, ... cat.pre.long.? % hidden
shootlong,... cat.pre.long.? % hidden
biascorrlong,... cat.pre.long.? % hidden
createTPMlong, ... cat.pre.long.createTPM % hidden
long_report, ... cat.pre.long.report % hidden
...
createTPM, ...
nonlin_coreg, ... cat.pre.vtools.
defs, ... cat.pre.vtools.
defs2, ... cat.pre.vtools.
avg_img, ... cat.pre.vtoolsexp.
data2mat, ... cat.pre.vtools.
...
catreport, ...
boxplot, ... cat.stat.eval ... print of XML data by the boxplot function and saving as images
getCSVXML, ... cat.stat.eval ... read out of XML/CSV data and export as batch dependency
xml2csv, ...
getXML, ...
getCSV, ...
file_move, ...
...
};
%RD202005: the cause problems at Christians installation ... check it
%if expert
% tools.values = [tools.values,{urqio}];
%end
return
%_______________________________________________________________________
function mp2rage = conf_vol_mp2rage(prefix,verb,expert)
% conf_vol_mp2rage. Batch for cat_vol_mp2rage to optimize MP2Rage images.
data = cfg_files;
data.tag = 'files';
data.name = 'Volumes';
data.filter = {'image'};
data.ufilter = '.*';
data.num = [1 Inf];
data.help = {'Select images. '};
spmseg = cfg_menu;
spmseg.tag = 'spmseg';
spmseg.name = 'SPM Preprocessing';
spmseg.labels = {'Yes (allways, with cleanup)'; 'Yes (only if required, no cleanup)'};
spmseg.values = {1 2};
spmseg.help = {'Run SPM Unified Segmentation if required and delete or keep the temporary results (e.g., to rerun this batch with other options). ' ''};
spmseg.val = {1};
spmseg.hidden = expert<1;
trimming = cfg_menu;
trimming.tag = 'headtrimming';
trimming.name = 'Crop image';
if expert > 1 % developer
trimming.labels = {'No'; 'Yes (brain)';'Yes (head)'};
trimming.values = {0 1 2};
else
trimming.labels = {'No';'Yes'};
trimming.values = {0 1};
end
trimming.val = {1};
trimming.hidden = expert<2; % ONLY DEVELOPER, NOT WORKING YET
trimming.help = {'Remove noise around the head to save disk space and fasten processing. ' ''};
bias = cfg_menu;
bias.tag = 'biascorrection';
bias.name = 'Additional bias corretion';
if expert > 1
bias.labels = {'No'; 'Yes (simple)'; 'Yes (complex)'};
bias.values = {0 1 2};
bias.help = {'Additional bias correction based on the values extracted from the SPM segmentation of the WM (simple) or all brain tissue segments (complex). Check the reports to identify problematic cases. ' ''};
else
bias.labels = {'No'; 'Yes'};
bias.values = {0 1};
bias.help = {'Additional bias correction. ' ''};
end
bias.val = {1};
%bias.hidden = expert<1;
logscale = cfg_menu;
logscale.tag = 'log';
logscale.name = 'Log/exp-based intensity transformation';
logscale.help = {'Use log/exp scaling for more equally distributed tissues. The default ("auto") select a function that support the most balanced tissue peaks.' ''};
logscale.labels = {'No';'Exp';'Log';'Auto'};
logscale.values = {0,-1,1,inf};
logscale.val = {inf};
logscale.hidden = expert<1;
intnorm = cfg_menu;
intnorm.tag = 'intnorm';
intnorm.name = 'Contrast transformation';
intnorm.help = {'Contrast normalization using the tangens function of GM normed values. This results in a compression of the GM values, whereas the outer CSF and WM values keep there intensities. ' ''};
if expert > 1
intnorm.labels = {'No (0)';'Light (-0.25)'; 'Standard (-0.50)'; 'Strong (-1.00)'; 'Severe (-1.50)'; 'Fixed (1.2)';'Fixed (1.4)';'Fixed (1.6)';'Fixed (1.8)';'Fixed (2.0)'};
intnorm.values = {0, -0.25,-0.50,-1.00,-1.50, 1.2,1.4,1.6,1.8,2.0};
intnorm.help = [intnorm.help {'Experts have additional manuell settings with light (1.2) to strong (2.0) corrections.'}];
else
intnorm.labels = {'No';'Light';'Standard';'Strong' };
intnorm.values = {0, -0.25,-0.50,-1.00};
end
intnorm.val = {-0.5};
intnorm.hidden = expert<1;
bet = cfg_menu;
bet.tag = 'skullstripping';
bet.name = 'Skull-stripping';
if expert > 1
bet.labels = {'No (0)';'SPM (1)';'Optimized (2)';'Optimized (only MP2Rage; 3)'};
bet.values = {0,1,2,3};
bet.val = {3};
else
bet.labels = {'No';'SPM';'Optimized'};
bet.values = {0,1,3};
bet.val = {3};
end
bet.help = {'Apply skull-stripping to the image. The "SPM" version missed some brain regions (e.g., motorcortex/occiptial) in some cases. The optimized version try to add some tissue arround in without running to much into the skull. ' ''};
% bloodvesselscorrection - not implemented yet >> should be handled in CAT anyway
% maybe useful to handle SPM detected structures that were labeled as head
% for experts
CSFnoise = cfg_menu;
CSFnoise.tag = 'restoreLCSFnoise';
CSFnoise.name = 'Restore lower CSF noise if MP2Rage';
CSFnoise.labels = {'No'; 'Yes'};
CSFnoise.values = {0 1};
CSFnoise.val = {1};
CSFnoise.hidden = expert<2;
CSFnoise.help = {'In MP2Rage the CSF peak is quite inbalanced and the values are limited by zero. this adds some noise as far as some steps in SPM/CAT expect more variation within the CSF.' ''};
prefix.val = {'mp2rc_'};
prefix.help = [prefix.help {'The string can include a subdirectory "mytestdir/myprefix_" that is than used to store the results. '}];
if expert
prefix.help = [prefix.help {'The keyword "PARA" will be replaced by a string that include major parameter settings for testing. '}];
end
report = cfg_menu;
report.tag = 'report';
report.name = 'Print report';
report.labels = {'No'; 'Yes'};
report.values = {0 1};
report.val = {1};
report.hidden = expert<1;
report.help = {'Create a report file with parameters, results and in-/output images.' ''};
verb.hidden = expert<1;
% == main ==
mp2rage = cfg_exbranch;
mp2rage.tag = 'mp2rage';
mp2rage.name = 'MP2RAGE preprocessing for CAT';
mp2rage.val = {data bias logscale intnorm bet CSFnoise prefix report verb};
mp2rage.prog = @cat_vol_mp2rage;
mp2rage.vout = @vout_mp2rage; % define output files
%mp2rage.hidden = expert<1;
mp2rage.help = {
'Batch to optimize MP2Rage (and other) images for CAT preprocessing (IN DEVELOPMENT). '
};
return
function report = conf_main_report(data_xml,outdir,expert)
%conf_main_report. Retrospective creation of CAT report.
data_xml.tag = 'files';
data_xml.name = 'CAT XML files';
data_xml.val = {};
data_xml.num = [1 Inf];
data_xml.help = {
'Select CAT XML files from the report directories of the subjects those report has to be (re)generated.'
};
Pm = data_xml;
Pm.name = 'Intensity Normalized Images';
Pm.tag = 'Pm';
Pm.filter = {'image','^m.*\.(nii.gz)$'};
Pm.hidden = expert < 1;
Pm.help = {
'Select bias corrected images to replace the default settings. '
'The same subjects has to be used as for the XML files. '
};
Pp0 = data_xml;
Pp0.name = 'Label maps';
Pp0.tag = 'Pp0';
Pp0.filter = {'image','^p0.*\.(nii.gz)$'};
Pp0.hidden = expert < 1;
Pp0.help = {
'Select segmentation label images to replace the default settings. '
'The same subjects has to be used as for the XML files. '
};
print = cfg_menu;
print.tag = 'print';
print.name = 'Print setting';
print.labels = {'volume only','volume and surfaces'};
print.values = {1 2};
print.def = @(val)cat_get_defaults('extopts.print', val{:});
print.hidden = expert < 1;
print.help = {
'Create final CAT report that requires Java. '
};
% remove old image field
report = cfg_exbranch;
report.val = {data_xml Pm Pp0 print outdir}; % xmlfields
report.help = {[...
'Retrospective creation of the CAT report PDF/JPG by using the CAT preprocessing XML file, e.g., ' ...
'when report creation was not possible or failed. ']};
report.tag = 'catreport';
report.vout = @vout_report;
report.prog = @cat_main_report;
report.name = 'Retrospective CAT Report';
return
%_______________________________________________________________________
function imcalc = conf_vol_imcalc(prefix,expert)
%conf_vol_imcalc. Like spm_imcalc but to run the same operation for many subjects.
imcalc = spm_cfg_imcalc;
data = cfg_files;
data.tag = 'subjects';
data.name = 'Volumes';
data.filter = {'image','.*\.(nii.gz)$'};
data.ufilter = '.*';
data.num = [1 Inf];
data.help = {'Select the same number and order of subjects for one image class. '};
image = data;
image.tag = 'images';
image.name = 'Images';
images = cfg_repeat;
images.tag = 'imagetype';
images.name = 'Image type';
images.values = {image};
images.num = [1 Inf];
images.help = {'Specify input images class, e.g., the T1 image of a subject. '};
% remove old image field
try
imcalc.val{1} = images;
imcalc.val{2} = prefix;
imcalc.val{3}.help = {[...
'Files produced by this function will be written into this output directory. ' ...
'If no directory is given, images will be written to the home of the first input image i1. ' ...
'A relative path (e.g., "../output") can be used. ']};
end
imcalc.tag = 'mimcalc';
imcalc.vout = @vout_mimcalc;
imcalc.prog = @cat_vol_mimcalc;
imcalc.hidden = expert < 1;
imcalc.name = 'Multi-subject Image Calculator';
return
%_______________________________________________________________________
function file_move = conf_io_file_move
% ---------------------------------------------------------------------
% file_move Move/Delete Files
% ---------------------------------------------------------------------
% ---------------------------------------------------------------------
% files Files to move/copy/delete
% ---------------------------------------------------------------------
files = cfg_files;
files.tag = 'files';
files.name = 'Files to move/copy/delete';
files.help = {'These files will be moved, copied or deleted.'};
files.filter = {'any'};
files.ufilter = '.*';
files.num = [0 Inf];
% ---------------------------------------------------------------------
% moveto Move to
% ---------------------------------------------------------------------
moveto = cfg_files;
moveto.tag = 'moveto';
moveto.name = 'Move to';
moveto.help = {'Files will be moved to the specified directory.'};
moveto.filter = {'dir'};
moveto.ufilter = '.*';
moveto.num = [1 1];
% ---------------------------------------------------------------------
% copyto Copy to
% ---------------------------------------------------------------------
copyto = cfg_files;
copyto.tag = 'copyto';
copyto.name = 'Copy to';
copyto.help = {'Files will be moved to the specified directory.'};
copyto.filter = {'dir'};
copyto.ufilter = '.*';
copyto.num = [1 1];
% ---------------------------------------------------------------------
% moveto Move to
% ---------------------------------------------------------------------
moveto1 = cfg_files;
moveto1.tag = 'moveto';
moveto1.name = 'Move to';
moveto1.help = {'Files will be moved to the specified directory.'};
moveto1.filter = {'dir'};
moveto1.ufilter = '.*';
moveto1.num = [1 1];
% ---------------------------------------------------------------------
% pattern Pattern
% ---------------------------------------------------------------------
pattern = cfg_entry;
pattern.tag = 'pattern';
pattern.name = 'Pattern';
pattern.help = {'The regular expression pattern to look for.'};
pattern.strtype = 's';
pattern.num = [1 Inf];
% ---------------------------------------------------------------------
% repl Replacement
% ---------------------------------------------------------------------
repl = cfg_entry;
repl.tag = 'repl';
repl.name = 'Replacement';
repl.help = {'This string (or pattern) will be inserted instead.'};
repl.strtype = 's';
repl.num = [1 Inf];
% ---------------------------------------------------------------------
% patrep Pattern/Replacement Pair
% ---------------------------------------------------------------------
patrep = cfg_branch;
patrep.tag = 'patrep';
patrep.name = 'Pattern/Replacement Pair';
patrep.val = {pattern repl };
% ---------------------------------------------------------------------
% patreplist Pattern/Replacement List
% ---------------------------------------------------------------------
patreplist = cfg_repeat;
patreplist.tag = 'patreplist';
patreplist.name = 'Pattern/Replacement List';
patreplist.help = {'Regexprep supports a list of multiple patterns and corresponding replacements. These will be applied to the filename portion (without path, without extension) one after another. E.g., if your filename is ''testimage(.nii)'', and you replace ''test'' with ''xyz'' and ''xyzim'' with ''newtestim'', the final filename will be ''newtestimage.nii''.'};
patreplist.values = {patrep };
patreplist.num = [1 Inf];
% ---------------------------------------------------------------------
% unique Unique Filenames
% ---------------------------------------------------------------------
unique = cfg_menu;
unique.tag = 'unique';
unique.name = 'Unique Filenames';
unique.help = {
'If the regexprep operation results in identical output filenames for two or more input files, these can not be written/renamed to their new location without loosing data. If you are sure that your regexprep patterns produce unique filenames, you do not need to care about this.'
'If you choose to append a running number, it will be zero-padded to make sure alphabetical sort of filenames returns them in the same order as the input files are.'
}';
unique.labels = {
'Don''t Care'
'Append Index Number'
}';
unique.values = {
false
true
}';
% ---------------------------------------------------------------------
% moveren Move and Rename
% ---------------------------------------------------------------------
moveren = cfg_branch;
moveren.tag = 'moveren';
moveren.name = 'Move and Rename';
moveren.val = {moveto1 patreplist unique };
moveren.help = {'The input files will be moved to the specified target folder. In addition, their filenames (not paths, not extensions) will be changed by replacing regular expression patterns using MATLABs regexprep function. Please consult MATLAB help and HTML documentation for how to specify regular expressions.'};
ren = cfg_branch;
ren.tag = 'ren';
ren.name = 'Rename';
ren.val = {patreplist unique };
ren.help = {'The input files will be moved to the specified target folder. In addition, their filenames (not paths, not extensions) will be changed by replacing regular expression patterns using MATLABs regexprep function. Please consult MATLAB help and HTML documentation for how to specify regular expressions.'};
% ---------------------------------------------------------------------
% copyto Copy to
% ---------------------------------------------------------------------
copyto1 = cfg_files;
copyto1.tag = 'copyto';
copyto1.name = 'Copy to';
copyto1.help = {'Files will be moved to the specified directory.'};
copyto1.filter = {'dir'};
copyto1.ufilter = '.*';
copyto1.num = [1 1];
% ---------------------------------------------------------------------
% pattern Pattern
% ---------------------------------------------------------------------
pattern = cfg_entry;
pattern.tag = 'pattern';
pattern.name = 'Pattern';
pattern.help = {'The regular expression pattern to look for.'};
pattern.strtype = 's';
pattern.num = [1 Inf];
% ---------------------------------------------------------------------
% repl Replacement
% ---------------------------------------------------------------------
repl = cfg_entry;
repl.tag = 'repl';
repl.name = 'Replacement';
repl.help = {'This string (or pattern) will be inserted instead.'};
repl.strtype = 's';
repl.num = [1 Inf];
% ---------------------------------------------------------------------
% patrep Pattern/Replacement Pair
% ---------------------------------------------------------------------
patrep = cfg_branch;
patrep.tag = 'patrep';
patrep.name = 'Pattern/Replacement Pair';
patrep.val = {pattern repl };
% ---------------------------------------------------------------------
% patreplist Pattern/Replacement List
% ---------------------------------------------------------------------
patreplist = cfg_repeat;
patreplist.tag = 'patreplist';
patreplist.name = 'Pattern/Replacement List';
patreplist.help = {'Regexprep supports a list of multiple patterns and corresponding replacements. These will be applied to the filename portion (without path, without extension) one after another. E.g., if your filename is ''testimage(.nii)'', and you replace ''test'' with ''xyz'' and ''xyzim'' with ''newtestim'', the final filename will be ''newtestimage.nii''.'};
patreplist.values = {patrep };
patreplist.num = [1 Inf];
% ---------------------------------------------------------------------
% unique Unique Filenames
% ---------------------------------------------------------------------
unique = cfg_menu;
unique.tag = 'unique';
unique.name = 'Unique Filenames';
unique.help = {
'If the regexprep operation results in identical output filenames for two or more input files, these can not be written/renamed to their new location without loosing data. If you are sure that your regexprep patterns produce unique filenames, you do not need to care about this.'
'If you choose to append a running number, it will be zero-padded to make sure alphabetical sort of filenames returns them in the same order as the input files are.'
}';
unique.labels = {
'Don''t Care'
'Append Index Number'
}';
unique.values = {
false
true
}';
unique.val = {false};
% ---------------------------------------------------------------------
% copyren Copy and Rename
% ---------------------------------------------------------------------
copyren = cfg_branch;
copyren.tag = 'copyren';
copyren.name = 'Copy and Rename';
copyren.val = {copyto1 patreplist unique };
copyren.help = {'The input files will be copied to the specified target folder. In addition, their filenames (not paths, not extensions) will be changed by replacing regular expression patterns using MATLABs regexprep function. Please consult MATLAB help and HTML documentation for how to specify regular expressions.'};
% ---------------------------------------------------------------------
% delete Delete
% ---------------------------------------------------------------------
delete = cfg_const;
delete.tag = 'delete';
delete.name = 'Delete';
delete.val = {false};
delete.help = {'The selected files will be deleted.'};
% ---------------------------------------------------------------------
% action Action
% ---------------------------------------------------------------------
action = cfg_choice;
action.tag = 'action';
action.name = 'Action';
action.values = {moveto copyto moveren copyren ren delete };
file_move = cfg_exbranch;
file_move.tag = 'file_move';
file_move.name = 'Move/Rename/Delete Files';
file_move.val = {files action };
file_move.help = {'Move, rename or delete files.'};
file_move.prog = @cat_io_file_move;
file_move.vout = @vout_file_move;
return
%_______________________________________________________________________
function long_report = conf_long_report(data_vol,data_xml,expert)
% -------------------------------------------------------------------------
% Batch to create a final report of the processing of a set of files of one
% (or multiple) subject(s).
%
% RD202201: start of development for fast visualisation of longitudinal and
% test-retest data
% -------------------------------------------------------------------------
data_vol.name = 'Volume Data Files';
data_vol.num = [0 Inf];
data_vol.val{1} = {''};
data_surf = cfg_files;
data_surf.tag = 'data_surf';
data_surf.name = '(Left) Surface Data Files';
data_surf.filter = 'any';
data_surf.ufilter = 'lh.(?!cent|pial|white|sphe|defe|hull|pbt).*';
data_surf.num = [0 Inf];
data_surf.help = {'Surface data files. Both sides will be processed'};
data_surf.val{1} = {''};
avg_vol = data_vol;
avg_vol.tag = 'avg_vol';
avg_vol.name = 'Volume Average Data File (In Development)'; % ###### not implemented yet ######
avg_vol.num = [0 1];
avg_vol.help = {'Segmentation of an average volume T1 to estimate further measures.' ''};
avg_vol.val{1} = {''};
avg_vol.hidden = expert<2;
avg_surf = data_surf;
avg_surf.tag = 'avg_vol';
avg_surf.name = '(Left) Surface Average Data File (In Development)'; % ###### not implemented yet ######
avg_surf.num = [0 1];
avg_surf.help = {'Surface/thickness of an average volume T1 to estimate further measures.' ''};
avg_surf.val{1} = {''};
avg_surf.hidden = expert<2;
% selected automatically ... need further controlling routines for covariance analysis
xmls = data_xml;
xmls.name = 'XML Data Files (In Development)'; % ###### not implemented yet ######
xmls.hidden = expert<2;
timepoints = cfg_entry;
timepoints.tag = 'timepoints';
timepoints.name = 'Timepoints (In Development)'; % ###### not implemented yet ######
timepoints.help = {'Define difference between timepoints in years. '};
timepoints.strtype = 'r';
timepoints.num = [0 inf];
timepoints.val = {[]};
timepoints.hidden = expert<2;
% == options ==
smoothvol = cfg_entry;
smoothvol.tag = 'smoothvol';
smoothvol.name = 'Volumetric Smoothing';
smoothvol.help = {'FWHM of volumetric smoothing in mm.'};
smoothvol.strtype = 'r';
smoothvol.num = [1 1];
smoothvol.val = {3};
smoothsurf = cfg_entry;
smoothsurf.tag = 'smoothsurf';
smoothsurf.name = 'Thickness Smoothing';
smoothsurf.help = {'Amount of surface-based smoothing in mm'};
smoothsurf.strtype = 'r';
smoothsurf.num = [1 1];
smoothsurf.val = {12};
midpoint = cfg_menu;
midpoint.tag = 'midpoint';
midpoint.name = 'Scaling (In Development)'; % ###### not implemented yet ######
midpoint.labels = {
'first image'
'mean'
};
midpoint.values = {0;1};
midpoint.val = {0};
midpoint.help = {'Data scaling by first image or by mean value. ' ''};
midpoint.hidden = expert<2;
boxplot = cfg_menu;
boxplot.tag = 'boxplot';
boxplot.name = 'Boxplot (In Development)'; % ###### not implemented yet ######
boxplot.labels = {
'no'
'yes'
};
boxplot.values = {0;1};
boxplot.val = {0};
boxplot.help = {'Use boxplots.' ''};
boxplot.hidden = expert < 2;
plotGMWM = cfg_menu;
plotGMWM.tag = 'plotGMWM';
plotGMWM.name = 'Plot WM and GM in one figure'; % ###### not implemented yet ######
plotGMWM.labels = {
'no'
'yes'
};
plotGMWM.values = {0;1};
plotGMWM.val = {1};
plotGMWM.help = {'Plot WM and GM in one figure. ' ''};
plotGMWM.hidden = expert < 2;
opts = cfg_exbranch;
opts.tag = 'opts';
opts.name = 'Options';
opts.val = {smoothvol smoothsurf midpoint plotGMWM};
opts.help = {'Specify some processing options.' ''};
opts.hidden = expert<1;
% == output ==
vols = cfg_menu;
vols.tag = 'vols';
vols.name = 'Difference Maps';
vols.labels = {'No';'Yes'};
vols.values = {0,1};
vols.val = {0};
vols.help = {'Write difference volume maps.' ''};
surfs = cfg_menu;
surfs.tag = 'surfs';
surfs.name = 'Difference Surfaces Data Files';
surfs.labels = {'No';'Yes'};
surfs.values = {0,1};
surfs.val = {0};
surfs.help = {'Write difference surface data files.' ''};
xml = cfg_menu;
xml.tag = 'xml';
xml.name = 'XML';
xml.labels = {'No';'Yes'};
xml.values = {0,1};
xml.val = {1};
xml.help = {'Write combined XML file.' ''};
output = cfg_exbranch;
output.tag = 'output';
output.name = 'Write Output Data';
output.val = {vols surfs xml};
output.help = {'Specify output data.' ''};
output.hidden = expert<1;
printlong = cfg_menu;
printlong.tag = 'printlong';
printlong.name = 'Create CAT long report';
printlong.labels = {'No','Yes (volume only)','Yes (volume and surfaces)'};
printlong.values = {0 1 2};
printlong.def = @(val)cat_get_defaults('extopts.print', val{:});
printlong.help = {
'Create final longitudinal CAT report that requires Java.'
};
% == main ==
long_report = cfg_exbranch;
long_report.tag = 'long_report';
long_report.name = 'Longitudinal Report';
if expert
long_report.val = {data_vol avg_vol data_surf avg_surf xmls timepoints opts output printlong};
else
long_report.val = {data_vol data_surf};
end
long_report.prog = @cat_long_report;
%long_report.vout = @vout_long_report;
long_report.hidden = expert<1;
long_report.help = {
};
return
%_______________________________________________________________________
function xml2csv = conf_io_xml2csv(outdir)
% -------------------------------------------------------------------------
% Read structures/XML-files and export and transform it to a table/CSV-file
%
% RD202304
% -------------------------------------------------------------------------
% n-files, e.g. XML for direct extraction or nii/gii as selector
files = cfg_files;
files.num = [1 Inf];
files.tag = 'files';
files.name = 'XML files';
files.filter = 'any';
files.ufilter = '^cat.*\.xml$';
files.val = {{''}};
files.help = {'Select XML files of one type (e.g., "cat_", "catROI_" or "catROIs"). '};
% filename
fname = cfg_entry;
fname.tag = 'fname';
fname.name = 'Filename';
fname.strtype = 's';
fname.num = [1 inf];
fname.val = {'CATxml.csv'};
fname.help = {'CSV filename.' };
% expert output options
% fieldnames
fieldnames = cfg_entry;
fieldnames.tag = 'fieldnames';
fieldnames.name = 'Included fieldnames';
fieldnames.strtype = 's+';
fieldnames.val = {{' '}};
fieldnames.num = [0 inf];
fieldnames.help = {
'Define keywords or complete fields to limit the extraction (empty = include all), i.e. only fields that inlclude these strings are used. '
'In case of catROI-files you can limit the extraction to specific atlas, regions, or tissues. '
'In case of cat-files you can limit the extraction to specific parameters ("opts" or "extopts") or QC ratings ("qualityratings"). '
''
};
% avoidfields
avoidfields = cfg_entry;
avoidfields.tag = 'avoidfields';
avoidfields.name = 'Excluded fieldnames';
avoidfields.strtype = 's+';
avoidfields.val = {{''}};
avoidfields.num = [0 inf];
avoidfields.help = {
'Define keywords or complete fields that should be avoided/excluded (empty = exclude none), i.e. fields that inlclude such strings even they were included before. '
'In case of catROI-files you can limit the extraction to specific atlas, regions, or tissues. '
'In case of cat-files you can limit the extraction to specific parameters or measures. '
''
};
report = cfg_menu;
report.tag = 'report';
report.name = 'CAT XML export field sets';
report.labels = {'default','only processing parameters','no processing parameters'};
report.values = {'default','paraonly' ,'nopara' };
report.val = {'default'};
report.help = {'Predefined sets of CAT XML values in case of "cat_" processing XML files (no effect in other XMLs). '};
xml2csv = cfg_exbranch;
xml2csv.tag = 'xml2csv';
xml2csv.name = 'XML2CSV';
xml2csv.val = {files fname outdir fieldnames avoidfields report};
xml2csv.prog = @cat_io_xml2csv;
%xml2csv.vout = @vout_long_report;
xml2csv.help = {
'Export XML files (e.g. the cat preprocessing results or catROI-files) as a CSV table. '
};
return
%_______________________________________________________________________
function [getCSVXML,getXML,getCSV] = cat_cfg_getCSVXML(outdir,expert)
% -------------------------------------------------------------------------
% Batch to read out of XML/CSV data and export as batch dependency/file.
%
% RD202104
% -------------------------------------------------------------------------
% n-files, e.g. XML for direct extraction or nii/gii as selector
files = cfg_files;
files.num = [0 Inf];
files.tag = 'files';
files.name = 'XML files';
files.filter = 'any';
files.ufilter = '^cat_.*\.xml$';
files.val = {{''}};
files.help = {'Select XML files of subjects those XML/CSV data should be extracted. '};
% 0..1-file ... maybe n later
csvfile = cfg_files;
csvfile.num = [0 1];
csvfile.tag = 'csvfile';
csvfile.name = 'CSV file';
csvfile.filter = 'any';
csvfile.ufilter = '.*\.(csv|tsv)$';
csvfile.val = {{''}};
csvfile.help = {
['Select one CSV/TSV file that contains further information, e.g. age or sex. The first line has to be the header with the name of the variables. ' ...
'The first row has to include an unique identifier for the selected subjects files give above, e.g. the subject ID, the filename, or path if the filename is not unique. ' ...
'For instance, a file IXI_IOP_493 can be identified by the subject ID 493 given in the IXI CSV/TSV table. ' ...
'However, filenames in BIDS are not suited for identification and you has to specify the "Path/filename selector" to select the directory entry that include the ID. ']
''
};
% -------------------------------------------------------------------------
% general definition
% -------------------------------------------------------------------------
% set of variables names for extraction ... preselection TIV IQR ...
% the variables were extracted and a depency for each created
% The CSV selection is a bit more tricky.
fields = cfg_entry;
fields.tag = 'fields';
fields.name = 'XML and CSV/TSV fieldnames';
fields.strtype = 's+';
fields.num = [0 inf];
fields.val = {{''}};
% fields.hidden = expert < 2;
fields.help = {
['Enter (part of) the fieldnames (XML) or columns names (CSV/TSV) or column numbers (positve to select or negative values as final deselection). ' ...
'The fieldnames (XML) or headerentries (CSV/TSV) are used to create the dependency objects and will be converted to variables. ' ...
'The CSV/TSV columns have to have unique names and non-standard characters are replaces. ']
['To extract one value of a matrix or cell field of an XML fiedl use the matlab specification, e.g., ' ...
'to extract the GM value from "subjectmeasures.vol_CGW" use "subjectmeasures.vol_CGW(2)".' ]
''
'Enter one field per row (what creates a cellstr), e.g.:'
' AGE'
' SEX_ID_(1=m,2=f)'