Commit a3ddc0dd authored by Jay Dubb's avatar Jay Dubb
Browse files

v1.28.8

-- Change when loading data set that for which the derived data in groupResults doesn't match the directory/file structure of the group folder (because the user has modified folder or file names after the groupResults file was generated) then fix any obstacles to loading and any errors that were generated but print warning and if the new "Group Data Loading Warnings" config parameter is set to "ask every time" then prompt user to select whether to continue loading or quit loading the suspect data set.

-- Add optional argument for "don't ask again" options to MenuBox.m

-- Force add newline to string in Logger.Write method IF it doesn't exist already.

-- Add print debug messages when loading data set to SubjClass and RunClass so that user has clear picture of what the data tree looks in the log file.
parent 859a9f47
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -26,4 +26,7 @@ files
% Auto Save Acquisition Files
% Auto Save Acquisition Files
No
No


% Group Data Loading Warnings
ask every time

% END
% END
+14 −14
Original line number Original line Diff line number Diff line
@@ -4,7 +4,6 @@ classdef GroupClass < TreeNodeClass
        version;
        version;
        versionStr;
        versionStr;
        subjs;
        subjs;
        logger
    end
    end
    
    
    properties % (Access = private)
    properties % (Access = private)
@@ -19,10 +18,8 @@ classdef GroupClass < TreeNodeClass
        
        
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
        function obj = GroupClass(varargin)
        function obj = GroupClass(varargin)
            global logger

            obj@TreeNodeClass(varargin);
            obj@TreeNodeClass(varargin);
            obj.logger = InitLogger(logger);

            obj.InitVersion();
            obj.InitVersion();


            if nargin<3 || ~strcmp(varargin{3}, 'noprint')
            if nargin<3 || ~strcmp(varargin{3}, 'noprint')
@@ -205,17 +202,20 @@ classdef GroupClass < TreeNodeClass
            % 
            % 
            % Conversly unconditional copy copies all properties in the runs under this group
            % Conversly unconditional copy copies all properties in the runs under this group
            if nargin==3 && strcmp(conditional, 'conditional')
            if nargin==3 && strcmp(conditional, 'conditional')
                if strcmp(obj.name,obj2.name)
                if obj.Mismatch(obj2)
                    return
                end
                for i = 1:length(obj.subjs)
                for i = 1:length(obj.subjs)
                    j = obj.existSubj(i,obj2);
                    j = obj.existSubj(i,obj2);
                        if (j>0)
                    if j>0
                        obj.subjs(i).Copy(obj2.subjs(j), 'conditional');
                        obj.subjs(i).Copy(obj2.subjs(j), 'conditional');
                    elseif i<=length(obj2.subjs)
                        obj.subjs(i).Copy(obj2.subjs(i), 'conditional');
                    else
                        obj.subjs(i).Mismatch();
                    end
                    end
                end                
                end                
                    if obj == obj2
                obj.Copy@TreeNodeClass(obj2, 'conditional');
                obj.Copy@TreeNodeClass(obj2, 'conditional');
                    end
                end
            else
            else
                for i=1:length(obj2.subjs)
                for i=1:length(obj2.subjs)
                    obj.subjs(i) = SubjClass(obj2.subjs(i));
                    obj.subjs(i) = SubjClass(obj2.subjs(i));
+13 −11
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ classdef RunClass < TreeNodeClass
            %   run1copy = RunClass(run1);
            %   run1copy = RunClass(run1);
            %           
            %           
            obj@TreeNodeClass(varargin);            
            obj@TreeNodeClass(varargin);            
            
            obj.type  = 'run';
            obj.type  = 'run';
            if nargin==0
            if nargin==0
                obj.name  = '';
                obj.name  = '';
@@ -121,7 +122,7 @@ classdef RunClass < TreeNodeClass
            end
            end
            
            
            if obj.acquired.Error() > 0
            if obj.acquired.Error() > 0
                fprintf('     **** Warning: %s failed to load.\n', obj.name);
                obj.logger.Write(sprintf('     **** Warning: %s failed to load.\n', obj.name));
                return;
                return;
            else
            else
                %fprintf('    Loaded file %s to run.\n', obj.name);                
                %fprintf('    Loaded file %s to run.\n', obj.name);                
@@ -159,7 +160,7 @@ classdef RunClass < TreeNodeClass
        function b = AcquiredDataModified(obj)
        function b = AcquiredDataModified(obj)
            b = obj.procStream.AcquiredDataModified();
            b = obj.procStream.AcquiredDataModified();
            if b
            if b
                fprintf('Acquisition data for run %s has been modified\n', obj.name);
                obj.logger.Write(sprintf('Acquisition data for run %s has been modified\n', obj.name));
            end
            end
        end
        end


