Skip to content

Commit

Permalink
Merge pull request #64 from bahanonu/bahanonu/functionUpdates
Browse files Browse the repository at this point in the history
Adding ciapkg API sub-package, improved directory management, etc.
  • Loading branch information
bahanonu authored Feb 25, 2021
2 parents bbda43b + 79c61dd commit afd1405
Show file tree
Hide file tree
Showing 38 changed files with 914 additions and 187 deletions.
7 changes: 7 additions & 0 deletions +ciapkg/+api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CIAtah API

Biafra Ahanonu

All functions in the `ciapkg.api` package are just pass-through functions to the actual underlying functions. This allows users to import all CIAtah functions into their function or script with `import ciapkg.api.*` as opposed to having to do that for each `ciapkg` sub-package.

Else, users can call nearly all CIAtah functions using `ciapkg.api.[Function Name]`, which allows easier namespacing.
10 changes: 10 additions & 0 deletions +ciapkg/+api/loadMovieList.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function [outputMovie, movieDims, nPixels, nFrames] = loadMovieList(movieList, varargin)
% Load movies, automatically detects type (avi, tif, or hdf5) and concatenates if multiple movies in a list.
% NOTE:
% The function assumes input is 2D time series movies with [x y frames] as dimensions
% If movies are different sizes, use largest dimensions and align all movies to top-left corner.
% Biafra Ahanonu
% started: 2013.11.01

[outputMovie, movieDims, nPixels, nFrames] = loadMovieList(movieList, 'passArgs', varargin);
end
7 changes: 7 additions & 0 deletions +ciapkg/+api/manageParallelWorkers.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function [success] = manageParallelWorkers(varargin)
% Manages loading and stopping parallel processing workers.
% Biafra Ahanonu
% started: 2015.12.01

[success] = manageParallelWorkers('passArgs', varargin);
end
3 changes: 3 additions & 0 deletions +ciapkg/+api/playMovie.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function [exitSignal, ostruct] = playMovie(inputMovie, varargin)
[exitSignal, ostruct] = playMovie(inputMovie,'passArgs', varargin);
end
119 changes: 119 additions & 0 deletions +ciapkg/+io/loadDependencies.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
function loadDependencies(varargin)
% Download and load CIAtah dependencies.
% Biafra Ahanonu
% started: 2014.07.31
% 2021.02.01 [15:09:46] branched from CIAtah
% branch from calciumImagingAnalysis 2020.05.07 [15:47:29]
% inputs
%
% outputs
%

% changelog
% 2020.05.12 [17:40:37] - Updated to enable GUI-less loading of dependencies. In particular for easier unit testing.
% 2020.06.28 [14:25:04] - Added ability for users to force update.
% 2021.01.22 [13:42:36] - NWB from specific release to reduce compatibility errors.
% 2021.02.01 [15:10:41] - Separated into non-class function for use in more functions without needing to load CIAtah class.
% 2021.02.01 [‏‎15:19:40] - Update `_external_programs` to call ciapkg.getDirExternalPrograms() to standardize call across all functions.
% TODO
% Verify all dependencies download and if not ask user to download again.

%========================
% DESCRIPTION
options.externalProgramsDir = ciapkg.getDirExternalPrograms();
options.guiEnabled = 1;
options.dependencyStr = {'downloadMiji','downloadCnmfGithubRepositories','example_downloadTestData','loadMiji','downloadNeuroDataWithoutBorders'};

options.dispStr = {'Download Fiji (to run Miji)','Download CNMF, CNMF-E, and CVX code.','Download test one- and two photon datasets.','Load Fiji/Miji into MATLAB path.','Download NWB (NeuroDataWithoutBorders)'};
% Int vector: index of options.dependencyStr to run by default with no GUI
options.depIdxArray = [1 2 3 5];
% Binary: 1 = force update even if already downloaded. 0 = skip if already downloaded
options.forceUpdate = 0;
% get options
options = getOptions(options,varargin);
% display(options)
% unpack options into current workspace
% fn=fieldnames(options);
% for i=1:length(fn)
% eval([fn{i} '=options.' fn{i} ';']);
% end
%========================

scnsize = get(0,'ScreenSize');
if ischar(options.dispStr)
options.dispStr = {options.dispStr};
end
if ischar(options.dependencyStr)
options.dependencyStr = {options.dependencyStr};
end
dependencyStr = options.dependencyStr;

dispStr = options.dispStr;
if options.guiEnabled==1
[depIdxArray, ~] = listdlg('ListString',dispStr,'ListSize',[scnsize(3)*0.3 scnsize(4)*0.3],'Name','Which dependencies to load? (Can select multiple)','InitialValue',options.depIdxArray);

