Skip to content

Commit

Permalink
Merge pull request #117 from CCC-members/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
arioskyag authored Dec 6, 2023
2 parents b41704f + fecb634 commit a5a910e
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 74 deletions.
36 changes: 36 additions & 0 deletions cfs_properties/functions/cfs_set.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function cfs_set( varargin )

if ((nargin >= 2) && ischar(varargin{1}))
contextName = varargin{1};
data = varargin{2};
else
return
end

% Get required context structure
switch contextName
case 'cfs_dir'
output1 = fullfile(getUserDir(),'.CiftiStorm');
case 'defaults_dir'
cfs_db_dir = fullfile(getUserDir(),'.CiftiStorm');
output1 = fullfile(cfs_db_dir,'defaults','anatomy');
output2 = fullfile(cfs_db_dir,'defaults','eeg');
output3 = fullfile(cfs_db_dir,'defaults','meg');
case 'datasets'
if(~isfolder(fullfile(getUserDir(),'.CiftiStorm')))
mkdir(fullfile(getUserDir(),'.CiftiStorm'));
end
if(~isfolder(fullfile(getUserDir(),'.CiftiStorm','Datasets')))
mkdir(fullfile(getUserDir(),'.CiftiStorm','Datasets'));
end
saveJSON(data,fullfile(getUserDir(),'.CiftiStorm','Datasets','Datasets.json'))

case 'bst_default_eeg'
output1 = 'https://github.com/brainstorm-tools/brainstorm3/raw/master/defaults/eeg';

case 'openmeeg'

case 'duneruro'
end

end
59 changes: 32 additions & 27 deletions cfs_properties/functions/check_properties.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
%CHECK_PROPERTIES Summary of this function goes here
% Detailed explanation goes here
status = true;
reject_subjects = {};
reject_subjects = struct;
reject_anat = {};
reject_nonbrain = {};

disp('==========================================================================');
disp("-->> Checking properties");
Expand Down Expand Up @@ -63,8 +65,8 @@
status = false;
return;
end
if(~isfolder(fullfile(general_params.output_path,'BC-V_Structure',protocol_name)))
mkdir(fullfile(general_params.output_path,'BC-V_Structure',protocol_name));
if(~isfolder(fullfile(general_params.output_path,'CiftiStorm',protocol_name)))
mkdir(fullfile(general_params.output_path,'CiftiStorm',protocol_name));
end
if(~isfolder(fullfile(general_params.output_path,'BST','Subjects',protocol_name)))
mkdir(fullfile(general_params.output_path,'BST','Subjects',protocol_name));
Expand Down Expand Up @@ -128,7 +130,7 @@
checked = check_HCP_anat_structure(structure, selected_anatomy);
if(~checked)
count_HCP_structure = count_HCP_structure + 1;
reject_subjects{length(reject_subjects)+1} = structure.name;
reject_anat{end+1} = structure.name;
end
end
if(~isequal(count_HCP_structure,0))
Expand Down Expand Up @@ -166,7 +168,7 @@
checked = check_non_brain_surfaces(structure);
if(~checked)
count_non_brain = count_non_brain + 1;
reject_subjects{length(reject_subjects)+1} = structure.name;
reject_nonbrain{end+1} = structure.name;
end
end
if(~isequal(count_non_brain,0))
Expand Down Expand Up @@ -275,7 +277,7 @@
raw_file = fullfile(base_path,structure.name,strrep(raw_data.file_location,'SubID',structure.name));
if(~isfile(raw_file))
count_raw = count_raw + 1;
reject_subjects{length(reject_subjects)+1} = structure.name;
reject_chann{end+1} = structure.name;
end
end
if(~isequal(count_raw,0))
Expand Down Expand Up @@ -319,29 +321,32 @@
return;
end
end
end

%% Joinning rejected subjects

Check failure on line 326 in cfs_properties/functions/check_properties.m

View workflow job for this annotation

GitHub Actions / Check for spelling errors

