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

v1.31.4

-- Implement configurable output folder for Homer3 derived data. Added new config params "Output Folder Name", and "Output File Name" that are currently set to the defaults 'homerOutput and 'groupResults.mat'.
-- Change unit tests to work with the change in output files and folders
parent 93919426
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -29,4 +29,10 @@ ask every time
% Stim Edit GUI Save Warnings # don't ask again, ask every time
don't ask again

% Output Folder Name
homerOutput

% Output File Name
groupResults.mat

% END
+10 −8
Original line number Diff line number Diff line
@@ -13,6 +13,9 @@ classdef DataTreeClass < handle
        dataStorageScheme
    end
    
    
    
    
    methods
        
        % ---------------------------------------------------------------
@@ -368,7 +371,11 @@ classdef DataTreeClass < handle
                    runCurr = RunClass().empty();
                end
            end
            obj.logger.Write(sprintf('\nLoaded acquisition data in %0.1f seconds\n\n', toc));            
            obj.logger.Write(sprintf('\n'));
            obj.logger.Write(sprintf('Loaded group %s acquisition data in %0.1f seconds\n', obj.groups(iG).name, toc));
            obj.logger.Write(sprintf('  Derived data output folder   : %s%s\n', obj.groups(iG).path, obj.groups(iG).outputDirname));
            obj.logger.Write(sprintf('  Derived data output file     : %s\n\n', obj.groups(iG).outputFilename));
            
        end


@@ -392,11 +399,6 @@ classdef DataTreeClass < handle
                group.SetIndexID(jj);
                obj.groups(jj) = group;
                obj.groups(jj).SetPath(obj.dirnameGroups{jj})

                % In case there's not enough disk space in the current
                % group folder, we have a separate path for saving group
                % results
                obj.groups(jj).SetPathOutput(obj.dirnameGroups{jj})
                obj.logger.Write(sprintf('Added group %s to dataTree.\n', obj.groups(jj).GetName));
            end

@@ -553,10 +555,10 @@ classdef DataTreeClass < handle
            
            t_local = tic;
            for ii = 1:length(obj.groups)
                obj.logger.Write(sprintf('Saving group %d in %s\n', ii, [obj.groups(ii).pathOutput, 'groupResults.mat']));                
                obj.logger.Write(sprintf('Saving group %d in %s\n', ii, [obj.groups(ii).pathOutputAlt, obj.groups(ii).GetOutputFilename()]));
                obj.groups(ii).Save(hwait);
            end
            obj.logger.Write(sprintf('Completed saving groupResults.mat for all groups in %0.3f seconds.\n', toc(t_local)));
            obj.logger.Write(sprintf('Completed saving processing results for all groups in %0.3f seconds.\n', toc(t_local)));
        end


+76 −16
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ classdef GroupClass < TreeNodeClass
    end
    
    properties % (Access = private)
        pathOutput
        outputFilename
    end
    
    
@@ -29,6 +29,11 @@ classdef GroupClass < TreeNodeClass
            obj.type    = 'group';
            obj.subjs   = SubjClass().empty;
                        
            obj.outputFilename = obj.cfg.GetValue('Output File Name');
            if isempty(obj.outputFilename)
                obj.outputFilename = 'groupResults.mat';
            end
            
            if nargin==0
                return;
            end
@@ -108,6 +113,12 @@ classdef GroupClass < TreeNodeClass
        end
        
        
        % ----------------------------------------------------------------------------------
        function filename = GetOutputFilename(obj)
            filename = obj.outputFilename;
        end
        
        
        % ----------------------------------------------------------------------------------
        function InitVersionStrFull(obj)
            if isempty(obj.version)
@@ -268,12 +279,22 @@ classdef GroupClass < TreeNodeClass
        % ----------------------------------------------------------------------------------
        function SetPath(obj, dirname)
            obj.path = dirname;
            
            % In case there's not enough disk space in the current
            % group folder, we have a alternative path that can be 
            % set independently for saving group results. By default 
            % it is set to root group folder. 
            obj.pathOutputAlt = obj.path;
        end
        
        
        % ----------------------------------------------------------------------------------
        function SetPathOutput(obj, dirname)
            obj.pathOutput = dirname;
            % In case there's not enough disk space in the current
            % group folder, we have a alternative path that can be 
            % set independently for saving group results. By default 
            % it is set to root group folder. 
            obj.pathOutputAlt = dirname;
        end
        
        
@@ -324,7 +345,7 @@ classdef GroupClass < TreeNodeClass
            % Find out if we need to ask user for processing options 
            % config file to initialize procStream.fcalls at the 
            % run, subject or group level. First try to find the proc 
            % input at each level from the save results groupresults.mat 
            % input at each level from the saved derived data. 
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            g = obj;
            s = obj.subjs(1);
@@ -498,8 +519,8 @@ classdef GroupClass < TreeNodeClass
            if ~exist('option','var')
                option = 'down';
            end
            if exist([obj.path, 'groupResults.mat'],'file')
                delete([obj.path, 'groupResults.mat']);
            if exist([obj.path, obj.outputDirname, obj.outputFilename],'file')
                delete([obj.path, obj.outputDirname, obj.outputFilename]);
            end
            if strcmp(option, 'down')
                for jj=1:length(obj.subjs)