forceDownloadVec = [0 1];
[forceUpdate, ~] = listdlg('ListString',{'No - skip installing dependency if already available.','Yes - force update to most recent version of dependency.'},'ListSize',[scnsize(3)*0.3 scnsize(4)*0.3],'Name','Force download/update? (e.g. "Yes" to update dependencies)','InitialValue',[1]);
forceUpdate = forceDownloadVec(forceUpdate);
else
depIdxArray = options.depIdxArray;
forceUpdate = 0;
end
analysisTypeD = dependencyStr(depIdxArray);
dispStr = dispStr(depIdxArray);
for depNo = 1:length(depIdxArray)
disp([10 repmat('>',1,42)])
disp(dispStr{depNo})
switch analysisTypeD{depNo}
case 'downloadCnmfGithubRepositories'
[success] = downloadCnmfGithubRepositories('forceUpdate',forceUpdate);
case 'downloadMiji'
depStr = {'Save Fiji to default directory','Save Fiji to custom directory'};
if options.guiEnabled==1
[depIdxArray, ~] = listdlg('ListString',depStr,'ListSize',[scnsize(3)*0.2 scnsize(4)*0.25],'Name','Where to save Fiji?');
else
depIdxArray = 1;
end
depStr = depStr{depIdxArray};
if depIdxArray==1
downloadMiji();
else
downloadMiji('defaultDir','');
end
% if exist('pathtoMiji','var')
% end
case 'loadMiji'
modelAddOutsideDependencies('miji');
case 'example_downloadTestData'
example_downloadTestData();
case 'downloadCellExtraction'
optionsH.forceUpdate = forceUpdate;
optionsH.signalExtractionDir = options.externalProgramsDir;
optionsH.gitNameDisp = {'cellmax_clean','extract'};
optionsH.gitRepos = {'https://github.com/schnitzer-lab/CELLMax_CLEAN','https://github.com/schnitzer-lab/EXTRACT'};
optionsH.gitRepos = cellfun(@(x) [x '/archive/master.zip'],optionsH.gitRepos,'UniformOutput',false);
optionsH.outputDir = optionsH.gitNameDisp;
optionsH.gitName = cellfun(@(x) [x '-master'],optionsH.gitNameDisp,'UniformOutput',false);
[success] = downloadGithubRepositories('options',optionsH);
case 'downloadNeuroDataWithoutBorders'
optionsH.forceUpdate = forceUpdate;
optionsH.signalExtractionDir = options.externalProgramsDir;
optionsH.gitNameDisp = {'nwb_schnitzer_lab','yamlmatlab','matnwb'};
optionsH.gitRepos = {'https://github.com/schnitzer-lab/nwb_schnitzer_lab','https://github.com/ewiger/yamlmatlab'};

% 'https://github.com/NeurodataWithoutBorders/matnwb'
optionsH.gitRepos = cellfun(@(x) [x '/archive/master.zip'],optionsH.gitRepos,'UniformOutput',false);
optionsH.gitRepos = [optionsH.gitRepos 'https://github.com/NeurodataWithoutBorders/matnwb/archive/v2.2.5.3.zip'];
optionsH.outputDir = optionsH.gitNameDisp;
optionsH.gitName = cellfun(@(x) [x '-master'],optionsH.gitNameDisp,'UniformOutput',false);
optionsH.gitName{end} = 'matnwb-2.2.5.3';
[success] = downloadGithubRepositories('options',optionsH);

% Add NWB folders to path.
ciapkg.nwb.setupNwb;
% obj.loadBatchFunctionFolders;
otherwise
% nothing
end
end
end
6 changes: 3 additions & 3 deletions +ciapkg/+io/updatePkg.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'ciapkg',...
'docs',...
'file_exchange'};
% Char: GitHub API URL to VERSION file on CIAPKG repository.
% [IGNORE] Char: GitHub API URL to VERSION file on CIAPKG repository.
options.versionURL = 'https://api.github.com/repos/bahanonu/calciumImagingAnalysis/contents/ciapkg/VERSION';
% Binary: 1 = pop-up GUI enabled
options.showGui = 1;
Expand Down Expand Up @@ -50,9 +50,9 @@
if verCompare==1
verInfoStr = 'Running most up-to-date version!';
elseif verCompare<1
verInfoStr = 'Running behind! Initiating update.';
verInfoStr = 'Running behind! Initiating update [IGNORE for now].';
elseif verCompare>1
verInfoStr = 'I do not know how, but you are running ahead! [Dev build]';
verInfoStr = 'I do not know how, but you are running a version ahead! [Dev build]';
end

disp(verInfoStr)
Expand Down
4 changes: 2 additions & 2 deletions +ciapkg/+nwb/setupNwb.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
%

