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