Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #155

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfs_properties/general_params.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "description":"", "modality":"EEG", "dataset":{ "Name":"CHBMP", "Description":"HeadModel_Ariosdy"}, "bst_config":{ "description":"", "protocol_name":"HeadModel_CHBMP", "reset_protocol":false, "bst_path":"/mnt/Develop/Tools/brainstorm3", "db_path":"local", "after_MaQC":{ "run":false}}, "output_path":"/mnt/Store/OneDrive/Ariosdy/Tesis/Application/Data", "tmp_path":"local"}
{ "description":"", "modality":"EEG", "dataset":{ "Name":"Barbados", "Description":"Barbados dataset from Multinational Norms" }, "bst_config":{ "description":"", "protocol_name":"Barbados", "reset_protocol":false, "bst_path":"D:/Develop/Tools/brainstorm3", "db_path":"local", "after_MaQC":{ "run":false } }, "output_path":"E:/Data/MultinationalNorm/Barbados/derivatives", "tmp_path":"local"}
Expand Down
2 changes: 1 addition & 1 deletion cfs_properties/process_import_anat.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "description":"", "anatomy_type":{ "description":"Select the type of anatomy to use. <<template>> Brainstorm default anatomy. <<individual>> HCP individual anatomy", "type":"individual", "type_list":[ { "id":"default", "name":"default_anatomy", "description":"Select the Brainstorm anatomy template. See app/bst_default_anatomy.json file and select all params from there", "template_name":"ICBM152_2023b", "default_atlas":"Desikan-Killiany" },{ "id":"individual", "name":"hcp_anat_individual", "description":"HCP individual anatomy", "base_path":"/mnt/Store/OneDrive/Ariosdy/Tesis/Application/Data/ciftify", "T1w_file_name":"T1w.nii.gz", "Atlas_file_name":"aparc+aseg.nii.gz" },{ "id":"template", "name":"hcp_anat_template", "description":"HCP anatomy to use as template for EEG dataset", "base_path":"D:/Data/MIITRA/ciftify", "template_name":"MIITRA", "T1w_file_name":"T1w.nii.gz", "Atlas_file_name":"aparc.a2009s+aseg.nii.gz" } ] }, "common_params":{ "mri_transformation":{ "use_transformation":false, "base_path":"/mnt/Store/Data/Conectome/Sample", "file_name":"meg/SubID/MEG/anatomy/SubID_MEG_anatomy_transform.txt" }, "non_brain_surfaces":{ "description":"FSL Bet command output", "base_path":"/mnt/Store/OneDrive/Ariosdy/Tesis/Application/Data/fsl_bet" }, "layer_desc":{ "description":"Layer descriptor. Options <<white>> OR <<midthickness>> OR <<pial>> OR <<bigbrain>> multilayer like bigbrain OR <<fs_LR>> like HCP FSAve (three layers).", "desc":"Midthickness" }, "surfaces_resolution":{ "description":"Numbers of vertices for downsample the surfaces: default <<8000>>", "nvertices":8000 } }}
{ "description":"", "anatomy_type":{ "description":"Select the type of anatomy to use. <<template>> Brainstorm default anatomy. <<individual>> HCP individual anatomy", "type":"default", "type_list":[ { "id":"default", "name":"default_anatomy", "description":"Select the Brainstorm anatomy template. See app/bst_default_anatomy.json file and select all params from there", "template_name":"ICBM152_2023b", "default_atlas":"Desikan-Killiany" },{ "id":"individual", "name":"hcp_anat_individual", "description":"HCP individual anatomy", "base_path":"/mnt/Store/OneDrive/Ariosdy/Tesis/Application/Data/ciftify", "T1w_file_name":"T1w.nii.gz", "Atlas_file_name":"aparc+aseg.nii.gz" },{ "id":"template", "name":"hcp_anat_template", "description":"HCP anatomy to use as template for EEG dataset", "base_path":"D:/Data/MIITRA/ciftify", "template_name":"MIITRA", "T1w_file_name":"T1w.nii.gz", "Atlas_file_name":"aparc.a2009s+aseg.nii.gz" } ] }, "common_params":{ "mri_transformation":{ "use_transformation":false, "base_path":"/mnt/Store/Data/Conectome/Sample", "file_name":"meg/SubID/MEG/anatomy/SubID_MEG_anatomy_transform.txt" }, "non_brain_surfaces":{ "description":"FSL Bet command output", "base_path":"/mnt/Store/OneDrive/Ariosdy/Tesis/Application/Data/fsl_bet" }, "layer_desc":{ "description":"Layer descriptor. Options <<white>> OR <<midthickness>> OR <<pial>> OR <<bigbrain>> multilayer like bigbrain OR <<fs_LR>> like HCP FSAve (three layers).", "desc":"Midthickness" }, "surfaces_resolution":{ "description":"Numbers of vertices for downsample the surfaces: default <<8000>>", "nvertices":8000 } }}
Expand Down
2 changes: 1 addition & 1 deletion cfs_properties/process_integration.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "description":"Integration process for Structural and Functional Data", "preproc_data":{ "description":"Select the base path for the preprocessed EEG or MEG", "base_path":"/mnt/Store/OneDrive/Ariosdy/Tesis/Application/Data/eeglab", "event_file":"All", "format":"set" }}
{ "description":"Integration process for Structural and Functional Data", "preproc_data":{ "description":"Select the base path for the preprocessed EEG or MEG", "base_path":"E:/Data/MultinationalNorm/Barbados/derivatives/eeglab", "event_file":"All", "segment":"", "format":"set" }}
Expand Down
12 changes: 12 additions & 0 deletions functions/cfs_process_interface.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
if(isempty(sTemplate))
fprintf(2,strcat('\nBC-V-->> Error: The selected template name in process_import_anat.json is wrong \n'));
disp(strcat("Name: ",subjects.name));
disp(strcat("Please check the aviable anatomy templates in bst_template/bst_default_anatomy.json file"));

