0001 function sbml_model = cobra_struct_to_sbml_struct( model, sbml_level,sbml_version )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 sbml_toolbox_v3 = true;
0031 if (size(strfind( help('Model_create'), 'sbmlVersion' ),1)==0)
0032 sbml_toolbox_v3 = false;
0033 sbml_level = 2;
0034 end
0035
0036
0037 if (~exist('sbml_level','var') )
0038 sbml_level = 2;
0039 end
0040 if (~exist('sbml_version','var') )
0041 sbml_version = 1;
0042 end
0043 reaction_units = 'mmol_per_gDW_per_hr';
0044 if sbml_toolbox_v3
0045 sbml_model = Model_create( sbml_level, sbml_version );
0046 else
0047 sbml_model = Model_create( sbml_level );
0048 end
0049 sbml_model.namespaces = struct();
0050 sbml_model.namespaces.prefix = '';
0051 sbml_model.namespaces.uri = 'http://www.sbml.org/sbml/level2';
0052 sbml_model.id = strrep( strrep( strrep(model.description,'.','_'), filesep, '_' ), ':','_' );
0053
0054
0055 if sbml_toolbox_v3
0056 tmp_unit = Unit_create( sbml_model.SBML_level, sbml_model.SBML_version );
0057 tmp_species = Species_create( sbml_model.SBML_level, sbml_model.SBML_version );
0058 sbml_tmp_compartment = Compartment_create( sbml_model.SBML_level, sbml_model.SBML_version );
0059 sbml_tmp_parameter = Parameter_create( sbml_model.SBML_level, sbml_model.SBML_version );
0060 sbml_tmp_species_ref = SpeciesReference_create( sbml_model.SBML_level, sbml_model.SBML_version );
0061 sbml_tmp_reaction = Reaction_create( sbml_model.SBML_level, sbml_model.SBML_version );
0062 sbml_tmp_law = KineticLaw_create( sbml_model.SBML_level, sbml_model.SBML_version );
0063 tmp_unit_definition = UnitDefinition_create( sbml_model.SBML_level, sbml_model.SBML_version );
0064 else
0065 tmp_unit = Unit_create( sbml_model.SBML_level);
0066 tmp_species = Species_create( sbml_model.SBML_level);
0067 sbml_tmp_compartment = Compartment_create( sbml_model.SBML_level);
0068 sbml_tmp_parameter = Parameter_create( sbml_model.SBML_level);
0069 sbml_tmp_species_ref = SpeciesReference_create( sbml_model.SBML_level);
0070 sbml_tmp_reaction = Reaction_create( sbml_model.SBML_level);
0071 sbml_tmp_law = KineticLaw_create( sbml_model.SBML_level);
0072 tmp_unit_definition = UnitDefinition_create( sbml_model.SBML_level);
0073 end
0074
0075 compartment_symbols = {'c','m','v','x','e','t','g','r','n','p'};
0076 compartment_names = {'Cytoplasm','Mitochondrion','Vacuole','Peroxisome','Extracellular','Pool','Golgi','Endoplasmic_reticulum','Nucleus','Periplasm'};
0077
0078
0079 tmp_unit_definition.id = reaction_units;
0080
0081 unit_kinds = {'mole','gram','second'};
0082 unit_exponents = [1 -1 -1];
0083 unit_scales = [-3 0 0];
0084 unit_multipliers = [1 1 1.0/60/60];
0085
0086 for i = 1:size( unit_kinds, 2 )
0087 tmp_unit.kind = unit_kinds{ i };
0088 tmp_unit.exponent = unit_exponents( i );
0089 tmp_unit.scale = unit_scales( i );
0090 tmp_unit.multiplier = unit_multipliers( i );
0091 tmp_unit_definition = UnitDefinition_addUnit( tmp_unit_definition, tmp_unit );
0092 end
0093 sbml_model = Model_addUnitDefinition( sbml_model, tmp_unit_definition );
0094
0095
0096
0097 the_compartments = {};
0098 for ( i=1:size( model.mets, 1 ) )
0099 tmp_met = model.mets{i};
0100
0101 if ( tmp_met( size( tmp_met, 2 ) ) == ']' );
0102 tmp_compartment = tmp_met( size( tmp_met, 2 ) - 1 );
0103 tmp_met = strrep( tmp_met, strcat( '[', tmp_compartment, ']' ), strcat( '_', tmp_compartment ) );
0104 end
0105 tmp_met = strcat( 'M_', strrep(tmp_met, '-', '_' ) );
0106 model.mets{ i } = tmp_met;
0107 tmp_species.id = tmp_met;
0108 tmp_species.compartment = tmp_met( size( tmp_met, 2 ) );
0109 if isfield( model, 'metNames' )
0110 tmp_species.name = model.metNames{i};
0111 end
0112 if isfield( model, 'metFormulas' )
0113 tmp_species.notes = ['<html xmlns="http://www.w3.org/1999/xhtml"><p>FORMULA: ' model.metFormulas{i} '</p></html>'];
0114 end
0115 if isfield( model, 'charges' )
0116
0117 tmp_species.charge = model.charges(i);
0118 end
0119 sbml_model.species = [ sbml_model.species tmp_species ];
0120
0121 the_compartments{ i } = tmp_species.compartment ;
0122 end
0123
0124
0125 the_compartments = unique( the_compartments );
0126 for (i=1:size(the_compartments,2))
0127 tmp_id = the_compartments{1,i};
0128 tmp_name = compartment_names{ find( strcmp( compartment_symbols, tmp_id ) ) };
0129 sbml_tmp_compartment.id = tmp_id;
0130 sbml_tmp_compartment.name = tmp_name;
0131 sbml_model = Model_addCompartment( sbml_model, sbml_tmp_compartment );
0132 end
0133
0134
0135 sbml_tmp_parameter.units = reaction_units;
0136 sbml_tmp_parameter.isSetValue = 1;
0137 for (i=1:size( model.rxns, 1 ) )
0138 tmp_id = strcat( 'R_', strrep( strrep(model.rxns{i}, '-', '_' ), '(e)', '_e' ) );
0139 model.rxns{i} = tmp_id;
0140 met_idx = find( model.S(:, i ) );
0141 sbml_tmp_reaction.notes = '';
0142
0143 sbml_tmp_reaction.reactant = [];
0144 sbml_tmp_reaction.product = [];
0145 sbml_tmp_reaction.kineticLaw = [];
0146 sbml_tmp_reaction.id = tmp_id;
0147 if isfield( model, 'rxnNames' )
0148 sbml_tmp_reaction.name = model.rxnNames{i};
0149 end
0150 if isfield( model, 'rev' )
0151 sbml_tmp_reaction.reversible = model.rev(i);
0152 end
0153 sbml_tmp_law.parameter = [];
0154 sbml_tmp_law.formula = 'FLUX_VALUE';
0155 sbml_tmp_parameter.id = 'LOWER_BOUND';
0156 sbml_tmp_parameter.value = model.lb( i );
0157 sbml_tmp_law.parameter = [ sbml_tmp_law.parameter sbml_tmp_parameter ];
0158 sbml_tmp_parameter.id = 'UPPER_BOUND';
0159 sbml_tmp_parameter.value = model.ub( i );
0160 sbml_tmp_law.parameter = [ sbml_tmp_law.parameter sbml_tmp_parameter ];
0161 sbml_tmp_parameter.id = 'FLUX_VALUE';
0162 sbml_tmp_parameter.value = 0;
0163 sbml_tmp_law.parameter = [ sbml_tmp_law.parameter sbml_tmp_parameter ];
0164 sbml_tmp_parameter.id = 'OBJECTIVE_COEFFICIENT';
0165 sbml_tmp_parameter.value = model.c( i );
0166 sbml_tmp_law.parameter = [ sbml_tmp_law.parameter sbml_tmp_parameter ];
0167 sbml_tmp_reaction.kineticLaw = sbml_tmp_law;
0168
0169 if ( isfield( model, 'grRules' ) || isfield( model, 'subSystems' ) )
0170 tmp_note = '<html xmlns="http://www.w3.org/1999/xhtml">';
0171 if isfield( model, 'grRules' )
0172 tmp_note = [tmp_note '<p>GENE_ASSOCIATION: ' model.grRules{i} '</p>' ];
0173 end
0174 if isfield( model, 'subSystems' )
0175 tmp_note = [ tmp_note ' <p>SUBSYSTEM: ' model.subSystems{i} '</p>'];
0176 end
0177 tmp_note = [tmp_note '</html>'];
0178 sbml_tmp_reaction.notes = tmp_note;
0179 end
0180
0181 for (j_met=1:size(met_idx,1) )
0182 tmp_idx = met_idx(j_met,1);
0183 sbml_tmp_species_ref.species = model.mets{tmp_idx};
0184 met_stoich = model.S( tmp_idx, i );
0185 sbml_tmp_species_ref.stoichiometry = abs( met_stoich );
0186 if ( met_stoich > 0 )
0187 sbml_tmp_reaction.product = [ sbml_tmp_reaction.product sbml_tmp_species_ref ];
0188 else
0189 sbml_tmp_reaction.reactant = [ sbml_tmp_reaction.reactant sbml_tmp_species_ref];
0190 end
0191 end
0192 sbml_model.reaction = [ sbml_model.reaction sbml_tmp_reaction ];
0193 end
0194
0195
0196
0197
0198
0199
0200
0201
0202