Figure_1.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. function fig = Figure_1(file_path, varargin)
  2. % Plot Figure 1
  3. %
  4. % include plotting toolbox gramm: https://github.com/piermorel/gramm
  5. %
  6. % neuron: neurons' number
  7. % SPIKES.spikes: neurons x [time; condition; trial timing]
  8. % SPIKES.spikes_wave: neurons x [mean; std]
  9. %
  10. if(nargin>1)
  11. nExampleNeuron = varargin{1};
  12. else
  13. nExampleNeuron = 1;
  14. end
  15. neurons = 1;
  16. for nSubject = 1:9
  17. file_name = sprintf('Data_Subject_%.2d_Session_01.h5',nSubject);
  18. f = nix.File([file_path,file_name],nix.FileMode.ReadOnly);
  19. block = f.blocks{1};
  20. group_SpikeTimes = block.openGroup('Spike times');
  21. trials_labels = cellfun(@(x) x.name, group_SpikeTimes.dataArrays, ...
  22. 'UniformOutput',0);
  23. info = cellfun(@(x) strsplit(x,'_'), trials_labels, 'UniformOutput',0);
  24. units = cell2mat(cellfun(@(x) str2double(x{4}), info, 'UniformOutput',0));
  25. trials = cell2mat(cellfun(@(x) str2double(x{8}), info, 'UniformOutput',0));
  26. for u=1:max(units)
  27. trial_ind = [];
  28. SpikeTimes = [];
  29. for t=1:max(trials)
  30. condition = (units==u)&(trials==t);
  31. dataArray_SpikeTimes = group_SpikeTimes.dataArrays{condition};
  32. data = dataArray_SpikeTimes.readAllData';
  33. SpikeTimes = [SpikeTimes; data];
  34. trial_ind = [trial_ind; ones(length(data), 1)*t];
  35. end
  36. SPIKES(neurons).spikes = [SpikeTimes trial_ind];
  37. indMultiTagUnitSpikeTimes = contains(cellfun(@(x) x.name,block.multiTags, ...
  38. 'UniformOutput',0),['Unit_',num2str(u),'_']);
  39. multiTag_SpikeTimes = block.multiTags{indMultiTagUnitSpikeTimes};
  40. dataArray_Waveform = multiTag_SpikeTimes.features{1}.openData;
  41. SPIKES(neurons).waveform = dataArray_Waveform.readAllData';
  42. neurons = neurons + 1;
  43. end
  44. end
  45. %%
  46. % FR all
  47. FR_all = [];
  48. for i = 1:length(SPIKES)
  49. n_trials = max(SPIKES(i).spikes(:, 2));
  50. FR_all = [ FR_all length(SPIKES(i).spikes(:,1)) / n_trials*0.026];
  51. end
  52. % ISI
  53. isis = [];
  54. for i = 1:length(SPIKES)
  55. isis_ = [];
  56. for t = 1:max(SPIKES(i).spikes(:,2))
  57. isis_ = [isis_; diff(sort(SPIKES(i).spikes(SPIKES(i).spikes(:,2)==t, 1))*1000)];
  58. end
  59. isis = [isis; (length(isis_(isis_<3))/length(isis_))*100];
  60. end
  61. % SNR
  62. snr = [];
  63. waveform = [];
  64. for i = 1:length(SPIKES)
  65. snr_0 = max(abs(SPIKES(i).waveform(:,1)))/mean(SPIKES(i).waveform(:,2));
  66. snr = [snr snr_0];
  67. waveform = [waveform; SPIKES(i).waveform(:,1)'];
  68. end
  69. FR = SPIKES(neuron).spikes;
  70. %% Firing rate one
  71. c = [];
  72. fs = -2; % min(FR(:,3));
  73. ls = 24; % max(FR(:,3));
  74. binSize = 0.1;
  75. for i = 1:max(FR(:,2))
  76. for t = [0 1] % 1 - red, 0 - blue
  77. if mod(i,2) == t % odd - neutral, even - aversiv
  78. spikeTimes = FR(FR(:,2) == i, 1);
  79. trials{i} = spikeTimes;
  80. c = [c t];
  81. temp = histc(spikeTimes, fs:binSize:ls);
  82. binned{i} = smooth(temp(1:end-1)/binSize, 10);
  83. % we set here bin centers
  84. bins{i} = (fs+binSize/2):binSize:(ls-binSize/2);
  85. end
  86. end
  87. end
  88. %%
  89. clear g
  90. fig = figure;
  91. % FR
  92. g(1)=gramm( 'x', bins, 'y', binned, 'color', c );
  93. n = length(binned);
  94. custom_statfun = @(y)([mean(y);
  95. mean(y) - std(y)/sqrt(17);
  96. mean(y) + std(y)/sqrt(17)]);
  97. g(1).stat_summary('setylim', true, 'type', custom_statfun);
  98. g(1).set_names( 'x', '', 'y', 'Rate [Hz]' );
  99. g(1).set_layout_options('position', [0.05 0.7 0.9 0.3])
  100. g(1).no_legend()
  101. g(1).axe_property('xlim',[fs 20],'XColor','none');
  102. % Inset
  103. g(6)=gramm('x', ([1:64]-20)/32,'y', waveform(neuron,:));
  104. g(6).geom_line();
  105. g(6).set_names( 'x', 'Time (ms)', 'y', 'uV' );
  106. g(6).set_layout_options('position',[0.1 0.9 0.1 0.1])
  107. g(6).set_text_options('base_size',4)
  108. g(6).set_color_options('chroma',0,'lightness',30);
  109. g(6).set_line_options('base_size', 1);
  110. g(6).no_legend()
  111. % g(6).axe_property('xlim',[fs 20],'XColor','none');
  112. % raster
  113. g(2)=gramm('x', trials,'color', c);
  114. g(2).geom_raster( 'geom', 'point');
  115. g(2).set_point_options('base_size', 3);
  116. g(2).set_names( 'x', 'Time [s]', 'y', 'Trial no. (reordered)' );
  117. g(2).set_layout_options('position', [0.05 0.43 0.9 0.3])
  118. g(2).no_legend()
  119. g(2).axe_property('xlim',[fs 20], 'ylim', [-1 9]);
  120. % ISI
  121. g(3)=gramm('x', isis);
  122. g(3).stat_bin();
  123. g(3).set_layout_options('position',[0.05 0.1 0.25 0.3])
  124. g(3).set_names( 'x', 'Percentage of ISI < 3 ms', 'y', 'No. of units' );
  125. g(3).set_color_options('hue_range',[155 200]);
  126. % FR all
  127. g(4)=gramm('x', FR_all);
  128. g(4).stat_bin();
  129. g(4).set_layout_options('position',[0.38 0.1 0.25 0.3])
  130. g(4).set_names( 'x', 'Firing rate [Hz]', 'y', 'No. of units' );
  131. g(4).axe_property('xlim',[0 20]);
  132. g(4).set_color_options('hue_range',[155 200]);
  133. % SNR
  134. g(5)=gramm('x', snr);
  135. g(5).stat_bin();
  136. g(5).set_layout_options('position',[0.71 0.1 0.25 0.3])
  137. g(5).set_names( 'x', 'Waveform peak SNR', 'y', 'No. of neurons' );
  138. g(5).axe_property('xlim',[0 10]);
  139. g(5).set_color_options('hue_range',[155 200]);
  140. % Labels
  141. x = [0 0 0 0.35 0.68];
  142. y = [0.97 0.7 0.37 0.37 0.37];
  143. l = ['a' 'b' 'c' 'd' 'e'];
  144. g(7)=gramm('x', x, 'y', y,'label',l);
  145. g(7).geom_label('Color','k', 'fontweight', 'bold')
  146. g(7).axe_property('XColor','none','YColor','none','xlim',[0 1],...
  147. 'ylim',[0 1],'Visible','off');
  148. g(7).set_layout_options('position',[0 0 1 1])
  149. g.draw();
  150. print('-dtiff','-r300','fig_1.tiff')
  151. end