Joinning ==> Joining
for i=1:length(reject_anat)
reject_subjects(end+1).SubID = reject_anat{i};
reject_subjects(end).Status = "Rejected";
reject_subjects(end).FileInfo = "";
reject_subjects(end).Process(1).Name = "Check_anat";
reject_subjects(end).Process(1).Status = "Rejected";
reject_subjects(end).Process(1).Error = 'The subject do not contain a correct anatomy folder';
end
%%
%% Checking subject number in each folder
%%
anat_params = properties.anatomy_params;
if(isequal(lower(anat_params.anatomy_type.id),'individual'))
hcp_base_path = selected_anatomy.base_path;
hcp_subjects = dir(hcp_base_path);
hcp_subjects(ismember( {hcp_subjects.name}, {'.', '..'})) = []; %remove . and ..
hcp_names = {hcp_subjects.name};

non_brain_path = non_brain.base_path;
nb_subjects = dir(non_brain_path);
nb_subjects(ismember( {nb_subjects.name}, {'.', '..'})) = []; %remove . and ..
nb_names = {nb_subjects.name};

index1 = ismember(hcp_names,nb_names);
index2 = ismember(nb_names,hcp_names);
hcp_names(index1) = [];
nb_names(index2) = [];
reject_subjects = [reject_subjects , hcp_names, nb_names];
for i=1:length(reject_nonbrain)
idx = find(ismember({reject_subjects.Name},reject_nonbrain{i}),1);
if(isempty(idx))
reject_subjects(end+1).SubID = reject_nonbrain{i};
reject_subjects(end).Status = "Rejected";
reject_subjects(end).FileInfo = "";
reject_subjects(end).Process(1).Name = "Check_nonbrain";
reject_subjects(end).Process(1).Status = "Rejected";
reject_subjects(end).Process(1).Error = 'The subject do not contain a correct non-brain structure';
else
reject_subjects(idx).Process(2).Name = reject_nonbrain{i};
reject_subjects(idx).Process(2).Status = "Rejected";
reject_subjects(idx).Process(2).Error = 'The subject do not contain a correct non-brain structure';
end
end
reject_subjects = unique(reject_subjects);
if(~isempty(reject_subjects))
disp("-->> Subjects to reject");
disp("--------------------------------------------------------------------------");
Expand Down
23 changes: 14 additions & 9 deletions ciftistorm.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function ciftistorm(varargin)
close all;
restoredefaultpath;
clearvars -except varargin;
disp('-->> Starting process');
disp('CFS -->> Starting process');
disp('==========================================================================');

%%
Expand Down Expand Up @@ -57,24 +57,29 @@ function ciftistorm(varargin)
if(isequal(properties,'canceled'))
return;
end
[status, reject_subjects] = check_properties(properties);
[status, reject_subjects] = check_properties(properties);
if(~status)
fprintf(2,strcat('\nBC-V-->> Error: The current configuration files are wrong \n'));
fprintf(2,strcat('\n-->> Error: The current configuration files are wrong \n'));
disp('Please check the configuration files.');
return;
end

%% BrainStorm configuration
disp('-->> Preparing BrainStorm properties.');
disp('==========================================================================');
bst_path = properties.general_params.bst_config.bst_path;
addpath(genpath(bst_path));
disp('CFS -->> Preparing BrainStorm properties.');
disp('==========================================================================');
status = starting_brainstorm(properties);

%% Calling dataset function to analysis
if(status)
process_error = cfs_process_interface(properties,reject_subjects);
% save("process_output.mat","process_error","reject_subjects");
datasetFile = cfs_process_interface(properties,reject_subjects);
dataset = jsondecode(fileread(datasetFile));
datasets = cfs_get('datasets');
if(isempty(datasets))
datasets = dataset;
else
datasets(end+1) = dataset;
end
cfs_set('datasets',datasets);
end

%% Stopping BrainStorm
Expand Down
40 changes: 24 additions & 16 deletions functions/cfs_process_interface.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [process_error] = cfs_process_interface(properties, reject_subjects)
function datasetFile = cfs_process_interface(properties, reject_subjects)
% HeadModel Process Interface
%
%
Expand Down Expand Up @@ -54,6 +54,7 @@
return;
end
else

base_path = anatomy_type.base_path;
subjects = dir(base_path);
subjects(ismember({subjects.name},{'.','..'})) = []; %remove . and ..
Expand All @@ -68,10 +69,9 @@
subID = subjects(sub).Name;
else
subID = subjects(sub).name;
end
CiftiStorm.Participants(end+1).SubID = subID;
end
disp('==========================================================================');
disp(strcat('-->> Processing subject: ', subID));
disp(strcat('CFS -->> Processing subject: ', subID));
disp('==========================================================================');

