1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- function plotRFsAlignedWithFit(StimTableCell, rSqThresh, respIndThresh, figDir, nameSuffix, varargin)
- if nargin > 5
- alignAll = varargin{1};
- else
- alignAll = false;
- end
- % [tcArrayCell, responseIndArrayCell, rSquareArrayCell, fitParamsCell, ...
- % tcExtCellArray, tcArgExtCellArray] = cellfun(@getTuningCurveArrayFromTable, ...
- % StimTableCell, 'uni', 0);
- [tcArrayCell, responseIndArrayCell, rSquareArrayCell, fitParamsCell, ...
- flyIndsCell, tcExtCellArray, tcArgExtCellArray] = getStimArraysForSameRois(StimTableCell);
- % Align to fit
- posCell = cellfun(@(x) arrayfun(@(y) y.b1, x, 'uni', 0), fitParamsCell, 'uni', 1);
- widthCell = cellfun(@(x) arrayfun(@(y) 2 * (2 * sqrt(log(2))) * y.c1, x, 'uni', 0), ...
- fitParamsCell, 'uni', 1); % The 2 factor is because of bar separation.
- lagsCell = cellfun(@(x, y) round(x - size(y, 2) / 2), posCell, tcArrayCell, 'uni', 0);
- barRFs = cellfun(@(x, y) alignRFsToAbsMax(x, 0, y'), tcArrayCell, lagsCell, 'uni', 0);
- validIndsCell = cellfun(@(x, y) x(:) > rSqThresh & y(:) > respIndThresh, ...
- rSquareArrayCell, responseIndArrayCell, 'uni', 0)';
- %% Blank epoch was already deleted, now delete vertical bars on edges of screen.
- barRFs{2}(:, end-1: end) = [];
- barRFs{4}(:, end-1: end) = [];
- barRFs{2}(:, 1: 2) = [];
- barRFs{4}(:, 1: 2) = [];
- %%
- if alignAll
- validAll = validIndsCell{1} & validIndsCell{2} & ...
- validIndsCell{3} & validIndsCell{4};
- offX = barRFs{1}(validAll, :);
- offY = barRFs{2}(validAll, :);
- onX = barRFs{3}(validAll, :);
- onY = barRFs{4}(validAll, :);
- else
- offX = barRFs{1}(validIndsCell{1}&validIndsCell{2}, :);
- offY = barRFs{2}(validIndsCell{2}&validIndsCell{1}, :);
- onX = barRFs{3}(validIndsCell{3}&validIndsCell{4}, :);
- onY = barRFs{4}(validIndsCell{4}&validIndsCell{3}, :);
- end
- % normalize to peak and smooth and normalize again.
- maxNorm = @(x, dim) x ./ max(abs(x), [], dim);
- getRow = @(x, nRow) x(nRow, :);
- normRFs = cellfun(@(x) cell2mat(arrayfun(@(y) smooth(getRow(maxNorm(x,2), y))', 1: size(x, 1), 'uni', 0)'), ...
- {offX, offY, onX, onY}, 'uni', 0);
- normRFs = cellfun(@(x) maxNorm(x,2), normRFs, 'uni', 0);
- %%
- % Plot lasagna plots, separate figures for off and on, and reapeated panel
- % is to have a colorbar that does not distort existing axis of interest.
- plotLasagnaRFs(offX, offY, 'OFF')
- plotLasagnaRFs(onX, onY, 'ON')
- function plotLasagnaRFs(xRFs, yRFs, polarityStr)
- %% Plot traces and average above colormap of single cell responses
- % Last subplot is a dummy to avoid resizing when colorbar is used.
- hFig = createPrintFig(15 * [ 1 2/3]);
- hSubAx = plotLasagnaTracesFromCell(gcf, {xRFs, yRFs, xRFs}, brewermap(6, 'Paired'));
- colorbar;
- arrayfun(@prettifyAxes, hSubAx);
- arrayfun(@offsetAxes, hSubAx);
- figFileName = ['RFcurves-' polarityStr '-XY-lasagna-' nameSuffix];
- print(hFig, [figDir figFileName '.pdf'], '-dpdf');
- end
- end
|