Skip to content

Commit

Permalink
Merge pull request #2 from DouweHorsthuis/update_2
Browse files Browse the repository at this point in the history
update after use
  • Loading branch information
DouweHorsthuis authored Oct 20, 2021
2 parents f2fa05f + dcf918e commit a834c20
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 210 deletions.
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ This is still a work in progress. This Repo will contain the full pipeline to an

**Table of Contents**
1. [About The Project](#about-the-project)
2. [Getting started](#getting-started)
2. [Getting started](#getting-started)
- [Prerequisites](#prerequisites)
3. [Resting state project](#resting-state-project)
3. [Pipeline](#pipeline)
- [Raw data to .set and merge](#raw-data-to-.set-and-merge)
- [Pre processing](#pre-processing)
3. [License](#license)
3. [Contact](#contact)
3. [Acknowledgement](#acknowledgement)
3. [Resting state project](#resting-state-project)
3. [Pipeline](#pipeline)
- [Raw data to .set and merge](#raw-data-to-.set-and-merge)
- [Pre processing](#pre-processing)
3. [Power Frequency Analysis](#power-frequency-analysis)
3. [Microstates](#microstates)
- [I_Mictrostates_groups](#i_mictrostates_groups)
- [I_Mictrostates_all](#i_mictrostates_all)
3. [License](#license)
3. [Contact](#contact)
3. [Acknowledgement](#acknowledgement)



Expand Down Expand Up @@ -115,12 +119,17 @@ After that we use the the [pwelch function of Matlab](https://www.mathworks.com/

# add here what channels we use, for now it's just indivual but we will change this to groups and averages of those groups

### Microstates Groups & all

### Microstates
this script follows the code as descibed in Poulsen, A. T., Pedroni, A., Langer, N., & Hansen, L. K. (2018). Microstate EEGlab toolbox: An introductory guide. [See their guide in bioRxiv for more information.](https://www.biorxiv.org/content/10.1101/289850v1)

In the first part the analysis only focuses on the group level. Since we use both eyes open and eyes closed data, we want to check how many microstates are suggested for both, so we can choose the best (same) amount for both. In the case of patient/control group we would need to compare all 4 the suggestions. Running the whole script would take a lot of time that wasn't needed.
#### I_Mictrostates_groups
In the We first focuses on the group level. Since we use both eyes open and eyes closed data, we want to check how many microstates are suggested for both, so we can choose the best (same) amount for both. In the case of patient/control group we would need to compare all 4 the suggestions. Running the whole script would take a lot of time that wasn't needed.

#### J_Microstates_all

The second script will backfit the mictrostates on the individual EEGs (since now you know how many microstates you want). Giving both plots per subject and adds data to the EEG structure to do stats on.

The second script will do everything again (since now you know how many microstates you want) and backfits it on the individual EEGs. Giving both plots per subject and adds data to the EEG structure to do stats on.


## License
Expand Down
38 changes: 20 additions & 18 deletions src/A_bdf_merge_sets.m
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
% Testing the scr code 6/21/2021
subject_list = {'10033' '10130' '10131' '10257' '10281' '10293' '10360' '10369' '10385' '10394' '10438' '10446' '10463' '10476' '10526' '10545' '10561' '10562' '10581' '10585' '10616' '10748' '10780' '10784' '10822' '10858' '10906' '10915' '10929' '10935' '12005' '12006' '12007' '12010' '12215' '12328' '12360' '12413' '12512' '12648' '12651' '12707' '12727' '12739' '12750' '12815' '12898' '12899'};% ------------------------------------------------
%% extra controls
subject_list = {'10297' '10331' '10385' '10497' '10553' '10590' '10640' '10867' '10906' '12004' '12006' '12139' '12177' '12188' '12197' '12203' '12206' '12230' '12272' '12415' '12449' '12474' '12482' '12516' '12534' '12549' '12588' '12632' '12735' '12746' '12755' '12770' '12852' '12870'};
%subject_list = {'10033' '10130' '10131' '10257' '10281' '10293' '10360' '10369' '10385' '10394' '10438' '10446' '10463' '10476' '10526' '10545' '10561' '10562' '10581' '10585' '10616' '10748' '10780' '10784' '10822' '10858' '10906' '10915' '10929' '10935' '12005' '12006' '12007' '12010' '12215' '12328' '12360' '12413' '12512' '12648' '12651' '12707' '12727' '12739' '12750' '12815' '12898' '12899'};% ------------------------------------------------

%subject_list = {'1106' '1108' '1132' '1134' '1154' '1160' '1173' '1174' '1179' '1190' '1838' '1839' '1874' '11013' '11051' '11056' '11098' '11106' '11198' '11220' '11244' '11293' '11325' '11354' '11369' '11375' '11515' '11560' '11580' '11667' '11721' '11723' '11750' '11852' '11896' '11898' '11913' '11927' '11958' '11965'}; %all the IDs for the indivual particpants
filename = 'restingstate'; % if your bdf file has a name besides the ID of the participant (e.g. oddball_paradigm)
home_path = '\\data.einsteinmed.org\users\Filip Ana Douwe\Resting state data\Control\'; %place data is (something like 'C:\data\')
home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Remaining_controls\'; %place data is (something like 'C:\data\')
blocks = 1; % the amount of BDF files. if different participant have different amounts of blocks, run those participant separate
for s = 3:length(subject_list)
for s = 1:length(subject_list)
clear ALLEEG
eeglab
close all
data_path = [home_path subject_list{s} '\'];
disp([data_path subject_list{s} '_' filename '.bdf'])

%if blocks == 1
%if participants have only 1 block, load only this one file
EEG = pop_biosig([data_path subject_list{s} '_' filename '.bdf']);

% else
% for bdf_bl = 1:blocks
% %if participants have more than one block, load the blocks in a row
% %your files need to have the same name, except for a increasing number at the end (e.g. id#_file_1.bdf id#_file_2)
% EEG = pop_biosig([data_path subject_list{s} '_' filename '_' num2str(bdf_bl) '.bdf']);
% [ALLEEG, ~] = eeg_store(ALLEEG, EEG, CURRENTSET);
% end
% %since there are more than 1 files, they need to be merged to one big .set file.
% EEG = pop_mergeset( ALLEEG, 1:blocks, 0);
% end
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 0,'setname', [subject_list{s} ' restingstate paradigm'],'gui','off'); %adds a name to the internal .set file
%if participants have only 1 block, load only this one file
EEG = pop_biosig([data_path subject_list{s} '_' filename '.bdf']);

% else
% for bdf_bl = 1:blocks
% %if participants have more than one block, load the blocks in a row
% %your files need to have the same name, except for a increasing number at the end (e.g. id#_file_1.bdf id#_file_2)
% EEG = pop_biosig([data_path subject_list{s} '_' filename '_' num2str(bdf_bl) '.bdf']);
% [ALLEEG, ~] = eeg_store(ALLEEG, EEG, CURRENTSET);
% end
% %since there are more than 1 files, they need to be merged to one big .set file.
% EEG = pop_mergeset( ALLEEG, 1:blocks, 0);
% end
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 0,'setname', [subject_list{s} ' restingstate paradigm'],'gui','off'); %adds a name to the internal .set file
%save the bdf as a .set file
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '.set'],'filepath',data_path);
end
Expand Down
30 changes: 21 additions & 9 deletions src/A_bdf_non_paradigm_merge_sets.m
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
% Testing the scr code 6/21/2021
% ------------------------------------------------
%clear variables
subject_list = {'10158' '10165' '10384' '10407' '10451' '10467' '10501' '10534' '10615' '10620' '10639' '10844' '10956'};
%% extra controls
clear variables
%_closed.bdf
%_open.bdf
subject_list = {'10399' '12002' '12122'};
%subject_list = {'10158' '10165' '10384' '10407' '10451' '10467' '10501' '10534' '10615' '10620' '10639' '10844' '10956'};
%subject_list = {'1101' '1164' '1808' '1852' '1855' '11014' '11094' '11151' '11170' '11275' '11349' '11516' '11558' '11583' '11647' '11729' '11735' '11768' '11783' '11820' '11912'};
filename = 'restingstate'; % if your bdf file has a name besides the ID of the participant (e.g. oddball_paradigm)
home_path = '\\data.einsteinmed.org\users\Filip Ana Douwe\Resting state data\Control\'; %place data is (something like 'C:\data\')
home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Remaining_controls\'; %place data is (something like 'C:\data\')
wrongconfig = zeros(1,length(subject_list)); %there are 160channel files that have a wrong config file, this is to save them
for s = 8:length(subject_list)
for s = 1:length(subject_list)
clear ALLEEG
eeglab
close all
data_path = [home_path subject_list{s} '\'];
disp([data_path subject_list{s} '_' filename '.bdf'])
disp([data_path subject_list{s} '.bdf'])

%loading file 1, adding triggers
EEG = pop_biosig([data_path subject_list{s} '_' filename '_open.bdf']);
EEG = pop_biosig([data_path subject_list{s} '_open.bdf']);
first = 1; %where the trigger will happen
second = 10;
TRIG = [first 0; second 50]; %script doesn't like only one trigger so adding 2 (first one can be ignored)
%%%% Import All events back into the EEG data structure
EEG = pop_importevent( EEG, 'event', TRIG, 'fields',{'latency','type'},'timeunit',NaN,'append','no');
EEG = pop_editeventvals(EEG,'delete',1); %deleting the extra event
EEG = pop_editeventvals(EEG,'delete',1); %deleting the extra event
EEG = eeg_checkset(EEG);
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
%loading file 2, adding triggers
EEG = pop_biosig([data_path subject_list{s} '_' filename '_closed.bdf']);
EEG = pop_biosig([data_path subject_list{s} '_closed.bdf']);
first = 1; %where the trigger will happen
second = 10;
TRIG = [first 0; second 51]; %script doesn't like only one trigger so adding 2 (first one can be ignored)
%%%% Import All events back into the EEG data structure
EEG = pop_importevent( EEG, 'event', TRIG, 'fields',{'latency','type'},'timeunit',NaN,'append','no');
EEG = pop_editeventvals(EEG,'delete',1); %deleting the extra event
EEG = pop_editeventvals(EEG,'delete',1); %deleting the extra event
EEG = eeg_checkset(EEG);
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
EEG = pop_mergeset( ALLEEG, 1:2, 0);%merging into one
Expand All @@ -44,6 +48,14 @@
wrongconfig(:,s)=string(subject_list(s));
end
disp('fixed configuration')
if strcmp(subject_list{s},'10399') %collected data with 160chn config but only data in 64 ch
EEG = pop_select( EEG, 'channel',{'A1','A2','A3','A4','A5','A6','A7','A8','A9','A10','A11','A12','A13','A14','A15','A16','A17','A18','A19','A20','A21','A22','A23','A24','A25','A26','A27','A28','A29','A30','A31','A32','B1','B2','B3','B4','B5','B6','B7','B8','B9','B10','B11','B12','B13','B14','B15','B16','B17','B18','B19','B20','B21','B22','B23','B24','B25','B26','B27','B28','B29','B30','B31','B32'});
correct_64_chan={'Fp1' 'AF7' 'AF3' 'F1' 'F3' 'F5' 'F7' 'FT7' 'FC5' 'FC3' 'FC1' 'C1' 'C3' 'C5' 'T7' 'TP7' 'CP5' 'CP3' 'CP1' 'P1' 'P3' 'P5' 'P7' 'P9' 'PO7' 'PO3' 'O1' 'Iz' 'Oz' 'POz' 'Pz' 'CPz' 'Fpz' 'Fp2' 'AF8' 'AF4' 'AFz' 'Fz' 'F2' 'F4' 'F6' 'F8' 'FT8' 'FC6' 'FC4' 'FC2' 'FCz' 'Cz' 'C2' 'C4' 'C6' 'T8' 'TP8' 'CP6' 'CP4' 'CP2' 'P2' 'P4' 'P6' 'P8' 'P10' 'PO8' 'PO4' 'O2'};
for n=1:64
EEG.chanlocs(n).labels = correct_64_chan{n};
wrongconfig(:,s)=string(subject_list(s));
end
end
EEG = eeg_checkset(EEG);
end
%save the bdf as a .set file
Expand Down
11 changes: 7 additions & 4 deletions src/B_preprocess1.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
% ------------------------------------------------
clear variables
eeglab
group = {'Aging' 'ASD' 'Control'};%
group = {'Control'};%
for g=1:length(group)
if strcmp(group{g},'ASD')
subject_list = {'1101' '1164' '1808' '1852' '1855' '11014' '11094' '11151' '11170' '11275' '11349' '11516' '11558' '11583' '11647' '11729' '11735' '11768' '11783' '11820' '11912' '1106' '1108' '1132' '1134' '1154' '1160' '1173' '1174' '1179' '1190' '1838' '1839' '1874' '11013' '11056' '11098' '11106' '11198' '11244' '11293' '11325' '11354' '11369' '11375' '11515' '11560' '11580' '11667' '11721' '11723' '11750' '11852' '11896' '11898' '11913' '11927' '11958' '11965'}; %all the IDs for the indivual particpants
Expand All @@ -17,8 +17,11 @@
subject_list = {'12022' '12023' '12031' '12081' '12094' '12188' '12255' '12335' '12339' '12362' '12364' '12372' '12376' '12390' '12398' '12407' '12408' '12451' '12454' '12457' '12458' '12459' '12468' '12478' '12498' '12510' '12517' '12532' '12564' '12631' '12633' '12634' '12636' '12665' '12670' '12696' '12719' '12724' '12751' '12763' '12769' '12776' '12790' '12806' '12814' '12823' '12830' '12847' '12851' '12855' '12856' '12857' '12859' '12871' '12872' '12892'};
home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Aging\';
elseif strcmp(group{g},'Control')
subject_list = {'10158' '10165' '10384' '10407' '10451' '10467' '10501' '10534' '10615' '10620' '10639' '10844' '10956' '10033' '10130' '10131' '10257' '10281' '10293' '10360' '10369' '10394' '10438' '10446' '10463' '10476' '10526' '10545' '10561' '10562' '10581' '10585' '10616' '10748' '10780' '10784' '10822' '10858' '10906' '10915' '10929' '10935' '12005' '12007' '12010' '12215' '12328' '12360' '12413' '12512' '12648' '12651' '12707' '12727' '12739' '12750' '12815' '12898' '12899'};% ------------------------------------------------
home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Control\';
%% extra controls
subject_list = {'10297' '10331' '10385' '10399' '10497' '10553' '10590' '10640' '10867' '10906' '12002' '12004' '12006' '12122' '12139' '12177' '12188' '12197' '12203' '12206' '12230' '12272' '12415' '12449' '12474' '12482' '12516' '12534' '12549' '12588' '12632' '12735' '12746' '12755' '12770' '12852' '12870'};
%% aged matched controls
%subject_list = {'10158' '10165' '10384' '10407' '10451' '10467' '10501' '10534' '10615' '10620' '10639' '10844' '10956' '10033' '10130' '10131' '10257' '10281' '10293' '10360' '10369' '10394' '10438' '10446' '10463' '10476' '10526' '10545' '10561' '10562' '10581' '10585' '10616' '10748' '10780' '10784' '10822' '10858' '10906' '10915' '10929' '10935' '12005' '12007' '12010' '12215' '12328' '12360' '12413' '12512' '12648' '12651' '12707' '12727' '12739' '12750' '12815' '12898' '12899'};% ------------------------------------------------
home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Remaining_controls\';
end
deleted_channels=zeros(length(subject_list),2);
wrongconfig_type2 = zeros(1,length(subject_list));
Expand Down Expand Up @@ -76,7 +79,7 @@
old_n_chan = EEG.nbchan;
EEG = clean_artifacts(EEG, 'FlatlineCriterion',5,'ChannelCriterion',0.8,'LineNoiseCriterion',4,'Highpass','off','BurstCriterion','off','WindowCriterion','off','BurstRejection','on','Distance','Euclidian');
new_n_chan = EEG.nbchan;
deleted_channels{s} = [string(subject_list{s}), old_n_chan-new_n_chan] ;
deleted_channels(s,:) = [string(subject_list{s}), old_n_chan-new_n_chan] ;
EEG = pop_saveset( EEG, 'filename',[subject_list{s} '_exchn.set'],'filepath', data_path);
end
%saving matrixes for quality control
Expand Down
15 changes: 10 additions & 5 deletions src/C_manual_check.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
%% ASD
%subject_list = {'1101' '1164' '1808' '1852' '1855' '11014' '11094' '11151' '11170' '11275' '11349' '11516' '11558' '11583' '11647' '11729' '11735' '11768' '11783' '11820' '11912' '1106' '1108' '1132' '1134' '1154' '1160' '1173' '1174' '1179' '1190' '1838' '1839' '1874' '11013' '11056' '11098' '11106' '11198' '11244' '11293' '11325' '11354' '11369' '11375' '11515' '11560' '11580' '11667' '11721' '11723' '11750' '11852' '11896' '11898' '11913' '11927' '11958' '11965'}; %all the IDs for the indivual particpants
%home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\ASD\';
%% ASD controls
%% aged matched controls
%subject_list = {'10033' '10130' '10131' '10158' '10165' '10257' '10281' '10293' '10360' '10369' '10384' '10394' '10407' '10438' '10446' '10451' '10463' '10467' '10476' '10501' '10526' '10534' '10545' '10561' '10562' '10581' '10585' '10616' '10615' '10620' '10639' '10748' '10780' '10784' '10822' '10858' '10906' '10915' '10929' '10935' '10844' '10956' '12005' '12007' '12010' '12215' '12328' '12360' '12413' '12512' '12648' '12651' '12707' '12727' '12739' '12750' '12815' '12898' '12899'};% ------------------------------------------------
%home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Control\';
%% extra controls
subject_list = {'10297' '10331' '10385' '10399' '10497' '10553' '10590' '10640' '10867' '10906' '12002' '12004' '12006' '12122' '12139' '12177' '12188' '12197' '12203' '12206' '12230' '12272' '12415' '12449' '12474' '12482' '12516' '12534' '12549' '12588' '12632' '12735' '12746' '12755' '12770' '12852' '12870'};
% did these again because need extra channels deleted
% subject_list = {'12139' '10399'};
home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Remaining_controls\';
%% MoBI
subject_list = {'12022' '12023' '12031' '12081' '12094' '12188' '12255' '12335' '12339' '12362' '12364' '12372' '12376' '12390' '12398' '12407' '12408' '12451' '12454' '12457' '12458' '12459' '12468' '12478' '12498' '12510' '12517' '12532' '12564' '12631' '12633' '12634' '12636' '12665' '12670' '12696' '12719' '12724' '12751' '12763' '12769' '12776' '12790' '12806' '12814' '12823' '12830' '12847' '12851' '12855' '12856' '12857' '12859' '12871' '12872' '12892'};
% controls and ASD subjects that need to be re-checked because of 160 channel info
%'10131' '10257' '10369' '10438' '10545' '10585' '12360' '12898' '1808' '1852' '1855' '11345' '1106' '1134' '1154' '1160' '1174' '1179' '1190' '1838' '11106' '11375' '11913'
home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Aging\';
% subject_list = {'12022' '12023' '12031' '12081' '12094' '12188' '12255' '12335' '12339' '12362' '12364' '12372' '12376' '12390' '12398' '12407' '12408' '12451' '12454' '12457' '12458' '12459' '12468' '12478' '12498' '12510' '12517' '12532' '12564' '12631' '12633' '12634' '12636' '12665' '12670' '12696' '12719' '12724' '12751' '12763' '12769' '12776' '12790' '12806' '12814' '12823' '12830' '12847' '12851' '12855' '12856' '12857' '12859' '12871' '12872' '12892'};
% % controls and ASD subjects that need to be re-checked because of 160 channel info
% %'10131' '10257' '10369' '10438' '10545' '10585' '12360' '12898' '1808' '1852' '1855' '11345' '1106' '1134' '1154' '1160' '1174' '1179' '1190' '1838' '11106' '11375' '11913'
% home_path = 'C:\Users\dohorsth\Desktop\Testing restingstate\Aging\';
for s=1:length(subject_list)
clear bad_chan;
fprintf('\n******\nProcessing subject %s\n******\n\n', subject_list{s});
Expand Down
Loading

0 comments on commit a834c20

Please sign in to comment.