Skip to content

Commit

Permalink
Merge pull request #784 from bachlab/598-pspm_review_GLM_button
Browse files Browse the repository at this point in the history
598 pspm review glm button
  • Loading branch information
dominikbach authored Oct 28, 2024
2 parents b4916d6 + b7b6aac commit a53785d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/pspm_cfg/pspm_cfg_selector_data_design.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
end
% marker channel
if isfield(job.timeunits, 'markers')
options.marker_chan_num = pspm_cfg_channel_selector('run', job.timeunits.markers.chan);
options.marker_chan_num = pspm_cfg_selector_channel('run', job.timeunits.markers.chan);
end
out1 = model;
out2 = options;
Expand Down
21 changes: 5 additions & 16 deletions src/pspm_extract_segments.m
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,13 @@
% ensure correct file suffix
[pt, fn, ~] = fileparts(options.outputfile);
outfile = [pt filesep fn '.mat'];
write_ok = 0;
if exist(outfile, 'file')
if options.overwrite
write_ok = 1;
else
button = questdlg(sprintf('File (%s) already exists. Replace file?', ...
outfile), 'Replace file?', 'Yes', 'No', 'No');

write_ok = strcmpi(button, 'Yes');
end
else
write_ok = 1;
end

if write_ok

if pspm_overwrite(options.outputfile, options.overwrite)
save(outfile, 'segments');
out.outputfile = outfile;
out.outputfile = outfile;
end


end

if options.plot
Expand Down
Binary file modified src/pspm_review.fig
Binary file not shown.
67 changes: 63 additions & 4 deletions src/pspm_review.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
% Introduced in PsPM 3.0
% Written in 2008-2015 by Gabriel Graeni (University of Zurich)
% Maintained in 2022 by Teddy
% Maintained in 2024 by Bernhard Agoué von Raußendorf

%% Initialise
global settings
Expand Down Expand Up @@ -47,10 +48,11 @@ function pspm_review_OpeningFcn(hObject, ~, handles, varargin)
set(handles.textPlot4,'HorizontalAlignment','left')
set(handles.textPlot5,'HorizontalAlignment','left')
set(handles.textPlot6,'HorizontalAlignment','left')
set(handles.textPlot7,'HorizontalAlignment','left')
set(handles.textStatus,'HorizontalAlignment','left')
set(handles.textStatus,'String','Select a model...');

handles.nrPlot = 6;
handles.nrPlot = 7;
%handles.figCnt = 0;
handles.modelCnt = 0;
handles.currentModel = 1;
Expand Down Expand Up @@ -303,13 +305,68 @@ function buttonPlot5_Callback(hObject, ~, handles)
set(handles.textStatus,'String',tmpStatusString);
guidata(hObject, handles);


% --- Executes on button press in buttonPlot6.
function buttonPlot6_Callback(hObject, ~, handles)
% hObject handle to buttonPlot6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmpStatusString = get(handles.textStatus,'String');
set(handles.textStatus,'String','Plotting is in progress. Please wait...');
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'

modelfile = handles.modelData{handles.currentModel}.modelfile;
options = struct();
[ssts, segments] = pspm_extract_segments('model', modelfile, options);

if ssts == -1
uiwait(msgbox('Error extracting segments from the model.', 'Error'))
else

glm = handles.modelData{handles.currentModel}.model;
sr = glm.input.sr;
cmap = lines(numel(segments.segments));
f.h = figure;
f.a.h = axes(f.h);
hold on;

legendNames = cell(1, numel(segments.segments));

for x = 1:numel(segments.segments)

plotdata = segments.segments{x}.mean;
t = (1:length(plotdata)) / sr;
f.a.p = plot(f.a.h, t, plotdata, 'Color', cmap(x, :), 'LineWidth', 1);
legendNames{x} = segments.segments{x}.name;

end

f.a.l = legend(legendNames, 'Interpreter', 'none', 'Location', 'best');
legend boxoff

set(get(f.a.h, 'xlabel'), 'String', 'Time (seconds)');
set(get(f.a.h, 'ylabel'), 'String', 'Mean Response (data units)');
set(get(f.a.h, 'title'), 'String', 'Mean Responses for All Segments');

hold off;
end



end

set(handles.textStatus,'String',tmpStatusString);
guidata(hObject, handles);


% --- Executes on button press in buttonPlot7.
function buttonPlot7_Callback(hObject, ~, handles)
% hObject handle to buttonPlot7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tmpStatusString = get(handles.textStatus,'String');
set(handles.textStatus,'String','Plotting is in progress. Please wait...');
switch handles.modelData{handles.currentModel}.modeltype
case 'glm'
[~, handles.modelData{handles.currentModel}.fig] = ...
Expand Down Expand Up @@ -463,16 +520,18 @@ function showModel(handles)
'Plot', ...
'Plot', ...
'Show', ...
'Plot', ...
'Plot'};
textPlotString = {'Design matrix in SPM style', ...
'Orthogonality in SPM style', ...
'Predicted & observed', ...
'Regressors in command window', ...
'Reconstructed responses'};
'Reconstructed responses', ...
'Plot data per condition'};
% detect contrasts
if isfield(handles.modelData{handles.currentModel}.model, 'con')
buttonPlotString{6} = 'Show';
textPlotString{6} = 'Contrast names in command window';
buttonPlotString{7} = 'Show';
textPlotString{7} = 'Contrast names in command window';
end
setInvisble(handles);
setButtonPlotString(handles, buttonPlotString);
Expand Down
5 changes: 5 additions & 0 deletions src/pspm_ui.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
% ● History
% Introduced in PsPM 5.1
% Written and maintained in 2021-2022
% Maintained in 2024 by Bernhard von Raußendorf

%% Initialise
global settings
Expand Down Expand Up @@ -262,6 +263,10 @@
'buttonPlot4',...
'textPlot5',...
'buttonPlot5',...
'textPlot6',...
'buttonPlot6',...
'textPlot7',...
'buttonPlot7',...
'buttonPlotClose',...
'textSessionNr',...
'editSessionNr',...
Expand Down

0 comments on commit a53785d

Please sign in to comment.