Bladeren bron

Dateien hochladen nach 'code_MATLAB'

Ece Boran 3 jaren geleden
bovenliggende
commit
9f20ffeb94
4 gewijzigde bestanden met toevoegingen van 267 en 14 verwijderingen
  1. 15 10
      code_MATLAB/Figure_1.m
  2. 4 4
      code_MATLAB/Figure_2.m
  3. 216 0
      code_MATLAB/Main_Load_NIX_Data.m
  4. 32 0
      code_MATLAB/Main_Plot_Figures.m

+ 15 - 10
code_MATLAB/Figure_1.m

@@ -1,4 +1,4 @@
-function f = Figure_1(neuron, file_path)
+function fig = Figure_1(file_path, varargin)
 % Plot Figure 1
 %
 % include plotting toolbox gramm: https://github.com/piermorel/gramm
@@ -8,20 +8,24 @@ function f = Figure_1(neuron, file_path)
 % SPIKES.spikes_wave: neurons x [mean; std]
 %
 
+if(nargin>1)
+    nExampleNeuron = varargin{1};
+else
+    nExampleNeuron = 1;
+end
+
 neurons = 1;
-for subject=1:9
-    file_name = ['Data_Subject_0',num2str(subject),'_Session_01.h5'];
+for nSubject = 1:9
+    file_name = sprintf('Data_Subject_%.2d_Session_01.h5',nSubject);
     f = nix.File([file_path,file_name],nix.FileMode.ReadOnly);
     
-    % sectionSession = f.openSection('Session');
-    
     block = f.blocks{1};
     group_SpikeTimes = block.openGroup('Spike times');
     trials_labels = cellfun(@(x) x.name, group_SpikeTimes.dataArrays, ...
-                            'UniformOutput',0);
+        'UniformOutput',0);
     info = cellfun(@(x) strsplit(x,'_'), trials_labels, 'UniformOutput',0);
     units = cell2mat(cellfun(@(x) str2double(x{4}), info, 'UniformOutput',0));
-    trials = cell2mat(cellfun(@(x) str2double(x{8}), info, 'UniformOutput',0));    
+    trials = cell2mat(cellfun(@(x) str2double(x{8}), info, 'UniformOutput',0));
     
     for u=1:max(units)
         trial_ind = [];
@@ -35,7 +39,7 @@ for subject=1:9
         end
         SPIKES(neurons).spikes = [SpikeTimes trial_ind];
         indMultiTagUnitSpikeTimes = contains(cellfun(@(x) x.name,block.multiTags, ...
-                                    'UniformOutput',0),['Unit_',num2str(u),'_']);
+            'UniformOutput',0),['Unit_',num2str(u),'_']);
         multiTag_SpikeTimes = block.multiTags{indMultiTagUnitSpikeTimes};
         dataArray_Waveform = multiTag_SpikeTimes.features{1}.openData;
         SPIKES(neurons).waveform = dataArray_Waveform.readAllData';
@@ -72,6 +76,7 @@ for i = 1:length(SPIKES)
 end
 
 FR = SPIKES(neuron).spikes;
+
 %% Firing rate one
 c = [];
 fs = -2; % min(FR(:,3));
@@ -90,10 +95,10 @@ for i = 1:max(FR(:,2))
         end
     end
 end
+
 %%
 clear g
-%figure('Position',[100 100 800 350]);
-figure
+fig = figure;
 % FR
 g(1)=gramm( 'x', bins, 'y', binned, 'color', c );
 n = length(binned);

+ 4 - 4
code_MATLAB/Figure_2.m

@@ -1,4 +1,4 @@
-function f = Figure_2(file_path)
+function fig = Figure_2(file_path)
 
 % TO BE INCLUDED IN THE PATH
 % fieldtrip: fieldtrip-20191028 www.fieldtrip.org
@@ -8,8 +8,8 @@ function f = Figure_2(file_path)
 %
 chs = [1 3 5 6 8 10 12]; % healthy amygdalae
 chtot = 0;
-for subject=1:9
-    file_name = ['Data_Subject_0',num2str(subject),'_Session_01.h5'];
+for nSubject=1:9
+    file_name = sprintf('Data_Subject_%.2d_Session_01.h5',nSubject);
     f = nix.File([file_path,file_name],nix.FileMode.ReadOnly);
     
     sectionSession = f.openSection('Session');
@@ -70,7 +70,7 @@ end
 %% plot Figure 2
 clear g
 %figure('Position',[100 100 800 350]);
-figure
+fig = figure;
 
 data = [PSD_face(chs,:); PSD_land(chs,:)];
 cval={'Aversive' 'Neutral'};

+ 216 - 0
code_MATLAB/Main_Load_NIX_Data.m

