Skip to content

Commit

Permalink
Merge pull request #90 from bahanonu/bahanonu/functionUpdates
Browse files Browse the repository at this point in the history
CIAtah 4.0 and NWB compatibility updates, remove unused File Exchange, etc.
  • Loading branch information
bahanonu committed Nov 11, 2021
2 parents 70da014 + df0ef0a commit ed76732
Show file tree
Hide file tree
Showing 387 changed files with 184 additions and 37,306 deletions.
2 changes: 1 addition & 1 deletion +ciapkg/+api/loadNeurodataWithoutBorders.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
% infoStruct - contains information about the file, e.g. the 'description' property that can contain information about the algorithm.
% algorithmStr - String of the algorithm name.

[inputImages,inputTraces,infoStruct, algorithmStr] = ciapkg.io.loadNeurodataWithoutBorders(inputFilePath,'passArgs', varargin);
[inputImages,inputTraces,infoStruct, algorithmStr] = ciapkg.nwb.loadNeurodataWithoutBorders(inputFilePath,'passArgs', varargin);
end
2 changes: 1 addition & 1 deletion +ciapkg/+api/saveNeurodataWithoutBorders.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
% TODO
%

[success] = ciapkg.io.saveNeurodataWithoutBorders(image_masks,roi_response_data,algorithm,outputFilePath,'passArgs', varargin);
[success] = ciapkg.nwb.saveNeurodataWithoutBorders(image_masks,roi_response_data,algorithm,outputFilePath,'passArgs', varargin);
end
16 changes: 16 additions & 0 deletions +ciapkg/+api/saveNwbMovie.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function [success] = saveNwbMovie(inputData,fileSavePath,varargin)
% Saves input matrix into NWB format output file.
% Biafra Ahanonu
% started: 2020.05.28 [09:51:52]
% inputs
%
% outputs
%

% changelog
%
% TODO
% Add structure that allows users to modify defaults for all the NWB settings

[success] = ciapkg.nwb.saveNwbMovie(inputData,fileSavePath,'passArgs', varargin);
end
17 changes: 17 additions & 0 deletions +ciapkg/+api/setupNwb.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function [success] = setupNwb(varargin)
% Checks that NWB code is present and setup correctly.
% Biafra Ahanonu
% started: 2021.01.24 [14:31:24]
% inputs
%
% outputs
%

% changelog
% 2021.02.01 [‏‎15:19:40] - Update `_external_programs` to call ciapkg.getDirExternalPrograms() to standardize call across all functions.
% 2021.03.26 [06:27:48] - Fix for options.defaultObjDir leading to incorrect NWB folder and cores not being generated.
% TODO
%

[success] = ciapkg.nwb.setupNwb('passArgs', varargin);
end
12 changes: 7 additions & 5 deletions +ciapkg/+io/loadDependencies.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function loadDependencies(varargin)

options.dispStr = {'Download Turboreg (motion correction)','Download ImageJ','Download CNMF, CNMF-E, and CVX code.','Download test one- and two photon datasets.','Download NWB (NeuroDataWithoutBorders)','Download EXTRACT','Download Bio-Formats','Download gramm (GRAMmar of graphics for Matlab, e.g. ggplot2-like)','Download NoRMCorre (motion correction)','Download Fiji (to run Miji)','Load Fiji/Miji into MATLAB path.'};
% Int vector: index of options.dependencyStr to run by default with no GUI
options.depIdxArray = [1 2 3 4 5 6 7];
options.depIdxArray = [1 2 3 4 5 6 7 8];
% Binary: 1 = force update even if already downloaded. 0 = skip if already downloaded
options.forceUpdate = 0;
% get options
Expand Down Expand Up @@ -146,19 +146,21 @@ function loadDependencies(varargin)
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'};

optionsH.gitNameDisp = {'nwbpkg','yamlmatlab','matnwb'};
optionsH.gitRepos = {'https://github.com/schnitzer-lab/nwbpkg','https://github.com/ewiger/yamlmatlab'};
% 'https://github.com/NeurodataWithoutBorders/matnwb'
optionsH.gitRepos = cellfun(@(x) [x '/archive/master.zip'],optionsH.gitRepos,'UniformOutput',false);

