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

Merge in removal of submodule references and replacement with copies of the...


Merge in removal of submodule references and replacement with copies of the DataTree and Utils libraries. Submodules too difficult to work with and bad git support (#107) (#109)

* v1.32.4

-- Fix some bugs in path utils functions
-- More improvements in build/installation process

* Update probe class to save and load 3D landmarks

* Update probe class to work with old SD files

* v1.32.4

-- Copy versoin number for Homer3 from AV

* -- Fix small bug in setpaths(0) paths removal

* CCA shrinkage back on

* Update hmrR_PreprocessIntensity_Negative.m

quick fix on negative value check

* v1.32.5

-- Fix issue with tCCA user functions not being loaded into function registry
-- Set data tree structure display in MainGUI to include the group name display unconditionally. In some instances the group name did not show if the all subjects had only one run.

* Update hmrR_PreprocessIntensity_Negative.m

Function to include zero values.

* v1.32.5

-- Sync DataTree and Utils with AtlasViewer

* v1.32.7

-- Add more robust error checking to exclude .snirf files that can't load DataClass.m
-- Add better error checking to DataClass and MeasListClass

* Create shared code and submodule references to DataTree and Utils (#74)

* -- Move DataTree and some Utils functions to independent submodules used by AtlasViewer and Homer3

* Add config file to DataTree and ability to load mutiple config files to config utility

Add config file to DataTree and ability to load mutiple config files to config utility

* Relink submodule references from jayd1860 to BUNPC

* Fix submodule download not working on linux when initializing repo with setpaths. Needed to disable git certificate verification when executing 'git submodule update' from matlab

* -- Add tool to setpaths to be able to download submodules without having git installed.

* -- Change code to setpaths not to initialize submodules every toime it is run. Add option to 'update' submodules to get latest changes.

* ISSUE_TEMPLATE folder (#77)

* Fix setpaths issue on MAC where the initialization of submodules causes setpaths to hang waiting for user to press ENTER because the system command running 'git branch' executes in its own shell. Setting the TERM=ansi seems to fix this issue.

* -- Add .gitignore file to simplify and clatrify git status output

* -- In previous commit didn't entirely fix issue with setpaths waiting for user input on MAC. Need to parse and remove garbage output correctly too

* Just use Snirf style GetAux to display aux data (#75)

* -- Set origin of submodules to be same as parent repo to follow paradigm of submodules and parent repo being one code (#78)

-- Fix submodule download in setpaths without git not working because setpaths options are not parsed correctly.
-- Clean up and remove obsolete files

* -- Fix issue in setpaths when attempting to download submodules using the non-git method. Assumtion that Github creates empty folder as placeholders for submodules when downloading using the "Download ZIP" option is not always true. Sometimes it creates empty folder, somtimes it doesn't. So isemptyFolder doesn't work when folder is not created. Added code to create empty submodule folder placeholder when it is missing.

-- Clean up: remove more obsolete files

* -- Fix typo

* -- Fix issue with setpaths submodules when there's a partial submodules download because of a previous error then need to clean uo submodule folders so there's no garbage in there then retry downloading.

* -- Greatly simplify and make it more straighfoward the setpaths process.
-- Add .numberfiles to submodules and check during setpaths process to make sure an incomplete download is detected and triggers a clean download.

* -- Fix setpaths error exception on linux and mac because ls([pathname, '*.m']) works differently on those platform than on Windows when there are NO files matching the specified pattern. Use dir instead of ls to fix this.
-- Fix multiple issues in submodule downloading using non-git method.
-- When user click cancel in response to download fail dialog, quit rather than retry.
-- Add search paths ONLY for the submodules that were successfully installed
-- Fix typos in dialog failed download message

* -- a) Fix setpaths bug in removeFolderContents.m on linux and MAC because the delimiter for path string is ':' not ';' as it is on Winodws. b) On linux the gitSetBranch.m used to get latest branch revis

* Fix setpaths('update') not working.

* -- Fix problems in setpaths with creating new submodule branches

-- Fix issue in setpaths with non-git submodule download and install.
   a) Fix some bugs and typos preventing correct download.
   b) Clean up and delete downloaded submodules files which are no longer needed after installation like the zip file and initial unzipped folder
   c) Clarify input dialog message and try to guess and or suggest the correct branch that matches parent repo

