plotRFsAlignedWithFit.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. function plotRFsAlignedWithFit(StimTableCell, rSqThresh, respIndThresh, figDir, nameSuffix, varargin)
  2. if nargin > 5
  3. alignAll = varargin{1};
  4. else
  5. alignAll = false;
  6. end
  7. % [tcArrayCell, responseIndArrayCell, rSquareArrayCell, fitParamsCell, ...
  8. % tcExtCellArray, tcArgExtCellArray] = cellfun(@getTuningCurveArrayFromTable, ...
  9. % StimTableCell, 'uni', 0);
  10. [tcArrayCell, responseIndArrayCell, rSquareArrayCell, fitParamsCell, ...
  11. flyIndsCell, tcExtCellArray, tcArgExtCellArray] = getStimArraysForSameRois(StimTableCell);
  12. % Align to fit
  13. posCell = cellfun(@(x) arrayfun(@(y) y.b1, x, 'uni', 0), fitParamsCell, 'uni', 1);
  14. widthCell = cellfun(@(x) arrayfun(@(y) 2 * (2 * sqrt(log(2))) * y.c1, x, 'uni', 0), ...
  15. fitParamsCell, 'uni', 1); % The 2 factor is because of bar separation.
  16. lagsCell = cellfun(@(x, y) round(x - size(y, 2) / 2), posCell, tcArrayCell, 'uni', 0);
  17. barRFs = cellfun(@(x, y) alignRFsToAbsMax(x, 0, y'), tcArrayCell, lagsCell, 'uni', 0);
  18. validIndsCell = cellfun(@(x, y) x(:) > rSqThresh & y(:) > respIndThresh, ...
  19. rSquareArrayCell, responseIndArrayCell, 'uni', 0)';
  20. %% Blank epoch was already deleted, now delete vertical bars on edges of screen.
  21. barRFs{2}(:, end-1: end) = [];
  22. barRFs{4}(:, end-1: end) = [];
  23. barRFs{2}(:, 1: 2) = [];
  24. barRFs{4}(:, 1: 2) = [];
  25. %%
  26. if alignAll
  27. validAll = validIndsCell{1} & validIndsCell{2} & ...
  28. validIndsCell{3} & validIndsCell{4};
  29. offX = barRFs{1}(validAll, :);
  30. offY = barRFs{2}(validAll, :);
  31. onX = barRFs{3}(validAll, :);
  32. onY = barRFs{4}(validAll, :);
  33. else
  34. offX = barRFs{1}(validIndsCell{1}&validIndsCell{2}, :);
  35. offY = barRFs{2}(validIndsCell{2}&validIndsCell{1}, :);
  36. onX = barRFs{3}(validIndsCell{3}&validIndsCell{4}, :);
  37. onY = barRFs{4}(validIndsCell{4}&validIndsCell{3}, :);
  38. end
  39. % normalize to peak and smooth and normalize again.
  40. maxNorm = @(x, dim) x ./ max(abs(x), [], dim);
  41. getRow = @(x, nRow) x(nRow, :);
  42. normRFs = cellfun(@(x) cell2mat(arrayfun(@(y) smooth(getRow(maxNorm(x,2), y))', 1: size(x, 1), 'uni', 0)'), ...
  43. {offX, offY, onX, onY}, 'uni', 0);
  44. normRFs = cellfun(@(x) maxNorm(x,2), normRFs, 'uni', 0);
  45. %%
  46. % Plot lasagna plots, separate figures for off and on, and reapeated panel
  47. % is to have a colorbar that does not distort existing axis of interest.
  48. plotLasagnaRFs(offX, offY, 'OFF')
  49. plotLasagnaRFs(onX, onY, 'ON')
  50. function plotLasagnaRFs(xRFs, yRFs, polarityStr)
  51. %% Plot traces and average above colormap of single cell responses
  52. % Last subplot is a dummy to avoid resizing when colorbar is used.
  53. hFig = createPrintFig(15 * [ 1 2/3]);
  54. hSubAx = plotLasagnaTracesFromCell(gcf, {xRFs, yRFs, xRFs}, brewermap(6, 'Paired'));
  55. colorbar;
  56. arrayfun(@prettifyAxes, hSubAx);
  57. arrayfun(@offsetAxes, hSubAx);
  58. figFileName = ['RFcurves-' polarityStr '-XY-lasagna-' nameSuffix];
  59. print(hFig, [figDir figFileName '.pdf'], '-dpdf');
  60. end
  61. end