Bladeren bron

gin commit from DESKTOP-1FLVU9O

Modified files: 4
eceboran 4 jaren geleden
bovenliggende
commit
31c4568e93
4 gewijzigde bestanden met toevoegingen van 81 en 80 verwijderingen
  1. 8 7
      code_MATLAB/Figure_1.m
  2. 6 3
      code_MATLAB/Figure_2.m
  3. 64 66
      code_MATLAB/Main_Load_NIX_Data.m
  4. 3 4
      code_MATLAB/Main_Plot_Figures.m

+ 8 - 7
code_MATLAB/Figure_1.m

@@ -124,7 +124,7 @@ end
 clear g
 fig = figure;
 % FR
-g(1)=gramm( 'x',bins,'y',binned,'color',c );
+g(1) = gramm( 'x',bins,'y',binned,'color',c );
 n = length(binned);
 custom_statfun = @(y)([mean(y);
     mean(y) - std(y)/sqrt(17);
@@ -135,7 +135,7 @@ 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(6)=gramm('x',([1:64]-20)/32,'y',waveform(nExampleNeuron,:));
+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])
@@ -145,7 +145,7 @@ 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(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)' );
@@ -153,20 +153,20 @@ g(2).set_layout_options('position',[0.05 0.43 0.9 0.3])
 g(2).no_legend()
 g(2).axe_property('xlim',[fs 20],'ylim',[-1 9]);
 % ISI
-g(3)=gramm('x',isis);
+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_color_options('hue_range',[155 200]);
 % FR all
-g(4)=gramm('x',FiringRatesHz);
+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]);
 % SNR
-g(5)=gramm('x',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_names( 'x','Waveform peak SNR','y','No. of neurons' );
@@ -176,13 +176,14 @@ g(5).set_color_options('hue_range',[155 200]);
 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'];
-g(7)=gramm('x',x,'y',y,'label',l);
+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).set_layout_options('position',[0 0 1 1])
 g.draw();
 
+% Save figure
 print('-dtiff','-r300','fig_1.tiff')
 
 end

+ 6 - 3
code_MATLAB/Figure_2.m

@@ -27,9 +27,11 @@ for nSubject = 1:9
     for nTrial = 1:all_trials
         dataArray_iEEG = group_iEEG.dataArrays{nTrial};
         striEEGLabels = dataArray_iEEG.dimensions{1}.labels;
-        tiEEG = (0:(double(max(dataArray_iEEG.dataExtent))-1))* ...
-            dataArray_iEEG.dimensions{2}.samplingInterval ...
-            + dataArray_iEEG.dimensions{2}.offset;
+        if(length(dataArray_iEEG.dataExtent)==2)
+            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 
         data_iEEG = dataArray_iEEG.readAllData;
         dataMacro.time{1,nTrial} = tiEEG;
         dataMacro.trial{1,nTrial} = data_iEEG;
@@ -84,6 +86,7 @@ g.stat_summary('setylim', true, 'type', custom_statfun);
 g.set_names( 'x', 'Frequency [Hz]', 'y', 'Power [dB]' );
 g.draw();
 
+% Save figure
 print('-dtiff','-r300','fig_2.tiff')
 
 end

+ 64 - 66
code_MATLAB/Main_Load_NIX_Data.m

@@ -4,15 +4,14 @@ clear
 clc
 
 %% Directory of the repository and the NIX library
-strMainPath = 'human_amygdala_mua_seeg_fearvideo';
-strMainPath = 'Human_Amygdala_MUA_sEEG_FearVideo';
+strMainPath = 'Human_Amygdala_MUA_sEEG_FearVideo'; % 'human_amygdala_mua_seeg_fearvideo'
 strNIXLibraryPath = 'nix-mx_Win64_1.4.1'; % or 'nix_mx_macOS_1.4.2_Matlab2020a'
 
 %% Add necessary folders to the MATLAB path
 addpath([strMainPath filesep 'code_MATLAB' filesep])
 addpath(genpath(strNIXLibraryPath))
 
-warning('strMainPath should be the full path of the folder Human_Amygdala_MUA_sEEG_FearVideo')
+warning('strMainPath should be the full path of the folder for the repository Human_Amygdala_MUA_sEEG_FearVideo (or human_amygdala_mua_seeg_fearvideo)')
 warning('strNIXLibraryPath should be the full path of the NIX library ''nix-mx_Win64_1.4.1''')
 
 %% NIX data files
@@ -22,7 +21,7 @@ strNIXFileNames = {strNIXFileNames.name}';
 assert(~isempty(strNIXFileNames),'strMainPath should be the full path of the folder Human_Amygdala_MUA_sEEG_FearVideo')
 
 %% Select NIX file to open
