0001 function varargout = prt_data_modality(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_data_modality_OpeningFcn, ...
0040 'gui_OutputFcn', @prt_data_modality_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_data_modality_OpeningFcn(hObject, eventdata, handles, varargin)
0057
0058
0059
0060
0061
0062
0063
0064 handles.output = hObject;
0065
0066
0067 Tag='DDmod';
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 :: Specify modality')
0080 set(handles.design_menu,...
0081 'String',{'Load SPM.mat','Specify design','No design'},...
0082 'Value',3);
0083
0084
0085 S0= spm('WinSize','0',1);
0086 if ispc
0087 PF='MS Sans Serif';
0088 else
0089 PF= spm_platform('fonts');
0090 PF=PF.helvetica;
0091 end
0092 tmp = [S0(3)/1280 (S0(4))/800];
0093 ratio=min(tmp)*[1 1 1 1];
0094 FS = 1 + 0.85*(min(ratio)-1);
0095 x=get(handles.figure1,'Position');
0096 set(handles.figure1,'DefaultTextFontSize',FS*8,...
0097 'DefaultUicontrolFontSize',FS*8,...
0098 'DefaultTextFontName',PF,...
0099 'DefaultAxesFontName',PF,...
0100 'DefaultUicontrolFontName',PF)
0101 set(handles.figure1,'Position',ratio.*x)
0102 set(handles.figure1,'Resize','on')
0103
0104
0105 color=prt_get_defaults('color');
0106 set(handles.figure1,'Color',color.bg1)
0107 aa=get(handles.figure1,'children');
0108 for i=1:length(aa)
0109 if strcmpi(get(aa(i),'type'),'uipanel')
0110 set(aa(i),'BackgroundColor',color.bg2)
0111 bb=get(aa(i),'children');
0112 if ~isempty(bb)
0113 for j=1:length(bb)
0114 if ~isempty(find(strcmpi(get(bb(j),'Style'),{'text',...
0115 'radiobutton','checkbox'})))
0116 set(bb(j),'BackgroundColor',color.bg2)
0117 elseif ~isempty(find(strcmpi(get(bb(j),'Style'),'pushbutton')))
0118 set(bb(j),'BackgroundColor',color.fr)
0119 end
0120 set(bb(j),'FontUnits','pixel')
0121 xf=get(bb(j),'FontSize');
0122 set(bb(j),'FontSize',ceil(FS*xf),'FontName',PF,...
0123 'FontUnits','normalized','Units','normalized')
0124 end
0125 end
0126 else
0127 if ~isempty(find(strcmpi(get(aa(i),'Style'),{'text',...
0128 'radiobutton','checkbox','listbox'})))
0129 set(aa(i),'BackgroundColor',color.bg1)
0130 elseif ~isempty(find(strcmpi(get(aa(i),'Style'),'pushbutton')))
0131 set(aa(i),'BackgroundColor',color.fr)
0132 end
0133 end
0134 set(aa(i),'FontUnits','pixel')
0135 xf=get(aa(i),'FontSize');
0136 if ispc
0137 set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0138 'FontUnits','normalized','Units','normalized')
0139 else
0140 set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0141 'Units','normalized')
0142 end
0143 end
0144
0145
0146
0147
0148 handles.mod=[];
0149 handles.mod.detrend=1;
0150 handles.mod.design=0;
0151 handles.mod.scans=[];
0152 handles.mod.name={};
0153 handles.mod.covar=[];
0154 handles.mod.rt_subj=[];
0155 handles.subj1=0;
0156
0157 if ~isempty(varargin) && strcmpi(varargin{1},'UserData')
0158
0159 if ~isempty(varargin{2}{2}) && strcmpi(varargin{2}{2}.subj_name,'Scans')
0160 set(handles.design_menu,'Enable','off')
0161 set(handles.edit_regt,'Enable','on')
0162 set(handles.edit_regt,'Visible','on')
0163 set(handles.edit_covar,'Enable','on')
0164 set(handles.edit_covar,'Visible','on')
0165 set(handles.text7,'Visible','on')
0166 set(handles.text6,'Visible','on')
0167 else
0168 set(handles.design_menu,'Enable','on')
0169 set(handles.edit_regt,'Enable','off')
0170 set(handles.edit_regt,'Visible','off')
0171 set(handles.edit_covar,'Enable','off')
0172 set(handles.edit_covar,'Visible','off')
0173 set(handles.text7,'Visible','off')
0174 set(handles.text6,'Visible','off')
0175 end
0176
0177 if ~isempty(varargin{2}{2}) && isfield(varargin{2}{2},'modality') && ...
0178 ~isempty(varargin{2}{2}.modality)
0179 handles.subjmod={varargin{2}{2}.modality(:).mod_name};
0180 if length(varargin{2})>=3 && ~isempty(varargin{2}{3})
0181 nlist=varargin{2}{1};
0182 modsel=varargin{2}{2}.modality(varargin{2}{3});
0183 valsel=find(strcmpi(modsel.mod_name,nlist));
0184 set(handles.modname,'String',nlist);
0185 set(handles.modname,'Value',valsel);
0186 handles.mod.detrend=modsel.detrend;
0187 handles.mod.design=modsel.design;
0188 if ~isempty(modsel.design)
0189 set(handles.design_menu,'Value',2)
0190 handles.desnmenu=2;
0191 end
0192 handles.mod.scans=modsel.scans;
0193 handles.mod.name=modsel.mod_name;
0194 handles.mod.covar=modsel.covar;
0195 handles.mod.rt_subj=modsel.rt_subj;
0196 else
0197 nlist=[varargin{2}{1}, {'Enter new'}];
0198 set(handles.modname,'String',nlist,'Value',length(nlist));
0199 end
0200 else
0201 nlist=[varargin{2}{1}, {'Enter new'}];
0202 set(handles.modname,'String',nlist,'Value',length(nlist));
0203 handles.subjmod={};
0204 end
0205 else
0206 nlist={'Enter new'};
0207 handles.subjmod={};
0208 set(handles.modname,'String',nlist,'Value',1);
0209 end
0210 if length(varargin{2})>=4 && ~isempty(varargin{2}{4})
0211 handles.subj1=varargin{2}{4};
0212 end
0213 if length(varargin{2})==5 && ~isempty(varargin{2}{5})
0214 handles.PRT=varargin{2}{5};
0215 end
0216 warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0217 end
0218
0219 guidata(hObject, handles);
0220
0221
0222 uiwait(handles.figure1);
0223
0224
0225
0226 function varargout = prt_data_modality_OutputFcn(hObject, eventdata, handles)
0227
0228
0229
0230
0231
0232
0233 if isfield(handles,'output') && ~isempty(handles.output)
0234 varargout{1} = handles.output;
0235 else
0236 varargout{1}=[];
0237 end
0238
0239
0240 if isfield(handles,'figure1')
0241 delete(handles.figure1);
0242 end
0243
0244
0245
0246 function modname_Callback(hObject, eventdata, handles)
0247
0248
0249
0250
0251
0252
0253 warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0254 list=get(handles.modname,'String');
0255
0256 if length(list)==1
0257 set(handles.modname,'Value',1)
0258 end
0259
0260 if any(strfind(list{get(handles.modname,'Value')}, 'Enter'))
0261 modname=prt_text_input('Title','Enter modality name');
0262 if isnumeric(modname)
0263 return
0264 end
0265 if ~any(strcmpi(list,modname))
0266 nlist=[list;{modname}];
0267 else
0268 beep
0269 disp('This modality has already been set for the selected subject')
0270 set(handles.modname,'String',list);
0271 valall=strfind(list,'Enter');
0272 for i=1:length(valall)
0273 if ~isempty(valall{i})
0274 val=i;
0275 break
0276 end
0277 end
0278 set(handles.modname,'Value',val);
0279 return
0280 end
0281 set(handles.modname,'String',nlist);
0282 set(handles.modname,'Value',length(nlist));
0283 else
0284 modname=list{get(handles.modname,'Value')};
0285 if ~isempty(handles.subjmod)
0286 if any(strcmpi(handles.subjmod,modname))
0287 set(handles.modname,'String',list);
0288 valall=strfind(list,'Enter');
0289 if length(valall)==1 && isempty(valall{1})
0290 val=1;
0291 set(handles.modname,'Value',val);
0292 else
0293 beep
0294 disp('This modality has already been set for the selected subject')
0295 for i=1:length(valall)
0296 if ~isempty(valall{i})
0297 val=i;
0298 break
0299 end
0300 end
0301 set(handles.modname,'Value',val);
0302 return
0303 end
0304 end
0305 end
0306 end
0307
0308
0309
0310 if isstruct(handles.subj1)
0311 if any(strcmpi(modname, {handles.subj1(:).mod_name}))
0312 handles.indmods1=find(strcmpi(modname, {handles.subj1(:).mod_name}));
0313 list=get(handles.design_menu,'String');
0314 list=[list;{'Replicate design of subject 1'}];
0315 set(handles.design_menu,'String',list);
0316 end
0317 end
0318 handles.mod.name=modname;
0319
0320 guidata(hObject, handles);
0321
0322
0323
0324 function modname_CreateFcn(hObject, eventdata, handles)
0325
0326
0327
0328
0329
0330
0331 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0332 set(hObject,'BackgroundColor','white');
0333 end
0334
0335
0336 function design_menu_Callback(hObject, eventdata, handles)
0337
0338
0339
0340
0341
0342
0343 choice=get(handles.design_menu,'Value');
0344
0345 if choice==0
0346 choice=handles.desnmenu;
0347 set(handles.design_menu,'Value')
0348 end
0349 if choice==1
0350 desn=spm_select(1,'mat','Select SPM.mat file',[],[],'SPM.mat');
0351 try
0352 load(desn);
0353 catch
0354 beep
0355 disp('Can not load SPM.mat file');
0356 return
0357 end
0358 ncond = length(SPM.Sess(1).U);
0359 conds=struct();
0360 for c = 1:ncond
0361 conds(c).cond_name = SPM.Sess(1).U(c).name{1};
0362 conds(c).onsets = SPM.Sess(1).U(c).ons;
0363 conds(c).durations = SPM.Sess(1).U(c).dur;
0364 end
0365 if strcmpi(SPM.xBF.UNITS,'scans')
0366 units=0;
0367 else
0368 units=1;
0369 end
0370 def=prt_get_defaults('datad');
0371 if isfield(handles.PRT.group,'hrfoverlap')
0372 overl=handles.PRT.group.hrfoverlap;
0373 else
0374 overl=def.hrfw;
0375 end
0376 if isfield(handles.PRT.group,'hrfdelay')
0377 del=handles.PRT.group.hrfdelay;
0378 else
0379 del=def.hrfd;
0380 end
0381 desn=prt_check_design(conds,SPM.xX.K.RT,units,overl,del);
0382 desn.covar = [];
0383 elseif choice==2
0384 if isstruct(handles.mod.design)
0385 desn=prt_data_conditions('UserData',{handles.mod.design,handles.PRT});
0386 else
0387 desn=prt_data_conditions;
0388 end
0389 elseif choice ==3
0390 desn=[];
0391 elseif choice==4
0392 desn=handles.subj1(handles.indmods1).design;
0393 end
0394 handles.mod.design=desn;
0395 if isfield(desn,'covar') && ~isempty(desn.covar)
0396 set(handles.edit_covar,'String','Entered');
0397 set(handles.edit_covar,'Visible','on');
0398 end
0399
0400 guidata(hObject, handles);
0401
0402
0403 function design_menu_CreateFcn(hObject, eventdata, handles)
0404
0405
0406
0407
0408
0409
0410 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0411 set(hObject,'BackgroundColor','white');
0412 end
0413
0414
0415 function getfiles_Callback(hObject, eventdata, handles)
0416
0417
0418
0419 if ~isempty(handles.mod.scans)
0420 sel=cellstr(handles.mod.scans);
0421 else
0422 sel=[];
0423 end
0424 t=spm_select([1 Inf],'image','Select files for the modality',sel);
0425 handles.mod.scans=t;
0426
0427 guidata(hObject, handles);
0428
0429
0430 function edit_regt_Callback(hObject, eventdata, handles)
0431
0432
0433
0434
0435
0436
0437
0438
0439 rt=get(handles.edit_regt,'String');
0440 if isempty(rt)
0441 return
0442 end
0443 if ~isnan(str2double(rt(1)))
0444 eval(['rte=[',rt,'];'])
0445 else
0446 try
0447 load(char(rt));
0448 catch
0449 beep
0450 disp('Could not load file or read the regression targets')
0451 disp('Please enter either a .mat file name or enter the values')
0452 return
0453 end
0454 if ~exist('rt_subj','var')
0455 beep
0456 sprintf('Regression targets file must contain ''rt_subj'' variable! ')
0457 disp('Please correct!')
0458 return
0459 else
0460 rte=rt_subj;
0461 end
0462 end
0463 handles.mod.rt_subj=rte;
0464
0465 guidata(hObject, handles);
0466
0467
0468 function edit_regt_CreateFcn(hObject, eventdata, handles)
0469
0470
0471
0472
0473
0474
0475 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0476 set(hObject,'BackgroundColor','white');
0477 end
0478
0479 function edit_covar_Callback(hObject, eventdata, handles)
0480
0481
0482
0483
0484
0485
0486
0487 rt=get(handles.edit_covar,'String');
0488 if isempty(rt)
0489 return
0490 end
0491 if ~isnan(str2double(rt(1)))
0492 eval(['rte=[',rt,'];'])
0493 else
0494 try
0495 load(char(rt));
0496 catch
0497 beep
0498 disp('Could not load file or read the covariate values')
0499 disp('Please enter either a .mat file name or enter the values')
0500 return
0501 end
0502 if ~exist('R','var')
0503 beep
0504 sprintf('Covariates file must contain ''R'' variable! ')
0505 disp('Please correct!')
0506 return
0507 else
0508 rte=R;
0509 end
0510 end
0511
0512 handles.mod.covar=rte;
0513
0514 guidata(hObject, handles);
0515
0516
0517 function edit_covar_CreateFcn(hObject, eventdata, handles)
0518
0519
0520
0521
0522
0523
0524 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0525 set(hObject,'BackgroundColor','white');
0526 end
0527
0528
0529
0530 function okbutton_Callback(hObject, eventdata, handles)
0531
0532
0533
0534
0535
0536 if isempty(handles.mod.scans)
0537 beep
0538 disp('Please, select the files before returning')
0539 return
0540 end
0541
0542
0543
0544 if ~isempty(handles.mod.rt_subj)
0545 szrt=length(handles.mod.rt_subj);
0546 if size(handles.mod.scans,1)~=szrt
0547 beep
0548 disp('Number of regression targets must be the number of files selected! ')
0549 disp('Please correct!')
0550 return
0551 end
0552 end
0553
0554
0555 if ~isempty(handles.mod.covar)
0556 szrt=size(handles.mod.covar);
0557 if ~any(size(handles.mod.scans,1)==szrt)
0558 beep
0559 disp('Number of covariates must be the number of files selected! ')
0560 disp('Please correct!')
0561 return
0562 end
0563 end
0564
0565 modprop=handles.mod;
0566 handles.output=modprop;
0567
0568 guidata(hObject, handles);
0569 uiresume(handles.figure1);
0570
0571
0572
0573 function cancelbutton_Callback(hObject, eventdata, handles)
0574
0575
0576
0577 uiresume(handles.figure1);