Scripting group assignment in large database

Hi,

I have a large database of 300+ subjects who belong to a number of groups.
I'd like to assign each subject to a group based on a table using a script.
Can I do that? Here's where I am at:

Protocol = bst_get('ProtocolInfo');
s = bst_get('ProtocolSubjects');
gps = readtable('Groups.csv');

for i = 1:size(gps,1)
    isub = strcmp({s.Subject.Name},gps.Subject{i});
    s.Subject(isub).Comments = gps.Group{i};
end


  1. Does it make sense to use the Comments field of the Subject structure to assign groups?
  2. If so, can I assign it back to the database?
  3. If not, is there a better way?

Many thanks,
Max

Hi Max,

  1. The Comments sounds like a good place. This field is there to store notes or extra info about the Subject. Since this is rarely used, if you want to sort Subjects by their group, you would need to do as you are doing now. Retrieve all the protocol Subjects, and check their Comments field.

  2. Yes, use bst_set('ProtocolSubjects', s); after you the FOR loop

  3. You approach is a good way. Unfortunately, the Subject grouping will not be reflected on the DB explorer tree. If you want that, the only way would be to rename the Subjects to Group_SubjectName. To do so check db_rename_subject. Please note that this changes also the path in the HDD for the Subject files.

1 Like