MakeCT1NeuronsRFs_Fig5.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. close all;
  2. clear all;
  3. clc;
  4. %% Define search path.
  5. parentDir = fileparts(fileparts(mfilename('fullpath')));
  6. saveFolder = [parentDir filesep 'data'];
  7. load([saveFolder filesep 'Fig5-CT1-processedTableWithBackgroundOnOff'], 'ProcessedTable');
  8. %%
  9. figDir = [parentDir filesep 'figures' filesep 'Fig5' filesep];
  10. if ~exist(figDir, 'dir')
  11. mkdir(figDir);
  12. end
  13. %%
  14. % Stimuli of interest.
  15. stimSetCellStr = getStimSetCellStr(2);
  16. %% Split table into cell types.
  17. tokens = arrayfun(@(x) regexp(x, '.*CT(\d).*', 'tokens'), ProcessedTable.timeSeriesPath);
  18. cellTypeNumArray = cellfun(@(x) str2num(x{1}{1}), tokens);
  19. cellTypeNum = unique(cellTypeNumArray);
  20. for iNeuron = 1: numel(cellTypeNum)
  21. StimTableNeuronCell{iNeuron} = ProcessedTable(cellTypeNumArray == cellTypeNum(iNeuron), :);
  22. end
  23. %%
  24. stimInd = 1;
  25. nStims = numel(stimSetCellStr);
  26. for iNeuron = 1: numel(cellTypeNum)
  27. for jStim = 1: nStims
  28. StimTableNeuronStim{iNeuron, jStim} = getStimSubsetTable(StimTableNeuronCell{iNeuron}, stimSetCellStr, jStim);
  29. end
  30. end
  31. for iFly = 1: numel(unique(ProcessedTable.flyInd))
  32. flyIndsCell = ProcessedTable.flyInd == iFly;
  33. flyStims = ProcessedTable(flyIndsCell, :).stimParamFileName;
  34. % Find if stim is within the chosen subset.
  35. flyStimInds{iFly} = (cellfun(@(x) find(strcmp(x, stimSetCellStr)), flyStims, 'uni', 0));
  36. % If it contains stimuli, check that it includes the 5 chosen.
  37. if ~isempty(flyStimInds{iFly})
  38. setDiff{iFly} = setdiff(1: 5, [flyStimInds{iFly}{:}]);
  39. else
  40. setDiff{iFly} = -1;
  41. end
  42. % For flies with all chosen stimuli order the table accordingly.
  43. if isempty(setDiff{iFly})
  44. sortFlyIndsTemp = find(flyIndsCell);
  45. [~, sortInd] = sort([flyStimInds{iFly}{:}]);
  46. sortFlyInds{iFly} = sortFlyIndsTemp(sortInd);
  47. end
  48. end
  49. StimOrderedTable = ProcessedTable(vec([sortFlyInds{:}]), :);
  50. %% Split table into cell types.
  51. tokens = arrayfun(@(x) regexp(x, '.*CT(\d).*', 'tokens'), StimOrderedTable.timeSeriesPath);
  52. cellTypeNumArray = cellfun(@(x) str2num(x{1}{1}), tokens);
  53. cellTypeNum = unique(cellTypeNumArray);
  54. for iNeuron = 1: numel(cellTypeNum)
  55. StimTableNeuronCell{iNeuron} = StimOrderedTable(cellTypeNumArray == cellTypeNum(iNeuron), :);
  56. end
  57. %%
  58. nStims = numel(stimSetCellStr);
  59. for iNeuron = 1: numel(cellTypeNum)
  60. for jStim = 1: nStims
  61. StimTableNeuronStim{iNeuron, jStim} = getStimSubsetTable(StimTableNeuronCell{iNeuron}, stimSetCellStr, jStim);
  62. end
  63. end
  64. %% Now can use this table cell array into the other functions.
  65. StimTable = ProcessedTable;
  66. StimSubTablesCell = arrayfun(@(x) getStimSubsetTable(ProcessedTable, ...
  67. stimSetCellStr, x), ...
  68. 1: numel(stimSetCellStr), 'uni', 0);
  69. %% Plot tuning curves. Do not discard the on.
  70. alignToOff = true;
  71. alignToAll = false;
  72. respQualityThreshold = 0.5;
  73. rSquareThreshold = 0.2;
  74. padWithNaNs = 0;
  75. qualityMeasure = 'responseQuality';
  76. %% Make Figure 5b-d
  77. cellTypeStr = {'CT1'};
  78. receptiveFields = plotRFsAlignedWithFitGenotypes(StimTableNeuronStim(:, 2: end), -20.0, 0, figDir, [cellTypeStr{:}]);
  79. %% Export data from Figure 5b-d
  80. dataFileName = [figDir filesep 'Fig5.xls'];
  81. sheetNamesCell = {'b-d'};
  82. stimNameStrCell = {'_OFF_horizontal_position_deg', '_OFF_vertical_position_deg', ...
  83. '_ON_horizontal_position_deg', '_ON_vertical_position_deg'};
  84. for iCellType = 1: numel(cellTypeStr)
  85. startRow = 1;
  86. sheetName = ['Fig5' sheetNamesCell{iCellType}];
  87. for iStim = 1: 4
  88. parameterLabel = [cellTypeStr{iCellType} stimNameStrCell{iStim}];
  89. DataTable = createRFsTable(receptiveFields{iCellType, iStim}, parameterLabel);
  90. writetable(DataTable, dataFileName, 'Sheet', sheetName, 'Range', ['A' num2str(startRow)]);
  91. startRow = startRow + size(DataTable, 1) + 2;
  92. end
  93. end
  94. %% Inline from plotRFsAlignedWithFitGenotypes
  95. respQualityThreshold = 0.5;
  96. rSquareThreshold = 0.2;
  97. respIndThresh = respQualityThreshold;
  98. rSqThresh = rSquareThreshold;
  99. % rSqThresh = -20;
  100. for iNeuron = 1: size(StimTableNeuronStim(:, 2: end), 1)
  101. StimTableCell = StimTableNeuronStim(iNeuron, 2: end);
  102. [~, responseIndArrayCell, rSquareArrayCell, fitParamsCell, ...
  103. flyIndsCell, ~, ~] = getStimArraysForSameRois(StimTableCell);
  104. % Align to fit
  105. widthCell{iNeuron} = cellfun(@(x) arrayfun(@(y) 2 * (2 * sqrt(log(2))) * y.c1, x, 'uni', 0), ...
  106. fitParamsCell, 'uni', 1); % The 2 factor is because of bar separation.
  107. validIndsCell{iNeuron} = cellfun(@(x, y) x(:) > rSqThresh & y(:) > respIndThresh, ...
  108. rSquareArrayCell, responseIndArrayCell, 'uni', 0)';
  109. end
  110. %%
  111. validOffInds = cellfun(@(x) x{1} & x{2}, validIndsCell, 'uni', 0);
  112. validOnInds = cellfun(@(x) x{3} & x{4}, validIndsCell, 'uni', 0);
  113. %%
  114. widthCell = cellfun(@(x) cat(1, x{:}), widthCell, 'uni', 0);
  115. %%
  116. xOFFWidth = cellfun(@(x, y) x(1, y), widthCell, validOffInds, 'uni', 0);
  117. yOFFWidth = cellfun(@(x, y) x(2, y), widthCell, validOffInds, 'uni', 0);
  118. xONWidth = cellfun(@(x, y) x(3, y), widthCell, validOnInds, 'uni', 0);
  119. yONWidth = cellfun(@(x, y) x(4, y), widthCell, validOnInds, 'uni', 0);
  120. allWidthsCell = {xOFFWidth, yOFFWidth, xONWidth, yONWidth};
  121. %%
  122. for iW = 1: numel(allWidthsCell)
  123. allWidthsCell{iW}(cellfun(@isempty, allWidthsCell{iW}, 'uni', 1)) = {pi};
  124. end
  125. %%
  126. hFig = createPrintFig(15 * [ 1 1/4]);
  127. colors = brewermap(4, 'Set1');
  128. colors = colors([1, 2, 4, 3], :);
  129. for iAx = 1: numel(allWidthsCell)
  130. hSubAx(iAx) = subplot(1, 4, iAx);
  131. hWidthAx = beanPlot(allWidthsCell{iAx}, cellTypeStr, colors, ...
  132. 1, gca, [0-eps 100], 'vertical', 0, 1, 0);
  133. end
  134. linkaxes(hSubAx, 'y');
  135. setFontForThesis(hWidthAx, gcf);
  136. arrayfun(@prettifyAxes, hWidthAx)
  137. arrayfun(@offsetAxes, hWidthAx)
  138. figFileName = ['RF-FWHM-bean'];
  139. % figFileName = ['RF-FWHM-bean_rSq-20_respInd0.5'];
  140. print(hFig, [figDir figFileName '.pdf'], '-dpdf')
  141. %% Export data from figure 5bc FWHM distributions
  142. dataFileName = [figDir filesep 'Fig5.xls'];
  143. stimNameStrCell = {'_OFF_bars_horizontal_deg', '_OFF_bars_vertical_deg', ...
  144. '_ON_bars_horizontal_deg', '_ON_bars_vertical_deg'};
  145. sheetName = ['Fig5b-d'];
  146. for iCellType = 1: numel(cellTypeStr)
  147. for iStim = 1: 4
  148. parameterLabel = [cellTypeStr{iCellType} '_FWHM' stimNameStrCell{iStim}];
  149. xlswrite(dataFileName, {parameterLabel}, sheetName, ['A' num2str(startRow)])
  150. if allWidthsCell{iStim}{iCellType} == pi % pi was placeholder for no data
  151. xlswrite(dataFileName, {''}, sheetName, ['B' num2str(startRow)])
  152. else
  153. xlswrite(dataFileName, allWidthsCell{iStim}{iCellType}, sheetName, ['B' num2str(startRow)])
  154. end
  155. startRow = startRow + 1;
  156. end
  157. startRow = startRow + 1;
  158. end