forked from fieldtrip/fieldtrip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinspect_bug1937.m
121 lines (79 loc) · 3.06 KB
/
inspect_bug1937.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
function inspect_bug1937
% WALLTIME 00:10:00
% MEM 1gb
% DEPENDENCY ft_connectivitysimulation ft_freqanalysis_mvar qsubfeval qsubget
% DATA no
% alebac, 19 Mar 2014: added support "waitfor" for multiple jobs
prevdir = pwd;
tmpdir = tempname(getenv('HOME'));
mkdir(tmpdir);
cd(tmpdir);
nSubjects = 4;
%% generate some data, similar to connectivitextended tutorial
cfg1 = [];
cfg1.ntrials = 10;
cfg1.triallength = 1;
cfg1.fsample = 200;
cfg1.nsignal = 3;
cfg1.method = 'ar';
cfg1.params(:, :, 1) = [ 0.8 0 0;0 0.9 0.5;0.4 0 0.5];
cfg1.params(:, :, 2) = [-0.5 0 0;0 -0.8 0;0 0 -0.2];
cfg1.noisecov = [0.3 0 0;0 1 0;0 0 0.2];
data = ft_connectivitysimulation(cfg1);
% save the data in a temporary directory in your home
save('data.mat', 'data', '-v7.3');
clear data cfg
%% step 1a - simple preproc
cfg1 = cell(1, nSubjects);
for iSubj = 1:nSubjects
cfg1{iSubj} = [];
cfg1{iSubj}.bpfilter = 'yes';
cfg1{iSubj}.bpfreq = [3 30];
cfg1{iSubj}.inputfile = 'data.mat';
cfg1{iSubj}.outputfile = sprintf('S%02d_data.mat', iSubj);
end
% do a sanity check without distributed computing
% data = ft_preprocessing(cfg1{1});
%% step 1b - submit the job to torque
joblist1 = cellfun(@qsubfeval, ...
repmat({'ft_preprocessing'}, [1 nSubjects]), ...
cfg1, ...
repmat({'memreq'}, [1 nSubjects]), num2cell(repmat(30*(1024^2), [1 nSubjects])), ...
repmat({'timreq'}, [1 nSubjects]), num2cell(repmat(30, [1 nSubjects])), ...
'UniformOutput', false);
%% step 2a
cfg2 = cell(1, nSubjects);
for iSubj = 1:nSubjects
cfg2{iSubj} = [];
cfg2{iSubj}.method = 'mtmfft';
cfg2{iSubj}.taper = 'hanning';
cfg2{iSubj}.inputfile = sprintf('S%02d_data.mat', iSubj);
cfg2{iSubj}.outputfile = sprintf('S%02d_freq.mat', iSubj);
end
% do a sanity check without distributed computing
% freq = ft_freqanalysis(cfg2{1});
%% step 2b - submit the job to torque
joblist2 = cellfun(@qsubfeval, ...
repmat({'ft_freqanalysis'}, [1 nSubjects]), ...
cfg2, ...
repmat({'memreq'}, [1 nSubjects]), num2cell(repmat(10*(1024^2), [1 nSubjects])), ...
repmat({'timreq'}, [1 nSubjects]), num2cell(repmat(30, [1 nSubjects])), ...
repmat({'waitfor'}, [1 nSubjects]), joblist1, ...
'UniformOutput', false);
%% step 3a - second level analysis
cfg3 = [];
for iSubj = 1:nSubjects
cfg3.inputfile{iSubj} = sprintf('S%02d_freq.mat', iSubj);
end
cfg3.outputfile = 'grandavg.mat';
% do a sanity check without distributed computing
% grandavg = ft_freqgrandaverage(cfg3)
%% step 3b - submit the job to torque
% should wait for all single subject jobs of step 2 are completed
joblist3 = qsubfeval(@ft_freqgrandaverage, cfg3,'memreq',1*(1024^3),'timreq',60,'waitfor',joblist2);
%% cleanup
[dum1, options1] = cellfun(@qsubget, joblist1, repmat({'output'}, [1 nSubjects]), repmat({'cell'}, [1 nSubjects]), 'UniformOutput', false);
[dum2, options2] = cellfun(@qsubget, joblist2, repmat({'output'}, [1 nSubjects]), repmat({'cell'}, [1 nSubjects]), 'UniformOutput', false);
[dum3, options3] = qsubget(joblist3,'output','cell');
cd(prevdir);
rmdir(tmpdir, 's');