Skip to content

Commit f162f70

Browse files
committed
v1.79.2
-- 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.
1 parent de02dd7 commit f162f70

File tree

11 files changed

+720
-80
lines changed

11 files changed

+720
-80
lines changed

AppSettings.cfg

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ don't ask again
1111
one processing element per file
1212
1313
% Load Stim From TSV File # Yes, No
14-
No
15-
16-
% Replace TSV File Tabs with Spaces # Yes, No
17-
No
14+
Yes
1815
1916
% END

DataTree/AcquiredData/DataFiles/SnirfFile2Tsv.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,4 @@
4848
writeTsv(dst, tsv);
4949
end
5050

51-
% Remove stim from
52-
% if optionExists(options, 'removeStim')
53-
% s.Load();
54-
% s.stim = StimClass().empty();
55-
% s.Save();
56-
% end
57-
5851

DataTree/AppSettings.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ No
4040
% Quiet Mode # On, Off
4141
Off
4242

43+
% Replace TSV File Tabs with Spaces # auto-replace, ask me, don't replace and don't ask me
44+
ask me
45+
4346
% END

DataTree/TreeNodeClass.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,17 @@ function ReloadStim(obj)
548548

549549

550550

551+
% ----------------------------------------------------------------------------------
552+
function fnameTsv = GetStimTsvFilename(obj)
553+
fnameTsv = [];
554+
if isempty(obj.acquired)
555+
return;
556+
end
557+
fnameTsv = obj.acquired.GetStimTsvFilename();
558+
end
559+
560+
561+
551562
% ----------------------------------------------------------------------------------
552563
function EditStim(obj, waitForInput)
553564
if ~exist('waitForInput','var')
@@ -558,10 +569,9 @@ function EditStim(obj, waitForInput)
558569
return;
559570
end
560571
filenameData = [obj.path, obj.GetFilename()];
561-
[p1,f1] = fileparts(filenameData);
562572

563573
% From data file name get events TSV file and load in matlab editor
564-
filenameEvents = [p1, '/', f1, '_events.tsv'];
574+
filenameEvents = obj.GetStimTsvFilename();
565575
if ~ispathvalid(filenameEvents)
566576
obj.logger.Write('Events TSV file for %s doesn''t exist.\n', filenameData);
567577
obj.ExportStim();

DataTree/Version.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
1.14.1
2-
1+
1.14.2

DataTree/setpaths.m

Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ function setpaths(addremove)
3333
% Add libraries on which DataTreeClass depends
3434
d = addDependenciesSearchPaths();
3535

36+
if ~isempty(which('setNamespace.m'))
37+
setNamespace(appname);
38+
end
39+
3640
% Start logger only after adding library paths. Logger is in the Utils libary.
3741
logger = Logger('setpaths');
3842

@@ -127,15 +131,14 @@ function setpaths(addremove)
127131

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

130-
PrintSystemInfo(logger, ['DataTreeClass'; d]);
134+
PrintSystemInfo(logger, [appname; d]);
131135
logger.CurrTime('Setpaths completed on ');
132136
logger.Close();
133137
cd(currdir);
134138

135139
catch ME
136140

137-
printStack(ME)
138-
if exist('logger','var')
141+
if exist('logger','var') && isa(logger, 'Logger')
139142
logger.Close();
140143
end
141144
cd(currdir);
@@ -180,7 +183,7 @@ function addSearchPaths(appPaths)
180183
else
181184
delimiter = ':';
182185
end
183-
appPaths = str2cell(p, delimiter);
186+
appPaths = str2cell_startup(p, delimiter);
184187
end
185188
for kk = 1:length(appPaths)
186189
if strfind(appPaths{kk}, '.git')
@@ -225,28 +228,23 @@ function removeSearchPaths(app)
225228