%%
Expand All @@ -90,7 +90,7 @@
%% Process Import Anatomy
%%
disp("--------------------------------------------------------------------------");
disp("-->> Process Import Anatomy");
disp("CFS -->> Process Import Anatomy");
disp("--------------------------------------------------------------------------");
[CiftiStorm, CSurfaces] = process_import_anat(CiftiStorm, properties,subID);
if(isequal(CiftiStorm.Participants(end).Status,'Rejected'));continue;end
Expand All @@ -99,7 +99,7 @@
%% Process: Generate BEM surfaces
%%
disp("--------------------------------------------------------------------------");
disp("-->> Process Generate BEM surfaces");
disp("CFS -->> Process Generate BEM surfaces");
disp("--------------------------------------------------------------------------");
[CiftiStorm, CSurfaces] = process_gen_bem_surfaces(CiftiStorm, properties, subID, CSurfaces);
if(isequal(CiftiStorm.Participants(end).Status,'Rejected'));continue;end
Expand All @@ -108,7 +108,7 @@
%% Process: Transform surfaces
%%
disp("--------------------------------------------------------------------------");
disp("-->> Transform surfaces");
disp("CFS -->> Transform surfaces");
disp("--------------------------------------------------------------------------");
[CiftiStorm, CSurfaces, sub_to_FSAve] = process_compute_surfaces(CiftiStorm, properties, subID, CSurfaces);
if(isequal(CiftiStorm.Participants(end).Status,'Rejected'));continue;end
Expand All @@ -117,7 +117,7 @@
%% Process: Import Atlas
%%
disp("--------------------------------------------------------------------------");
disp("-->> Process Import Atlas");
disp("CFS -->> Process Import Atlas");
disp("--------------------------------------------------------------------------");
CiftiStorm = process_import_atlas(CiftiStorm, properties, subID, CSurfaces);
if(isequal(CiftiStorm.Participants(end).Status,'Rejected'));continue;end
Expand All @@ -126,7 +126,7 @@
%% Process: Generate SPM canonical surfaces
%%
disp("--------------------------------------------------------------------------");
disp("-->> Process Generate SPM canonical surfaces");
disp("CFS -->> Process Generate SPM canonical surfaces");
disp("--------------------------------------------------------------------------");
CiftiStorm = process_canonical_surfaces(CiftiStorm, properties, subID);
if(isequal(CiftiStorm.Participants(end).Status,'Rejected'));continue;end
Expand All @@ -135,7 +135,7 @@
%% Process Import Channel
%%
disp("--------------------------------------------------------------------------");
disp("-->> Process Import Channel");
disp("CFS -->> Process Import Channel");
disp("--------------------------------------------------------------------------");
CiftiStorm = process_import_chann(CiftiStorm, properties, subID, CSurfaces);
if(isequal(CiftiStorm.Participants(end).Status,'Rejected'));continue;end
Expand All @@ -144,7 +144,7 @@
%% Process: Compute Headmodel
%%
disp("--------------------------------------------------------------------------");
disp("-->> Process Compute HeadModel");
disp("CFS -->> Process Compute HeadModel");
disp("--------------------------------------------------------------------------");
CiftiStorm = process_comp_headmodel(CiftiStorm, properties, subID, CSurfaces);
if(isequal(CiftiStorm.Participants(end).Status,'Rejected'));continue;end
Expand All @@ -153,16 +153,24 @@
%% Process: Export subject
%%
disp("--------------------------------------------------------------------------");
disp("-->> Process Export subject");
disp("CFS -->> Process Export subject");
disp("--------------------------------------------------------------------------");
CiftiStorm = process_export_subject(CiftiStorm,properties,subID);
CiftiStorm = process_export_subject(CiftiStorm, properties, subID, CSurfaces, sub_to_FSAve);
if(isequal(CiftiStorm.Participants(end).Status,'Rejected'));continue;end

