Skip to content

Commit b890ef6

Browse files
committed
Properly arranged directory
1 parent 36b8fe9 commit b890ef6

17 files changed

+578
-19
lines changed

power_calculator_test_script.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
create_test_fc_data_set()
1515
create_test_fc_atlas()
1616

17-
% edge_based_tests('test_hcp_fc.mat')
17+
edge_based_tests('test_hcp_fc.mat')
1818

19-
% network_based_tests('test_hcp_fc.mat')
19+
network_based_tests('test_hcp_fc.mat')
2020

21-
% data_inference_from_contrast_test()
21+
data_inference_from_contrast_test()
2222

2323
test_power_calculation_from_gt_and_data()
2424

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function atlas_file = atlas_data_set_map(Params)
2+
3+
atlas_ok = ~isnan(Params.atlas_file);
4+
5+
atlas_file = NaN;
6+
7+
disp(Params.data_set)
8+
9+
if atlas_ok
10+
atlas_file = Params.atlas_file;
11+
else
12+
13+
switch Params.data_set
14+
15+
case 'hcp_fc'
16+
17+
atlas_file = './atlas_storage/map268_subnetwork.mat';
18+
19+
case 'test_hcp_fc'
20+
21+
atlas_file = './atlas_storage/test_hcp_fc_atlas.mat';
22+
23+
end
24+
25+
end
26+
27+
%% Maybe we remove this? - Not everything requires an atlas
28+
if isnan(atlas_file)
29+
error('No atlas file found')
30+
end
31+
32+
end

test_scripts/.DS_Store

8 KB
Binary file not shown.

test_scripts/common_test_setup.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Params = common_test_setup(data_set_name)
2+
3+
%% Remove output folder if it exists
4+
if isfolder('./test_power_calculator/')
5+
rmdir('./test_power_calculator/', 's'); % 's' removes all subfolders and files
6+
end
7+
8+
Params = setparams();
9+
Params = setup_global_test_parameters(Params, data_set_name);
10+
11+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function create_test_fc_atlas()
2+
3+
% Define ROI mappings
4+
% newroi, oldroi, category, label, hemisphere
5+
newroi = [1; 2; 3; 4; 5];
6+
oldroi = [1; 2; 3; 4; 5];
7+
category = [1; 1; 1; 1; 2];
8+
label = ['Ef'; 'Ef'; 'Ef'; 'Ef'; 'Nf'];
9+
hemiphere = ['L'; 'L'; 'L'; 'L'; 'R'];
10+
11+
%% Convert to table
12+
% For now only map is available as an attribute
13+
map = table(newroi, oldroi, category, label, hemiphere);
14+
15+
% Save to file (optional)
16+
save('./atlas_storage/test_hcp_fc_atlas.mat', 'map');
17+
18+
end

test_scripts/create_test_fc_data_set.m

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,42 @@ function create_test_fc_data_set()
1010
%% Definition of the tast dataset description
1111
nodes = 5;
1212
variables = 10; % 5*(5 - 1)/2
13-
subject_number = 20; % 20 subs is enough
13+
subject_number = 50; % 50 subs is enough - since the matrices are quite small there should be no issues
1414

1515
%% Define study info - this is the test dataset to mimic hcp
1616
study_info.dataset = 'test_hcp';
1717
study_info.map = 'fc';
1818
study_info.test = 't';
19-
study_info.mask = triu(ones(nodes), 1);
20-
19+
study_info.mask = logical(triu(ones(nodes), 1));
20+
21+
outcome.test1.sub_ids = NaN;
22+
outcome.test1.score = NaN;
23+
outcome.test1.score_label = NaN;
2124
outcome.test1.contrast = {'TASK', 'REST'};
2225
outcome.test1.category = 'cognitive';
2326

27+
brain_data.TASK.motion = NaN;
28+
brain_data.REST.motion = NaN;
2429

25-
brain_data.TASK = zeros(variables, subject_number);
26-
for i = 1:subject_number
27-
brain_data.TASK(:, i) = [1, 1, 1, 1, 1, 0.5, 0.2, 0.8, 0, 0];
28-
end
30+
brain_data.TASK.sub_ids = (1:subject_number)' + 100000;
31+
brain_data.REST.sub_ids = (1:subject_number)' + 100000;
2932

