Unverified Commit cc591fe5 authored by jayd1860's avatar jayd1860 Committed by GitHub
Browse files

Merge pull request #66 from BUNPC/development

For release v1.32.2
parents 2b875c21 78b40e4e
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -24,9 +24,18 @@ 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 # 
homerOutput

% Output File Name # 
groupResults.mat

% Fix File Name Conflicts # don't ask again, ask every time
ask every time

% END
+126 −20
Original line number Diff line number Diff line
@@ -16,31 +16,48 @@ classdef DataFilesClass < handle
        function obj = DataFilesClass(varargin)
            obj.type = '';
            obj.pathnm = pwd;
            skipconfigfile = false;
            obj.nfiles = 0;
            obj.err = -1;
            obj.errmsg = {};
            
            skipconfigfile = false;
            askToFixNameConflicts = [];
            
            if nargin>0
            if nargin==0
                return
            end            
            if nargin==1
                obj.pathnm = varargin{1};
            end            
            obj.pathnm = filesepStandard(obj.pathnm,'full');

            if nargin>1
            if nargin==2
                obj.pathnm = varargin{1};
                obj.type = varargin{2};
                if obj.type(1)=='.'
                    obj.type(1)='';
            end            
            if nargin==3
                obj.pathnm = varargin{1};
                obj.type = varargin{2};
                if strcmp(varargin{3}, 'standalone')
                    skipconfigfile = true;
                end
            obj.errmsg = {};
            
            if nargin>2
            end            
            if nargin==4
                obj.pathnm = varargin{1};
                obj.type = varargin{2};
                if strcmp(varargin{3}, 'standalone')
                    skipconfigfile = true;
                end
                askToFixNameConflicts = varargin{4};
            end
                        
            obj.config = struct('RegressionTestActive','');
            if skipconfigfile==false
            if obj.type(1)=='.'
                obj.type(1)='';
            end
            obj.pathnm = filesepStandard(obj.pathnm,'full');
            
            % Configuration parameters
            obj.config = struct('RegressionTestActive','','AskToFixNameConflicts',1);
            cfg = ConfigFileClass();
            if skipconfigfile==false
                str = cfg.GetValue('Regression Test Active');
                if strcmp(str,'true')
                    obj.config.RegressionTestActive=true;
@@ -50,11 +67,17 @@ classdef DataFilesClass < handle
            else
                obj.config.RegressionTestActive=false;
            end
            if ~isempty(askToFixNameConflicts)
                obj.config.AskToFixNameConflicts = askToFixNameConflicts;
            elseif strcmp(cfg.GetValue('Fix File Name Conflicts'), sprintf('don''t ask again'))
                obj.config.AskToFixNameConflicts = 0;
            end
            
            if nargin==0
                return;
            end
            
            obj.err = 0;
            obj.files = mydir(obj.pathnm);
            GetDataSet(obj);
        end
@@ -63,9 +86,10 @@ classdef DataFilesClass < handle
        % -----------------------------------------------------------------------------------
        function GetDataSet(obj)
            if exist(obj.pathnm, 'dir')~=7
                error(sprintf('Invalid subject folder: ''%s''', obj.pathnm));
                error('Invalid subject folder: ''%s''', obj.pathnm);
            end
            obj.findDataSet(obj.type);
            obj.ErrorCheckName();
        end

        
@@ -117,6 +141,7 @@ classdef DataFilesClass < handle
        end
        
        
        
        % ----------------------------------------------------
        function getDataFile(obj, filename)
            obj.files = mydir(filename);