% Add matnwb
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;
ciapkg.nwb.setupNwb('checkDependencies',0);
% obj.loadBatchFunctionFolders;
case 'downloadBioFormats'
optionsH.forceUpdate = forceUpdate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [inputImages,inputTraces,infoStruct, algorithmStr] = loadNeurodataWithoutBorders(inputFilePath,varargin)
% DESCRIPTION.
% Load NWB file containing cell-extraction data.
% Biafra Ahanonu
% started: 2020.04.04 [15:02:22]
% inputs
Expand Down Expand Up @@ -47,6 +47,9 @@
%========================

try
% Check that NWB code is downloaded and setup.
ciapkg.api.setupNwb('checkDependencies',1);

inputImages = [];
inputTraces = [];
infoStruct = struct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
% 2021.02.03 [12:34:06] - Added a check for inputs with a single signal and function returns as it is not supported.
% 2021.03.20 [19:35:28] - Update to checking if only a single signal input.
% 2021.08.08 [19:30:20] - Updated to handle CIAtah v4.0 switch to all functions inside ciapkg package.
% 2021.11.08 [11:52:13] - Added nwbpkg support.
% TODO
%

import ciapkg.api.* % import CIAtah functions in ciapkg package API.

%========================
% DESCRIPTION
options.fpathYML = [ciapkg.getDirExternalPrograms() filesep 'nwb_schnitzer_lab' filesep 'ExampleMetadata.yml'];
options.fpathYML = [ciapkg.getDirExternalPrograms() filesep 'nwbpkg' filesep '+nwbpkg' filesep 'ExampleMetadata.yml'];
% get options
options = getOptions(options,varargin);
% display(options)
Expand All @@ -39,37 +40,11 @@

success = 0;

try
% Check that all necessary files are loaded
loadDependenciesFlag = 0;
if length(which('yaml.ReadYaml'))==0
disp('yaml not loaded, loading now...')
loadDependenciesFlag = 1;
end
if length(which('get_input_args'))==0
disp('matnwb not loaded, loading now...')
loadDependenciesFlag = 1;
end
if length(which('add_processed_ophys'))==0
disp('nwb_schnitzer_lab not loaded, loading now...')
loadDependenciesFlag = 1;
end
if loadDependenciesFlag==1
ciapkg.io.loadDependencies(...
'guiEnabled',0,...
'depIdxArray',5,...
'forceUpdate',0);
% 'dependencyStr','downloadNeuroDataWithoutBorders',...
% 'dispStr','Download NWB (NeuroDataWithoutBorders)',...
ciapkg.loadDirs;
end
catch err
disp(repmat('@',1,7))
disp(getReport(err,'extended','hyperlinks','on'));
disp(repmat('@',1,7))
end

try
% Check that NWB code is downloaded and setup.
ciapkg.api.setupNwb('checkDependencies',1);

metadata = yaml.ReadYaml(options.fpathYML);
data_path = outputFilePath;

Expand Down Expand Up @@ -119,15 +94,15 @@
roi_response_data.(['ROI_' num2str(i)]) = tmpData{i};
end

nwbfile_input_args = get_input_args(metadata, 'NWBFile');
nwbfile_input_args = nwbpkg.get_input_args(metadata, 'NWBFile');
% Convert to ISO 8601 format
nwbfile_input_args{4} = datestr(nwbfile_input_args{4}, 'yyyy-mm-dd HH:MM:SS');
nwb = NwbFile(nwbfile_input_args{:});

subject_input_args = get_input_args(metadata, 'Subject');
subject_input_args = nwbpkg.get_input_args(metadata, 'Subject');
nwb.general_subject = types.core.Subject(subject_input_args{:});

nwb = add_processed_ophys(nwb, metadata, image_masks, roi_response_data,data_type);
nwb = nwbpkg.add_processed_ophys(nwb, metadata, image_masks, roi_response_data,data_type);

