-
Notifications
You must be signed in to change notification settings - Fork 3
/
PSE.m
729 lines (558 loc) · 25 KB
/
PSE.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TVB parameter space exploration + checks on modeling parameters
%
% Written by Hannelore Aerts
% (UGent, Faculty of Psychology, Department of Data Analysis)
% Date last modification: 05/02/2018
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Settings
scale = 68;
thr = {'thrA', 'thrR'};
dist_metric = {'Len', 'Log'};
%% Loop over all subjects
main='/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/';
sublist=dir(main);
n=length(sublist);
for sub=1:n
for tt = 1:2
tm = thr{tt};
for dd = 1:2
dm = dist_metric{dd};
%% Load empirical data
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
in_fold = fullfile('/home/hannelore/Documents/ANALYSES/BTC_prepro/subjects/preop', subID);
out_fold = (['/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/' subID '/TVBii_' subID '_G-Ji']);
cd(fullfile(in_fold, 'fmri'));
load([subID '_fMRI_new.mat']);
FC_emp = FC_cc_DK68;
FC_emp = weight_conversion(FC_emp, 'autofix'); %put diagonal to zero
FC_emp_z=atanh(FC_emp); %Fisher Z transformation
clear CON* PAT* FC_cc* FC_mi ROI*
cd(out_fold);
SCtmp=load(['TVBiiInput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], ['SC' tm 'n']);
SC=cell2mat(struct2cell(SCtmp));
clear SCtmp
%% Compare empirical structure vs. function
upperIdx = ones([scale scale]);
upperIdx = triu(upperIdx,1);
len=length(find(upperIdx));
FC_emp_zv = reshape(FC_emp_z(~~upperIdx), [len 1]);
SCv = reshape(SC(~~upperIdx), [len 1]);
SC_FC_corP = corr(SCv, FC_emp_zv);
SC_FC_corS = corr(SCv, FC_emp_zv, 'Type', 'Spearman');
%% Load simulated BOLD
params_path=out_fold;
sim_path=([params_path '/output_' tm '_scale' num2str(scale) '_dist' dm]);
paramslist=dir([params_path '/params/param_set_*']);
m=length(paramslist);
TVBii_PSE = nan(m,10);
TVBii_Ji = nan(scale,m);
for index=2:m
% Load parameters
params = dlmread([params_path '/params/param_set_' num2str(index)]);
% Load simulated TS
s=dir([sim_path '/BOLD_param_set_' num2str(index) '.txt']);
if exist([sim_path '/BOLD_param_set_' num2str(index) '.txt']) == 0
disp('No file found: putting nan in output')
SC_FC_corP(2)=nan;
emp_sim_cor(2)=nan;
Ji = nan(68,1);
J = mean(Ji);
elseif s.bytes ~= 0
Ji = dlmread([sim_path '/BOLD_param_set_' num2str(index) '.txt']);
Ji = Ji(1:scale,2);
J = mean(Ji);
TS_sim = dlmread([sim_path '/BOLD_param_set_' num2str(index) '.txt']);
TS_sim = TS_sim(end-179:end,:);
FC_sim = corr(TS_sim);
FC_sim = weight_conversion(FC_sim, 'autofix');
FC_sim_z = atanh(FC_sim);
FC_sim_zv = reshape(FC_sim_z(~~upperIdx), [len 1]);
% Correlate simulated and empirical BOLD
emp_sim_corP = corr(FC_emp_zv, FC_sim_zv);
emp_sim_corS = corr(FC_emp_zv, FC_sim_zv, 'Type', 'Spearman');
elseif s.bytes == 0
disp('Empty file found: putting nan in output')
emp_sim_cor=nan;
Ji = nan(68,1);
J = mean(Ji);
end;
% Save output
TVBii_PSE(index, 1) = params(1); %number of nodes
TVBii_PSE(index, 2) = params(2); %G
TVBii_PSE(index, 3) = params(3); %J_NMDA
TVBii_PSE(index, 4) = params(4); %W+
TVBii_PSE(index, 5) = J; %average J
TVBii_PSE(index, 6) = params(9); %TR
TVBii_PSE(index, 7) = SC_FC_corP; %SC_FC correlation (Pearson)
TVBii_PSE(index, 8) = SC_FC_corS; %SC_FC correlation (Spearman)
TVBii_PSE(index, 9) = emp_sim_corP; %emp_sim cor (Pearson)
TVBii_PSE(index, 10) = emp_sim_corS; %emp_sim cor (Spearman)
TVBii_Ji(:,index)=Ji;
clear FC_sim* TS_sim J Ji emp_sim_cor* params s
end
cd(out_fold);
save(sprintf('TVBiiOutput_%s_scale%d_dist%s',tm,scale,dm), 'FC_emp', 'FC_emp_z', 'FC_emp_zv', 'SC', 'SCv', 'TVBii_PSE', 'TVBii_Ji');
clear TVBii_PSE TVBii_Ji params* sim_path SC_FC_cor* FC* SC*
clear in_fold index len out_fold upperIdx
end
end
end
%% Exploration of results: effect of thresholding, distance and correlation metric on G
results_fold='/home/hannelore/Documents/ANALYSES/TVB_global2/results_TVBii';
for sub=1:n
subID = sublist(sub).name;
disp(['Processing ' subID]);
out_fold = (['/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/' subID '/TVBii_' subID '_G-Ji']);
cd(out_fold);
% Load all data
load([out_fold '/TVBiiOutput_thrA_scale68_distLen'], 'TVBii_PSE')
G_ALen = TVBii_PSE(:,2);
corP_ALen = TVBii_PSE(:,9);
corS_ALen = TVBii_PSE(:,10);
clear TVBii_PSE
load([out_fold '/TVBiiOutput_thrA_scale68_distLog'], 'TVBii_PSE')
G_ALog = TVBii_PSE(:,2);
corP_ALog = TVBii_PSE(:,9);
corS_ALog = TVBii_PSE(:,10);
clear TVBii_PSE
load([out_fold '/TVBiiOutput_thrR_scale68_distLen'], 'TVBii_PSE')
G_RLen = TVBii_PSE(:,2);
corP_RLen = TVBii_PSE(:,9);
corS_RLen = TVBii_PSE(:,10);
clear TVBii_PSE
load([out_fold '/TVBiiOutput_thrR_scale68_distLog'], 'TVBii_PSE')
G_RLog = TVBii_PSE(:,2);
corP_RLog = TVBii_PSE(:,9);
corS_RLog = TVBii_PSE(:,10);
clear TVBii_PSE
% Plot
cd(results_fold);
% G ~ corP for different thresholds and distance metrics
plot(G_ALen, corP_ALen, 'LineWidth', 2, 'Color', 'y');
xlabel('G'); ylabel('Pearson correlation FCsim - FCemp');
hold on
plot(G_ALog, corP_ALog, 'LineWidth', 2, 'Color', 'b');
% complete overlap with corP_ALen
hold on
plot(G_RLen, corP_RLen, 'LineWidth', 2, 'Color', 'c');
hold on
plot(G_RLog, corP_RLog, 'LineWidth', 2, 'Color', 'g');
% complete overlap with corP_distLen
legend('thrA, distLog', 'thrA, distLen', 'thrR, distLog', 'thrR, distLen');
print([subID '_G-corP_thr-dist'], '-dpng');
close all
% G ~ corS for different thresholds and distance metrics
plot(G_ALen, corS_ALen, 'LineWidth', 2, 'Color', 'y');
xlabel('G'); ylabel('Pearson correlation FCsim - FCemp');
hold on
plot(G_ALog, corS_ALog, 'LineWidth', 2, 'Color', 'b');
% complete overlap with corS_ALen
hold on
plot(G_RLen, corS_RLen, 'LineWidth', 2, 'Color', 'c');
hold on
plot(G_RLog, corS_RLog, 'LineWidth', 2, 'Color', 'g');
% complete overlap with corS_RLen
legend('thrA, distLog', 'thrA, distLen', 'thrR, distLog', 'thrR, distLen');
print([subID '_G-corS_thr-dist'], '-dpng');
close all
% G ~ cor for different thresholds and correlation metrics
plot(G_ALog, corP_ALog, 'LineWidth', 2, 'Color', 'y');
xlabel('G'); ylabel('Correlation FCsim - FCemp');
hold on
plot(G_ALog, corS_ALog, 'LineWidth', 2, 'Color', 'b');
hold on
plot(G_RLog, corP_RLog, 'LineWidth', 2, 'Color', 'c');
hold on
plot(G_RLog, corS_RLog, 'LineWidth', 2, 'Color', 'g');
legend('thrA, corP', 'thrA, corS', 'thrR, corP', 'thrR, corS');
print([subID '_G-cor_thr-cor'], '-dpng');
close all
% close overlap between threshold methods, greatest difference
% between correlation metrics but qualitatively same pattern
% (though Pearson cor generally higher than Spearman cor)
clear G_* cor*
end
%--> Continue with distLog, corP, both thresholds!
%% Save Gmax, SC-FC, FCemp-FCsim, and J for both thresholds
results_fold='/home/hannelore/Documents/ANALYSES/TVB_global2/results_TVBii';
TVBii_results_thrA=nan(n,5);
TVBii_results_thrR=nan(n,5);
for sub=1:n
subID = sublist(sub).name;
disp(['Processing ' subID]);
out_fold = (['/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/' subID '/TVBii_' subID '_G-Ji']);
cd(out_fold);
% ThrA
load([out_fold '/TVBiiOutput_thrA_scale68_distLog'], 'TVBii_PSE');
results_sorted = sortrows(TVBii_PSE, -9);
TVBii_results_thrA(sub, 1)=sub; %subject number (alphabetical order)
TVBii_results_thrA(sub, 2)=results_sorted(1,7); %SC-FC
TVBii_results_thrA(sub, 3)=results_sorted(1,9); %corP FCemp-FCsim max
TVBii_results_thrA(sub, 4)=results_sorted(1,2); %G
TVBii_results_thrA(sub, 5)=results_sorted(1,5); %average J
clear TVBii_PSE results_sorted
% ThrR
load([out_fold '/TVBiiOutput_thrR_scale68_distLog'], 'TVBii_PSE');
results_sorted = sortrows(TVBii_PSE, -9);
TVBii_results_thrR(sub, 1)=sub; %subject number (alphabetical order)
TVBii_results_thrR(sub, 2)=results_sorted(1,7); %SC-FC
TVBii_results_thrR(sub, 3)=results_sorted(1,9); %corP FCemp-FCsim max
TVBii_results_thrR(sub, 4)=results_sorted(1,2); %G
TVBii_results_thrR(sub, 5)=results_sorted(1,5); %average J
clear TVBii_PSE results_sorted
end
% Save
cd(results_fold)
save('results_G-J_thrA', 'TVBii_results_thrA');
save('results_G-J_thrR', 'TVBii_results_thrR');
%% Sanity check 1: cor FCemp-FCsim using CONavg parameters
for tt = 1:2
tm = thr{tt};
dm = 'Log';
for sub=1:n
% Load empirical data
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
in_fold = fullfile('/home/hannelore/Documents/ANALYSES/BTC_prepro/subjects/preop', subID);
out_fold = (['/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/' subID '/TVBii_' subID '_G-Ji']);
cd(fullfile(in_fold, 'fmri'));
load([subID '_fMRI_new.mat']);
FC_emp = FC_cc_DK68;
FC_emp = weight_conversion(FC_emp, 'autofix'); %put diagonal to zero
FC_emp_z=atanh(FC_emp); #Fisher-Z transform
clear CON* PAT* FC_cc* FC_mi ROI*
upperIdx = ones([scale scale]);
upperIdx = triu(upperIdx,1);
len=length(find(upperIdx));
FC_emp_zv = reshape(FC_emp_z(~~upperIdx), [len 1]);
% Load simulated BOLD
sim_path=([out_fold '/output_' tm '_scale' num2str(scale) '_dist' dm '_CONavg']);
TS_sim = dlmread([sim_path '/BOLD_param_set_CON.txt']);
TS_sim = TS_sim(end-179:end,:);
FC_sim = corr(TS_sim);
FC_sim = weight_conversion(FC_sim, 'autofix');
FC_sim_z = atanh(FC_sim);
FC_sim_zv = reshape(FC_sim_z(~~upperIdx), [len 1]);
clear upperIdx len
% Correlate simulated and empirical BOLD
emp_sim_corP(sub,1) = corr(FC_emp_zv, FC_sim_zv);
emp_sim_corS(sub,1) = corr(FC_emp_zv, FC_sim_zv, 'Type', 'Spearman');
clear FC_* TS_sim in_fold out_fold
end
results_fold='/home/hannelore/Documents/ANALYSES/TVB_global2/results_TVBii';
cd(results_fold)
emp_sim_corP_CONavgparams=emp_sim_corP;
emp_sim_corS_CONavgparams=emp_sim_corS;
save(['SanChecks_' tm], 'emp_sim_corP_CONavgparams', 'emp_sim_corS_CONavgparams');
end
% Plot subject max FCemp-FCsim correlation against that obtained with
% average parameters
% thrA
cd(results_fold)
load('SanChecks_thrA.mat');
load('results_G-J_thrA.mat');
dif = TVBii_results_thrA(:,3) - emp_sim_corP_CONavgparams;
% Difference between 2 distributions significant?
[h,p,ks2stat] = kstest2(emp_sim_corP_CONavgparams, TVBii_results_thrA(:,3))
% --> yes! ks2stat=0.3889, p=0.0059
clear emp_sim_cor* TVBii_results_thrA dif h p ks2stat
% thrR
cd(results_fold)
load('SanChecks_thrR.mat');
load('results_G-J_thrR.mat');
dif = TVBii_results_thrR(:,3) - emp_sim_corP_CONavgparams;
% Difference between 2 distributions significant?
[h,p,ks2stat] = kstest2(emp_sim_corP_CONavgparams, TVBii_results_thrR(:,3))
% --> yes! ks2stat=0.3889, p=0.0059
clear emp_sim_cor* TVBii_results_thrA dif h p ks2stat
%% Sanity check 2: use average SC matrix with subject-specific model params
% (optimized G + median J [because of skewnes])
% First get CON average SC weights & dist matrix
tm = 'thrA';
dm = 'Log';
for sub=1:11
% Load individual SC matrix and add it to 3D array
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
out_fold = (['/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/' subID '/TVBii_' subID '_G-Ji']);
cd(out_fold)
load(['TVBiiOutput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], 'SC');
SCall(:,:,sub)=SC;
clear SC
load(['TVBiiInput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], 'SC_dist');
SCdistall(:,:,sub)=SC_dist;
clear SC_dist
end
SC_CONavg=mean(SCall, 3);
SCdist_CONavg=mean(SCdistall, 3);
%now run "Generate_TVBii_Input_v4.m"!
CONavg_fold=([main 'avgCON']);
cd(CONavg_fold)
save('SC_CONavg', 'SC_CONavg', 'SCdist_CONavg');
% Compare FCsim (using SCavg) to FCemp
main='/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/';
sublist=dir(main); sublist=sublist(3:38,:);
n=length(sublist);
for sub=1:n
% Load empirical data
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
in_fold = ([main subID '/TVBii_' subID '_G-Ji']);
load([in_fold '/TVBiiOutput_thrA_scale68_distLen.mat'], 'FC_emp_zv');
% Load simulated BOLD
sim_path=([main 'avgCON/TVBii_G-Ji/output']);
TS_sim = dlmread([sim_path '/BOLD_param_set_' num2str(sub) '.txt']);
TS_sim = TS_sim(end-179:end,:);
FC_sim = corr(TS_sim);
FC_sim = weight_conversion(FC_sim, 'autofix');
FC_sim_z = atanh(FC_sim);
upperIdx=ones([scale scale]);upperIdx=triu(upperIdx,1);len=length(find(upperIdx));
FC_sim_zv = reshape(FC_sim_z(~~upperIdx), [len 1]);
clear upperIdx len
% Correlate simulated and empirical BOLD
emp_sim_corP(sub,1) = corr(FC_emp_zv, FC_sim_zv);
emp_sim_corS(sub,1) = corr(FC_emp_zv, FC_sim_zv, 'Type', 'Spearman');
clear FC_* TS_sim in_fold out_fold
end
results_fold='/home/hannelore/Documents/ANALYSES/TVB_global2/results_TVBii';
cd(results_fold)
emp_sim_corP_CONavgSC=emp_sim_corP;
emp_sim_corS_CONavgSC=emp_sim_corS;
save('SanChecks_thrA', 'emp_sim_corP_CONavgSC', 'emp_sim_corS_CONavgSC', '-append');
% Difference between 2 distributions significant?
[h,p,ks2stat] = kstest2(emp_sim_corP_CONavgSC, TVBii_results_thrA(:,3))
% --> yes! ks2stat=0.4444, p=0.001
%% Sanity check 3: use average SC matrix to optimize indiv modelparams
% First get CON average SC weights & dist matrix
cd([TVB_fold 'avgCON']);
load('SC_CONavg', 'SC_CONavg');
% Compare FCsim (using SCavg) to FCemp
main='/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/';
sublist=dir(main);
n=length(sublist);
upperIdx=ones([scale scale]);upperIdx=triu(upperIdx,1);len=length(find(upperIdx));
% Initialise output
emp_sim_cor=nan(n,200);
for sub=1:n
% Load empirical data
subID = sublist(sub).name;
disp(['Processing ' subID]);
in_fold = ([main subID '/TVBii_' subID '_G-Ji']);
load([in_fold '/TVBiiOutput_thrA_scale68_distLen.mat'], 'FC_emp_zv');
% Load simulated BOLD
sim_path=([main 'avgCON/TVBii_G-Ji/output2']);
params_path=([main 'avgCON/TVBii_G-Ji/params2']);
paramslist=dir([params_path '/param_set_*']);
m=length(paramslist);
for index=1:m
% For now, only save correlation between FCsim & FCemp
TS_sim = dlmread([sim_path '/BOLD_param_set_' num2str(index) '.txt']);
TS_sim = TS_sim(end-179:end,:);
FC_sim = corr(TS_sim);
FC_sim = weight_conversion(FC_sim, 'autofix');
FC_sim_z = atanh(FC_sim);
FC_sim_zv = reshape(FC_sim_z(~~upperIdx), [len 1]);
% Correlate simulated and empirical BOLD
emp_sim_cor(sub, index) = corr(FC_emp_zv, FC_sim_zv);
% Clean up
clear TS* FC_sim*
end
clear FC_emp_zv
end
% Save output
output_fold=('/home/hannelore/Documents/ANALYSES/TVB_global2/results_TVBii');
cd(output_fold);
emp_sim_corP_CONavgSCparams=emp_sim_cor;
save('SanChecks_thrA.mat', 'emp_sim_corP_CONavgSCparams', '-append');
emp_sim_corP_CONavgSCparams_max = max(emp_sim_corP_CONavgSCparams');
save('SanChecks_thrA.mat', 'emp_sim_corP_CONavgSCparams_max', '-append');
% Difference between 2 distributions significant?
load([output_fold '/results_G-J_thrA.mat']);
[h,p,ks2stat] = kstest2(emp_sim_corP_CONavgSCparams_max, TVBii_results_thrA(:,3))
% --> not better, nor worse! ks2stat=0.1111, p=0.97
% Plot for couple of subjects distribution of G-cor to see whether same G
% values are obtained with both methods
sub='CON03T1' %n=3
sub='CON09T1' %n=9
sub='PAT03T1' %n=14
sub='PAT07T1' %n=18
load([main '/' sub '/TVBii_' sub '_G-Ji/TVBiiOutput_thrA_scale68_distLog.mat'], 'TVBii_PSE');
plot(TVBii_PSE(:,9), 'Linewidth', 2, 'Color', 'b')
hold on
plot(emp_sim_corP_CONavgSCparams(18,:), 'Linewidth', 2, 'Color', 'c')
legend('Subject-specific params & SC', 'CON avg SC + PSE')
legend('Location', 'southoutside'); legend('boxoff')
xlabel('G'); ylabel('Pearson correlation coefficient');
cd([output_fold '/individual plots'])
print([sub '_indivSC-avgSCpse'], '-dpng')
%% Check Ji distribution : skewed
J_avg=nan(n,1);
J_md=nan(n,1);
for tt = 2
tm = thr{tt};
for index=1:n
dm = 'Log';
scale = 68;
% Load data
subID=sublist(index).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
load([main subID '/TVBii_' subID '_G-Ji/TVBiiOutput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], 'Ji_max')
cd('/home/hannelore/Documents/ANALYSES/TVB_global2/results_TVBii/individual plots')
figure();hist(Ji_max)
%print([subID '_Ji_dist'], '-dpng');
J_avg(index,1)=mean(Ji_max);
J_md(index,1)=median(Ji_max);
clear Ji_max
end
end
%% Average Ji in vicinity of tumor
% Tumor nodes
DM_fold='/home/hannelore/Documents/ANALYSES/BTC_prepro/tumorrois_all.csv';
TVB_fold='/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/';
tumornodes=csvread(DM_fold, 1);
cd(TVB_fold);
sublist=dir(TVB_fold); sublist=sublist(3:end,:);
n=length(sublist);
for tt = 1:2
tm = thr{tt};
for sub=2:n
dm = 'Log';
% First get Ji values corresponding to max FCsim-FCemp
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
in_path = [TVB_fold subID '/TVBii_' subID '_G-Ji/'];
cd(in_path);
load([in_path 'TVBiiOutput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], 'TVBii_PSE', 'TVBii_Ji');
[maxval, maxind] = max(TVBii_PSE(:,9));
Ji_max = TVBii_Ji(:,maxind);
% Now identify tumor nodes
sub_tumornodes = find(tumornodes(:,sub));
Ji_tumornodes = Ji_max(sub_tumornodes,:);
J_tumornodes = mean(Ji_tumornodes);
J_tumornodes_allsubs(sub,1) = mean(Ji_tumornodes);
J_tumornodes_allsubs_md(sub,1) = median(Ji_tumornodes);
%save([in_path 'TVBiiOutput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], 'J_tumornodes', 'Ji_tumornodes', 'Ji_max', '-append');
clear subID in_path Ji_* J_tumornodes sub_tumornodes TVBii_PSE TVBii_Ji maxval maxind
end
clear J_tumornodes_allsubs*
end
clear tumornodes DM_fold
% Tumor nodes (random nodes for CON instead of MEN nodes)
DM_fold='/home/hannelore/Documents/ANALYSES/BTC_prepro/tumorrois_all_CONrandom.csv';
TVB_fold='/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/';
tumornodes=csvread(DM_fold, 1);
numberofrois=sum(tumornodes~=0,1)'
cd(TVB_fold);
sublist=dir(TVB_fold); sublist=sublist(3:end,:);
n=length(sublist);
for tt = 1:2
tm = thr{tt};
for sub=1:n
dm = 'Log';
% First get Ji values corresponding to max FCsim-FCemp
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
in_path = [TVB_fold subID '/TVBii_' subID '_G-Ji/'];
cd(in_path);
load([in_path 'TVBiiOutput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], 'TVBii_PSE', 'TVBii_Ji');
[maxval, maxind] = max(TVBii_PSE(:,9));
Ji_max = TVBii_Ji(:,maxind);
% Now identify tumor nodes
sub_tumornodes = find(tumornodes(:,sub));
Ji_tumornodes = Ji_max(sub_tumornodes,:);
J_tumornodes = mean(Ji_tumornodes);
J_tumornodes_allsubs(sub,1) = mean(Ji_tumornodes);
J_tumornodes_allsubs_md(sub,1) = median(Ji_tumornodes);
%save([in_path 'TVBiiOutput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], 'J_tumornodes', 'Ji_tumornodes', 'Ji_max', '-append');
clear subID in_path Ji_* J_tumornodes sub_tumornodes TVBii_PSE TVBii_Ji maxval maxind
end
clear J_tumornodes_allsubs*
end
clear tumornodes DM_fold
% Check median Ji in non-tumor regions
DM_fold='/home/hannelore/Documents/ANALYSES/BTC_prepro/tumorrois_all_CONrandom.csv';
TVB_fold='/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/';
tumornodes=csvread(DM_fold, 1);
numberofrois=sum(tumornodes~=0,1)'
cd(TVB_fold);
sublist=dir(TVB_fold); sublist=sublist(3:end,:);
n=length(sublist);
for tt = 1:2
tm = thr{tt};
for sub=1:n
dm = 'Log';
% First get Ji values corresponding to max FCsim-FCemp
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
in_path = [TVB_fold subID '/TVBii_' subID '_G-Ji/'];
cd(in_path);
load([in_path 'TVBiiOutput_' tm '_scale' num2str(scale) '_dist' dm '.mat'], 'TVBii_PSE', 'TVBii_Ji');
[maxval, maxind] = max(TVBii_PSE(:,9));
Ji_max = TVBii_Ji(:,maxind);
% Now identify tumor nodes
sub_nontumornodes = find(tumornodes(:,sub)==0);
Ji_nontumornodes = Ji_max(sub_nontumornodes,:);
J_nontumornodes_allsubs_md(sub,1) = median(Ji_nontumornodes);
clear subID in_path Ji_* sub_nontumornodes TVBii_PSE TVBii_Ji maxval maxind
end
clear J_tumornodes_allsubs*
end
clear tumornodes DM_fold
%% Check group differences in Ji_tumor persist when regressing out SC strength
main='/home/hannelore/Documents/ANALYSES/TVB_global2/subjects/';
sublist=dir(main); sublist=sublist(3:end,:);
n=length(sublist);
DM_fold='/home/hannelore/Documents/ANALYSES/BTC_prepro/tumorrois_all_CONrandom.csv';
tumornodes=csvread(DM_fold, 1);
tm='thrA'
dm='Log'
for sub=1:n
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
% Load Ji data corresponding to optimal G value
load([main subID '/TVBii_' subID '_G-Ji/TVBiiOutput_thrA_scale68_distLog.mat'], 'TVBii_PSE');
[maxcor, maxcorInd] = max(TVBii_PSE(:,9));
% Load Ji and SC strength values for corresponding max cor value of G
results_fold=([main subID '/TVBii_' subID '_G-Ji/output_thrA_scale68_distLog']);
J = dlmread([results_fold '/BOLD_param_set_' num2str(maxcorInd) '.txt']);
Ji = J(1:scale,2);
Ji_strength = J(1:scale,1);
B=regress(Ji, Ji_strength);
res(:,sub)=Ji-B*Ji_strength;
% Median JiBrain res
J_res(sub)=median(res(:,sub));
% Median JiTumor res
sub_tumornodes = find(tumornodes(:,sub));
JiT_res(sub) = median(res(sub_tumornodes,sub));
% Median JiNonTumor res
sub_nontumornodes = find(tumornodes(:,sub)==0);
JiNT_res(sub) = median(res(sub_nontumornodes,sub));
clear J TVBii_PSE B Ji Ji_strength
end
%% Check group differences in Ji_tumor persist when regressing out only ROI size
for sub=1:n
subID = sublist(sub).name;
disp(['Processing ' subID ' (scale' num2str(scale) ', ' tm ', dist' dm ')']);
% Load Ji data corresponding to optimal G value
load([main subID '/TVBii_' subID '_G-Ji/TVBiiOutput_thrA_scale68_distLog.mat'], 'TVBii_PSE');
[maxcor, maxcorInd] = max(TVBii_PSE(:,9));
% Load Ji and SC strength values for corresponding max cor value of G
results_fold=([main subID '/TVBii_' subID '_G-Ji/output_thrA_scale68_distLog']);
J = dlmread([results_fold '/BOLD_param_set_' num2str(maxcorInd) '.txt']);
Ji = J(1:scale,2);
Ji_strength = J(1:scale,1);
sub_roisize=RoiSize(:,sub);
X = sub_roisize;
[B,bint,res]=regress(Ji, X);
% Median JiBrain res
J_res3(sub)=median(res(:));
% Median JiTumor res
sub_tumornodes = find(tumornodes(:,sub));
JiT_res3(sub) = median(res(sub_tumornodes,:));
% Median JiNonTumor res
sub_nontumornodes = find(tumornodes(:,sub)==0);
JiNT_res3(sub) = median(res(sub_nontumornodes,:));
clear maxcor* res results_fold J TVBii_PSE B Ji Ji_strength
end