Commit 1d6bed1e authored by Jay Dubb's avatar Jay Dubb
Browse files

1.28.7

-- Fix Homer3 not detecting and not offering to convert all .nirs files if even one .snirf exists in a group folder. It should offer to convert to .snirf whichever .nirs files have not been converted to .snirf.
-- Add some improvements to the debug messages in Nirs2Snirf and related functions used to convert .nirs to .snirf
-- Replace convertToStandardPath with filesepStandard for uniformity everywhere possible. Didn't do it everywhere because convertToStandardPath behaves slightly differently in the case of relative path it converts to absolute path whereas filesepStandard does not. So in cases where there might be a relative path which is necessesary I didn't replace with filesepStandard.
parent 4c4a1dec
Loading
Loading
Loading
Loading
+32 −7
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ classdef DataFilesClass < handle
        errmsg;
        pathnm;
        config;
        
        nfiles;
    end
    
    methods
@@ -17,6 +17,7 @@ classdef DataFilesClass < handle
            obj.type = '';
            obj.pathnm = pwd;
            skipconfigfile = false;
            obj.nfiles = 0;
            
            if nargin>0
                obj.pathnm = varargin{1};
@@ -72,9 +73,8 @@ classdef DataFilesClass < handle
        function findDataSet(obj, type)
            obj.files = mydir([obj.pathnm, '/*.', type]);
            if isempty( obj.files )                
                
                % If there are no .nirs files in current dir, don't give up yet - check
                % the subdirs for .nirs files.
                % If there are no data files in current dir, don't give up yet - check
                % the subdirs for data files.
                dirs = mydir(obj.pathnm);
                for ii=1:length(dirs)
                    if dirs(ii).isdir && ...
@@ -93,9 +93,12 @@ classdef DataFilesClass < handle
                                foos(jj).name         = [dirs(ii).name, '/', foos(jj).name];
                                foos(jj).map2group    = struct('iGroup',0, 'iSubj',0, 'iRun',0);
                                foos(jj).pathfull     = dirs(ii).pathfull;
                                if ~foos(jj).isdir
                                    obj.nfiles = obj.nfiles+1;
                                end
                            end
                            
                            % Add .nirs file from current subdir to files struct
                            % Add file from current subdir to files struct
                            if isempty(obj.files)
                                obj.files = dirs(ii);
                            else
@@ -109,6 +112,7 @@ classdef DataFilesClass < handle
                for ii = 1:length(obj.files)
                    obj.files(ii).pathfull = obj.pathnm;
                end
                obj.nfiles = obj.nfiles+length(obj.files);
            end
        end
        
@@ -152,5 +156,26 @@ classdef DataFilesClass < handle
            end
        end
       
        
                
        % ----------------------------------------------------------
        function found = ConvertedFrom(obj, src)
            found = zeros(length(src.files), 1);
            for ii = 1:length(src.files)
                if src.files(ii).isdir
                    found(ii) = -1;
                    continue;
                end
                [ps, fs] = fileparts(src.files(ii).name);
                for jj = 1:length(obj.files)
                    [pd, fd] = fileparts(obj.files(jj).name);
                    if strcmp(filesepStandard([ps,'/',fs], 'nameonly'), filesepStandard([pd,'/',fd], 'nameonly'))
                        found(ii) = 1;
                        break;
                    end
                end
            end
        end
        
    end
end
+45 −14
Original line number Diff line number Diff line
function [files, dirnameGroup] = FindFiles(varargin)
function files = FindFiles(varargin)

% Syntax:
%
@@ -62,22 +62,27 @@ while files.isempty()
    switch fmt
        case {'snirf','.snirf'}
            files = DataFilesClass(dirnameGroup, 'snirf');
            if files.isempty()
                files = DataFilesClass(dirnameGroup, 'nirs');
                if ~files.isempty()
                    if files.config.RegressionTestActive
                        q = 1;
                    else                        
                        msg{1} = sprintf('Homer3 did not find any .snirf files in the current folder but did find .nirs files. ');
                        msg{2} = sprintf('Do you want to convert .nirs files to .snirf format and load them?');
                        q = MenuBox([msg{:}], {'YES','NO'}, 'center');
            filesSrc = DataFilesClass(dirnameGroup, 'nirs');           
            if ~filesSrc.isempty()
                nfolders = length(filesSrc.files)-filesSrc.nfiles;
                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
            % been converted to .snirf. 
            found = files.ConvertedFrom(filesSrc);
            if ~all(found)
                q = GetOptionsForIncompleteDataSet(files, filesSrc);
                if q==2
                    if files.isempty()
                        files = [];
                        return;
                    end
                    return;
                end
                Nirs2Snirf(dirnameGroup);
                Nirs2Snirf(dirnameGroup, filesSrc.files(~found));
                files = DataFilesClass(dirnameGroup, 'snirf');
            end
        case {'snirfonly'}
