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

-- Fix 2 issues with loading Rob Luke's BIDS datasets (#121)

* 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)

* -- Fix some bugs in unit test logging - and displaying call stack in case of error

* v1.35.3

-- Fix Rob Luke's https://github.com/rob-luke/BIDS-NIRS-Tapping dataset not being loaded correctly probe lacks sourcePos2D and detectorPos2D. It has sourcePos3D and detectorPos3D so we project 3D to 2D if the 2D fields are empty. If landmarks are missing then we use crude default 3D-to-2D projection algorithm. If landmarks are available then we use another algorithm that Sreekanth Kura and David Boas are developing

* -- Change syncSubmodules to not use version numbers any more and rely on dates instead
parent 758aa4fa
Loading
Loading
Loading
Loading
+39 −9
Original line number Original line Diff line number Diff line
@@ -162,7 +162,26 @@ classdef DataFilesClass < handle
                ['nirs/sub-*_run-*_nirs.', obj.filetype];
                ['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-*';
                'sub-*';
                'ses-*';
                'ses-*';
@@ -224,10 +243,9 @@ classdef DataFilesClass < handle


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


        
        
        
        
        % -------------------------------------------------------
        function Project_3D_to_2D(obj) 
            if isempty(obj.landmarkPos3D)
                
                % When 3D landmarks aren't available use crude default 3D-to-2D projection algorithm 
                if isempty(obj.sourcePos2D)
                    obj.sourcePos2D = project_3D_to_2D(obj.sourcePos3D);
                end
                if isempty(obj.detectorPos2D)
                    obj.detectorPos2D = project_3D_to_2D(obj.detectorPos3D);
                end
                
            else

                % 3D landmarks are available, use ...

            end
        end

        
        
        % -------------------------------------------------------
        % -------------------------------------------------------
        function err = LoadHdf5(obj, fileobj, location)
        function err = LoadHdf5(obj, fileobj, location)
            err = 0;
            err = 0;
@@ -174,6 +195,8 @@ classdef ProbeClass < FileLoadSaveClass
                obj.detectorLabels            = HDF5_DatasetLoad(gid, 'detectorLabels', obj.detectorLabels);
                obj.detectorLabels            = HDF5_DatasetLoad(gid, 'detectorLabels', obj.detectorLabels);
                obj.landmarkLabels            = HDF5_DatasetLoad(gid, 'landmarkLabels', obj.landmarkLabels);
                obj.landmarkLabels            = HDF5_DatasetLoad(gid, 'landmarkLabels', obj.landmarkLabels);
                
                
                obj.Project_3D_to_2D();
                
                % Close group
                % Close group
                HDF5_GroupClose(fileobj, gid, fid);
                HDF5_GroupClose(fileobj, gid, fid);
                
                
+2 −2
Original line number Original line Diff line number Diff line
@@ -174,7 +174,7 @@ classdef DataTreeClass < handle
            end
            end
            if ~isempty(k)
            if ~isempty(k)
                dataInit = FindFiles(obj.dirnameGroups{kk}, supportedFormats{k});
                dataInit = FindFiles(obj.dirnameGroups{kk}, supportedFormats{k});
                if isempty(dataInit) || dataInit.isempty()
                if isempty(dataInit) || dataInit.IsEmpty()
                    return;
                    return;
                end
                end
            else
            else
@@ -253,7 +253,7 @@ classdef DataTreeClass < handle
                    iter = 1;
                    iter = 1;
                    while dataInit.GetError() < 0
                    while dataInit.GetError() < 0
                        dataInit = FindFiles(obj.dirnameGroups{kk}, fmt, options);
                        dataInit = FindFiles(obj.dirnameGroups{kk}, fmt, options);
                        if isempty(dataInit) || dataInit.isempty()
                        if isempty(dataInit) || dataInit.IsEmpty()
                            return;
                            return;
                        end
                        end
                        dataInitPrev(iter) = dataInit;
                        dataInitPrev(iter) = dataInit;
Loading