Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
900 lines (807 sloc)
27.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function aedes_fmri_gui(DATA,mask) | |
% fMRI tool GUI | |
% Check input arguments | |
if nargin == 0 | |
error('Too few input arguments.') | |
elseif nargin == 1 | |
mask = []; | |
elseif nargin > 2 | |
error('Too many input arguments.') | |
end | |
% Check data | |
if isstruct(DATA) && isfield(DATA,'FTDATA') | |
Dat.data = DATA.FTDATA; | |
elseif isnumeric(DATA) && ndims(DATA)==4 | |
Dat.data=DATA; | |
else | |
error('Input data has to be a 4D numeric matrix or Aedes data structure!') | |
end | |
Dat.nVolumes = size(Dat.data,4); | |
% Check mask | |
if islogical(mask) | |
Dat.mask = mask; | |
else | |
Dat.mask = []; | |
end | |
% Check mask size | |
if ~isempty(Dat.mask) | |
sz_mask = [size(Dat.mask,1),size(Dat.mask,2),size(Dat.mask,3)]; | |
sz_data = [size(Dat.data,1),size(Dat.data,2),size(Dat.data,3)]; | |
if ~isequal(sz_mask,sz_data) | |
warning('Mask size does not match with data volume size. Disabling masking...') | |
Dat.mask = []; | |
end | |
end | |
% Construct the GUI | |
H = l_MainGui; | |
% Build the main GUI ----------------------------------------------------- | |
function H=l_MainGui() | |
% Load default font and colors | |
GD=aedes_gui_defaults; | |
% Overlay controls figure | |
fig_h = 500; | |
fig_w = 500; | |
fig_location = aedes_dialoglocation([fig_w,fig_h]); | |
fig_left = fig_location(1); | |
fig_bottom = fig_location(2); | |
% Main figure | |
H.fig = figure('units','pixel',... | |
'position',... | |
[fig_left fig_bottom ... | |
fig_w fig_h],... | |
'Name','Aedes - fMRI Analysis',... | |
'numbertitle','off',... | |
'tag','aedes_fmri_analysis_tool_fig',... | |
'Toolbar','none',... | |
'Color',GD.col.mainfig,... | |
'Menubar','none',... | |
'DockControls','off',... | |
'renderer','painters',... | |
'resize','off',... | |
'CloseRequestFcn',@l_Close,... | |
'Handlevisibility','off'); | |
if ~GD.HG2graphics | |
set(H.fig, 'DoubleBuffer','on') | |
end | |
% % Data uipanel ----------------------------------- | |
% H.uipanel_data = uipanel('parent',H.fig,... | |
% 'units','pixel',... | |
% 'position',[10 fig_h-10-100 fig_w-20 100],... | |
% 'title','Image data',... | |
% 'backgroundcolor',GD.col.mainfig); | |
% Templates uipanel ------------------------------ | |
% pos = get(H.uipanel_data,'position'); | |
% H.uipanel_tmpl = uipanel('parent',H.fig,... | |
% 'units','pixel',... | |
% 'position',[pos(1) fig_h-20-pos(4)-60 fig_w-20 60],... | |
% 'title','Analysis parameter templates',... | |
% 'backgroundcolor',GD.col.mainfig); | |
H.uipanel_tmpl = uipanel('parent',H.fig,... | |
'units','pixel',... | |
'position',[10 fig_h-10-60 fig_w-20 60],... | |
'title','Analysis parameter templates',... | |
'backgroundcolor',GD.col.mainfig); | |
if ispref('Aedes','fMRIToolTemplates') | |
tmp = getpref('Aedes','fMRIToolTemplates'); | |
popup_str = {' ',tmp{:,1}}; | |
else | |
popup_str = ' '; | |
end | |
H.popup_tmpl = uicontrol('parent',H.uipanel_tmpl,... | |
'style','popupmenu','position',[20 10 200 25],... | |
'string',popup_str); | |
pos = get(H.popup_tmpl,'position'); | |
btn_w = (fig_w-20-20-pos(3)-4*10)/3; | |
H.loadbtn_tmpl = uicontrol('parent',H.uipanel_tmpl,... | |
'style','pushbutton','position',[pos(1)+pos(3)+10 10 btn_w 25],... | |
'string','Load',... | |
'callback',@l_LoadTemplate); | |
H.savebtn_tmpl = uicontrol('parent',H.uipanel_tmpl,... | |
'style','pushbutton','position',[pos(1)+pos(3)+2*10+btn_w 10 btn_w 25],... | |
'string','Save',... | |
'callback',@l_SaveTemplate); | |
H.deletebtn_tmpl = uicontrol('parent',H.uipanel_tmpl,... | |
'style','pushbutton','position',[pos(1)+pos(3)+3*10+2*btn_w 10 btn_w 25],... | |
'string','Delete',... | |
'callback',@l_DeleteTemplate); | |
% Parameters buttons ------------------------------ | |
pos = get(H.uipanel_tmpl,'position'); | |
H.preprocessing_toggle = uicontrol('parent',H.fig,... | |
'style','togglebutton','position',[pos(1) pos(2)-20-30 100 30],... | |
'string','Preprocessing',... | |
'value',1,... | |
'callback',@l_ChangeTab); | |
pos = get(H.preprocessing_toggle,'position'); | |
H.design_toggle = uicontrol('parent',H.fig,... | |
'style','togglebutton','position',[pos(1)+pos(3)+15 pos(2) pos(3:4)],... | |
'string','Design',... | |
'value',0,... | |
'callback',@l_ChangeTab); | |
pos = get(H.design_toggle,'position'); | |
H.results_toggle = uicontrol('parent',H.fig,... | |
'style','togglebutton','position',[pos(1)+pos(3)+15 pos(2) pos(3:4)],... | |
'string','Results',... | |
'value',0,... | |
'callback',@l_ChangeTab); | |
% Preprocessing tab ------------------------------- | |
pos = get(H.preprocessing_toggle,'position'); | |
H.uipanel_preprocessing = uipanel('parent',H.fig,... | |
'units','pixel',... | |
'position',[10 10+40 fig_w-20 pos(2)-20-40],... | |
'title','Preprocessing',... | |
'visible','on',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.uipanel_preprocessing,'position'); | |
H.TR_tx = uicontrol('parent',H.uipanel_preprocessing,... | |
'style','text',... | |
'string','Repetition time, TR (sec.):',... | |
'position',[20 pos(4)-25-25-10 250 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.TR_tx,'position'); | |
H.TR_edit = uicontrol('parent',H.uipanel_preprocessing,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 100 25],... | |
'backgroundcolor','w'); | |
H.smooth_checkbox = uicontrol('parent',H.uipanel_preprocessing,... | |
'style','checkbox',... | |
'string','Spatial smoothing',... | |
'value',1,... | |
'position',[pos(1) pos(2)-35-5 pos(3:4)],... | |
'backgroundcolor',GD.col.mainfig,... | |
'callback',@checkbox_callback); | |
pos = get(H.smooth_checkbox,'position'); | |
H.smooth_tx = uicontrol('parent',H.uipanel_preprocessing,... | |
'style','text',... | |
'string','Smoothing kernel FWHM (pixels):',... | |
'position',[pos(1)+20 pos(2)-25-5 230 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.smooth_tx,'position'); | |
H.smooth_edit = uicontrol('parent',H.uipanel_preprocessing,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 100 25],... | |
'backgroundcolor','w'); | |
pos = get(H.smooth_checkbox,'position'); | |
H.hp_checkbox = uicontrol('parent',H.uipanel_preprocessing,... | |
'style','checkbox',... | |
'string','Temporal filtering',... | |
'value',1,... | |
'position',[pos(1) pos(2)-35-25-10 pos(3:4)],... | |
'backgroundcolor',GD.col.mainfig,... | |
'callback',@checkbox_callback); | |
pos = get(H.hp_checkbox,'position'); | |
H.hp_tx = uicontrol('parent',H.uipanel_preprocessing,... | |
'style','text',... | |
'string','High-pass filter cut-off (sec.):',... | |
'position',[pos(1)+20 pos(2)-25-5 230 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.hp_tx,'position'); | |
H.hp_edit = uicontrol('parent',H.uipanel_preprocessing,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 100 25],... | |
'backgroundcolor','w'); | |
set(H.hp_checkbox,'userdata',[H.hp_tx,H.hp_edit]) | |
set(H.smooth_checkbox,'userdata',[H.smooth_tx,H.smooth_edit]) | |
% Design tab -------------------------------------- | |
pos = get(H.uipanel_preprocessing,'position'); | |
H.uipanel_design = uipanel('parent',H.fig,... | |
'units','pixel',... | |
'position',pos,... | |
'title','Design',... | |
'visible','off',... | |
'backgroundcolor',GD.col.mainfig); | |
H.hrf_tx = uicontrol('parent',H.uipanel_design,... | |
'style','text',... | |
'string','Hemodynamic response function:',... | |
'position',[20 pos(4)-25-25-10 250 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.hrf_tx,'position'); | |
H.hrf_popup = uicontrol('parent',H.uipanel_design,... | |
'style','popupmenu',... | |
'string',{'Human','Rodent'},... | |
'position',[pos(1)+pos(3)+20 pos(2) 170 25],... | |
'backgroundcolor','w'); | |
H.omit_volumes_tx = uicontrol('parent',H.uipanel_design,... | |
'style','text',... | |
'string','Omit volumes from analysis (indices):',... | |
'position',[pos(1) pos(2)-25-10 250 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.omit_volumes_tx,'position'); | |
H.omit_volumes_edit = uicontrol('parent',H.uipanel_design,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 170 25],... | |
'backgroundcolor','w'); | |
H.conditions_tx = uicontrol('parent',H.uipanel_design,... | |
'style','text',... | |
'string','Conditions:',... | |
'position',[pos(1) pos(2)-15-10 250 15],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.conditions_tx,'position'); | |
H.first_condition_tx = uicontrol('parent',H.uipanel_design,... | |
'style','text',... | |
'string','First condition:',... | |
'position',[pos(1)+20 pos(2)-15-5 230 15],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.first_condition_tx,'position'); | |
H.onsets_tx = uicontrol('parent',H.uipanel_design,... | |
'style','text',... | |
'string','Onsets (scans):',... | |
'position',[pos(1)+20 pos(2)-25-5 210 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.onsets_tx,'position'); | |
H.onsets_edit = uicontrol('parent',H.uipanel_design,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 170 25],... | |
'backgroundcolor','w'); | |
H.durations_tx = uicontrol('parent',H.uipanel_design,... | |
'style','text',... | |
'string','Durations (scans):',... | |
'position',[pos(1) pos(2)-25-5 210 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.durations_tx,'position'); | |
H.durations_edit = uicontrol('parent',H.uipanel_design,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 170 25],... | |
'backgroundcolor','w'); | |
H.second_condition_cb = uicontrol('parent',H.uipanel_design,... | |
'style','checkbox',... | |
'string','Second condition:',... | |
'position',[pos(1)-20 pos(2)-20-20 230 20],... | |
'horizontalalign','left',... | |
'value',0,... | |
'backgroundcolor',GD.col.mainfig,... | |
'callback',@checkbox_callback); | |
pos = get(H.second_condition_cb,'position'); | |
H.onsets2_tx = uicontrol('parent',H.uipanel_design,... | |
'style','text',... | |
'string','Onsets (scans):',... | |
'position',[pos(1)+20 pos(2)-25-5 210 25],... | |
'horizontalalign','left',... | |
'enable','off',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.onsets2_tx,'position'); | |
H.onsets2_edit = uicontrol('parent',H.uipanel_design,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 170 25],... | |
'backgroundcolor','w',... | |
'enable','off'); | |
H.durations2_tx = uicontrol('parent',H.uipanel_design,... | |
'style','text',... | |
'string','Durations (scans):',... | |
'position',[pos(1) pos(2)-25-5 210 25],... | |
'horizontalalign','left',... | |
'enable','off',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.durations2_tx,'position'); | |
H.durations2_edit = uicontrol('parent',H.uipanel_design,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 170 25],... | |
'backgroundcolor','w',... | |
'enable','off'); | |
set(H.second_condition_cb,'userdata',... | |
[H.onsets2_tx,H.onsets2_edit,H.durations2_tx,H.durations2_edit]) | |
% Results tab ------------------------------------- | |
pos = get(H.uipanel_preprocessing,'position'); | |
H.uipanel_results = uipanel('parent',H.fig,... | |
'units','pixel',... | |
'position',pos,... | |
'title','Results',... | |
'visible','off',... | |
'backgroundcolor',GD.col.mainfig); | |
H.t_contrast_tx = uicontrol('parent',H.uipanel_results,... | |
'style','text',... | |
'string','Contrast vector for t-statistics:',... | |
'position',[20 pos(4)-25-25-10 250 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.t_contrast_tx,'position'); | |
H.t_contrast_edit = uicontrol('parent',H.uipanel_results,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+pos(3)+20 pos(2) 170 25],... | |
'backgroundcolor','w'); | |
H.threshold_tx = uicontrol('parent',H.uipanel_results,... | |
'style','text',... | |
'string','Threshold (p < value):',... | |
'position',[pos(1) pos(2)-25-10 250 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig); | |
pos = get(H.threshold_tx,'position'); | |
H.threshold_edit = uicontrol('parent',H.uipanel_results,... | |
'style','edit',... | |
'string','0.05',... | |
'position',[pos(1)+pos(3)+20 pos(2) 170 25],... | |
'backgroundcolor','w'); | |
H.th_fdr_radio = uicontrol('parent',H.uipanel_results,... | |
'style','radio',... | |
'string','Use FDR-corrected threshold',... | |
'value',1,... | |
'position',[pos(1)+20 pos(2)-25-5 230 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig,... | |
'callback',@radiobutton_callback); | |
pos = get(H.th_fdr_radio,'position'); | |
H.th_uncorr_radio = uicontrol('parent',H.uipanel_results,... | |
'style','radio',... | |
'value',0,... | |
'string','Use uncorrected threshold',... | |
'position',[pos(1) pos(2)-25-5 230 25],... | |
'horizontalalign','left',... | |
'backgroundcolor',GD.col.mainfig,... | |
'callback',@radiobutton_callback); | |
pos = get(H.th_uncorr_radio,'position'); | |
H.use_mask_cb = uicontrol('parent',H.uipanel_results,... | |
'style','checkbox',... | |
'string','Use brain mask (ROI labeled "mask")',... | |
'position',[pos(1)-20 pos(2)-20-20 250 20],... | |
'horizontalalign','left',... | |
'value',0,... | |
'backgroundcolor',GD.col.mainfig); | |
if ~isempty(Dat.mask) | |
set(H.use_mask_cb,'value',1) | |
else | |
set(H.use_mask_cb,'enable','off') | |
end | |
pos = get(H.use_mask_cb,'position'); | |
H.save_results_cb = uicontrol('parent',H.uipanel_results,... | |
'style','checkbox',... | |
'string','Save results in a MAT-file in folder:',... | |
'position',[pos(1) pos(2)-20-20 250 20],... | |
'horizontalalign','left',... | |
'value',1,... | |
'backgroundcolor',GD.col.mainfig,... | |
'callback',@checkbox_callback); | |
pos = get(H.save_results_cb,'position'); | |
H.save_results_edit = uicontrol('parent',H.uipanel_results,... | |
'style','edit',... | |
'string','',... | |
'position',[pos(1)+20 pos(2)-25-5 340 25],... | |
'backgroundcolor','w',... | |
'horizontalalign','left'); | |
pos = get(H.save_results_edit,'position'); | |
H.save_results_browse = uicontrol('parent',H.uipanel_results,... | |
'style','pushbutton',... | |
'string','Browse...',... | |
'position',[pos(1)+pos(3)+10 pos(2) 70 25],... | |
'callback',@l_BrowserFolder); | |
pos = get(H.save_results_edit,'position'); | |
H.view_results_cb = uicontrol('parent',H.uipanel_results,... | |
'style','checkbox',... | |
'string','View results in Aedes',... | |
'position',[pos(1)-20 pos(2)-20-20 250 20],... | |
'horizontalalign','left',... | |
'value',1,... | |
'backgroundcolor',GD.col.mainfig,... | |
'callback',@checkbox_callback); | |
set(H.save_results_cb,'userdata',... | |
[H.save_results_edit,H.save_results_browse]) | |
set(H.th_fdr_radio,'userdata',... | |
[H.th_fdr_radio,H.th_uncorr_radio]) | |
set(H.th_uncorr_radio,'userdata',... | |
[H.th_fdr_radio,H.th_uncorr_radio]) | |
% Start and Close buttons ------------------------- | |
H.close_btn = uicontrol('parent',H.fig,... | |
'style','pushbutton','position',[fig_w-10-100 10 100 30],... | |
'string','Close',... | |
'callback',@l_Close); | |
pos = get(H.close_btn,'position'); | |
H.start_btn = uicontrol('parent',H.fig,... | |
'style','pushbutton','position',[pos(1)-10-pos(3) pos(2:4)],... | |
'string','Start',... | |
'callback',@l_Start); | |
end | |
% Enable/disable uicontrols | |
function checkbox_callback(h,evd) | |
% Make sure that results are either save or viewed or both | |
val_save = get(H.save_results_cb,'value'); | |
val_view = get(H.view_results_cb,'value'); | |
if ~val_save && ~val_view | |
if h == H.save_results_cb | |
set(H.save_results_cb,'value',1) | |
else | |
set(H.view_results_cb,'value',1) | |
end | |
end | |
if get(h,'value') | |
set(get(h,'userdata'),'enable','on') | |
else | |
set(get(h,'userdata'),'enable','off') | |
end | |
end | |
function radiobutton_callback(h,evd) | |
set(get(h,'userdata'),'value',0) | |
set(h,'value',1) | |
end | |
function l_BrowserFolder(h,evd) | |
d = uigetdir; | |
if isequal(d,0) | |
return | |
end | |
set(H.save_results_edit,'string',d) | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Change tab | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function l_ChangeTab(h,evd) | |
panels = [H.uipanel_preprocessing,H.uipanel_design,... | |
H.uipanel_results]; | |
btns = [H.preprocessing_toggle,H.design_toggle,... | |
H.results_toggle]; | |
set(btns,'value',0) | |
ind = find(btns == h); | |
set(h,'value',1) | |
set(panels(ind),'visible','on') | |
set(panels(setdiff([1 2 3],ind)),'visible','off') | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Close GUI | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function l_Close(h,evd) | |
delete(H.fig) | |
return | |
resp = questdlg('Are you sure you want to close the fMRI Analysis Tool?',... | |
'Close fMRI Analysis Tool',... | |
'Yes','No','No'); | |
if isempty(resp) || strcmpi(resp,'No') | |
return | |
end | |
delete(H.fig) | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Get all inputted values and selections | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function out = l_GetValues() | |
out = struct; | |
% Get preprocessing values | |
out.prep.TR = str2num(get(H.TR_edit,'string')); | |
out.prep.smooth.do_smooth = get(H.smooth_checkbox,'value'); | |
out.prep.smooth.kernel = str2num(get(H.smooth_edit,'string')); | |
out.prep.hp.do_filt = get(H.hp_checkbox,'value'); | |
out.prep.hp.cutoff = str2num(get(H.hp_edit,'string')); | |
% Get design values | |
str=get(H.hrf_popup,'string'); | |
out.design.hrf = str{get(H.hrf_popup,'value')}; | |
out.design.omit_volumes = str2num(get(H.omit_volumes_edit,'string')); | |
out.design.first_condition.onsets =str2num(get(H.onsets_edit,'string')); | |
out.design.first_condition.durations = str2num(get(H.durations_edit,'string')); | |
out.design.second_condition.use_second_condition = get(H.second_condition_cb,'value'); | |
out.design.second_condition.onsets =str2num(get(H.onsets2_edit,'string')); | |
out.design.second_condition.durations = str2num(get(H.durations2_edit,'string')); | |
% Get results values | |
out.results.contrast = str2num(get(H.t_contrast_edit,'string')); | |
out.results.threshold.p_value = str2num(get(H.threshold_edit,'string')); | |
if get(H.th_fdr_radio,'value') | |
out.results.threshold.corr = 'FDR'; | |
else | |
out.results.threshold.corr = 'uncorr'; | |
end | |
out.results.use_mask = get(H.use_mask_cb,'value'); | |
out.results.save_results = get(H.save_results_cb,'value'); | |
out.results.save_results_folder = get(H.save_results_edit,'string'); | |
out.results.view_in_aedes = get(H.view_results_cb,'value'); | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Set all values from a structure | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function l_SetValues(in_struct) | |
% Set preprocessing values | |
set(H.TR_edit,'string',num2str(in_struct.prep.TR)) | |
set(H.smooth_checkbox,'value',in_struct.prep.smooth.do_smooth); | |
set(H.smooth_edit,'string',num2str(in_struct.prep.smooth.kernel)); | |
set(H.hp_checkbox,'value',in_struct.prep.hp.do_filt); | |
set(H.hp_edit,'string',num2str(in_struct.prep.hp.cutoff)) | |
% Set design values | |
if strcmpi(in_struct.design.hrf,'human') | |
set(H.hrf_popup,'value',1); | |
else | |
set(H.hrf_popup,'value',2); | |
end | |
set(H.omit_volumes_edit,'string',num2str(in_struct.design.omit_volumes)) | |
set(H.onsets_edit,'string',num2str(in_struct.design.first_condition.onsets)) | |
set(H.durations_edit,'string',num2str(in_struct.design.first_condition.durations)) | |
set(H.second_condition_cb,'value',in_struct.design.second_condition.use_second_condition); | |
set(H.onsets2_edit,'string',num2str(in_struct.design.second_condition.onsets)); | |
set(H.durations2_edit,'string',num2str(in_struct.design.second_condition.durations)); | |
% Set results values | |
set(H.t_contrast_edit,'string',num2str(in_struct.results.contrast)); | |
set(H.threshold_edit,'string',num2str(in_struct.results.threshold.p_value)) | |
if strcmpi(in_struct.results.threshold.corr,'FDR') | |
set(H.th_fdr_radio,'value',1) | |
set(H.th_uncorr_radio,'value',0) | |
else | |
set(H.th_uncorr_radio,'value',1) | |
set(H.th_fdr_radio,'value',0) | |
end | |
if strcmpi(get(H.use_mask_cb,'enable'),'on') | |
set(H.use_mask_cb,'value',in_struct.results.use_mask) | |
end | |
set(H.save_results_cb,'value',in_struct.results.save_results); | |
set(H.save_results_edit,'string',in_struct.results.save_results_folder); | |
set(H.view_results_cb,'value',in_struct.results.view_in_aedes); | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Do sanity check for input values | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function [ok,msg] = l_SanityCheck(in_struct) | |
ok = false; | |
msg = ''; | |
% Check TR | |
TR = in_struct.prep.TR; | |
if length(TR) ~= 1 | |
msg = 'TR'; | |
return | |
end | |
% Check smoothing | |
if in_struct.prep.smooth.do_smooth | |
kr_sz = in_struct.prep.smooth.kernel; | |
if length(kr_sz) ~= 3 | |
msg = 'smoothing kernel size'; | |
return | |
end | |
end | |
% Check high-pass filtering | |
if in_struct.prep.hp.do_filt | |
co = in_struct.prep.hp.cutoff; | |
if length(co) ~= 1 | |
msg = 'high-pass filter cut-off'; | |
return | |
end | |
end | |
% Check omit volumes | |
ov = in_struct.design.omit_volumes; | |
if ~isempty(ov) && any(ov < 1 | ov > Dat.nVolumes) | |
msg = 'index/indices in omit volumes'; | |
return | |
end | |
% Check first condition onsets and durations | |
onsets = in_struct.design.first_condition.onsets; | |
durations = in_struct.design.first_condition.durations; | |
if length(onsets) ~= length(durations) || isempty(onsets) ... | |
|| any(onsets<1) || any(onsets>Dat.nVolumes) || isempty(durations) ... | |
|| any(durations<1) || any((onsets+durations)>Dat.nVolumes) | |
msg = 'first condition onsets or durations'; | |
return | |
end | |
% Check 2nd condition onsets and durations | |
if in_struct.design.second_condition.use_second_condition | |
onsets = in_struct.design.second_condition.onsets; | |
durations = in_struct.design.second_condition.durations; | |
if length(onsets) ~= length(durations) || isempty(onsets) ... | |
|| any(onsets<1) || any(onsets>Dat.nVolumes) || isempty(durations) ... | |
|| any(durations<1) || any((onsets+durations)>Dat.nVolumes) | |
msg = 'second condition onsets or durations'; | |
return | |
end | |
end | |
% Check contrast vector | |
c=in_struct.results.contrast; | |
if in_struct.design.second_condition.use_second_condition | |
cols = 3; | |
else | |
cols = 2; | |
end | |
if length(c) ~= cols | |
msg = 'contrast vector length'; | |
return | |
end | |
% Check p value | |
p_val = in_struct.results.threshold.p_value; | |
if length(p_val) ~= 1 || p_val <= 0 || p_val >= 1 | |
msg = 'threshold p-value'; | |
return | |
end | |
% Check save folder | |
if get(H.save_results_cb,'value') | |
if ~isdir(get(H.save_results_edit,'string')) | |
msg = 'save directory' | |
return | |
end | |
end | |
% All passed | |
ok = true; | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Save parameter template | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function l_SaveTemplate(h,evd) | |
% Prompt for a name for the template | |
popup_str = get(H.popup_tmpl,'string'); | |
popup_val = get(H.popup_tmpl,'value'); | |
save_new = true; | |
if popup_val ~= 1 | |
% Prompt if current template should be overwritten | |
qResp = questdlg(['Save a new template or overwrite "',popup_str{popup_val},'"?'],... | |
'Save a new template or overwrite existing',... | |
'Save new','Overwrite','Save new'); | |
if strcmp(qResp,'Overwrite') | |
save_new = false; | |
end | |
end | |
if save_new | |
done = false; | |
while ~done | |
resp=aedes_inputdlg('Please write a name for the template',... | |
'Template name'); | |
if isempty(resp) | |
% Canceled | |
break | |
elseif any(strcmpi(resp{1},popup_str)) | |
h=errordlg(['A template named "',resp{1},'" already exists. Please select unique name.'],... | |
'Template already exists','modal'); | |
uiwait(h) | |
elseif isempty(strtrim(resp{1})) | |
h=errordlg(['Template name cannot be empty'],... | |
'Template name cannot be empty','modal'); | |
uiwait(h) | |
else | |
done = true; | |
end | |
end | |
if ~done | |
return | |
end | |
resp = resp{1}; | |
else | |
resp = popup_str{popup_val}; | |
end | |
% Get current values | |
vals = l_GetValues; | |
% Save to preferences | |
if ispref('Aedes','fMRIToolTemplates') | |
tmp = getpref('Aedes','fMRIToolTemplates'); | |
else | |
tmp = {}; | |
end | |
if ~save_new | |
ind = find(strcmp(resp,{tmp{:,1}})); | |
tmp{ind,2} = vals; | |
else | |
tmp(end+1,:) = {resp,vals}; | |
% Add template to popup list | |
if iscell(popup_str) | |
popup_str{end+1} = resp; | |
else | |
popup_str = {popup_str,resp}; | |
end | |
set(H.popup_tmpl,'string',popup_str,'value',length(popup_str)) | |
end | |
setpref('Aedes','fMRIToolTemplates',tmp) | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Load parameter template | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function l_LoadTemplate(h,evd) | |
popup_str = get(H.popup_tmpl,'string'); | |
popup_val = get(H.popup_tmpl,'value'); | |
if popup_val == 1 | |
return | |
end | |
load_name = popup_str{popup_val}; | |
tmp = getpref('Aedes','fMRIToolTemplates'); | |
ind = strcmp(load_name,{tmp{:,1}}); | |
tmpl_values = tmp{ind,2}; | |
l_SetValues(tmpl_values) | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Delete parameter template | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function l_DeleteTemplate(h,evd) | |
popup_str = get(H.popup_tmpl,'string'); | |
popup_val = get(H.popup_tmpl,'value'); | |
if popup_val == 1 | |
return | |
end | |
resp = questdlg(['Really delete template "',popup_str{popup_val},'"?'],... | |
'Confirm template deletion','Yes','No','No'); | |
if isempty(resp) || strcmpi(resp,'No') | |
return | |
end | |
del_name = popup_str{popup_val}; | |
tmp = getpref('Aedes','fMRIToolTemplates'); | |
ind = strcmp(del_name,{tmp{:,1}}); | |
tmp(ind,:)=[]; | |
if isempty(tmp) | |
rmpref('Aedes','fMRIToolTemplates') | |
else | |
setpref('Aedes','fMRIToolTemplates',tmp) | |
end | |
popup_str(popup_val)=[]; | |
set(H.popup_tmpl,'string',popup_str,'value',1) | |
end | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Start fMRI analysis | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function l_Start(h,evd) | |
% Get input values | |
vals = l_GetValues; | |
% Do sanity check | |
[ok,msg] = l_SanityCheck(vals); | |
if ~ok | |
errordlg(['Input value error. Invalid ',msg,'.'],... | |
'Input value error','modal'); | |
return | |
end | |
% Close GUI | |
delete(H.fig) | |
TR = vals.prep.TR; | |
if vals.design.second_condition.use_second_condition | |
onset = {vals.design.first_condition.onsets,... | |
vals.design.second_condition.onsets}; | |
durat = {vals.design.first_condition.durations,... | |
vals.design.second_condition.durations}; | |
else | |
onset = vals.design.first_condition.onsets; | |
durat = vals.design.first_condition.durations; | |
end | |
if vals.prep.smooth.do_smooth | |
smooth_sz = vals.prep.smooth.kernel; | |
else | |
smooth_sz = []; | |
end | |
qFDR = vals.results.threshold.p_value; | |
contr = vals.results.contrast; | |
if vals.prep.hp.do_filt | |
hipass = vals.prep.hp.cutoff; | |
else | |
hipass = []; | |
end | |
hrf_type = vals.design.hrf; | |
omitVols = vals.design.omit_volumes; | |
if vals.results.use_mask | |
mask = Dat.mask; | |
else | |
mask = []; | |
end | |
% Do the fMRI analysis | |
[maps,th] = aedes_fmri_analysis(Dat.data,'TR',TR,... | |
'onsets',onset,'durations',durat,... | |
'contrast',contr,'smooth',smooth_sz,... | |
'p-value',qFDR,... | |
'hipass',hipass,'omitvolumes',omitVols,... | |
'mask',mask,'hrf',hrf_type,... | |
'multicomp',vals.results.threshold.corr); | |
% Save results to MAT-file | |
if vals.results.save_results | |
opts = vals; | |
fname = ['results_',datestr(now,'YYYY_mm_dd_HHMMSS.FFF'),'.mat']; | |
save(fullfile(vals.results.save_results_folder,fname),'maps','th','opts') | |
end | |
% View results in Aedes | |
if vals.results.view_in_aedes | |
overlay.FTDATA = maps.tmap; | |
overlay.ImageOverlayCmapStr = 'hot'; | |
overlay.ImageOverlayTholdDirPos = 1; | |
overlay.ImageOverlayAlpha = 1; | |
if iscell(onset) | |
overlay.fMRIonsets = onset{1}; | |
overlay.fMRIdurats = durat{1}; | |
else | |
overlay.fMRIonsets = onset; | |
overlay.fMRIdurats = durat; | |
end | |
if ~isempty(th) | |
overlay.ImageOverlayThold = th; | |
overlay.ImOverlayMin = 0; | |
else | |
overlay.ImageOverlayAlpha = 0; | |
end | |
aedes(DATA,[],overlay); | |
end | |
end | |
end |