@@ -127,3 +132,29 @@ while files.isempty()
end



% ----------------------------------------------------------------------------
function  q = GetOptionsForIncompleteDataSet(files, filesSrc)
if files.config.RegressionTestActive
    q = 1;
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');
else
    if files.nfiles>1
        s = 'have';
    else
        s = 'has';
    end
    if filesSrc.nfiles-files.nfiles>1
        msg{1} = sprintf('Homer3 found %d .nirs files which have not been converted to .snirf format and %d that %s. ', filesSrc.nfiles-files.nfiles, files.nfiles, s);
        msg{2} = sprintf('Do you want to convert the remaining %d .nirs files to .snirf format?', filesSrc.nfiles-files.nfiles);
    else
        msg{1} = sprintf('Homer3 found %d .nirs file which has not been converted to .snirf format and %d that %s. ', filesSrc.nfiles-files.nfiles, files.nfiles, s);
        msg{2} = sprintf('Do you want to convert the remaining .nirs file to .snirf format?');
    end
    q = MenuBox([msg{:}], {'YES','NO'}, 'center');
end

+15 −7
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ DEBUG=false;
snirf = SnirfClass().empty();

if ~exist('dirname','var') || isempty(dirname)
    dirname = convertToStandardPath(pwd);
    dirname = filesepStandard(pwd);
end
if ~exist('nirsfiles0','var') || isempty(nirsfiles0)
    nirsfiles0 = DataFilesClass(dirname,'nirs').files;
@@ -39,16 +39,22 @@ elseif isa(nirsfiles0, 'FileClass')
    nirsfiles = nirsfiles0;
end

h = waitbar_improved(0,'Converting .nirs files to .snirf ...');
fprintf('\n');

h = waitbar_improved(0, sprintf('Converting %d .nirs files to .snirf ...', length(nirsfiles)));
for ii=1:length(nirsfiles)
    if nirsfiles(ii).isdir
        continue;
    end
    [pname, fname, ext] = fileparts([nirsfiles(ii).pathfull, '/', nirsfiles(ii).name]);
    fprintf('Converting %s to %s\n', [pname,'/',fname,ext], [pname,'/',fname,'.snirf']);
    
    src = filesepStandard([pname,'/',fname, ext]);
    dst = filesepStandard([pname,'/',fname,'.snirf'], 'nameonly');
    
    fprintf('Converting %s to %s\n', src, dst);
    waitbar_improved(ii/length(nirsfiles), h, sprintf('Converting %s to SNIRF: %d of %d', nirsfiles(ii).name, ii, length(nirsfiles)));

    nirs = load([pname,'/',fname,ext],'-mat');
    nirs = load(src,'-mat');
    
    if DEBUG==false
        snirf(ii) = SnirfClass(nirs);
@@ -56,9 +62,11 @@ for ii=1:length(nirsfiles)
        snirf(ii) = SnirfClass(nirs, ntimebases);
    end
    
    snirf(ii).Save([pname,'/',fname,'.snirf']);
    snirf(ii).Save(dst);
    if replace
        delete([pname,'/',fname,ext]);
        delete(src);
    end
end
close(h);

fprintf('\n');
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ for ii=1:length(nirsfiles)
    
    % Convert sample .nirs file to SNIRF file (*.snirf) 
    [pname,fname,ext] = fileparts([examplesDir, nirsfiles(ii).name]);
    pname = convertToStandardPath(pname);
    pname = filesepStandard(pname);
    fprintf('Converting %s to %s\n', [pname, fname, ext], [pname, fname, '.snirf']);
    [snirf_saved, snirf_loaded] = snirf_load_save([pname, nirsfiles(ii).name]);
    
+1 −1
Original line number Diff line number Diff line
function rootdirexamples = findexamplesdir()

rootdir = fileparts(which('SnirfClass.m'));
rootdirexamples = convertToStandardPath([rootdir, '/Examples/']);
rootdirexamples = filesepStandard([rootdir, '/Examples/']);
Loading