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 temp=[];
0159 for j=1:length(des.conds(i).durations)
0160 temp=[temp, ' ',num2str(des.conds(i).durations(j),3)];
0161 end
0162 dat{i,3}=temp;
0163 handles.cond(i).durations=des.conds(i).durations;
0164 catch
0165 dat{i,3}='NaN';
0166 handles.cond(i).durations=[];
0167 end
0168 try
0169 temp=[];
0170 for j=1:length(des.conds(i).onsets)
0171 temp=[temp, ' ',num2str(des.conds(i).onsets(j),3)];
0172 end
0173 dat{i,2}=temp;
0174 handles.cond(i).onsets=des.conds(i).onsets;
0175 catch
0176 dat{i,2}='NaN';
0177 handles.cond(i).onsets=[];
0178 end
0179 try
0180 temp=[];
0181 for j=1:length(des.conds(i).rt_trial)
0182 temp=[temp, ' ',num2str(des.conds(i).rt_trial(j),3)];
0183 end
0184 dat{i,4}=temp;
0185 handles.cond(i).rt_trial=des.conds(i).rt_trial;
0186 catch
0187 dat{i,4}='NaN';
0188 handles.cond(i).rt_trial=[];
0189 end
0190 end
0191 set(handles.condtable,'visible','on');
0192 set(handles.condtable,'Data',dat);
0193 handles.trval=des.TR;
0194 set(handles.tredit,'String',num2str(des.TR));
0195 handles.unit=des.unit;
0196 else
0197 dat={'cond1','0','0','[]'};
0198 set(handles.condtable,'visible','off');
0199 handles.trval=0;
0200 handles.covar=[];
0201 des.unit=1;
0202 end
0203 set(handles.condtable,'Data',dat);
0204 set(handles.condtable,'ColumnName',{'Name','Onsets','Duration','Regression targets (trials)'});
0205 set(handles.condtable,'ColumnEditable',[true,true,true,true]);
0206 set(handles.condtable,'ColumnWidth',{'auto',130,130,0});
0207 set(handles.condtable,'ColumnFormat',{'char','char','char','char'});
0208 set(handles.pop_unit,'String',{'Seconds','Scans'});
0209 if des.unit
0210 uv=1;
0211 else
0212 uv=2;
0213 end
0214 set(handles.pop_unit,'Value',uv)
0215 handles.unit=des.unit;
0216
0217 def=prt_get_defaults('datad');
0218 if ~isempty(varargin) && length(varargin{2})>1
0219 PRT=varargin{2}{2};
0220 if isfield(PRT.group,'hrfdelay')
0221 handles.hrfdel=PRT.group(1).hrfdelay;
0222 else
0223 handles.hrfdel=def.hrfd;
0224 end
0225 if isfield(PRT.group,'hrfoverlap')
0226 handles.hrfover=PRT.group(1).hrfoverlap;
0227 else
0228 handles.hrfover=def.hrfw;
0229 end
0230 else
0231 handles.hrfdel=def.hrfd;
0232 handles.hrfover=def.hrfw;
0233 end
0234 end
0235
0236 guidata(hObject, handles);
0237
0238
0239 uiwait(handles.figure1);
0240
0241
0242
0243 function varargout = prt_data_conditions_OutputFcn(hObject, eventdata, handles)
0244
0245
0246
0247
0248
0249
0250 if isfield(handles,'output') && ~isempty(handles.output)
0251 varargout{1} = handles.output;
0252 else
0253 varargout{1}=[];
0254 end
0255
0256
0257 if isfield(handles,'figure1')
0258 delete(handles.figure1);
0259 end
0260
0261
0262
0263 function condmenu_Callback(hObject, eventdata, handles)
0264
0265
0266
0267
0268
0269
0270 choice=get(handles.condmenu,'Value');
0271 if choice==1
0272 ncond=str2double(prt_text_input('Title','Enter number of conditions'));
0273 if isnan(ncond)
0274 return
0275 end
0276 dat=cell(ncond,4);
0277 for i=1:ncond
0278 dat{i,1}=['cond ',num2str(i)];
0279 dat{i,2}='NaN';
0280 dat{i,3}='NaN';
0281 dat{i,4}='[]';
0282 handles.cond(i).cond_name=['cond ',num2str(i)];
0283 end
0284 set(handles.condtable,'visible','on');
0285 set(handles.condtable,'Data',dat);
0286 else
0287 des = spm_select(1,'.mat','Select multiple conditions file');
0288 try
0289 load(des);
0290 catch
0291 beep
0292 disp('Could not load file')
0293 return
0294 end
0295 try
0296 na=names;
0297 catch
0298 beep
0299 disp('No "names" found in the .mat file, please select another file')
0300 return
0301 end
0302 try
0303 dur=durations;
0304 catch
0305 beep
0306 disp('No "durations" found in the .mat file, please select another file')
0307 return
0308 end
0309 try
0310 ons=onsets;
0311 catch
0312 beep
0313 disp('No "onsets" found in the .mat file, please select another file')
0314 return
0315 end
0316
0317
0318
0319
0320
0321
0322 szn=length(names);
0323 dat=cell(szn,4);
0324 for i=1:szn
0325 try
0326 dat{i,1}=na{i};
0327 catch
0328 dat{i,1}=['cond ',num2str(i)];
0329 end
0330 handles.cond(i).cond_name=dat{i,1};
0331 try
0332 dat{i,3}=num2str(dur{i},3);
0333 handles.cond(i).durations=dur{i};
0334 catch
0335 dat{i,3}='NaN';
0336 handles.cond(i).durations=[];
0337 end
0338 try
0339 dat{i,2}=num2str(ons{i},3);
0340 handles.cond(i).onsets=ons{i};
0341 catch
0342 dat{i,2}='NaN';
0343 handles.cond(i).onsets=[];
0344 end
0345 try
0346 dat{i,4}=num2str(rt_trial{i},3);
0347 handles.cond(i).rt_trial=rt_trial{i};
0348 catch
0349 dat{i,4}='NaN';
0350 handles.cond(i).rt_trial=[];
0351 end
0352 end
0353 set(handles.condtable,'visible','on');
0354 set(handles.condtable,'Data',dat);
0355 end
0356
0357 guidata(hObject, handles);
0358
0359
0360 function condmenu_CreateFcn(hObject, eventdata, handles)
0361
0362
0363
0364
0365
0366
0367 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0368 set(hObject,'BackgroundColor','white');
0369 end
0370
0371
0372
0373 function tredit_Callback(hObject, eventdata, handles)
0374
0375
0376
0377
0378
0379
0380 val=get(handles.tredit,'String');
0381 eval(['handles.trval=',val,';']);
0382
0383 guidata(hObject, handles);
0384
0385
0386 function tredit_CreateFcn(hObject, eventdata, handles)
0387
0388
0389
0390
0391
0392
0393 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0394 set(hObject,'BackgroundColor','white');
0395 end
0396
0397
0398 function pop_unit_Callback(hObject, eventdata, handles)
0399
0400
0401
0402
0403
0404
0405 un=get(handles.pop_unit,'Value');
0406 if un==0
0407 set(handles.pop_unit,'Value',1)
0408 un=1;
0409 end
0410 if un==1
0411 handles.unit=1;
0412 else
0413 handles.unit=0;
0414 end
0415
0416 guidata(hObject, handles);
0417
0418
0419 function pop_unit_CreateFcn(hObject, eventdata, handles)
0420
0421
0422
0423
0424
0425
0426 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0427 set(hObject,'BackgroundColor','white');
0428 end
0429
0430
0431
0432 function condtable_CellEditCallback(hObject, eventdata, handles)
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442 ind=eventdata.Indices;
0443 if ind(2)>1
0444 dat=eventdata.EditData;
0445 eval(['vect=[',dat,'];']);
0446
0447
0448 if any(isnan(vect)) || any(vect>10^6) || ~any(size(vect)==1)
0449 beep
0450 disp('Bad formatting of values found!')
0451 sprintf('Please review and correct condition %d, column %d', ind(1), ind(2))
0452 return
0453 end
0454 end
0455 if ind(2)==2
0456 vectb=unique(vect);
0457 if length(vect)~=length(vectb)
0458 beep
0459 disp('Duplicated values found in the onsets of condition %d', ind(1))
0460 disp('Please correct')
0461 return
0462 end
0463 end
0464 if ind(2)==1
0465 handles.cond(ind(1)).cond_name=eventdata.EditData;
0466 elseif ind(2)==2
0467 handles.cond(ind(1)).onsets=vect;
0468 elseif ind(2)==3
0469 handles.cond(ind(1)).durations=vect;
0470 elseif ind(2)==4
0471
0472 handles.cond(ind(1)).rt_trial=vect;
0473 end
0474
0475 if ~isfield(handles.cond(ind(1)),'rt_trial')
0476 handles.cond(ind(1)).rt_trial=[];
0477 end
0478
0479 guidata(hObject, handles);
0480
0481
0482
0483 function okbutton_Callback(hObject, eventdata, handles)
0484
0485
0486
0487
0488
0489 if handles.trval==0
0490 beep
0491 disp('Enter TR value before continuing')
0492 return
0493 end
0494
0495
0496
0497 ncond=length(handles.cond);
0498
0499
0500
0501 for i=1:ncond
0502 szon=length(handles.cond(i).onsets);
0503 szdur=length(handles.cond(i).durations);
0504
0505 if szdur==1
0506 handles.cond(i).durations=repmat(handles.cond(i).durations, 1, szon);
0507 szdur=length(handles.cond(i).durations);
0508 end
0509 if szdur ~=szon
0510 beep
0511 sprintf('The onsets and durations of condition %d do not have the same size', i)
0512 disp('Please correct')
0513 return
0514 end
0515
0516
0517
0518
0519
0520
0521 end
0522
0523
0524
0525 conds=prt_check_design(handles.cond,handles.trval,handles.unit,...
0526 handles.hrfover,handles.hrfdel);
0527 conds.covar=handles.covar;
0528 handles.output=conds;
0529
0530
0531 guidata(hObject, handles);
0532
0533 uiresume(handles.figure1);
0534
0535
0536 function cancelbutton_Callback(hObject, eventdata, handles)
0537
0538
0539
0540 uiresume(handles.figure1);
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567