Skip to content

Commit

Permalink
Merge pull request #802 from bachlab/598-pspm_review_DCM_button
Browse files Browse the repository at this point in the history
Shows extracted responses in first level review (DCM)
  • Loading branch information
dominikbach authored Dec 2, 2024
2 parents 3f487e9 + 941c009 commit a9b8aa6
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 49 deletions.
45 changes: 45 additions & 0 deletions src/pspm_rev_dcm.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
% 'scrf' show peripheral skin conductance response function as used
% for trial-by-trial estimation of sympathetic input
% 'names' show trial and condition names in command window
% 'seg' show the mean responses of all segments identified in
% the DCM model. ('pspm_extract_segments')
% * sn: session.
% * trl: trial.
% ● History
% Introduced In PsPM 3.0
% Written in 2008-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging)
% Maintained in 2022 by Teddy
% Maintained in 2024 by Bernhard Agoué von Raußendorf


%% Initialise
global settings
Expand Down Expand Up @@ -123,6 +127,47 @@
fprintf('Condition %d: %s\n',n,dcm.condnames{n});
end;
fprintf('---------------------------------------\n');
case 'seg'

options = struct();
[ssts, segments] = pspm_extract_segments('model', dcm, options);

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


sr = dcm.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;

sts = 1;
Expand Down
37 changes: 37 additions & 0 deletions src/pspm_rev_glm.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
% 3 - predicted & observed
% 4 - print regressor names
% 5 - reconstructed responses
% 6 - plot mean responses of all segments
% ● Outputs
% * sts : status variable indicating whether the function run successfully
% * fig : returns the figure handles
% ● History
% Introduced In PsPM 3.0
% Written in 2008-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging)
% Maintained in 2022 by Teddy
% Maintained in 2024 by Bernhard Agoué von Raußendorf

% initialise
global settings
Expand Down Expand Up @@ -226,6 +228,41 @@
XLim = cellfun(@(x){num2str(x)}, XLim);
set(fig(5).ax(1).h, 'XTickLabel',XLim);
set(fig(5).title, 'String', sprintf('Estimated responses per condition: %s', filename), 'FontWeight', 'Bold', 'FontSize', 14, 'Interpreter', 'none');
case 6

options = struct();
[ssts, segments] = pspm_extract_segments('model', glm, options);
if ssts == -1
uiwait(msgbox('Error extracting segments from the model.', 'Error'))
else
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
end
Expand Down
Binary file modified src/pspm_review.fig
Binary file not shown.
71 changes: 22 additions & 49 deletions src/pspm_review.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ function buttonAddModel_Callback(hObject, ~, handles)
end
setButtonEnable(handles)

if handles.modelCnt > 1
set(handles.buttonRemoveModel2, 'Enable', 'on');
if handles.modelCnt > 1
set(handles.buttonRemoveModel, 'Enable', 'on');
end
guidata(hObject, handles);

% --- Executes on button press in buttonRemoveModel2.
% --- Executes on button press in buttonRemoveModel.
function buttonRemoveModel_Callback(hObject, ~, handles)
% hObject handle to buttonRemoveModel2 (see GCBO)
% hObject handle to buttonRemoveModel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.modelData{handles.currentModel} = [];
Expand All @@ -157,8 +157,8 @@ function buttonRemoveModel_Callback(hObject, ~, handles)
handles.currentModel = handles.modelCnt;
end
set(handles.listModel, 'Value', handles.currentModel);
if handles.modelCnt < 2
set(handles.buttonRemoveModel2, 'Enable', 'off');
if handles.modelCnt < 2
set(handles.buttonRemoveModel, 'Enable', 'off');
end
showModel(handles);

Expand Down Expand Up @@ -201,7 +201,7 @@ function buttonPlot1_Callback(hObject, ~, handles)
case 'dcm'
sessionNr = checkSessionNr(handles);
if sessionNr
pspm_rev_dcm(handles.modelData{handles.currentModel}.model, 'sum', sessionNr, [])
pspm_rev_dcm(handles.modelData{handles.currentModel}.model, 'sum', sessionNr, []);
end

case 'sf'
Expand Down Expand Up @@ -294,12 +294,13 @@ function buttonPlot5_Callback(hObject, ~, handles)
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] = ...
pspm_rev_glm(handles.modelData{handles.currentModel}.modelfile, 5);

case 'dcm'
[~, handles.modelData{handles.currentModel}.fig] = ...
pspm_rev_con(handles.modelData{handles.currentModel}.model);
pspm_rev_dcm(handles.modelData{handles.currentModel}.modelfile, 'seg', [], []);

end
set(handles.textStatus,'String',tmpStatusString);
Expand All @@ -315,44 +316,14 @@ function buttonPlot6_Callback(hObject, ~, handles)
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
modelfile = handles.modelData{handles.currentModel}.modelfile;
[~, handles.modelData{handles.currentModel}.fig] = pspm_rev_glm(modelfile, 6);


% contrast in comand window
case 'dcm'
[~, handles.modelData{handles.currentModel}.fig] = ...
pspm_rev_con(handles.modelData{handles.currentModel}.model);

end

Expand Down Expand Up @@ -543,15 +514,17 @@ function showModel(handles)
buttonPlotString = {'Display', ...
'Display', ...
'Display', ...
'Show'};
'Show', ...
'Plot'};
textPlotString = {'All trials for one session', ...
'Diagnostics for trial nr.', ...
'Skin conductance response function (SCR)', ...
'Trial and condition names in command window'};
'Trial and condition names in command window', ...
'Plot data per condition'};
% detect contrasts
if isfield(handles.modelData{handles.currentModel}.model, 'con')
buttonPlotString{5} = 'Show';
textPlotString{5} = 'Contrast names in command window';
buttonPlotString{6} = 'Show';
textPlotString{6} = 'Contrast names in command window';
end
setInvisble(handles);
setButtonPlotString(handles, buttonPlotString);
Expand Down

0 comments on commit a9b8aa6

Please sign in to comment.