Home > phiwave > phiwave.m

phiwave

PURPOSE ^

Startup, callback and utility routine for Phiwave

SYNOPSIS ^

function varargout=phiwave(varargin)

DESCRIPTION ^

 Startup, callback and utility routine for Phiwave

 Phiwave: Functional image wavelet analysis 

 Phiwave (the collection of files listed by Contents.m) is copyright under
 the GNU general public license.  Please see phiw_licence.man for details.
 
 Phiwave written by 
 John Aston, Matthew Brett, Rainer Hinz and Federico Turkheimer

 Data structures, programming style and portions of the code rely heavily
 on SPM (http://www.fil.ion.ucl.ac.uk/spm), which is also released
 under the GNU public licence.  Many thanks the SPM authors:
 (John Ashburner, Karl Friston, Andrew Holmes, Jean-Baptiste Poline et al).

 $Id: phiwave.m,v 1.21 2005/07/07 01:01:24 matthewbrett Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout=phiwave(varargin) 
0002 % Startup, callback and utility routine for Phiwave
0003 %
0004 % Phiwave: Functional image wavelet analysis
0005 %
0006 % Phiwave (the collection of files listed by Contents.m) is copyright under
0007 % the GNU general public license.  Please see phiw_licence.man for details.
0008 %
0009 % Phiwave written by
0010 % John Aston, Matthew Brett, Rainer Hinz and Federico Turkheimer
0011 %
0012 % Data structures, programming style and portions of the code rely heavily
0013 % on SPM (http://www.fil.ion.ucl.ac.uk/spm), which is also released
0014 % under the GNU public licence.  Many thanks the SPM authors:
0015 % (John Ashburner, Karl Friston, Andrew Holmes, Jean-Baptiste Poline et al).
0016 %
0017 % $Id: phiwave.m,v 1.21 2005/07/07 01:01:24 matthewbrett Exp $
0018 
0019 % Programmer's help
0020 % -----------------
0021 % For a list of the functions implemented here, try
0022 % grep "^case " phiwave.m
0023 %
0024 % To make a release, use the MarsBaR release/pre_release script with
0025 % something like:
0026 %
0027 % pre_release('matthewbrett', '-%s', pwd, 'phiwave', 'Phiwave wavelet toolbox');
0028 %
0029 % Don't forget to update the Phiwave and required MarsBaR version
0030 % numbers, change into a temporary directory, and put m2html on the path
0031 % before running the pre_release script.
0032   
0033 % Third sourceforge release; alpha
0034 PWver = '3.2';  
0035 
0036 % Required MarsBaR version
0037 MBver = '0.38.2';
0038 
0039 % Various working variables in global variable structure
0040 global PHI;
0041 
0042 %-Format arguments
0043 %-----------------------------------------------------------------------
0044 if nargin == 0, Action='Startup'; else, Action = varargin{1}; end
0045 
0046 %=======================================================================
0047 switch lower(Action), case 'startup'                     %-Start phiwave
0048 %=======================================================================
0049 
0050 %-Turn on warning messages for debugging
0051 warning backtrace
0052 
0053 % splash screen once per session
0054 splashf = ~phiwave('is_started');
0055 
0056 % promote spm directory to top of path, read defaults
0057 phiwave('on');
0058 
0059 %-Open startup window, set window defaults
0060 %-----------------------------------------------------------------------
0061 S = get(0,'ScreenSize');
0062 if all(S==1), error('Can''t open any graphics windows...'), end
0063 PF = spm_platform('fonts');
0064 
0065 % Splash screen
0066 %------------------------------------------
0067 if splashf
0068   phiwave('splash');
0069 end
0070 
0071 %-Draw phiwave window
0072 %-----------------------------------------------------------------------
0073 Fmenu = phiwave('CreateMenuWin','off');
0074 
0075 %-Reveal windows
0076 %-----------------------------------------------------------------------
0077 set([Fmenu],'Visible','on')
0078 
0079 %=======================================================================
0080 case 'on'                                           %-Initialise Phiwave
0081 %=======================================================================
0082 
0083 % check path for SPM
0084 if isempty(which('spm'))
0085   error('SPM does not appear to be on the path')
0086 end
0087 
0088 % check path for MarsBaR
0089 if isempty(which('marsbar'))
0090   marsbar_path = fullfile(spm('dir'), 'toolbox', 'marsbar');
0091   if exist(marsbar_path, 'dir')
0092     addpath(marsbar_path);
0093   else
0094     error('Cannot find MarsBaR - MarsBaR should be on your matlab path');
0095   end
0096 end
0097 
0098 % check MarsBaR version
0099 badv = 1;
0100 try
0101   badv = mars_utils('version_less_than', marsbar('ver'), MBver); 
0102 end
0103 if badv, error(['Need at least MarsBaR version ' MBver]); end
0104 
0105 % start MarsBaR
0106 marsbar('on');
0107 
0108 % promote Phiwave analysis directories
0109 pwpath = fileparts(which('phiwave.m'));
0110 PHI.ADDPATHS = {fullfile(pwpath, 'uvi_wave')};
0111 addpath(PHI.ADDPATHS{:}, '-begin');
0112 fprintf('Phiwave analysis functions prepended to path\n');
0113 
0114 % check SPM defaults are loaded
0115 mars_veropts('defaults');
0116 
0117 % set up the ARMOIRE stuff
0118 % see marmoire help for details
0119 if isfield(PHI, 'ARMOIRE')
0120   o = PHI.ARMOIRE; 
0121 else
0122   o = marmoire;
0123 end
0124 
0125 spm_design_filter = mars_veropts('design_filter_spec');
0126 filter_specs  = {spm_design_filter,...
0127          {'*phiw_spm.mat', 'Phiwave results (*phiw_spm.mat)'}};
0128 o = add_if_absent(o, 'def_design', ...
0129           struct('default_file_name', 'SPMcfg.mat',...      
0130              'filter_spec', {filter_specs{1}},...
0131              'title', 'Default design',...
0132              'set_action','phiw_arm_call(''set_design'',o,item,old_o)'));
0133 o = add_if_absent(o, 'est_design',...
0134           struct('default_file_name', 'untitled_phiw_spm.mat',...
0135              'filter_spec', {filter_specs{2}},...
0136              'title', 'Phiwave estimated design',...
0137              'set_action', 'phiw_arm_call(''set_results'',o,item,old_o)'));
0138 PHI.ARMOIRE = o;
0139 
0140 % and workspace
0141 if ~isfield(PHI, 'WORKSPACE'), PHI.WORKSPACE = []; end
0142 
0143 % read any necessary defaults
0144 if ~mars_struct('isthere', PHI, 'OPTIONS')
0145   loadf = 1;
0146   PHI.OPTIONS = [];
0147 else
0148   loadf = 0;
0149 end
0150 [pwdefs sourcestr] = phiw_options('Defaults');
0151 PHI.OPTIONS = phiw_options('fill', PHI.OPTIONS, pwdefs);
0152 if loadf
0153   fprintf('Loaded Phiwave defaults from %s\n',sourcestr);
0154 end
0155 
0156 %=======================================================================
0157 case 'off'                                              %-Unload Phiwave
0158 %=======================================================================
0159 % res = phiwave('Off')
0160 %-----------------------------------------------------------------------
0161 varargout = {0};
0162 
0163 % leave if no signs of phiwave
0164 if ~phiwave('is_started'), return, end
0165 
0166 % save outstanding information
0167 btn = phiw_arm('save_ui', 'all', struct('ync', 1, 'no_no_save', 1));
0168 if btn == -1, varargout = {-1}; return, end % cancel
0169 
0170 % remove phiwave added directories, unstart marsbar
0171 rmpath(PHI.ADDPATHS{:});
0172 marsbar('off');
0173 fprintf('Phiwave analysis functions removed from path\n');
0174 
0175 %=======================================================================
0176 case 'quit'                                        %-Quit Phiwave window
0177 %=======================================================================
0178 % phiwave('Quit')
0179 %-----------------------------------------------------------------------
0180 
0181 % do path stuff, save any pending changes
0182 if phiwave('off') == -1, return, end % check for cancel
0183 
0184 % leave if no signs of PHIWAVE
0185 if ~phiwave('is_started'), return, end
0186 
0187 %-Close any existing 'Phiwave' 'Tag'ged windows
0188 delete(spm_figure('FindWin','Phiwave'));
0189 fprintf('Arrivederci...\n\n');
0190 
0191 %=======================================================================
0192 case 'is_started'        %-returns 1 if Phiwave GUI has been initialized
0193 %=======================================================================
0194 % tf  = phiwave('is_started')
0195 varargout = {~isempty(PHI)};
0196 
0197 %=======================================================================
0198 case 'cfgfile'                                  %-finds Phiwave cfg file
0199 %=======================================================================
0200 % cfgfn  = phiwave('cfgfile')
0201 cfgfile = 'phiwavecfg.mat';
0202 varargout = {which(cfgfile), cfgfile}; 
0203 
0204 %=======================================================================
0205 case 'createmenuwin'                          %-Draw Phiwave menu window
0206 %=======================================================================
0207 % Fmenu = phiwave('CreateMenuWin',Vis)
0208 if nargin<2, Vis='on'; else, Vis=varargin{2}; end
0209 
0210 %-Close any existing 'Phiwave' 'Tag'ged windows
0211 delete(spm_figure('FindWin','Phiwave'))
0212 
0213 % Version etc info
0214 [PWver,PWc] = phiwave('Ver');
0215 
0216 %-Get size and scalings and create Menu window
0217 %-----------------------------------------------------------------------
0218 WS   = spm('WinScale');                %-Window scaling factors
0219 FS   = spm('FontSizes');            %-Scaled font sizes
0220 PF   = spm_platform('fonts');            %-Font names (for this platform)
0221 Rect = [50 600 300 275];               %-Raw size menu window rectangle
0222 bno = 4; bgno = bno+1;
0223 bgapr = 0.25;
0224 bh = Rect(4) / (bno + bgno*bgapr);      % Button height
0225 gh = bh * bgapr;                        % Button gap
0226 by = fliplr(cumsum([0 ones(1, bno-1)*(bh+gh)])+gh);
0227 bx = Rect(3)*0.1;
0228 bw = Rect(3)*0.8;
0229 Fmenu = figure('IntegerHandle','off',...
0230     'Name',sprintf('%s',PWc),...
0231     'NumberTitle','off',...
0232     'Tag','Phiwave',...
0233     'Position',Rect.*WS,...
0234     'Resize','off',...
0235     'Color',[1 1 1]*.8,...
0236     'UserData',struct('PWver',PWver,'PWc',PWc),...
0237     'MenuBar','none',...
0238     'DefaultTextFontName',PF.helvetica,...
0239     'DefaultTextFontSize',FS(12),...
0240     'DefaultUicontrolFontName',PF.helvetica,...
0241     'DefaultUicontrolFontSize',FS(12),...
0242     'DefaultUicontrolInterruptible','on',...
0243     'Renderer','painters',...
0244     'Visible','off');
0245 
0246 %-Objects with Callbacks - main Phiwave routines
0247 %=======================================================================
0248 
0249 % Design menu
0250 fw_st = 'struct(''force'', 1, ''warn_empty'', 1)';
0251 funcs = {...
0252     'phiwave(''make_design'', ''pet'');',...
0253     'phiwave(''make_design'', ''fmri'');',...
0254     'phiwave(''make_design'', ''basic'');',...
0255     'phiwave(''design_report'')',...
0256     'phiwave(''add_images'')',...
0257     'phiwave(''edit_filter'')',...
0258     'phiwave(''check_images'')',...
0259     'phiwave(''list_images'')',...
0260     'phiwave(''ana_cd'')',...
0261     'phiwave(''ana_desmooth'')',...
0262     'phiwave(''explicit_mask'')',...
0263     'phiwave(''def_from_est'')',...
0264     'phiwave(''set_def'');',...
0265     ['phiw_arm(''save_ui'', ''def_design'', ' fw_st ');'],...
0266     'phiw_arm(''show_summary'', ''def_design'')'};
0267 
0268 uicontrol(Fmenu,'Style','PopUp',...
0269       'String',['Design...'...
0270             '|PET models',...
0271             '|FMRI models',...
0272             '|Basic models',...
0273             '|Explore',...
0274             '|Add images to FMRI design',...
0275             '|Add/edit filter for FMRI design',...    
0276             '|Check image names in design',...
0277             '|List image names to console',...
0278             '|Change design path to images',...
0279             '|Convert to unsmoothed',...
0280             '|Set explicit mask for design',...
0281             '|Set design from estimated',...
0282             '|Set design from file',...
0283             '|Save design to file',...
0284             '|Show default design summary'],...
0285       'Position',[bx by(1) bw bh].*WS,...
0286       'ToolTipString','Set/specify design...',...
0287       'CallBack','spm(''PopUpCB'',gcbo)',...
0288       'UserData',funcs);
0289 
0290 % results menu
0291 funcs = {...
0292     'phiwave(''estimate'');',...
0293     'phiwave(''merge_contrasts'');',...
0294     'phiwave(''add_trial_f'');',...
0295     'phiwave(''set_defcon'');',...
0296     'phiwave(''writecons'')',...
0297     'phiwave(''denoisecon'')',...
0298     'phiw_display(''display'', ''slices'')',...
0299     'phiw_display(''display'', ''orth'')',...
0300     'phiwave(''set_results'');',...
0301     ['phiw_arm(''save_ui'', ''est_design'', ' fw_st ');'],...
0302     'phiw_arm(''show_summary'', ''est_design'')'};
0303 
0304 uicontrol(Fmenu,'Style','PopUp',...
0305       'String',['Results...'...
0306             '|Estimate results',...
0307             '|Import contrasts',...
0308             '|Add trial-specific F',...
0309             '|Default contrast...',...
0310             '|Specify / write contrast', ...
0311             '|Denoise contrast' ...
0312             '|Display slices',...
0313             '|Display sections',...
0314             '|Set results from file',...
0315             '|Save results to file',...
0316             '|Show estimated design summary'],...
0317       'Position',[bx by(2) bw bh].*WS,...
0318       'ToolTipString','Write/display contrasts...',...
0319       'CallBack','spm(''PopUpCB'',gcbo)',...
0320       'UserData',funcs);
0321 
0322 funcs = {'global PHI; PHI.OPTIONS=phiw_options(''load'');',...
0323      'phiw_options(''save'');',...
0324      'global PHI; PHI.OPTIONS=phiw_options(''edit'');',...
0325      ['global PHI; [PHI.OPTIONS str]=phiw_options(''defaults'');' ...
0326       ' fprintf(''Defaults loaded from %s\n'', str)']};
0327      
0328 uicontrol(Fmenu,'Style','PopUp',...
0329       'String',['Options...'...
0330           '|Load options|Save options|Edit options|Restore defaults'],...
0331       'Position',[bx by(3) bw bh].*WS,...
0332       'ToolTipString','Load/save/edit Phiwave options',...
0333       'CallBack','spm(''PopUpCB'',gcbo)',...
0334       'UserData',funcs);
0335 
0336 % quit button
0337 uicontrol(Fmenu,'String','Quit',...
0338       'Position',[bx by(bno) bw bh].*WS,...
0339       'ToolTipString','exit Phiwave',...
0340       'ForeGroundColor','r',...
0341       'Interruptible','off',...
0342       'CallBack','phiwave(''Quit'')');
0343 
0344 % Set quit action if Phiwave window is closed
0345 %-----------------------------------------------------------------------
0346 set(Fmenu,'CloseRequestFcn','phiwave(''Quit'')')
0347 set(Fmenu,'Visible',Vis)
0348 
0349 varargout = {Fmenu};
0350 
0351 %=======================================================================
0352 case {'ver', 'version'}                         %-Return Phiwave version
0353 %=======================================================================
0354 % [v [,banner]] = phiwave('Ver')
0355 %-----------------------------------------------------------------------
0356 varargout = {PWver, 'Phiwave - wavelet analysis toolbox'};
0357 
0358 %=======================================================================
0359 case 'splash'                                       %-show splash screen
0360 %=======================================================================
0361 % phiwave('splash')
0362 %-----------------------------------------------------------------------
0363 % Shows splash screen
0364 WS   = spm('WinScale');        %-Window scaling factors
0365 [X,map] = imread('phiwave.jpg');
0366 aspct = size(X,1) / size(X,2);
0367 ww = 400;
0368 srect = [200 300 ww ww*aspct] .* WS;   %-Scaled size splash rectangle
0369 h = figure('visible','off',...
0370        'menubar','none',...
0371        'numbertitle','off',...
0372        'name','Welcome to Phiwave',...
0373        'pos',srect);
0374 im = image(X);
0375 colormap(map);
0376 ax = get(im, 'Parent');
0377 axis off;
0378 axis image;
0379 axis tight;
0380 set(ax,'plotboxaspectratiomode','manual',...
0381        'unit','pixels',...
0382        'pos',[0 0 srect(3:4)]);
0383 set(h,'visible','on');
0384 pause(3);
0385 close(h);
0386  
0387 %=======================================================================
0388 case 'make_design'                       %-runs design creation routines
0389 %=======================================================================
0390 % phiwave('make_design', des_type)
0391 %-----------------------------------------------------------------------
0392 if nargin < 2
0393   des_type = 'basic';
0394 else
0395   des_type = varargin{2};
0396 end
0397 if sf_prev_save('def_design') == -1, return, end
0398 D = ui_build(mars_veropts('default_design'), des_type);
0399 phiw_arm('set', 'def_design', D);
0400 phiwave('design_report');
0401 
0402 %=======================================================================
0403 case 'list_images'                     %-lists image files in SPM design
0404 %=======================================================================
0405 % phiwave('list_images')
0406 %-----------------------------------------------------------------------
0407 phiwD = phiw_arm('get', 'def_design');
0408 if isempty(phiwD), return, end;
0409 if has_images(phiwD)
0410   P = image_names(phiwD);
0411   strvcat(P{:})
0412 else
0413   disp('Design does not contain images');
0414 end
0415 
0416 %=======================================================================
0417 case 'check_images'                   %-checks image files in SPM design
0418 %=======================================================================
0419 % phiwave('check_images')
0420 %-----------------------------------------------------------------------
0421 phiwD = phiw_arm('get', 'def_design');
0422 if isempty(phiwD), return, end;
0423 if ~has_images(phiwD)
0424   disp('Design does not contain images');
0425   return
0426 end
0427 
0428 P = image_names(phiwD);
0429 P = strvcat(P{:});
0430 ok_f = 1;
0431 for i = 1:size(P, 1)
0432   fname = deblank(P(i,:));
0433   if ~exist(fname, 'file');
0434     fprintf('Image %d: %s does not exist\n', i, fname);
0435     ok_f = 0;
0436   end
0437 end
0438 if ok_f
0439   disp('All images in design appear to exist');
0440 end
0441 
0442 %=======================================================================
0443 case 'ana_cd'                      %-changes path to files in SPM design
0444 %=======================================================================
0445 % phiwave('ana_cd')
0446 %-----------------------------------------------------------------------
0447 phiwD = phiw_arm('get', 'def_design');
0448 if isempty(phiwD), return, end;
0449 
0450 % Setup input window
0451 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Change image path in design', 0);
0452 
0453 % root path shown in output window
0454 P = image_names(phiwD);
0455 P = strvcat(P{:});
0456 root_names = spm_str_manip(P, 'H');
0457 spm_input(deblank(root_names(1,:)),1,'d','Common path is:');
0458 
0459 % new root
0460 newpath = spm_get([-1 0], '', 'New directory root for files');
0461 if isempty(newpath), return, end
0462 
0463 % do
0464 phiwD = cd_images(phiwD, newpath);
0465 phiw_arm('set', 'def_design', phiwD);
0466 
0467 %=======================================================================
0468 case 'ana_desmooth'           %-makes new SPM design for unsmoothed data
0469 %=======================================================================
0470 % phiwave('ana_desmooth')
0471 %-----------------------------------------------------------------------
0472 phiwD = phiw_arm('get', 'def_design');
0473 if isempty(phiwD), return, end;
0474 phiwD = prefix_images(phiwD, 'remove', 's');
0475 phiw_arm('set', 'def_design', phiwD);
0476 disp('Done');
0477 
0478 %=======================================================================
0479 case 'explicit_mask'                    %-sets explicit mask into design
0480 %=======================================================================
0481 % phiwave('explicit_mask')
0482 %-----------------------------------------------------------------------
0483 phiwD = phiw_arm('get', 'def_design');
0484 if isempty(phiwD), return, end;
0485 mask_img = spm_get([0 1], mars_veropts('get_img_ext'), ...
0486            'Select explicit masking image for design');
0487 if isempty(mask_img), return, end
0488 phiwD = explicit_mask(phiwD, mask_img);
0489 phiw_arm('set', 'def_design', phiwD);
0490 disp('Done');
0491 
0492 %=======================================================================
0493 case 'add_images'                            %-add images to FMRI design
0494 %=======================================================================
0495 % phiwave('add_images')
0496 %-----------------------------------------------------------------------
0497 phiwD = phiw_arm('get', 'def_design');
0498 if isempty(phiwD), return, end
0499 if ~is_fmri(phiwD), return, end
0500 phiwD = fill(phiwD, {'images'});
0501 phiw_arm('update', 'def_design', phiwD);
0502 phiw_arm('set_param', 'def_design', 'file_name', '');
0503 phiw_arm('show_summary', 'def_design');
0504 
0505 %=======================================================================
0506 case 'edit_filter'                   %-add / edit filter for FMRI design
0507 %=======================================================================
0508 % phiwave('edit_filter')
0509 %-----------------------------------------------------------------------
0510 phiwD = phiw_arm('get', 'def_design');
0511 if isempty(phiwD), return, end
0512 if ~is_fmri(phiwD), return, end
0513 tmp = {'filter'};
0514 if ~strcmp(type(phiwD), 'SPM99'), tmp = [tmp {'autocorr'}]; end
0515 phiwD = fill(phiwD, tmp);
0516 phiw_arm('update', 'def_design', phiwD);
0517 phiw_arm('set_param', 'def_design', 'file_name', '');
0518 phiw_arm('show_summary', 'def_design');
0519 
0520 %=======================================================================
0521 case 'def_from_est'          %-sets default design from estimated design
0522 %=======================================================================
0523 % phiwave('def_from_est')
0524 %-----------------------------------------------------------------------
0525 phiwE = phiw_arm('get', 'est_design');
0526 if isempty(phiwE), return, end;
0527 errf = phiw_arm('set', 'def_design', phiwE);
0528 if ~errf, phiwave('design_report'); end
0529 
0530 %=======================================================================
0531 case 'set_def'                           %-sets default design using GUI
0532 %=======================================================================
0533 % phiwave('set_def')
0534 %-----------------------------------------------------------------------
0535 if phiw_arm('set_ui', 'def_design'), return, end
0536 phiwave('design_report');
0537 
0538 %=======================================================================
0539 case 'design_report'                         %-does explore design thing
0540 %=======================================================================
0541 % phiwave('design_report')
0542 %-----------------------------------------------------------------------
0543 phiwD = phiw_arm('get', 'def_design');
0544 if isempty(phiwD), return, end;
0545 spm('FnUIsetup','Explore design', 0);
0546 
0547 fprintf('%-40s: ','Design reporting');
0548 ui_report(phiwD, 'DesMtx');
0549 ui_report(phiwD, 'DesRepUI');
0550 fprintf('%30s\n','...done');
0551 
0552 %=======================================================================
0553 case 'estimate'                                       %-Estimates design
0554 %=======================================================================
0555 % phiwave('estimate')
0556 %-----------------------------------------------------------------------
0557 phiwD= phiw_arm('get', 'def_design');
0558 if isempty(phiwD), return, end
0559 if sf_prev_save('est_design') == -1, return, end
0560 flags = mars_struct('merge', PHI.OPTIONS.wt, PHI.OPTIONS.statistics);
0561 phiwRes = estimate(phiwD, [], flags);
0562 phiw_arm('set', 'est_design', phiwRes);
0563 phiw_arm('show_summary', 'est_design');
0564 
0565 %=======================================================================
0566 case 'set_results'          %-sets estimated design into global stucture
0567 %=======================================================================
0568 % donef = phiwave('set_results')
0569 %-----------------------------------------------------------------------
0570 % Set results, put results ROI data into roi_data container
0571 varargout = {0};
0572 
0573 % Check if there's anything we don't want to write over
0574 if sf_prev_save('est_design') == -1, return, end
0575 
0576 % Do set
0577 phiw_arm('set_ui', 'est_design');
0578 if phiw_arm('isempty', 'est_design'), return, end
0579 
0580 % Get design, set ROI data
0581 phiwRes = phiw_arm('get', 'est_design');
0582 
0583 % Clear default contrast
0584 if mars_struct('isthere', PHI, 'WORKSPACE', 'default_contrast')
0585   PHI.WORKSPACE.default_contrast = [];
0586   fprintf('Reset of estimated design, cleared default contrast...\n');
0587 end
0588 
0589 % Report on design
0590 fprintf('%-40s: ','Design reporting');
0591 ui_report(phiwRes, 'DesMtx');
0592 ui_report(phiwRes, 'DesRepUI');
0593 fprintf('%30s\n','...done');
0594 
0595 varargout = {1};
0596 return
0597 
0598 %=======================================================================
0599 case 'set_defcon'                                 %-set default contrast
0600 %=======================================================================
0601 % Ic = phiwave('set_defcon')
0602 %-----------------------------------------------------------------------
0603 varargout = {[]};
0604 phiwRes = phiw_arm('get', 'est_design');
0605 if isempty(phiwRes), return, end
0606 
0607 % Setup input window
0608 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Default contrast', 0);
0609 Ic = mars_struct('getifthere',PHI, 'WORKSPACE', 'default_contrast');
0610 if isempty(Ic)
0611   cname = '[Not set]';
0612 else 
0613   xCon = get_contrasts(phiwRes);
0614   cname = xCon(Ic).name; 
0615 end
0616 spm_input(cname, 1, 'd', 'Default contrast');
0617 opts = {'Quit', 'Set new default'};
0618 if ~isempty(Ic), opts = [opts {'Clear default contrast'}]; end
0619 switch spm_input('What to do?', '+1', 'm', opts, [1:length(opts)], 1);
0620  case 1
0621  case 2
0622   [Ic phiwRes changef] = ui_get_contrasts(phiwRes, 'T|F',1,...
0623              'Select default contrast','',1);
0624   if changef
0625     phiw_arm('update', 'est_design', phiwRes);
0626   end
0627  case 3
0628   Ic = [];
0629 end
0630 PHI.WORKSPACE.default_contrast = Ic;
0631 varargout = {Ic};
0632  
0633 %=======================================================================
0634 case 'merge_contrasts'                                %-import contrasts
0635 %=======================================================================
0636 % phiwave('merge_contrasts')
0637 %-----------------------------------------------------------------------
0638 D = phiw_arm('get', 'est_design');
0639 if isempty(D), return, end
0640 filter_spec = {...
0641     'SPM.mat','SPM: SPM.mat';...
0642     '*phiw_spm.mat','Phiwave: *phiw_spm.mat';...
0643     '*x?on.mat','xCon.mat file'};
0644 [fn pn] = mars_uifile('get', ...
0645     filter_spec, ...
0646     'Source design/contrast file...');
0647 if isequal(fn,0) | isequal(pn,0), return, end
0648 fname = fullfile(pn, fn);
0649 D2 = mardo(fname);
0650 
0651 % has this got contrasts?
0652 if ~has_contrasts(D2)
0653   error(['Cannot find contrasts in design/contrast file ' fname]);
0654 end
0655   
0656 % now try to trap case of contrast only file
0657 if ~is_valid(D2)
0658   D2 = get_contrasts(D2);
0659 end
0660 
0661 [D Ic changef] = add_contrasts(D, D2, 'ui');
0662 disp('Done');
0663 if changef
0664   phiw_arm('update', 'est_design', D);
0665 end
0666 
0667 %=======================================================================
0668 case 'add_trial_f'            %-add trial-specific F contrasts to design
0669 %=======================================================================
0670 % phiwave('add_trial_f')
0671 %-----------------------------------------------------------------------
0672 D = phiw_arm('get', 'est_design');
0673 if isempty(D), return, end
0674 if ~is_fmri(D)
0675   disp('Can only add trial specific F contrasts for FMRI designs');
0676   return
0677 end
0678 [D changef] = add_trial_f(D);
0679 disp('Done');
0680 if changef
0681   phiw_arm('update', 'est_design', D);
0682 end
0683 
0684 
0685 %=======================================================================
0686 case 'writecons'                                     %-write contrast(s)
0687 %=======================================================================
0688 % phiwave('writecons')
0689 %-----------------------------------------------------------------------
0690 % Write contrast images only, update design as necessary
0691 phiwRes = phiw_arm('get', 'est_design');
0692 if isempty(phiwRes), return, end
0693 Ic = mars_struct('getifthere', PHI, 'WORKSPACE', 'default_contrast');
0694 if ~isempty(Ic)
0695   xCon = get_contrasts(phiwRes);
0696   fprintf('Using default contrast: %s\n', xCon(Ic).name);
0697 end
0698 flags = struct('t_only', 1, 'con_only', 1);
0699 [phiwRes connos changef] = write_contrasts(phiwRes, Ic, flags);
0700 if changef
0701   phiw_arm('update', 'est_design', phiwRes); 
0702 end
0703 
0704 %=======================================================================
0705 case 'denoisecon'                                     %-denoise contrast
0706 %=======================================================================
0707 % phiwave('denoisecon')
0708 %-----------------------------------------------------------------------
0709 phiwRes = phiw_arm('get', 'est_design');
0710 if isempty(phiwRes), return, end
0711 Ic = mars_struct('getifthere', PHI, 'WORKSPACE', 'default_contrast');
0712 if ~isempty(Ic)
0713   xCon = get_contrasts(phiwRes);
0714   fprintf('Using default contrast: %s\n', xCon(Ic).name);
0715 end
0716 [Vdcon Vderr phiwRes changef] = get_wdimg(phiwRes, Ic, PHI.OPTIONS.denoise);
0717 if changef
0718   phiw_arm('update', 'est_design', phiwRes); 
0719 end
0720 if isempty(Vdcon),return,end
0721 phiw_display('display', [], Vdcon);
0722 
0723 %=======================================================================
0724 case 'make'                                                       %-make
0725 %=======================================================================
0726 % phiwave('make' [,optfile])
0727 %-----------------------------------------------------------------------
0728 % runs Phiwave mex file compilation
0729 %
0730 % Inputs
0731 % optfile    - optional options (mexopts) file to use for compile
0732 %
0733 % You may want to look into the optimizations for mex compilation
0734 % See the SPM99 spm_MAKE.sh file or SPM2 Makefile for examples
0735 %
0736 % My favorite compilation flags for a pentium 4 system, linux, gcc are:
0737 % -fomit-frame-pointer -O3 -march=pentium4 -mfpmath=sse -funroll-loops
0738 
0739 if nargin < 2
0740   optfile = '';
0741 else
0742   optfile = varargin{2};
0743 end
0744 
0745 if ~isempty(optfile)
0746   if ~exist(optfile, 'file')
0747     error(['optfile ' optfile ' does not appear to exist']);
0748   end
0749   optfile = [' -f ' optfile];
0750 end
0751 
0752 mexfiles = { {'uvi_wave'}, ...
0753          {'do_wtx.c', 'do_iwtx.c'};...
0754          {'@phiw_wvimg', 'private'}, {'pplot_elbow.c'} };
0755          
0756 pwd_orig = pwd;
0757 phiwave_dir = fileparts(which('phiwave.m'));
0758 if isempty(phiwave_dir)
0759   error('Can''t find phiwave on the matlab path');
0760 end
0761 try
0762   for d = 1:size(mexfiles, 1)
0763     cd(fullfile(phiwave_dir, mexfiles{d}{:}));
0764     files = mexfiles{d, 2};
0765     for f = 1:length(files)
0766       fprintf('Compiling %s\n', fullfile(pwd, files{f}));
0767       if isempty(optfile)
0768     mex(files{f});
0769       else
0770     mex(optfile, files{f});
0771       end
0772     end
0773   end
0774   cd(pwd_orig);
0775 catch
0776   cd(pwd_orig);
0777   rethrow(lasterror);
0778 end 
0779  
0780 %=======================================================================
0781 case 'error_log'                   %-makes file to help debugging errors
0782 %=======================================================================
0783 % fname = phiwave('error_log', fname);
0784 %-----------------------------------------------------------------------
0785 if nargin < 2
0786   fname = 'error_log.mat';
0787 else
0788   fname = varargin{2};
0789 end
0790 
0791 e_log = struct('last_error', lasterr, ...
0792            'm_ver', phiwave('ver'),...
0793            'mars', PHI);
0794 savestruct(fname, e_log);
0795 if ~isempty(which('zip'))
0796   zip([fname '.zip'], fname);
0797   fname = [fname '.zip'];
0798 end
0799 disp(['Saved error log as ' fname]);
0800 
0801 %=======================================================================
0802 case 'phiw_menu'                     %-menu selection of phiwave actions
0803 %=======================================================================
0804 % phiwave('phiw_menu',tstr,pstr,tasks_str,tasks)
0805 %-----------------------------------------------------------------------
0806 
0807 [tstr pstr optfields optlabs] = deal(varargin{2:5}); 
0808 if nargin < 6
0809   optargs = cell(1, length(optfields));
0810 else
0811   optargs = varargin{6};
0812 end
0813 
0814 [Finter,Fgraph,CmdLine] = spm('FnUIsetup',tstr);
0815 of_end = length(optfields)+1;
0816 my_task = spm_input(pstr, '+1', 'm',...
0817           {optlabs{:} 'Quit'},...
0818           [1:of_end],of_end);
0819 if my_task == of_end, return, end
0820 phiwave(optfields{my_task}{:});
0821 
0822 %=======================================================================
0823 otherwise                                        %-Unknown action string
0824 %=======================================================================
0825 error(['Unknown action string: ' Action])
0826 
0827 %=======================================================================
0828 end
0829 return
0830 
0831 %=======================================================================
0832 % Subfunctions
0833 %=======================================================================
0834 function btn = sf_prev_save(obj_name)
0835 btn = mars_arm('save_ui', obj_name, ...
0836            struct('ync', 1, ...
0837               'no_no_save', 1, ...
0838               'prompt_prefix', 'previous '));
0839 % If answer is 'No', then flag that we don't need to save
0840 if btn == 0
0841   mars_arm('set_param', obj_name, 'has_changed', 0);
0842 end
0843 return

Generated on Wed 06-Jul-2005 18:07:21 by m2html © 2003