collectRFs.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. % Function collects the receptive fields (X,Y) (On, Off) from all neurons
  2. % into a cell array 4 x nChannels with rows: (xOff, yOff, xOn, yOn)
  3. % This reads only first layer recorded in a fly.
  4. % For this only data with 5 stimuli can be used:
  5. % OnOff flashes plus 4 bar stimuli
  6. function receptiveFieldsAll = collectRFs(dataEdges, tuningStat, varargin)
  7. if nargin >= 3
  8. deleteLastROI = varargin{1};
  9. else
  10. deleteLastROI = 1;
  11. end
  12. % Define the array to compare to randomized recordings.
  13. xOffStimFileName = 'StandingStripe_1s_XAxis_5degWide_2degSep_m1.0Con_rand_USEFRUSTUM.txt';
  14. yOffStimFileName = 'StandingStripe_1s_YAxis_5degWide_2degSep_m1.0Con_rand_USEFRUSTUM.txt';
  15. xOnStimFileName = 'StandingStripe_1s_XAxis_5degWide_2degSep_p1.0Con_rand_USEFRUSTUM.txt';
  16. yOnStimFileName = 'StandingStripe_1s_YAxis_5degWide_2degSep_p1.0Con_rand_USEFRUSTUM.txt';
  17. barStimFileNames = {xOffStimFileName, yOffStimFileName, xOnStimFileName, yOnStimFileName};
  18. nChannels = numel(dataEdges{1}.roiTCsInterp);
  19. receptiveFieldsAll = cell(4, nChannels);
  20. for iFly = 1: size(dataEdges, 1)
  21. % flyPathInd = iFly;
  22. for jStim = 2:5
  23. % Find index of matching stimulus.
  24. rfInd = find(strcmp(dataEdges{iFly, 1, jStim}.stimulusName, barStimFileNames));
  25. if ~isempty(rfInd)
  26. for kChannel = 1: nChannels
  27. nEpochs = numel(dataEdges{iFly, 1, jStim}.stimFrameInds);
  28. nCells = size(dataEdges{iFly, 1, jStim}.roiTCs{kChannel}, 2);
  29. roiTCs = dataEdges{iFly, 1, jStim}.roiTCs{kChannel};
  30. receptiveFields = nan * ones(nCells, nEpochs);
  31. switch tuningStat
  32. case 'maxAbs'
  33. for iEpoch = 1: nEpochs
  34. epochInds = dataEdges{iFly, 1, jStim}.stimFrameInds{iEpoch}(3: end - 1);
  35. [~, maxEpochInd] = max(abs(squeeze(roiTCs(1, :, epochInds))), [], 2);
  36. receptiveFields(:, iEpoch) = vec(arrayfun(@(x) squeeze(roiTCs(1, x, epochInds(maxEpochInd(x)))), 1: size(roiTCs, 2)));
  37. end
  38. case 'median'
  39. receptiveFields = cell2mat(cellfun(@(x) median(squeeze(roiTCs(1, :, x)), 2), ...
  40. dataEdges{iFly, 1, jStim}.stimFrameInds, 'UniformOutput', false));
  41. case 'mean'
  42. receptiveFields = cell2mat(cellfun(@(x) mean(squeeze(roiTCs(1, :, x)), 2), ...
  43. dataEdges{iFly, 1, jStim}.stimFrameInds, 'UniformOutput', false));
  44. end
  45. receptiveFieldsAll{rfInd, kChannel} = [receptiveFieldsAll{rfInd, kChannel}; receptiveFields(1: end - 1 * deleteLastROI, :)];
  46. end
  47. end
  48. end
  49. clear receptiveFields
  50. end
  51. % Hard-coded error correction for some extra ROI.
  52. if contains(dataEdges{1}.flyPath, 'Tm9GCaMP6f-Tm4jRGECO1a')
  53. receptiveFieldsAll{1,1}(10, :) =[];
  54. end
  55. end