Commit 5bfcf19d authored by Jay Dubb's avatar Jay Dubb
Browse files

v1.31.13

-- Added backward compatibility to data tree for dealing with old format Homer3 derived data which was saved directly under group folder previously. Asks user if they want to move it to new folder if new format data does not exist.
-- Improve data tree algorithm for determining save file name. Added method GetOutputFilename vs GetFilename to distinguish between derived and acquired data
-- Fix some issues with Export data and make it's output save to same folders as regular derived data. Fix also data Reset method
-- Improvements in utility functions.
-- Sync AppSettings.cfg with AtlasViewer they should be the same
parent eba57454
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -24,15 +24,15 @@ files
No

% Group Data Loading Warnings # don't ask again, ask every time
ask every time
don't ask again

% Stim Edit GUI Save Warnings # don't ask again, ask every time
don't ask again

% Output Folder Name
% Output Folder Name # 
homerOutput

% Output File Name
% Output File Name # 
groupResults.mat

% END
+1 −1
Original line number Diff line number Diff line
@@ -555,7 +555,7 @@ 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).pathOutputAlt, obj.groups(ii).GetOutputFilename()]));
                obj.logger.Write(sprintf('Saving group %d in %s\n', ii, [obj.groups(ii).pathOutputAlt, obj.groups(ii).GetFilename()]));
                obj.groups(ii).Save(hwait);
            end
            obj.logger.Write(sprintf('Completed saving processing results for all groups in %0.3f seconds.\n', toc(t_local)));
+70 −24
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ classdef GroupClass < TreeNodeClass
        
        
        % ----------------------------------------------------------------------------------
        function filename = GetOutputFilename(obj)
        function filename = GetFilename(obj)
            filename = obj.outputFilename;
        end
        
@@ -482,7 +482,7 @@ classdef GroupClass < TreeNodeClass
            obj.procStream.input.LoadVars(obj.outputVars);

            % Calculate processing stream
            obj.procStream.Calc(obj.GetFilename);
            obj.procStream.Calc(obj.GetOutputFilename());

            if obj.DEBUG
                obj.logger.Write(sprintf('Completed processing stream for group %d\n', obj.iGroup));
@@ -587,7 +587,7 @@ classdef GroupClass < TreeNodeClass
            if isempty(obj)
                return;
            end
            err1 = obj.procStream.Load(obj.GetFilename);
            err1 = obj.procStream.Load(obj.GetOutputFilename());
            err2 = obj.subjs(1).LoadSubBranch();
            if err1==0 && err2==0
                err = 0;
@@ -672,7 +672,7 @@ classdef GroupClass < TreeNodeClass
                obj.logger.Write(sprintf('Auto-saving processing results ...\n'), obj.logger.ProgressBar(), hwait);
            end
            
            group = GroupClass(obj); %#ok<NASGU>
            group = GroupClass(obj);
            try 
                obj.CreateOutputDir();
                save([obj.pathOutputAlt, obj.outputDirname, obj.outputFilename], 'group');
@@ -735,7 +735,7 @@ classdef GroupClass < TreeNodeClass
                iBlk = 1;
            end
            
            obj.procStream.ExportHRF(obj.name, obj.CondNames, iBlk);
            obj.procStream.ExportHRF(obj.GetOutputFilename, obj.CondNames, iBlk);
            if strcmp(procElemSelect, 'all')
                for ii=1:length(obj.subjs)
                    obj.subjs(ii).ExportHRF('all', iBlk);
@@ -949,13 +949,26 @@ classdef GroupClass < TreeNodeClass
            end
        end

        
        % ----------------------------------------------------------------------------------
        function r = ListOutputFilenames(obj, options)
            if ~exist('options','var')
                options = '';
            end
            r = obj.GetOutputFilename(options);
            fprintf('%s %s\n', obj.path, r);
            for ii = 1:length(obj.subjs)
                obj.subjs(ii).ListOutputFilenames(options);
            end
        end        

    end
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Private methods
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    methods (Access = private)
    methods (Access = public)
        
        % ----------------------------------------------------------------------------------
        % Check whether subject k'th subject from this group exists in group G and return
@@ -1001,25 +1014,58 @@ classdef GroupClass < TreeNodeClass
        
        
        
        % ----------------------------------------------------------------------------------
        function b = HaveOutput(obj)
            b = false;
            for ii = 1:length(obj.subjs)
                b = obj.subjs(ii).HaveOutput();
                if b
                    break;
                end
            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
            if ispathvalid([obj.path, 'groupResults.mat'])
                g = load([obj.path, 'groupResults.mat']);
                
                % Do not try to restore old data older than Homer3
                if isempty(g)
                    return;
                end
                if ~isproperty(g,'group')
                    return;
                end
                if ~isa(g.group, 'GroupClass')
                    return;
                end
                
                % Do not try to restore old data if there is already data
                % in the new format
                if obj.HaveOutput()
                    return;
                end
                
                msg = sprintf('Detected derived data in an old Homer3 format.');
                obj.logger.Write(sprintf('Backward Compatability: %s\n', msg));
                
                % If we're here it means that old format homer3 data exists
                % AND NO new homer3 format data exists
                q = MenuBox(sprintf('%s. Do you want to save it in the new format?', msg),{'Yes','No'});
                if q==1
                    obj.BackwardCompatability@TreeNodeClass();
                    for ii = 1:length(obj.subjs)
                        obj.subjs(ii).BackwardCompatability();
                    end
                    
                    obj.logger.Write(sprintf('Moving %s to %s\n', 'groupResults.mat', [obj.path, obj.outputDirname, obj.outputFilename]));
                    movefile('groupResults.mat', [obj.path, obj.outputDirname, obj.outputFilename])
                end
            end
        end
            
    end  % Private methods

+18 −35
Original line number Diff line number Diff line
@@ -161,44 +161,27 @@ classdef ProcResultClass < handle
    methods
        
        % ----------------------------------------------------------------------------------
        function SetFilename(obj, filename)
        function filename = SetFilename(obj, filename)            
            if nargin==1
                filename = '';
                return;
            end                
            if isempty(filename)
                return;
            end
            [pname, fname, ext] = fileparts(filename);
            
            % Set the containing folder name 
            if isempty(ext)
                % Filename argument names folder
                                
                rootdir = '';
                if ispathvalid(pname)
                    rootdir = [filesepStandard(pname), filesepStandard(fname, 'nameonly')];
                elseif ispathvalid(filename)
                    rootdir = filesepStandard(filename);
                end
                
                % Set the containing folder name 
                if ispathvalid(['./', rootdir])
                    rootdir = ['./', rootdir];
                elseif ispathvalid(['../', rootdir])
                    rootdir = ['../', rootdir];                    
                end                
                if ispathvalid([rootdir, fname, '.mat'], 'file')
                    pname = rootdir;
                ext = '.mat';
                if ispathvalid([filesepStandard(pname), fname], 'dir')
                    pname = [filesepStandard(pname), fname];
                elseif ispathvalid([filesepStandard(['../', pname]), fname], 'dir')
                    pname = [filesepStandard(['../', pname]), fname];
                elseif ispathvalid(filesepStandard(['../', pname]), 'dir')
                    pname = filesepStandard(['../', pname]);
                end
                pname = filesepStandard(pname);
                
            elseif ispathvalid(pname)
                if ispathvalid(['./', filesepStandard(pname)])
                    pname = ['./', filesepStandard(pname)];
                else
                    pname = [filesepStandard(pname)];
            end

            end
            
            obj.filename = [pname, fname, '.mat'];
            filename = [filesepStandard(pname, 'nameonly:dir'), fname, ext];
            obj.filename = filename;
        end
        
        
@@ -212,7 +195,7 @@ classdef ProcResultClass < handle
                options = 'keepinmemory';
            end
            
            obj.SetFilename(filename)
            obj.SetFilename(filename);
            
            output = obj;
            props = propnames(vars);
@@ -262,7 +245,7 @@ classdef ProcResultClass < handle
        % ----------------------------------------------------------------------------------
        function err = Load(obj, filename)
            err = 0;
            obj.SetFilename(filename)
            obj.SetFilename(filename);
            if isempty(obj.filename)
                return;
            end
@@ -316,7 +299,7 @@ classdef ProcResultClass < handle
        function Reset(obj, filename)
            obj.Initialize();

            obj.SetFilename(filename)
            obj.SetFilename(filename);
            if isempty(obj.filename)
                return;
            end
@@ -686,7 +669,7 @@ classdef ProcResultClass < handle
            if ~exist('filename', 'var')
                filename = '';
            end            
            obj.SetFilename(filename)
            obj.SetFilename(filename);
            
            % If file name is set and exists then load data from file
            if ~isempty(filename) && exist(obj.filename, 'file')
+2 −2
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ classdef ProcStreamClass < handle
                end
                
                % Parse obj.input parameters
                [sargin, p, sarginVal] = obj.ParseInputParams(iFcall);
                [sargin, p, sarginVal] = obj.ParseInputParams(iFcall); %#ok<ASGLU>
                
                % Parse obj.input output arguments
                sargout = obj.ParseOutputArgs(iFcall);
@@ -282,7 +282,7 @@ classdef ProcStreamClass < handle
                lst = [0, lst, length(foos)+1]; %#ok<*AGROW>
                for ii=1:length(lst)-1
                    foo2 = foos(lst(ii)+1:lst(ii+1)-1);
                    lst2 = strmatch( foo2, paramOut, 'exact' );
                    lst2 = strmatch( foo2, paramOut, 'exact' ); %#ok<MATCH3>
                    idx = strfind(foo2,'foo');
                    if isempty(lst2) && (isempty(idx) || idx>1) && ~isempty(foo2)
                        paramOut{end+1} = foo2;
Loading