-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbf_group_batch.m
93 lines (84 loc) · 2.65 KB
/
bf_group_batch.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
function res = bf_group_batch(BF, S)
% Run a DAiSS batch on a group of subjects
% Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
% $Id$
%--------------------------------------------------------------------------
if nargin == 0
batchfile = cfg_files;
batchfile.tag = 'batchfile';
batchfile.name = 'Batch .mat or .m file';
batchfile.filter = '(.*.mat$)|(.*.m$)';
batchfile.num = [1 Inf];
batchfile.help = {'Select batch specification file.'};
batch = cfg_branch;
batch.tag = 'batch';
batch.name = 'Batch';
batch.val = {batchfile};
res = batch;
return
elseif nargin < 2
error('Two input arguments are required');
end
batchfile = char(S.batchfile);
if isequal(spm_file(batchfile, 'ext'), 'm')
cdir = pwd;
if ~isempty(spm_file(batchfile, 'path'))
try
cd(spm_file(batchfile, 'path'));
catch
% This is to allow the use of pipelines saved with DAiSS
% on different machines
tbxdir = fileparts(mfilename('fullpath'));
cd(tbxdir);
end
end
vars = who;
eval(spm_file(batchfile, 'basename'));
cd(cdir);
name = setdiff(who, [vars; {'vars'}]);
if numel(name)~= 1
error('Invalid batch specification');
end
matlabbatch = eval(char(name));
if ~isa(matlabbatch, 'cell')
error('Invalid batch specification');
end
elseif isequal(spm_file(batchfile, 'ext'), 'mat')
try
tmp = load(batchfile);
catch
tbxdir = fileparts(mfilename('fullpath'));
tmp = load(spm_file(batchfile, 'path', tbxdir));
end
name = fieldnames(tmp);
if numel(name)~= 1
error('Invalid batch specification');
end
matlabbatch = tmp.(char(name));
if ~isa(matlabbatch, 'cell')
error('Invalid batch specification');
end
else
error('Invalid batch specification');
end
try
matlabbatch{1}.spm.tools.beamforming;
[~, matlabbatch] = spm_jobman('harvest', matlabbatch);
catch
error('Invalid batch specification. DAiSS batch expected.');
end
res = cell(1, numel(BF));
for i = 1:numel(BF)
if isfield(matlabbatch{1}.spm.tools.beamforming, 'data');
D = spm_eeg_load(BF{i});
matlabbatch{1}.spm.tools.beamforming.data.D = {fullfile(D)};
dum = mkdir(D.path, [S.prefix 'BF']);
matlabbatch{1}.spm.tools.beamforming.data.dir = {fullfile(D.path, [S.prefix 'BF'])};
else
module = char(fieldnames(matlabbatch{1}.spm.tools.beamforming));
matlabbatch{1}.spm.tools.beamforming.(module).BF = BF(i);
end
out = spm_jobman('run', matlabbatch);
res(i) = out{end}.BF;
end