Skip to content

Commit

Permalink
[FEATURE] - Manual manipulation of spectra inside GUI
Browse files Browse the repository at this point in the history
Added a new feature to the GUI to manually manipulate spectra in the GUI. For this, you have to finish OspreyProcess. Afterwards, you have to click on the dataset you want to manipulate inside the listbox. Manipulation is done with the keyboard.

'Other intersting key presses after clicking are:\n' ...
                                    'left arrow - remove data\n' ...
                                    'right arrow - add data\n\r\n' ...
                                    'In the Processed Tab you can manipulate the averaged spectrum as follows:\n' ...
                                    'a - Subtract 5 degree from ph0\n' ...
                                    'd - Add 5 degree to ph0\n' ...
                                    'q - Subtract 0.00001 s from ph1\n' ...
                                    'e - Add 0.00001 s to ph1\n' ...
                                    's - Subtract 1 Hz from f\n' ...
                                    'w - Add 1 Hz to f\n' ...
                                    'f - Add 180 degree to ph0\n\r\n' ...
                                    'You can change the axis of the processed plot as follows:\n' ...
                                    'r - Reset y-axis limits\n' ...
                                    'z - Zoom out y-axis\n' ...
                                    'x - Zoom in y-axis\n' ...
                                    'c - Move y-axis center down\n' ...
                                    'v - Move y-axis center up'

- Spectra are automatically saved if Fit button is pressed.
- Press Save MRSCont button if you want to leave without fitting.
- Final manipulations are stored inside the manual field of each FID-A MRS struct
  • Loading branch information
