Batch scripting anatomy import (auto)

Hi, I’ve been using the GUI to load the fs folders for each subject (because I didn’t have too many to work on each time). But right now, I have quite a handful & I wanted to batch all the subjects together. I see that there’s a process for anatomy import but not for the (auto) option available in GUI - the auto option was very useful because I didn’t have to individually specify the fiducial points.

I’d appreciate any advice on how to go about it.

Hi @hchoi, the (auto) option computes the MNI normalization if any of the fiducials (NAS, LPA, RPA, AC, PC or IH) is missing, then it uses 15,000 vertices for the imported cortex. This is the same behaviour of the Import > Import anatomy > Import anatomy folder when you set the number of vertices to 15000, and the position of any (or all) fiducials is absent or set to [0, 0, 0].

You can find an example of this in the script that reproduces the introduction tutorial:

As you do not have the fiducial positions, you can remove those fields from the process call, or set them to [0,0,0].

Note: the process will automatically create the Subject if it is not already in the database.

Check this link for how script a (FOR) loop over Subjects:

Thank you. This is what I have:

if ~brainstorm('status')
    brainstorm nogui
end

ProtocolName = 'neuradyn_bst_rest';

% Get the protocol index
iProtocol = bst_get('Protocol', ProtocolName);
if isempty(iProtocol)
    error(['Unknown protocol: ' ProtocolName]);
end

% Select the current procotol
gui_brainstorm('SetCurrentProtocol', iProtocol);


SubjectNames = {}; 

RawFiles = {...
    }; % each subject's fs folder directory

if isfolder(RawFiles)
    disp(['Directory found: ', RawFiles]);
else
    warning('MyToolbox:FolderNotFound', 'The directory "%s" does not exist.', RawFiles);
end



for iSubject = 1:length(SubjectNames)
    % Process: Import anatomy folder
    bst_process('CallProcess', 'process_import_anatomy', [], [], ...
        'subjectname', SubjectNames{iSubject}, ...
        'mrifile',     {RawFiles{iSubject}, 'FreeSurfer'}, ...
        'nvertices',   15000);
end

I had a previous commenter suggest import_anatomy_fs(), but it didn’t work - that on top of a recent Brainstorm update, I now get an error when trying to load this specific protocol (other protocols load and work fine):

*Error using regexprep
All cells must be char row vectors.*

*Error in gui_brainstorm (line 34)
eval(macro_method);*

*Error in bst_startup (line 669)
gui_brainstorm('SetCurrentProtocol', GlobalData.DataBase.iProtocol);*

*Error in brainstorm (line 134)
bst_startup(BrainstormHomeDir, 1, BrainstormDbDir, TemplateName);*

I think it’s because of the ProtocolSubjects variable in the protocol.mat, which look like this:

I’d greatly appreciate your advice.

Hi @hchoi, the other post (provided by @xqptw) was removed as the preferred by way to import the anatomy is through process_import_anatomy.

This seems to be the case. Try to regenerate the protocol.mat.

  1. Close Brainstorm and Matlab
  2. Delete the protocol.mat for the Protocol that is giving you the error
  3. Start Brainstorm
1 Like

Thank you for both advice! I was able to just revert / recover the original protocol.mat because our IT keeps a frequent backup.