Browse Source

Dateien hochladen nach 'code_MATLAB'

Ece Boran 3 years ago
parent
commit
2313bd6f1c
2 changed files with 101 additions and 63 deletions
  1. 78 49
      code_MATLAB/Figure_2.m
  2. 23 14
      code_MATLAB/Figure_3.m

+ 78 - 49
code_MATLAB/Figure_2.m

@@ -30,7 +30,7 @@ for nSubject = 1:9
     % Multitags for spike times
     group_MultiTagsSpikes = block.openGroup('Spike times multitags');
     multiTags_SpikeTimes = group_MultiTagsSpikes.multiTags;
-
+    
     % If there are no neurons, continue
     if(isempty(multiTags_SpikeTimes))
         continue;
@@ -66,8 +66,8 @@ for nSubject = 1:9
         dataArray_Waveform = multiTags_SpikeTimes{nDataArray}.features{1}.openData;
         % Store waveforms
         SPIKES(iNeuron).waveform = dataArray_Waveform.readAllData';
-     end
-    SPIKES_All = [SPIKES_All,SPIKES];    
+    end
+    SPIKES_All = [SPIKES_All,SPIKES];
 end
 
 
@@ -102,88 +102,117 @@ FR = SPIKES_All(nExampleNeuron).spikes;
 
 %% Firing rate for a single neuron
 c = [];
-fs = -2;
-ls = 24;
+tPre = -2;
+tPost = 24;
 binSize = 0.1;
 ranTrials = {};
 for i = 1:max(FR(:,2))
-    for iTrial = [0 1] % 1 - red, 0 - blue
-        if mod(i,2) == iTrial % odd - neutral, even - aversiv
+    for iCondition = [0,1] % 1 - aversive, 0 - neutral
+        if(mod(i,2)==iCondition)
             spikeTimes = FR(FR(:,2) == i,1);
             ranTrials{i} = spikeTimes;
-            c = [c iTrial];
-            temp = histc(spikeTimes,fs:binSize:ls);
+            % Trial conditions
+            c = [c,iCondition+1];
+            % Binned spikes
+            temp = histc(spikeTimes,tPre:binSize:tPost);
             binned{i} = smooth(temp(1:end-1)/binSize,10);
-            % we set here bin centers
-            bins{i} = (fs+binSize/2):binSize:(ls-binSize/2);
+            % Bin centers
+            bins{i} = (tPre+binSize/2):binSize:(tPost-binSize/2);
         end
     end
 end
 
 %% Plot Figure 2
-clear g
 fig = figure;
-% FR
-g(1) = gramm( 'x',bins,'y',binned,'color',c );
-n = length(binned);
+fig.Units = 'centimeters';
+fig.Position(2:4) = [5,16,16];
+% Example neuron
+% Firing rate
+strTrialCondition = {'Aversive','Neutral'};
+catTrialCondition = strTrialCondition(c);
+g(1) = gramm('x',bins,'y',binned,'Color',catTrialCondition);
 custom_statfun = @(y)([mean(y);
-    mean(y) - std(y)/sqrt(17);
-    mean(y) + std(y)/sqrt(17)]);
+    mean(y)-std(y)/sqrt(17);
+    mean(y)+std(y)/sqrt(17)]);
 g(1).stat_summary('setylim',true,'type',custom_statfun);
-g(1).set_names( 'x','','y','Rate [Hz]');
-g(1).set_layout_options('position',[0.05,0.7,0.9,0.3]);
-g(1).no_legend();
-g(1).axe_property('xlim',[fs 20],'XColor','none');
-% Inset
+g(1).set_names('x','','y','Rate (Hz)','Color','');
+g(1).set_layout_options('position',[0.05,0.7,0.85,0.25],'Legend_Position',[0.16,0.85,0.25,0.15]);
+g(1).set_color_options('map',[1,0,0;0,0,1],'n_color',2,'n_lightness',1);
+g(1).axe_property('XLim',[tPre,tPost],'XTick',[],'YLim',[-1,10.5],'YTick',0:5:10,'XColor','none','YColor','k',...
+    'FontName','Arial','FontSize',10,'TickDir','out','TickLength',[0.015,0.0250]);
+% Spike shape
 g(6) = gramm('x',((1:64)-20)/32,'y',waveform(nExampleNeuron,:));
 g(6).geom_line();
-g(6).set_names('x','Time (ms)','y','uV' );
-g(6).set_layout_options('position',[0.1,0.9,0.1,0.1]);
-g(6).set_text_options('base_size',4);
-g(6).set_color_options('chroma',0,'lightness',30);
+g(6).set_names('x','Time (ms)','y','\muV');
+g(6).set_layout_options('position',[0.75,0.85,0.13,0.12]);
+g(6).set_text_options('base_size',4,'interpreter','tex');
+% g(6).set_color_options('chroma',0,'lightness',30);
+g(6).set_color_options('map',[0,0,0],'n_color',1,'n_lightness',1);
 g(6).set_line_options('base_size',1);
 g(6).no_legend();
