-
Notifications
You must be signed in to change notification settings - Fork 0
/
abcd_perm_agg.m
executable file
·113 lines (87 loc) · 5.21 KB
/
abcd_perm_agg.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
% abcd_perm_agg.m
% Written by Nikhil Goyal, National Institute of Mental Health, 2019-2020
% Created: 7/1/2020
% Modified: 7/10/20 (modified to accomodate the outputs of the updated abcd_cca_batch.m which reduces the amount of data in each .mat file)
% Script is used in batch processing to calculate CCA for each of the 100,000 permutations we generate
function abcd_perm_agg(perms_per_batch_in, N_perm_in, N_dim_in, abcd_cca_dir, n_subs_in)
if nargin<5
sprintf("ERROR, not enough arguments.")
sprintf("Example: abcd_perm_agg(2000, 100000, 70, '/data/ABCD_MBDU/goyaln2/abcd_cca_replication/', 5013)")
return
end
if ~isdeployed
addpath(genpath(sprintf('%s/dependencies/', abcd_cca_dir)));
addpath(genpath(sprintf('%s/data/', abcd_cca_dir)));
perms_per_batch = perms_per_batch_in;
N_perm = N_perm_in;
N_dim = N_dim_in;
n_subs = n_subs_in;
elseif isdeployed
% When compiled matlab, it reads the command line args all as strings so we need to convert
perms_per_batch = str2num(perms_per_batch_in);
N_perm = str2num(N_perm_in);
N_dim = str2num(N_dim_in);
n_subs = str2num(n_subs_in);
end
r_agg = [];
nullNETv_prctile_95_agg = [];
nullNETv_prctile_5_agg = [];
nullNETv_mean_agg = [];
nullNETv_std_agg = [];
nullSMv_prctile_95_agg = [];
nullSMv_prctile_5_agg = [];
nullSMv_mean_agg = [];
nullSMv_std_agg = [];
nullNETr_prctile_95_agg = [];
nullSMr_prctile_95_agg = [];
nullNETr_std_agg = [];
nullSMr_std_agg = [];
for perm = 1:perms_per_batch:N_perm
% Iterate over 1 = 1, 1001, 2001, .... 99001
% filename of .mat files we need to load are of form permutations_<#>.mat
f_name = sprintf('%s/data/%d/permutations/permutations_%d.mat',abcd_cca_dir, n_subs, perm);
% Load the .mat file
mat_file = load(f_name);
r_agg = [r_agg; mat_file.s(1).r ];
nullNETv_prctile_95_agg = [nullNETv_prctile_95_agg; mat_file.s(1).nullNETv_prctile_95 ];
nullNETv_prctile_5_agg = [nullNETv_prctile_5_agg; mat_file.s(1).nullNETv_prctile_5 ];
nullNETv_mean_agg = [nullNETv_mean_agg; mat_file.s(1).nullNETv_mean ];
nullNETv_std_agg = [nullNETv_std_agg; mat_file.s(1).nullNETv_std];
nullSMv_prctile_95_agg = [nullSMv_prctile_95_agg; mat_file.s(1).nullSMv_prctile_95 ];
nullSMv_prctile_5_agg = [nullSMv_prctile_5_agg; mat_file.s(1).nullSMv_prctile_5 ];
nullSMv_mean_agg = [nullSMv_mean_agg; mat_file.s(1).nullSMv_mean ];
nullSMv_std_agg = [nullSMv_std_agg; mat_file.s(1).nullSMv_std];
nullNETr_prctile_95_agg = [nullNETr_prctile_95_agg; mat_file.s(1).nullNETr_prctile_95 ];
nullSMr_prctile_95_agg = [nullSMr_prctile_95_agg; mat_file.s(1).nullSMr_prctile_95 ];
nullNETr_std_agg = [nullNETr_std_agg; mat_file.s(1).nullNETr_std];
nullSMr_std_agg = [nullSMr_std_agg; mat_file.s(1).nullSMr_std];
end
s_agg = struct( 'perms_per_batch', {}, ...
'tot_perms', {}, ...
'nullNETv_prctile_95', {}, ...
'nullNETv_prctile_5', {}, ...
'nullNETv_mean', {}, ...
'nullSMv_prctile_95', {}, ...
'nullSMv_prctile_5', {}, ...
'nullSMv_mean', {}, ...
'nullNETr_prctile_95', {}, ...
'nullSMr_prctile_95', {}, ...
'r', {} );
s_agg(1).perms_per_batch = perms_per_batch;
s_agg(1).tot_perms = N_perm;
s_agg(1).nullNETv_prctile_95 = mean( nullNETv_prctile_95_agg,1);
s_agg(1).nullNETv_prctile_5 = mean( nullNETv_prctile_5_agg,1);
s_agg(1).nullNETv_mean = mean( nullNETv_mean_agg, 1);
s_agg(1).nullNETv_std = mean(nullNETv_std_agg, 1);
s_agg(1).nullSMv_prctile_95 = mean( nullSMv_prctile_95_agg, 1);
s_agg(1).nullSMv_prctile_5 = mean( nullSMv_prctile_5_agg, 1);
s_agg(1).nullSMv_mean = mean( nullSMv_mean_agg, 1);
s_agg(1).nullSMv_std = mean(nullSMv_std_agg, 1);
s_agg(1).nullNETr_prctile_95 = prctile( max(abs(nullNETr_prctile_95_agg)), 95);
s_agg(1).nullSMr_prctile_95 = prctile( max(abs(nullSMr_prctile_95_agg)), 95);
s_agg(1).r = r_agg;
s_agg(1).nullNETr_std = mean(nullNETr_std_agg, 1);
s_agg(1).nullSMr_std = mean(nullSMr_std_agg, 1);
% Now save
save(sprintf('%s/data/%d/permutation_data.mat', abcd_cca_dir, n_subs), 's_agg');
end