cobra_struct_to_sbml_struct

PURPOSE ^

cobra_struct_to_sbml_struct converts a cobra structure to an sbml

SYNOPSIS ^

function sbml_model = cobra_struct_to_sbml_struct( model, sbml_level,sbml_version )

DESCRIPTION ^

  cobra_struct_to_sbml_struct converts a cobra structure to an sbml
  structure using the structures provided in the SBML toolbox 3.0.0

 sbmlModel = convertCobraToSBML(cobraModel,noInitDigitFlag)

NOTE: The name mangling of reaction and metabolite ids is necessary
for compliance with the SBML sID standard.

NOTE: Sometimes the Model_create function doesn't listen to the
sbml_version parameter, so it is essential that the items that
are added to the sbml_model are defined with the sbml_model's level 
and version:  sbml_model.SBML_level,sbml_model.SBML_version

NOTE:  Some of the structures are recycled to reduce to overhead for
their creation.  There's a chance this can cause bugs in the future.

NOTE: Currently, I don't add in the boundary metabolites.

NOTE: Speed could probably be improved by directly adding structures to
lists in a struct instead of using the SBML _addItem function, but this
could break in future versions of the SBML toolbox. 

POTENTIAL BUG: Assumes that the compartment abbreviation is 1 character.

POTENTIAL FUTURE BUG: To speed things up, sbml structs have been
recycled and are directly appended into lists instead of using _addItem

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function sbml_model = cobra_struct_to_sbml_struct( model, sbml_level,sbml_version )
0002 %  cobra_struct_to_sbml_struct converts a cobra structure to an sbml
0003 %  structure using the structures provided in the SBML toolbox 3.0.0
0004 %
0005 % sbmlModel = convertCobraToSBML(cobraModel,noInitDigitFlag)
0006 %
0007 %NOTE: The name mangling of reaction and metabolite ids is necessary
0008 %for compliance with the SBML sID standard.
0009 %
0010 %NOTE: Sometimes the Model_create function doesn't listen to the
0011 %sbml_version parameter, so it is essential that the items that
0012 %are added to the sbml_model are defined with the sbml_model's level
0013 %and version:  sbml_model.SBML_level,sbml_model.SBML_version
0014 %
0015 %NOTE:  Some of the structures are recycled to reduce to overhead for
0016 %their creation.  There's a chance this can cause bugs in the future.
0017 %
0018 %NOTE: Currently, I don't add in the boundary metabolites.
0019 %
0020 %NOTE: Speed could probably be improved by directly adding structures to
0021 %lists in a struct instead of using the SBML _addItem function, but this
0022 %could break in future versions of the SBML toolbox.
0023 %
0024 %POTENTIAL BUG: Assumes that the compartment abbreviation is 1 character.
0025 %
0026 %POTENTIAL FUTURE BUG: To speed things up, sbml structs have been
0027 %recycled and are directly appended into lists instead of using _addItem
0028  
0029   %A flag to know if the user is using the older version of the sbml toolbox.
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 %  load 'model.mat'; %Just for initial function development and debugging.
0036 %  a_tic = tic;
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   %POTENTIAL FUTURE BUG: Create temporary structs to speed things up.
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   %% Compartments
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   %Create and add the unit definition to the sbml model struct.
0079   tmp_unit_definition.id =  reaction_units;
0080   %The 4 following lists are in matched order for each unit.
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   %Add the units to the unit definition
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   %List to hold the compartment ids.
0097   the_compartments = {};
0098   for ( i=1:size( model.mets, 1 ) )
0099     tmp_met = model.mets{i};
0100     %Change id to correspond to SBML id specifications
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       %NOTE: charge is being removed in SBML level 3
0117       tmp_species.charge = model.charges(i);
0118     end
0119     sbml_model.species = [ sbml_model.species tmp_species ];
0120     %This is where the compartment symbols are aggregated.
0121     the_compartments{ i } = tmp_species.compartment ;
0122   end
0123 
0124   %Add the unique compartments to the model struct.
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   %Add the reactions to the model struct.  Use the species references.
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     %Reset the fields that have been filled.
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     %Add in other notes
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     %Add in the reactants and products
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 %toc(a_tic)
0197 %  save -MAT 'sbml.mat' sbml_model; %just for development purposes.
0198 
0199 
0200 
0201 
0202

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003