Package for transformation of Matlab/Simbiology objects to regular structures accesible for serialization like JSON, YAML etc.
SimBiology is a popular tool for modeling in systems biology and systems pharmacology. It stores models in internal objects which can be created or modified by GUI or by Matlab scripting. Nevertheless in some cases you need representation of the model code in general-porpose way for additional analysis or exporting to another tools.
JSON (JavaScript Object Notation) is one of two most popular formats of searilization and it is supported by all programming languages. So it a good choice for model exporting.
Matlab provides function jsonencode()
function but it cannot be used for SimBiology.*
objects directly. SbioToStruct()
function solves the problem.
- Download file SbioToStruct.m or whole package from (https://github.com/insysbio/sbio-to-json) and add the path to the package.
addpath('Y:\sbio-to-json');
- Load model from simbiodemos.
out = sbioloadproject('C:\Program Files\MATLAB\R2017b\toolbox\simbio\simbiodemos\AntibacterialPKPD.sbproj');
model = out.m1;
- Convert model object to Matlab structure
strc = SbioToStruct(model);
- Serialize to JSON and save to file.
json = jsonencode(strc);
fileID = fopen('model.json','w');
fprintf(fileID, json);
fclose(fileID);
Steps 1 and 2 as above... but
- Download JSONlab package (https://github.com/fangq/jsonlab) and add the path to the package
addpath('Y:\jsonlab');
- Use savejson() to create json file
json=savejson('', strc,'model-pretty.json');
{
"Annotation": "",
"Events": [],
"Name": "Antibacterial",
"Notes": "",
"Parameters": [
[
{
"Annotation": "",
"ConstantValue": 1,
"Name": "KC50",
"Notes": "",
"Parent": "Antibacterial",
"Tag": "",
"Type": "parameter",
"UserData": [],
"Value": 1,
"ValueUnits": "microgram\/milliliter"
}
],
[
{
"Annotation": "",
"ConstantValue": 1,
"Name": "Kmax",
"Notes": "",
"Parent": "Antibacterial",
"Tag": "",
"Type": "parameter",
"UserData": [],
"Value": 3.5,
"ValueUnits": "1\/hour"
}
],
...
Note! JSONlab provides nice and flexible serialization but the structure of final JSON may differ from jsonencode()
function depending on serialization options.
Steps 1 and 2 as above... but
- Download Matlab YAML package (https://github.com/hiroshiban/Mcalibrator2/tree/master/subfunctions/ifit-1.5/Objects/yaml) and add the path to the package
addpath('Y:\yaml');
- Use YAML.dump() to create YAML
yaml = YAML.dump(strc);
YAML.write('model.yml', yaml);
The package can also be used for another object which includes SimBiology.*
objects.
root = sbioroot;
rootStruct = SbioToStruct(root);
parameterStruct = SbioToStruct(model.parameter(1));
- @metelkin
- @ivborissov
Apache 2.0