plotParamsThresholdedDistribution.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. function [widthCell, varargout] = plotParamsThresholdedDistribution(StimTableCell, threshold, qualityMeasure, figDir, varargin)
  2. % PLOTPARAMSTHRESHOLDEDDISTRIBUTION Plots Gaussian fit params distributions for
  3. % a given threshold of a quality measure.
  4. % C = PLOTSCATTERPARAMSVSQUALITYINDEX(STIMTABLE, THRESHOLDARRAY, QUALITYMEASURE, FIGDIR)
  5. % plots the STIMTABLE params for the cutoffs of THRESHOLDARRAY for the
  6. % selected QUALITYMEASURE, and saves to FIGDIR.
  7. %
  8. % C = ADDME(A,B) adds A and B together.
  9. %
  10. % See also SUM, PLUS.
  11. % Maybe still align the yaxis labels and include the correlation coefficent
  12. % if you want to make some claims.
  13. switch nargin
  14. case 4
  15. rSquareThreshold = -20;
  16. alignToOff = false;
  17. alignToAll = false;
  18. case 5
  19. rSquareThreshold = varargin{1};
  20. alignToOff = false;
  21. alignToAll = false;
  22. case 6
  23. rSquareThreshold = varargin{1};
  24. alignToOff = varargin{2};
  25. alignToAll = false;
  26. case 7
  27. rSquareThreshold = varargin{1};
  28. alignToOff = varargin{2};
  29. alignToAll = varargin{3};
  30. otherwise
  31. warning('Too many arguments, cannot process them meaningfully!');
  32. end
  33. [~, ...
  34. ~, ...
  35. fitParams, ...
  36. flyInds, ...
  37. isAboveThreshold, ...
  38. tcExt, ...
  39. tcArgExt] = getAlignedTuningCurveArrayFromTable(StimTableCell, ...
  40. threshold, ...
  41. rSquareThreshold, ...
  42. alignToOff, ...
  43. alignToAll);
  44. nStims = numel(StimTableCell);
  45. for iStim = 1: nStims
  46. StimTable = StimTableCell{iStim};
  47. [~, ~, ~, responseIndArray, ~] = getParamsArrayFromStimTable(StimTable, qualityMeasure);
  48. if threshold >= max(responseIndArray)
  49. warning(['Went over threshold respQuality ' num2str(threshold) ...
  50. '. Range is [' num2str(min(responseIndArray)) ...
  51. ', ' num2str(max(responseIndArray)) ']']);
  52. % threshold = min(responseIndArray);
  53. end
  54. [~, gof] = getFitParamsStructArrayFromTable(StimTable);
  55. rSquare = [gof.rsquare];
  56. if rSquareThreshold >= max(rSquare)
  57. warning(['Went over threshold rSquare ' num2str(rSquareThreshold) ...
  58. '. Range is [' num2str(min(rSquare)) ', ' num2str(max(rSquare)) ']']);
  59. % rSquareThreshold = min(rSquare);
  60. end
  61. stimDegreeFactor = 2;
  62. amplitudeCell{iStim} = fitParams.a1{iStim};
  63. positionCell{iStim} = stimDegreeFactor * (fitParams.b1{iStim} - 1);
  64. widthCell{iStim} = stimDegreeFactor * 2 * sqrt(log(2)) * fitParams.c1{iStim}; % full-width half maximum conversion amplitudeCell{iStim} = a1;
  65. nRois(iStim) = sum(isAboveThreshold{iStim});
  66. nTotalRois(iStim) = numel(isAboveThreshold{iStim});
  67. % Check how many flies have good cells. This neeeds to include rSquare.
  68. nContributingFlies(iStim) = numel(unique(flyInds{iStim}));
  69. tcArgExt{iStim} = (tcArgExt{iStim} - 1) * stimDegreeFactor;
  70. end
  71. metadata.nRois = nRois;
  72. metadata.nTotalRois = nTotalRois;
  73. metadata.nContributingFlies = nContributingFlies;
  74. varargout{1} = metadata;
  75. legendStr = arrayfun(@(x, y, z) ['N = ' num2str(x) ...
  76. ' (n = ' num2str(y) '/' num2str(z) ')'], ...
  77. nContributingFlies, nRois, nTotalRois, 'uni', 0);
  78. fileStimSuffix = {'ONOFF', 'XOFF', 'YOFF', 'XON', 'YON'};
  79. %%
  80. dataCell = [amplitudeCell; positionCell; widthCell; tcExt; tcArgExt];
  81. yLabelCell = {'Amplitude \DeltaF/F_0', 'Center position (\circ)', ...
  82. 'FWHM (\circ)', 'Extreme \DeltaF/F_0', ...
  83. 'Extreme position (\circ)'};
  84. fileNameSuffixCell = {'Amp', 'Pos', 'Width', 'NonParamAmp', 'NonParamPos'};
  85. supportCell = {'unbounded', 'positive', 'positive', 'unbounded', 'unbounded'};
  86. supportCell = {'unbounded', [0-eps 60+eps], [0-eps 100], 'unbounded', [0-eps 60+eps]};
  87. if rSquareThreshold < 0
  88. supportCell{2} = 'unbounded';
  89. end
  90. nParams = size(dataCell, 1);
  91. for iParam = 1: nParams
  92. data = dataCell(iParam, :);
  93. hFig = createPrintFig(10 * [1 3 / 4]);
  94. hParamsSubAx(1) = axes('Parent', hFig);
  95. % Set to pi in case the array is empty.
  96. isEmptyArray = cellfun(@isempty, data);
  97. if any(isEmptyArray)
  98. data(isEmptyArray) = {pi};
  99. end
  100. hBeanAx = beanPlot(data, fileStimSuffix(2: end), getONOFFXYColors, 0.5, ...
  101. hParamsSubAx(1), supportCell{iParam}, 'vertical', 0, 0, 1);
  102. % axis(hParamsSubAx, 'square');
  103. hYLabel(1) = ylabel(hParamsSubAx(1), yLabelCell{iParam});
  104. hLegend = legend(findall(hBeanAx, 'Type', 'patch'), legendStr, ...
  105. 'Location', 'northoutside');
  106. setFontForThesis([hParamsSubAx, hBeanAx, hLegend], hFig)
  107. arrayfun(@prettifyAxes, hParamsSubAx);
  108. arrayfun(@offsetAxes, hParamsSubAx);
  109. [~, ~, genotype] = parseFlyPath(fileparts(StimTable.timeSeriesPath{1}));
  110. figFileName = ['ReceptiveField' fileNameSuffixCell{iParam} '-' genotype '-' ...
  111. qualityMeasure '-' num2str(threshold) ...
  112. '-rSquare-' num2str(rSquareThreshold)...
  113. '-All' num2str(alignToAll) ...
  114. '-Off' num2str(alignToOff)];
  115. % set(gcf,'renderer','painters')
  116. % set(gcf, 'PaperPositionMode', 'auto');
  117. print(hFig, [figDir figFileName '.pdf'], '-dpdf')
  118. print(hFig, [figDir figFileName '.png'], '-dpng', '-r300')
  119. % print(hFig, [figDir figFileName '.eps'], '-depsc2', '-r300')
  120. end
  121. end