@@ -584,11 +605,13 @@ classdef GroupClass < TreeNodeClass
                return;
            end
            
            obj.BackwardCompatability();

            group = [];
            if exist([obj.path, 'groupResults.mat'],'file')
                g = load([obj.path, 'groupResults.mat']);
            if ispathvalid([obj.path, obj.outputDirname, obj.outputFilename],'file')
                g = load([obj.path, obj.outputDirname, obj.outputFilename]);
                
                % Do some basic error checks on groupResults contents
                % Do some basic error checks on saved derived data contents
                if isproperty(g, 'group') && isa(g.group, 'GroupClass')
                    if isproperty(g.group, 'version')
                        if ismethod(g.group, 'GetVersion')
@@ -602,7 +625,7 @@ classdef GroupClass < TreeNodeClass
            % Copy saved group to current group if versions are compatible. obj.CompareVersions==0 
            % means the versions of the saved group and current one are equal.
            if ~isempty(group) && obj.CompareVersions(group)<=0
                % Do a conditional copy of group from groupResults file. Conditional copy copies ONLY 
                % Do a conditional copy of group from saved processing output file. Conditional copy copies ONLY 
                % derived data, that is, only from procStream but NOT acqruired. We do not want to 
                % overwrite the real acquired data loaded from acquisition files 
                hwait = waitbar(0,'Loading group');
@@ -610,9 +633,10 @@ classdef GroupClass < TreeNodeClass
                close(hwait);
            else
                group = obj; %#ok<NASGU>
                if exist([obj.path, 'groupResults.mat'],'file')
                    obj.logger.Write(sprintf('Warning: This folder contains old version of groupResults.mat. Will move it to groupResults_old.mat\n'));
                    movefile([obj.path, 'groupResults.mat'], './groupResults_old.mat')
                if exist([obj.path, obj.outputDirname, obj.outputFilename],'file')
                    obj.logger.Write(sprintf('Warning: This folder contains old version of processing results. Will move it to *_old.mat\n'));
                    [~,outputFilename] = fileparts(obj.outputFilename);
                    movefile([obj.path, obj.outputDirname, obj.outputFilename], [obj.path, obj.outputDirname, outputFilename, '_old.mat'])
                end
                obj.Save();
            end
@@ -627,15 +651,16 @@ classdef GroupClass < TreeNodeClass
                hwait = [];
            end            
            
            obj.logger.Write(sprintf('Saving processed data in %s\n', [obj.path, 'groupResults.mat']));
            obj.logger.Write(sprintf('Saving processed data in %s\n', [obj.path, obj.outputDirname, obj.outputFilename]));
            
            if ishandle(hwait)
                obj.logger.Write(sprintf('Auto-saving processing results ...\n'), obj.logger.ProgressBar(), hwait);
            end
            
            group = GroupClass(obj); %#ok<NASGU>
            group = GroupClass(obj);
            try 
                save([obj.pathOutput, 'groupResults.mat'], 'group');
                obj.CreateOutputDir();
                save([obj.pathOutputAlt, obj.outputDirname, obj.outputFilename], 'group');
            catch ME
                MessageBox(ME.message);
                obj.logger.Write(ME.message);
@@ -644,6 +669,19 @@ classdef GroupClass < TreeNodeClass
        
        
        
        % ----------------------------------------------------------------------------------
        function CreateOutputDir(obj)
            if ispathvalid([obj.pathOutputAlt, obj.outputDirname])
                return;
            end
            mkdir([obj.pathOutputAlt, obj.outputDirname]);
            for ii = 1:length(obj.subjs)
                obj.subjs(ii).CreateOutputDir();
            end
        end
            
           
        
        % ----------------------------------------------------------------------------------
        function SaveAcquiredData(obj)            
            for ii = 1:length(obj.subjs)
@@ -946,6 +984,28 @@ classdef GroupClass < TreeNodeClass
            end
        end
        
        
        
        % ----------------------------------------------------------------------------------
        function BackwardCompatability(obj)
%             if ispathvalid([obj.path, 'groupResults.mat'])
%                 q = MenuBox('Detected derived data in this group folder in the old format. Do you want to save it in the new format?',{'Yes','No'});
%                 if q==1
%                     if ~ispathvalid([obj.path, obj.outputDirname])
%                         mkdir([obj.path, obj.outputDirname])
%                     end
%                     movefile('groupResults.mat', [obj.path, obj.outputDirname, obj.outputFilename])
%                     files = dir('*.mat');
%                     for ii = 1:length(files)
%                         movefile(files(ii).name, [obj.path, obj.outputDirname]);
%                     end
%                 else
%                     obj.outputDirname = '';
%                 end
%             end
        end
        

    end  % Private methods

end % classdef GroupClass < TreeNodeClass
+48 −24
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ classdef ProcResultClass < handle
        
    properties (Access=private)
        filename
        logger
    end
    
    