@@ -168,13 +169,14 @@ classdef RunClass < TreeNodeClass
        % Copy processing params (procInut and procResult) from
        % Copy processing params (procInut and procResult) from
        % N2 to N1 if N1 and N2 are same nodes
        % N2 to N1 if N1 and N2 are same nodes
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
        function Copy(obj, R, conditional)
        function Copy(obj, obj2, conditional)
            if nargin==3 && strcmp(conditional, 'conditional')
            if nargin==3 && strcmp(conditional, 'conditional')
                if obj == R
                if obj.Mismatch(obj2)
                    obj.Copy@TreeNodeClass(R, 'conditional');
                    return
                end
                end
                obj.Copy@TreeNodeClass(obj2, 'conditional');
            else
            else
                obj.Copy@TreeNodeClass(R);
                obj.Copy@TreeNodeClass(obj2);
                if isempty(obj.acquired)
                if isempty(obj.acquired)
                    if obj.IsNirs()
                    if obj.IsNirs()
                        obj.acquired = NirsClass();
                        obj.acquired = NirsClass();
@@ -182,7 +184,7 @@ classdef RunClass < TreeNodeClass
                        obj.acquired = SnirfClass();
                        obj.acquired = SnirfClass();
                    end
                    end
                end
                end
                obj.acquired.Copy(R.acquired);
                obj.acquired.Copy(obj2.acquired);
            end
            end
        end
        end


@@ -299,8 +301,8 @@ classdef RunClass < TreeNodeClass
            obj.procStream.Calc(obj.GetFilename);
            obj.procStream.Calc(obj.GetFilename);


            if obj.DEBUG
            if obj.DEBUG
                fprintf('Completed processing stream for group %d, subject %d, run %d\n', obj.iGroup, obj.iSubj, obj.iRun);
                obj.logger.Write(sprintf('Completed processing stream for group %d, subject %d, run %d\n', obj.iGroup, obj.iSubj, obj.iRun));
                fprintf('\n')
                obj.logger.Write('\n')
            end            
            end            
        end
        end


+19 −15
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@ classdef SubjClass < TreeNodeClass
        runs;
        runs;
    end
    end
       
       
    
    methods
    methods
                
                
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
@@ -57,32 +58,35 @@ classdef SubjClass < TreeNodeClass
        % Copy processing params (procInut and procResult) from
        % Copy processing params (procInut and procResult) from
        % S to obj if obj and S are equivalent nodes
        % S to obj if obj and S are equivalent nodes
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
        function Copy(obj, S, conditional)
        function Copy(obj, obj2, conditional)
            % Copy SubjClass object obj2 to SubjClass object obj. Conditional option applies 
            % Copy SubjClass object obj2 to SubjClass object obj. Conditional option applies 
            % only to all the runs under this group. If == 'conditional' ONLY derived data, 
            % only to all the runs under this group. If == 'conditional' ONLY derived data, 
            % that is, only from procStream but NOT from acquired data is copied for all the runs. 
            % that is, only from procStream but NOT from acquired data is copied for all the runs. 
            % 
            % 
            % Conversly unconditional copy copies all properties in the runs under this subject
            % Conversly unconditional copy copies all properties in the runs under this subject
            if nargin==3 && strcmp(conditional, 'conditional')
            if nargin==3 && strcmp(conditional, 'conditional')
                if strcmp(obj.name, S.name)
                if obj.Mismatch(obj2)
                    return
                end
                for i = 1:length(obj.runs)
                for i = 1:length(obj.runs)
                        j = obj.existRun(i,S);
                    j = obj.existRun(i,obj2);
                    if (j>0)
                    if (j>0)
                            obj.runs(i).Copy(S.runs(j), 'conditional');
                        obj.runs(i).Copy(obj2.runs(j), 'conditional');
                        end
                    elseif i<=length(obj2.runs)
                    end
                        obj.runs(i).Copy(obj2.runs(i), 'conditional');
                    if obj == S
                    else
                        obj.Copy@TreeNodeClass(S, 'conditional');
                        obj.Mismatch();
                    end
                    end
                end
                end
                obj.Copy@TreeNodeClass(obj2, 'conditional');
            else
            else
                if nargin<3
                if nargin<3
                    conditional = '';
                    conditional = '';
                end
                end
                for i=1:length(S.runs)
                for i=1:length(obj2.runs)
                    obj.runs(i) = RunClass(S.runs(i), conditional);
                    obj.runs(i) = RunClass(obj2.runs(i), conditional);
                end
                end
                obj.Copy@TreeNodeClass(S);
                obj.Copy@TreeNodeClass(obj2);
            end
            end
        end
        end
        
        
@@ -165,7 +169,7 @@ classdef SubjClass < TreeNodeClass
                jj = length(obj.runs)+1;
                jj = length(obj.runs)+1;
                run.SetIndexID(obj.iGroup, obj.iSubj, jj);
                run.SetIndexID(obj.iGroup, obj.iSubj, jj);
                obj.runs(jj) = run;
                obj.runs(jj) = run;
                fprintf('     Added run %s to subject %s.\n', obj.runs(jj).GetFileName, obj.GetName);
                obj.logger.Write(sprintf('     Added run %s to subject %s.\n', obj.runs(jj).GetFileName, obj.GetName));
            end
            end
            
            
            % If subject has only one run AND the run file name is not formatted according to the standard Homer 
            % If subject has only one run AND the run file name is not formatted according to the standard Homer 
