function varargout = plotTuningCurveArrayFromTable(StimTableCell, figDir, varargin) %% Input should be a cell array of tables for XOFF, YOFF, XON, YON. switch nargin case 2 alignToOff = false; alignToAll = false; thresholdResponseInd = 0; thresholdRSquare = -20; padWithNaNs = 0; case 3 alignToOff = varargin{1}; alignToAll = false; thresholdResponseInd = 0; thresholdRSquare = -20; padWithNaNs = 0; case 4 alignToOff = varargin{1}; alignToAll = varargin{2}; thresholdResponseInd = 0; thresholdRSquare = -20; padWithNaNs = 0; case 5 alignToOff = varargin{1}; alignToAll = varargin{2}; thresholdResponseInd = varargin{3}; thresholdRSquare = -20; padWithNaNs = 0; case 6 alignToOff = varargin{1}; alignToAll = varargin{2}; thresholdResponseInd = varargin{3}; thresholdRSquare = varargin{4}; padWithNaNs = 0; case 7 alignToOff = varargin{1}; alignToAll = varargin{2}; thresholdResponseInd = varargin{3}; thresholdRSquare = varargin{4}; padWithNaNs = varargin{5}; otherwise warning('Too many arguments, cannot process them meaningfully!'); end % try [alignedRFsCell, ... alignedRFsCellNaN] = getAlignedTuningCurveArrayFromTable( StimTableCell, ... thresholdResponseInd, ... thresholdRSquare, ... alignToOff, ... alignToAll); % catch % fprintf('Something went wrong! \n') % return % end % qualityMeasure = 'responseQuality'; hFig = createPrintFig(15 * 1 * [1 0.8]); nStims = numel(StimTableCell); data = cellfun(@vec, alignedRFsCell, 'uni', 0); data = cat(1, data{:}); % colorBounds = ZeroCenteredBounds(data, [0 100]); for iStim = 1: nStims StimTable = StimTableCell{iStim}; tuningCurves = alignedRFsCell{iStim}; tuningCurvesNaN = alignedRFsCellNaN{iStim}; hSubAx(iStim) = subplot(2, 2, iStim); colorMap = setFavoriteColormap; barSpacing = [StimTable.stimParams{1}.spacing2]; barPosition = arrayfun(@(x) x.amp, [StimTable.stimParams{1}.stimtrans]); % Center position. barPosition = barPosition - median(barPosition); % To ignore bar position just use the units of indices. barPosition = mean(barSpacing) * (1: size(tuningCurves, 2)); imAlpha = ones(size(tuningCurvesNaN(:, :))); if padWithNaNs imAlpha(isnan(tuningCurvesNaN(:, :))) = 0; end imagesc(barPosition(2: end), 1: size(tuningCurves, 1), tuningCurves(:, :), ... 'AlphaData', imAlpha); colorBounds = ZeroCenteredBounds(tuningCurves, [0 100]); set(gca, 'CLim', colorBounds); set(gca, 'color', 1 * [1 1 1]); end formatSubAxes(hSubAx, padWithNaNs); [~, ~, genotype] = parseFlyPath(fileparts(StimTable.timeSeriesPath{1})); figFileName = ['RF-TuningCurves-' genotype '-' ... qualityMeasure '-' num2str(thresholdResponseInd) '-'... 'rSquare-' num2str(thresholdRSquare) '-', ... 'All-' num2str(alignToAll) ... 'Off-' num2str(alignToOff)]; % set(gcf,'renderer','painters') % set(gcf, 'PaperPositionMode', 'auto'); print(hFig, [figDir figFileName '.pdf'], '-dpdf') print(hFig, [figDir figFileName '.png'], '-dpng', '-r300') % print(hFig, [figDir figFileName '.eps'], '-depsc2', '-r300') varargout{1} = alignedRFsCell; function tryout %% Plot tuning curves. nStims = 4; for iStim = 2: 5 StimTable = StimTableCell{iStim}; % Retrieve table data in arrays. [tcArray, responseIndArray, rSquareArray, fitParams] = getTuningCurveArrayFromTable(StimTable); % We can threshold now. thresholdResponseInd = 0.0; isAboveThreshold = responseIndArray > thresholdResponseInd; tcArray = tcArray(isAboveThreshold, :); responseIndArray = responseIndArray(isAboveThreshold); rSquareArray = rSquareArray(isAboveThreshold); % Sort cells by response quality. [sortedResponseIndArray, sortInd] = sort(responseIndArray, 'descend'); subplot(4, nStims, iStim - 1); imagesc(tcArray(sortInd, :), ZeroCenteredBounds(tcArray, [0 100])); % setFavoriteColormap; colormap(brewermap([], 'BrBG')) % Sort by fit quality. [sortedRSquareArray, sortInd] = sort(rSquareArray, 'descend'); subplot(4, nStims, iStim - 1 + nStims); imagesc(tcArray(sortInd, :), ZeroCenteredBounds(tcArray, [0 100])); setFavoriteColormap; colormap(brewermap([], 'BrBG')) % colormap(brewermap([], 'RdBu')) % Check how it looks aligning the tuning curves. [alignedRFsCell, lagDiffsCell] = alignRFsToAbsMax(tcArray, 0); % alignedRFs = tcArray; % [alignedRFs, lagDiffs] = alignRFsToAbsMax(alignedRFs, 0); % [alignedRFs, lagDiffs] = alignRFsToAbsMax(alignedRFs, 0); % [alignedRFs, lagDiffs] = alignRFsToAbsMax(alignedRFs, 0); [sortedRSquareArray, sortInd] = sort(rSquareArray, 'descend'); subplot(4, nStims, iStim - 1 + 2 * nStims); imagesc(alignedRFsCell(:, :), ZeroCenteredBounds(alignedRFsCell, [0 100])); % setFavoriteColormap; colormap(brewermap([], 'BrBG')) % colormap(brewermap([], 'RdBu')) [sortedRSquareArray, sortInd] = sort(rSquareArray, 'descend'); subplot(4, nStims, iStim - 1 + 3 * nStims); imagesc(tcArray(:, :), ZeroCenteredBounds(alignedRFsCell, [0 100])); % setFavoriteColormap; % colormap(brewermap([], 'RdBu')) % imagesc(sortedRSquareArray', ZeroCenteredBounds(sortedRSquareArray, [0 100])); end end end function polarity = getStimPolarity(StimTable) % Get stim polarity. tokens = regexp(StimTable(1, :).stimParamFileName{1}, '.*_([mp]).*Con_.*', 'tokens'); switch tokens{1}{1} case 'm' polarity = 'off'; case 'p' polarity = 'on'; otherwise polarity = 'other'; end end function formatSubAxes(hSubAx, varargin) if nargin > 1 padWithNaNs = varargin{1}; else padWithNaNs = 0; end % Move the plots closer together. hSubAx(2).Position(1) = hSubAx(2).Position(1) - 0.1; hSubAx(4).Position(1) = hSubAx(4).Position(1) - 0.1; % Set colorbar formatting. tempPos = hSubAx(2).Position; hColorBar(1) = colorbar(hSubAx(2)); hSubAx(2).Position = tempPos; tempPos = hSubAx(4).Position; hColorBar(2) = colorbar(hSubAx(4)); hSubAx(4).Position = tempPos; hColorBar(2).Label.String = '\DeltaF / F_0'; hFig = hSubAx(1).Parent; fileStimSuffix = {'XOFF', 'YOFF', 'XON', 'YON'}; axis(hSubAx, 'square'); arrayfun(@(x) set(x, 'DataAspectRatio'), hSubAx); for iStim = 1: numel(hSubAx) hSubTitle(iStim) = title(hSubAx(iStim), fileStimSuffix{iStim}); end hYLabel(1) = ylabel(hSubAx(3), 'ROI No.'); hXLabel(1) = xlabel(hSubAx(3), 'Bar Position (\circ)'); arrayfun(@prettifyAxes, [hSubAx hColorBar]); % arrayfun(@offsetAxes, hSubAx); % Make the yaxis same so you can see the relative contribution of number of % cells for each stimulus. % linkaxes(hSubAx, 'y'); % Set color of axis to zero color to highlight lack of data. Maybe zero is % misleading but its perfectly uniform so i will not look like the rest of % the data. colorMap = colormap(hSubAx(1)); if ~padWithNaNs set(hSubAx, 'Color', colorMap(end / 2, :)); end setFontForThesis([hSubAx hColorBar], hFig) end