Check failure on line 51 in functions/cfs_process_interface.m

View workflow job for this annotation

GitHub Actions / Check for spelling errors

aviable ==> available, a viable
disp('-->> Process stopped!!!');
return;
end
Expand Down Expand Up @@ -165,6 +165,18 @@
disp(strcat('CFS -->> Subject:' , subID, '. Processing finished.'));
disp('==========================================================================');
end
%%
%% Getting participants metadata
%%
eeglab_path = fullfile(properties.integration_params.preproc_data.base_path);
participants_file = fullfile(eeglab_path,'Participants.json');
if(isfile(participants_file))
copyfile(participants_file,fullfile(CiftiStorm.Location,'Participants.json'))
end

%%
%% Saving dataset information
%%
disp(strcat('CFS -->> Saving Dataset.'));
disp('==============================================================================');
datasetFile = fullfile(CiftiStorm.Location,'CiftiStorm.json');
Expand Down
20 changes: 10 additions & 10 deletions functions/export/StructFunct_integration.m
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
function [MEEGs, HeadModels, Cdata] = StructFunct_integration(EEG_path, modality, HeadModels, Cdata)

MEEGs = struct;

EEG_file = dir(EEG_path);
EEG_file([EEG_file.isdir]==1) = [];
if(~isempty(EEG_file))
count = 1;
for i=1:length(EEG_file)
[~,filename,ext] = fileparts(EEG_file(i).name);
if(isequal(ext,'.set'))
MEEGs(count).EEG = load(fullfile(EEG_file(i).folder,EEG_file(i).name),'-mat');
while(isfield( MEEGs(count).EEG,'EEG'))
MEEGs(count).EEG = MEEGs(count).EEG.EEG;
MEEGs(count) = load(fullfile(EEG_file(i).folder,EEG_file(i).name),'-mat');
while(isfield( MEEGs(count),'EEG'))
MEEGs(count) = MEEGs(count).EEG;
end
if(ischar(MEEGs(count).EEG.data))
if(ischar(MEEGs(count).data))
fid = fopen(fullfile(EEG_file(i).folder,strrep(EEG_file(i).name,'set','fdt')), 'r', 'ieee-le');
for trialIdx = 1:MEEGs(count).EEG.trials % In case the saved data are epoched, loop the process for each epoch. Thanks Ramesh Srinivasan!
currentTrialData = fread(fid, [MEEGs(count).EEG.nbchan MEEGs(count).EEG.pnts], 'float32');
for trialIdx = 1:MEEGs(count).trials % In case the saved data are epoched, loop the process for each epoch. Thanks Ramesh Srinivasan!
currentTrialData = fread(fid, [MEEGs(count).nbchan MEEGs(count).pnts], 'float32');
data{trialIdx} = currentTrialData; % Data dimentions are: electrodes, time points, and trials (the last one is for epoched data)
end
fclose(fid);
MEEGs(count).EEG.data = data;
MEEGs(count).data = data;
end
if(~contains(filename,'task'))
filename_parts = split(filename,'_');
Expand All @@ -32,13 +32,13 @@
count = count + 1;
end
end
MEEG = MEEGs(1).EEG;
MEEG = MEEGs(1);

