-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalm_from_excel.m
More file actions
232 lines (200 loc) · 8.05 KB
/
Copy pathpalm_from_excel.m
File metadata and controls
232 lines (200 loc) · 8.05 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
function [] = palm_from_excel(filename,rowNumber,varargin)
% Authors: John C. Williams, Tram N. B. Nguyen, and Philip N. Tubiolo
% Stony Brook University School of Medicine
% Albert Einstein College of Medicine
[~,~,raw] = xlsread(filename);
disp(['Running palm from file : ' filename '.']); pause(eps); drawnow;
disp(['Row number : ' num2str(rowNumber) ':']); pause(eps); drawnow;
disp(raw(rowNumber,:)'); pause(eps); drawnow;
MULTIPLE_FILE_DELIMITER = ';' ;
LABEL_STRINGS = {...
'Output Directory (-o)', ...
'Input Files (-i)', ...
'Masks (-m)',...
'Design matrix (-d)',...
't-Contrasts (-t)', ...
'T (TFCE)', ...
'numPermutations' ...
'ee/ise', ...
'corrcon', ...
'corrmod', ...
'npc', ...
'npccon', ...
'npcmod', ...
'logp', ...
'fdr', ...
'Surface Files (-s)', ...
'F-Contrasts (-f)', ...
'Additional options (no -)', ...
'tfce2d', ...
'Precision', ...
'savedof', ...
'savemetrics', ...
'saveglm' ...
};
labelRow = raw(1,:); % First row = labels
thisPalmCallRow = raw(rowNumber,:);
[~,~,matchColumns] = intersect(upper(LABEL_STRINGS),upper(labelRow),'stable');
col.outputDir = matchColumns(1);
col.inputFiles = matchColumns(2);
col.masks = matchColumns(3);
col.designMatrix = matchColumns(4);
col.t_contrasts = matchColumns(5);
col.TFCE = matchColumns(6);
col.numPermutations = matchColumns(7);
col.permType = matchColumns(8);
col.corrcon = matchColumns(9);
col.corrmod = matchColumns(10);
col.npc = matchColumns(11);
col.npccon = matchColumns(12);
col.npcmod = matchColumns(13);
col.logp = matchColumns(14);
col.fdr = matchColumns(15);
col.surfaceFiles = matchColumns(16);
col.F_contrasts = matchColumns(17);
col.additional_options = matchColumns(18);
col.tfce2d = matchColumns(19);
col.precision = matchColumns(20);
col.savedof = matchColumns(21);
col.savemetrics = matchColumns(22);
col.saveglm = matchColumns(23);
outputDir = thisPalmCallRow{1,col.outputDir};
inputFiles_text = thisPalmCallRow{1,col.inputFiles};
masks_text = thisPalmCallRow{1,col.masks};
designMatrix = thisPalmCallRow{1,col.designMatrix};
t_contrasts_text = thisPalmCallRow{1,col.t_contrasts};
permType_text = thisPalmCallRow{1,col.permType};
numPermutations = thisPalmCallRow{1,col.numPermutations};
text.T = thisPalmCallRow{1,col.TFCE};
text.corrcon = thisPalmCallRow{1,col.corrcon};
text.corrmod = thisPalmCallRow{1,col.corrmod};
text.npc = thisPalmCallRow{1,col.npc};
text.npccon = thisPalmCallRow{1,col.npccon};
text.npcmod = thisPalmCallRow{1,col.npcmod};
text.logp = thisPalmCallRow{1,col.logp};
text.fdr = thisPalmCallRow{1,col.fdr};
surfaceFiles_text = thisPalmCallRow{1,col.surfaceFiles};
F_contrasts_text = thisPalmCallRow{1,col.F_contrasts};
additional_options_text = thisPalmCallRow{1,col.additional_options};
text.tfce2d = thisPalmCallRow{1,col.tfce2d};
precision_text = thisPalmCallRow{1,col.precision};
text.savedof = thisPalmCallRow{1,col.savedof};
text.savemetrics = thisPalmCallRow{1,col.savemetrics};
text.saveglm = thisPalmCallRow{1,col.saveglm};
palmargs.permType = strcat('-' , lower(permType_text));
text_fieldnames = fieldnames(text);
for i = 1:length(text_fieldnames)
this_field = text_fieldnames{i};
if (strcmpi(this_field,text.(this_field)) == true)
palmargs.(this_field) = strcat({'-'}, this_field);
elseif ( isempty(text.(this_field)) == true || any(isnan(text.(this_field))) )
palmargs.(this_field) = [];
else
errorText = ['Invalid argument. ' 'Row: ' num2str(rowNumber) '. ' 'Argument: ' this_field '. \n' ...
'Passed option ' text.(this_field) ' is incorrect. \n' ...
'Option must either match argument name to enable ' '(' this_field ')' ', or the cell must be left empty to disable. \n'];
error(sprintf(errorText));
end
end
if (~isempty(inputFiles_text) && any(~isnan(inputFiles_text)))
inputFiles_text = strcat('-i;', {' '} , strrep(inputFiles_text,';','; -i;'));
inputFiles = strtrim(strsplit(inputFiles_text{1}, MULTIPLE_FILE_DELIMITER));
else
inputFiles = [];
end
if (~isempty(masks_text) && any(~isnan(masks_text)))
masks_text = strcat('-m;', {' '} , strrep(masks_text,';','; -m;'));
masks = strtrim(strsplit(masks_text{1}, MULTIPLE_FILE_DELIMITER));
else
masks = [];
end
if (~isempty(surfaceFiles_text) && any(~isnan(surfaceFiles_text)))
surfaceFiles_text_temp = strcat('-s;', {' '} , strrep(surfaceFiles_text,';','; -s;'));
surfaceFiles_temp = strtrim(strsplit(surfaceFiles_text_temp{1}, MULTIPLE_FILE_DELIMITER));
surfaceFiles_temp2 = cellfun(@strsplit,surfaceFiles_temp,'UniformOutput',false);
surfaceFiles = [surfaceFiles_temp2{:}];
else
surfaceFiles = [];
end
if (~isempty(t_contrasts_text) && any(~isnan(t_contrasts_text)))
t_contrasts_text = strcat('-t;', {' '} , strrep(t_contrasts_text,';','; -t;'));
t_contrasts = strtrim(strsplit(t_contrasts_text{1}, MULTIPLE_FILE_DELIMITER));
else
t_contrasts = [];
end
if (~isempty(F_contrasts_text) && any(~isnan(F_contrasts_text)))
F_contrasts_text = strcat('-f;', {' '} , strrep(F_contrasts_text,';','; -f;'));
F_contrasts = strtrim(strsplit(F_contrasts_text{1}, MULTIPLE_FILE_DELIMITER));
else
F_contrasts = [];
end
if (~isempty(precision_text) && any(~isnan(precision_text)))
precision_text = {'-precision', precision_text};
precision = strtrim(precision_text);
else
precision = [];
end
if (~isempty(additional_options_text) && any(~isnan(additional_options_text)))
additional_options_text = strcat('-', strrep(additional_options_text,'; ','; -'));
additional_options = strtrim(strsplit(additional_options_text, MULTIPLE_FILE_DELIMITER));
else
additional_options = [];
end
% outputDirEndChar = outputDir(end);
% if(~strcmpi(outputDirEndChar,filesep))
% outputDir(end+1) = filesep;
% end
palm_arg_cell = [ ...
inputFiles, ...
surfaceFiles, ...
masks, ...
{'-d'},{designMatrix}, ...
t_contrasts, ...
F_contrasts, ...
{'-n'},{numPermutations}, ...
{'-o'},{outputDir}, ...
palmargs.permType, ...
palmargs.T, ...
palmargs.tfce2d ...
palmargs.logp, ...
palmargs.fdr, ...
palmargs.npc, ...
palmargs.npccon, ...
palmargs.npcmod, ...
palmargs.corrcon, ...
palmargs.corrmod, ...
palmargs.savedof, ...
palmargs.savemetrics, ...
palmargs.saveglm, ...
precision, ...
additional_options ...
];
for i = 1:length(palm_arg_cell)
disp(palm_arg_cell{i}); pause(eps); drawnow;
end
palmString = 'palm';
for i = 1:length(palm_arg_cell)
palmString = [palmString ' ' palm_arg_cell{i}];
end
palmString = [palmString '\n\n'];
disp(palmString); pause(eps); drawnow;
if (isempty(varargin))
mkdir(outputDir); pause(eps); drawnow;
palm( palm_arg_cell{:} ); pause(eps); drawnow;
else
output_file_name = varargin{1};
appendToFile = false;
if (length(varargin) > 1)
checkAppend = varargin{2};
appendToFile = strcmpi(checkAppend,'-append');
end
if (~appendToFile)
permission = 'wt+';
else
permission = 'at+';
end
fid = fopen(output_file_name, permission); pause(eps); drawnow;
fprintf(fid, palmString); pause(eps); drawnow;
fclose(fid); pause(eps); drawnow;
end
end