Hello, CAT12 gets removed then reinstalled every time I run my script.
Can anyone help me figure this out? I can't figure it out. Inside the GUI, it says the CAT12 is up to date. But, the script thinks it is out of date. This is the command window that shows when I run the code:
CAT12 SEGMENTATION
BST> SPM12 template found: C:\Users\wba254\.brainstorm\plugins\spm12\spm12\tpm\TPM.nii
BST> Processing dependencies: cat12 requires: spm12
BST> Plugin cat12 is outdated and will be updated.
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12
BST> Deleting plugin cat12: C:\Users\wba254\.brainstorm\plugins\cat12
BST> Executing callback UninstalledFcn: LinkCatSpm(0);
BST> Deleting existing SPM12 toolbox: rmdir /q /s "C:\Users\wba254\.brainstorm\plugins\spm12\spm12\toolbox\cat12"
BST> Downloading URL : http://www.neuro.uni-jena.de/cat12/cat12_latest.zip
BST> Saving to file : C:\Users\wba254\.brainstorm\plugins\cat12\plugin.zip
and here is the main script:
%% PATHS
% DATA PATHS
addpath('D:\EEG_Epilepsy\Codes\Will Stuff\New Stuff\Subject Data');
eegPath = 'D:\EEG_Epilepsy\Codes\Will Stuff\New Stuff\Subject Data';
% FUNCTION PATHS
addpath('D:\EEG_Epilepsy\Codes\Will Stuff\New Stuff\Functions');
AnatDir = fullfile('D:\EEG_Epilepsy\Codes\Will Stuff\New Stuff\Subject Data', 'MRI');
%% START BRAINSTORM IN NO GUI MODE
brainstorm nogui
% Define CAT12 expected path
cat12_plugin_path = fullfile(bst_get('BrainstormUserDir'), 'plugins', 'cat12', 'cat12');
% Check if it's installed
if isfolder(cat12_plugin_path)
disp('CAT12 plugin folder found. Adding to path...');
addpath(genpath(cat12_plugin_path)); % Ensure functions are accessible
else
disp('CAT12 plugin not found. Installing...');
plugin_install('spm12', 1); % Required for CAT12
plugin_install('cat12', 1);
end
% GENERATE PROTOCOL: IF ALREADY EXISTS, DON'T CREATE
iProtocol = generateProtocol('deltaTestingV5');
% NUMBER OF SUBJECTS IN STUDY
numSub = 6;
% CONFIGURE, CREATE, AND IMPORT SUBJECTS
% This function also returns the names of the subject
[subjectDataID,subjectID] = configureSubjects(numSub);
%% LOOP TO:
% FILTER EPOCHS
% passband frequencies
fc1 = [0.3,4];
fc2 = [1,4];
% LOAD RAW EEG, SPLIT INTO EPOCHS, and FILTER, FOLLOWED
% BY IMPORTING INTO BRAINTORM
global GlobalData
GlobalData.UserPrefs.PluginAutoUpdate = 0;
for i=1:2
gui_brainstorm('EmptyTempFolder');
% IMPORT DATA FOR EACH CORRESPONDING SUBJECT
eegStruct = load(subjectDataID(i,1));
% IMPORT MRI
importMRI(char(subjectID(i)),char(subjectDataID(i,2)));
try
% All processing for this subject
...
segmentCAT12(char(subjectID(i)));
...
catch ME
warning('Subject %s failed: %s', char(subjectID(i)), ME.message);
end
% small delay between subjects
pause(10)
disp(i)
end
here is the function "segmentCat12", which I had to make the code easier to read. I do not believe any of the other functions are relevant, they work as intended.
function segmentCAT12(subjectID)
disp('CAT12 SEGMENTATION')
% Input files
sFiles = [];
SubjectNames = {char(subjectID)};
% Start a new report
bst_report('Start', sFiles);
% Process: Segment MRI with CAT12
sFiles = bst_process('CallProcess', 'process_segment_cat12', sFiles, [], ...
'subjectname', SubjectNames{1}, ...
'nvertices', 3750, ...
'tpmnii', {'', 'Nifti1'}, ...
'sphreg', 1, ...
'vol', 1, ...
'extramaps', 0, ...
'cerebellum', 0);
% Save and display report
ReportFile = bst_report('Save', sFiles);
bst_report('Open', ReportFile);
% bst_report('Export', ReportFile, ExportDir);
% bst_report('Email', ReportFile, username, to, subject, isFullReport);
% Delete temporary files
% gui_brainstorm('EmptyTempFolder');
end
here is the generate protocol function
function iProtocol = generateProtocol(protocalName)
% Check if protocol exists
iProtocol = bst_get('Protocol', protocalName);
% If it doesn't exist, create it
if isempty(iProtocol)
gui_brainstorm('CreateProtocol', protocalName, 0, 0);
end
% Set as current protocol
gui_brainstorm('SetCurrentProtocol', bst_get('Protocol', protocalName));
end
and finally, here is what the command window shows after it installs cat12