@@ -25,6 +26,10 @@ classdef ProcResultClass < handle
        
        % ---------------------------------------------------------------------------
        function obj = ProcResultClass()
            global logger
            
            obj.logger = InitLogger(logger);
            
            obj.Initialize();
            obj.filename = '';
        end
@@ -160,36 +165,36 @@ classdef ProcResultClass < handle
            if isempty(filename)
                return;
            end
            [pname, fname] = fileparts(filename);
            [pname, fname, ext] = fileparts(filename);
            
            % Set the containing folder name 
            if isempty(pname)
                % See if folder corresponding to saved output exists. If it
                % does then set it to be same as the .mat filename (without
                % the extension)
                rootdir = '';
                if exist(['./', fname], 'dir')==7
                    rootdir = fname;
            if isempty(ext)
                % Filename argument names folder
                                
                    % Next 3 lines are for backwards compatibility: if the saved output 
                    % for subject is stored in the group instead of subject folder as was 
                    % done in previous versions of this code, then move saved file to 
                    % subject folder
                    if exist(['./', fname, '.mat'], 'file')==2
                        movefile(['./', fname, '.mat'], ['./', rootdir, '/', fname, '.mat']);
                    end
                rootdir = '';
                if ispathvalid(pname)
                    rootdir = [filesepStandard(pname), filesepStandard(fname)];
                elseif ispathvalid(filename)
                    rootdir = filesepStandard(filename);
                end
                
                % Set the containing folder name 
                if exist(['./', rootdir, '/', fname, '.mat'], 'file')==2
                if ispathvalid(['./', rootdir, fname, '.mat'], 'file')
                    pname = ['./', rootdir];
                elseif exist(['../', rootdir, '/', fname, '.mat'], 'file')==2
                elseif ispathvalid(['../', rootdir, fname, '.mat'], 'file')
                    pname = ['../', rootdir];
                else
                    pname = ['./', rootdir]; 
                end
                pname = filesepStandard(pname);
                
            elseif ispathvalid(pname)
                
                pname = ['./', filesepStandard(pname)];

            end
            obj.filename = [pname, '/', fname, '.mat'];
            
            obj.filename = [pname, fname, '.mat'];
        end
        
        
@@ -205,7 +210,7 @@ classdef ProcResultClass < handle
            
            obj.SetFilename(filename)
            
            output = obj; %#ok<NASGU>
            output = obj;
            props = propnames(vars);
            for ii=1:length(props)
                if eval( sprintf('isproperty(output, ''%s'');', props{ii}) )
@@ -221,7 +226,26 @@ classdef ProcResultClass < handle
                return;
            end
            
            % If saving this data for the first time folder might have to be created under 
            % the processd data output folder, depending on the group folder folder structure
            pname = fileparts(obj.filename);
            if ~isempty(pname)
                if ~ispathvalid(pname)
                    mkdir(pname)
                end
            end
            
            try
                obj.logger.Write(sprintf('Saving derived data output: %s', obj.filename));
            	save(obj.filename, '-mat', 'output');
            catch
                if ~ispathvalid(obj.filename)
                    msg = sprintf('ERROR: Was not able to save processed data - %s not found.', obj.filename);
                    MessageBox(msg);
                    obj.logger.Write(msg);
                    return;
                end
            end
            
            % Free memory for this object
            if ~isempty(findstr('freememory', options)) %#ok<FSTR>
@@ -246,7 +270,7 @@ classdef ProcResultClass < handle
            end
            
            % Error check file
            if ~exist(obj.filename,'file')
            if ~ispathvalid(obj.filename,'file')
                return
            end
            
@@ -294,7 +318,7 @@ classdef ProcResultClass < handle
            end
            
            % Check that data file associated with this processing element exists
            if exist(obj.filename,'file')
            if ispathvalid(obj.filename, 'file')
                % Delete file containing the actual datas
                delete(obj.filename);
            end
@@ -302,7 +326,7 @@ classdef ProcResultClass < handle

            % Check that exported data file associated with this processing element exists
            [pname, fname] = fileparts(obj.filename);
            if exist([pname, '/', fname, '_HRF.txt'], 'file')
            if ispathvalid([pname, '/', fname, '_HRF.txt'], 'file')
                delete([pname, '/', fname, '_HRF.txt']);
            end
        end
+13 −0
Original line number Diff line number Diff line
@@ -233,6 +233,19 @@ classdef SubjClass < TreeNodeClass
        end            
            
        
        % ----------------------------------------------------------------------------------
        function CreateOutputDir(obj)
            if ispathvalid([obj.pathOutputAlt, obj.outputDirname, obj.name])
                return;
            end
            if ~ispathvalid([obj.pathOutputAlt, obj.name])
                return;
            end
            mkdir([obj.pathOutputAlt, obj.outputDirname, obj.name]);
        end
            

        
        % ----------------------------------------------------------------------------------
        function LoadVars(obj, r, tHRF_common)
            % Set common tHRF: make sure size of tHRF, dcAvg and dcAvg is same for
Loading