0001 function varargout = prt_data_conditions(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_conditions_OpeningFcn, ...
0040 'gui_OutputFcn', @prt_data_conditions_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_conditions_OpeningFcn(hObject, eventdata, handles, varargin)
0057
0058
0059
0060
0061
0062
0063
0064 handles.output = hObject;
0065
0066
0067 Tag='DDcond';
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 conditions')
0080 set(handles.condmenu,'String',{'Specify','From .mat file'})
0081 set(handles.condmenu,'Value',2)
0082
0083 S0= spm('WinSize','0',1);
0084 if ispc
0085 PF ='MS Sans Serif';
0086 else
0087 PF = spm_platform('fonts');
0088 PF = PF.helvetica;
0089 end
0090 tmp = [S0(3)/1280 (S0(4))/800];
0091 ratio=min(tmp)*[1 1 1 1];
0092 FS = 1 + 0.85*(min(ratio)-1);
0093 x=get(handles.figure1,'Position');
0094 set(handles.figure1,'DefaultTextFontSize',FS*12,...
0095 'DefaultUicontrolFontSize',FS*12,...
0096 'DefaultTextFontName',PF,...
0097 'DefaultAxesFontName',PF,...
0098 'DefaultUicontrolFontName',PF)
0099 set(handles.figure1,'Position',ratio.*x)
0100 set(handles.figure1,'Resize','on')
0101
0102
0103 color=prt_get_defaults('color');
0104 set(handles.figure1,'Color',color.bg1)
0105 aa=get(handles.figure1,'children');
0106 for i=1:length(aa)
0107 if strcmpi(get(aa(i),'type'),'uipanel')
0108 set(aa(i),'BackgroundColor',color.bg2)
0109 bb=get(aa(i),'children');
0110 if ~isempty(bb)
0111 for j=1:length(bb)
0112 if ~isempty(find(strcmpi(get(bb(j),'Style'),{'text',...
0113 'radiobutton','checkbox'})))
0114 set(bb(j),'BackgroundColor',color.bg2)
0115 elseif ~isempty(find(strcmpi(get(bb(j),'Style'),'pushbutton')))
0116 set(bb(j),'BackgroundColor',color.fr)
0117 end
0118 set(bb(j),'FontUnits','pixel')
0119 xf=get(bb(j),'FontSize');
0120 set(bb(j),'FontSize',ceil(FS*xf),'FontName',PF,...
0121 'FontUnits','normalized','Units','normalized')
0122 end
0123 end
0124 elseif strcmpi(get(aa(i),'type'),'uicontrol')
0125 if ~isempty(find(strcmpi(get(aa(i),'Style'),{'text',...
0126 'radiobutton','checkbox','listbox'})))
0127 set(aa(i),'BackgroundColor',color.bg1)
0128 elseif ~isempty(find(strcmpi(get(aa(i),'Style'),'pushbutton')))
0129 set(aa(i),'BackgroundColor',color.fr)
0130 end
0131 end
0132 set(aa(i),'FontUnits','pixel')
0133 xf=get(aa(i),'FontSize');
0134 if ispc
0135 set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0136 'FontUnits','normalized','Units','normalized')
0137 else
0138 set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0139 'Units','normalized')
0140 end
0141 end
0142
0143
0144
0145 handles.cond=struct();
0146 if ~isempty(varargin) && strcmpi(varargin{1},'UserData')
0147 des=varargin{2}{1};
0148 szn=length(des.conds);
0149 dat=cell(szn,4);
0150 for i=1:szn
0151 try
0152 dat{i,1}=des.conds(i).cond_name;
0153 catch
0154 dat{i,1}=['cond ',num2str(i)];
0155 end
0156 handles.cond(i).cond_name=dat{i,1};
0157 try
0158 dat{i,3}=num2str(des.conds(i).durations,3);
0159 handles.cond(i).durations=des.conds(i).durations;
0160 catch
0161 dat{i,3}='NaN';
0162 handles.cond(i).durations=[];
0163 end
0164 try
0165 dat{i,2}=num2str(des.conds(i).onsets,3);
0166 handles.cond(i).onsets=des.conds(i).onsets;
0167 catch
0168 dat{i,2}='NaN';
0169 handles.cond(i).onsets=[];
0170 end
0171 try
0172 dat{i,4}=num2str(des.conds(i).rt_trial,3);
0173 handles.cond(i).rt_trial=des.conds(i).rt_trial;
0174 catch
0175 dat{i,4}='NaN';
0176 handles.cond(i).rt_trial=[];
0177 end
0178 end
0179 set(handles.condtable,'visible','on');
0180 set(handles.condtable,'Data',dat);
0181 handles.trval=des.TR;
0182 set(handles.tredit,'String',num2str(des.TR));
0183 handles.unit=des.unit;
0184 if ~isempty(des.covar)
0185 set(handles.covedit,'String',num2str((des.covar(:))',3));
0186 handles.covar=des.covar;
0187 else
0188 handles.covar=[];
0189 set(handles.covedit,'String','');
0190 end
0191 else
0192 dat={'cond1','0','0','[]'};
0193 set(handles.condtable,'visible','off');
0194 handles.trval=0;
0195 handles.covar=[];
0196 des.unit=1;
0197 end
0198 set(handles.condtable,'Data',dat);
0199 set(handles.condtable,'ColumnName',{'Name','Onsets','Duration','Regression targets (trials)'});
0200 set(handles.condtable,'ColumnEditable',[true,true,true,true]);
0201 set(handles.condtable,'ColumnWidth',{'auto',130,130,0});
0202 set(handles.condtable,'ColumnFormat',{'char','char','char','char'});
0203 set(handles.pop_unit,'String',{'Seconds','Scans'});
0204 if des.unit
0205 uv=1;
0206 else
0207 uv=2;
0208 end
0209 set(handles.pop_unit,'Value',uv)
0210 handles.unit=des.unit;
0211
0212 def=prt_get_defaults('datad');
0213 if ~isempty(varargin) && length(varargin{2})>1
0214 PRT=varargin{2}{2};
0215 if isfield(PRT.group,'hrfdelay')
0216 handles.hrfdel=PRT.group(1).hrfdelay;
0217 else
0218 handles.hrfdel=def.hrfd;
0219 end
0220 if isfield(PRT.group,'hrfoverlap')
0221 handles.hrfover=PRT.group(1).hrfoverlap;
0222 else
0223 handles.hrfover=def.hrfw;
0224 end
0225 else
0226 handles.hrfdel=def.hrfd;
0227 handles.hrfover=def.hrfw;
0228 end
0229 end
0230
0231 guidata(hObject, handles);
0232
0233
0234 uiwait(handles.figure1);
0235
0236
0237
0238 function varargout = prt_data_conditions_OutputFcn(hObject, eventdata, handles)
0239
0240
0241
0242
0243
0244
0245 if isfield(handles,'output') && ~isempty(handles.output)
0246 varargout{1} = handles.output;
0247 else
0248 varargout{1}=[];
0249 end
0250
0251
0252 if isfield(handles,'figure1')
0253 delete(handles.figure1);
0254 end
0255
0256
0257
0258 function condmenu_Callback(hObject, eventdata, handles)
0259
0260
0261
0262
0263
0264
0265 choice=get(handles.condmenu,'Value');
0266 if choice==1
0267 ncond=str2double(prt_text_input('Title','Enter number of conditions'));
0268 if isnan(ncond)
0269 return
0270 end
0271 dat=cell(ncond,4);
0272 for i=1:ncond
0273 dat{i,1}=['cond ',num2str(i)];
0274 dat{i,2}='NaN';
0275 dat{i,3}='NaN';
0276 dat{i,4}='[]';
0277 end
0278 set(handles.condtable,'visible','on');
0279 set(handles.condtable,'Data',dat);
0280 else
0281 des = spm_select(1,'.mat','Select multiple conditions file');
0282 try
0283 load(des);
0284 catch
0285 beep
0286 disp('Could not load file')
0287 return
0288 end
0289 try
0290 na=names;
0291 catch
0292 beep
0293 disp('No "names" found in the .mat file, please select another file')
0294 return
0295 end
0296 try
0297 dur=durations;
0298 catch
0299 beep
0300 disp('No "durations" found in the .mat file, please select another file')
0301 return
0302 end
0303 try
0304 ons=onsets;
0305 catch
0306 beep
0307 disp('No "onsets" found in the .mat file, please select another file')
0308 return
0309 end
0310
0311
0312
0313
0314
0315
0316 szn=length(names);
0317 dat=cell(szn,4);
0318 for i=1:szn
0319 try
0320 dat{i,1}=na{i};
0321 catch
0322 dat{i,1}=['cond ',num2str(i)];
0323 end
0324 handles.cond(i).cond_name=dat{i,1};
0325 try
0326 dat{i,3}=num2str(dur{i},3);
0327 handles.cond(i).durations=dur{i};
0328 catch
0329 dat{i,3}='NaN';
0330 handles.cond(i).durations=[];
0331 end
0332 try
0333 dat{i,2}=num2str(ons{i},3);
0334 handles.cond(i).onsets=ons{i};
0335 catch
0336 dat{i,2}='NaN';
0337 handles.cond(i).onsets=[];
0338 end
0339 try
0340 dat{i,4}=num2str(rt_trial{i},3);
0341 handles.cond(i).rt_trial=rt_trial{i};
0342 catch
0343 dat{i,4}='NaN';
0344 handles.cond(i).rt_trial=[];
0345 end
0346 end
0347 set(handles.condtable,'visible','on');
0348 set(handles.condtable,'Data',dat);
0349 end
0350
0351 guidata(hObject, handles);
0352
0353
0354 function condmenu_CreateFcn(hObject, eventdata, handles)
0355
0356
0357
0358
0359
0360
0361 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0362 set(hObject,'BackgroundColor','white');
0363 end
0364
0365
0366
0367 function tredit_Callback(hObject, eventdata, handles)
0368
0369
0370
0371
0372
0373
0374 val=get(handles.tredit,'String');
0375 eval(['handles.trval=',val,';']);
0376
0377 guidata(hObject, handles);
0378
0379
0380 function tredit_CreateFcn(hObject, eventdata, handles)
0381
0382
0383
0384
0385
0386
0387 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0388 set(hObject,'BackgroundColor','white');
0389 end
0390
0391
0392 function pop_unit_Callback(hObject, eventdata, handles)
0393
0394
0395
0396
0397
0398
0399 un=get(handles.pop_unit,'Value');
0400 if un==0
0401 set(handles.pop_unit,'Value',1)
0402 un=1;
0403 end
0404 if un==1
0405 handles.unit=1;
0406 else
0407 handles.unit=0;
0408 end
0409
0410 guidata(hObject, handles);
0411
0412
0413 function pop_unit_CreateFcn(hObject, eventdata, handles)
0414
0415
0416
0417
0418
0419
0420 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0421 set(hObject,'BackgroundColor','white');
0422 end
0423
0424 function covedit_Callback(hObject, eventdata, handles)
0425
0426
0427
0428
0429
0430
0431 dat=get(handles.covedit,'String');
0432 eval(['vect=[',dat,'];']);
0433
0434
0435 if isnan(vect)
0436 try
0437 load(char(vect));
0438 catch
0439 beep
0440 disp('Could not load file or read the covariate values')
0441 disp('Please enter either a .mat file name or enter the values')
0442 return
0443 end
0444 if ~exist('R','var')
0445 beep
0446 sprintf('Covariates file must contain ''R'' variable! ')
0447 disp('Please correct!')
0448 return
0449 else
0450 vect=R;
0451 end
0452 end
0453 handles.covar=vect;
0454
0455 guidata(hObject, handles);
0456
0457
0458
0459 function covedit_CreateFcn(hObject, eventdata, handles)
0460
0461
0462
0463
0464
0465
0466 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0467 set(hObject,'BackgroundColor','white');
0468 end
0469
0470
0471
0472 function condtable_CellEditCallback(hObject, eventdata, handles)
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482 ind=eventdata.Indices;
0483 if ind(2)>1
0484 dat=eventdata.EditData;
0485 eval(['vect=[',dat,'];']);
0486
0487
0488 if any(isnan(vect)) || any(vect>10^6) || ~any(size(vect)==1)
0489 beep
0490 disp('Bad formatting of values found!')
0491 sprintf('Please review and correct condition %d, column %d', ind(1), ind(2))
0492 return
0493 end
0494 end
0495 if ind(2)==2
0496 vectb=unique(vect);
0497 if length(vect)~=length(vectb)
0498 beep
0499 disp('Duplicated values found in the onsets of condition %d', ind(1))
0500 disp('Please correct')
0501 return
0502 end
0503 end
0504 if ind(2)==1
0505 handles.cond(ind(1)).cond_name=eventdata.EditData;
0506 elseif ind(2)==2
0507 handles.cond(ind(1)).onsets=vect;
0508 elseif ind(2)==3
0509 handles.cond(ind(1)).durations=vect;
0510 elseif ind(2)==4
0511
0512 handles.cond(ind(1)).rt_trial=vect;
0513 end
0514
0515 if ~isfield(handles.cond(ind(1)),'rt_trial')
0516 handles.cond(ind(1)).rt_trial=[];
0517 end
0518
0519 guidata(hObject, handles);
0520
0521
0522
0523 function okbutton_Callback(hObject, eventdata, handles)
0524
0525
0526
0527
0528
0529 if handles.trval==0
0530 beep
0531 disp('Enter TR value before continuing')
0532 return
0533 end
0534
0535
0536
0537 ncond=length(handles.cond);
0538
0539
0540
0541 for i=1:ncond
0542 szon=length(handles.cond(i).onsets);
0543 szdur=length(handles.cond(i).durations);
0544
0545 if szdur==1
0546 handles.cond(i).durations=repmat(handles.cond(i).durations, 1, szon);
0547 szdur=length(handles.cond(i).durations);
0548 end
0549 if szdur ~=szon
0550 beep
0551 sprintf('The onsets and durations of condition %d do not have the same size', i)
0552 disp('Please correct')
0553 return
0554 end
0555
0556
0557
0558
0559
0560
0561 end
0562
0563
0564
0565 conds=prt_check_design(handles.cond,handles.trval,handles.unit,...
0566 handles.hrfover,handles.hrfdel);
0567 conds.covar=handles.covar;
0568 handles.output=conds;
0569
0570
0571 guidata(hObject, handles);
0572
0573 uiresume(handles.figure1);
0574
0575
0576 function cancelbutton_Callback(hObject, eventdata, handles)
0577
0578
0579
0580 uiresume(handles.figure1);
0581