-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom_preart.m
More file actions
112 lines (90 loc) · 2.72 KB
/
from_preart.m
File metadata and controls
112 lines (90 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
%Peform artifact rejection/correction for subject that has an existing
%preart EEGset
% 1. Load preart set
% 2. Add ICA weights
% 3. Open artifact rejection script
%
%Author: Eric Fields
%Version Date: 8 August 2023
%Copyright (c) 2023, Eric Fields
%All rights reserved.
%This code is free and open source software made available under the terms
%of the 3-clause BSD license:
%https://opensource.org/licenses/BSD-3-Clause
clearvars; close all; clc;
%% Parameters
%Get main data directory
main_dir = EmCon_main_dir();
%Default artifact rejection script
default_arf = fullfile(main_dir, 'code', 'arf', 'EmCon_default_arf.m');
%Batch processing
%subject_ids = get_subset('postart', [], main_dir);
%% Set-up
cd(main_dir);
addpath(fullfile(main_dir, 'code'));
addpath(fullfile(main_dir, 'code', 'arf'));
%If subject_ids variable is not defined above, prompt user
if ~exist('subject_ids', 'var') || isempty(subject_ids)
subject_ids = input('\n\nSubject ID: ','s');
end
if strcmpi(subject_ids, 'rand')
subject_ids = rand_sub('preart', 'postart', main_dir);
if isempty(subject_ids)
return;
end
end
%Parse subject ID input
%If subject_ids is a cell array, use as is
if iscell(subject_ids)
sub_ids = subject_ids;
%If subject_ids is a text file, read lines into cell array
elseif exist(subject_ids, 'file')
sub_ids = {};
f_in = fopen(subject_ids);
while ~feof(f_in)
sub_ids = [sub_ids fgetl(f_in)]; %#ok<AGROW>
end
fclose(f_in);
%If subject_ids is a string (i.e., single subject), convert to cell array
elseif ischar(subject_ids)
sub_ids = {subject_ids};
else
error('\nInappropriate value for subject_ids variable\n');
end
%Batch processing?
if length(sub_ids) > 1
batch_proc = true;
compute_erps = true;
else
batch_proc = false;
end
%% Run
for i = 1:length(sub_ids)
sub_id = sub_ids{i};
%Start EEGLAB
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab; %#ok<ASGLU>
%Load preart EEGset
EEG = pop_loadset('filename', [sub_id '_preart.set'], 'filepath', fullfile(main_dir, 'EEGsets'));
[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, 0);
%Check for ICA weights
if isempty(EEG.icaweights) && ~batch_proc
user_resp = questdlg('No ICA weights. Continue?');
if ~strcmpi('Yes', user_resp)
eeglab redraw;
return
end
end
%Open or run arf script
sub_arf = fullfile(main_dir, 'code', 'arf', sprintf('arf_%s.m', sub_id));
if batch_proc
run(sub_arf)
else
if ~exist(sub_arf, 'file')
fprintf('\nSubject arf script doesn''t exist, so I will create one.\n\n');
copyfile(default_arf, sub_arf);
end
edit(sub_arf);
end
end
eeglab redraw;
erplab redraw;