example_load_rgc_data.m 7.1 KB

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