-% g(6).axe_property('xlim',[fs 20],'XColor','none');
-% raster
-g(2) = gramm('x',ranTrials,'color',c);
+g(6).axe_property('XLim',[(1-20)/32,(64-20)/32],'XTick',[0,1],'YTick',[0,30],'XColor','k','YColor','k',...
+    'FontName','Arial','FontSize',7,'TickDir','out','TickLength',[0.08,0.0250]);
+% Raster
+g(2) = gramm('x',ranTrials,'Color',c);
 g(2).geom_raster('geom','point');
 g(2).set_point_options('base_size',3);
-g(2).set_names('x','Time [s]','y','Trial no. (reordered)');
-g(2).set_layout_options('position',[0.05,0.43,0.9,0.3]);
+g(2).set_names('x','Time (s)','y','Trial no. (reordered)');
+g(2).set_layout_options('position',[0.05,0.4,0.85,0.28]);
+g(2).set_color_options('map',[1,0,0;0,0,1],'n_color',2,'n_lightness',1);
 g(2).no_legend();
-g(2).axe_property('xlim',[fs,20],'ylim',[-1,9]);
+g(2).axe_property('XLim',[tPre,tPost],'YLim',[-1,11],'YTick',0:5:10,'XColor','k','YColor','k',...
+    'FontName','Arial','FontSize',10,'TickDir','out','TickLength',[0.015,0.0250]);
+% Spike sorting quality metrics
 % ISI
 g(3) = gramm('x',isis);
 g(3).stat_bin();
-g(3).set_layout_options('position',[0.05,0.1,0.25,0.3]);
-g(3).set_names('x','Percentage of ISI < 3 ms','y','No. of units');
+g(3).set_layout_options('position',[0.05,0.1,0.25,0.25]);
+g(3).set_names('x','Percentage of ISI < 3 ms','y','No. of neurons');
+g(3).axe_property('XLim',[-0.15,3.7],'YLim',[0,7],'XColor','k','YColor','k',...
+    'FontName','Arial','FontSize',10,'TickDir','out','TickLength',[0.03,0.0250]);
 g(3).set_color_options('hue_range',[155,200]);
-% FR all
+% Firing rate
 g(4) = gramm('x',FiringRatesHz);
 g(4).stat_bin();
-g(4).set_layout_options('position',[0.38,0.1,0.25,0.3]);
-g(4).set_names('x','Firing rate [Hz]','y','No. of units');
-g(4).axe_property('xlim',[0 20]);
-g(4).set_color_options('hue_range',[155 200]);
+g(4).set_layout_options('position',[0.35,0.1,0.25,0.25]);
+g(4).set_names('x','Firing rate (Hz)','y','No. of neurons');
+g(4).axe_property('XLim',[-0.8 20],'YLim',[0,7],'XColor','k','YColor','k',...
+    'FontName','Arial','FontSize',10,'TickDir','out','TickLength',[0.03,0.0250]);
+g(4).set_color_options('hue_range',[155,200]);
 % SNR
 g(5) = gramm('x',snr);
 g(5).stat_bin();
-g(5).set_layout_options('position',[0.71,0.1,0.25,0.3]);
+g(5).set_layout_options('position',[0.65,0.1,0.25,0.25]);
 g(5).set_names('x','Waveform peak SNR','y','No. of neurons');
-g(5).axe_property('xlim',[0 10]);
-g(5).set_color_options('hue_range',[155 200]);
+g(5).axe_property('XLim',[-0.4,10],'YLim',[0,7],'XColor','k','YColor','k',...
+    'FontName','Arial','FontSize',10,'TickDir','out','TickLength',[0.03,0.0250]);
+g(5).set_color_options('hue_range',[155,200]);
 % Labels
-x = [0,0,0,0.35,0.68];
-y = [0.97,0.7,0.37,0.37,0.37];
-l = ['a','b','c','d','e'];
+x = [0.02,0.02,0.34,0.66];
+y = [0.98,0.35,0.35,0.35];
+l = ['a','b','c','d'];
 g(7) = gramm('x',x,'y',y,'label',l);
-g(7).geom_label('Color','k','fontweight','bold');
-g(7).axe_property('XColor','none','YColor','none','xlim',[0,1],...
-    'ylim',[0,1],'Visible','off');
+g(7).geom_label('Color','k','FontWeight','bold','FontName','Arial');
+g(7).axe_property('XColor','none','YColor','none','XLim',[0,1],...
+    'YLim',[0,1],'Visible','off');
 g(7).set_layout_options('position',[0,0,1,1]);
 g.draw();
 
+yPosOffset = g(1).facet_axes_handles.Position(1)-g(3).facet_axes_handles.Position(1);
+for iAx = 3:5
+    g(iAx).facet_axes_handles.Position(1) = g(iAx).facet_axes_handles.Position(1)+yPosOffset;
+end
+% YLabel positions
+for iAx = setdiff(1:7,[6,7])
+    g(iAx).facet_axes_handles.YLabel.Units = 'centimeters';
+    g(iAx).facet_axes_handles.YLabel.Position(1) = -0.8;
+end
+
+g(2).facet_axes_handles.Children(1).MarkerSize = 2.5;
+g(2).facet_axes_handles.Children(2).MarkerSize = 2.5;
+
 % Save figure