@@ -265,7 +269,7 @@ classdef SubjClass < TreeNodeClass
            end
            end
                        
                        
            if obj.DEBUG
            if obj.DEBUG
                fprintf('Calculating processing stream for group %d, subject %d\n', obj.iGroup, obj.iSubj)
                obj.logger.Write(sprintf('Calculating processing stream for group %d, subject %d\n', obj.iGroup, obj.iSubj));
            end
            end
            
            
            % Calculate all runs in this session and generate common tHRF
            % Calculate all runs in this session and generate common tHRF
+74 −11
Original line number Original line Diff line number Diff line
@@ -17,13 +17,17 @@ classdef TreeNodeClass < handle
        outputVars
        outputVars
        DEBUG
        DEBUG
        path
        path
        logger
    end
    end
    
    
    methods        
    methods        
        
        
        
        % ---------------------------------------------------------------------------------
        % ---------------------------------------------------------------------------------
        function obj = TreeNodeClass(arg)
        function obj = TreeNodeClass(arg)
            global logger

            obj.logger = InitLogger(logger);

            obj.DEBUG = 0;
            obj.DEBUG = 0;
            
            
            obj.name = '';
            obj.name = '';
@@ -36,7 +40,6 @@ classdef TreeNodeClass < handle
            obj.CondNames = {};
            obj.CondNames = {};
            obj.path = filesepStandard(pwd);            
            obj.path = filesepStandard(pwd);            
                        
                        
            
            obj.InitParentAppFunc();
            obj.InitParentAppFunc();
            
            
            % If this constructor is called from this class' copy method,
            % If this constructor is called from this class' copy method,
@@ -56,7 +59,7 @@ classdef TreeNodeClass < handle
                end
                end
            end
            end
            obj.CondColTbl('init');
            obj.CondColTbl('init');
                                   
            obj.GroupDataLoadWarnings();            
        end
        end
        
        
    end
    end
@@ -174,7 +177,7 @@ classdef TreeNodeClass < handle
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
        function InitParentAppFunc(obj)
        function InitParentAppFunc(obj)
            global maingui
            global maingui
            if ~isempty(maingui)
            if isfield(maingui, 'Update')
                obj.updateParentGui = maingui.Update;
                obj.updateParentGui = maingui.Update;
            end
            end
        end
        end
@@ -660,6 +663,53 @@ classdef TreeNodeClass < handle
        end
        end
        
        
        
        
        % ----------------------------------------------------------------------------------
        function status = Mismatch(obj, obj2)
            status = 0;
            if exist('obj2','var')                
                if obj == obj2
                    return
                end
            end
            status = 1;
                        
            configFileOptions =  MenuBox('',{},[],[], 'dontaskagain');
            choices = { ...
                sprintf('Continue Loading'); ...
                sprintf('Quit Loading'); ...
            };
        
            if exist('obj2','var')
                msg{1} = sprintf('WARNING: Saved data for %s "%s" does not match this group folder. ', obj.type, obj.name);
                msg{2} = sprintf('Are you sure this saved data belongs to this group folder?');
            else
                msg{1} = sprintf('WARNING: The %s "%s" does not match the saved group data. ', obj.type, obj.name);
                msg{2} = sprintf('Are you sure the saved data belongs to this group folder?');
            end
            obj.logger.Write([msg{:}])
            if strcmp(obj.GroupDataLoadWarnings, configFileOptions{1})
                status = 0;
                return;
            end
            selection = MenuBox([msg{:}], choices, [], [], 'dontaskagain');
            if selection(1)==1
                status = 0;
            end
            
            % Find out if config value does not equal current selection. If
            % not then reset config value
            if selection(2)>0
                if ~strcmp(obj.GroupDataLoadWarnings, configFileOptions{selection(2)})
                    % Overwrite config value
                    cfg = ConfigFileClass();
                    cfg.SetValue('Group Data Loading Warnings', configFileOptions{selection(2)});
                    cfg.Save();
                    obj.GroupDataLoadWarnings()
                end
            end
                        
        end
                
    end
    end


    
    
@@ -710,6 +760,19 @@ classdef TreeNodeClass < handle
        end
        end
   
   
                
                
        % --------------------------------------------------------------------------------
        function out = GroupDataLoadWarnings()
            persistent v;
            if ~exist('arg','var')
                cfg = ConfigFileClass();
                v = cfg.GetValue('Group Data Loading Warnings');
            elseif exist('arg','var')
                v = arg;
            end
            out = v;
        end
        
        
    end
    end
    
    
end
end
Loading