-
Notifications
You must be signed in to change notification settings - Fork 1
/
Script_onepop.m
109 lines (68 loc) · 2.98 KB
/
Script_onepop.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
%% This is an example script to run the CAPs analyses without the GUI
% In this script, we assume one population of subjects only
addpath(genpath(pwd));
%% 1. Loading the data files
% Data: cell array, each cell of size n_TP x n_masked_voxels
TC =
% Mask: n_voxels x 1 logical vector
mask =
% Header: the header (obtained by spm_vol) of one NIFTI file with proper
% data dimension and .mat information
brain_info =
% Framewise displacement: a n_TP x n_subj matrix with framewise
% displacement information
FD =
% Seed: a n_masked_voxels x n_seed logical vector with seed information
Seed =
%% 2. Specifying the main parameters
% Threshold above which to select frames
T = 0.8;
% Selection mode ('Threshold' or 'Percentage')
SelMode = 'Threshold';
% Threshold of FD above which to scrub out the frame and also the t-1 and
% t+1 frames (if you want another scrubbing setting, directly edit the
% code)
Tmot = 0.5;
% Type of used seed information: select between 'Average','Union' or
% 'Intersection'
SeedType = 'Average';
% Contains the information, for each seed (each row), about whether to
% retain activation (1 0) or deactivation (0 1) time points
SignMatrix = [1,0];
% Percentage of positive-valued voxels to retain for clustering
Pp = 100;
% Percentage of negative-valued voxels to retain for clustering
Pn = 100;
% Number of repetitions of the K-means clustering algorithm
n_rep = 50;
% Percentage of frames to use in each fold of consensus clustering
Pcc = 80;
% Number of folds we run consensus clustering for
N = 50;
%% 3. Selecting the frames to analyse
% Xon will contain the retained frames, and Indices will tag the time
% points associated to these frames, for each subject (it contains a
% subfield for retained frames and a subfield for scrubbed frames)
[Xon,~,Indices] = CAP_find_activity(TC,Seed,T,FD,Tmot,SelMode,SeedType,SignMatrix);
%% 4. Consensus clustering (if wished to determine the optimum K)
% This specifies the range of values over which to perform consensus
% clustering: if you want to run parallel consensus clustering processes,
% you should feed in different ranges to each call of the function
K_range = 2:6;
% Have each of these run in a separate process on the server =)
[Consensus] = CAP_ConsensusClustering(Xon,K_range,'items',Pcc/100,N,'correlation');
% Calculates the quality metrics
[~,PAC] = ComputeClusteringQuality(Consensus,[]);
% Qual should be inspected to determine the best cluster number(s)
% You should fill this with the actual value
K_opt = 4;
%% 5. Clustering into CAPs
[CAP,~,~,idx] = Run_Clustering_Sim(cell2mat(Xon),...
K_opt,mask,brain_info,Pp,Pn,n_rep,[],SeedType);
%% 6. Computing metrics
% The TR of your data in seconds
TR = 2;
[ExpressionMap,Counts,Entries,Avg_Duration,Duration,TransitionProbabilities,...
From_Baseline,To_Baseline,Baseline_resilience,Resilience,Betweenness,...
InDegree,OutDegree,SubjectEntries] = Compute_Metrics_simpler(idx,...
Indices.kept.active,Indices.scrubbedandactive,K_opt,TR);