0001 function varargout = prt_ui_compute_weights(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 gui_Singleton = 1;
0037 gui_State = struct('gui_Name', mfilename, ...
0038 'gui_Singleton', gui_Singleton, ...
0039 'gui_OpeningFcn', @prt_ui_compute_weights_OpeningFcn, ...
0040 'gui_OutputFcn', @prt_ui_compute_weights_OutputFcn, ...
0041 'gui_LayoutFcn', [] , ...
0042 'gui_Callback', []);
0043 if nargin && ischar(varargin{1})
0044 gui_State.gui_Callback = str2func(varargin{1});
0045 end
0046
0047 if nargout
0048 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0049 else
0050 gui_mainfcn(gui_State, varargin{:});
0051 end
0052
0053
0054
0055
0056 function prt_ui_compute_weights_OpeningFcn(hObject, eventdata, handles, varargin)
0057
0058
0059
0060
0061
0062
0063
0064 handles.output = hObject;
0065
0066
0067 Tag='weights';
0068 F = findall(allchild(0),'Flat','Tag',Tag);
0069 if length(F) > 1
0070
0071 close(F(2:end))
0072 F = F(1);
0073 uistack(F,'top')
0074 elseif length(F)==1
0075 uistack(F,'top')
0076 else
0077 set(handles.figure1,'Tag',Tag)
0078
0079 set(handles.figure1,'Name','PRoNTo :: Compute weights')
0080
0081 S0= spm('WinSize','0',1);
0082 if ispc
0083 PF='MS Sans Serif';
0084 else
0085 PF= spm_platform('fonts');
0086 PF=PF.helvetica;
0087 end
0088 tmp = [S0(3)/1280 (S0(4))/800];
0089 ratio=min(tmp)*[1 1 1 1];
0090 FS = 1 + 0.85*(min(ratio)-1);
0091 x=get(handles.figure1,'Position');
0092 set(handles.figure1,'DefaultTextFontSize',FS*12,...
0093 'DefaultUicontrolFontSize',FS*12,...
0094 'DefaultTextFontName',PF,...
0095 'DefaultAxesFontName',PF,...
0096 'DefaultUicontrolFontName',PF)
0097 set(handles.figure1,'Position',ratio.*x)
0098 set(handles.figure1,'Resize','on')
0099
0100 color=prt_get_defaults('color');
0101 set(handles.figure1,'Color',color.bg1)
0102 aa=get(handles.figure1,'children');
0103 for i=1:length(aa)
0104 if strcmpi(get(aa(i),'type'),'uipanel')
0105 set(aa(i),'BackgroundColor',color.bg2)
0106 bb=get(aa(i),'children');
0107 if ~isempty(bb)
0108 for j=1:length(bb)
0109 if ~isempty(find(strcmpi(get(bb(j),'Style'),{'text',...
0110 'radiobutton','checkbox'})))
0111 set(bb(j),'BackgroundColor',color.bg2)
0112 elseif ~isempty(find(strcmpi(get(bb(j),'Style'),'pushbutton')))
0113 set(bb(j),'BackgroundColor',color.fr)
0114 end
0115 set(bb(j),'FontUnits','pixel')
0116 xf=get(bb(j),'FontSize');
0117 set(bb(j),'FontSize',ceil(FS*xf),'FontName',PF,...
0118 'FontUnits','normalized','Units','normalized')
0119 end
0120 end
0121 elseif strcmpi(get(aa(i),'type'),'uicontrol')
0122 if ~isempty(find(strcmpi(get(aa(i),'Style'),{'text',...
0123 'radiobutton','checkbox'})))
0124 set(aa(i),'BackgroundColor',color.bg1)
0125 elseif ~isempty(find(strcmpi(get(aa(i),'Style'),'pushbutton')))
0126 set(aa(i),'BackgroundColor',color.fr)
0127 end
0128 end
0129 set(aa(i),'FontUnits','pixel')
0130 xf=get(aa(i),'FontSize');
0131 set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0132 'Units','normalized')
0133 end
0134
0135
0136 set(handles.flag_cwi,'Value',0);
0137 set(handles.flag_cwi,'Visible','off');
0138 set(handles.flag_cwi,'Enable','off');
0139 handles.flag = 0;
0140 set(handles.compbutt,'Enable','off')
0141 handles.img_name=[];
0142 handles.flag2 = 0;
0143 handles.atl_name = [];
0144 set(handles.edit_atlas,'Enable','off')
0145 set(handles.br_atlas,'Enable','off')
0146 set(handles.build_ROI_flag2,'Value',0)
0147 end
0148
0149 guidata(hObject, handles);
0150
0151
0152
0153
0154
0155
0156 function varargout = prt_ui_compute_weights_OutputFcn(hObject, eventdata, handles)
0157
0158
0159
0160
0161
0162
0163 varargout{1} = handles.output;
0164
0165
0166
0167 function edit_prt_Callback(hObject, eventdata, handles)
0168
0169
0170
0171
0172
0173
0174 handles.fname=get(handles.edit_prt,'String');
0175 handles.prtdir=fileparts(handles.fname);
0176 if exist('PRT','var')
0177 clear PRT
0178 end
0179 PRT=prt_load(handles.fname);
0180 if ~isempty(PRT)
0181 handles.dat=PRT;
0182 else
0183 beep
0184 disp('Could not load file')
0185 return
0186 end
0187
0188 if ~isfield(handles.dat,'model')
0189 beep
0190 disp('No model found in this PRT')
0191 disp('Please specify model first')
0192 delete(handles.figure1)
0193 end
0194
0195 handles.indm=[];
0196 for m = 1:length(handles.dat.model)
0197 if isfield(handles.dat.model(m),'input') && ~isempty(handles.dat.model(m).input)
0198 if isfield(handles.dat.model(m),'output') && ~isempty(handles.dat.model(m).output)
0199 handles.indm=[handles.indm,m];
0200 end
0201 end
0202 end
0203
0204 if isempty(handles.indm)
0205 beep
0206 disp('No model computed in this PRT')
0207 disp('Please specify AND run model before computing weights')
0208 return
0209 end
0210
0211 list={handles.dat.model(:).model_name};
0212 set(handles.pop_models,'String',list(handles.indm))
0213 set(handles.pop_models,'Value',1)
0214 handles.selmod=handles.indm(1);
0215 set(handles.compbutt,'Enable','on')
0216 in = struct();
0217 im = handles.indm(1);
0218 in.fs_name = handles.dat.model(im).input.fs(1).fs_name;
0219 fid = prt_init_fs(handles.dat,in);
0220 if isfield(handles.dat.fs(fid),'atlas_name') && ...
0221 ~isempty(handles.dat.fs(fid).atlas_name) && ...
0222 ~isempty(strfind(handles.dat.model(im).input.machine.function,'MKL'))
0223 if iscell(handles.dat.fs(fid).atlas_name)
0224 set(handles.edit_atlas,'String',handles.dat.fs(fid).atlas_name{1});
0225 else
0226 set(handles.edit_atlas,'String',handles.dat.fs(fid).atlas_name);
0227 end
0228 else
0229 set(handles.edit_atlas,'String','Load atlas');
0230 end
0231
0232 guidata(hObject, handles);
0233
0234
0235
0236 function edit_prt_CreateFcn(hObject, eventdata, handles)
0237
0238
0239
0240
0241
0242
0243 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0244 set(hObject,'BackgroundColor','white');
0245 end
0246
0247
0248
0249 function br_prt_Callback(hObject, eventdata, handles)
0250
0251
0252
0253 handles.fname=spm_select(1,'.mat','Select PRT.mat',[],pwd,'PRT.mat');
0254 set(handles.edit_prt,'String',handles.fname)
0255 handles.prtdir=fileparts(handles.fname);
0256 if exist('PRT','var')
0257 clear PRT
0258 end
0259 PRT=prt_load(handles.fname);
0260 if ~isempty(PRT)
0261 handles.dat=PRT;
0262 else
0263 beep
0264 disp('Could not load file')
0265 return
0266 end
0267
0268 if ~isfield(handles.dat,'model')
0269 beep
0270 disp('No model found in this PRT')
0271 disp('Please specify model first')
0272 delete(handles.figure1)
0273 end
0274 handles.indm=[];
0275 for i=1:length(handles.dat.model)
0276 if ~isempty(handles.dat.model(i).output)
0277 handles.indm=[handles.indm,i];
0278 end
0279 end
0280 list={handles.dat.model(:).model_name};
0281 set(handles.pop_models,'String',list(handles.indm))
0282 set(handles.pop_models,'Value',1)
0283 handles.selmod=handles.indm(1);
0284 set(handles.compbutt,'Enable','on')
0285 in = struct();
0286 im = handles.indm(1);
0287 in.fs_name = handles.dat.model(im).input.fs(1).fs_name;
0288 fid = prt_init_fs(handles.dat,in);
0289 if isfield(handles.dat.fs(fid),'atlas_name') && ...
0290 ~isempty(handles.dat.fs(fid).atlas_name) && ...
0291 ~isempty(strfind(handles.dat.model(im).input.machine.function,'MKL'))
0292 if iscell(handles.dat.fs(fid).atlas_name)
0293 set(handles.edit_atlas,'String',handles.dat.fs(fid).atlas_name{1});
0294 else
0295 set(handles.edit_atlas,'String',handles.dat.fs(fid).atlas_name);
0296 end
0297 else
0298 set(handles.edit_atlas,'String','Load atlas');
0299 end
0300
0301 guidata(hObject, handles);
0302
0303
0304
0305 function pop_models_Callback(hObject, eventdata, handles)
0306
0307
0308
0309
0310
0311
0312 val=get(handles.pop_models,'Value');
0313 if val==0
0314 warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0315 set(handles.pop_models,'Value',1)
0316 val=1;
0317 end
0318 in = struct();
0319 im = handles.indm(val);
0320 in.fs_name = handles.dat.model(im).input.fs(1).fs_name;
0321 fid = prt_init_fs(handles.dat,in);
0322 if isfield(handles.dat.fs(fid),'atlas_name') && ...
0323 ~isempty(handles.dat.fs(fid).atlas_name) && ...
0324 ~isempty(strfind(handles.dat.model(im).input.machine.function,'MKL'))
0325 if iscell(handles.dat.fs(fid).atlas_name)
0326 set(handles.edit_atlas,'String',handles.dat.fs(fid).atlas_name{1});
0327 else
0328 set(handles.edit_atlas,'String',handles.dat.fs(fid).atlas_name);
0329 end
0330 else
0331 set(handles.edit_atlas,'String','Load atlas');
0332 end
0333 im_name = ['weights_',handles.dat.model(im).model_name,'.img'];
0334 set(handles.edit_imgname,'String',im_name)
0335 handles.selmod=handles.indm(val);
0336
0337 guidata(hObject, handles);
0338
0339
0340
0341 function pop_models_CreateFcn(hObject, eventdata, handles)
0342
0343
0344
0345
0346
0347
0348 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0349 set(hObject,'BackgroundColor','white');
0350 end
0351
0352 function edit_imgname_Callback(hObject, eventdata, handles)
0353
0354
0355
0356
0357
0358
0359 handles.img_name=get(handles.edit_imgname,'String');
0360 if ~prt_checkAlphaNumUnder(handles.img_name)
0361 beep
0362 disp('Name of the image should be in alphanumeric format (no extension)')
0363 disp('Please correct')
0364 return
0365 end
0366
0367 guidata(hObject, handles);
0368
0369
0370 function edit_imgname_CreateFcn(hObject, eventdata, handles)
0371
0372
0373
0374
0375
0376
0377 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0378 set(hObject,'BackgroundColor','white');
0379 end
0380
0381
0382
0383 function flag_cwi_Callback(hObject, eventdata, handles)
0384
0385
0386
0387
0388
0389 flag=get(handles.flag_cwi,'Value');
0390 if flag
0391 handles.flag=1;
0392 else
0393 handles.flag=0;
0394 end
0395 guidata(hObject, handles);
0396
0397
0398 function build_ROI_flag2_Callback(hObject, eventdata, handles)
0399
0400
0401
0402
0403
0404 val = get(handles.build_ROI_flag2,'Value');
0405 if val
0406 handles.flag2 = 1;
0407 handles.atl_name = [];
0408 set(handles.edit_atlas,'Enable','on')
0409 set(handles.br_atlas,'Enable','on')
0410 else
0411 handles.flag2 = 0;
0412 handles.atl_name = [];
0413 set(handles.edit_atlas,'Enable','off')
0414 set(handles.br_atlas,'Enable','off')
0415 end
0416 guidata(hObject, handles);
0417
0418
0419 function edit_atlas_Callback(hObject, eventdata, handles)
0420
0421
0422
0423
0424
0425
0426 handles.atl_name=get(handles.edit_atlas,'String');
0427 if ~prt_checkAlphaNumUnder(handles.atl_name)
0428 beep
0429 disp('Name of the atlas should be in alphanumeric format (no extension)')
0430 disp('Please correct')
0431 return
0432 end
0433
0434 guidata(hObject, handles);
0435
0436
0437 function edit_atlas_CreateFcn(hObject, eventdata, handles)
0438
0439
0440
0441
0442
0443
0444 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0445 set(hObject,'BackgroundColor','white');
0446 end
0447
0448
0449
0450 function br_atlas_Callback(hObject, eventdata, handles)
0451
0452
0453
0454 handles.atl_name=spm_select(1,'img','Select atlas to build weights per region',[],pwd,'.*');
0455 set(handles.edit_atlas,'String',handles.atl_name)
0456
0457 guidata(hObject, handles);
0458
0459
0460 function compbutt_Callback(hObject, eventdata, handles)
0461
0462
0463
0464 list={handles.dat.model(:).model_name};
0465 in.model_name=list{handles.selmod};
0466 in.pathdir=handles.prtdir;
0467 in.img_name=handles.img_name;
0468 in.atl_name = handles.atl_name;
0469 prt_compute_weights(handles.dat,in,handles.flag,handles.flag2);
0470 delete(handles.figure1)