226229
% ----------------------------------------------------
227230
function d = addDependenciesSearchPaths()
228-
if exist([pwd, '/Utils/submodules'],'dir')
229-
addpath([pwd, '/Utils/submodules'],'-end');
230-
end
231-
d = dependencies();
232-
for ii = 1:length(d)
233-
rootpath = findFolder(pwd, d{ii});
234-
rootpath(rootpath=='\') = '/';
235-
if ispathvalid_startup([rootpath, '/Shared'],'dir')
236-
rootpath = [rootpath, '/Shared'];
237-
end
238-
if ~exist(rootpath,'dir')
231+
submodules = downloadDependencies();
232+
d = cell(size(submodules,1),1);
233+
for ii = 1:size(submodules)
234+
submodulespath = [filesepStandard_startup(pwd), submodules{ii,end}];
235+
if ~exist(submodulespath,'dir')
239236
printMethod(sprintf('ERROR: Could not find required dependency %s\n', d{ii}));
240237
continue;
241238
end
242-
addSearchPaths(rootpath);
239+
printMethod(sprintf('Adding searchpaths for submodule %s\n', submodulespath));
240+
addSearchPaths(submodulespath);
241+
d{ii,1} = submodules{ii,end};
243242
end
244243

245244

246245

247-
248246
% -----------------------------------------------------------------------------
249-
function [C,k] = str2cell(str, delimiters, options)
247+
function [C,k] = str2cell_startup(str, delimiters, options)
250248

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

311309

312310

311+
% -------------------------------------------------------------------------
312+
function submodules = parseGitSubmodulesFile(repo)
313+
submodules = cell(0,3);
314+
315+
if ~exist('repo','var') || isempty(repo)
316+
repo = pwd;
317+
end
318+
currdir = pwd;
319+
if repo(end) ~= '/' && repo(end) ~= '\'
320+
repo = [repo, '/'];
321+
end
322+
323+
filename = [repo, '.gitmodules'];
324+
if ~exist(filename, 'file')
325+
return;
326+
end
327+
cd(repo);
328+
329+
fid = fopen(filename, 'rt');
330+
strs = textscan(fid, '%s');
331+
strs = strs{1};
332+
kk = 1;
333+
for ii = 1:length(strs)
334+
if strcmp(strs{ii}, '[submodule')
335+
jj = 1;
336+
while ~strcmp(strs{ii+jj}, '[submodule')
337+
if ii+jj+2>length(strs)
338+
break;
339+
end
340+
if strcmp(strs{ii+jj}, 'path')
341+
submodules{kk,2} = [pwd, '/', strs{ii+jj+2}];
342+
end
343+
if strcmp(strs{ii+jj}, 'path')
344+
submodules{kk,3} = strs{ii+jj+2};
345+
end
346+
if strcmp(strs{ii+jj}, 'url')
347+
submodules{kk,1} = strs{ii+jj+2};
348+
end
349+
jj = jj+1;
350+
end
351+
kk = kk+1;
352+
end
353+
end
354+
fclose(fid);
355+
cd(currdir);
356+
357+
358+
359+
313360
% -------------------------------------------------------------------------
314361
function dirpath = findFolder(repo, dirname)
315362
dirpath = '';
@@ -351,9 +398,9 @@ function printMethod(msg)
351398
exclList = {exclList};
352399
end
353400

354-
subdirFullpath = filesepStandard(subdir,'full');
401+
subdirFullpath = filesepStandard_startup(subdir,'full');
355402

356-
if ~ispathvalid(subdirFullpath, 'dir')
403+
if ~ispathvalid_startup(subdirFullpath, 'dir')
357404
logger.Write('Warning: folder %s doesn''t exist\n', subdirFullpath);
358405
return;
359406
end
@@ -369,7 +416,7 @@ function printMethod(msg)
369416
end
370417

371418
if isdotmfolder(subdirFullpath)
372-
dotmfolders = {filesepStandard(subdirFullpath, 'nameonly')};
419+
dotmfolders = {filesepStandard_startup(subdirFullpath, 'nameonly')};
373420
end
374421

375422
for ii = 1:length(dirs)
@@ -390,7 +437,7 @@ function printMethod(msg)
390437
function b = isdotmfolder(folder)
391438
global MAXPATHLENGTH
392439
b = false;
393-
if ~ispathvalid(folder, 'dir')
440+
if ~ispathvalid_startup(folder, 'dir')
394441
return
395442
end
396443
if isempty(dir([folder,'/*.m']))
@@ -421,7 +468,7 @@ function printMethod(msg)
421468
if pname(end)=='/'
422469
pname(end) = '';
423470
end
424-
if ~ispathvalid(pname,'dir')
471+
if ~ispathvalid_startup(pname,'dir')
425472
return;
426473
end
427474
[~,f,e] = fileparts(pname);
@@ -452,13 +499,13 @@ function printMethod(msg)
452499
if ~exist('options','var')
453500
options = '';
454501
end
455-
if optionExists(options, 'nochange')
502+
if optionExists_startup(options, 'nochange')
456503
option = '';
457504
else
458505
option = 'full';
459506
end
460-
p1 = filesepStandard(p1_0, option);
461-
p2 = filesepStandard(p2_0, option);
507+
p1 = filesepStandard_startup(p1_0, option);
508+
p2 = filesepStandard_startup(p2_0, option);
462509
if isempty(p1)
463510
p1 = p1_0;
464511
end
@@ -481,7 +528,7 @@ function printMethod(msg)
481528

482529
%
483530
% Usage:
484-
% pathname = filesepStandard(pathname, options)
531+
% pathname = filesepStandard_startup(pathname, options)
485532
%
486533
% Takes a pathname as argument and replaces any non-standard file/folder
487534
% separators with standard ones, that is '/'. It also gets rid of redundant
@@ -490,7 +537,7 @@ function printMethod(msg)
490537
% Example:
491538
%
492539
% >> pathname = 'C:\dir1\\\dir2\\dir3\test1/\test2/'
493-
% >> pathname = filesepStandard(pathname)
540+
% >> pathname = filesepStandard_startup(pathname)
494541
%
495542
% pathname =
496543
%
@@ -754,8 +801,8 @@ function printMethod(msg)
754801
path1 = lower(path1);
755802
path2 = lower(path2);
756803
end
757-
p1 = str2cell(path1,{'\','/'});
758-
p2 = str2cell(path2,{'\','/'});
804+
p1 = str2cell_startup(path1,{'\','/'});
805+
p2 = str2cell_startup(path2,{'\','/'});
759806
if length(p1) ~= length(p2)
760807
return;
761808
end

Utils/Shared/ConfigFileClass.m

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ function AddParam(obj, name, val, valOptions, iF)
375375
else
376376
valOptions = strtrim_improve(obj.linestr(ii:jj));
377377
valOptions = split(valOptions,', ');
378+
for ii = 1:length(valOptions)
379+
valOptions{ii} = strtrim_improve(valOptions{ii});
380+
end
378381
end
379382
end
380383

@@ -416,7 +419,28 @@ function AddParam(obj, name, val, valOptions, iF)
416419
end
417420
end
418421

419-
% -------------------------------------------------------------------------------------------------
422+
423+
424+
% -------------------------------------------------------------------------------------------------
425+
function valOptions = GetValueOptions(obj, paramName)
426+
valOptions = '';
427+
if nargin<2
428+
return;
429+
end
430+
if ~ischar(paramName)
431+
return;
432+
end
433+
for ii = 1:length(obj.params)
434+
if strcmpi(obj.params(ii).name, paramName)
435+
valOptions = obj.params(ii).valOptions;
436+
break;
437+
end
438+
end
439+
end
440+
441+
442+
443+
% -------------------------------------------------------------------------------------------------
420444
function val = GetMultiValues(obj, paramName)
421445
val = '';
422446
if nargin<2
@@ -435,11 +459,24 @@ function AddParam(obj, name, val, valOptions, iF)
435459
end
436460
end
437461

462+
463+
438464
% -------------------------------------------------------------------------------------------------
439-
function SetValue(obj, paramName, val)
465+
function SetValue(obj, paramName, val, autosave)
440466
if nargin<3
441467
return;
442468
end
469+
if ~exist('autosave','var')
470+
autosave = 0;
471+
end
472+
if ischar(autosave)
473+
if strcmpi(autosave,'autosave')
474+
autosave = true;
475+
end
476+
else
477+
autosave = false;
478+
end
479+
443480
if ~ischar(paramName)
444481
return;
445482
end
@@ -448,6 +485,10 @@ function SetValue(obj, paramName, val)
448485
obj.params(ii).val{1} = val;
449486
end
450487
end
488+
489+
if autosave
490+
obj.Save();
491+
end
451492
end
452493

453494

Utils/Shared/Version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.1
1+
1.6.0

0 commit comments

Comments
 (0)