def _get_denominator(self, reaction, mode): def get_substr_term(s): term = self._get_substrate_term(s) term = term[:term.rfind(')') + 1] term = 'sqrt(%s)' % term return term text = ' * '.join( [get_substr_term(s) for s in misc.get_participants(reaction)]) return '(%s)' % text
def _get_denominator(self, reaction, mode): def get_substr_term(s): term = self._get_substrate_term(s) term = term[:term.rfind(')') + 1] term = 'sqrt(%s)' % term return term text = ' * '.join([get_substr_term(s) for s in misc.get_participants(reaction)]) return '(%s)' % text
def _create_local_params(self, reaction, params, mode): ''' create the local parameters for a reaction @type reaction: libsbml.reaction @param reaction: the reaction, if paramter is associated with a reaction @type params: list @param params: list of local (assigned to a reaction) parameters, as generated by pack_parameters function @type mode: string @param mode: parametrisation type ('cat' | 'weg' | 'hal') ''' local_param_count = 0 # iterate over all parameter types for this mode for p_type in self.mode2params[mode]: # get options scope, deps, id_temp, required = self.param2options[p_type] if scope == 'global': # this function is for global parameters continue # get the value p_value = params[local_param_count] local_param_count += 1 # based on dependencies, # add one parameter for reaction / reactant / modifier if deps == '': self._add_param(p_type, p_value, reaction) elif deps == 's': for i, s in enumerate(misc.get_participants(reaction)): self._add_param(p_type, p_value[i], reaction, s) elif deps == 'k': # here go the k_i_vec and k_a_vec for i, s in enumerate(misc.get_modifiers(reaction)): sboterm = s.getSBOTerm() if p_value[i] is None: continue else: if sboterm in self.sbo_act and p_type == 'k_a_vec': self._add_param(p_type, p_value[i], reaction, s) elif sboterm in self.sbo_inh and p_type == 'k_i_vec': self._add_param(p_type, p_value[i], reaction, s) elif deps == 'm': # here go the inh_ratio_vec and act_ratio_vec for i, s in enumerate(reaction.getListOfModifiers()): if p_value[i] is None: continue self._add_param(p_type, p_value[i], reaction=reaction, species=s)
def _get_denominator(self, reaction, mode): get_substr_term = lambda s: self._get_substrate_term(s).replace( '(', '( 1 + ') text = ' * '.join( [get_substr_term(s) for s in misc.get_participants(reaction)]) return '(%s)' % text
def _get_numerator(self, reaction, mode): ''' get the numerator for the kinetic law @type reaction: libsbml.reaction @param reaction: the reaction @type mode: string @param mode: parametrisation type ('cat' | 'weg' | 'hal') ''' # define little functionto get s^stoich def get_substrate_term(s): s_id = s.getSpecies() if s.getStoichiometry() != 1: s_id += '^' + str(s.getStoichiometry()) return s_id # define little function to get KM^stoich def get_km_term(s): km_id = self.param2options['km_vec'][2].replace( '$REAC$', reaction.getId()).replace('$SPECIES$', s.getSpecies()) if s.getStoichiometry() != 1: km_id += '^' + str(s.getStoichiometry()) return km_id # get the id templates for kf, kb and hill coeff. kf_id_temp = self.param2options['kf'][2] kb_id_temp = self.param2options['kb'][2] hill_id_temp = self.param2options['hill_coeff'][2] # generate the numerator term dpending on parameterization type if mode == 'cat': forw_term = kf_id_temp.replace('$REAC$', reaction.getId()) + ' * ' back_term = kb_id_temp.replace('$REAC$', reaction.getId()) + ' * ' forw_term += ' * '.join([ self._get_substrate_term(s) for s in reaction.getListOfReactants() ]) back_term += ' * '.join([ self._get_substrate_term(s) for s in reaction.getListOfProducts() ]) if reaction.getNumReactants() == 0: forw_term = '0' elif reaction.getNumProducts() == 0: back_term = '0' term = '( ( %s ) - ( %s ) )' % (forw_term, back_term) elif mode == 'hal': react_term = ' * '.join([get_substrate_term(s) for s in reaction.getListOfReactants()]) \ or '0' prod_term = ' * '.join([get_substrate_term(s) for s in reaction.getListOfProducts()]) \ or '0' km_term = ' * '.join( [get_km_term(s) for s in misc.get_participants(reaction)]) kv = self.param2options['kv'][2].replace('$REAC$', reaction.getId()) keq = self.param2options['keq'][2].replace('$REAC$', reaction.getId()) hill_coeff = hill_id_temp.replace('$REAC$', reaction.getId()) term = '''( %s * ( ( ((%s)^(%s/2.)) * %s) - (((%s)^(-%s/2.)) * %s) ) )''' % (kv, keq, hill_coeff, react_term, keq, hill_coeff, prod_term) term = '(%s) / sqrt(%s)' % (term, km_term) elif mode == 'weg': mu_id_temp = self.param2options['mu_vec'][2] def get_mu_term(s): mu_id = mu_id_temp.replace('$SPECIES$', s.getSpecies()) if s.getStoichiometry() != 1: mu_id = str(s.getStoichiometry()) + '*' + mu_id return mu_id mu_f_term = ' + '.join([get_mu_term(s) for s in reaction.getListOfReactants()]) \ or '0' mu_b_term = ' + '.join([get_mu_term(s) for s in reaction.getListOfProducts()]) \ or '0' mu_term = '(%s) - (%s)' % (mu_b_term, mu_f_term) hill_coeff = hill_id_temp.replace('$REAC$', reaction.getId()) react_term = ' * '.join([get_substrate_term(s) for s in reaction.getListOfReactants()])\ or '0' prod_term = ' * '.join([get_substrate_term(s) for s in reaction.getListOfProducts()]) \ or '0' km_term = ' * '.join( [get_km_term(s) for s in misc.get_participants(reaction)]) kv = self.param2options['kv'][2].replace('$REAC$', reaction.getId()) term = '''( %s * (( exp(-%s * (%s)/(2*R*temp)) * (%s) ) - (exp(%s * (%s)/(2*R*temp)) * (%s)) ) / sqrt(%s))''' \ % (kv, hill_coeff, mu_term, react_term, hill_coeff, mu_term, prod_term, km_term) else: # in case somebody chose a mode we do not know raise Exception('Implement') return term
def _pack_parameters(self, mode): ''' get the parameters from the sbtab and pack them in a way that they can be added easily. Parameters are separated in local ones (associated with a reaction) and global ones. @type mode: string @param mode: parametrisation type ('cat' | 'weg' | 'hal') @rtype: tuple @return: tuple of (global_parameters, local_parameters) where global parameters is the list of global params (1 entry for each param type) and local_parameter is the list of local params (1 entry for each reaction) ''' # get the global params global_params = [] # get global params for all parameters specified for this mode for p_type in self.mode2params[mode]: p_vec = [] scope, deps, dummy, required = self.param2options[p_type] if scope == 'local': continue # if param. depends on species, get one param for each species, if # it depends on reaction get one for each reaction if deps == 's' or deps == 'k': for s in self._model.getListOfSpecies(): if misc.is_enzyme(s): continue p_value = self._get_sbtab_entry(p_type, species=s) p_vec.append(p_value) elif deps == 'r': for r in self._model.getListOfReactions(): p_value = self._get_sbtab_entry(p_type, reaction=r) p_vec.append(p_value) global_params.append(p_vec) # get local parameters (one set for each reaction) local_params = [] for r in self._model.getListOfReactions(): reaction_params = [] for p_type in self.mode2params[mode]: scope, deps, dummy, required = self.param2options[p_type] if scope == 'global': continue if deps == '': p_vec = self._get_sbtab_entry(p_type, reaction=r) elif deps == 's': p_vec = [] for s in misc.get_participants(r): p_value = self._get_sbtab_entry( p_type, reaction=r, species=self._model.getSpecies(s.getSpecies())) p_vec.append(p_value) elif deps == 'k': p_vec = [] for s in misc.get_modifiers(r): p_value = self._get_sbtab_entry( p_type, reaction=r, species=self._model.getSpecies(s.getSpecies())) p_vec.append(p_value) elif deps == 'm': p_vec = [] for m in r.getListOfModifiers(): p_value = self._get_sbtab_entry( p_type, reaction=r, species=self._model.getSpecies(m.getSpecies())) p_vec.append(p_value) reaction_params.append(p_vec) local_params.append(reaction_params) return (global_params, local_params)
def _get_denominator(self, reaction, mode): get_substr_term = lambda s: self._get_substrate_term(s).replace('(', '( 1 + ') text = ' * '.join([get_substr_term(s) for s in misc.get_participants(reaction)]) return '(%s)' % text
def _get_numerator(self, reaction, mode): ''' get the numerator for the kinetic law @type reaction: libsbml.reaction @param reaction: the reaction @type mode: string @param mode: parametrisation type ('cat' | 'weg' | 'hal') ''' # define little functionto get s^stoich def get_substrate_term(s): s_id = s.getSpecies() if s.getStoichiometry() != 1: s_id += '^' + str(s.getStoichiometry()) return s_id # define little function to get KM^stoich def get_km_term(s): km_id = self.param2options['km_vec'][2].replace('$REAC$', reaction.getId()).replace('$SPECIES$', s.getSpecies()) if s.getStoichiometry() != 1: km_id += '^' + str(s.getStoichiometry()) return km_id # get the id templates for kf, kb and hill coeff. kf_id_temp = self.param2options['kf'][2] kb_id_temp = self.param2options['kb'][2] hill_id_temp = self.param2options['hill_coeff'][2] # generate the numerator term dpending on parameterization type if mode == 'cat': forw_term = kf_id_temp.replace('$REAC$', reaction.getId()) + ' * ' back_term = kb_id_temp.replace('$REAC$', reaction.getId()) + ' * ' forw_term += ' * '.join([self._get_substrate_term(s) for s in reaction.getListOfReactants()]) back_term += ' * '.join([self._get_substrate_term(s) for s in reaction.getListOfProducts()]) if reaction.getNumReactants() == 0: forw_term = '0' elif reaction.getNumProducts() == 0: back_term = '0' term = '( ( %s ) - ( %s ) )' % (forw_term, back_term) elif mode == 'hal': react_term = ' * '.join([get_substrate_term(s) for s in reaction.getListOfReactants()]) \ or '0' prod_term = ' * '.join([get_substrate_term(s) for s in reaction.getListOfProducts()]) \ or '0' km_term = ' * '.join([get_km_term(s) for s in misc.get_participants(reaction)]) kv = self.param2options['kv'][2].replace('$REAC$', reaction.getId()) keq = self.param2options['keq'][2].replace('$REAC$', reaction.getId()) hill_coeff = hill_id_temp.replace('$REAC$', reaction.getId()) term = '''( %s * ( ( ((%s)^(%s/2.)) * %s) - (((%s)^(-%s/2.)) * %s) ) )''' % (kv, keq, hill_coeff, react_term, keq, hill_coeff, prod_term) term = '(%s) / sqrt(%s)' % (term, km_term) elif mode == 'weg': mu_id_temp = self.param2options['mu_vec'][2] def get_mu_term(s): mu_id = mu_id_temp.replace('$SPECIES$', s.getSpecies()) if s.getStoichiometry() != 1: mu_id = str(s.getStoichiometry()) + '*' + mu_id return mu_id mu_f_term = ' + '.join([get_mu_term(s) for s in reaction.getListOfReactants()]) \ or '0' mu_b_term = ' + '.join([get_mu_term(s) for s in reaction.getListOfProducts()]) \ or '0' mu_term = '(%s) - (%s)' % (mu_b_term, mu_f_term) hill_coeff = hill_id_temp.replace('$REAC$', reaction.getId()) react_term = ' * '.join([get_substrate_term(s) for s in reaction.getListOfReactants()])\ or '0' prod_term = ' * '.join([get_substrate_term(s) for s in reaction.getListOfProducts()]) \ or '0' km_term = ' * '.join([get_km_term(s) for s in misc.get_participants(reaction)]) kv = self.param2options['kv'][2].replace('$REAC$', reaction.getId()) term = '''( %s * (( exp(-%s * (%s)/(2*R*temp)) * (%s) ) - (exp(%s * (%s)/(2*R*temp)) * (%s)) ) / sqrt(%s))''' \ % (kv, hill_coeff, mu_term, react_term, hill_coeff, mu_term, prod_term, km_term) else: # in case somebody chose a mode we do not know raise Exception('Implement') return term
def _pack_parameters(self, mode): ''' get the parameters from the sbtab and pack them in a way that they can be added easily. Parameters are separated in local ones (associated with a reaction) and global ones. @type mode: string @param mode: parametrisation type ('cat' | 'weg' | 'hal') @rtype: tuple @return: tuple of (global_parameters, local_parameters) where global parameters is the list of global params (1 entry for each param type) and local_parameter is the list of local params (1 entry for each reaction) ''' # get the global params global_params = [] # get global params for all parameters specified for this mode for p_type in self.mode2params[mode]: p_vec = [] scope, deps, dummy, required = self.param2options[p_type] if scope == 'local': continue # if param. depends on species, get one param for each species, if # it depends on reaction get one for each reaction if deps == 's' or deps == 'k': for s in self._model.getListOfSpecies(): if misc.is_enzyme(s): continue p_value = self._get_sbtab_entry(p_type, species=s) p_vec.append(p_value) elif deps == 'r': for r in self._model.getListOfReactions(): p_value = self._get_sbtab_entry(p_type, reaction=r) p_vec.append(p_value) global_params.append(p_vec) # get local parameters (one set for each reaction) local_params = [] for r in self._model.getListOfReactions(): reaction_params = [] for p_type in self.mode2params[mode]: scope, deps, dummy, required = self.param2options[p_type] if scope == 'global': continue if deps == '': p_vec = self._get_sbtab_entry(p_type, reaction=r) elif deps == 's': p_vec = [] for s in misc.get_participants(r): p_value = self._get_sbtab_entry(p_type, reaction=r, species=self._model.getSpecies(s.getSpecies())) p_vec.append(p_value) elif deps == 'k': p_vec = [] for s in misc.get_modifiers(r): p_value = self._get_sbtab_entry(p_type, reaction=r, species=self._model.getSpecies(s.getSpecies())) p_vec.append(p_value) elif deps == 'm': p_vec = [] for m in r.getListOfModifiers(): p_value = self._get_sbtab_entry(p_type, reaction=r, species=self._model.getSpecies(m.getSpecies())) p_vec.append(p_value) reaction_params.append(p_vec) local_params.append(reaction_params) return (global_params, local_params)