example_load_rgc_data.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. function expdata = example_load_rgc_data(varargin)
  2. %
  3. %
  4. %%% example_load_rgc_data %%%
  5. %
  6. %
  7. % This function loads the data for any example cell from the accompanying
  8. % dataset of Khani and Gollisch (2017 and 2021). The dataset is available at:
  9. % https://gin.g-node.org/gollischlab/Khani_and_Gollisch_2021_RGC_spike_trains_chromatic_integration
  10. % and
  11. % https://gin.g-node.org/gollischlab/Khani_and_Gollisch_2017_RGC_spiketrains_for_spatial_contrast_adaptation
  12. % This function first get the path of the downloaded database and then loads
  13. % the frametimes and spike times of a selected ganglion cells from the list
  14. % of avaiable good cells. The list that can be found at list_of_good_cells.txt
  15. % inside each folder of the database.
  16. % example use: 1- example_load_rgc_data();
  17. % 2- example_load_rgc_data('datapath','PATH TO DOWNLOAD FOLDER')
  18. % 3- example_load_rgc_data('datapath','PATH TO DOWNLOAD FOLDER', stimulusnumber, 7)
  19. % 4- example_load_rgc_data('datapath','PATH TO DOWNLOAD FOLDER', cellnumber, 12, clusternumber, 12)
  20. % 4- example_load_rgc_data('datapath','PATH TO DOWNLOAD FOLDER', stimulusnumber, 7, cellnumber, 12, clusternumber, 12)
  21. %
  22. %
  23. % ===============================Inputs====================================
  24. %
  25. % datapath : path to the folder in the database.
  26. % stimulusnumber : number to select the correct stimulus.
  27. % cellnumber : an example cell number from the list of good cells.
  28. % clusternumber : a cluster number for the selected cell.
  29. %
  30. %================================Output====================================
  31. %
  32. % expdata : spiketime, frametimes, stimulus parameters and cell
  33. % id information of the selected cell.
  34. %
  35. % written by Mohammad, 18.02.2021
  36. %--------------------------------------------------------------------------------------------------%
  37. %---------- main-function ----------%
  38. %--------------------------------------------------------------------------------------------------%
  39. % first load the data for an example cell
  40. [dp, stimulusnumber, cellnumber, clusternumber] = select_example_cell(varargin{:});
  41. % now load the date that selected example cell
  42. expdata = load_data_for_selected_cell(dp, stimulusnumber, cellnumber, clusternumber);
  43. expdata.datapath = dp;
  44. expdata.stimulusnumber = stimulusnumber;
  45. expdata.cellnumber = cellnumber;
  46. expdata.clusternumber = clusternumber;
  47. end
  48. %--------------------------------------------------------------------------------------------------%
  49. %---------- sub-functions ----------%
  50. %--------------------------------------------------------------------------------------------------%
  51. function [dp, stimulusnumber, cellnumber, clusternumber] = select_example_cell(varargin)
  52. % first parse the user inputs
  53. p = inputParser(); % check the user options.
  54. p.addParameter('datapath', [], @(x) ischar(x) || isstring(x));
  55. p.addParameter('stimulusnumber', [], @isnumeric);
  56. p.addParameter('cellnumber', [], @isnumeric);
  57. p.addParameter('clusternumber', [], @isnumeric);
  58. p.addParameter('help', false, @(x) islogical(x) || (isnumeric(x) && ismember(x,[0,1])));
  59. p.parse(varargin{:});
  60. % defualt parameters
  61. defpara = p.Results;
  62. if isempty(defpara.datapath)
  63. dp = uigetdir('Select an experiment folder:');
  64. else
  65. dp = defpara.datapath;
  66. end
  67. if isempty(defpara.cellnumber) || isempty(defpara.clusternumber)
  68. listofgoodcells = load([dp,filesep,'list_of_good_cells.txt'],'-ascii');
  69. cellabels = sprintfc('cell %g, cluster %g',listofgoodcells);
  70. if numel(cellabels) > 1
  71. idx = listdlg('PromptString',{'Select an example ganglion cell:'},...
  72. 'SelectionMode','single','ListString',cellabels,'listsize',[250 250]);
  73. else
  74. idx = 1;
  75. end
  76. cellnumber = listofgoodcells(idx,1);
  77. clusternumber = listofgoodcells(idx,2);
  78. else
  79. cellnumber = defpara.cellnumber;
  80. clusternumber = defpara.clusternumber;
  81. end
  82. if isempty(defpara.stimulusnumber)
  83. stimnames = importdata([dp,filesep,'stimuli_names.txt']);
  84. % cinames = stimnames(~(cellfun('isempty',(strfind(stimnames,'_Chromatic_Integration_')))));
  85. % cinames = cinames((cellfun('isempty',(strfind(cinames,'Local')))));
  86. % cinames = cinames((cellfun('isempty',(strfind(cinames,'Grating')))));
  87. cinames = stimnames(~(cellfun('isempty',(strfind(stimnames,'Contrast_Adaptation')))));
  88. if numel(cinames) > 1
  89. idx = listdlg('PromptString',{'Select an example dataset:'},...
  90. 'SelectionMode','single','ListString',cinames,'listsize',[450 100]);
  91. cinames = cinames{idx};
  92. end
  93. stimulusnumber = str2double(extractBefore(cinames,'_'));
  94. else
  95. stimulusnumber = defpara.stimulusnumber;
  96. end
  97. end
  98. %--------------------------------------------------------------------------------------------------%
  99. function expdata = load_data_for_selected_cell(dp, stimnum, cellnum, clusternum)
  100. %
  101. ftfolder = [dp,filesep,'frametimes'];
  102. if ~exist(ftfolder,'dir'), ftfolder = dp; end
  103. rasfolder = [dp,filesep,'spiketimes'];
  104. if ~exist(rasfolder,'dir'), rasfolder = dp; end
  105. paramfolder = [dp,filesep,'stimulusparameters'];
  106. if ~exist(paramfolder,'dir'), paramfolder = dp; end
  107. ftnames = dir([ftfolder, filesep, num2str(stimnum,'%02g'),'*_frametimings.txt']);
  108. rastername = [rasfolder, filesep, sprintf('%d_SP_C%d%02d.txt', stimnum, cellnum, clusternum)];
  109. warning('off','all'); % this is supress the warning about long names, hopefully nothing happen in between these lines!
  110. expdata.spiketimes = load(rastername, '-ascii');
  111. expdata.frametimes = load([ftfolder,filesep,ftnames.name], '-ascii');
  112. stimpath = dir([paramfolder,filesep,num2str(stimnum,'%02g'),'*_parameters.txt']);
  113. % now reading the txt file with parameters
  114. fid = fopen([paramfolder,filesep,stimpath.name]);
  115. tline = fgetl(fid);
  116. while ischar(tline)
  117. tline = fgetl(fid);
  118. if tline == -1, break; end
  119. fn = extractBefore(tline,' = ');
  120. if isempty(fn), continue; end
  121. val = extractAfter(tline,' = ');
  122. % to convert to double
  123. if ~isnan(str2double(val))
  124. val = str2double(val);
  125. end
  126. % to convert to logical
  127. if strcmp(val,'true'), val = true; end
  128. if strcmp(val,'false'), val = false; end
  129. % store the values in a structure
  130. stimpara.(fn) = val;
  131. end
  132. fclose(fid);
  133. expdata.stimpara = stimpara;
  134. expdata.name = extractBefore(ftnames.name,'_frametimings.txt');
  135. expdata.paraname = extractBefore(stimpath.name,'_parameters.txt');
  136. if strcmp(expdata.name , expdata.paraname)
  137. expdata = rmfield(expdata,'paraname');
  138. end
  139. warning('on','all');
  140. end
  141. %--------------------------------------------------------------------------------------------------%