disp(strcat('-->> Subject:' , subID, '. Processing finished.'));
disp(strcat('CFS -->> Subject:' , subID, '. Processing finished.'));
disp('==========================================================================');
end
disp(strcat('-->> Process finished....'));
disp(strcat('CFS -->> Saving Dataset.'));
disp('==============================================================================');
datasetFile = fullfile(CiftiStorm.Location,'CiftiStorm.json');
saveJSON(CiftiStorm,datasetFile);
h = matlab.desktop.editor.openDocument(datasetFile);
h.smartIndentContents
h.save
h.close

disp(strcat('CFS -->> Dataset processed....'));
disp('==============================================================================');
disp('==============================================================================');
save report.mat subjects_processed subjects_process_error;
end
6 changes: 1 addition & 5 deletions functions/export/export_subject_structure.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
return;
end

%% Uploding Subject file into BrainStorm Protocol
disp('BST-P ->> Uploading Subject file into BrainStorm Protocol.');
disp('==========================================================================');

%%
%% Genering leadfield file
%%
Expand All @@ -50,7 +46,7 @@
%%
%% Saving files in BC-VARETA Structure
%%
base_path = fullfile(output_path,'BC-V_Structure',ProtocolInfo.Comment);
base_path = fullfile(output_path,'CiftiStorm',ProtocolInfo.Comment);
save_output_files(base_path, modality, subID, HeadModels, Cdata, Shead, Sout, Sinn, Scortex);

end
Expand Down
15 changes: 3 additions & 12 deletions functions/processes/process_export_subject.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
function CiftiStorm = process_export_subject(CiftiStorm, properties, subID, CSurfaces, sub_to_FSAve)

errMessage = [];
ProtocolName = general_params.bst_config.protocol_name;
output_path = general_params.output_path;
ProtocolName = properties.general_params.bst_config.protocol_name;
output_path = properties.general_params.output_path;

%%
%% Export subject from protocol
%%
disp("--------------------------------------------------------------------------");
disp("-->> Export Subject from BST Protocol");
disp("--------------------------------------------------------------------------");
if(~isfolder(fullfile(output_path,'BST','Subjects',ProtocolName)))
mkdir(fullfile(output_path,'BST','Subjects',ProtocolName));
end
Expand All @@ -21,22 +19,15 @@
%%
%% Save and display report
%%
disp("--------------------------------------------------------------------------");
disp("-->> Export BST Report");
disp("--------------------------------------------------------------------------");
report_path = get_report_path(properties, subID);
ReportFile = bst_report('Save', []);
bst_report('Export', ReportFile, fullfile(report_path,[subID,'.html']));
disp(strcat("-->> Process finished for subject: ",subID));

%%
%% Export Subject
%%
disp("--------------------------------------------------------------------------");
disp("-->> Export to CiftiStorm");
disp("--------------------------------------------------------------------------");

disp(strcat('cfs -->> Export subject:' , subID));
disp(strcat('-->> Export subject:' , subID));
errMessage = export_subject_structure(properties, subID, CSurfaces, sub_to_FSAve);

if(isempty(errMessage))
Expand Down
5 changes: 4 additions & 1 deletion functions/starting_brainstorm.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
%%
%% Starting BrainStorm
%%
bst_path = properties.general_params.bst_config.bst_path;
addpath(genpath(bst_path));
status = true;
brainstorm reset
brainstorm nogui local
Expand All @@ -16,7 +18,8 @@
%%
%% Loading BST modules
%%
disp("-->> Installing external plugins.");
disp('==========================================================================');
disp("CFS -->> Installing external plugins.");
disp('==========================================================================');
if(~isempty(bst_plugin('GetInstalled', 'spm12')))
[isOk, errMsg, PlugDesc] = bst_plugin('Unload', 'spm12');
Expand Down
Binary file modified guide/CiftiStorm.mlapp
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/BC-VARETA/dataConverter/download_testdata.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if(~isfolder(fullfile(pwd,'data')) && isequal(testDataPath,fullfile(pwd,'data')))
mkdir(fullfile(pwd,'data'));
end
dafaultWorkspace = fullfile(char(java.lang.System.getProperty('user.home')),"BC-VARETA_Structure");
dafaultWorkspace = fullfile(char(java.lang.System.getProperty('user.home')),"CiftiStorm");
if(~isfolder(BC_V_Workspace) && ~isequal(BC_V_Workspace,dafaultWorkspace))
disp("The Workspace path is not a folder");
return;
Expand Down
Loading

0 comments on commit a5a910e

Please sign in to comment.