%%
%% Filter Channels and LeadField by Preprocessed MEEG
%%
if(isequal(modality,'EEG'))
labels = {MEEGs(1).EEG.chanlocs(:).labels};
labels = {MEEGs(1).chanlocs(:).labels};
elseif(isequal(modality,'MEG'))
labels = MEEG.labels;
else
Expand Down
8 changes: 5 additions & 3 deletions functions/export/save_output_files.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@
if(isequal(action,'all'))
disp ("-->> Saving MEEG file");
for i=1:length(MEEGs)
EEG = MEEGs(i).EEG;
EEG = MEEGs(i);
save(fullfile(output_subject_dir,subject_info.meeg_dir{i}),'-struct','EEG');
end
end

%%
%% Export subject from protocol
%%
disp ("-->> Saving Brainstorm subject file");
process_export_subject(output_subject_dir, subID, MEEGs(1));
if(isequal(action,'all'))
disp ("-->> Saving Brainstorm subject file");
process_export_subject(output_subject_dir, subID, MEEGs(1));
end
disp ("-->> Saving channel file");
save(fullfile(output_subject_dir,subject_info.channel_dir),'-struct','Cdata');
disp ("-->> Saving leadfield file");
Expand Down
9 changes: 7 additions & 2 deletions functions/processes/process_export_subject.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function process_export_subject(output_subject_dir, subID, EEG)
function process_export_subject(output_subject_dir, subID, EEG, varargin)

for i=1:length(varargin)
eval([inputname(i+4) '= varargin{i};']);
end

%%
%% Update subject protocol with preprocessed data
Expand All @@ -20,7 +23,7 @@ function process_export_subject(output_subject_dir, subID, EEG)
end
HeadModel = load(fullfile(ProtocolInfo.STUDIES, sStudies.HeadModel.FileName));
Cdata = load(fullfile(ProtocolInfo.STUDIES, sStudies.Channel.FileName));
[Cdata_r, Gain] = remove_channels_by_preproc_data({EEG.EEG.chanlocs.labels}, Cdata, HeadModel.Gain);
[Cdata_r, Gain] = remove_channels_by_preproc_data({EEG.chanlocs.labels}, Cdata, HeadModel.Gain);

HeadModel.Gain = Gain;
save(fullfile(ProtocolInfo.STUDIES, sStudies.HeadModel.FileName),'-struct','HeadModel');
Expand All @@ -40,6 +43,8 @@ function process_export_subject(output_subject_dir, subID, EEG)
subject_file = fullfile(output_subject_dir,'brainstorm',strcat(subID,'.zip'));
export_protocol(iProtocol, iSubject, subject_file);



%%
%% Save and display report
%%
Expand Down
26 changes: 17 additions & 9 deletions functions/processes/process_integration.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,27 @@
action = 'anat';
save_output_files(base_path, modality, subID, HeadModels, Cdata, Shead, Sout, Sinn, Scortex, AQCI, action);

subjects = dir(eeglab_path);
subjects = dir(eeglab_path);
subjects(ismember({subjects.name},{'.','..'})) = [];
for e=1:length(subjects)
subject = subjects(e);
subID = subject.name;
subject = subjects(e);
subID = subject.name;
disp(strcat("-->> Saving subject: ",subID));
disp("--------------------------------------------------------------------------");
EEG_path = fullfile(eeglab_path,subID);
HeadModels = rawHeadModels;
Cdata = rawCdata;
[MEEGs,HeadModels,Cdata] = StructFunct_integration(EEG_path, modality, HeadModels, Cdata);
AQCI = AutomaticQCI(HeadModels.HeadModel.Gain, Cdata, Scortex.Sc);
save_output_files(base_path, modality, subID, MEEGs, HeadModels, Cdata, Shead, Sout, Sinn, Scortex, AQCI);
EEG_path = fullfile(eeglab_path,subID);
HeadModels = rawHeadModels;
Cdata = rawCdata;
[MEEGs,HeadModels,Cdata] = StructFunct_integration(EEG_path, modality, HeadModels, Cdata);
AQCI = AutomaticQCI(HeadModels.HeadModel.Gain, Cdata, Scortex.Sc);
templateName = CiftiStorm.Template.SubID;

%%
%% Dupicate subject if template or default
%%
[newTemplateName, Messages] = process_duplicate('DuplicateSubject', templateName, '_copy');
db_rename_subject(newTemplateName, subID, 0);
action = 'all';
save_output_files(base_path, modality, subID, MEEGs, HeadModels, Cdata, Shead, Sout, Sinn, Scortex, AQCI, action);

participant = CiftiStorm.Template;
participant.SubID = subID;
Expand Down
Loading