123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- function [file_nums, varargout] = ...
- parse_input_peakfun(files, varargin)
- %% Input parser for self-written data analysis functions
- % This function parses the input for functions used for analysing double
- % recordings. It is checked whether the inputs are valid to ensure that
- % the functions calling this input parser work properly. If the input is
- % not suitable an appropriate error message is displayed. A file number is
- % always needed, the other arguments are optional.
- % -------------------------------------------------------------------------
- % Input [additional arguments are positional,
- % ----- optional arguments are name-value pairs]
- %
- % files: ID(s) of the '.mat' file(s) in the directory used by
- % the 'extract_data' function
- % trials: number(s) of the trials to be analysed, type: integer
- % (additional) or vector, default: 'all'
- % Filter: select between three filter options:
- % (optional) 'hn' applys a hum-noise-remove filter
- % 'hnhfn' additonally applys a low pass filter to
- % remove high frequency noise
- % If not set, it will be set to "no" (default).
- % Tolerance: tolerance value for data selection in ms. Default 50 ms
- % (optional)
- % MinPeakPromT: value for 'MinPeakProminence' which is used in the
- % (optional) 'findpeaks' function to find T cell peaks.
- % Type: float. Default: 15
- % StimCell: set whether the data for the stimulated T cell or
- % (optional) the stimulated interneuron should be used.
- % 'INT' for interneuron stimulated
- % 'T' for T-cell stimulated (default)
- % ErrorBars: set whether error bars (standard deviation) should be
- % (optional) plotted (1) or not (0). Default: 1
- % Stimuli: select which stimuli should be used in a function
- % (optional) selection between the given stimuli by their
- % current. Type: float or vector or 'all'.
- % Default: 'all'
- % PlotFlag: set whether specific functions should create plots (1)
- % (optional) not (0). Default: 0.
- % ------
- % Output
- % ------
- % parsed version of the input, in detail:
- % 1. file_num
- % 2. (additional) trials
- % 3. (optional) filter_choice
- % 4. (optional) tol: tolerance
- % 5. (optional) MinPeakPromT
- % 6. (optional) StimCell
- % 7. (optional) ErrorBars
- % 8. (optional) Stimuli
- % 9. (optional) PlotFlag
- % -------------------------------------------------------------------------
- % Program by Bjarne Schultze [last modified 02.03.2022]
- % -------------------------------------------------------------------------
- % set default and possible values for input parameters
- default_filter = "no"; % no filter
- possible_filters = ["no","hn","hnhfn"]; % three possible filter options
- default_tol = 0.05; % 50 ms tolerance
- default_MinPeakPromT = 17; % for a T-cell
- default_StimCell = "T"; % data with stimulated T-cell
- possible_stimCells = ["T", "INT"]; % two possible stim cell options
- default_errorbars = 1; % error bars will be plotted
- possible_stimuli = [-2,-1,-0.5,0.03125,0.0625,0.125,0.25,0.5,0.75,1,...
- 1.25,1.5]; % possible stimuli to select from
- % handle to anonymous function for validating input: vector input
- valid_in_vector = @(x) isnumeric(x) && isvector(x) && ...
- isequal(length(x),sum(x>0));
- % handle to anonymous function for validating input: scalar input
- valid_in_scalar = @(x) (x>0) && isscalar(x) && isnumeric(x);
- % specify the input arguments
- p = inputParser;
- addRequired(p, 'files', valid_in_vector);
- addOptional(p, 'trials', 'all', valid_in_vector);
- addParameter(p, 'Filter', default_filter, ...
- @(x) ~isempty(validatestring(x, possible_filters)));
- addParameter(p, 'Tolerance', default_tol, ...
- @(x) (x>=0) && isscalar(x) && isnumeric(x));
- addParameter(p, 'MinPeakPromT', default_MinPeakPromT, valid_in_scalar);
- addParameter(p, 'StimCell', default_StimCell, ...
- @(x) ~isempty(validatestring(x, possible_stimCells)));
- addParameter(p, 'ErrorBars', default_errorbars, @(x) (x==0) || (x==1));
- addParameter(p, 'Stimuli', 'all', ...
- @(x) length(intersect(x,possible_stimuli)) == length(x));
- addParameter(p, 'PlotFlag', 0, @(x) isequal(x,1) || isequal(x,0));
- % parse the input
- parse(p, files, varargin{:});
- % assign the parsing results to the output variables
- file_nums = p.Results.files;
- varargout{1} = p.Results.trials;
- varargout{2} = p.Results.Filter;
- varargout{3} = p.Results.Tolerance;
- varargout{4} = p.Results.MinPeakPromT;
- varargout{5} = p.Results.StimCell;
- varargout{6} = p.Results.ErrorBars;
- varargout{7} = p.Results.Stimuli;
- varargout{8} = p.Results.PlotFlag;
- % end of function definition
- end
|