@@ -124,8 +149,80 @@ classdef DataFilesClass < handle
        
        
        
        % ----------------------------------------------------
        function ErrorCheckName(obj)
            for ii = length(obj.files):-1:1
                if obj.files(ii).ErrorCheckName()<0
                    q = obj.AskToFixNameConflicts(ii);                    
                    if q == 1
                        obj.files(ii).FixNameConflict();
                    else
                        obj.files(ii).NameConflictFixed();
                    end
                end
                if obj.files(ii).GetError()<0
                    obj.err = -1;
                end
            end
        end
        
        
        
        % --------------------------------------------------------------------------
        function answer = AskToFixNameConflicts(obj, ii)
            answer = 0;
            if obj.config.AskToFixNameConflicts == 0
                obj.files(ii).NameConflictFixed();
                return
            end
            q = MenuBox(obj.GetErrorMsg(ii), {'YES','NO'},[],[],'askEveryTimeOptions');
            if q(1) == 0
                return;
            end
            if length(q)>1 && q(2) == 1
                cfg = ConfigFileClass();
                cfg.SetValue('Fix File Name Conflicts', sprintf('don''t ask again'));
                cfg.Save()
                obj.config.AskToFixNameConflicts = 0;
            end
            if q(1)==2
                obj.files(ii).NameConflictFixed();
            end
            answer = q(1);
        end
        
        
        
        % -----------------------------------------------------
        function errmsg = GetErrorMsg(obj, ii)
            p1      = fileparts(obj.files(ii).GetName());
            [p2,f2] = fileparts(filesepStandard(obj.files(ii).pathfull,'nameonly:file'));
            [~,f3]  = fileparts(p2);
            if isfile_private(obj.files(ii).GetName())
                filetype = 'file';
            else
                filetype = 'folder';
            end
            containingFolder = '';
            if obj.files(ii).GetError() == -1
                containingFolder = p1;
            end
            if obj.files(ii).GetError() == -2
                containingFolder = f2;
            end
            if obj.files(ii).GetError() == -3
                containingFolder = f3;
            end
            msg{1} = sprintf('WARNING: The current %s (%s) has the same name as the folder (%s) containing it. ', filetype, obj.files(ii).GetName(), containingFolder);
            msg{2} = sprintf('All %ss should have a different name than the folder containing them, otherwise ', ['F',filetype(2:end)]);
            msg{3} = sprintf('it may cause incorrect results in processing. Do you want to rename this %s?', filetype);
            errmsg = [msg{:}];            
        end
        

        
        % -------------------------------------------------------
        function pushbuttonLoadDataset_Callback(obj, hObject)
        function pushbuttonLoadDataset_Callback(~, hObject)
            hp = get(hObject,'parent');
            hc = get(hp,'children');
            for ii=1:length(hc)
@@ -172,10 +269,19 @@ classdef DataFilesClass < handle
                    if strcmp(filesepStandard([ps,'/',fs], 'nameonly'), filesepStandard([pd,'/',fd], 'nameonly'))
                        found(ii) = 1;
                        break;
                    else
                        dbgpt = 1;
                    end
                end
            end
        end
        
        
        
        % ----------------------------------------------------------
        function err = GetError(obj)
            err = obj.err;
        end
        
    end
end
+110 −3
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ classdef FileClass < matlab.mixin.Copyable
        datenum

        % FileClass specific properties
        namePrev
        idx
        subjdir
        subjdiridx
@@ -19,11 +20,13 @@ classdef FileClass < matlab.mixin.Copyable
        map2group
        pathfull
        err
        logger
    end
    
    methods

        function obj = FileClass(varargin)
            global logger
            
            obj.name       = '';
            obj.date       = '';
@@ -31,6 +34,7 @@ classdef FileClass < matlab.mixin.Copyable
            obj.isdir      = 0;
            obj.datenum    = 0;
            
            obj.namePrev   = '';
            obj.idx        = 0;
            obj.subjdir    = '';
            obj.subjdiridx = 0;
@@ -38,6 +42,7 @@ classdef FileClass < matlab.mixin.Copyable
            obj.map2group  = struct('iSubj',0,'iRun',0);
            obj.pathfull   = '';
            obj.err        = -1;          % Assume file is not loadable
            obj.logger     = InitLogger(logger);            
            
            if nargin==0
                return;
@@ -87,7 +92,7 @@ classdef FileClass < matlab.mixin.Copyable
        
        
        % -----------------------------------------------------------
        function file_struct = Dirname2Struct(obj, dirnameFull)
        function file_struct = Dirname2Struct(~, dirnameFull)
            file_struct = [];
            [~, dirname] = fileparts(dirnameFull);
            dirs = dir([dirnameFull, '/..']);
