Skip to content

Commit

Permalink
v1.79.2
Browse files Browse the repository at this point in the history
-- Add more standalone startup function to setpaths.m to be able to independent of any startup code search paths except current folder
-- Chnage default value of config param Load Stim From TSV File from no to yes.

* DataTree, v1.14.2
-- Fix events TSV file naming bug. Add TSV file name method TreeNode.GetStimTsvFilename() to use for all events TSV file naming.
-- Fixes to setpaths for running DataTree standalone

* Utils, v1.6.0
-- Fix some bugs in events TSV stim loading error handling. Add config param "Replace TSV File Tabs with Spaces" to handle events TSV errors when file  is a mix of spaces and tabs.
-- Add method ConfigFileClass.GetValueOptions for getting all available value options for a param.
  • Loading branch information
jayd1860 committed May 12, 2023
1 parent de02dd7 commit f162f70
Show file tree
Hide file tree
Showing 11 changed files with 720 additions and 80 deletions.
5 changes: 1 addition & 4 deletions AppSettings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ don't ask again
one processing element per file
% Load Stim From TSV File # Yes, No
No
% Replace TSV File Tabs with Spaces # Yes, No
No
Yes
% END
7 changes: 0 additions & 7 deletions DataTree/AcquiredData/DataFiles/SnirfFile2Tsv.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,4 @@
writeTsv(dst, tsv);
end

% Remove stim from
% if optionExists(options, 'removeStim')
% s.Load();
% s.stim = StimClass().empty();
% s.Save();
% end


3 changes: 3 additions & 0 deletions DataTree/AppSettings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ No
% Quiet Mode # On, Off
Off

% Replace TSV File Tabs with Spaces # auto-replace, ask me, don't replace and don't ask me
ask me

% END
14 changes: 12 additions & 2 deletions DataTree/TreeNodeClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@ function ReloadStim(obj)



% ----------------------------------------------------------------------------------
function fnameTsv = GetStimTsvFilename(obj)
fnameTsv = [];
if isempty(obj.acquired)
return;
end
fnameTsv = obj.acquired.GetStimTsvFilename();
end



% ----------------------------------------------------------------------------------
function EditStim(obj, waitForInput)
if ~exist('waitForInput','var')
Expand All @@ -558,10 +569,9 @@ function EditStim(obj, waitForInput)
return;
end
filenameData = [obj.path, obj.GetFilename()];
[p1,f1] = fileparts(filenameData);

% From data file name get events TSV file and load in matlab editor
filenameEvents = [p1, '/', f1, '_events.tsv'];
filenameEvents = obj.GetStimTsvFilename();
if ~ispathvalid(filenameEvents)
obj.logger.Write('Events TSV file for %s doesn''t exist.\n', filenameData);
obj.ExportStim();
Expand Down
3 changes: 1 addition & 2 deletions DataTree/Version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
1.14.1

1.14.2
107 changes: 77 additions & 30 deletions DataTree/setpaths.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function setpaths(addremove)
% Add libraries on which DataTreeClass depends
d = addDependenciesSearchPaths();

if ~isempty(which('setNamespace.m'))
setNamespace(appname);
end

% Start logger only after adding library paths. Logger is in the Utils libary.
logger = Logger('setpaths');

Expand Down Expand Up @@ -127,15 +131,14 @@ function setpaths(addremove)

warning('on','MATLAB:rmpath:DirNotFound');

PrintSystemInfo(logger, ['DataTreeClass'; d]);
PrintSystemInfo(logger, [appname; d]);
logger.CurrTime('Setpaths completed on ');
logger.Close();
cd(currdir);

catch ME

printStack(ME)
if exist('logger','var')
if exist('logger','var') && isa(logger, 'Logger')
logger.Close();
end
cd(currdir);
Expand Down Expand Up @@ -180,7 +183,7 @@ function addSearchPaths(appPaths)
else
delimiter = ':';
end
appPaths = str2cell(p, delimiter);
appPaths = str2cell_startup(p, delimiter);
end
for kk = 1:length(appPaths)
if strfind(appPaths{kk}, '.git')
Expand Down Expand Up @@ -225,28 +228,23 @@ function removeSearchPaths(app)

