Commit 10d483b2 authored by sreekanthkura7's avatar sreekanthkura7
Browse files

merge development branch into SK branch

parents ebf6f8b5 831979f2
Loading
Loading
Loading
Loading
+69 −9
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ classdef DataFilesClass < handle
    
    properties
        files;
        filesErr;
        filetype;
        dirFormats;
        err;
@@ -21,6 +22,7 @@ classdef DataFilesClass < handle
        % ----------------------------------------------------
        function obj = DataFilesClass(varargin)            
            obj.files = FileClass.empty();
            obj.filesErr = FileClass.empty();
            obj.filetype = '';
            obj.rootdir = pwd;
            obj.nfiles = 0;
@@ -116,15 +118,15 @@ classdef DataFilesClass < handle
                obj.InitLookupTable();
                obj.FindDataSet(ii);
                
                % Remove any files that cannot pass the basic test of loading
                % its data
                obj.ErrorCheck();
                if ~isempty(obj.files)
                    break
                end
            end
            
            % Remove any files that cannot pass the basic test of loading
            % its data
            obj.ErrorCheckName();
            obj.ErrorCheckFinal();
        end

        
@@ -188,6 +190,13 @@ classdef DataFilesClass < handle
                ['nirs/*.', obj.filetype];
                }
                                
                %%%% 10. BIDS-like folder structure without nirs sub-folder
                {
                'sub-*';
                'ses-*';
                ['*.', obj.filetype];
                }
                                
                };
        end
        
@@ -215,10 +224,13 @@ classdef DataFilesClass < handle
            parentdir = filesepStandard(parentdir);
            pattern = obj.dirFormats.choices{iFormat}{iPattern};
            
            dirs = mydir([parentdir, pattern]);
            dirs = mydir([parentdir, pattern], obj.rootdir);
            
            dirnamePrev = '';
            for ii = 1:length(dirs)
                if dirs(ii).IsEmpty()
                    continue;
                end
                if dirs(ii).IsFile()
                    if strcmp(pattern, '*')
                        continue
@@ -255,7 +267,7 @@ classdef DataFilesClass < handle
                if obj.SearchLookupTable(pathrel2)
                    continue;
                end
                obj.files(end+1) = FileClass([obj.rootdir, '/', pathrel2]);
                obj.files(end+1) = FileClass([obj.rootdir, '/', pathrel2], obj.rootdir);
                obj.AddLookupTable(obj.files(end).name)
            end
        end
@@ -290,6 +302,41 @@ classdef DataFilesClass < handle
        
        
        
        % ----------------------------------------------------
        function ErrorCheckFinal(obj)
            obj.ErrorCheckName();
            
            % Find all acquisition files in group folder
            fileNames = findTypeFiles(obj.rootdir, ['.', obj.filetype]);
            
            % Make alist of all files excluded from current data set  
            for ii = 1:length(fileNames)
                filefound = false;
                
                for jj = 1:length(obj.files)
                    if pathscompare(fileNames{ii}, [obj.rootdir, obj.files(jj).name])
                        filefound = true;
                        break;
                    end
                end
                
                for jj = 1:length(obj.filesErr)
                    if pathscompare(fileNames{ii}, [obj.rootdir, obj.filesErr(jj).name])
                        filefound = true;
                        break;
                    end
                end
                
                if ~filefound
                    obj.filesErr(end+1) = FileClass(fileNames{ii});
                    obj.filesErr(end).SetError('Invalid File Name');
                end
            end
        
        end
        
        
        
        % --------------------------------------------------------------------------
        function answer = AskToFixNameConflicts(obj, ii)
            global cfg
@@ -418,6 +465,8 @@ classdef DataFilesClass < handle
            end
            
            % Try to create object of data filetype and load data into it
            msg = 'Please wait while we check group folder for valid data files ...';
            hwait = waitbar_improved(0, msg);
            dataflag = false;
            for ii = 1:length(obj.files)
                if obj.files(ii).isdir
@@ -426,17 +475,27 @@ classdef DataFilesClass < handle
                filename = [obj.files(ii).rootdir, obj.files(ii).name];
                eval( sprintf('o = %s(filename);', constructor) );
                if  o.GetError() < 0
                    obj.logger.Write('FAILED error check:   %s will not be added to data set\n', filename);
                    obj.logger.Write('DataFilesClass.ErrorCheck:   FAILED error check - %s will not be added to data set\n', filename);
                    errorIdxs = [errorIdxs, ii]; %#ok<AGROW>
                elseif  contains(o.GetErrorMsg(), 'WARNING: ''data'' corrupt and unusable')                    
                    obj.logger.Write('DataFilesClass.ErrorCheck:   WARNING data is unusable - %s will not be added to data set\n', filename);
                    errorIdxs = [errorIdxs, ii]; %#ok<AGROW>
                else
                    dataflag = true;
                end
                hwait = waitbar_improved(ii/length(obj.files), hwait, msg);
            end
            if dataflag==false
                obj.files = FileClass.empty();
            else
                for jj = 1:length(errorIdxs)
                    obj.filesErr(end+1) = obj.files(errorIdxs(jj)).copy;
                    obj.filesErr(end).SetError('Invalid Data Format');
                end
            	obj.files(errorIdxs) = [];
                obj.nfiles = obj.nfiles - length(errorIdxs);
            end
            close(hwait);
        end
        
        
