parse_input_peakfun.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. function [file_nums, varargout] = ...
  2. parse_input_peakfun(files, varargin)
  3. %% Input parser for self-written data analysis functions
  4. % This function parses the input for functions used for analysing double
  5. % recordings. It is checked whether the inputs are valid to ensure that
  6. % the functions calling this input parser work properly. If the input is
  7. % not suitable an appropriate error message is displayed. A file number is
  8. % always needed, the other arguments are optional.
  9. % -------------------------------------------------------------------------
  10. % Input [additional arguments are positional,
  11. % ----- optional arguments are name-value pairs]
  12. %
  13. % files: ID(s) of the '.mat' file(s) in the directory used by
  14. % the 'extract_data' function
  15. % trials: number(s) of the trials to be analysed, type: integer
  16. % (additional) or vector, default: 'all'
  17. % Filter: select between three filter options:
  18. % (optional) 'hn' applys a hum-noise-remove filter
  19. % 'hnhfn' additonally applys a low pass filter to
  20. % remove high frequency noise
  21. % If not set, it will be set to "no" (default).
  22. % Tolerance: tolerance value for data selection in ms. Default 50 ms
  23. % (optional)
  24. % MinPeakPromT: value for 'MinPeakProminence' which is used in the
  25. % (optional) 'findpeaks' function to find T cell peaks.
  26. % Type: float. Default: 15
  27. % StimCell: set whether the data for the stimulated T cell or
  28. % (optional) the stimulated interneuron should be used.
  29. % 'INT' for interneuron stimulated
  30. % 'T' for T-cell stimulated (default)
  31. % ErrorBars: set whether error bars (standard deviation) should be
  32. % (optional) plotted (1) or not (0). Default: 1
  33. % Stimuli: select which stimuli should be used in a function
  34. % (optional) selection between the given stimuli by their
  35. % current. Type: float or vector or 'all'.
  36. % Default: 'all'
  37. % PlotFlag: set whether specific functions should create plots (1)
  38. % (optional) not (0). Default: 0.
  39. % ------
  40. % Output
  41. % ------
  42. % parsed version of the input, in detail:
  43. % 1. file_num
  44. % 2. (additional) trials
  45. % 3. (optional) filter_choice
  46. % 4. (optional) tol: tolerance
  47. % 5. (optional) MinPeakPromT
  48. % 6. (optional) StimCell
  49. % 7. (optional) ErrorBars
  50. % 8. (optional) Stimuli
  51. % 9. (optional) PlotFlag
  52. % -------------------------------------------------------------------------
  53. % Program by Bjarne Schultze [last modified 02.03.2022]
  54. % -------------------------------------------------------------------------
  55. % set default and possible values for input parameters
  56. default_filter = "no"; % no filter
  57. possible_filters = ["no","hn","hnhfn"]; % three possible filter options
  58. default_tol = 0.05; % 50 ms tolerance
  59. default_MinPeakPromT = 17; % for a T-cell
  60. default_StimCell = "T"; % data with stimulated T-cell
  61. possible_stimCells = ["T", "INT"]; % two possible stim cell options
  62. default_errorbars = 1; % error bars will be plotted
  63. possible_stimuli = [-2,-1,-0.5,0.03125,0.0625,0.125,0.25,0.5,0.75,1,...
  64. 1.25,1.5]; % possible stimuli to select from
  65. % handle to anonymous function for validating input: vector input
  66. valid_in_vector = @(x) isnumeric(x) && isvector(x) && ...
  67. isequal(length(x),sum(x>0));
  68. % handle to anonymous function for validating input: scalar input
  69. valid_in_scalar = @(x) (x>0) && isscalar(x) && isnumeric(x);
  70. % specify the input arguments
  71. p = inputParser;
  72. addRequired(p, 'files', valid_in_vector);
  73. addOptional(p, 'trials', 'all', valid_in_vector);
  74. addParameter(p, 'Filter', default_filter, ...
  75. @(x) ~isempty(validatestring(x, possible_filters)));
  76. addParameter(p, 'Tolerance', default_tol, ...
  77. @(x) (x>=0) && isscalar(x) && isnumeric(x));
  78. addParameter(p, 'MinPeakPromT', default_MinPeakPromT, valid_in_scalar);
  79. addParameter(p, 'StimCell', default_StimCell, ...
  80. @(x) ~isempty(validatestring(x, possible_stimCells)));
  81. addParameter(p, 'ErrorBars', default_errorbars, @(x) (x==0) || (x==1));
  82. addParameter(p, 'Stimuli', 'all', ...
  83. @(x) length(intersect(x,possible_stimuli)) == length(x));
  84. addParameter(p, 'PlotFlag', 0, @(x) isequal(x,1) || isequal(x,0));
  85. % parse the input
  86. parse(p, files, varargin{:});
  87. % assign the parsing results to the output variables
  88. file_nums = p.Results.files;
  89. varargout{1} = p.Results.trials;
  90. varargout{2} = p.Results.Filter;
  91. varargout{3} = p.Results.Tolerance;
  92. varargout{4} = p.Results.MinPeakPromT;
  93. varargout{5} = p.Results.StimCell;
  94. varargout{6} = p.Results.ErrorBars;
  95. varargout{7} = p.Results.Stimuli;
  96. varargout{8} = p.Results.PlotFlag;
  97. % end of function definition
  98. end