lightpsth.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. function lightpsth(sessionpath)
  2. %LIGHTPSTH Spike times aligned to photostimulation.
  3. % LIGHTPSTH(SESSIONPATH) calculates peri-event time histogram aligned to
  4. % the onset of photostimulation pulse trains for unclustered tetrode
  5. % data.
  6. %
  7. % Saa also TAGGEDPROP.
  8. % Balazs Hangya
  9. % Institute of Experimental Medicine, Budapest, Hungary
  10. % hangya.balazs@koki.mta.hu
  11. % List of TT files
  12. % sessionpath='C:\Users\sviatko.katalin\Documents\cellbase_data\WH002\180310a'
  13. dr = dir(sessionpath);
  14. files = {dr.name};
  15. TTpattern = getpref('cellbase','cell_pattern'); % find tetrode files with a cellbase-defined naming convention
  16. TTfiles = strfind(files,TTpattern);
  17. TTinx = regexp(files,[TTpattern '\d\.mat']);
  18. TTinx = cellfun(@(s)~isempty(s),TTinx);
  19. TTfiles = files(TTinx);
  20. % Load photostimulation time stamps
  21. fnm = fullfile(sessionpath,'lightevent.mat');
  22. if ~exist(fnm,'file')
  23. convert_events(sessionpath); % convert PulsePal events
  24. end
  25. load(fnm);
  26. % Load spike times
  27. NumTetrodes = length(TTfiles);
  28. wn = [-20 100]; % PSTH window: -20 to 100 ms
  29. mwn = max(abs(wn)); % maximal lag
  30. psth = nan(NumTetrodes,2*mwn+1);
  31. legendstring = cell(1,NumTetrodes);
  32. for iT = 1:NumTetrodes
  33. fnm = fullfile(sessionpath,TTfiles{iT});
  34. load(fnm)
  35. % Pseudo-trains
  36. mx = ceil(TimeStamps(end)*1000);
  37. pse = zeros(1,mx+1000); % pseudo-event train, ms resolution
  38. pse(ceil(pulseon*1000)) = 1;
  39. psu = zeros(1,mx+1000); % pseudo-spike train
  40. psu(ceil(TimeStamps*1000)) = 1;
  41. % PSTH
  42. [lpsth, lags] = xcorr(psu,pse,mwn);
  43. psth(iT,:) = lpsth;
  44. legendstring{iT} = ['TT' num2str(iT)];
  45. end
  46. % Plot
  47. H = figure;
  48. plot(lags,psth');
  49. legend(TTfiles);
  50. fnm = [sessionpath '\' 'light_psth.jpg']; % save
  51. saveas(H,fnm)
  52. fnm = [sessionpath '\' 'light_psth.fig'];
  53. saveas(H,fnm)
  54. close(H)