-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunpsy_sbps.m
84 lines (68 loc) · 2.22 KB
/
funpsy_sbps.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
function psess=funpsy_sbps(cfg)
%FUNPSY_SBPS Takes a list of seeds/ROIs and computes full differential phase synchrony between each pair of seeds/ROIs
% psess=funpsy_sbps(cfg) stores the results in psess.results.sbps
% 'cfg' is a struct with mandatory and optional fields
% cfg.sessionfile=string with the path of the sessionfile
% cfg.rois=string array with a list of ROIs, at least 2 needed
% OPTIONAL:
% cfg.pairwise=1
%% COPYRIGHT NOTICE
% IF YOU EDIT OR REUSE PART OF THE BELOW PLEASE DO NOT RE-DISTRIBUTE WITHOUT NOTIFYING THE ORIGINAL AUTHOR
% IF YOU PUBLISH PLEASE QUOTE THE ORIGINAL ARTICLE
%%
processID='funpsy_sbps>>>';
load(cfg.sessionfile)
% Test: does the session file exist?
psess=funpsy_loadsession(cfg,processID); % also loads the session file
% Test: was the session initialized?
funpsy_testinit(psess,processID);
% Test: was the analytic signal created?
funpsy_testAS(psess,processID);
% Test: do we already have the roi data?
funpsy_testROIdata(psess,processID);
%% FUNCTION SPECIFIC PARAMETERS TEST
% more to be added
%% cfg.overwrite
% Did we compute SBPS already? Should we recompute it?
isinit=0;
if(isfield(psess.history,'sbps'))
if(psess.history.sbps == 1)
isinit=1;
end
end
overexists=isfield(cfg,'overwrite');
overwrite=0;
if(overexists==1)
overwrite=cfg.overwrite;
end
if(isinit==1 && overwrite == 1)
fprintf('%s\n',[processID 'The SBPS data will be overwritten.'])
psess.history.svps=0;
end
if(isinit==1 && overwrite == 0)
fprintf('%s\n',[processID 'SBPS data exist and will not be overwritten.']);
return
end
%% Processing
R=length(psess.rois);
data=zeros(psess.T,R,psess.Nsubj);
for sub=1:psess.Nsubj
disp(num2str(sub))
for r=1:R
temp=load([psess.roidata{sub} '/' num2str(r) '.mat']);
data(:,r,sub)=angle(temp.roits);
end
end
outpath=[psess.outpath 'results/sbps/'];
disp('Creating folder')
mkdir(outpath)
% to add here a check if matlabpool is open
parfor roi=1:(R-1)
funpsy_parsbps(roi,outpath,psess,data)
end
fprintf('\n%s\n',[processID 'Seed based phase synchrony computed'])
psess.history.sbps=1;
psess.results.sbps=outpath;
disp([processID 'Updating session: ' psess.session_name]);
save(psess.sessionfile,'psess');
disp([processID '...done']);