-- Add exception handling to setpaths. in case of error return to original folder

-- Add comprehensive help comments to setpaths describing it's use

* -- Don't add current app twice. Check app include list to see if it already has been added to search paths

* Glm fixes (#80)

- GLM docs fixes

- Convolve HRFs with stim duration before export

* -- In setpaths exclude more folders to avoid problems and headaches with unexpected matlab behavior because of inclusion of weird .m files from a build of AV. So for instance exclude *.app and *_install folders which contain a large amount of files which should never be included in matlab search paths.
-- Add ability to findDotMFolders to exclude folders based on wildcard patterns rather than only explicit names. This allows exclusion of many folders that fit a pattern without having to explicitly list ALL of them
-- Fix several bugs in the build for MAC
-- Finally fixed the requirement that you have to run MAC installation specifically from ~/Downloads/homer3_install. Added code to makesetup.pl to create a more intelligent setup.command which does not depend on execution from a specific folder.

* -- Fix build not working because need to copy ALL config files to installation folder
-- Improve launch performance by changing config file access to global variable

* -- Change setpath submodule download without git, to not ask questions about which branch to download. Instead derive the branch name from root folder name of parent app and default to master of it cannot be determined. This change somehow did not make it earlier into repo

* -- Update submodule references to latest development branch rev

* -- Change unit test to use global config variable rather than opening/closing ConfigFileClass objects
-- Update getVernum to match AV
-- Update submodule references

* DataTree submodule reference update and Mac support fixes (#89)

-- Update DataTree submodule reference to latest change containing fix for errors when there are no data files (because all have errors that prevent loading)

-- Fix more issues with install executable on MAC

* Gets info about latest version from GitHub API rather than openfnirs.org (#92)

* Gets info about latest version from GitHub API rather than openfnirs.org

* Version++

* -- Change setpaths to not download submodules by default. Use 'init' or 'update' options to download automatically. If using github desktop then github desktop download submodules automatically. (#95)

-- Change downloadSharedLibs to change .gitmodules origin url to point to where ever parent came from
-- Add .gitattributes to exclude files from branch merges such as submodule references and .gitmodules
-- Sync getVernum with Homre3. (getVernum will eventually be moved to Utils/Shared library)
-- Improve creation of installation file and installation process using myCopyFile.m

* -- Update submodule reference for development branch to latest
-- Fix .gitmodules to point to development branch instaead of master

* -- Fix setpaths gitSubmodulesUpdate not updating changes to submodules correctly

* -- Fix wrong path to DataTree to exclude from merges
-- Add .gitattributes in list of files to exclude fropm merges

* -- Update submodule references

* -- Update submodule reference to Utils

* Remove submodule references and replace with copies of the DataTree and Utils libraries. Submodules too difficult to work with and bad git support (#107)

* -- Update DataTree reference pointer

* -- Update Utils submodule reference to latest

* Remove submodules: too hard to work with, not enough support from git

* Remove submodules: too hard to work with, not enough support from git

* Merge in change to get rid of submodule references which are more trouble than they are worth (#2)

* v1.32.4

-- Fix some bugs in path utils functions
-- More improvements in build/installation process

* Update probe class to save and load 3D landmarks

* Update probe class to work with old SD files

* v1.32.4

-- Copy versoin number for Homer3 from AV

* -- Fix small bug in setpaths(0) paths removal

* CCA shrinkage back on

* Update hmrR_PreprocessIntensity_Negative.m

quick fix on negative value check

* v1.32.5

-- Fix issue with tCCA user functions not being loaded into function registry
-- Set data tree structure display in MainGUI to include the group name display unconditionally. In some instances the group name did not show if the all subjects had only one run.

* Update hmrR_PreprocessIntensity_Negative.m

Function to include zero values.

* v1.32.5

-- Sync DataTree and Utils with AtlasViewer

* v1.32.7

-- Add more robust error checking to exclude .snirf files that can't load DataClass.m
-- Add better error checking to DataClass and MeasListClass

* Create shared code and submodule references to DataTree and Utils (#74)

* -- Move DataTree and some Utils functions to independent submodules used by AtlasViewer and Homer3

* Add config file to DataTree and ability to load mutiple config files to config utility

Add config file to DataTree and ability to load mutiple config files to config utility

* Relink submodule references from jayd1860 to BUNPC

* Fix submodule download not working on linux when initializing repo with setpaths. Needed to disable git certificate verification when executing 'git submodule update' from matlab

* -- Add tool to setpaths to be able to download submodules without having git installed.

* -- Change code to setpaths not to initialize submodules every toime it is run. Add option to 'update' submodules to get latest changes.

* ISSUE_TEMPLATE folder (#77)

* Fix setpaths issue on MAC where the initialization of submodules causes setpaths to hang waiting for user to press ENTER because the system command running 'git branch' executes in its own shell. Setting the TERM=ansi seems to fix this issue.

* -- Add .gitignore file to simplify and clatrify git status output

* -- In previous commit didn't entirely fix issue with setpaths waiting for user input on MAC. Need to parse and remove garbage output correctly too

* Just use Snirf style GetAux to display aux data (#75)

* -- Set origin of submodules to be same as parent repo to follow paradigm of submodules and parent repo being one code (#78)

-- Fix submodule download in setpaths without git not working because setpaths options are not parsed correctly.
-- Clean up and remove obsolete files

* -- Fix issue in setpaths when attempting to download submodules using the non-git method. Assumtion that Github creates empty folder as placeholders for submodules when downloading using the "Download ZIP" option is not always true. Sometimes it creates empty folder, somtimes it doesn't. So isemptyFolder doesn't work when folder is not created. Added code to create empty submodule folder placeholder when it is missing.

-- Clean up: remove more obsolete files

* -- Fix typo

* -- Fix issue with setpaths submodules when there's a partial submodules download because of a previous error then need to clean uo submodule folders so there's no garbage in there then retry downloading.

* -- Greatly simplify and make it more straighfoward the setpaths process.
-- Add .numberfiles to submodules and check during setpaths process to make sure an incomplete download is detected and triggers a clean download.

* -- Fix setpaths error exception on linux and mac because ls([pathname, '*.m']) works differently on those platform than on Windows when there are NO files matching the specified pattern. Use dir instead of ls to fix this.
-- Fix multiple issues in submodule downloading using non-git method.
-- When user click cancel in response to download fail dialog, quit rather than retry.
-- Add search paths ONLY for the submodules that were successfully installed
-- Fix typos in dialog failed download message

* -- a) Fix setpaths bug in removeFolderContents.m on linux and MAC because the delimiter for path string is ':' not ';' as it is on Winodws. b) On linux the gitSetBranch.m used to get latest branch revis

* Fix setpaths('update') not working.

* -- Fix problems in setpaths with creating new submodule branches

-- Fix issue in setpaths with non-git submodule download and install.
   a) Fix some bugs and typos preventing correct download.
   b) Clean up and delete downloaded submodules files which are no longer needed after installation like the zip file and initial unzipped folder
   c) Clarify input dialog message and try to guess and or suggest the correct branch that matches parent repo

-- Add exception handling to setpaths. in case of error return to original folder

-- Add comprehensive help comments to setpaths describing it's use

* -- Don't add current app twice. Check app include list to see if it already has been added to search paths

* Glm fixes (#80)

- GLM docs fixes

- Convolve HRFs with stim duration before export

* -- In setpaths exclude more folders to avoid problems and headaches with unexpected matlab behavior because of inclusion of weird .m files from a build of AV. So for instance exclude *.app and *_install folders which contain a large amount of files which should never be included in matlab search paths.
-- Add ability to findDotMFolders to exclude folders based on wildcard patterns rather than only explicit names. This allows exclusion of many folders that fit a pattern without having to explicitly list ALL of them
-- Fix several bugs in the build for MAC
-- Finally fixed the requirement that you have to run MAC installation specifically from ~/Downloads/homer3_install. Added code to makesetup.pl to create a more intelligent setup.command which does not depend on execution from a specific folder.

* -- Fix build not working because need to copy ALL config files to installation folder
-- Improve launch performance by changing config file access to global variable

* -- Change setpath submodule download without git, to not ask questions about which branch to download. Instead derive the branch name from root folder name of parent app and default to master of it cannot be determined. This change somehow did not make it earlier into repo

* -- Update submodule references to latest development branch rev

* -- Change unit test to use global config variable rather than opening/closing ConfigFileClass objects
-- Update getVernum to match AV
-- Update submodule references

* DataTree submodule reference update and Mac support fixes (#89)

-- Update DataTree submodule reference to latest change containing fix for errors when there are no data files (because all have errors that prevent loading)

-- Fix more issues with install executable on MAC

* Gets info about latest version from GitHub API rather than openfnirs.org (#92)

* Gets info about latest version from GitHub API rather than openfnirs.org

* Version++

* -- Change setpaths to not download submodules by default. Use 'init' or 'update' options to download automatically. If using github desktop then github desktop download submodules automatically. (#95)

-- Change downloadSharedLibs to change .gitmodules origin url to point to where ever parent came from
-- Add .gitattributes to exclude files from branch merges such as submodule references and .gitmodules
-- Sync getVernum with Homre3. (getVernum will eventually be moved to Utils/Shared library)
-- Improve creation of installation file and installation process using myCopyFile.m

* -- Update submodule reference for development branch to latest
-- Fix .gitmodules to point to development branch instaead of master

* -- Fix setpaths gitSubmodulesUpdate not updating changes to submodules correctly

* -- Fix wrong path to DataTree to exclude from merges
-- Add .gitattributes in list of files to exclude fropm merges

* -- Update submodule references

* -- Update submodule reference to Utils

* Remove submodules: too hard to work with, not enough support from git

* Remove submodules: too hard to work with, not enough support from git

Co-authored-by: default avatarjayd1860 <jayd1860@gmail.com>
Co-authored-by: default avatarsreekanthkura7 <sreekanth.kura7@gmail.com>
Co-authored-by: default avatarMeryem Ayse Yucel <49535526+mayucel@users.noreply.github.com>
Co-authored-by: default avatarJay Dubb <jdubb@scc1.bu.edu>
Co-authored-by: default avatarstephen scott tucker <sstucker@bu.edu>
Co-authored-by: default avatarJay Dubb <jayd1860@github.com>

* -- Step 2 of change to remove submodules references and replacing with hard copy of the DataTree and Utils libraries

Co-authored-by: default avatarjayd1860 <jayd1860@gmail.com>
Co-authored-by: default avatarsreekanthkura7 <sreekanth.kura7@gmail.com>
Co-authored-by: default avatarMeryem Ayse Yucel <49535526+mayucel@users.noreply.github.com>
Co-authored-by: default avatarJay Dubb <jdubb@scc1.bu.edu>
Co-authored-by: default avatarstephen scott tucker <sstucker@bu.edu>
Co-authored-by: default avatarJay Dubb <jayd1860@github.com>

Co-authored-by: default avatarjayd1860 <jayd1860@gmail.com>
Co-authored-by: default avatarsreekanthkura7 <sreekanth.kura7@gmail.com>
Co-authored-by: default avatarMeryem Ayse Yucel <49535526+mayucel@users.noreply.github.com>
Co-authored-by: default avatarJay Dubb <jdubb@scc1.bu.edu>
Co-authored-by: default avatarstephen scott tucker <sstucker@bu.edu>
Co-authored-by: default avatarJay Dubb <jayd1860@github.com>
parent 6ebf8494
Loading
Loading
Loading
Loading

DataTree/.numberfiles

0 → 100644
+1 −0
Original line number Original line Diff line number Diff line
67
 No newline at end of file
+255 −0
Original line number Original line Diff line number Diff line
classdef AcqDataClass < matlab.mixin.Copyable
       
    properties (Access = private)
        logger
    end
    properties (Access = protected)
        errmsgs
    end
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % These methods must be implemented in any derived class
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    methods(Abstract)
        
        % ---------------------------------------------------------
        objnew    = GetFormatVersion(obj, options);

        % ---------------------------------------------------------
        val       = GetFormatVersionString(obj);
   
        % ---------------------------------------------------------
        t         = GetTime(obj, iBlk)
       
        % ---------------------------------------------------------
        datamat   = GetDataTimeSeries(obj, options, iBlk)
        
        % ---------------------------------------------------------
        SD        = GetSDG(obj,option)

        % ---------------------------------------------------------
        srcpos    = GetSrcPos(obj,option)

        % ---------------------------------------------------------
        detpos    = GetDetPos(obj,option)
        
        % ---------------------------------------------------------
        ml        = GetMeasList(obj, iBlk)


        % ---------------------------------------------------------
        wls       = GetWls(obj)
        
        % ---------------------------------------------------------
        SetStims_MatInput(obj, s, t, CondNames)
        
        % ---------------------------------------------------------
        s         = GetStims(obj, t)

        % ---------------------------------------------------------
        CondNames = GetConditions(obj)


        % ---------------------------------------------------------
        SetConditions(obj, CondNames)
        
        % ---------------------------------------------------------
        aux       = GetAuxiliary(obj)
        
        % ---------------------------------------------------------
        SetStimDuration(obj, icond, duration);
        
        % ---------------------------------------------------------
        duration = GetStimDuration(obj, icond);
        
        % ---------------------------------------------------------
        n = GetDataBlocksNum(obj);

        % ---------------------------------------------------------
        [iDataBlks, ich] = GetDataBlocksIdxs(obj, ich);
        
        % ---------------------------------------------------------
        objnew = CopyMutable(obj, options);

    end
    
    
    methods
        
        % -------------------------------------------------------
        function Initialize(obj)
            global logger
            obj.logger = InitLogger(logger);
        end
        
        
        % -------------------------------------------------------
        function err = Error(obj)
            err = obj.GetError();
        end
        
        
        % ---------------------------------------------------------
        function msg = GetErrorMsg(obj)
            msg = '';
            if isempty(obj)
                msg = 'AcqDataClass object is empty';
                return;
            end
            if isempty(obj.errmsgs)
                return;
            end
            if ~obj.GetError()
                return;
            end
            msg = obj.errmsgs{abs(obj.GetError())};
        end
        
        
        % -------------------------------------------------------
        function FreeMemory(obj, filename)
            if ~exist('filename','var')
                filename = '';
            end
            if isempty(filename)
                return;
            end            
            obj.Initialize();
        end
        
        
        % ---------------------------------------------------------
        function bbox = GetSdgBbox(obj)
            bbox = [];
            
            optpos = [obj.GetSrcPos('2D'); obj.GetDetPos('2D')];
            if isempty(optpos)
                return
            end
            
            xmax = max(optpos(:,1));
            ymax = max(optpos(:,2));

            xmin = min(optpos(:,1));
            ymin = min(optpos(:,2));
            
            width = xmax-xmin;
            height = ymax-ymin;
            
            if width==0
                width = 1;
            end
            if height==0
                height = 1;
            end
            
            px = width * 0.05; 
            py = height * 0.05; 

            bbox = [xmin-px, xmax+px, ymin-py, ymax+py];
        end
        
        
        % ----------------------------------------------------------------------------------
        function varval = GetVar(obj, varname)
            if ismethod(obj,['Get_', varname])
                varval = eval( sprintf('obj.Get_%s()', varname) );
            elseif ismethod(obj,['Get', varname])
                varval = eval( sprintf('obj.Get%s()', varname) );
            elseif isproperty(obj, varname)
                varval = eval( sprintf('obj.%s', varname) );
            else
                varval = [];
            end
            
            % If varval is a class object with an IsEmpty() method and length of varval is one or 
            % less, then use it determine whether it's valid. If not, return empty as if it were 
            % really empty. This is useful when we want to copy only part of an object to save on space. 
            % For instance to reconstruct nirs style 's' variable from a SNIRF stim object we need the t 
            % property from a SNIRF data container, but we only need that one property not the whole thing
            % so we initilize only the t property. We don't want this partially initialized data object 
            % to be found (by GetVar) and used directly in the proc stream processing, we only want to use 
            % indirectly to retrieve s from stim. So we do this check to see if it's valid. It won't be 
            % since it's only partially initialized.
            if isa(varval, 'handle') && ismethod(varval,'IsEmpty')
                if length(varval)==1 && varval(1).IsEmpty()
                    varval = [];
                end
            end
        end
        
        
        % ----------------------------------------------------------------------------------
        function t = GetTimeCombined(obj)
            % Function combines the time vectors for all data blocks into one time vectors. 
            t = obj.GetTime(1);
            tStart = t(1);
            tEnd   = t(end);
            tStep  = mean(diff(t));
            
            nBlks = obj.GetDataBlocksNum();
            for iBlk=2:nBlks
                t = obj.GetTime(iBlk);
                if t(1) < tStart
                    tStart = t(1);
                end
                if t(end) > tEnd
                    tEnd = t(end);
                end
                if mean(diff(t)) < tStep
                    tStep = mean(diff(t));
                end
            end
            t = tStart:tStep:tEnd;            
        end
        
                
        % ----------------------------------------------------------------------------------
        function data = GetStimData(~, ~)
            data = [];
        end
        
        
        % ----------------------------------------------------------------------------------
        function val = GetStimDataLabels(~, ~)
            val = {};
        end
                        
        
        % ----------------------------------------------------------------------------------
        function b = equal(obj, obj2)
            b = true;
            if isempty(obj.GetFilename)
                return;
            end
            if isempty(obj2.GetFilename)
                return;
            end
            [~, fname1, ext1] = fileparts(obj.GetFilename);
            [~, fname2, ext2] = fileparts(obj2.GetFilename);            
            if ~strcmpi([fname1, ext1], [fname2, ext2])
                b = false;
            end
        end
        
        
        % ----------------------------------------------------------------------------------
        function status = Mismatch(obj, obj2)
            status = 0;
            msg = {};
            if ~exist('obj2','var')
                return;
            end
            if ~obj.equal(obj2)
                [~, fname, ext] = fileparts(obj.GetFilename);
                msg{1} = sprintf('WARNING: The acquisition file "%s" does not match the derived data in this group folder. ', [fname, ext]);
                msg{2} = sprintf('Are you sure this acquisition file belongs in this group folder?');
                obj.logger.Write([msg{:}])
            end
        end
        
        
        
    end
    
end
+353 −0
Original line number Original line Diff line number Diff line
classdef DataFilesClass < handle
    
    properties
        files;
        type;
        err;
        errmsg;
        pathnm;
        config;
        nfiles;
        logger
    end
    
    methods
        
        % ----------------------------------------------------
        function obj = DataFilesClass(varargin)            
            obj.type = '';
            obj.pathnm = pwd;
            obj.nfiles = 0;
            obj.err = -1;
            obj.errmsg = {};
            
            global logger
            global cfg
            
            logger = InitLogger(logger);
            cfg    = InitConfig(cfg);
            
            obj.logger = logger;
            
            skipconfigfile = false;
            askToFixNameConflicts = [];
            
            if nargin==0
                return
            end            
            if nargin==1
                obj.pathnm = varargin{1};
            end            
            if nargin==2
                obj.pathnm = varargin{1};
                obj.type = varargin{2};
            end
            if nargin==3
                obj.pathnm = varargin{1};
                obj.type = varargin{2};
                if strcmp(varargin{3}, 'standalone')
                    skipconfigfile = true;
                end
            end            
            if nargin==4
                obj.pathnm = varargin{1};
                obj.type = varargin{2};
                if strcmp(varargin{3}, 'standalone')
                    skipconfigfile = true;
                end
                askToFixNameConflicts = varargin{4};
            end
                        
            if obj.type(1)=='.'
                obj.type(1)='';
            end
            obj.pathnm = filesepStandard(obj.pathnm,'full');
            
            % Configuration parameters
            obj.config = struct('RegressionTestActive','','AskToFixNameConflicts',1);
            if skipconfigfile==false
                str = cfg.GetValue('Regression Test Active');
                if strcmp(str,'true')
                    obj.config.RegressionTestActive=true;
                else
                    obj.config.RegressionTestActive=false;
                end
            else
                obj.config.RegressionTestActive=false;
            end
            obj.config.SuppressErrorChecking = false;
            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 ~obj.config.AskToFixNameConflicts
                obj.config.SuppressErrorChecking = true;                
            end
            
            if nargin==0
                return;
            end
            
            obj.err = 0;
            obj.files = mydir(obj.pathnm);
            GetDataSet(obj);
        end
        
        
        % -----------------------------------------------------------------------------------
        function GetDataSet(obj)
            if exist(obj.pathnm, 'dir')~=7
                error('Invalid subject folder: ''%s''', obj.pathnm);
            end
            obj.findDataSet(obj.type);
            
            % Remove any files that cannot pass the basic test of loading
            % its data
            obj.ErrorCheck(obj.type);
            obj.ErrorCheckName();
        end

        
        % ----------------------------------------------------
        function findDataSet(obj, type)
            obj.files = mydir([obj.pathnm, '/*.', type]);
            
            % Remove any files that cannot pass the basic test of loading
            % its data
            obj.ErrorCheck(type);

            if isempty( obj.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 && ...
                            ~strcmp(dirs(ii).name,'.') && ...
                            ~strcmp(dirs(ii).name,'..') && ...
                            ~strcmp(dirs(ii).name,'hide')
                        dirs(ii).idx = length(obj.files)+1;
                        foos = mydir([obj.pathnm, dirs(ii).name, '/*.', type]);
                        nfoos = length(foos);
                        if nfoos>0
                            for jj = 1:nfoos
                                foos(jj).subjdir      = dirs(ii).name;
                                foos(jj).subjdiridx   = dirs(ii).idx;
                                foos(jj).idx          = dirs(ii).idx+jj;
                                foos(jj).filename     = foos(jj).name;
                                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 file from current subdir to files struct
                            if isempty(obj.files)
                                obj.files = dirs(ii);
                            else
                                obj.files(end+1) = dirs(ii);
                            end
                            obj.files(end+1:end+nfoos) = foos;                                                        
                        end
                    end
                end
            else
                for ii = 1:length(obj.files)
                    obj.files(ii).pathfull = obj.pathnm;
                end
                obj.nfiles = obj.nfiles+length(obj.files);
            end
        end
        
        
        
        % ----------------------------------------------------
        function getDataFile(obj, filename)
            obj.files = mydir(filename);
        end
        
        
        
        % ----------------------------------------------------
        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)
            global cfg
            
            ConfigFileClass
            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.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(~, hObject)
            hp = get(hObject,'parent');
            hc = get(hp,'children');
            for ii=1:length(hc)
                
                if strcmp(get(hc(ii),'tag'),'pushbuttonLoad')
                    hButtnLoad = hc(ii);
                elseif strcmp(get(hc(ii),'tag'),'pushbuttonSelectAnother')
                    hButtnSelectAnother = hc(ii);
                end
                
            end
            
            if hObject==hButtnLoad
                delete(hButtnSelectAnother);
            elseif hObject==hButtnSelectAnother
                delete(hButtnLoad);
            end
            delete(hp);
        end
            
        
        % ----------------------------------------------------------
        function b = isempty(obj)
            if isempty(obj.files)
                b = true;
            else
                b = false;
            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
        
        
        
        % ----------------------------------------------------------
        function ErrorCheck(obj, type)
            errorIdxs = [];

            if isempty(obj.files)
                return
            end
                       
            % Assume constructor name follows from name of data format type
            constructor = sprintf('%sClass', [upper(type(1)), type(2:end)]);
            
            % Make sure function by that name exists; otherwise no way to
            % use it to check loadability
            if isempty(which(constructor))
                return;
            end
            
            % Try to create object of data type and load data into it
            dataflag = false;
            for ii = 1:length(obj.files)
                if obj.files(ii).isdir
                    continue;
                end
                filename = [obj.files(ii).pathfull, 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);
                    errorIdxs = [errorIdxs, ii]; %#ok<AGROW>
                else
                    dataflag = true;
                end
            end
            if dataflag==false
                obj.files = FileClass.empty();
            else
            	obj.files(errorIdxs) = [];
            end
        end
        
        
        % ----------------------------------------------------------
        function err = GetError(obj)
            err = -1;
            if isempty(obj)
                return;
            end
            err = obj.err;
        end
        
    end
end
+101 −0
Original line number Original line Diff line number Diff line
function DeleteDataFiles(varargin)

% Syntax:
%
%   DeleteDataFiles()
%   DeleteDataFiles(dirname)
%   DeleteDataFiles(dirname, datafiles0)
%   DeleteDataFiles(dirname, format)
%   DeleteDataFiles(dirname, datafiles0, options)
%   DeleteDataFiles(dirname, format, options)
%
% Description:
%   
%   Delete all .<format extension> files in group folder. DeleteDataFiles will find all 
%   .<format extension> data acquisition files in the group folder. If dirname is not supplied it'll 
%   treat the current working directory as the group folder. 
%
% Examples:
%
%   1. Delete all .snirf files in the Homer3 Examples directory
%
%       DeleteDataFiles('C:\jdubb\workspaces\Homer3\DataTree\AcquiredData\Snirf\Examples', '.snirf')
%
%   2. Delete all .nirs files files in the current group folder
%
%       DeleteDataFiles(pwd, '.nirs)
%
%

global supportedFormats
if isempty(supportedFormats)
    supportedFormats = {
    '.snirf',0;
    '.nirs',0;
    };
end


% Set argument defaults
dirname = filesepStandard(pwd);
format = supportedFormats{1};
datafiles0 = [];
options = 'delete';


% Parse arguments
if nargin==1
    dirname = filesepStandard(varargin{1},'full');
elseif nargin==2
    dirname = filesepStandard(varargin{1},'full');
    if ischar(varargin{2})
        format = varargin{2};
    else
        datafiles0 = varargin{2};
    end
elseif nargin==3
    dirname = filesepStandard(varargin{1}, 'full');
    if ischar(varargin{2})
        format = varargin{2};
    else
        datafiles0 = varargin{2};
    end
    options = varargin{3};
end
if isempty(datafiles0)
    datafiles0 = DataFilesClass(dirname, format, 'standalone').files;
end


% Get final list of data files
datafiles = mydir(dirname);
if iscell(datafiles0)
    for ii=1:length(datafiles0)
        datafiles(ii) = mydir([dirname, datafiles0{ii}]);
    end
elseif ischar(datafiles0)
    datafiles = mydir([dirname, datafiles0]);
elseif isa(datafiles0, 'FileClass')
    datafiles = datafiles0;
end


% Delete data files
for ii=1:length(datafiles)
    if datafiles(ii).isdir
        continue;
    end
    if strcmp(options, 'delete')
        fprintf('Deleting %s\n', [datafiles(ii).pathfull, '/', datafiles(ii).name]);
        delete([datafiles(ii).pathfull, '/', datafiles(ii).name]);
    elseif strcmp(options, 'move')
        fprintf('Moving %s to %s\n', [datafiles(ii).pathfull, '/', datafiles(ii).name], [datafiles(ii).pathfull, '/', datafiles(ii).name, '.old']);
        movefile([datafiles(ii).pathfull, '/', datafiles(ii).name], [datafiles(ii).pathfull, '/', datafiles(ii).name, '.old']);
    elseif strcmp(options, 'restore')
        [pname, fname] = fileparts(datafiles(ii).name);
        fprintf('Restoring %s to %s\n', [datafiles(ii).pathfull, '/', datafiles(ii).name], [datafiles(ii).pathfull, '/', pname, '/', fname]);
        movefile([datafiles(ii).pathfull, '/', datafiles(ii).name], [datafiles(ii).pathfull, '/', pname, '/', fname]);
    end
    pause(0.25);
end
+323 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading