function [sbm] = cell2sbm( sbm, cell_data ) % sbm = cell2sbm( sbm, cell_data ) % Loads (2 x n) cell_data into an SBmodel, where the first row contains % species/parameter/compartment names, and the second row contains values % % sbm - the SBmodel to use % cell_data - a ( 2 x n ) cell array % % Check argument goodness if ( ~ strcmp( class( sbm ), 'SBmodel' ) ) error( 'First argument must be an SBmodel.' ); end if ( ~ iscell( cell_data ) ) error( 'Second argument must be a cell array.' ); elseif ( size( cell_data, 1 ) ~= 2 ) error( 'Cell data must have two rows.' ); end % Load default parameter name and values [species,ODEs,ic] = SBstates(sbm); [pn,pv] = SBparameters(sbm); [varnames,varforms] = SBvariables(sbm); sbs = SBstruct( sbm ); numIDs = size( cell_data, 2 ); NUMSWAPS = 0; for i = 1:numIDs sbmlid = cell_data{1,i}; value = cell_data{2,i}; if ( ~ ischar( sbmlid ) ) error( ['Non-string found in first row of cell data at index ' num2str(i)] ); elseif ( ~ isnumeric( value ) ) error( ['Non-numeric found in second row of cell data at index ' num2str(i) ] ); else % See if SBML ID is a Species i_s = strmatch( sbmlid, species, 'exact' ); if ( ~ isempty( i_s ) ) if strcmp( sbs.states(i_s).unittype, 'amount' ) cmptnm = sbs.states(i_s).compartment; i_p = strmatch( cmptnm, pn, 'exact' ); cpmtsz = pv(i_p); sbs.states(i_s).initialCondition = value / 6.0221415E+23 / cpmtsz; %sbs.states(i_s).unittype = 'concentration'; else sbs.states(i_s).initialCondition = value; end NUMSWAPS = NUMSWAPS + 1; else % See if it is a Parameter i_p = strmatch( sbmlid, pn, 'exact' ); if ( ~ isempty( i_p ) ) sbs.parameters(i_p).value = value; NUMSWAPS = NUMSWAPS + 1; else % See if it is a Variable or called, "time_zero" i_v = strmatch( sbmlid, varnames, 'exact' ); if ( isempty( i_v ) && ~strcmp( sbmlid, 'time_zero' ) ), %disp( ['Note: ' sbmlid ' is neither a species nor a parameter in this SBmodel.'] ); end end end end end disp( [num2str(NUMSWAPS) ' swaps made.']); % Load new values into model sbm = SBmodel(sbs);