Tutorial for the Matlab API tool
Installation
Download the BrainSTEM Matlab API tools repository from GitHub at github.com/brainstem-org/brainstem_matlab_api_tools and add it to your Matlab setpath.
Setup credentials/token:
Email and password will be requested
get_token
The token is saved to a mat file (brainstem_authentication.mat
) in the Matlab API tool folder.
Loading sessions
load_model
can be used to load any model: We just need to set the name of the model.
output1 = load_model('model','session');
We can fetch a single session entry from the loaded models.
session = output1.sessions(1);
We can also filter the models by providing cell array with paired filters In this example, it will just load sessions whose name is “yeah”.
output1_1 = load_model('model','session','filter',{'name','yeah'});
Loaded models can be sorted by different criteria applying to their fields. In this example, sessions will be sorted in descending ording according to their name.
output1_2 = load_model('model','session','sort',{'-name'});
In some cases models contain relations with other models, and they can be also loaded with the models if requested. In this example, all the projects, data acquisition, behaviors and manipulations related to each session will be included.
output1_3 = load_model('model','session','include',{'projects','dataacquisition','behaviors','manipulations'});
The list of related data acquisition can be retrieved from the returned dictionary.
dataacquisition = output1_3.dataacquisition;
Get all subjects with related procedures and subject state changes
output1_4 = load_model('model','subject','include',{'procedures'});
Get all projects with related subjects and sessions
output1_5 = load_model('model','project','include',{'sessions','subjects'});
All these options can be combined to suit the requirements of the users. For example, we can get only the session that contain the word “Rat” in their name, sorted in descending order by their name and including the related projects.
output1_6 = load_model('model','session', 'filter',{'name.icontains', 'Rat'}, 'sort',{'-name'}, 'include',{'projects'});
Updating a session
We can make changes to a model and update it in the database. In this case, we change the description of one of the previously loaded sessions.
session = output1.sessions(1);
session.description = 'new description';
output2 = save_model('data',session,'model','session');
Creating a new session
We can submit a new entry by defining a struct with the required fields.
session = {};
session.name = 'New session85';
session.description = 'new session description';
session.projects = {'0c894095-2d16-4bde-ad50-c33b7680417d'};
Submitting session
output3 = save_model('data',session,'model','session');
Load public projects
Request the public data by defining the portal to be public
output4 = load_model('model','project','portal','public');
This tutorial in also available in the Matlab API tool Github repository.