-print('-dtiff','-r300','fig_2.tiff')
+print('-dpdf','-r600','-painters','Fig2.pdf');
+print('-dpng','-r600','-painters','Fig2.png');
 
 end

+ 23 - 14
code_MATLAB/Figure_3.m

@@ -11,8 +11,10 @@ function fig = Figure_3( strNIXFolderPath )
 % Add the toolbox 'FieldTrip' to the MATLAB path
 % The toolbox can be downloaded from http://www.fieldtriptoolbox.org/download
 
-chs = [1 3 5 6 8 10 12]; % healthy amygdalae
-chtot = 0;
+chs = [1,3,5,6,8,10,12]; % healthy amygdalae
+nTotalNumberOfChannels = 0;
+PSD_aversive = [];
+PSD_neutral = [];
 for nSubject = 1:9
     file_name = sprintf('Data_Subject_%.2d_Session_01.h5',nSubject);
     f = nix.File([strNIXFolderPath,filesep,file_name],nix.FileMode.ReadOnly);
@@ -31,7 +33,7 @@ for nSubject = 1:9
             tiEEG = (0:(double(dataArray_iEEG.dataExtent(2))-1))*dataArray_iEEG.dimensions{2}.samplingInterval+dataArray_iEEG.dimensions{2}.offset;
         else
             tiEEG = (0:(double(dataArray_iEEG.dataExtent(1))-1))*dataArray_iEEG.dimensions{2}.samplingInterval+dataArray_iEEG.dimensions{2}.offset;
-        end 
+        end
         data_iEEG = dataArray_iEEG.readAllData;
         dataMacro.time{1,nTrial} = tiEEG;
         dataMacro.trial{1,nTrial} = data_iEEG;
@@ -56,7 +58,6 @@ for nSubject = 1:9
     
     
     ch = 1:length(TFR_land.label);
-    tt = TFR_land.time;
     ff = TFR_land.freq;
     
     pwr_face  = squeeze(nanmean(TFR_face.powspctrm(:,ch,:,:)));
@@ -64,29 +65,37 @@ for nSubject = 1:9
     
     psd_face  = nanmean(pwr_face,length(size(pwr_face)));
     psd_land  = nanmean(pwr_land,length(size(pwr_land)));
-    PSD_face(chtot+ch,:) = psd_face;
-    PSD_land(chtot+ch,:) = psd_land;
-    chtot = chtot+ch(end);
+    PSD_aversive(nTotalNumberOfChannels+ch,:) = psd_face;
+    PSD_neutral(nTotalNumberOfChannels+ch,:) = psd_land;
+    nTotalNumberOfChannels = nTotalNumberOfChannels+ch(end);
     
 end
 
-
 %% Plot Figure 3
 fig = figure;
-
-data = [PSD_face(chs,:); PSD_land(chs,:)];
-cval = {'Aversive' 'Neutral'};
-cind = [ones(chtot/2,1)*1;ones(chtot/2,1)*2];
+fig.Units = 'centimeters';
+fig.Position(3:4) = [12,10];
+data = [PSD_aversive(chs,:);PSD_neutral(chs,:)];
+cval = {'Aversive','Neutral'};
+cind = [ones(nTotalNumberOfChannels/2,1)*1;ones(nTotalNumberOfChannels/2,1)*2];
 c = cval(cind);
 g = gramm('x',ff,'y',data,'color',c);
 custom_statfun = @(y)([10*log10(nanmean(y));
     10*log10(nanmean(y))-nanstd(10*log10(nanmean(y)))/sqrt(8*6);
     10*log10(nanmean(y))+nanstd(10*log10(nanmean(y)))/sqrt(8*6)]);
 g.stat_summary('setylim',true,'type',custom_statfun);
-g.set_names( 'x', 'Frequency [Hz]','y','Power [dB]');
+g.set_names('x','Frequency (Hz)','y','Power (dB)','Color','');
+g.axe_property('XLim',[-4,105],'YLim',[-2,18],'YTick',0:4:16,'XColor','k','YColor','k','TickDir','out','TickLength',[0.02,0.0250],...
+    'FontName','Arial','FontSize',10);
+g.set_layout_options('Legend_Position',[0.7,0.7,0.25,0.3]);
+g.set_text_options('Font','Arial');
+g.set_color_options('map',[1,0,0;0,0,1],'n_color',2,'n_lightness',1);
 g.draw();
 
+g.legend_axe_handle.FontName = 'Arial';
+
 % Save figure
-print('-dtiff','-r300','fig_3.tiff')
+print('-dpdf','-r600','-painters','Fig3.pdf');
+print('-dpng','-r600','-painters','Fig3.png');
 
 end