-nFile = 5;
+nFile = 1;
 
 %% Open NIX file
 strFilePath = [strMainPath filesep 'data_NIX' filesep strNIXFileNames{nFile}];
@@ -163,20 +162,21 @@ ylabel(['Voltage (',dataArray_iEEG.unit,')'])
 xlim([tiEEG(1),tiEEG(end)])
 legend(striEEGLabels)
 
-%% Sources of the iEEG data
-sourceUnit = dataArray_iEEG.sources{1};
-% Electrode label
-sourceUnit.sources{1}.name
-% Anatomical location
-sourceUnit.sources{2}.name
-
-%% Use electrode map to get properties of the macroelectrode the unit is on
+%% Electrode information
 groupiEEGElecrodes = block.openGroup('iEEG electrode information');
 
-nElectrode = find(strcmpi(cellfun(@(x) x.name,groupiEEGElecrodes.sources,'UniformOutput',0),sourceUnit.name));
-
-% MNI coordinates of the electrode
-groupiEEGElecrodes.multiTags{1}.retrieveFeatureData(nElectrode,'iEEG_Electrode_MNI_Coordinates')
+%% Sources of the iEEG data
+for nSource = 1:dataArray_iEEG.sourceCount
+    sourceUnit = dataArray_iEEG.sources{nSource};
+    % Electrode label
+    sourceUnit.sources{1}.name
+    % Anatomical location
+    sourceUnit.sources{2}.name
+    
+    nElectrode = find(strcmpi(cellfun(@(x) x.name,groupiEEGElecrodes.sources,'UniformOutput',0),sourceUnit.name));
+    % MNI coordinates of the electrode
+    groupiEEGElecrodes.multiTags{1}.retrieveFeatureData(nElectrode,'iEEG_Electrode_MNI_Coordinates')
+end
 
 %% Units
 group_SpikeTimesMultitags = block.openGroup('Spike times multitags');
@@ -185,54 +185,52 @@ if(group_SpikeTimesMultitags.multiTagCount==0)
     warning('This subject does not have any units')
     
 else
