Repository navigation
Expand file tree
/
Copy pathMain.m
More file actions
120 lines (95 loc) · 3.77 KB
/
Copy pathMain.m
File metadata and controls
120 lines (95 loc) · 3.77 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
113
114
115
116
117
118
119
% main.m
% Script to process data in the `files_to_process` folder and save results
% Contact: Sebastian Gallo, galloseb@mit.edu
% Date: Jan 13, 2025
% Must be ran while in peds_cp folder
% Must have path to chronux and eeg lab
clc; clear; close all;
% Define paths
projectDir = pwd; % Current directory containing `peds_cp`
dataDir = fullfile(projectDir, 'files_to_process');
resultsDir = fullfile(projectDir, 'results');
% Create results directory if it doesn't exist
if ~exist(resultsDir, 'dir')
mkdir(resultsDir);
end
% Get list of .mat files in the data directory
dataFiles = dir(fullfile(dataDir, '*.mat'));
%% Single use case for Topoplot
%% Directory Creation
% Simulate a single file from the data directory
fileName = 'Archive_1_CS_2_nobads_laplac_ds256_focus.mat'; % Test file
dataPath = fullfile(dataDir, fileName);
% Test parameters
peakFreq = 13; % Frequency of interest (e.g., 10 Hz)
compareFreq = 7; % Optional comparison frequency (e.g., 5 Hz)
fprintf('Processing file: %s\n', fileName);
% Determine if the file is a patient (CS) or control (CN)
if contains(fileName, '_CS_')
group = 'patients';
subjectID = regexp(fileName, 'CS_\d+', 'match', 'once'); % Extract CS_#
elseif contains(fileName, '_CN_')
group = 'controls';
subjectID = regexp(fileName, 'CN_\d+', 'match', 'once'); % Extract CN_#
else
fprintf('Skipping file (unknown group): %s\n', fileName);
return;
end
% Define the save path based on group and subject ID
savePath = fullfile(resultsDir, group, subjectID,'topoplot');
% Create the save directory if it doesn't exist
if ~exist(savePath, 'dir')
mkdir(savePath);
end
%% Topoplot creation
% Call the function to generate the topoplot
try
runPowerTopoplot(dataPath, savePath, peakFreq, compareFreq);
fprintf('Successfully processed %s\n', fileName);
catch ME
fprintf('Error processing %s: %s\n', fileName, ME.message);
end
fprintf('Processing completed. Results saved in %s\n', savePath);
%% Section for processing all topoplot
% Parameters
peakFreq = 13; % Frequency of interest (e.g., 13 Hz)
compareFreq = [7]; % Optional comparison frequency (set to [] if not used)
% Loop through each file and process
for i = 1:length(dataFiles)
fprintf('Processing file %d of %d: %s\n', i, length(dataFiles), dataFiles(i).name);
% Full path to the data file
dataPath = fullfile(dataFiles(i).folder, dataFiles(i).name);
fileName = dataFiles(i).name; % Get the file name
% Check if it's a patient (CS) or control (CN)
if contains(fileName, '_CS_')
group = 'patients';
subjectID = regexp(fileName, 'CS_\d+', 'match', 'once'); % Extract CS_#
elseif contains(fileName, '_CN_')
group = 'controls';
subjectID = regexp(fileName, 'CN_\d+', 'match', 'once'); % Extract CN_#
else
fprintf('Skipping file (unknown group): %s\n', fileName);
continue;
end
% Define save path based on group and subject ID
savePath = fullfile(resultsDir, group, subjectID, 'topoplot');
% Create the save directory if it doesn't exist
if ~exist(savePath, 'dir')
mkdir(savePath);
end
% Determine if both `peakFreq` and `compareFreq` are used
try
if isempty(compareFreq)
% Only peakFreq
runPowerTopoplot(dataPath, savePath, peakFreq);
fprintf('Processed %s with peakFreq only: %d Hz\n', fileName, peakFreq);
else
% Both peakFreq and compareFreq
runPowerTopoplot(dataPath, savePath, peakFreq, compareFreq);
fprintf('Processed %s with peakFreq: %d Hz and compareFreq: %d Hz\n', fileName, peakFreq, compareFreq);
end
catch ME
fprintf('Error processing %s: %s\n', fileName, ME.message);
end
end
fprintf('All files processed. Results saved in %s\n', resultsDir);