@@ -0,0 +1,216 @@
+%% Close all figures, clear variables and command window
+close all
+clear
+clc
+
+%% Directory of the repository and the NIX library
+strMainPath = 'Human_Amygdala_MUA_sEEG_FearVideo\';
+strNIXLibraryPath = 'nix-mx_Win64_1.4.1\';
+
+%% Add necessary folders to the MATLAB path
+addpath([strMainPath,'\code_MATLAB\'])
+addpath(genpath(strNIXLibraryPath))
+
+warning('strMainPath should be the full path of the folder 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
+strNIXFileNames = dir([strMainPath,'\data_NIX\*.h5']);
+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 = 1;
+
+%% Open NIX file
+strFilePath = [strMainPath,'\data_NIX\',strNIXFileNames{nFile}];
+try
+    f = nix.File(strFilePath,nix.FileMode.ReadOnly);
+catch s
+    if(strcmpi(s.message,'Undefined variable "nix" or class "nix.FileMode.ReadOnly".'))
+        error('strNIXLibraryPath should be the full path of the NIX library ''nix-mx_Win64_1.4.1''')
+    else
+        error(s.message)
+    end
+end
+
+%% Read metadata
+% Display names of all sections
+cellfun(@(x) disp(x.name),f.sections)
+
+%% General information
+sectionGeneral = f.openSection('General');
+% Properties
+cellfun(@(x) disp(x.name),sectionGeneral.properties)
+% Institution
+fprintf(['Institution: ',sectionGeneral.openProperty('Institution').values{1}.value,'\n'])
+% Recording location
+fprintf(['Recording location: ',sectionGeneral.openProperty('Recording location').values{1}.value,'\n'])
+% Sections
+cellfun(@(x) disp(x.name),sectionGeneral.sections)
+% Publications
+sectionPublications = sectionGeneral.openSection('Related publications');
+cellfun(@(x) disp(x.name),sectionPublications.properties)
+fprintf(['Publication name: ',sectionPublications.openProperty('Publication name').values{1}.value,'\n'])
+fprintf(['Publication DOI: ',sectionPublications.openProperty('Publication DOI').values{1}.value,'\n'])
+% Recording setup
+sectionRecordingSetup = sectionGeneral.openSection('Recording setup');
+cellfun(@(x) disp(x.name),sectionRecordingSetup.properties)
+fprintf(['Recording setup iEEG: ',sectionRecordingSetup.openProperty('Recording setup iEEG').values{1}.value,'\n'])
+
+%% Task information
+sectionTask = f.openSection('Task');
+% Properties
+cellfun(@(x) disp(x.name),sectionTask.properties)
+% Task characteristics
+fprintf(['Task name: ',sectionTask.openProperty('Task name').values{1}.value,'\n'])
+fprintf(['Task description: ',sectionTask.openProperty('Task description').values{1}.value,'\n'])
+fprintf(['Task URL: ',sectionTask.openProperty('Task URL').values{1}.value,'\n']) % TODO
+
+%% Subject information
+sectionSubject = f.openSection('Subject');
+% Properties
+cellfun(@(x) disp(x.name),sectionSubject.properties)
+% Subject characteristics
+fprintf(['Age: ',num2str(sectionSubject.openProperty('Age').values{1}.value),'\n'])
+fprintf(['Gender: ',sectionSubject.openProperty('Gender').values{1}.value,'\n']) % Sex?
+fprintf(['Pathology: ',sectionSubject.openProperty('Pathology').values{1}.value,'\n'])
+fprintf(['Depth electrodes: ',sectionSubject.openProperty('Depth electrodes').values{1}.value,'\n'])
+fprintf(['Electrodes in seizure onset zone (SOZ): ',sectionSubject.openProperty('Electrodes in seizure onset zone (SOZ)').values{1}.value,'\n'])
+
+%% Session information
+sectionSession = f.openSection('Session');
+% Properties
+cellfun(@(x) disp(x.name),sectionSession.properties)
+% Session characteristics
+fprintf(['Number of trials: ',num2str(sectionSession.openProperty('Number of trials').values{1}.value),'\n'])
+fprintf(['Trial duration: ',num2str(sectionSession.openProperty('Trial duration').values{1}.value),' ',sectionSession.openProperty('Trial duration').unit,'\n'])
+% Sections
+cellfun(@(x) disp(x.name),sectionSession.sections)
+
+%% Trial information
+sectionTrialProperties = sectionSession.openSection('Trial properties');
+% Sections
+cellfun(@(x) disp(x.name),sectionTrialProperties.sections)
+% Each section is for a single trial
+% Select trial
+nTrial = 1;
+sectionSingleTrial = sectionTrialProperties.sections{nTrial};
+
+%% Single trial
+% Properties
+cellfun(@(x) disp(x.name),sectionSingleTrial.properties)
+for nProperty = 1:length(sectionSingleTrial.properties)
+    switch sectionSingleTrial.properties{nProperty}.datatype
+        case {'double','logical'}
+            fprintf([sectionSingleTrial.properties{nProperty}.name,': ',num2str(sectionSingleTrial.properties{nProperty}.values{1}.value),'\n'])
+        otherwise
+            fprintf([sectionSingleTrial.properties{nProperty}.name,': ',sectionSingleTrial.properties{nProperty}.values{1}.value,'\n'])
+    end
+end
+
+%% Blocks
+cellfun(@(x) disp(x.name),f.blocks)
+block = f.blocks{1};
+
+%% Groups of data arrays, tags, multitags
+groups = block.groups;
+cellfun(@(x) disp(x.name),block.groups)
+
+%% Select trial
+nTrial = 1;
+
+%% iEEG data
+group_iEEG = block.openGroup('iEEG data');
+% Data array
+dataArray_iEEG = group_iEEG.dataArrays{nTrial};
+
+% Electrode labels
+striEEGLabels = dataArray_iEEG.dimensions{1}.labels;
+% Time axis
+tiEEG = (0:(double(dataArray_iEEG.dataExtent(2))-1))*dataArray_iEEG.dimensions{2}.samplingInterval+dataArray_iEEG.dimensions{2}.offset;
+% Read data
+data_iEEG = dataArray_iEEG.readAllData;
+
+% Plot trial data
+figure
+plot(tiEEG,data_iEEG)
+title(['iEEG data - Trial ',num2str(nTrial)])
+xlabel(['Time (',dataArray_iEEG.dimensions{2}.unit,')'])
+ylabel(['Voltage (',dataArray_iEEG.unit,')'])
+xlim([tiEEG(1),tiEEG(end)])
+legend(striEEGLabels)
+
+%% Trial events
+group_TrialEvents_iEEG = block.openGroup('Trial events single tags iEEG');
+
+%% Trial events for a single trial
+indTrialTags_iEEG = contains(cellfun(@(x) x.name,group_TrialEvents_iEEG.tags,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
+
+TrialEvents_iEEG = group_TrialEvents_iEEG.tags(indTrialTags_iEEG);
+
+cellfun(@(x) disp(x.name),TrialEvents_iEEG)
+
+%% Time of a single event
+nEvent = 1; % Condition
+fprintf(['Event name: ',TrialEvents_iEEG{nEvent}.name,'\n'])
+fprintf([sprintf('Time w.r.t. fixation: %.1f %s',TrialEvents_iEEG{nEvent}.position(2),TrialEvents_iEEG{nEvent}.units{1}),'\n'])
+fprintf([sprintf('Duration: %.1f %s',TrialEvents_iEEG{nEvent}.extent(2),TrialEvents_iEEG{nEvent}.units{1}),'\n'])
+
+%% Units
+group_SpikeTimes = block.openGroup('Spike times');
+
+%% Select unit and trial
+nUnit = 1;
+nTrial = 5;
+indUnitSpikeTimes = contains(cellfun(@(x) x.name,group_SpikeTimes.dataArrays,'UniformOutput',0),['Unit_',num2str(nUnit),'_'])&...
+    contains(cellfun(@(x) x.name,group_SpikeTimes.dataArrays,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
+
+dataArray_SpikeTimes = group_SpikeTimes.dataArrays{indUnitSpikeTimes};
+% 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,')'])
+
+%% Multitag for the unit
+indMultiTagUnitSpikeTimes = contains(cellfun(@(x) x.name,block.multiTags,'UniformOutput',0),['Unit_',num2str(nUnit),'_'])&...
+    contains(cellfun(@(x) x.name,block.multiTags,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
+
+multiTag_SpikeTimes = block.multiTags{indMultiTagUnitSpikeTimes};
+
+%% 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')
+

+ 32 - 0
code_MATLAB/Main_Plot_Figures.m

@@ -0,0 +1,32 @@
+%% Close all figures, clear variables and command window
+close all
+clear
+clc
+
+%% Directory of the repository and the NIX library
+strMainPath = 'Human_Amygdala_MUA_sEEG_FearVideo\';
+strNIXLibraryPath = 'nix-mx_Win64_1.4.1\';
+strFieldTripPath = 'fieldtrip-20200315\';
+
+%% Add necessary folders to the MATLAB path
+addpath([strMainPath,'\code_MATLAB\'])
+addpath(genpath(strNIXLibraryPath))
+addpath(strFieldTripPath)
+ft_defaults
+
+warning('strMainPath should be the full path of the folder 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''')
+
+%% NIX data files
+strNIXFileNames = dir([strMainPath,'\data_NIX\*.h5']);
+strNIXFileNames = {strNIXFileNames.name}';
+
+assert(~isempty(strNIXFileNames),'strMainPath should be the full path of the folder Human_Amygdala_MUA_sEEG_FearVideo')
+
+%% Figure 1
+nExampleNeuron = 1;
+fig1 = Figure_1([strMainPath,'\data_NIX\'],nExampleNeuron);
+
+%% Figure 2
+fig2 = Figure_2([strMainPath,'\data_NIX\']);