Commit 0ca282ac authored by jayd1860's avatar jayd1860
Browse files

v1.35.2

-- Fix not finding .snirf files in Rob Luke's dataset   https://github.com/rob-luke/BIDS-NIRS-Tapping  because the file name pattern does not match any of the available options in DataFilesClass. Updated list of BIDS file name patterns to earch for.
-- Fix some bugs in DataFilesClass file search (change name of isempty method to IsEmpty so that there's no overriding of matlab's built in isempty: this caused DataFilesClass object to be mysteriously empty when executing constructor, also AddParentDirs method assigning incorrect name to FileClass member objects)
parent 758aa4fa
Loading
Loading
Loading
Loading
+39 −9
Original line number Diff line number Diff line
@@ -162,7 +162,26 @@ classdef DataFilesClass < handle
                ['nirs/sub-*_run-*_nirs.', obj.filetype];
                }
                
                %%%% 6. BIDS-like folder structure without file naming restrictions
                %%%% 6. BIDS #3
                {
                'sub-*';
                ['nirs/sub-*_*_nirs.', obj.filetype];
                }
                
                %%%% 7. BIDS #4 
                {
                '*';
                ['nirs/sub-*_*_nirs.', obj.filetype];
                }
                
                %%%% 8. BIDS folder structure
                {
                'sub-*';
                'ses-*';
                ['nirs/sub-*_run-*_nirs.', obj.filetype];
                }
                                
                %%%% 9. BIDS-like folder structure without file naming restrictions
                {
                'sub-*';
                'ses-*';
@@ -224,10 +243,9 @@ classdef DataFilesClass < handle

        
        % ----------------------------------------------------
        function AddParentDirs(obj, dir)
            pathrel = getPathRelative([dir.rootdir, dir.name], obj.rootdir);
        function AddParentDirs(obj, dirname)
            pathrel = getPathRelative([dirname.rootdir, dirname.name], obj.rootdir);
            subdirs = str2cell_fast(pathrel, {'/','\'});
            notUnique = false;
            N = length(subdirs);
            for ii = 1:N-1
                if strcmp(subdirs{ii}, 'nirs')
@@ -237,7 +255,7 @@ classdef DataFilesClass < handle
                if obj.SearchLookupTable(pathrel2)
                    continue;
                end
                obj.files(end+1) = FileClass(pathrel2);
                obj.files(end+1) = FileClass([obj.rootdir, '/', pathrel2]);
                obj.AddLookupTable(obj.files(end).name)
            end
        end
@@ -305,7 +323,7 @@ classdef DataFilesClass < handle
            [p2,f2] = fileparts(filesepStandard(obj.files(ii).rootdir,'nameonly:file'));
            [~,f3]  = fileparts(p2);
            if isfile_private(obj.files(ii).GetName())
                filetype = 'file';
                filetype = 'file'; %#ok<*PROPLC>
            else
                filetype = 'folder';
            end
@@ -351,7 +369,7 @@ classdef DataFilesClass < handle
            
        
        % ----------------------------------------------------------
        function b = isempty(obj)
        function b = IsEmpty(obj)
            if isempty(obj.files)
                b = true;
            else
@@ -441,11 +459,23 @@ classdef DataFilesClass < handle
            obj.logger.Write('DataTreeClass - Data Set Folder Structure:\n');
            for ii = 1:length(obj.files)
                k = length(find(obj.files(ii).name=='/'));   
                if ii<10, j=3; elseif ii>9 && ii<100, j=2; else j=3; end
                if ii<10
                    j=3; 
                elseif ii>9 && ii<100
                    j=2;
                else
                    j=3;
                end
                if optionExists(options, 'flat')
                    obj.logger.Write(sprintf('%d.%s%s\n', ii, blanks(j), obj.files(ii).name));
                else
                    if ii<10, j=3; elseif ii>9 && ii<100, j=2; else j=3; end
                    if ii<10
                        j=3; 
                    elseif ii>9 && ii<100
                        j=2; 
                    else 
                        j=3; 
                    end
                    if optionExists(options, 'numbered')
                        n = k*stepsize+stepsize+j;
                        obj.logger.Write(sprintf('%d.%s%s\n', ii, blanks(n), obj.files(ii).filename));
+2 −2
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ classdef FileClass < matlab.mixin.Copyable
            
            % Consolidate second to last 'nirs' part with last part   
            if strcmp(parts{end-1}, 'nirs')
                parts{end} = [parts{end-1}, parts{end}];
                parts{end} = [parts{end-1}, '/', parts{end}];
                parts(end-1) = [];
            end
        end
@@ -258,7 +258,7 @@ classdef FileClass < matlab.mixin.Copyable
                subjName = obj.name;
            elseif obj.IsFile && length(parts)==2
                subjName = parts{1};
                sessName = [subjName '/ses-',parts{end}];
                sessName = [subjName, '/ses-', fname];
                runName  = obj.name;
            end
            
+6 −6
Original line number Diff line number Diff line
@@ -58,12 +58,12 @@ end
% Check files data set for errors. If there are no valid
% nirs files don't attempt to load them.
files = DataFilesClass();
while files.isempty()
while files.IsEmpty()
    switch fmt
        case {'snirf','.snirf'}
            files = DataFilesClass(dirnameGroup, 'snirf');
            filesSrc = DataFilesClass(dirnameGroup, 'nirs', '', false);
            if ~filesSrc.isempty()
            if ~filesSrc.IsEmpty()
                nfolders = length(filesSrc.files)-filesSrc.nfiles;
                if nfolders==0
                    nfolders = 1;
@@ -77,7 +77,7 @@ while files.isempty()
            if ~all(found)
                q = GetOptionsForIncompleteDataSet(files, filesSrc);
                if q==2
                    if files.isempty()
                    if files.IsEmpty()
                        files = [];
                    end
                    return;
@@ -87,7 +87,7 @@ while files.isempty()
            end
        case {'snirfonly'}
            files = DataFilesClass(dirnameGroup, 'snirf');
            if files.isempty()
            if files.IsEmpty()
                files = [];
                return;
            end
@@ -112,7 +112,7 @@ while files.isempty()
    
    % If no files were found ion the current format then ask user to choose
    % another group folder
    if files.isempty()
    if files.IsEmpty()
        if strcmp(fmt, 'snirfonly')
            files = [];
            return
@@ -144,7 +144,7 @@ end
function  q = GetOptionsForIncompleteDataSet(files, filesSrc)
if files.config.RegressionTestActive
    q = 1;
elseif  files.isempty()
elseif  files.IsEmpty()
    msg{1} = sprintf('Homer3 did not find any .snirf files in the current folder but did find %d .nirs files. ', filesSrc.nfiles);
    msg{2} = sprintf('Do you want to convert .nirs files to .snirf format and load them?');
    q = MenuBox(msg, {'YES','NO'}, 'center');
+2 −2
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ classdef DataTreeClass < handle
            end
            if ~isempty(k)
                dataInit = FindFiles(obj.dirnameGroups{kk}, supportedFormats{k});
                if isempty(dataInit) || dataInit.isempty()
                if isempty(dataInit) || dataInit.IsEmpty()
                    return;
                end
            else
@@ -253,7 +253,7 @@ classdef DataTreeClass < handle
                    iter = 1;
                    while dataInit.GetError() < 0
                        dataInit = FindFiles(obj.dirnameGroups{kk}, fmt, options);
                        if isempty(dataInit) || dataInit.isempty()
                        if isempty(dataInit) || dataInit.IsEmpty()
                            return;
                        end
                        dataInitPrev(iter) = dataInit;
+1 −1
Original line number Diff line number Diff line
@@ -307,7 +307,7 @@ classdef GroupClass < TreeNodeClass
                subj.SetIndexID(obj.iGroup, jj);
                subj.SetPath(obj.path);                      % Inherit root path from group
                obj.subjs(jj) = subj;
                obj.logger.Write(sprintf('   Added subject %s to group %s.\n', obj.subjs(jj).GetName, obj.GetName));
                obj.logger.Write('   Added subject %s to group %s.\n', obj.subjs(jj).GetFileName, obj.GetFileName);
            end
                        
            % Add sess to subj
Loading