0001 function varargout = prt_ui_design(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 gui_Singleton = 1;
0035 gui_State = struct('gui_Name', mfilename, ...
0036 'gui_Singleton', gui_Singleton, ...
0037 'gui_OpeningFcn', @prt_ui_design_OpeningFcn, ...
0038 'gui_OutputFcn', @prt_ui_design_OutputFcn, ...
0039 'gui_LayoutFcn', [] , ...
0040 'gui_Callback', []);
0041 if nargin && ischar(varargin{1})
0042 gui_State.gui_Callback = str2func(varargin{1});
0043 end
0044
0045 if nargout
0046 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0047 else
0048 gui_mainfcn(gui_State, varargin{:});
0049 end
0050
0051
0052
0053
0054 function prt_ui_design_OpeningFcn(hObject, eventdata, handles, varargin)
0055
0056
0057
0058
0059
0060
0061
0062 handles.output = hObject;
0063
0064 Tag='DDwin';
0065 F = findall(allchild(0),'Flat','Tag',Tag);
0066 if length(F) > 1
0067
0068 close(F(2:end))
0069 F = F(1);
0070 uistack(F,'top')
0071 elseif length(F)==1
0072 uistack(F,'top')
0073 else
0074 set(handles.figure1,'Tag',Tag)
0075 set(handles.figure1,'Name','PRoNTo :: Data and design')
0076
0077 S0= spm('WinSize','0',1);
0078 if ispc
0079 PF='MS Sans Serif';
0080 else
0081 PF= spm_platform('fonts');
0082 PF=PF.helvetica;
0083 end
0084 tmp = [S0(3)/1280 (S0(4))/800];
0085 ratio=min(tmp)*[1 1 1 1];
0086 FS = 1 + 0.85*(min(ratio)-1);
0087 x=get(handles.figure1,'Position');
0088 set(handles.figure1,'DefaultTextFontSize',FS*12,...
0089 'DefaultUicontrolFontSize',FS*12,...
0090 'DefaultTextFontName',PF,...
0091 'DefaultAxesFontName',PF,...
0092 'DefaultUicontrolFontName',PF)
0093 set(handles.figure1,'Position',ratio.*x)
0094 set(handles.figure1,'Resize','on')
0095
0096
0097 color=prt_get_defaults('color');
0098 set(handles.figure1,'Color',color.bg1)
0099 handles.color=color;
0100 aa=get(handles.figure1,'children');
0101 for i=1:length(aa)
0102 if strcmpi(get(aa(i),'type'),'uipanel')
0103 set(aa(i),'BackgroundColor',color.bg2)
0104 bb=get(aa(i),'children');
0105 if ~isempty(bb)
0106 for j=1:length(bb)
0107 if ~isempty(find(strcmpi(get(bb(j),'Style'),{'text',...
0108 'radiobutton','checkbox'})))
0109 set(bb(j),'BackgroundColor',color.bg2)
0110 elseif ~isempty(find(strcmpi(get(bb(j),'Style'),'pushbutton')))
0111 set(bb(j),'BackgroundColor',color.fr)
0112 end
0113 set(bb(j),'FontUnits','pixel')
0114 xf=get(bb(j),'FontSize');
0115 set(bb(j),'FontSize',ceil(FS*xf),'FontName',PF,...
0116 'FontUnits','normalized','Units','normalized')
0117 end
0118 end
0119 else
0120 if ~isempty(find(strcmpi(get(aa(i),'Style'),{'text',...
0121 'radiobutton','checkbox'})))
0122 set(aa(i),'BackgroundColor',color.bg1)
0123 elseif ~isempty(find(strcmpi(get(aa(i),'Style'),'pushbutton')))
0124 set(aa(i),'BackgroundColor',color.fr)
0125 end
0126 end
0127 set(aa(i),'FontUnits','pixel')
0128 xf=get(aa(i),'FontSize');
0129 if ispc
0130 set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0131 'FontUnits','normalized','Units','normalized')
0132 else
0133 set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0134 'Units','normalized')
0135 end
0136 end
0137
0138
0139 handles.saved=0;
0140 set(handles.save_data,'ForegroundColor',handles.color.high)
0141 set(handles.save_data,'FontWeight','bold')
0142 set(handles.text6,'ForegroundColor',handles.color.high)
0143
0144
0145 handles.cgr=1;
0146 handles.cs=1;
0147 handles.cm=1;
0148 handles.cf=1;
0149 handles.dat=struct('dir',[],'group',[],'design',[],'masks',[]);
0150 handles.modlist={};
0151 handles.load_fsmod=0;
0152 end
0153
0154
0155
0156 guidata(hObject, handles);
0157
0158
0159
0160
0161
0162
0163 function varargout = prt_ui_design_OutputFcn(hObject, eventdata, handles)
0164
0165
0166
0167
0168
0169
0170 varargout{1} = handles.output;
0171
0172
0173
0174 function group_list_Callback(hObject, eventdata, handles)
0175
0176
0177
0178
0179
0180
0181 handles.cgr=get(handles.group_list,'Value');
0182 handles.cs=1;
0183 handles.cm=1;
0184 handles.cf=1;
0185 update_display_data(hObject,handles);
0186
0187 handles=guidata(hObject);
0188
0189 guidata(hObject, handles);
0190
0191
0192
0193 function group_list_CreateFcn(hObject, eventdata, handles)
0194
0195
0196
0197
0198
0199
0200 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0201 set(hObject,'BackgroundColor','white');
0202 end
0203
0204
0205
0206 function subjects_list_Callback(hObject, eventdata, handles)
0207
0208
0209
0210
0211
0212
0213
0214 handles.cs=get(handles.subjects_list,'Value');
0215 handles.cm=1;
0216 handles.cf=1;
0217 update_display_data(hObject,handles);
0218 handles=guidata(hObject);
0219
0220 guidata(hObject, handles);
0221
0222
0223 function subjects_list_CreateFcn(hObject, eventdata, handles)
0224
0225
0226
0227
0228
0229
0230 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0231 set(hObject,'BackgroundColor','white');
0232 end
0233
0234
0235
0236 function modality_list_Callback(hObject, eventdata, handles)
0237
0238
0239
0240
0241
0242
0243 handles.cm=get(handles.modality_list,'Value');
0244 handles.cf=1;
0245 update_display_data(hObject,handles);
0246 handles=guidata(hObject);
0247
0248 guidata(hObject, handles);
0249
0250
0251 function modality_list_CreateFcn(hObject, eventdata, handles)
0252
0253
0254
0255
0256
0257
0258 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0259 set(hObject,'BackgroundColor','white');
0260 end
0261
0262
0263
0264 function file_list_Callback(hObject, eventdata, handles)
0265
0266
0267
0268
0269
0270
0271
0272 handles.cf=get(handles.file_list,'Value');
0273 update_display_data(hObject,handles);
0274 handles=guidata(hObject);
0275
0276 guidata(hObject, handles);
0277
0278 guidata(hObject, handles);
0279
0280
0281 function file_list_CreateFcn(hObject, eventdata, handles)
0282
0283
0284
0285
0286
0287
0288 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0289 set(hObject,'BackgroundColor','white');
0290 end
0291
0292
0293
0294 function br_res_dir_Callback(hObject, eventdata, handles)
0295
0296
0297
0298 handles.dat.dir=uigetdir(cd,'Directory to write results');
0299 set(handles.edit1,'String',handles.dat.dir,'FontAngle','normal')
0300 handles.saved=0;
0301 set(handles.save_data,'ForegroundColor',handles.color.high)
0302
0303 guidata(hObject, handles);
0304
0305
0306 function edit1_Callback(hObject, eventdata, handles)
0307
0308
0309
0310
0311
0312
0313 handles.dat.dir=get(handles.edit1,'String');
0314 handles.saved=0;
0315 set(handles.save_data,'ForegroundColor',handles.color.high)
0316
0317 guidata(hObject, handles);
0318
0319
0320 function edit1_CreateFcn(hObject, eventdata, handles)
0321
0322
0323
0324
0325
0326
0327 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0328 set(hObject,'BackgroundColor','white');
0329 end
0330
0331
0332
0333 function gr_add_Callback(hObject, eventdata, handles)
0334
0335
0336
0337 gname=prt_text_input('Title','Enter group name');
0338 if isnumeric(gname)
0339 return
0340 end
0341 if ~isfield(handles,'ds')
0342 handles.ds=cell(1);
0343 else
0344 handles.ds=[handles.ds; cell(1)];
0345 end
0346 ngr=length(handles.ds);
0347 handles.cgr=ngr;
0348 handles.dat.group(ngr).gr_name=gname;
0349 newlist=[get(handles.group_list,'String'); {gname}];
0350 set(handles.group_list,'String',newlist);
0351 val=get(handles.use_scans,'Value');
0352 ren=uicontextmenu;
0353
0354 guidata(hObject, handles);
0355 item1=uimenu(ren,'Label','Rename','Callback',@rengroup);
0356 set(handles.group_list,'UIContextMenu',ren)
0357 handles=guidata(hObject);
0358 if val==1
0359 set(handles.use_scans,'Value',0)
0360 set(handles.subj_add,'enable','on')
0361 set(handles.subj_remove,'enable','on')
0362 end
0363
0364 guidata(hObject, handles);
0365
0366 update_display_data(hObject,handles);
0367 handles=guidata(hObject);
0368 handles.saved=0;
0369 set(handles.save_data,'ForegroundColor',handles.color.high)
0370
0371 guidata(hObject, handles);
0372
0373
0374
0375 function rengroup(hObject,eventdata)
0376 handles=guidata(hObject);
0377 val=get(handles.group_list,'Value');
0378 renam=prt_text_input('Title','Rename group');
0379 if isempty(renam)
0380 return
0381 end
0382 handles.dat.group(val).gr_name=renam;
0383 list=get(handles.group_list,'String');
0384 list{val}=renam;
0385 set(handles.group_list,'String',list)
0386
0387 guidata(hObject, handles);
0388
0389
0390
0391 function gr_remove_Callback(hObject, eventdata, handles)
0392
0393
0394
0395 list=get(handles.group_list,'String');
0396 ngr=length(handles.ds);
0397 if ngr==1
0398 nlist=[];
0399 handles.dat.group=[];
0400 handles.cs=0;
0401 handles.cm=0;
0402 handles.cf=0;
0403 handles=rmfield(handles,'ds');
0404 set(handles.mask_list,...
0405 'String',{'none'},...
0406 'Value',1);
0407 set(handles.text6,'ForegroundColor',handles.color.high)
0408 handles.modlist={};
0409 elseif handles.cgr==1 && ngr>1
0410 nlist={list{2:end}};
0411 handles.dat.group=handles.dat.group(2:end);
0412 handles.ds={handles.ds{2:end}};
0413 handles.cgr=1;
0414 handles.cs=1;
0415 handles.cm=1;
0416 handles.cf=1;
0417 elseif handles.cgr==ngr
0418 nlist={list{1:end-1}};
0419 handles.dat.group=handles.dat.group(1:end-1);
0420 handles.cgr=handles.cgr-1;
0421 handles.ds={handles.ds{1:end-1}};
0422 handles.cs=1;
0423 handles.cm=1;
0424 handles.cf=1;
0425 else
0426 nlist={list{1:handles.cgr-1};list{handles.cgr+1:end}};
0427 handles.ds={handles.ds{1:handles.cgr-1};handles.ds{handles.cgr+1:end}};
0428 handles.dat.group=handles.dat.group([1:handles.cgr-1,handles.cgr+1:end]);
0429 handles.cgr=handles.cgr-1;
0430 handles.cs=1;
0431 handles.cm=1;
0432 handles.cf=1;
0433 end
0434 set(handles.group_list,'String',nlist);
0435 val=get(handles.use_scans,'Value');
0436 if val==1
0437 set(handles.use_scans,'Value',0)
0438 set(handles.subj_add,'enable','on')
0439 set(handles.subj_remove,'enable','on')
0440 end
0441 update_display_data(hObject,handles);
0442 handles=guidata(hObject);
0443 handles.saved=0;
0444 set(handles.save_data,'ForegroundColor',handles.color.high)
0445
0446 guidata(hObject, handles);
0447
0448
0449
0450 function subj_add_Callback(hObject, eventdata, handles)
0451
0452
0453
0454 if ~isfield(handles,'ds') || length(handles.ds)<1
0455 beep
0456 disp(['Please add at least one group before adding subjects'])
0457 return
0458 end
0459 defnam=['S',num2str(length(handles.ds{handles.cgr})+1)];
0460 sname=prt_text_input('Title','Enter subject name','UserData',defnam);
0461 if isnumeric(sname)
0462 return
0463 elseif ~isempty(strfind(lower(sname),'scan'))
0464 beep
0465 disp('Scan(s) is a reserved name. Please correct')
0466 return
0467 end
0468 if isfield(handles.dat.group(handles.cgr),'subject') && ...
0469 isfield(handles.dat.group(handles.cgr).subject,'subj_name')
0470 namlist={handles.dat.group(handles.cgr).subject(:).subj_name};
0471 if any(strcmpi(namlist,sname))
0472 disp(['This subject has already been defined, name attributed is ', ...
0473 'S', num2str(length(namlist)+1)]);
0474 sname=['S', num2str(length(namlist)+1)];
0475 end
0476 end
0477 handles.ds{handles.cgr}=[handles.ds{handles.cgr}, cell(1)];
0478 handles.cs=length(handles.ds{handles.cgr});
0479 if ~isfield(handles.dat.group(handles.cgr),'subject')
0480 handles.dat.group(handles.cgr).subject=[];
0481 end
0482 handles.dat.group(handles.cgr).subject(handles.cs).subj_name=sname;
0483 newlist=[get(handles.subjects_list,'String'); {sname}];
0484 set(handles.subjects_list,'String',newlist);
0485 rens=uicontextmenu;
0486
0487 guidata(hObject, handles);
0488 item1=uimenu(rens,'Label','Rename','Callback',@rensubj);
0489 set(handles.subjects_list,'UIContextMenu',rens)
0490 handles=guidata(hObject);
0491
0492 guidata(hObject, handles);
0493
0494 update_display_data(hObject,handles);
0495 handles=guidata(hObject);
0496 handles.saved=0;
0497 set(handles.save_data,'ForegroundColor',handles.color.high)
0498
0499 guidata(hObject, handles);
0500
0501
0502 function rensubj(hObject,eventdata)
0503 handles=guidata(hObject);
0504 val=get(handles.subjects_list,'Value');
0505 usesc=get(handles.use_scans,'Value');
0506 if usesc
0507 beep
0508 disp('Can not rename subjects with the "scans" option')
0509 return
0510 end
0511 renam=prt_text_input('Title','Rename subject');
0512 if isempty(renam)
0513 return
0514 end
0515 if ~isempty(strfind(lower(renam),'scan'))
0516 beep
0517 disp('Scan(s) is a reserved name. Please correct')
0518 return
0519 end
0520 handles.dat.group(handles.cgr).subject(val).subj_name=renam;
0521 list=get(handles.subjects_list,'String');
0522 list{val}=renam;
0523 set(handles.subjects_list,'String',list)
0524
0525 guidata(hObject, handles);
0526
0527
0528
0529 function use_scans_Callback(hObject, eventdata, handles)
0530
0531
0532
0533
0534
0535 val=get(handles.use_scans,'Value');
0536 if ~isfield(handles.dat,'group') || isempty(handles.ds)
0537 beep
0538 disp('Please add at least one group before adding scans')
0539 return
0540 end
0541 handles.ds{handles.cgr}=cell(1);
0542 handles.cs=1;
0543 handles.dat.group(handles.cgr).subject=[];
0544 if val==1
0545 set(handles.subj_add,'enable','off')
0546 set(handles.subj_remove,'enable','off')
0547 set(handles.subjects_list,'String',{'Scans'});
0548 handles.dat.group(handles.cgr).subject(handles.cs).subj_name='Scans';
0549 else
0550 set(handles.subj_add,'enable','on')
0551 set(handles.subj_remove,'enable','on')
0552 set(handles.subjects_list,'String',{});
0553 end
0554
0555 guidata(hObject, handles);
0556
0557 update_display_data(hObject,handles);
0558 handles=guidata(hObject);
0559 handles.saved=0;
0560 set(handles.save_data,'ForegroundColor',handles.color.high)
0561
0562 guidata(hObject, handles);
0563
0564
0565
0566
0567 function subj_remove_Callback(hObject, eventdata, handles)
0568
0569
0570
0571 list=get(handles.subjects_list,'String');
0572 cgr=handles.cgr;
0573 nsubj=length(handles.ds{cgr});
0574 if nsubj==1
0575 nlist=[];
0576 handles.dat.group(cgr).subject=[];
0577 handles.cs=0;
0578 handles.cm=0;
0579 handles.cf=0;
0580 handles.ds{cgr}={};
0581 set(handles.mask_list,...
0582 'String',{'none'},...
0583 'Value',1);
0584 set(handles.text6,'ForegroundColor',handles.color.high)
0585 handles.modlist={};
0586 handles.dat.masks=[];
0587 elseif handles.cs==1 && nsubj>1
0588 nlist={list{2:end}};
0589 handles.dat.group(cgr).subject=handles.dat.group(cgr).subject(2:end);
0590 handles.ds{cgr}={handles.ds{cgr}{2:end}};
0591 handles.cs=1;
0592 handles.cm=1;
0593 handles.cf=1;
0594 elseif handles.cs==nsubj
0595 nlist={list{1:end-1}};
0596 handles.dat.group(cgr).subject=handles.dat.group(cgr).subject(1:end-1);
0597 handles.ds{cgr}={handles.ds{cgr}{1:end-1}};
0598 handles.cs=handles.cs-1;
0599 handles.cm=1;
0600 handles.cf=1;
0601 else
0602 nlist={list{1:handles.cgr-1};list{handles.cgr+1:end}};
0603 handles.dat.group(cgr).subject=handles.dat.group(cgr).subject([1:handles.cs-1,handles.cs+1:end]);
0604 handles.ds{cgr}={handles.ds{cgr}{1:handles.cs-1},handles.ds{cgr}{handles.cs+1:end}};
0605 handles.cs=handles.cs-1;
0606 handles.cm=1;
0607 handles.cf=1;
0608 end
0609 set(handles.subjects_list,'String',nlist);
0610 update_display_data(hObject,handles);
0611 handles=guidata(hObject);
0612 handles.saved=0;
0613 set(handles.save_data,'ForegroundColor',handles.color.high)
0614
0615 guidata(hObject, handles);
0616
0617
0618 function mod_add_Callback(hObject, eventdata, handles)
0619
0620
0621
0622 if ~isfield(handles,'ds') || length(handles.ds)<1 || ...
0623 length(handles.ds{handles.cgr})<1
0624 beep
0625 disp(['Please add at least one group and one subject before adding modalities'])
0626 return
0627 end
0628 if isfield(handles.dat.group(handles.cgr).subject(1),'modality')
0629 in4=handles.dat.group(handles.cgr).subject(1).modality;
0630 else
0631 in4=[];
0632 end
0633 in1=handles.modlist;
0634 in2=handles.dat.group(handles.cgr).subject(handles.cs);
0635 in3=[];
0636 in5=handles.dat;
0637 mod=prt_data_modality('UserData',{in1,in2,in3,in4,in5});
0638 if isnumeric(mod)
0639 return
0640 end
0641 if isempty(mod.name)
0642 beep
0643 disp('A name should be given to the modality')
0644 return
0645 end
0646 if ~isempty(handles.modlist)
0647 for i=1:length(handles.modlist)
0648 if ~any(strcmpi(handles.modlist,mod.name))
0649 handles.modlist=[handles.modlist, {mod.name}];
0650 end
0651 end
0652 else
0653 handles.modlist=[handles.modlist; {mod.name}];
0654 end
0655 handles.ds{handles.cgr}{handles.cs}=[handles.ds{handles.cgr}{handles.cs}, cell(1)];
0656 handles.cm=length(handles.ds{handles.cgr}{handles.cs});
0657 handles.ds{handles.cgr}{handles.cs}{handles.cm}=size(mod.scans,1);
0658 if ~isfield(handles.dat.group(handles.cgr).subject(handles.cs),'modality')
0659 handles.dat.group(handles.cgr).subject(handles.cs).modality=struct([]);
0660 end
0661
0662
0663 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).mod_name=mod.name;
0664 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).detrend=mod.detrend;
0665 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).covar=mod.covar;
0666 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).rt_subj=mod.rt_subj;
0667 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).design=mod.design;
0668 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).scans=mod.scans;
0669 newlist=[get(handles.modality_list,'String'); {mod.name}];
0670 set(handles.modality_list,'String',newlist);
0671 set(handles.modality_list,'Value',length(newlist));
0672 if ~isempty(handles.modlist)
0673 set(handles.mask_list,'String',handles.modlist);
0674 set(handles.mask_list,'Value',length(handles.modlist));
0675 else
0676 set(handles.mask_list,'String',{'none'});
0677 set(handles.mask_list,'Value',1);
0678 end
0679 if ~isempty(mod.scans)
0680 set(handles.file_list,'String',cellstr(mod.scans));
0681 end
0682 handles.cf=1;
0683 renm=uicontextmenu;
0684 item1=uimenu(renm,'Label','Modify','Callback',@renmod);
0685
0686 guidata(hObject, handles);
0687 set(handles.modality_list,'UIContextMenu',renm)
0688 handles=guidata(hObject);
0689
0690 guidata(hObject, handles);
0691
0692 update_display_data(hObject,handles);
0693 handles=guidata(hObject);
0694 handles.saved=0;
0695 set(handles.save_data,'ForegroundColor',handles.color.high)
0696
0697
0698 guidata(hObject, handles);
0699
0700
0701 function renmod(hObject,eventdata)
0702 handles=guidata(hObject);
0703 val=get(handles.modality_list,'Value');
0704 in1=handles.modlist;
0705 in2=handles.dat.group(handles.cgr).subject(handles.cs);
0706 in3=val;
0707 in4=[];
0708 in5=handles.dat;
0709 mod=prt_data_modality('UserData',{in1,in2,in3,in4,in5});
0710 if isnumeric(mod)
0711 return
0712 end
0713
0714 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).mod_name=mod.name;
0715 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).detrend=mod.detrend;
0716 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).covar=mod.covar;
0717 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).rt_subj=mod.rt_subj;
0718 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).design=mod.design;
0719 handles.dat.group(handles.cgr).subject(handles.cs).modality(handles.cm).scans=mod.scans;
0720
0721
0722
0723 list=get(handles.modality_list,'String');
0724 if ~strcmpi(list{val},mod.name)
0725 flag=0;
0726 if ~isempty(handles.modlist)
0727 for i=1:length(handles.ds)
0728 for j=1:length(handles.ds{i})
0729 if isfield(handles.dat.group(i).subject(j).modality,'mod_name') && ...
0730 any(strcmpi({handles.dat.group(i).subject(j).modality(:).mod_name},list{val}))
0731 flag=flag+1;
0732 end
0733 end
0734 end
0735 if ~flag
0736 for i=1:length(handles.modlist)
0737 if strcmpi(handles.modlist{i},list{get(handles.modality_list,'Value')})
0738 if i==1
0739 handles.modlist={handles.modlist{2:end}};
0740 elseif i==length(handles.modlist)
0741 handles.modlist={handles.modlist{1:end-1}};
0742 else
0743 handles.modlist={handles.modlist{1:i-1}; handles.modlist{i+1:end}};
0744 end
0745 break
0746 end
0747 end
0748 end
0749 end
0750 list{val}=mod.name;
0751 set(handles.modality_list,'String',list);
0752
0753 if isempty(handles.modlist)
0754 set(handles.mask_list,'String',{'none'});
0755 set(handles.mask_list,'Value',1);
0756 else
0757 set(handles.mask_list,'String',handles.modlist);
0758 set(handles.mask_list,'Value',length(handles.modlist));
0759 end
0760 if isfield(handles.dat.masks,'mod_name')
0761 for i=1:size(handles.dat.masks,2)
0762 if strcmpi(handles.dat.masks(i).mod_name, list{val})
0763 indm=i;
0764 end
0765 end
0766 if indm==1
0767 if length(handles.dat.masks)==1
0768 handles.dat.masks=[];
0769 else
0770 handles.dat.masks=handles.dat.masks(2:end);
0771 end
0772 elseif indm==length(handles.dat.masks)
0773 handles.dat.masks=handles.dat.masks(1:end-1);
0774 else
0775 handles.dat.masks=[handles.dat.masks(1:indm-1), handles.dat.masks(indm+1:end)];
0776 end
0777 end
0778 end
0779
0780 guidata(hObject, handles);
0781
0782
0783
0784 function mod_remove_Callback(hObject, eventdata, handles)
0785
0786
0787
0788 list=get(handles.modality_list,'String');
0789 cgr=handles.cgr;
0790 cs=handles.cs;
0791 nmod=length(handles.ds{cgr}{cs});
0792 flag=0;
0793 if nmod==1
0794 nlist=[];
0795 handles.dat.group(cgr).subject(cs).modality=[];
0796 handles.cm=0;
0797 handles.cf=0;
0798 handles.ds{cgr}{cs}={};
0799 elseif handles.cm==1 && nmod>1
0800 nlist={list{2:end}};
0801 handles.dat.group(cgr).subject(cs).modality=handles.dat.group(cgr).subject(cs).modality(2:end);
0802 handles.ds{cgr}{cs}={handles.ds{cgr}{cs}{2:end}};
0803 handles.cm=1;
0804 handles.cf=1;
0805 elseif handles.cm==nmod
0806 nlist={list{1:end-1}};
0807 handles.dat.group(cgr).subject(cs).modality=handles.dat.group(cgr).subject(cs).modality(1:end-1);
0808 handles.ds{cgr}{cs}={handles.ds{cgr}{cs}{1:end-1}};
0809 handles.cm=handles.cm-1;
0810 handles.cf=1;
0811 else
0812 nlist={list{1:handles.cm-1};list{handles.cm+1:end}};
0813 handles.dat.group(cgr).subject(cs).modality=handles.dat.group(cgr).subject(cs).modality([1:handles.cm-1,handles.cm+1:end]);
0814 handles.ds{cgr}{cs}={handles.ds{cgr}{cs}{1:handles.cm-1},handles.ds{cgr}{cs}{handles.cm+1:end}};
0815 handles.cm=handles.cm-1;
0816 handles.cf=1;
0817 end
0818 set(handles.modality_list,'String',nlist);
0819 if ~isempty(handles.modlist)
0820 for i=1:length(handles.ds)
0821 for j=1:length(handles.ds{i})
0822 if isfield(handles.dat.group(i).subject(j).modality,'mod_name') && ...
0823 any(strcmpi({handles.dat.group(i).subject(j).modality(:).mod_name},list{get(handles.modality_list,'Value')}))
0824 flag=flag+1;
0825 end
0826 end
0827 end
0828 if ~flag
0829 for i=1:length(handles.modlist)
0830 if strcmpi(handles.modlist{i},list{get(handles.modality_list,'Value')})
0831 if i==1
0832 handles.modlist={handles.modlist{2:end}};
0833 elseif i==length(handles.modlist)
0834 handles.modlist={handles.modlist{1:end-1}};
0835 else
0836 handles.modlist={handles.modlist{1:i-1}; handles.modlist{i+1:end}};
0837 end
0838 break
0839 end
0840 end
0841 end
0842 end
0843
0844 if isempty(handles.modlist)
0845 set(handles.mask_list,'String',{'none'});
0846 set(handles.mask_list,'Value',1);
0847 else
0848 set(handles.mask_list,'String',handles.modlist);
0849 set(handles.mask_list,'Value',length(handles.modlist));
0850 end
0851 if isfield(handles.dat.masks,'mod_name')
0852 for i=1:size(handles.dat.masks,2)
0853 if strcmpi(handles.dat.masks(i).mod_name, list{get(handles.modality_list,'Value')})
0854 indm=i;
0855 end
0856 end
0857 if indm==1
0858 if length(handles.dat.masks)==1
0859 handles.dat.masks=[];
0860 else
0861 handles.dat.masks=handles.dat.masks(2:end);
0862 end
0863 elseif indm==length(handles.dat.masks)
0864 handles.dat.masks=handles.dat.masks(1:end-1);
0865 else
0866 handles.dat.masks=[handles.dat.masks(1:indm-1), handles.dat.masks(indm+1:end)];
0867 end
0868 end
0869 update_display_data(hObject,handles);
0870 handles=guidata(hObject);
0871 handles.saved=0;
0872 set(handles.save_data,'ForegroundColor',handles.color.high)
0873
0874 guidata(hObject, handles);
0875
0876
0877 function file_add_Callback(hObject, eventdata, handles)
0878
0879
0880
0881
0882
0883 if ~isfield(handles,'ds') || length(handles.ds)<1 || ...
0884 length(handles.ds{handles.cgr})<1 || ...
0885 length(handles.ds{handles.cgr}{handles.cs})<1
0886 beep
0887 disp('Please, select at least one group, subject and modality before adding files')
0888 return
0889 end
0890 cgr=handles.cgr;
0891 cs=handles.cs;
0892 cm=handles.cm;
0893 try
0894 prevlist=cellstr(handles.dat.group(cgr).subject(cs).modality(cm).scans);
0895 catch
0896 prevlist={};
0897 end
0898 fnames=spm_select([1 Inf],'image','Select files for the modality',prevlist);
0899 handles.dat.group(cgr).subject(cs).modality(cm).scans=fnames;
0900 handles.ds{cgr}{cs}{cm}=length(fnames);
0901 handles.cf=1;
0902 set(handles.file_list,'String',cellstr(fnames));
0903
0904 guidata(hObject, handles);
0905
0906 update_display_data(hObject,handles);
0907 handles=guidata(hObject);
0908 handles.saved=0;
0909 set(handles.save_data,'ForegroundColor',handles.color.high)
0910
0911 guidata(hObject, handles);
0912
0913
0914
0915
0916 function mask_list_Callback(hObject, eventdata, handles)
0917
0918
0919
0920
0921
0922
0923
0924 warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0925 list=get(handles.mask_list,'String');
0926
0927 if length(list)==1
0928 set(handles.mask_list,'Value',1)
0929 end
0930
0931 val=list{get(handles.mask_list,'Value')};
0932 flag=0;
0933 if ~isfield(handles.dat.masks,'mod_name')
0934 sel='';
0935 indm=1;
0936 else
0937 for i=1:size(handles.dat.masks,2)
0938 if strcmpi(handles.dat.masks(i).mod_name, val)
0939 sel=handles.dat.masks(i).fname;
0940 indm=i;
0941 flag=1;
0942 end
0943 end
0944 if ~flag
0945 sel='';
0946 indm=length(handles.dat.masks)+1;
0947 end
0948 end
0949 mname=spm_select(1,'image',['Select mask for ',val],cellstr(sel));
0950 if ~isempty(mname)
0951 handles.dat.masks(indm).mod_name=val;
0952 handles.dat.masks(indm).fname=mname;
0953 end
0954
0955
0956 if length(handles.modlist)==length(handles.dat.masks)
0957 f=0;
0958 for i=1:length(handles.modlist)
0959 if ~isempty(handles.dat.masks(i))
0960 f=f+1;
0961 end
0962 end
0963 if f==length(handles.modlist)
0964 set(handles.text6,'ForegroundColor',[0 0 0])
0965 else
0966 set(handles.text6,'ForegroundColor',handles.color.high)
0967 end
0968 end
0969
0970 handles.saved=0;
0971 set(handles.save_data,'ForegroundColor',handles.color.high)
0972
0973 guidata(hObject, handles);
0974
0975
0976
0977 function mask_list_CreateFcn(hObject, eventdata, handles)
0978
0979
0980
0981
0982
0983
0984 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0985 set(hObject,'BackgroundColor','white');
0986 end
0987
0988
0989 function load_butt_Callback(hObject, eventdata, handles)
0990
0991
0992
0993
0994
0995 prtname = spm_select(1,'mat','Select PRT.mat',[],pwd,'PRT.mat');
0996 PRT=prt_load(prtname);
0997 if isempty(PRT)
0998 beep
0999 disp('Could not load file')
1000 return
1001 end
1002 handles.dat=PRT;
1003 set(handles.save_data,'ForegroundColor',[0 0 0])
1004
1005
1006
1007
1008 handles.saved=1;
1009
1010 if ~isfield(PRT.masks,'mod_name')
1011 flagmask=0;
1012 handles.modlist={};
1013 else
1014 handles.modlist={PRT.masks(:).mod_name};
1015 flagmask=1;
1016 end
1017
1018
1019 if isfield(PRT,'group')
1020 ng=length(PRT.group);
1021 handles.ds=cell(ng,1);
1022 for i=1:ng
1023 if isfield(PRT.group(i),'subject')
1024 ns=length(PRT.group(i).subject);
1025 handles.ds{i}=cell(1,ns);
1026 for j=1:ns
1027 if ~isfield(PRT.group(i).subject,'subj_name')
1028 handles.saved=0;
1029 set(handles.save_data,'ForegroundColor',handles.color.high)
1030 PRT.group(i).subject(j).subj_name=['S',num2str(j)];
1031 end
1032 if isfield(PRT.group(i).subject(j),'modality')
1033 nm=length(PRT.group(i).subject(j).modality);
1034 handles.ds{i}{j}=cell(1,nm);
1035 for k=1:nm
1036
1037
1038 if ~flagmask
1039 mname=PRT.group(i).subject(j).modality(k).mod_name;
1040 if ~any(strcmpi(handles.modlist,mname))
1041 handles.saved=0;
1042 handles.modlist=[handles.modlist, {mname}];
1043 end
1044 end
1045 handles.ds{i}{j}{k}=size(PRT.group(i).subject(j).modality(k).scans,1);
1046 end
1047 end
1048 end
1049 end
1050 end
1051 end
1052
1053 if ~flagmask==1
1054 disp('The files for masking are not linked to a modality name')
1055 disp('The information was erased. Please select the mask files')
1056 PRT.masks=struct();
1057 handles.saved=0;
1058 set(handles.save_data,'ForegroundColor',handles.color.high)
1059 set(handles.text6,'ForegroundColor',handles.color.high)
1060 end
1061 if ~isempty(handles.modlist)
1062 set(handles.mask_list,'String',handles.modlist);
1063 else
1064 set(handles.mask_list,'String',{'none'});
1065 end
1066 handles.cgr=1;
1067 handles.cs=1;
1068 handles.cm=1;
1069 handles.cf=1;
1070 a=fileparts(prtname);
1071 set(handles.edit1,'String',a)
1072 set(handles.group_list,'String',{PRT.group(:).gr_name})
1073
1074
1075
1076 ren=uicontextmenu;
1077
1078 guidata(hObject, handles);
1079 item1=uimenu(ren,'Label','Rename','Callback',@rengroup);
1080 set(handles.group_list,'UIContextMenu',ren)
1081 handles=guidata(hObject);
1082
1083 rens=uicontextmenu;
1084
1085 guidata(hObject, handles);
1086 item1=uimenu(rens,'Label','Rename','Callback',@rensubj);
1087 set(handles.subjects_list,'UIContextMenu',rens)
1088 handles=guidata(hObject);
1089
1090 renm=uicontextmenu;
1091 item1=uimenu(renm,'Label','Modify','Callback',@renmod);
1092
1093 guidata(hObject, handles);
1094 set(handles.modality_list,'UIContextMenu',renm)
1095 handles=guidata(hObject);
1096
1097
1098 if isfield(PRT,'fs')
1099 beep
1100 disp('Fields refering to feature sets have been found')
1101 disp('These will be removed if modifications to the dataset are performed')
1102 disp('Previously computed models will also be deleted')
1103 disp('Be sure to change the directory if you want to keep trace of previous work')
1104 handles.load_fsmod=1;
1105 else
1106 handles.load_fsmod=0;
1107 end
1108
1109 handles.dat=PRT;
1110 handles.dat.dir=a;
1111
1112 guidata(hObject, handles);
1113
1114 update_display_data(hObject,handles);
1115 handles=guidata(hObject);
1116 set(handles.text6,'ForegroundColor',[0 0 0])
1117
1118 guidata(hObject, handles);
1119
1120
1121
1122 function save_data_Callback(hObject, eventdata, handles)
1123
1124
1125
1126
1127 if handles.load_fsmod
1128 sure=prt_ui_sure;
1129 if ~sure || isempty(sure)
1130 return
1131 end
1132 end
1133
1134
1135 if ~isfield(handles,'ds') || length(handles.ds) <1 || ...
1136 length(handles.ds{1})<1 || length(handles.ds{1}{1})<1
1137 beep
1138 disp('Please, enter at least one group completed before saving')
1139 return
1140 end
1141
1142
1143
1144 for i=1:length(handles.ds)
1145 if ~isempty(strfind(lower(handles.dat.group(i).subject(1).subj_name),'scan'))
1146 subj=struct();
1147 nsubj=handles.ds{i}{1}{1};
1148 for j=1:length(handles.dat.group(i).subject(1).modality)
1149 nsubj2=handles.ds{i}{1}{j};
1150 if nsubj ~=nsubj2
1151 beep
1152 sprintf('Number of subjects in modality %d and 1 of group %d are different ',j,i)
1153 disp('Please correct')
1154 return
1155 end
1156 end
1157 handles.ds{i}=cell(nsubj,1);
1158 for k=1:nsubj
1159 subj(k).subj_name=['S', num2str(k)];
1160 nmod=length(handles.dat.group(i).subject(1).modality);
1161 handles.ds{i}{k}=cell(nmod);
1162 for j=1:nmod
1163 handles.ds{i}{k}{j}=1;
1164 subj(k).modality(j)=handles.dat.group(i).subject(1).modality(j);
1165 subj(k).modality(j).scans=subj(k).modality(j).scans(k,:);
1166 if ~isempty(handles.dat.group(i).subject(1).modality(j).rt_subj)
1167 subj(k).modality(j).rt_subj=subj(k).modality(j).rt_subj(k);
1168 else
1169 subj(k).modality(j).rt_subj=[];
1170 end
1171 if ~isempty(handles.dat.group(i).subject(1).modality(j).covar)
1172 subj(k).modality(j).covar=subj(k).modality(j).covar(k,:);
1173 else
1174 subj(k).modality(j).covar=[];
1175 end
1176 end
1177 end
1178 handles.dat.group(i).subject=subj;
1179 end
1180 end
1181
1182
1183
1184
1185 ng=length(handles.ds);
1186 nm=length(handles.ds{1}{1});
1187 ns=length(handles.ds{1});
1188 list=get(handles.mask_list,'String');
1189 nmask=length(list);
1190
1191 if nmask~=length(handles.dat.masks)
1192 beep
1193 sprintf('%d masks were found, while %d modalities were added',length(handles.dat.masks),nmask)
1194 disp('Please correct')
1195 return
1196 end
1197
1198 for i=1:ng
1199 matdat=zeros(ns,nm);
1200 ns=length(handles.ds{i});
1201 for j=1:ns
1202 nmi=length(handles.ds{i}{1});
1203 nmj=length(handles.ds{i}{j});
1204 if nmj~=nmi
1205 beep
1206 sprintf('Numbers of modalities in subjects 1 and %d from group %d differ', j,i)
1207 disp('Please correct')
1208 return
1209 elseif nmj~=nm
1210 beep
1211 sprintf('Numbers of modalities in groups 1 and %d differ \n',i)
1212 disp('Please correct')
1213 return
1214 elseif nmj~=nmask
1215 beep
1216 sprintf('%d modalities found for subject %d of group %d, while %d masks found \n',nmj,j,i,nmask)
1217 disp('Possible errors in the modalities names, please correct')
1218 return
1219 end
1220 for k=1:nm
1221 m2=find(strcmpi({handles.dat.group(i).subject(j).modality(:).mod_name},list(k)));
1222 matdat(j,k)=handles.ds{i}{j}{m2};
1223 if isstruct(handles.dat.group(i).subject(j).modality(m2).design)
1224 des=handles.dat.group(i).subject(j).modality(m2).design;
1225 maxcond=max([des.conds(:).scans]);
1226 if matdat(j,k)<maxcond
1227 beep
1228 sprintf('Design of subject %d, group %d, modality %d, exceeds time series \n',j,i,k)
1229 disp('Corresponding events were discarded')
1230 for l=1:length(des.conds)
1231 ovser=find(des.conds(l).scans>matdat(j,k));
1232 inser=find(des.conds(l).scans<=matdat(j,k));
1233 des.conds(l).discardedscans=[des.conds(l).discardedscans, des.conds(l).scans(ovser)];
1234 des.conds(l).scans=des.conds(l).scans(inser);
1235 des.conds(l).blocks=des.conds(l).blocks(inser);
1236 end
1237 handles.dat.group(i).subject(j).modality(m2).design=des;
1238 end
1239 end
1240 end
1241 handles.dat.group(i).subject(j).modality(k)=handles.dat.group(i).subject(j).modality(m2);
1242 end
1243 end
1244 def=prt_get_defaults('datad');
1245
1246 disp('Saving the data.....>>')
1247 PRT=struct();
1248 PRT.group=handles.dat.group;
1249
1250 if ~isfield(handles.dat.group(1),'hrfoverlap')
1251 for i=1:ng
1252 PRT.group(i).hrfoverlap=def.hrfw;
1253 end
1254 end
1255 if ~isfield(handles.dat.group(1),'hrfdelay')
1256 for i=1:ng
1257 PRT.group(i).hrfdelay=def.hrfd;
1258 end
1259 end
1260 PRT.masks=handles.dat.masks;
1261
1262
1263
1264 if isfield(PRT,'fs')
1265 PRT=rmfield(PRT,'fs');
1266 beep
1267 disp('Fields refering to feature sets have been found')
1268 disp('These will be removed')
1269 disp('Be sure to change the directory if you want to keep trace of previous work')
1270 end
1271 if isfield(PRT,'fas')
1272 PRT=rmfield(PRT,'fas');
1273 end
1274 if isfield(PRT,'model')
1275 PRT=rmfield(PRT,'model');
1276 end
1277
1278
1279 resn=fullfile(handles.dat.dir,'PRT.mat');
1280 save(resn,'PRT')
1281
1282 handles.saved=1;
1283 disp('Save Done')
1284 set(handles.save_data,'ForegroundColor',[0 0 0])
1285 cd(handles.dat.dir)
1286
1287
1288 guidata(hObject, handles);
1289
1290
1291
1292 function review_button_Callback(hObject, eventdata, handles)
1293
1294
1295
1296 try
1297 nm=length(handles.dat.group(1).subject(1).modality);
1298 catch
1299 beep
1300 disp('Please enter at least one subject in one group before reviewing')
1301 return
1302 end
1303 try
1304 nma=length(handles.dat.masks);
1305 catch
1306 beep
1307 disp('A mask should be specified for each modality before reviewing')
1308 return
1309 end
1310 if nm~=nma
1311 beep
1312 disp('Number of masks does not match number of modalities')
1313 disp('Please, correct')
1314 return
1315 end
1316 if ~(handles.saved)
1317 PRT=struct();
1318 PRT.group=handles.dat.group;
1319 PRT.masks=handles.dat.masks;
1320 else
1321 fname=[get(handles.edit1,'String'),filesep,'PRT.mat'];
1322 PRT=prt_load(fname);
1323 if isempty(PRT)
1324 beep
1325 disp('Could not load the saved PRT.mat')
1326 return
1327 end
1328 end
1329 prt_data_review('UserData',{PRT,handles.dat.dir});
1330 fname=[get(handles.edit1,'String'),filesep,'PRT.mat'];
1331 PRT=prt_load(fname);
1332 handles.dat.group=PRT.group;
1333 handles.dat.masks=PRT.masks;
1334
1335 guidata(hObject, handles);
1336
1337
1338
1339
1340 function quit_data_Callback(hObject, eventdata, handles)
1341
1342
1343
1344
1345
1346 if ~isfield(handles,'ds') || length(handles.ds) <1 || ...
1347 length(handles.ds{1})<1 || length(handles.ds{1}{1})<1
1348
1349 delete(handles.figure1);
1350 else
1351 if ~handles.saved
1352 beep
1353 disp('Modifications performed since last saving, please save again')
1354 return
1355 else
1356
1357 delete(handles.figure1);
1358 end
1359 end
1360
1361
1362
1363
1364
1365
1366 function update_display_data(hObject,hand)
1367
1368 ng=hand.cgr;
1369 ns=hand.cs;
1370 nm=hand.cm;
1371 nf=hand.cf;
1372
1373 set(hand.group_list,'Value',ng)
1374
1375 try
1376 set(hand.subjects_list,'String',{hand.dat.group(ng).subject(:).subj_name})
1377 set(hand.subjects_list,'Value',ns)
1378 catch
1379 set(hand.subjects_list,'String',{})
1380 end
1381
1382 try
1383 set(hand.modality_list,'String',{hand.dat.group(ng).subject(ns).modality(:).mod_name})
1384 set(hand.modality_list,'Value',nm)
1385 catch
1386 set(hand.modality_list,'String',{})
1387 end
1388
1389 try
1390 set(hand.file_list,'String',{hand.dat.group(ng).subject(ns).modality(nm).scans})
1391 set(hand.file_list,'Value',nf)
1392 catch
1393 set(hand.file_list,'String',{})
1394 end
1395
1396
1397 guidata(hObject, hand);