% ----------------------------------------------------
function d = addDependenciesSearchPaths()
if exist([pwd, '/Utils/submodules'],'dir')
addpath([pwd, '/Utils/submodules'],'-end');
end
d = dependencies();
for ii = 1:length(d)
rootpath = findFolder(pwd, d{ii});
rootpath(rootpath=='\') = '/';
if ispathvalid_startup([rootpath, '/Shared'],'dir')
rootpath = [rootpath, '/Shared'];
end
if ~exist(rootpath,'dir')
submodules = downloadDependencies();
d = cell(size(submodules,1),1);
for ii = 1:size(submodules)
submodulespath = [filesepStandard_startup(pwd), submodules{ii,end}];
if ~exist(submodulespath,'dir')
printMethod(sprintf('ERROR: Could not find required dependency %s\n', d{ii}));
continue;
end
addSearchPaths(rootpath);
printMethod(sprintf('Adding searchpaths for submodule %s\n', submodulespath));
addSearchPaths(submodulespath);
d{ii,1} = submodules{ii,end};
end




% -----------------------------------------------------------------------------
function [C,k] = str2cell(str, delimiters, options)
function [C,k] = str2cell_startup(str, delimiters, options)

% Option tells weather to keep leading whitespaces.
% (Trailing whitespaces are always removed)
Expand Down Expand Up @@ -310,6 +308,55 @@ function printMethod(msg)



% -------------------------------------------------------------------------
function submodules = parseGitSubmodulesFile(repo)
submodules = cell(0,3);

if ~exist('repo','var') || isempty(repo)
repo = pwd;
end
currdir = pwd;
if repo(end) ~= '/' && repo(end) ~= '\'
repo = [repo, '/'];
end

filename = [repo, '.gitmodules'];
if ~exist(filename, 'file')
return;
end
cd(repo);

fid = fopen(filename, 'rt');
strs = textscan(fid, '%s');
strs = strs{1};
kk = 1;
for ii = 1:length(strs)
if strcmp(strs{ii}, '[submodule')
jj = 1;
while ~strcmp(strs{ii+jj}, '[submodule')
if ii+jj+2>length(strs)
break;
end
if strcmp(strs{ii+jj}, 'path')
submodules{kk,2} = [pwd, '/', strs{ii+jj+2}];
end
if strcmp(strs{ii+jj}, 'path')
submodules{kk,3} = strs{ii+jj+2};
end
if strcmp(strs{ii+jj}, 'url')
submodules{kk,1} = strs{ii+jj+2};
end
jj = jj+1;
end
kk = kk+1;
end
end
fclose(fid);
cd(currdir);




% -------------------------------------------------------------------------
function dirpath = findFolder(repo, dirname)
dirpath = '';
Expand Down Expand Up @@ -351,9 +398,9 @@ function printMethod(msg)
exclList = {exclList};
end

subdirFullpath = filesepStandard(subdir,'full');
subdirFullpath = filesepStandard_startup(subdir,'full');

if ~ispathvalid(subdirFullpath, 'dir')
if ~ispathvalid_startup(subdirFullpath, 'dir')
logger.Write('Warning: folder %s doesn''t exist\n', subdirFullpath);
return;
end
Expand All @@ -369,7 +416,7 @@ function printMethod(msg)
end

if isdotmfolder(subdirFullpath)
dotmfolders = {filesepStandard(subdirFullpath, 'nameonly')};
dotmfolders = {filesepStandard_startup(subdirFullpath, 'nameonly')};
end

for ii = 1:length(dirs)
Expand All @@ -390,7 +437,7 @@ function printMethod(msg)
function b = isdotmfolder(folder)
global MAXPATHLENGTH
b = false;
if ~ispathvalid(folder, 'dir')
if ~ispathvalid_startup(folder, 'dir')
return
end
if isempty(dir([folder,'/*.m']))
Expand Down Expand Up @@ -421,7 +468,7 @@ function printMethod(msg)
if pname(end)=='/'
pname(end) = '';
end
if ~ispathvalid(pname,'dir')
if ~ispathvalid_startup(pname,'dir')
return;
end
[~,f,e] = fileparts(pname);
Expand Down Expand Up @@ -452,13 +499,13 @@ function printMethod(msg)
if ~exist('options','var')
options = '';
end
if optionExists(options, 'nochange')
if optionExists_startup(options, 'nochange')
option = '';
else
option = 'full';
end
p1 = filesepStandard(p1_0, option);
p2 = filesepStandard(p2_0, option);
p1 = filesepStandard_startup(p1_0, option);
p2 = filesepStandard_startup(p2_0, option);
if isempty(p1)
p1 = p1_0;
end
Expand All @@ -481,7 +528,7 @@ function printMethod(msg)

%
% Usage:
% pathname = filesepStandard(pathname, options)
% pathname = filesepStandard_startup(pathname, options)
%
% Takes a pathname as argument and replaces any non-standard file/folder
% separators with standard ones, that is '/'. It also gets rid of redundant
Expand All @@ -490,7 +537,7 @@ function printMethod(msg)
% Example:
%
% >> pathname = 'C:\dir1\\\dir2\\dir3\test1/\test2/'
% >> pathname = filesepStandard(pathname)
% >> pathname = filesepStandard_startup(pathname)
%
% pathname =
%
Expand Down Expand Up @@ -754,8 +801,8 @@ function printMethod(msg)
path1 = lower(path1);
path2 = lower(path2);
end
p1 = str2cell(path1,{'\','/'});
p2 = str2cell(path2,{'\','/'});
p1 = str2cell_startup(path1,{'\','/'});
p2 = str2cell_startup(path2,{'\','/'});
if length(p1) ~= length(p2)
return;
end
Expand Down
45 changes: 43 additions & 2 deletions Utils/Shared/ConfigFileClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ function AddParam(obj, name, val, valOptions, iF)
else
valOptions = strtrim_improve(obj.linestr(ii:jj));
valOptions = split(valOptions,', ');
for ii = 1:length(valOptions)
valOptions{ii} = strtrim_improve(valOptions{ii});
end
end
end

Expand Down Expand Up @@ -416,7 +419,28 @@ function AddParam(obj, name, val, valOptions, iF)
end
end

% -------------------------------------------------------------------------------------------------


% -------------------------------------------------------------------------------------------------
function valOptions = GetValueOptions(obj, paramName)
valOptions = '';
if nargin<2
return;
end
if ~ischar(paramName)
return;
end
for ii = 1:length(obj.params)
if strcmpi(obj.params(ii).name, paramName)
valOptions = obj.params(ii).valOptions;
break;
end
end
end



% -------------------------------------------------------------------------------------------------
function val = GetMultiValues(obj, paramName)
val = '';
if nargin<2
Expand All @@ -435,11 +459,24 @@ function AddParam(obj, name, val, valOptions, iF)
end
end



% -------------------------------------------------------------------------------------------------
function SetValue(obj, paramName, val)
function SetValue(obj, paramName, val, autosave)
if nargin<3
return;
end
if ~exist('autosave','var')
autosave = 0;
end
if ischar(autosave)
if strcmpi(autosave,'autosave')
autosave = true;
end
else
autosave = false;
end

if ~ischar(paramName)
return;
end
Expand All @@ -448,6 +485,10 @@ function SetValue(obj, paramName, val)
obj.params(ii).val{1} = val;
end
end

if autosave
obj.Save();
end
end


Expand Down
2 changes: 1 addition & 1 deletion Utils/Shared/Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.1
1.6.0

0 comments on commit f162f70

Please sign in to comment.