@@ -211,6 +216,108 @@ classdef FileClass < matlab.mixin.Copyable
        end

        
        % ----------------------------------------------------
        function err = ErrorCheckName(obj)
            a = obj.name;
            [p1,f1] = fileparts(obj.name);
            [p2,f2] = fileparts(filesepStandard(obj.pathfull,'nameonly:file'));
            [~,f3]  = fileparts(p2);
            if strcmp(f1, p1)
                obj.err = -1;
            end
            if strcmp(f1, f2)
                obj.err = -2;
            end
            if strcmp(f1, f3)
                obj.err = -3;
            end
            err = obj.err;
        end
        
        
                
        % ----------------------------------------------------
        function FixNameConflict(obj)
            if obj.err == 0
                return
            end
            keeptrying = true;
            while keeptrying
                [p,f,e] = fileparts(obj.name);
                suggestedRenaming = obj.SuggestRenaming(f,e);
                [rootpath, newname] = SaveFileGUI(suggestedRenaming, p, '', 'rename');
                newnameFull = [rootpath, newname];
                if isempty(newnameFull)
                    % Means user chnaged mind and canceled. So we call it fixed
                    obj.NameConflictFixed()
                    return;
                end
                if strcmp(newname, [f,e])
                    q = MenuBox('ERROR: The file name has not been renamed. Do you want to try again?', {'YES','NO'});
                    if q==1
                        continue;
                    else
                        return;
                    end
                end
                if pathscompare(obj.name, newnameFull)
                    return;
                end
                if ~isempty(e)
                    d = dir([filesepStandard(p),f,'.*']);
                    [p2,f2] = fileparts(newnameFull);
                    for ii = 1:length(d)
                        [~,~,e1] = fileparts(d(ii).name);
                        obj.logger.Write(sprintf('FileClass: Renaming  %s to %s\n', [filesepStandard(p),f,e1], [filesepStandard(p2),f2,e1]));
                        movefile([filesepStandard(p),f,e1], [filesepStandard(p2),f2,e1]);
                    end
                else
                    obj.logger.Write(sprintf('FileClass: Renaming  %s to %s\n', obj.name, newnameFull));
                    movefile(obj.name, newnameFull);
                end
                obj.namePrev = obj.name;
                obj.name = [filesepStandard(p), newname];
                keeptrying = false;
            end
        end
        
        
        
        % -----------------------------------------------------------------
        function name = SuggestRenaming(~, fname, ext)
            n = 1;
            base = fname;
            if isempty(ext)
                addon = 's';
            else
                addon = 'r';
            end
            name = sprintf('%s_%s%d%s', base, addon, n, ext);
            while ispathvalid(name)
                n = n+1;
                name = sprintf('%s_%s%d%s', base, addon, n, ext);
            end
        end
        
        
        % -----------------------------------------------------
        function NameConflictFixed(obj)
            obj.err = 0;
        end
        
        
        % -----------------------------------------------------
        function name = GetName(obj)
            name = obj.name;
        end
        
        
        % -----------------------------------------------------
        function err = GetError(obj)
            err = obj.err;
        end
        
        
    end
       
end
 No newline at end of file
+16 −12
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ while files.isempty()
    switch fmt
        case {'snirf','.snirf'}
            files = DataFilesClass(dirnameGroup, 'snirf');
            filesSrc = DataFilesClass(dirnameGroup, 'nirs');           
            filesSrc = DataFilesClass(dirnameGroup, 'nirs', '', false);           
            if ~filesSrc.isempty()
                nfolders = length(filesSrc.files)-filesSrc.nfiles;
                if nfolders==0
@@ -125,6 +125,10 @@ while files.isempty()
                    files = DataFilesClass();
                    return;
                end
                
                % Change current folder to new group
                cd(dirnameGroup)
                
            case {'snirfonly'}
                files = [];
        end
+7 −1
Original line number Diff line number Diff line
@@ -231,7 +231,13 @@ classdef DataClass < FileLoadSaveClass
                if obj.measurementList(ii).GetCondition()>1
                    break;
                end
                % Deal with the cases where the measurementList contains
                % wavelengthIndex versus not
                if ~isempty(obj.measurementList(ii).GetWavelengthIndex())
                    ml(ii,:) = [obj.measurementList(ii).GetSourceIndex(), obj.measurementList(ii).GetDetectorIndex(), 1, obj.measurementList(ii).GetWavelengthIndex()];
                else 
                    ml(ii,:) = [obj.measurementList(ii).GetSourceIndex(), obj.measurementList(ii).GetDetectorIndex(), 1, 1];
                end
            end
            
            % Remove unused rows that were pre-allocated
Loading