@@ -518,5 +577,6 @@ classdef DataFilesClass < handle
            b = obj.lookupTable(string2hash(str, n));
        end
        
        
    end
end
+560 −539
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ classdef FileClass < matlab.mixin.Copyable
        rootdir
        err
        logger
        errmsgs
    end
    
    methods
@@ -39,6 +40,8 @@ classdef FileClass < matlab.mixin.Copyable
            obj.rootdir    = '';
            obj.err        = -1;          % Assume file is not loadable
            obj.logger     = InitLogger(logger);            
            obj.errmsgs    = {'Invalid Data Format','Invalid File Name'};
            
            
            if nargin==0
                return;
@@ -59,7 +62,7 @@ classdef FileClass < matlab.mixin.Copyable
            else
                file.rootdir = pwd;
            end
            file.rootdir = filesepStandard(file.rootdir);            
            file.rootdir = filesepStandard(file.rootdir, 'full');            
            
            obj.Add(file);
        end
@@ -75,15 +78,15 @@ classdef FileClass < matlab.mixin.Copyable
            end
            
            if isproperty(obj2, 'folder')
                rootdir = [filesepStandard(obj2.folder), obj2.name]; %#ok<*PROPLC>
                rootpath = [filesepStandard(obj2.folder), obj2.name]; %#ok<*PROPLC>
            else
                rootdir = [filesepStandard(obj2.rootdir), obj2.name];                
                rootpath = [filesepStandard(obj2.rootdir), obj2.name];                
            end
            
            obj.idx          = obj.idx+1;
            obj.isdir        = obj2.isdir;
            obj.filename     = obj2.name;
            obj.name         = getPathRelative(rootdir, obj2.rootdir);
            obj.name         = getPathRelative(rootpath, obj2.rootdir);
            obj.rootdir 	 = obj2.rootdir;
            obj.err          = 0;          % Set error to NO ERROR            
        end
@@ -116,7 +119,11 @@ classdef FileClass < matlab.mixin.Copyable
                end
                dirname(k) = '*';
            end
            file = dir(dirname);
            temp = dir(dirname);
            if isempty(temp)
                return;
            end
            file = temp(1);
        end
        
        
@@ -191,8 +198,8 @@ classdef FileClass < matlab.mixin.Copyable
            %       R2.ext          ==>  [G1,  sub_R2,  ses_sub_R2,  R2]
            %       R3.ext          ==>  [G1,  sub_R3,  ses_sub_R3,  R3]
            if obj.IsFile && length(parts)==1 && length(subparts)==1
                subjName = ['sub_', fname];
                sessName = ['ses_', subjName];
                subjName = ['sub-', fname];
                sessName = ['ses-', subjName];
                runName  = obj.name;
            end

@@ -209,7 +216,7 @@ classdef FileClass < matlab.mixin.Copyable
            %       S3_R3.ext       ==>  [G1,  S2,  ses_S2_R3,  R3]
            if obj.IsFile && length(parts)==1 && length(subparts)==2
                subjName = subparts{1};
                sessName = ['ses_', subjName, '_', fname];
                sessName = ['ses-', subjName, '_', subjName];
                runName  = obj.name;
            end
            
@@ -258,7 +265,7 @@ classdef FileClass < matlab.mixin.Copyable
                subjName = obj.name;
            elseif obj.IsFile && length(parts)==2
                subjName = parts{1};
                sessName = [subjName, '/ses-', fname];
                sessName = [subjName, '/ses-', subjName];
                runName  = obj.name;
            end
            
@@ -535,6 +542,20 @@ classdef FileClass < matlab.mixin.Copyable
        end
        
        
        % -----------------------------------------------------
        function err = SetError(obj, err)
            if ischar(err)
                err = find(strcmp(obj.errmsgs, err));
            end
            obj.err = err;
        end
        
        
        % -----------------------------------------------------
        function msg = GetErrorMsg(obj)
            msg = obj.errmsgs{abs(obj.err)};
        end
        
    end
  
end
 No newline at end of file
+0 −3
Original line number Diff line number Diff line
@@ -68,7 +68,6 @@ while files.IsEmpty()
                if nfolders==0
                    nfolders = 1;
                end
                fprintf('FindFiles: Found %d .nirs data files in %d folders\n', filesSrc.nfiles, nfolders);
            end
            
            % Search for source acquisition files in .nirs format which have not
@@ -134,8 +133,6 @@ while files.IsEmpty()
        cd(dirnameGroup)
    end
    
    fprintf('FindFiles: Found %d %s data files in %d folders\n', files.nfiles, fmt, length(files.files)-files.nfiles);
    
end


+1 −0
Original line number Diff line number Diff line
@@ -18,3 +18,4 @@ elseif iscolumn(val) && ischar(val)
    val = permute(val, ndims(val):-1:1);
    
end
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ if ~exist('pathname','var') || isempty(pathname)
    pathname = pwd;
end
if ~exist('pathroot','var') || isempty(pathroot)
    pathroot = pwd;
    pathroot = fileparts(pathname);
end

if ispathvalid(pathname, 'dir') && ~includes(pathname, '*')
Loading