HJZollner committed Apr 15, 2024
1 parent 8527cb4 commit 39c6788
Show file tree
Hide file tree
Showing 15 changed files with 742 additions and 34 deletions.
22 changes: 21 additions & 1 deletion GUI/OspreyGUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
gui.controls.Tab = 1;
gui.controls.Number = 1;
gui.controls.KeyPress = 0;
%Manual manipulation like phasing performed
gui.process.ManualManipulation = 0;
%File selections for each sub function
gui.load.Selected = 1;
gui.process.Selected = 1;
Expand Down Expand Up @@ -440,7 +442,25 @@
gui.layout.ListBox = uicontrol('Style', 'list','BackgroundColor', 'w','FontName', gui.font,'BackgroundColor',gui.colormap.Background, ...
'Parent', gui.layout.controlPanel, 'String',gui.layout.RedFileList(:) , ...
'Value', gui.controls.Selected, 'Interruptible', 'on', 'BusyAction', 'cancel', ...
'ForegroundColor',gui.colormap.Foreground, 'TooltipString', 'Select a file you want to inspect.','Tag','SubjectListBox');
'ForegroundColor',gui.colormap.Foreground, 'TooltipString', sprintf(['Select a file you want to inspect.\n\r\n' ...
'Other intersting key presses after clicking are:\n' ...
'left arrow - remove data\n' ...
'right arrow - add data\n\r\n' ...
'In the Processed Tab you can manipulate the averaged spectrum as follows:\n' ...
'a - Subtract 5 degree from ph0\n' ...
'd - Add 5 degree to ph0\n' ...
'q - Subtract 0.00001 s from ph1\n' ...
'e - Add 0.00001 s to ph1\n' ...
's - Subtract 1 Hz from f\n' ...
'w - Add 1 Hz to f\n' ...
'f - Add 180 degree to ph0\n\r\n' ...
'You can change the axis of the processed plot as follows:\n' ...
'r - Reset y-axis limits\n' ...
'z - Zoom out y-axis\n' ...
'x - Zoom in y-axis\n' ...
'c - Move y-axis center down\n' ...
'v - Move y-axis center up' ...
]),'Tag','SubjectListBox');
if MRSCont.flags.isMRSI
gui.layout.MRSILocPanel = uix.Panel('Parent', gui.layout.leftMenu, 'Title', 'Voxel Location','BackgroundColor',gui.colormap.Background);
set(gui.layout.MRSILocPanel,'Units','Normalized','Position',[0.5 0 0.66 0.1], 'FontSize', 16, 'FontName', gui.font, 'FontWeight', 'Bold',...
Expand Down
200 changes: 200 additions & 0 deletions GUI/osp_WindowKeyDown.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function osp_WindowKeyDown(~,EventData,gui)
% 31 downarrow
% Get MRSCont from hidden class container
MRSCont = getappdata(gui.figure,'MRSCont');
gui.controls.PhasePress = 0;
MRSCont.flags.exclude = 1;
if strcmp(EventData.Key, 'uparrow') % scrolling up
OldValue = get( gui.layout.ListBox,'value');
Expand Down Expand Up @@ -129,5 +130,204 @@ function osp_WindowKeyDown(~,EventData,gui)
end
end
end
if strcmp(EventData.Key, 'f') % 180 degree flip
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 1;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
gui.process.ManualManipulation = 1;
end
if strcmp(EventData.Key, 'd') % positive phase
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 1;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
gui.process.ManualManipulation = 1;
end
if strcmp(EventData.Key, 'a') % negative phase
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 1;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
gui.process.ManualManipulation = 1;
end
if strcmp(EventData.Key, 'e') % positive phase1
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 1;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
gui.process.ManualManipulation = 1;
end
if strcmp(EventData.Key, 'q') % negative phase1
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 1;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
gui.process.ManualManipulation = 1;
end
if strcmp(EventData.Key, 'w') % positive freq
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 1;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
gui.process.ManualManipulation = 1;
end
if strcmp(EventData.Key, 's') % negative freq
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 1;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
gui.process.ManualManipulation = 1;
end
if strcmp(EventData.Key, 'r') % reset axis
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 1;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
end
if strcmp(EventData.Key, 'z') % zoom out
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 1;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
end
if strcmp(EventData.Key, 'x') % zoom in
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 1;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 0;
end
if strcmp(EventData.Key, 'c') % move up
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 1;
gui.controls.MoveDown = 0;
end
if strcmp(EventData.Key, 'v') % move down
gui.controls.KeyPress = 1;
gui.controls.PhasePress = 1;
gui.controls.posPhase0Shift = 0;
gui.controls.negPhase0Shift = 0;
gui.controls.posPhase1Shift = 0;
gui.controls.negPhase1Shift = 0;
gui.controls.flipPhase = 0;
gui.controls.posFreqShift = 0;
gui.controls.negFreqShift = 0;
gui.controls.resetAxis = 0;
gui.controls.zoomOut = 0;
gui.controls.zoomIn = 0;
gui.controls.MoveUp = 0;
gui.controls.MoveDown = 1;
end
setappdata(gui.figure,'MRSCont',MRSCont); % Write MRSCont into hidden container in gui class
end
7 changes: 6 additions & 1 deletion GUI/osp_WindowKeyUp.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ function osp_WindowKeyUp(~,~,gui)
% 2020-01-16: First version of the code.
%%% 1. GET HANDLES %%%
gui.controls.KeyPress = 0;
osp_updateListBox(gui);
if gui.controls.PhasePress == 0
osp_updateListBox(gui);
else
gui.controls.PhasePress = 0;
osp_phaseProWindow(gui)
end
end
1 change: 1 addition & 0 deletions GUI/osp_iniProcessWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ function osp_iniProcessWindow(gui)
close(h(ff))
end
end
gui.controls.YLimits = [];
gui.info.nYvoxels = MRSCont.processed.metab{1, 1}.subspecs;
setappdata(gui.figure,'MRSCont',MRSCont); % Write MRSCont into hidden container in gui class
end
24 changes: 24 additions & 0 deletions GUI/osp_onFit.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ function osp_onFit( ~, ~ ,gui)
set(gui.layout.fitTab, 'SelectionChangedFcn','');
gui.layout.b_fit.Enable = 'off';
gui.layout.tabs.Selection = 3;
if gui.process.ManualManipulation
% Optional: write edited files to LCModel .RAW files
if MRSCont.opts.saveLCM && ~MRSCont.flags.isPRIAM && ~MRSCont.flags.isMRSI
[MRSCont] = osp_saveLCM(MRSCont);
end

% Optional: write edited files to jMRUI .txt files
if MRSCont.opts.savejMRUI && ~MRSCont.flags.isPRIAM && ~MRSCont.flags.isMRSI
[MRSCont] = osp_saveJMRUI(MRSCont);
end

% Optional: write edited files to vendor specific format files readable to
% LCModel and jMRUI
% SPAR/SDAT if Philips
% RDA if Siemens
if MRSCont.opts.saveVendor && ~MRSCont.flags.isPRIAM && ~MRSCont.flags.isMRSI
[MRSCont] = osp_saveVendor(MRSCont);
end

% Optional: write edited files to NIfTI-MRS format
if MRSCont.opts.saveNII && ~MRSCont.flags.isPRIAM && ~MRSCont.flags.isMRSI
[MRSCont] = osp_saveNII(MRSCont);
end
end
[gui,MRSCont] = osp_processingWindow(gui,MRSCont);
%%% 2. CALL OSPREYFIT %%%
MRSCont = OspreyFit(MRSCont);
Expand Down
28 changes: 28 additions & 0 deletions GUI/osp_onSave.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,32 @@ function osp_onSave( ~, ~,gui)
setappdata(gui.figure,'MRSCont',MRSCont); % Write MRSCont into hidden container in gui class
set(gui.figure,'HandleVisibility','on');
toc(refProcessTime);

if gui.process.ManualManipulation
fprintf('Rewriting MRS data after manual manipulation...\n');
% Optional: write edited files to LCModel .RAW files
if MRSCont.opts.saveLCM && ~MRSCont.flags.isPRIAM && ~MRSCont.flags.isMRSI
[MRSCont] = osp_saveLCM(MRSCont);
end

% Optional: write edited files to jMRUI .txt files
if MRSCont.opts.savejMRUI && ~MRSCont.flags.isPRIAM && ~MRSCont.flags.isMRSI
[MRSCont] = osp_saveJMRUI(MRSCont);
end

% Optional: write edited files to vendor specific format files readable to
% LCModel and jMRUI
% SPAR/SDAT if Philips
% RDA if Siemens
if MRSCont.opts.saveVendor && ~MRSCont.flags.isPRIAM && ~MRSCont.flags.isMRSI
[MRSCont] = osp_saveVendor(MRSCont);
end

% Optional: write edited files to NIfTI-MRS format
if MRSCont.opts.saveNII && ~MRSCont.flags.isPRIAM && ~MRSCont.flags.isMRSI
[MRSCont] = osp_saveNII(MRSCont);
end
fprintf('... done.\n');
end

end % onExit
Loading

0 comments on commit 39c6788

Please sign in to comment.