% changelog
%
% 2021.02.01 [‏‎15:19:40] - Update `_external_programs` to call ciapkg.getDirExternalPrograms() to standardize call across all functions.
% TODO
%

% ========================
% Str: default path for CIAtah
options.defaultObjDir = ciapkg.getDir;
% Str: default root path where all external programs are stored
options.externalProgramsDir = '_external_programs';
options.externalProgramsDir = ciapkg.getDirExternalPrograms();
% Str: default path for MatNWB Matlab code
options.matnwbDir = 'matnwb';
% get options
Expand Down
35 changes: 35 additions & 0 deletions +ciapkg/getDirExternalPrograms.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function [externalProgramsDir] = getDirExternalPrograms(varargin)
% Returns the directory where external programs are stored. All functions should call this to find external program directory.
% Biafra Ahanonu
% started: 2021.02.02 [10:55:23]
% inputs
%
% outputs
%

% changelog
%
% TODO
%

%========================
% DESCRIPTION
% options.exampleOption = '';
% get options
% options = getOptions(options,varargin);
% display(options)
% unpack options into current workspace
% fn=fieldnames(options);
% for i=1:length(fn)
% eval([fn{i} '=options.' fn{i} ';']);
% end
%========================

try
externalProgramsDir = [ciapkg.getDir() filesep '_external_programs'];
catch err
disp(repmat('@',1,7))
disp(getReport(err,'extended','hyperlinks','on'));
disp(repmat('@',1,7))
end
end
41 changes: 41 additions & 0 deletions +ciapkg/getDirPkg.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function [ciapkgDir] = getDirPkg(dirType,varargin)
% Standardized location to obtain relevant CIAtah directories, e.g. location of default data folder.
% Biafra Ahanonu
% started: 2020.08.31 [12:46:57]
% inputs
%
% outputs
%

% changelog
%
% TODO
%

%========================
% DESCRIPTION
% options.exampleOption = '';
% get options
% options = getOptions(options,varargin);
% display(options)
% unpack options into current workspace
% fn=fieldnames(options);
% for i=1:length(fn)
% eval([fn{i} '=options.' fn{i} ';']);
% end
%========================

try
switch dirType
case 'data'
ciapkgDir = [ciapkg.getDir() filesep 'data'];
otherwise
ciapkgDir = '';
disp('Incorrect input, returning null.')
end
catch err
disp(repmat('@',1,7))
disp(getReport(err,'extended','hyperlinks','on'));
disp(repmat('@',1,7))
end
end
2 changes: 1 addition & 1 deletion +ciapkg/version.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
% versionStr = verStr{1};
% dateTimeStr = num2str(verStr{2});

verStr = readtable([ciapkg.getDir filesep 'ciapkg' filesep 'VERSION'],'ReadVariableNames',0,'FileType','text','Format','auto','TextType','string')
verStr = readtable([ciapkg.getDir filesep 'ciapkg' filesep 'VERSION'],'ReadVariableNames',0,'FileType','text','Format','auto','TextType','string');
versionStr = verStr{1,1}{1};
dateTimeStr = num2str(verStr{2,1}{1});
catch
Expand Down
13 changes: 11 additions & 2 deletions +ciapkg/versionOnline.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [onlineVersion] = versionOnline(varargin)
function [onlineVersion, dateTimeStr] = versionOnline(varargin)
% Obtains the online repository version.
% Biafra Ahanonu
% started: 2020.08.18 [‏‎11:16:56]
Expand All @@ -8,7 +8,7 @@
%

% changelog
%
% 2021.02.02 [13:42:19] - Updated to handle new VERSION file that includes datestamp on 2nd line.
% TODO
%

Expand All @@ -29,6 +29,8 @@

try
success = 0;
onlineVersion = '';
dateTimeStr = '';

% Get version information online
% Get information about specific version file online using GitHub API
Expand All @@ -40,10 +42,17 @@
disp('Could not dowload CIAPKG version information.')
return;
end
if ~isempty(regexp(onlineVersion,'\n'))
onlineVersionTmp = strsplit(onlineVersion,'\n');
onlineVersion = onlineVersionTmp{1};
dateTimeStr = onlineVersionTmp{2};
end
end
success = 1;
catch err
onlineVersion = '';
dateTimeStr = '';
success = 0;
disp(repmat('@',1,7))
disp(getReport(err,'extended','hyperlinks','on'));
disp(repmat('@',1,7))
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ _external_programs/*/
_external_programs/cnmf_current
_external_programs/cnmfe
_external_programs/cvx_rd
_external_programs/matnwb
_external_programs/nwb_schnitzer_lab
_external_programs/yamlmatlab
_external_programs/normcorre

# Signal extraction dependency zips
_external_programs/*.zip
Expand Down
Loading

0 comments on commit afd1405

Please sign in to comment.