ssa_rebound_fig4_rebounds.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. % example raster of rebounding neuron - call out both types (across bouts
  2. % and across phases)
  3. % raster of same unit, showing what's going on
  4. % trajectory of same unit, showing that cross-phase rebound is basically
  5. % just a return to earlier stage in habituation
  6. % imagescs showing (both kinds of) rebound across datasets
  7. % distributions of rebounds (both kinds, all 4 songs)
  8. %% prep
  9. clear
  10. close all
  11. pipeline_out = 'D:\ssa_expmts\multibird_summary_ssa.mat';
  12. % bird 2, su 006, song1
  13. % response curve looks great, raster looks great (but key motifs should be
  14. % first 10 of p1 and first 5 of p2), response curve is pretty good too
  15. example_bird = [2];
  16. example_unit = [6];
  17. example_song = [1];
  18. %% load multibird summary
  19. load(pipeline_out)
  20. %% response summary example - can we focus on song 1?
  21. psth_bird_id = example_bird;
  22. psth_unit_type = 'su';
  23. psth_unit_id = example_unit;
  24. es = example_song;
  25. % transition times for the stim
  26. s1s2 = 125;
  27. s2s3 = 250;
  28. s3s4 = 375;
  29. s4s1b = 500;
  30. s1bs2b = 550;
  31. s2bs3b = 600;
  32. s3bs4b = 650;
  33. std_end = 700;
  34. km = [0 125 250 375 500 550 600 650 700];
  35. % s1 s2 s3 s4
  36. if strcmp(psth_unit_type, 'su')
  37. if psth_bird_id > 1
  38. base = sum(num_goods(1:psth_bird_id-1));
  39. else
  40. base = 0;
  41. end
  42. actual_id = base + psth_unit_id;
  43. this_row = total_motif_resp(1:std_end,actual_id);
  44. else
  45. this_row = total_motif_resp_mu(1:std_end,actual_id);
  46. end
  47. h2=figure(1006);
  48. subplot(3,1,[1 2])
  49. plot(km(es)+1:km(es+1), this_row(km(es)+1:km(es+1)), 'r-')
  50. hold on;
  51. plot(126:175, this_row(km(es+4)+1:km(es+5)), 'r.')
  52. hold off;
  53. ylabel('resp strength (hz)')
  54. title(['Std Motif Responses'])
  55. xlim([1 175])
  56. subplot(313)
  57. plot(this_row(km(es)+1:km(es)+25), 'r*-')
  58. xlim([1 25])
  59. title('First Responses to Std 1')
  60. ylim([min(0, min(this_row)) max(this_row)+10])
  61. print('figure_pieces/fig4_ssaExample', '-dsvg', '-r300')
  62. saveas(h2, 'figure_pieces/fig4_ssaExample.fig')
  63. %% raster example - looks okay, but maybe exclude
  64. for ex_idx = 1:length(example_bird)
  65. ex_bird = example_bird(ex_idx);
  66. ex_unit = example_unit(ex_idx);
  67. ex_song = example_song(ex_idx);
  68. switch ex_bird
  69. case 1
  70. load('D:\ssa_expmts\pipelines\pipeline_9059_210811_LH_NCM_g0.mat')
  71. case 2
  72. load('D:\ssa_expmts\pipelines\pipeline_9072_210810_LH_NCM_g0_v2.mat')
  73. case 3
  74. load('D:\ssa_expmts\pipelines\pipeline_9074_210811_LH_NCM_g0.mat')
  75. end
  76. raster_win = [-0.025 0.2];
  77. impt_trials = [1 501;...
  78. 126 551;...
  79. 251 601;...
  80. 376 561];
  81. songIdx = ex_song;
  82. this_mot_len = (motifInfo{impt_trials(songIdx,1),3} - motifInfo{impt_trials(songIdx,1),1}) + 0.2;
  83. this_rast_win = raster_win + [0 this_mot_len];
  84. ats_1 = motifInfo(impt_trials(songIdx,1):impt_trials(songIdx,1)+9);
  85. ats_2 = motifInfo(impt_trials(songIdx,2):impt_trials(songIdx,2)+4);
  86. these_ats = cell2mat([ats_1'; ats_2']);
  87. these_gu = sp.cids(find(sp.cgs==uType));
  88. these_spikes = sp.st(sp.clu == these_gu(ex_unit));
  89. ssa_rebound_rasters_v2(these_spikes, these_ats, ex_unit, this_rast_win, micData, dataset_name, 'su')
  90. h5 = gcf;
  91. print(['figure_pieces/fig4_rbdRasterEx' '_' num2str(ex_idx)], '-dsvg', '-r300')
  92. saveas(h5, ['figure_pieces/fig4_rbdRasterEx' '_' num2str(ex_idx) '.fig'])
  93. end
  94. %% trajectory example
  95. % first 5 responses p1, last 5 responses p1, first 5 responses p2
  96. for ex_idx = 1:length(example_bird)
  97. ex_bird = example_bird(ex_idx);
  98. ex_unit = example_unit(ex_idx) -3;
  99. ex_song = example_song(ex_idx);
  100. switch ex_bird
  101. case 1
  102. these_units = 1:num_goods(1);
  103. case 2
  104. these_units = num_goods(1)+1:num_goods(1)+num_goods(2);
  105. case 3
  106. these_units = num_goods(2)+1:sum(num_goods);
  107. end
  108. this_unit = these_units(ex_unit);
  109. relevant_motif_chunks = [1 5; 121 125; 126 130];
  110. line_colors = {'r-', 'k-', 'r--'};
  111. eval(['this_resp_vector = big_rv' num2str(ex_song) ';'])
  112. this_resp_piece = squeeze(this_resp_vector(this_unit,:,:));
  113. % this_resp_piece = this_resp_piece ./ max(this_resp_piece); % causes issues...
  114. for lineIdx = 1:3
  115. impt_motifs = relevant_motif_chunks(lineIdx,:);
  116. good_motifs = this_resp_piece(impt_motifs(1):impt_motifs(2),:);
  117. this_line = mean(good_motifs,1);
  118. figure(101212)
  119. plot(this_line, line_colors{lineIdx})
  120. if lineIdx == 1
  121. hold on;
  122. elseif lineIdx == 3
  123. hold off;
  124. end
  125. end
  126. title(['Bird ' num2str(ex_bird) ', Unit ' num2str(ex_unit) ', Song' num2str(songIdx)])
  127. ylabel('Resp. Str.')
  128. xlabel('Time')
  129. h5 = gcf;
  130. print(['figure_pieces/fig4_rbdCurveEx' '_' num2str(ex_idx)], '-dsvg', '-r300')
  131. saveas(h5, ['figure_pieces/fig4_rbdCurveEx' '_' num2str(ex_idx) '.fig'])
  132. end
  133. %% distributions showing rebounds across experiment
  134. % (we'll sort imagesc by the intra-phase rbd later)
  135. tmr_norm = total_motif_resp ./ max(total_motif_resp, [], 1);
  136. key_motifs = [1 126 251 376;
  137. 501 551 601 651];
  138. for song_idx = 1:4
  139. this_m1_ids = key_motifs(1,song_idx):5:key_motifs(1,song_idx)+124;
  140. this_m5_ids = key_motifs(1,song_idx)+4:5:key_motifs(1,song_idx)+124;
  141. this_p1b25 = key_motifs(1,song_idx)+120:key_motifs(1,song_idx)+124;
  142. this_p2b1 = key_motifs(2,song_idx):key_motifs(2,song_idx)+4;
  143. this_p1_rbds = tmr_norm(this_m1_ids(2:end),:) - ...
  144. tmr_norm(this_m5_ids(1:end-1),:); % if rebound exists, this number will be positive
  145. avg_p1_rbds = mean(this_p1_rbds,1); % for each unit
  146. this_p2_rbds = mean(tmr_norm(this_p2b1,:)) - ...
  147. mean(tmr_norm(this_p1b25,:));
  148. % no averaging needed because just one number per unit
  149. eval(['rbds_p1_s' num2str(song_idx) ' = avg_p1_rbds;'])
  150. eval(['rbds_p2_s' num2str(song_idx) ' = this_p2_rbds;'])
  151. figure(8181)
  152. subplot(2,2,song_idx)
  153. histogram(avg_p1_rbds)
  154. title(['Inter-bout Rebound, Song ' num2str(song_idx)])
  155. figure(8282)
  156. subplot(2,2,song_idx)
  157. histogram(this_p2_rbds)
  158. title(['Inter-phase Rebound, Song ' num2str(song_idx)])
  159. end
  160. h5 = figure(8181);
  161. print(['figure_pieces/fig4_ib_rbds'], '-dsvg', '-r300')
  162. saveas(h5, ['figure_pieces/fig4_ib_rbds.fig'])
  163. h5 = figure(8282);
  164. print(['figure_pieces/fig4_ip_rbds'], '-dsvg', '-r300')
  165. saveas(h5, ['figure_pieces/fig4_ip_rbds.fig'])
  166. %% imagescs showing p1 rebounds
  167. key_motifs = [1 125;
  168. 126 250;
  169. 251 375;
  170. 376 500];
  171. for song_idx = 1:4
  172. this_song_response =...
  173. total_motif_resp(key_motifs(song_idx,1):key_motifs(song_idx,2),:);
  174. tsr_norm = this_song_response ./ max(this_song_response,[],1);
  175. eval(['this_rbds = rbds_p1_s' num2str(song_idx) ';'])
  176. [~,rbd_sort] = sort(this_rbds,'descend');
  177. figure(8383)
  178. subplot(2,2,song_idx)
  179. imagesc(tsr_norm(:,rbd_sort)')
  180. title(['P1 Motif Responses, Song ' num2str(song_idx)])
  181. xlabel('Motif Number')
  182. ylabel('Unit ID')
  183. end
  184. h5 = figure(8383);
  185. print(['figure_pieces/fig4_rbd_imagesc'], '-dsvg', '-r300')
  186. saveas(h5, ['figure_pieces/fig4_rbd_imagesc.fig'])