33+
brain_data.TASK.data = zeros(variables, subject_number);
3034
for i = 1:subject_number
31-
brain_data.REST(:, i) = [-1, -1, -1, -1, -1, 0.5, 0.2, 0.8, 0, 0];
35+
brain_data.TASK.data(:, i) = [1, 1, 1, 1, 1, 1, 0.2, 0.8, 0.5, 0];
3236
end
3337

38+
brain_data.REST.data = zeros(variables, subject_number);
39+
for i = 1:subject_number
40+
brain_data.REST.data(:, i) = [-1, -1, -1, -1, -1, -1, 0.2, 0.8, 0.5, 0];
41+
end
42+
3443
data_dir = './data/';
3544
mkdir(data_dir);
3645

37-
file_name = './data/test_hpc_fc.mat';
46+
file_name = './data/test_hcp_fc.mat';
3847

3948
save(file_name, 'brain_data', 'study_info', 'outcome');
4049

41-
end
50+
end
51+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function data_inference_from_contrast_test()
2+
3+
% Run tests for different subject configurations
4+
% total overlap - t test case
5+
[TestData, BrainData, RP] = test_test_type_inference(...
6+
[1, 2, 3, 4, 5, 6, 7, 8], [5, 6, 7, 8, 1, 2, 3, 4]); % High overlap
7+
test_data_retrieval(TestData, BrainData, RP);
8+
9+
% High Overlap - `t` test case (should classify as `t`)
10+
% High overlap, but not identical
11+
[TestData, BrainData, RP] = test_test_type_inference(...
12+
[1, 2, 3, 4, 5, 6, 7, 8], [4, 5, 6, 7, 8, 9, 10, 11]);
13+
test_data_retrieval(TestData, BrainData, RP);
14+
15+
% No overlap t2 test case
16+
[TestData, BrainData, RP] = test_test_type_inference(...
17+
[1, 2, 3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14, 15, 16]); % No overlap
18+
test_data_retrieval(TestData, BrainData, RP);
19+
20+
% `t` vs `t2` (Partial Overlap)
21+
[TestData, BrainData, RP] = test_test_type_inference(...
22+
[1, 2, 3, 4, 5, 6, 7, 8], [5, 6, 7, 8, 9, 10, 11, 12]);
23+
test_data_retrieval(TestData, BrainData, RP);
24+
25+
end

