Skip to content

Code for transformation of Matlab/Simbiology model to JSON format

License

Notifications You must be signed in to change notification settings

insysbio/sbio-to-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sbio-to-json

Package for transformation of Matlab/Simbiology objects to regular structures accesible for serialization like JSON, YAML etc.

Motivation

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.

Installation

  1. 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');

Quick demo

  1. Load model from simbiodemos.
out = sbioloadproject('C:\Program Files\MATLAB\R2017b\toolbox\simbio\simbiodemos\AntibacterialPKPD.sbproj');
model = out.m1;
  1. Convert model object to Matlab structure
strc = SbioToStruct(model);
  1. Serialize to JSON and save to file.
json = jsonencode(strc);

fileID = fopen('model.json','w');
fprintf(fileID, json);
fclose(fileID);

Convert to pretty JSON

Steps 1 and 2 as above... but

  1. Download JSONlab package (https://github.com/fangq/jsonlab) and add the path to the package
addpath('Y:\jsonlab');
  1. 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.

Convert to YAML

Steps 1 and 2 as above... but

  1. 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');
  1. Use YAML.dump() to create YAML
yaml = YAML.dump(strc);
YAML.write('model.yml', yaml);

Another object to convert

The package can also be used for another object which includes SimBiology.* objects.

root = sbioroot;
rootStruct = SbioToStruct(root);
parameterStruct = SbioToStruct(model.parameter(1));

Other

Authors

  • @metelkin
  • @ivborissov

License

Apache 2.0

Releases

No releases published

Packages

No packages published

Languages