Brainstorm Script keeps reinstalling CAT12

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

This is missing.

Very sorry, I'm not sure how that happened. But yes, it reinstalls CAT12 even though it is updated. I manually disabled autoupdates inside "bst_plugin.m", and it seems to have worked, but I am rerunning the code to see if it really did.

Here is what happens once the code reaches the CAT12 segmentation:

BST> Starting Brainstorm:
BST> =================================
BST> Version: 06-Mar-2025
BST> Deleting old process reports...
BST> Loading configuration file...
BST> Checking internet connectivity... failed
BST> Initializing user interface...
BST> Starting OpenGL engine... hardware
BST> Plugin fastica: D:\EEGReaching\MatlabLibraries\pca_ica\pca_ica
BST> Plugin libsvm: C:\Users\jpbo234\Documents\Trey-Thesis\EEG_EGML-main\libsvm-3.35
BST> Reading process folder...
BST> Loading current protocol...
PROGRESS> Set current protocol: Loading protocol...
PROGRESS> Unload all: Closing figures...
PROGRESS> Database explorer: Applying search...
BST> =================================
 
WARNING: The temporary directory contains 1 file(s):
BST> C:\Users\wba254\.brainstorm\tmp\
BST>  |- cat12_250420_173730
BST> If these files are not in use from another process, they will not be deleted automatically.
BST> To delete all the temporary files, add the following command to your script: 
BST> gui_brainstorm('EmptyTempFolder');

CAT12 plugin folder found. Adding to path...
PROGRESS> Set current protocol: Loading protocol...
PROGRESS> Unload all: Closing figures...
PROGRESS> Database explorer: Applying search...
Skipped (already exists): Subject001
Skipped (already exists): Subject002
Skipped (already exists): Subject003
Skipped (already exists): Subject004
Skipped (already exists): Subject005
Skipped (already exists): Subject006
BST> Emptying temporary directory...
PROGRESS> Process: Running process: Import MRI...
PROGRESS> Import MRI: Loading MRI file...
CAT12 SEGMENTATION
PROGRESS> Process: Running process: Segment MRI with CAT12...
BST> SPM12 template found: C:\Users\wba254\.brainstorm\plugins\spm12\spm12\tpm\TPM.nii
PROGRESS> Processing dependencies for cat12...
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> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\CAT.glnx86
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\CAT.maca64
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\CAT.maci64
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\CAT.w32
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\atlases_surfaces
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\atlases_surfaces_32k
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\doc
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\doc\css
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\doc\icons
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\doc\images
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\doc\js
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\doc\webfonts
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\standalone
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\templates_MNI152NLin2009cAsym
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\templates_surfaces
BST> Removing plugin cat12 from path: C:\Users\wba254\.brainstorm\plugins\cat12\cat12\templates_surfaces_32k
BST> Deleting plugin cat12: C:\Users\wba254\.brainstorm\plugins\cat12
BST> Executing callback UninstalledFcn: LinkCatSpm(0);
BST> Adding plugin spm12 to path: C:\Users\wba254\.brainstorm\plugins\spm12\spm12
BST> Adding plugin spm12 to path: C:\Users\wba254\.brainstorm\plugins\spm12\spm12\matlabbatch
BST> Executing callback LoadedFcn: spm('defaults','EEG');
BST> Deleting existing SPM12 toolbox: rmdir /q /s "C:\Users\wba254\.brainstorm\plugins\spm12\spm12\toolbox\cat12"
PROGRESS> Installing plugin 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

Thanks for sharing so much details in this.

It seems to me that there are multiple versions of CAT12 in your path. So when the version check is done, it finds a CAT12 that is not handled by Brainstorm.

Without Brainstorm running, please run in your system the Matlab command:
which('cat_version', '-all')

I see, you are adding the dir for CAT12 plugin into the Matlab's path. This action is not needed, adding and removing plugins dir into the path is part of Brainstorm functionality and will avoid troubles.

I appreciate the response. I got this in return. Note that I went into the "bst_plugin.m" and set PlugDesc(end).AutoUpdate = 0.

