-
Notifications
You must be signed in to change notification settings - Fork 3
/
overwrite_script_level1.m
executable file
·80 lines (64 loc) · 2.58 KB
/
overwrite_script_level1.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
%
% CBS SPM preprocessing batch package -- Template Overwrite Script
% Created by Caitlin Carey
%
% This script overwrites filler variables generated by the template script.
%
%--------------------------------------------------------------------------
fprintf('Overwriting template preproc batch for %s %s\n',type,subject);
% these are taken from input
subjectNum = subject;
directoryPre = directory;
taskDir = task;
outFolder = outfold;
subjectType = type;
% creates subject directory path
if (strcmp(subjectType,'NONE'))
subjectDir = [directoryPre, subjectNum, '/'];
else
subjectDir = [directoryPre, type, '/', subjectNum, '/'];
end
% here i need to do some checking of the input...like if the analysis
% folder actually exists...
if (exist([subjectDir, outFolder], 'dir') == 7)
rmdir([subjectDir, outFolder],'s');
end
mkdir([subjectDir, outFolder]);
% determines number of runs
runs = length(dir([subjectDir,taskDir, 'run*']));
%--------------------------------------------------------------------------
% here i'm not sure if the batch numbers change...so we might need to
% finagle this a bit more
% if we dont have the correct number of runs, throw error
if (length(matlabbatch{1}.spm.stats.fmri_spec.sess) ~= runs)
error('TestRuns:WrongNum','Subject does not have expected number of runs.');
end
% creates structure of epis for each run
% need to make this more generic...
for i = 1:runs
try
fprintf('Grabbing functionals from %s.\n', [subjectDir, taskDir, 'run', num2str(i), '/']);
epis = strtrim(ls([subjectDir, taskDir, 'run', num2str(i), '/swrf*.img']));
catch
fprintf('Could not locate functionals in %s.\n', [subjectDir, taskDir, 'run', num2str(i), '/']);
rethrow(lasterror());
end
% checks that we have the correct number of epis
originallen = length(matlabbatch{1}.spm.stats.fmri_spec.sess(i).scans);
functionals = regexp(epis,'\n','split')';
% if not, throw error
if (length(functionals) ~= originallen)
error('TestEpis:WrongNum','Subject does not have expected number of epis.');
end
% if so, replace template epis
matlabbatch{1}.spm.stats.fmri_spec.sess(i).scans = functionals;
try
regressors = strtrim(ls([subjectDir, taskDir, 'run', num2str(i), '/rp_f*.txt']));
matlabbatch{1}.spm.stats.fmri_spec.sess(i).multi_reg = {regressors};
catch
fprintf('Could not locate regressors in %s.\n', [subjectDir, taskDir, 'run', num2str(i), '/']);
rethrow(lasterror());
end
end
% defines new output folder
matlabbatch{1}.spm.stats.fmri_spec.dir = {[subjectDir, outFolder]};