-%% Select unit and trial
-nUnit = 1;
-nTrial = 5;
-% MultiTag for the selected unit and trial
-indUnitSpikeTimes = contains(cellfun(@(x) x.name,group_SpikeTimesMultitags.multiTags,'UniformOutput',0),['Unit_',num2str(nUnit),'_'])&...
-    contains(cellfun(@(x) x.name,group_SpikeTimesMultitags.multiTags,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
-multiTag_SpikeTimes = group_SpikeTimesMultitags.multiTags{indUnitSpikeTimes};
-
-%% Spike times
-dataArray_SpikeTimes = multiTag_SpikeTimes.openPositions;
-% Read data
-SpikeTimes = dataArray_SpikeTimes.readAllData;
-
-figure
-stem(dataArray_SpikeTimes.readAllData,ones(length(SpikeTimes),1))
-title(['Spike times - Unit ',num2str(nUnit),' - Trial ',num2str(nTrial)])
-xlabel(['Time (',dataArray_SpikeTimes.dimensions{1}.unit,')'])
-
-%% Waveform for the unit
-dataArray_Waveform = multiTag_SpikeTimes.features{1}.openData;
-% Time axis
-tWaveform = (0:(double(dataArray_Waveform.dataExtent(2))-1))*dataArray_Waveform.dimensions{2}.samplingInterval+dataArray_Waveform.dimensions{2}.offset;
-% Read data
-waveform = dataArray_Waveform.readAllData;
-% Plot
-figure
-plot(tWaveform,waveform(1,:),'b')
-hold on
-plot(tWaveform,waveform(1,:)+waveform(2,:),'b--')
-plot(tWaveform,waveform(1,:)-waveform(2,:),'b--')
-title(['Waveform - Unit ',num2str(nUnit)])
-xlabel(['Time (',dataArray_Waveform.dimensions{2}.unit,')'])
-ylabel(['Voltage (',dataArray_Waveform.unit,')'])
-legend({'Mean','Std'})
-
-%% Source of the unit
-sourceUnit = dataArray_SpikeTimes.sources{1};
-% Electrode label
-sourceUnit.sources{1}.name
-% Anatomical location
-sourceUnit.sources{2}.name
-
-%% Use electrode map to get properties of the macroelectrode the unit is on
-groupiEEGElecrodes = block.openGroup('iEEG electrode information');
-
-nElectrode = find(strcmpi(cellfun(@(x) x.name,groupiEEGElecrodes.sources,'UniformOutput',0),sourceUnit.name));
-
-% MNI coordinates of the electrode
-groupiEEGElecrodes.multiTags{1}.retrieveFeatureData(nElectrode,'iEEG_Electrode_MNI_Coordinates')
-
+    %% Select unit and trial
+    nUnit = 1;
+    nTrial = 5;
+    % MultiTag for the selected unit and trial
+    indUnitSpikeTimes = contains(cellfun(@(x) x.name,group_SpikeTimesMultitags.multiTags,'UniformOutput',0),['Unit_',num2str(nUnit),'_'])&...
+        contains(cellfun(@(x) x.name,group_SpikeTimesMultitags.multiTags,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
+    multiTag_SpikeTimes = group_SpikeTimesMultitags.multiTags{indUnitSpikeTimes};
+    
+    %% Spike times
+    dataArray_SpikeTimes = multiTag_SpikeTimes.openPositions;
+    % Read data
+    SpikeTimes = dataArray_SpikeTimes.readAllData;
+    
+    figure
+    stem(dataArray_SpikeTimes.readAllData,ones(length(SpikeTimes),1))
+    title(['Spike times - Unit ',num2str(nUnit),' - Trial ',num2str(nTrial)])
+    xlabel(['Time (',dataArray_SpikeTimes.dimensions{1}.unit,')'])
+    
+    %% Waveform for the unit
+    dataArray_Waveform = multiTag_SpikeTimes.features{1}.openData;
+    % Time axis
+    tWaveform = (0:(double(dataArray_Waveform.dataExtent(2))-1))*dataArray_Waveform.dimensions{2}.samplingInterval+dataArray_Waveform.dimensions{2}.offset;
+    % Read data
+    waveform = dataArray_Waveform.readAllData;
+    % Plot
+    figure
+    plot(tWaveform,waveform(1,:),'b')
+    hold on
+    plot(tWaveform,waveform(1,:)+waveform(2,:),'b--')
+    plot(tWaveform,waveform(1,:)-waveform(2,:),'b--')
+    title(['Waveform - Unit ',num2str(nUnit)])
+    xlabel(['Time (',dataArray_Waveform.dimensions{2}.unit,')'])
+    ylabel(['Voltage (',dataArray_Waveform.unit,')'])
+    legend({'Mean','Std'})
+    
+    %% Source of the unit
+    sourceUnit = dataArray_SpikeTimes.sources{1};
+    % Electrode label
+    sourceUnit.sources{1}.name
+    % Anatomical location
+    sourceUnit.sources{2}.name
+    
+    %% Use electrode map to get properties of the macroelectrode the unit is on
+    nElectrode = find(strcmpi(cellfun(@(x) x.name,groupiEEGElecrodes.sources,'UniformOutput',0),sourceUnit.name));
+    
+    % MNI coordinates of the electrode
+    groupiEEGElecrodes.multiTags{1}.retrieveFeatureData(nElectrode,'iEEG_Electrode_MNI_Coordinates')
+    
 end

+ 3 - 4
code_MATLAB/Main_Plot_Figures.m

@@ -4,8 +4,7 @@ clear
 clc
 
 %% Directory of the repository and the NIX library
-strMainPath = 'human_amygdala_mua_seeg_fearvideo';
-strMainPath = 'Human_Amygdala_MUA_sEEG_FearVideo';
+strMainPath = 'Human_Amygdala_MUA_sEEG_FearVideo'; % 'human_amygdala_mua_seeg_fearvideo'
 strNIXLibraryPath = 'nix-mx_Win64_1.4.1'; % For Mac: 'nix_mx_macOS_1.4.2_Matlab2020a'
 strFieldTripPath = 'fieldtrip-20200315';
 strGrammPath = 'gramm-master'; % https://github.com/piermorel/gramm
@@ -17,7 +16,7 @@ addpath(strFieldTripPath)
 addpath(strGrammPath)
 ft_defaults
 
-warning('strMainPath should be the full path of the folder Human_Amygdala_MUA_sEEG_FearVideo')
+warning('strMainPath should be the full path of the folder for the repository Human_Amygdala_MUA_sEEG_FearVideo (or human_amygdala_mua_seeg_fearvideo)')
 warning('strNIXLibraryPath should be the full path of the NIX library ''nix-mx_Win64_1.4.1''')
 warning('strFieldTripPath should be the full path of the FieldTrip toolbox ''fieldtrip-2020xxxx''')
 warning('strGrammPath should be the full path of the Gramm toolbox ''gramm-master''')
@@ -29,7 +28,7 @@ strNIXFileNames = {strNIXFileNames.name}';
 assert(~isempty(strNIXFileNames),'strMainPath should be the full path of the folder Human_Amygdala_MUA_sEEG_FearVideo')
 
 %% Figure 1
-nExampleNeuron = 32; % neuron 30 reproduces the publication figure
+nExampleNeuron = 32; % neuron 32 reproduces the publication figure
 fig1 = Figure_1([strMainPath filesep 'data_NIX' filesep],nExampleNeuron);
 
 %% Figure 2