test_scripts/edge_based_tests.m

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function edge_based_tests(data_set_name)
2+
3+
Params = common_test_setup(data_set_name);
4+
5+
stat_method_cell = {'Parametric_Bonferroni', 'Parametric_FDR', 'Size', 'TFCE'};
6+
7+
Params.all_cluster_stat_types = stat_method_cell;
8+
9+
Params = setup_global_test_parameters(Params, data_set_name);
10+
11+
rep_cal_function(Params)
12+
13+
ResData = unite_results_from_directory('directory', './test_power_calculator/');
14+
15+
for i = 1:length(stat_method_cell)
16+
method = stat_method_cell{i};
17+
18+
% The query is based on how the dataset is created
19+
query = {'testing', 'test_hcp', 'REST_TASK', method, 'subs_40', 'brain_data'};
20+
21+
brain_data = getfield(ResData, query{:});
22+
23+
pvals = brain_data.pvals_all;
24+
25+
% I think I need to add the power calculator scripts too - just to
26+
% make sure
27+
28+
% Ensure first row is all zeros
29+
error_effect = sprintf('Network-Level Test Failed in Method %s: Effect not detected', method);
30+
error_non_effect = sprintf('Network-Level Test Failed in Method %s: Effect detected', method);
31+
32+
% Check for significant p-values where an effect is expected (rows 1 to 6)
33+
for row = 1:6
34+
assert(all(pvals(row, :) <= 0.05), error_effect);
35+
end
36+
37+
% Check for non-significant p-values where no effect is expected (rows 7 to 10)
38+
for row = 7:10
39+
assert(all(pvals(row, :) == 1), error_non_effect);
40+
end
41+
42+
end
43+
44+
end
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
function generate_synthetic_gt_data()
2+
% Directory where synthetic ground truth files will be saved
3+
output_dir = './test_power_calculator/ground_truth/';
4+
5+
% Ensure directory exists
6+
if ~exist(output_dir, 'dir')
7+
mkdir(output_dir);
8+
end
9+
10+
% Set fixed number of edges and networks (same as the test data)
11+
num_edges = 10; % Example: 100 edges for edge-level tests
12+
num_networks = 4; % Example: 10 networks for network-level tests
13+
14+
% Define split points for assigning 25% and 25%-50% ranges
15+
split_25_edges = round(0.25 * num_edges);
16+
split_50_edges = round(0.50 * num_edges);
17+
split_25_networks = round(0.25 * num_networks);
18+
split_50_networks = round(0.50 * num_networks);
19+
20+
% Common metadata fields for both edge and network level tests
21+
meta_data = struct();
22+
meta_data.dataset = 'synthetic_test';
23+
meta_data.map = 'mock_map';
24+
meta_data.test = 'synthetic'; % Placeholder test type
25+
meta_data.test_components = {'REST', 'TASK'};
26+
meta_data.omnibus = 'none';
27+
meta_data.subject_number = 40; % Fixed subject number for testing
28+
meta_data.testing_code = 1; % Indicator for test mode
29+
meta_data.run_time = rand() * 10; % Fake runtime
30+
meta_data.date = '1990-04-27';
31+
32+
% ----- Edge-Level Ground Truth -----
33+
brain_data = struct();
34+
brain_data.edge_stats_all = zeros(num_edges, 1);
35+
brain_data.edge_stats_all_neg = zeros(num_edges, 1);
36+
37+
% Assign 25% of edges as positive true positives
38+
brain_data.edge_stats_all(1:split_25_edges) = abs(randn(split_25_edges, 1)) + 1e-5;
39+
% Assign next 25% of edges as negative true positives
40+
brain_data.edge_stats_all(split_25_edges+1:split_50_edges) = ...
41+
-abs(randn(split_50_edges - split_25_edges, 1)) - 1e-5;
42+
43+
% Set `edge_stats_all_neg` explicitly to match but with reversed sign
44+
brain_data.edge_stats_all_neg = -brain_data.edge_stats_all;
45+
46+
47+
% Update meta_data for edge-level test
48+
meta_data.test_type = 'Parametric_Bonferroni'; % Edge-level method
49+
50+
% Save edge-level ground truth
51+
filename_edge = sprintf('%sgt_synthetic_edge.mat', output_dir);
52+
save(filename_edge, 'brain_data', 'meta_data');
53+
54+
% ----- Network-Level Ground Truth -----
55+
brain_data = struct();
56+
brain_data.cluster_stats_all = zeros(num_networks, 1);
57+
brain_data.cluster_stats_all_neg = zeros(num_networks, 1);
58+
59+
% ----- Network-Level GT Fix -----
60+
% Assign 25% of networks as positive true positives
61+
brain_data.cluster_stats_all(1:split_25_networks) = abs(randn(split_25_networks, 1)) + 1e-5;
62+
% Assign next 25% of networks as negative true positives
63+
brain_data.cluster_stats_all(split_25_networks+1:split_50_networks) = ...
64+
-abs(randn(split_50_networks - split_25_networks, 1)) - 1e-5;
65+
66+
% Set `cluster_stats_all_neg` explicitly to match but with reversed sign
67+
brain_data.cluster_stats_all_neg = -brain_data.cluster_stats_all;
68+
69+
% Update meta_data for network-level test
70+
meta_data.test_type = 'Constrained'; % Network-level method
71+
72+
% Save network-level ground truth
73+
filename_network = sprintf('%sgt_synthetic_network.mat', output_dir);
74+
save(filename_network, 'brain_data', 'meta_data');
75+
76+
end
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
function generate_synthetic_power_data()
2+
% Directory where synthetic test files will be saved
3+
output_dir = './test_power_calculator/';
4+
5+
% Ensure directory exists
6+
if ~exist(output_dir, 'dir')
7+
mkdir(output_dir);
8+
end
9+
10+
% Define test types based on whether they are edge-level or network-level
11+
edge_level_tests = {'Parametric_Bonferroni', 'Parametric_FDR', 'Size', 'TFCE'};
12+
network_level_tests = {'Constrained', 'Constrained_FWER'};
13+
14+
% Set fixed number of edges and networks (arbitrary for synthetic testing)
15+
num_edges = 10; % Example: 100 edges for edge-level tests
16+
num_networks = 4; % Example: 10 networks for network-level tests
17+
n_repetitions = 100; % Number of repetitions for power calculation
18+
19+
% Compute split for 25% of elements
20+
split_25_edges = floor(num_edges * 0.25);
21+
split_25_networks = floor(num_networks * 0.25);
22+
23+
% Loop through each test type
24+
for test_type = [edge_level_tests, network_level_tests]
25+
tt = test_type{1}; % Extract string
26+
27+
% Generate mock brain_data structure
28+
brain_data = struct();
29+
30+
if ismember(tt, edge_level_tests)
31+
% Edge-level test: p-values should match number of edges
32+
brain_data.edge_stats_all = randn(num_edges, n_repetitions);
33+
brain_data.edge_stats_all_neg = randn(num_edges, n_repetitions);
34+
brain_data.cluster_stats_all = []; % Not used for edge tests
35+
brain_data.cluster_stats_all_neg = [];
36+
37+
% Initialize arrays with non-significant values (>0.5)
38+
brain_data.pvals_all = 0.6 * ones(num_edges, n_repetitions);
39+
brain_data.pvals_all_neg = 0.6 * ones(num_edges, n_repetitions);
40+
41+
% Ensure 25% power: In 25% of repetitions, p-value is set to zero (significant)
42+
for rep = 1:n_repetitions
43+
if mod(rep, 4) == 0 % Every 4th repetition should have significant results
44+
brain_data.pvals_all([1, 2, 3], rep) = 0; % Positive detections
45+
brain_data.pvals_all_neg([4, 5], rep) = 0; % Negative detections
46+
end
47+
end
48+
49+
elseif ismember(tt, network_level_tests)
50+
% Network-level test: p-values should match number of networks
51+
brain_data.edge_stats_all = []; % Not used for network tests
52+
brain_data.edge_stats_all_neg = [];
53+
brain_data.cluster_stats_all = randn(num_networks, n_repetitions);
54+
brain_data.cluster_stats_all_neg = randn(num_networks, n_repetitions);
55+
56+
% Initialize arrays with non-significant values (>0.5)
57+
brain_data.pvals_all = 0.6 * ones(num_networks, n_repetitions);
58+
brain_data.pvals_all_neg = 0.6 * ones(num_networks, n_repetitions);
59+
60+
% Ensure 25% power: In 25% of repetitions, p-value is set to zero (significant)
61+
for rep = 1:n_repetitions
62+
if mod(rep, 4) == 0 % Every 4th repetition should have significant results
63+
brain_data.pvals_all(1:split_25_networks, rep) = 0;
64+
brain_data.pvals_all_neg(split_25_networks+1:2*split_25_networks, rep) = 0;
65+
end
66+
end
67+
end
68+
69+
% Ensure mutual exclusivity: no index should be zero in both p-values
70+
invalid_indices = (brain_data.pvals_all == 0 & brain_data.pvals_all_neg == 0);
71+
brain_data.pvals_all(invalid_indices) = rand(sum(invalid_indices, 'all'), 1);
72+
73+
% Generate mock meta_data
74+
meta_data = struct();
75+
meta_data.dataset = 'synthetic_test';
76+
meta_data.map = 'mock_map';
77+
meta_data.test = 'synthetic'; % Placeholder test type
78+
meta_data.test_components = {'REST', 'TASK'};
79+
meta_data.omnibus = NaN;
80+
meta_data.subject_number = 40; % Single fixed subject number
81+
meta_data.testing_code = 1; % Indicator for test mode
82+
meta_data.test_type = tt; % Critical test type distinction
83+
meta_data.run_time = rand() * 10; % Fake runtime
84+
85+
% Add critical power calculation parameters
86+
meta_data.rep_parameters.pthresh_second_level = 0.05; % FWER/FDR threshold
87+
meta_data.rep_parameters.n_repetitions = n_repetitions; % Number of repetitions
88+
89+
% Generate filename
90+
filename = sprintf('%ssynthetic_%s.mat', output_dir, tt);
91+
92+
% Save synthetic data
93+
save(filename, 'brain_data', 'meta_data');
94+
95+
end
96+
97+
end

0 commit comments

Comments
 (0)