% Remove previous file if it already exists
if exist(outputFilePath,'file')==2
Expand Down
15 changes: 12 additions & 3 deletions +ciapkg/+nwb/saveNwbMovie.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [output1,output2] = saveNwbMovie(inputData,fileSavePath,varargin)
% Saves input matrix into NWB format
function [success] = saveNwbMovie(inputData,fileSavePath,varargin)
% Saves input matrix into NWB format output file.
% Biafra Ahanonu
% started: 2020.05.28 [09:51:52]
% inputs
Expand All @@ -8,10 +8,12 @@
%

% changelog
%
% 2021.08.10 [09:57:36] - Updated to handle CIAtah v4.0 switch to all functions inside ciapkg package.
% TODO
% Add structure that allows users to modify defaults for all the NWB settings

import ciapkg.api.* % import CIAtah functions in ciapkg package API.

%========================
% old way of saving, only temporary until full switch
options.datasetname = '/1';
Expand Down Expand Up @@ -42,6 +44,11 @@
%========================

try
success = 0;

% Check that NWB code is downloaded and setup.
ciapkg.api.setupNwb('checkDependencies',1);

if strcmp(options.writeMode,'new')
if exist(fileSavePath,'file')==2
fprintf('Deleting: %s.\n',fileSavePath)
Expand Down Expand Up @@ -151,6 +158,8 @@
end
end

success = 1;

catch err
disp(repmat('@',1,7))
disp(getReport(err,'extended','hyperlinks','on'));
Expand Down
44 changes: 41 additions & 3 deletions +ciapkg/+nwb/setupNwb.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function [success] = setupNwb(varargin)
% DESCRIPTION.
% Checks that NWB code is present and setup correctly.
% Biafra Ahanonu
% started: INSERT_DATE
% started: 2021.01.24 [14:31:24]
% inputs
%
% outputs
Expand All @@ -10,6 +10,8 @@
% changelog
% 2021.02.01 [‏‎15:19:40] - Update `_external_programs` to call ciapkg.getDirExternalPrograms() to standardize call across all functions.
% 2021.03.26 [06:27:48] - Fix for options.defaultObjDir leading to incorrect NWB folder and cores not being generated.
% 2021.11.07 [16:13:44] - Update to include check for each of the NWB dependencies taken from saveNeurodataWithoutBorders.
% 2021.11.08 [11:52:13] - Added nwbpkg support.
% TODO
%

Expand All @@ -20,8 +22,10 @@
options.externalProgramsDir = ciapkg.getDirExternalPrograms();
% Str: default path for MatNWB Matlab code
options.matnwbDir = 'matnwb';
% Binary: 0 = skip the first check to prevent infinite loop during initial package setup
options.checkDependencies = 0;
% get options
options = getOptions(options,varargin);
options = ciapkg.api.getOptions(options,varargin);
% display(options)
% unpack options into current workspace
% fn=fieldnames(options);
Expand All @@ -32,6 +36,40 @@

try
success = 0;
try
if options.checkDependencies==1
% Check that all necessary files are loaded
loadDependenciesFlag = 0;
if length(which('yaml.ReadYaml'))==0
disp('yaml not loaded, loading now...')
loadDependenciesFlag = 1;
end
if length(which('NwbFile'))==0
disp('matnwb not loaded, loading now...')
loadDependenciesFlag = 1;
end
if length(which('nwbpkg.add_processed_ophys'))==0
disp('nwb_schnitzer_lab not loaded, loading now...')
loadDependenciesFlag = 1;
end
if loadDependenciesFlag==1&options.checkDependencies==1
ciapkg.io.loadDependencies(...
'guiEnabled',0,...
'depIdxArray',5,...
'forceUpdate',0);
% 'dependencyStr','downloadNeuroDataWithoutBorders',...
% 'dispStr','Download NWB (NeuroDataWithoutBorders)',...
ciapkg.loadDirs;
else
disp('NWB dependencies loaded.')
end
end
catch err
disp(repmat('@',1,7))
disp(getReport(err,'extended','hyperlinks','on'));
disp(repmat('@',1,7))
end

% Load NWB Schema as needed
if exist('types.core.Image')==0
try
Expand Down
4 changes: 2 additions & 2 deletions +ciapkg/VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
v4.0.0
2021.08.10 [12:54:03]
v4.0.2
2021.11.09 [19:55:19]
Loading

0 comments on commit ed76732

Please sign in to comment.