ssa_rebound_fig7_ibi_fracValues.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. %% IBI experiment results
  2. % distributions again
  3. % summaries showing significance
  4. %% prep
  5. clear
  6. close all
  7. pipeline_out = 'D:\ibi_expmts\multibird_summary_ibi.mat';
  8. %% load multibird summary
  9. load(pipeline_out)
  10. %% summary
  11. % final shape of big_ibi_tensor is (song id X unit num X rep id X ibi id)
  12. rebound_units = cell(2,1);
  13. avg_rebound_strength = cell(2,1);
  14. key_motifs = [1 2751; 1251 2801];
  15. xvals = [.05, .1, .150, .2, .250, .3, .4, .5, .75, 1];
  16. this_uType_str = 'su';
  17. these_good_units = sum(num_goods);
  18. these_motif_resp = total_motif_resp;
  19. this_tensor_raw = big_ibi_tensor;
  20. this_tensor_frac = big_ibi_frac;
  21. for songIdx = 1:2 % only first two songs are important
  22. tkm = key_motifs(songIdx,:);
  23. these_frac_inc_values = zeros(length(these_good_units), 250); % if error, numBouts is not 25
  24. these_raw_inc_values = zeros(length(these_good_units), 250);
  25. these_dev_values = zeros(length(these_good_units), 250);
  26. bout_nums = [ceil(tkm(1)/5) ceil(tkm(1)/5)+249];
  27. for unitIdx = 1:sum(num_goods)
  28. % disp([this_uType_str num2str(unitIdx) ' of '
  29. % num2str(sum(num_goods)) ', Song ' num2str(songIdx)]) % helpful
  30. % for testing
  31. this_resp_p1 = total_motif_resp(tkm(1):tkm(1)+1249, unitIdx);
  32. this_resp_p2 = total_motif_resp(tkm(2):tkm(2)+49, unitIdx);
  33. max_p1 = max(this_resp_p1);
  34. stacked_p1 = reshape(this_resp_p1, [5, 250]);
  35. stacked_p2 = reshape(this_resp_p2, [5, 10]);
  36. zero_starts_p1 = find(stacked_p1(1,:) == 0);
  37. zero_starts_p2 = find(stacked_p2(1,:) == 0);
  38. if unitIdx == 1
  39. eval(['resp1_tensor_s' num2str(songIdx) ' = ' ...
  40. ' zeros(5, 250, length(these_good_units));']);
  41. eval(['resp2_tensor_s' num2str(songIdx) ' = ' ...
  42. ' zeros(5, 10, length(these_good_units));']);
  43. end
  44. eval(['resp1_tensor_s' num2str(songIdx) '(:,:,unitIdx) = ' ...
  45. ' stacked_p1;']);
  46. eval(['resp2_tensor_s' num2str(songIdx) this_uType_str '(:,:,unitIdx) = ' ...
  47. ' stacked_p2;']);
  48. mean_ib_p1s = mean(stacked_p1, 2);
  49. std_ib_p1s = std(stacked_p1, [], 2);
  50. mean_ib_p2s = mean(stacked_p2, 2);
  51. std_ib_p2s = std(stacked_p2, [], 2);
  52. num_bouts = length(this_resp_p1)/5;
  53. these_raw_ib_rbds = zeros(num_bouts,1);
  54. these_frac_ib_rbds = zeros(num_bouts,1);
  55. for bIdx = 1:num_bouts
  56. this_first_motif = (bIdx-1)*5 + 1;
  57. if bIdx > 1
  58. this_resp = this_resp_p1(this_first_motif:this_first_motif+4);
  59. last_resp = this_resp_p1(this_first_motif-5:this_first_motif-1);
  60. raw_ib_rbd = this_resp(1) - last_resp(end);
  61. frac_ib_rbd = raw_ib_rbd / max_p1;
  62. these_raw_ib_rbds(bIdx) = raw_ib_rbd;
  63. these_frac_ib_rbds(bIdx) = frac_ib_rbd;
  64. these_frac_inc_values(unitIdx, bIdx) = frac_ib_rbd;
  65. these_raw_inc_values(unitIdx, bIdx) = raw_ib_rbd;
  66. end
  67. end
  68. avg_raw_tensor = mean(squeeze(this_tensor_raw(songIdx,unitIdx,:,:)),1);
  69. std_raw_tensor = std(squeeze(this_tensor_raw(songIdx,unitIdx,:,:)),0,1) ./ sqrt(size(this_tensor_raw,3));
  70. end_dist = squeeze(this_tensor_frac(songIdx,unitIdx,:,end));
  71. rbd_sig = ttest(end_dist,0,'Tail','right');
  72. rbd_sig(isnan(rbd_sig)) = 0;
  73. if rbd_sig
  74. % disp('rbd sig!') % helpful for testing
  75. rebound_units{songIdx}(end+1) = unitIdx;
  76. avg_rebound_strength{songIdx} = [avg_rebound_strength{songIdx}; avg_raw_tensor]; % rows are units
  77. end
  78. end
  79. these_IBIs = xvals;
  80. %
  81. rbd_avg_across_trials = mean(squeeze(this_tensor_frac(songIdx,rebound_units{songIdx},:,:)),2);
  82. this_y = squeeze(mean(rbd_avg_across_trials,1));
  83. this_err = std(rbd_avg_across_trials, [], 1) ./ sqrt(length(rebound_units{songIdx}));
  84. XX = [ones(length(these_IBIs),1) these_IBIs'];
  85. b = XX\this_y;
  86. yCalc = XX*b;
  87. rsq = 1 - sum((this_y - yCalc).^2) / sum((this_y - mean(this_y)).^2);
  88. figure(2345)
  89. subplot(1,2,songIdx)
  90. errorbar(these_IBIs, this_y, 2*squeeze(this_err), 'o')
  91. hold on;
  92. plot(these_IBIs, yCalc, 'r-')
  93. hold off;
  94. title(['Rebounds by IBI, Song ' num2str(songIdx) ', ' this_uType_str])
  95. xlabel('Inter-bout Interval')
  96. ylabel('Rebound (prop. of max.)')
  97. set(gca, 'FontSize', 24)
  98. xlim([0 1.1])
  99. disp(['slope is ' num2str(b(2)) ' of max per sec.'])
  100. disp(['rsq is ' num2str(rsq) '.'])
  101. end
  102. h5 = figure(2345);
  103. print(['figure_pieces/fig7_ibi_summary_frac_v2'], '-dsvg', '-r300')
  104. saveas(h5, ['figure_pieces/fig7_ibi_summary_frac_v2.fig'])
  105. %% distributions of strengths at 1s ibi
  106. bin_edges = -20:4:60;
  107. for song_idx = 1:2
  108. these_long_rbds = squeeze(big_ibi_tensor(song_idx,:,:,10));
  109. these_avg_long_rbds = mean(these_long_rbds, 2);
  110. this_sig = rebound_units{song_idx};
  111. figure(999)
  112. subplot(1,2,song_idx)
  113. histogram(these_avg_long_rbds,'BinEdges', bin_edges)
  114. hold on;
  115. histogram(these_avg_long_rbds(this_sig),'BinEdges', bin_edges)
  116. hold off;
  117. xlabel('Rebound (Hz)')
  118. ylabel('Number of neurons')
  119. title(['Rebounds, Song ' num2str(song_idx)])
  120. end
  121. h5 = figure(999);
  122. print(['figure_pieces/fig7_ibi_rbd_dist_raw'], '-dsvg', '-r300')
  123. saveas(h5, ['figure_pieces/fig7_ibi_rbd_dist_raw.fig'])
  124. %% distributions of strengths at 1s ibi
  125. bin_edges = -0.8:0.1:0.8;
  126. for song_idx = 1:2
  127. these_long_rbds = squeeze(big_ibi_frac(song_idx,:,:,10));
  128. these_avg_long_rbds = mean(these_long_rbds, 2);
  129. this_sig = rebound_units{song_idx};
  130. figure(999)
  131. subplot(1,2,song_idx)
  132. histogram(these_avg_long_rbds,'BinEdges', bin_edges)
  133. hold on;
  134. histogram(these_avg_long_rbds(this_sig),'BinEdges', bin_edges)
  135. hold off;
  136. xlabel('Rebound (frac. of max.)')
  137. ylabel('Number of neurons')
  138. title(['Rebounds, Song ' num2str(song_idx)])
  139. end
  140. h5 = figure(999);
  141. print(['figure_pieces/fig7_ibi_rbd_dist_frac'], '-dsvg', '-r300')
  142. saveas(h5, ['figure_pieces/fig7_ibi_rbd_dist_frac.fig'])