which('cat_version', '-all')
C:\Users\wba254.brainstorm\plugins\cat12\cat12\cat_version.m

What is the result of this line?
[a, b] = cat_version

Could you uninstall the CAT12 plugin and install from Brainstorm from scratch?
Avoiding to manually handle the Matlab path

thank you for your continued help and patience.

brainstorm keeps failing to connect to the internet. maybe this is why it keeps reinstalling?

ok, before I reinstalled CAT12, this is what the result was:

[b,a] = cat_version
b =
'CAT12.9'
a =
'2577'

this is what shows after i reinstalled:

[b,a] = cat_version
b =
'CAT12.9'
a =
'2577'

also, just for more info, here is the text box that appeared after it was reinstalled:

% Computational Anatomy Toolbox
% Version 2577 (CAT12.9) 2024-05-03
% ______________________________________________________________________
%
% Christian Gaser, Robert Dahnke
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$
% ==========================================================================
% Description
% ==========================================================================
% This toolbox is a collection of extensions to the segmentation algorithm
% of SPM12 (Wellcome Department of Cognitive Neurology) to provide computational
% morphometry. It is developed by Christian Gaser and Robert Dahnke (Jena
% University Hospital, Departments of Psychiatry and Neurology) and is available
% to the scientific community under the terms of the GNU General Public Licence as
% published by the Free Software Foundation; either version 2 of the Licence,
% or (at your option) any later version.
%
% If you use any CAT12 code for commercial application, please email
% christian.gaser@uni-jena.de.
%
% General files
% INSTALL.txt - installation instructions
% CHANGES.txt - changes in revisions
% Contents.m - this file
%
% Core functions
% cat12.m
% cat_amap.m - compilation wrapper for cat_amap.c
% cat_main.m
% cat_run.m - runtime funtion for CAT12
% cat_run_job.m
% cat_run_newcatch.m
% cat_run_oldcatch.m
% cat_defaults.m - sets the defaults for CAT12
% cat_get_defaults.m - defaults for CAT12
% spm_cat12.m - toolbox wrapper to call CAT12
%
% Utilities
% cat_sanlm.m - Spatial Adaptive Non Local Means Denoising Filter
% cat_update.m - check for new updates
% cat_debug.m - print debug information for SPM12 and CAT12
% cat_ornlm.m
% cat_plot_boxplot.m
% slice_overlay.m - overlay tool
% sliderPanel.m
%
% Input & Output
% cat_io_3Dto4D.m
% cat_io_FreeSurfer.m
% cat_io_cgw2seg.m
% cat_io_checkinopt.m
% cat_io_cmd.m
% cat_io_colormaps.m
% cat_io_cprintf.m
% cat_io_csv.m
% cat_io_handle_pre.m
% cat_io_img2nii.m
% cat_io_matlabversion.m
% cat_io_remat.m
% cat_io_seg2cgw.m
% cat_io_struct2table.m
% cat_io_updateStruct.m
% cat_io_writenii.m
% cat_io_xml.m
% cat_io_xml2csv.m
%
% Longitudinal batch
% cat_long_main.m - longitudinal batch mode
% cat_long_multi_run.m - call cat_long_main for multiple subjects
%
% Statistics
% cat_stat_calc_stc.m
% cat_stat_homogeneity.m - check sample homogeneity across sample
% cat_stat_marks.m
% cat_stat_nanmean.m
% cat_stat_nanmedian.m
% cat_stat_nanstat1d.m
% cat_stat_nanstd.m
% cat_stat_nansum.m
% cat_stat_showslice_all.m - show 1 slice of all images
% cat_stat_spm.m
% cat_stat_spmF2x.m - transformation of F-maps to P, -log(P), R2 maps
% cat_stat_spmT2x.m - transformation of t-maps to P, -log(P), r or d-maps
% cat_stat_TIV.m - read total intracranial volume (TIV) from xml-files
%
% Surface functions
% cat_surf_avg.m
% cat_surf_calc.m
% cat_surf_createCS.m
% cat_surf_display.m
% cat_surf_info.m
% cat_surf_parameters.m
% cat_surf_rename.m
% cat_surf_render.m
% cat_surf_resamp.m
% cat_surf_resamp_freesurfer.m
% cat_surf_resample.m
% cat_surf_smooth.m
% cat_surf_vol2surf.m
%
% Test and experimental functions
% cat_tst_BWPsliceartifact.m
% cat_tst_CJV.m
% cat_tst_calc_kappa.m
% cat_tst_qa.m
% cat_tst_staple_multilabels.m
%
% Volume functions
% cat_vol_approx.m
% cat_vol_atlas.m
% cat_vol_average.m
% cat_vol_calc_roi.m
% cat_vol_correct_slice_scaling.m
% cat_vol_ctype.m
% cat_vol_defs.m - apply deformations to images
% cat_vol_findfiles.m
% cat_vol_groupwise_ls.m
% cat_vol_imcalc.m
% cat_vol_iscale.m
% cat_vol_morph.m - morphological operations to 3D data
% cat_vol_nanmean3.m
% cat_vol_partvol.m
% cat_vol_pbt.m
% cat_vol_resize.m
% cat_vol_sanlm.m - GUI for cat_sanlm
% cat_vol_series_align.m
% cat_vol_set_com.m
% cat_vol_slice_overlay.m - wrapper for overlay tool slice_overlay
% cat_vol_slice_overlay_ui.m - example for user interface for overlay wrapper cat_slice_overlay.m
% cat_vol_smooth3X.m
%
% Batch mode
% cat_batch_long.m - batch mode wrapper for spm_jobman for longitudinal pipeline
% cat_batch_spm.m - batch mode wrapper for spm_jobman for SPM12
% cat_batch_vbm.m - batch mode wrapper for spm_jobman for CAT12
%
% Check input and files
% cat_check.m
% cat_check_system_output.m
%
% Configuration
% cat_conf_extopts.m
% cat_conf_long.m
% cat_conf_opts.m
% cat_conf_stools.m
% cat_conf_stoolsexp.m
% cat_conf_tools.m - wrapper for calling CAT12 utilities
% tbx_cfg_cat.m
%
% Templates/Atlases volumes
% Template_?_GS.nii - Geodesic Shooting template of 555 subjects from IXI database
% in MNI152NLin2009cAsym space provided for 6 different iteration steps
% Template_T1.nii - average of 555 T1 images of IXI database in MNI152 space after
% Geodesic Shooting
% aal3.* - AAL3 atlas
% anatomy2.* - Anatomy2 atlas
% cobra.* - CoBra atlas
% hammers.* - Hammers atlas
% ibsr.* - IBSR atlas
% julichbrain.* _ JulichBrain atlas
% mori.* - Mori atlas
% thalamus.* - Thalamic Nuclei atlas
% neuromorphometrics.* - Neuromorphometrics atlas
% lpba40.nii - LPBA40 atlas
% brainmask.nii - brainmask
% cat12.nii - partitions for hemispheres, subcortical structures and vessels
%
% Templates/Atlases surfaces
% ?h.central.Template_T1.gii
% - central surface of Dartel average brain for result mapping
% ?h.central.freesurfer.gii - central surface of freesurfer fsaverage
% ?h.inflated.freesurfer.gii - inflated surface of freesurfer fsaverage
% ?h.sphere.freesurfer.gii - spherical surface of freesurfer fsvaverage

Yes, that could be reason, as it would try to upload to the 'latest' (as it cannot check what is the current number for latest) regardless of what is installed.

Can you manually update the URL in bst_check_internet from:
http://neuroimage.usc.edu/bst/getversion.php
to
https://neuroimage.usc.edu/bst/getversion.php

Then restart Brainstorm and try to install CAT12

that seemed to fix it! I'm gonna run through one iteration of the code. I'll reply if there's any problems but it did not attempt to reinstall CAT12 this time, it just started segmenting with cAT12, which is what I wanted.

Thank you!