diff --git a/GUI/OspreyGUI.m b/GUI/OspreyGUI.m index 215559a8..bd2aac23 100644 --- a/GUI/OspreyGUI.m +++ b/GUI/OspreyGUI.m @@ -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; @@ -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',... diff --git a/GUI/osp_WindowKeyDown.m b/GUI/osp_WindowKeyDown.m index c97a2a61..0d87a401 100644 --- a/GUI/osp_WindowKeyDown.m +++ b/GUI/osp_WindowKeyDown.m @@ -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'); @@ -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 \ No newline at end of file diff --git a/GUI/osp_WindowKeyUp.m b/GUI/osp_WindowKeyUp.m index 2f4ef92d..b28066b4 100644 --- a/GUI/osp_WindowKeyUp.m +++ b/GUI/osp_WindowKeyUp.m @@ -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 \ No newline at end of file diff --git a/GUI/osp_iniProcessWindow.m b/GUI/osp_iniProcessWindow.m index 7350da98..738f635b 100644 --- a/GUI/osp_iniProcessWindow.m +++ b/GUI/osp_iniProcessWindow.m @@ -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 \ No newline at end of file diff --git a/GUI/osp_onFit.m b/GUI/osp_onFit.m index 6823b3e0..f4a58473 100644 --- a/GUI/osp_onFit.m +++ b/GUI/osp_onFit.m @@ -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); diff --git a/GUI/osp_onSave.m b/GUI/osp_onSave.m index 8dd7d587..28bac2a1 100644 --- a/GUI/osp_onSave.m +++ b/GUI/osp_onSave.m @@ -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 \ No newline at end of file diff --git a/GUI/osp_phaseProWindow.m b/GUI/osp_phaseProWindow.m new file mode 100644 index 00000000..6e3810bb --- /dev/null +++ b/GUI/osp_phaseProWindow.m @@ -0,0 +1,361 @@ +function osp_phaseProWindow(gui) +%% osp_phaseProWindow +% This function updates the process tab for manual phasing. +% +% +% USAGE: +% osp_updateProWindow(gui); +% +% INPUT: +% gui = gui class containing all handles and the MRSCont +% +% +% AUTHORS: +% Dr. Helge Zoellner (Johns Hopkins University, 2020-01-16) +% hzoelln2@jhmi.edu +% +% CREDITS: +% This code is based on numerous functions from the FID-A toolbox by +% Dr. Jamie Near (McGill University) +% https://github.com/CIC-methods/FID-A +% Simpson et al., Magn Reson Med 77:23-33 (2017) +% +% HISTORY: +% 2020-01-16: First version of the code. +%%% 1. INITIALIZE %%% + MRSCont = getappdata(gui.figure,'MRSCont'); % Get MRSCont from hidden container in gui class + if (isfield(MRSCont.flags,'isPRIAM') || isfield(MRSCont.flags,'isMRSI')) && (MRSCont.flags.isPRIAM || MRSCont.flags.isMRSI) + set(gui.layout.(gui.layout.proTabhandles{gui.process.Selected}).Children(2).Children(3).Children(1).Children.Children(4),'String',gui.controls.act_z); + set(gui.layout.(gui.layout.proTabhandles{gui.process.Selected}).Children(2).Children(3).Children(1).Children.Children(5),'String',gui.controls.act_y); + set(gui.layout.(gui.layout.proTabhandles{gui.process.Selected}).Children(2).Children(3).Children(1).Children.Children(6),'String',gui.controls.act_x); + else + set(gui.layout.(gui.layout.proTabhandles{gui.process.Selected}).Children(2).Children(3).Children(1).Children.Children(3),'String',gui.controls.act_y); + set(gui.layout.(gui.layout.proTabhandles{gui.process.Selected}).Children(2).Children(3).Children(1).Children.Children(4),'String',gui.controls.act_x); + end + gui.layout.EmptyProPlot = 0; + Selection = gui.process.TabTitles{gui.process.Selected}; + Exp = gui.controls.act_x; + SubSpec = gui.controls.act_y; + + if (MRSCont.processed.(gui.process.TabTitles{gui.process.Selected}){gui.controls.Selected}.dims.extras == 0) || (Exp > MRSCont.processed.(gui.process.TabTitles{gui.process.Selected}){gui.controls.Selected}.sz(MRSCont.processed.(gui.process.TabTitles{gui.process.Selected}){gui.controls.Selected}.dims.extras)) + Exp = 1; + gui.controls.act_x = 1; + end + if (MRSCont.processed.(gui.process.TabTitles{gui.process.Selected}){gui.controls.Selected}.dims.subSpecs == 0) || (SubSpec > MRSCont.processed.(gui.process.TabTitles{gui.process.Selected}){gui.controls.Selected}.sz(MRSCont.processed.(gui.process.TabTitles{gui.process.Selected}){gui.controls.Selected}.dims.subSpecs)) + SubSpec = 1; + gui.controls.act_y = 1; + end + +%%% 2. PHASING AND FREQUENCY SHIFT HAPPENS HERE %%% + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'extras') + procData = op_takeextra(MRSCont.processed.metab{gui.controls.Selected},Exp); + if gui.controls.posPhase0Shift + procData=op_addphase(procData ,5); + if isfield(procData, 'manual') && isfield(procData.manual,'ph0') && Exp <= length(procData.manual.ph0) + procData.manual.ph0(Exp) = procData.manual.ph0(Exp) + 5; + else + procData.manual.ph0(Exp) = 5; + end + end + if gui.controls.negPhase0Shift + procData=op_addphase(procData ,-5); + if isfield(procData, 'manual') && isfield(procData.manual,'ph0') && Exp <= length(procData.manual.ph0) + procData.manual.ph0(Exp) = procData.manual.ph0(Exp) - 5; + else + procData.manual.ph0(Exp) = -5; + end + end + if gui.controls.posPhase1Shift + procData=op_addphase(procData ,0,0.00001); + if isfield(procData, 'manual') && isfield(procData.manual,'ph1') && Exp <= length(procData.manual.ph1) + procData.manual.ph1(Exp) = procData.manual.ph1(Exp) + 0.00001; + else + procData.manual.ph1(Exp) = 0.00001; + end + end + if gui.controls.negPhase1Shift + procData=op_addphase(procData ,0,-0.00001); + if isfield(procData, 'manual') && isfield(procData.manual,'ph1') && Exp <= length(procData.manual.ph1) + procData.manual.ph1(Exp) = procData.manual.ph1(Exp) - 0.00001; + else + procData.manual.ph1(Exp) = -0.00001; + end + end + if gui.controls.flipPhase + procData=op_addphase(procData ,180); + if isfield(procData, 'manual') && isfield(procData.manual,'ph0') && Exp <= length(procData.manual.ph0) + procData.manual.ph0(Exp) = procData.manual.ph0(Exp) + 180; + else + procData.manual.ph0(Exp) = 180; + end + end + if gui.controls.posFreqShift + procData=op_freqshift(procData ,1); + if isfield(procData, 'manual') && isfield(procData.manual,'f') && Exp <= length(procData.manual.f) + procData.manual.f(Exp) = procData.manual.f(Exp) + 1; + else + procData.manual.f(Exp) = 1; + end + end + if gui.controls.negFreqShift + procData=op_freqshift(procData ,-1); + if isfield(procData, 'manual') && isfield(procData.manual,'f') && Exp <= length(procData.manual.f) + procData.manual.f(Exp) = procData.manual.f(Exp) - 1; + else + procData.manual.f(Exp) = -1; + end + end + if isfield(procData, 'manual') && isfield(procData.manual,'ph0') + if abs(procData.manual.ph0(Exp)) > 360 + procData.manual.ph0(Exp) = procData.manual.ph0(Exp) + sign(procData.manual.ph0(Exp))*(-1)*360; + end + end + MRSCont.processed.metab{gui.controls.Selected}=op_addextra(MRSCont.processed.metab{gui.controls.Selected},procData,Exp); + + if isfield(MRSCont, 'processed_no_align') + procData = op_takeextra(MRSCont.processed_no_align.metab{gui.controls.Selected},Exp); + if gui.controls.posPhase0Shift + procData=op_addphase(procData ,5); + if isfield(procData, 'manual') && isfield(procData.manual,'ph0') && Exp <= length(procData.manual.ph0) + procData.manual.ph0(Exp) = procData.manual.ph0(Exp) + 5; + else + procData.manual.ph0(Exp) = 5; + end + end + if gui.controls.negPhase0Shift + procData=op_addphase(procData ,-5); + if isfield(procData, 'manual') && isfield(procData.manual,'ph0') && Exp <= length(procData.manual.ph0) + procData.manual.ph0(Exp) = procData.manual.ph0(Exp) - 5; + else + procData.manual.ph0(Exp) = -5; + end + end + if gui.controls.posPhase1Shift + procData=op_addphase(procData ,0,0.00001); + if isfield(procData, 'manual') && isfield(procData.manual,'ph1') && Exp <= length(procData.manual.ph1) + procData.manual.ph1(Exp) = procData.manual.ph1(Exp) + 0.00001; + else + procData.manual.ph1(Exp) = 0.00001; + end + end + if gui.controls.negPhase1Shift + procData=op_addphase(procData ,0,-0.00001); + if isfield(procData, 'manual') && isfield(procData.manual,'ph1') && Exp <= length(procData.manual.ph1) + procData.manual.ph1(Exp) = procData.manual.ph1(Exp) - 0.00001; + else + procData.manual.ph1(Exp) = -0.00001; + end + end + if gui.controls.flipPhase + procData=op_addphase(procData ,180); + if isfield(procData, 'manual') && isfield(procData.manual,'ph0') && Exp <= length(procData.manual.ph0) + procData.manual.ph0(Exp) = procData.manual.ph0(Exp) + 180; + else + procData.manual.ph0(Exp) = 180; + end + end + if gui.controls.posFreqShift + procData=op_freqshift(procData ,1); + if isfield(procData, 'manual') && isfield(procData.manual,'f') && Exp <= length(procData.manual.f) + procData.manual.f(Exp) = procData.manual.f(Exp) + 1; + else + procData.manual.f(Exp) = 1; + end + end + if gui.controls.negFreqShift + procData=op_freqshift(procData ,-1); + if isfield(procData, 'manual') && isfield(procData.manual,'f') && Exp <= length(procData.manual.f) + procData.manual.f(Exp) = procData.manual.f(Exp) - 1; + else + procData.manual.f(Exp) = -1; + end + end + if isfield(procData, 'manual') && isfield(procData.manual,'ph0') + if abs(procData.manual.ph0(Exp)) > 360 + procData.manual.ph0(Exp) = procData.manual.ph0(Exp) + sign(procData.manual.ph0(Exp))*(-1)*360; + end + end + MRSCont.processed_no_align.metab{gui.controls.Selected}=op_addextra(MRSCont.processed_no_align,procData,Exp); + end + else + if gui.controls.posPhase0Shift + MRSCont.processed.metab{gui.controls.Selected}=op_addphase(MRSCont.processed.metab{gui.controls.Selected} ,5); + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed.metab{gui.controls.Selected}.manual,'ph0') + MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 = MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 + 5; + else + MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 = 5; + end + end + if gui.controls.negPhase0Shift + MRSCont.processed.metab{gui.controls.Selected}=op_addphase(MRSCont.processed.metab{gui.controls.Selected} ,-5); + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed.metab{gui.controls.Selected}.manual,'ph0') + MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 = MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 - 5; + else + MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 = -5; + end + end + if gui.controls.posPhase1Shift + MRSCont.processed.metab{gui.controls.Selected}=op_addphase(MRSCont.processed.metab{gui.controls.Selected} ,0,0.00001); + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed.metab{gui.controls.Selected}.manual,'ph1') + MRSCont.processed.metab{gui.controls.Selected}.manual.ph1 = MRSCont.processed.metab{gui.controls.Selected}.manual.ph1 + 0.00001; + else + MRSCont.processed.metab{gui.controls.Selected}.manual.ph1 = 0.00001; + end + end + if gui.controls.negPhase1Shift + MRSCont.processed.metab{gui.controls.Selected}=op_addphase(MRSCont.processed.metab{gui.controls.Selected} ,0,-0.00001); + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed.metab{gui.controls.Selected}.manual,'ph1') + MRSCont.processed.metab{gui.controls.Selected}.manual.ph1 = MRSCont.processed.metab{gui.controls.Selected}.manual.ph1 -0.00001; + else + MRSCont.processed.metab{gui.controls.Selected}.manual.ph1 = -0.00001; + end + end + if gui.controls.flipPhase + MRSCont.processed.metab{gui.controls.Selected}=op_addphase(MRSCont.processed.metab{gui.controls.Selected} ,180); + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed.metab{gui.controls.Selected}.manual,'ph0') + MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 = MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 + 180; + else + MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 = 180; + end + end + if gui.controls.posFreqShift + MRSCont.processed.metab{gui.controls.Selected}=op_freqshift(MRSCont.processed.metab{gui.controls.Selected} ,1); + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed.metab{gui.controls.Selected}.manual,'f') + MRSCont.processed.metab{gui.controls.Selected}.manual.f = MRSCont.processed.metab{gui.controls.Selected}.manual.f + 1; + else + MRSCont.processed.metab{gui.controls.Selected}.manual.f = 1; + end + end + if gui.controls.negFreqShift + MRSCont.processed.metab{gui.controls.Selected}=op_freqshift(MRSCont.processed.metab{gui.controls.Selected} ,-1); + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed.metab{gui.controls.Selected}.manual,'f') + MRSCont.processed.metab{gui.controls.Selected}.manual.f = MRSCont.processed.metab{gui.controls.Selected}.manual.f - 1; + else + MRSCont.processed.metab{gui.controls.Selected}.manual.f = -1; + end + end + if isfield(MRSCont.processed.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed.metab{gui.controls.Selected}.manual,'ph0') + if abs(MRSCont.processed.metab{gui.controls.Selected}.manual.ph0) > 360 + MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 = MRSCont.processed.metab{gui.controls.Selected}.manual.ph0 + sign(MRSCont.processed.metab{gui.controls.Selected}.manual.ph0)*(-1)*360; + end + end + + if isfield(MRSCont, 'processed_no_align') + if gui.controls.posPhase0Shift + MRSCont.processed_no_align.metab{gui.controls.Selected}=op_addphase(MRSCont.processed_no_align.metab{gui.controls.Selected} ,5); + if isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual,'ph0') + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 = MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 + 5; + else + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 = 5; + end + end + if gui.controls.negPhase0Shift + MRSCont.processed_no_align.metab{gui.controls.Selected}=op_addphase(MRSCont.processed_no_align.metab{gui.controls.Selected} ,-5); + if isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual,'ph0') + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 = MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 - 5; + else + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 = -5; + end + end + if gui.controls.posPhase1Shift + MRSCont.processed_no_align.metab{gui.controls.Selected}=op_addphase(MRSCont.processed_no_align.metab{gui.controls.Selected} ,0,0.00001); + if isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual,'ph1') + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph1 = MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph1 + 0.00001; + else + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph1 = 0.00001; + end + end + if gui.controls.negPhase1Shift + MRSCont.processed_no_align.metab{gui.controls.Selected}=op_addphase(MRSCont.processed_no_align.metab{gui.controls.Selected} ,0,-0.00001); + if isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual,'ph1') + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph1 = MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph1 -0.00001; + else + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph1 = -0.00001; + end + end + if gui.controls.flipPhase + MRSCont.processed_no_align.metab{gui.controls.Selected}=op_addphase(MRSCont.processed_no_align.metab{gui.controls.Selected} ,180); + if isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual,'ph0') + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 = MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 + 180; + else + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 = 180; + end + end + if gui.controls.posFreqShift + MRSCont.processed_no_align.metab{gui.controls.Selected}=op_freqshift(MRSCont.processed_no_align.metab{gui.controls.Selected} ,1); + if isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual,'f') + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.f = MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.f + 1; + else + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.f = 1; + end + end + if gui.controls.negFreqShift + MRSCont.processed_no_align.metab{gui.controls.Selected}=op_freqshift(MRSCont.processed_no_align.metab{gui.controls.Selected} ,-1); + if isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual,'f') + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.f = MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.f - 1; + else + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.f = -1; + end + end + if isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}, 'manual') && isfield(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual,'ph0') + if abs(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0) > 360 + MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 = MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0 + sign(MRSCont.processed_no_align.metab{gui.controls.Selected}.manual.ph0)*(-1)*360; + end + end + + end + end + +%%% 3. VISUALIZATION PART OF THIS TAB %%% + temp_match = MRSCont.plot.processed.match; + MRSCont.plot.processed.match = 2; + if ~(isfield(MRSCont.flags,'isPRIAM') || isfield(MRSCont.flags,'isMRSI')) || ~(MRSCont.flags.isPRIAM || MRSCont.flags.isMRSI) + temp = osp_plotProcess(MRSCont, gui.controls.Selected,Selection,SubSpec,Exp); %Create figure + elseif isfield(MRSCont.flags,'isPRIAM') && MRSCont.flags.isPRIAM + temp = osp_plotProcess(MRSCont, gui.controls.Selected,Selection,SubSpec,Exp,gui.controls.act_x); %Create figure + else + temp = osp_plotProcess(MRSCont, gui.controls.Selected,Selection,SubSpec,Exp,[gui.controls.act_x gui.controls.act_y gui.controls.act_z]); %Create figure + end + MRSCont.plot.processed.match = temp_match; + %Delete old content + delete(gui.layout.proAlgn.Children.Children) + %Fill window with new content + set( flipud(temp.Children(2).Children), 'Parent', gui.layout.proAlgn.Children ); % Update aligned and averaged plot + set( gui.layout.proAlgn.Children, 'XLim', temp.Children(2).XLim); + set( gui.layout.proAlgn.Children, 'YLimMode', 'auto'); + if isempty(gui.controls.YLimits) + gui.controls.YLimits = gui.layout.proAlgn.Children.YLim; + end + + if gui.controls.resetAxis + set( gui.layout.proAlgn.Children, 'YLimMode', 'auto'); + gui.controls.YLimits = gui.layout.proAlgn.Children.YLim; + end + + range = abs(gui.controls.YLimits(1)) + abs(gui.controls.YLimits(2)); + if gui.controls.zoomOut + gui.controls.YLimits = [gui.controls.YLimits(1)+sign(gui.controls.YLimits(1))*range*0.05 gui.controls.YLimits(2)+sign(gui.controls.YLimits(2))*range*0.05]; + end + if gui.controls.zoomIn + gui.controls.YLimits = [gui.controls.YLimits(1)-sign(gui.controls.YLimits(1))*range*0.05 gui.controls.YLimits(2)-sign(gui.controls.YLimits(2))*range*0.05]; + end + if gui.controls.MoveUp + gui.controls.YLimits = [gui.controls.YLimits(1)+range*0.01 gui.controls.YLimits(2)+range*0.01]; + end + if gui.controls.MoveDown + gui.controls.YLimits = [gui.controls.YLimits(1)-range*0.01 gui.controls.YLimits(2)-range*0.01]; + end + + % For debugging purposes + % if isfield(MRSCont.processed.metab{gui.controls.Selected},'manual') + % MRSCont.processed.metab{gui.controls.Selected}.manual + % end + % gui.controls.YLimits + + set(gui.layout.proAlgn.Children, 'YLim', gui.controls.YLimits); + set( gui.layout.proAlgn.Children, 'XTick', temp.Children(2).XTick); + close( temp ); + + set(gui.controls.b_save_proTab{gui.process.Selected},'Callback',{@osp_onPrint,gui}); + setappdata(gui.figure,'MRSCont',MRSCont); % Write MRSCont into hidden container in gui class +end \ No newline at end of file diff --git a/GUI/osp_updateProWindow.m b/GUI/osp_updateProWindow.m index 25499131..1977091a 100644 --- a/GUI/osp_updateProWindow.m +++ b/GUI/osp_updateProWindow.m @@ -127,5 +127,6 @@ function osp_updateProWindow(gui) end set(gui.upperBox.pro.Info{gui.process.Selected},'Title', ['Actual file: ' MRSCont.files{gui.controls.Selected}]); set(gui.controls.b_save_proTab{gui.process.Selected},'Callback',{@osp_onPrint,gui}); + gui.controls.YLimits = []; setappdata(gui.figure,'MRSCont',MRSCont); % Write MRSCont into hidden container in gui class end \ No newline at end of file diff --git a/libraries/FID-A/processingTools/op_add_analysis_provenance.m b/libraries/FID-A/processingTools/op_add_analysis_provenance.m index 8ad9e646..306fbb67 100644 --- a/libraries/FID-A/processingTools/op_add_analysis_provenance.m +++ b/libraries/FID-A/processingTools/op_add_analysis_provenance.m @@ -42,7 +42,11 @@ % Add shared fields fields.Time = datestr(now,30); fields.Program = 'Osprey'; - fields.Version = hdr_ext.ProcessingSoftwareVersion.Value; + try + fields.Version = hdr_ext.ProcessingSoftwareVersion.Value; + catch + fields.Version = hdr_ext.ProcessingSoftwareVersion; + end fields = orderfields(fields,{'Time','Program','Version','Method', 'Details'}); field_names = {'Time','Program','Version','Method', 'Details'}; diff --git a/libraries/FID-A/processingTools/op_addextra.m b/libraries/FID-A/processingTools/op_addextra.m new file mode 100644 index 00000000..f45ed872 --- /dev/null +++ b/libraries/FID-A/processingTools/op_addextra.m @@ -0,0 +1,59 @@ +% op_addextra.m +% Jamie Near, McGill University 2014. +% +% USAGE: +% out=op_takesubspec(in,index); +% +% DESCRIPTION: +% Add the subspectra with indices corresponding to the 'index' input +% array. +% +% INPUTS: +% in = input data in matlab structure format. +% index = vector indicating the indices of the subspectra you would like +% to extract. +% +% OUTPUTS: +% out = Output dataset consisting of subspectra indices extracted from +% the input. + +function out=op_addextra(in,in2,index); + +if in.dims.extras>0 +in.fids = squeeze(in.fids); + if in.dims.extras==1 + %SHOULD NEVER HAPPEN (Time dimension should always be dim=1) + error('ERROR: dims.extras==1. This should never happen! Aborting!'); + elseif in.dims.extras==2 + in.fids(:,index,:,:,:) = in2.fids(:,1,:,:,:); + elseif in.dims.extras==3; + in.fids(:,:,index,:,:,:) = in2.fids(:,:,1,:,:,:); + elseif in.dims.extras==4; + in.fids(:,:,:,index,:,:,:) = in2.fids(:,:,:,1,:,:,:); + elseif in.dims.extras==5 + in.fids(:,:,:,:,index,:,:,:) = in2.fids(:,:,:,:,1,:,:,:); + end + + %re-calculate Specs using fft + in.specs=fftshift(fft(in.fids,[],in.dims.t),in.dims.t); + + %re-calculate the sz variable + sz=size(in.fids); + + %add manual phasing entries + if isfield(in2, 'manual') + in.manual = in2.manual; + end + + %FILLING IN DATA STRUCTURE + out=in; + out.sz=sz; + + + %FILLING IN THE FLAGS + out.flags=in.flags; + out.flags.writtentostruct=1; + out.flags.isISIS=0; +else + out = in; +end diff --git a/plot/osp_plotProcess.m b/plot/osp_plotProcess.m index 8c237bf4..13214bd7 100755 --- a/plot/osp_plotProcess.m +++ b/plot/osp_plotProcess.m @@ -916,7 +916,12 @@ plot(ax_proc, NoAlignProcDataToPlot.ppm, real(NoAlignProcDataToPlot.specs(:,1)), 'Color',MRSCont.colormap.LightAccent, 'LineWidth', 1); end else - plot(ax_proc, NoAlignProcDataToPlot.ppm, real(NoAlignProcDataToPlot.specs(:,1))/max(real(NoAlignProcDataToPlot.specs(NoAlignProcDataToPlot.ppm>ppmmin&NoAlignProcDataToPlot.ppmppmmin&NoAlignProcDataToPlot.ppmppmmin&NoAlignProcDataToPlot.ppmppmmin&NoAlignProcDataToPlot.ppmppmmin&procDataToPlot.ppmppmmin&procDataToPlot.ppmppmmin&procDataToPlot.ppmppmmin&procDataToPlot.ppm