def _set_metabolite_concentrations(self): ''' set the metabolite concentrations to values given in the sbtab (if specified) ''' for s in self._model.getListOfSpecies(): if misc.is_enzyme(s): # enzymes are treated separately continue conc = float(self._get_sbtab_entry('met_conc', species=s)) try: conc = float(self._get_sbtab_entry('met_conc', species=s)) s.setInitialConcentration(conc) except: self._print_warning('''No initial concentration found for species %s. Setting value to 1.''' % s.getId()) s.setInitialConcentration(1.)
def _create_global_params(self, g_params, mode): ''' create the global parameters @type g_params: list @param g_params: list of global parameters, as generated by pack_parameters function @type mode: string @param mode: parametrisation type ('cat' | 'weg' | 'hal') ''' # Hack, add temperature and gas constant if parametrization is 'weg' if mode == 'weg': p = self._model.createParameter() p.setId('temp') p.setValue(300) p = self._model.createParameter() p.setId('R') p.setValue(8.31) # iterate over all global parameter types global_param_count = 0 for p_type in self.mode2params[mode]: scope, deps, id_temp, required = self.param2options[p_type] if scope == 'local': continue p_value = g_params[global_param_count] global_param_count += 1 # decide whether parameter depends on species / reaction and add it if deps == 's' or deps == 'k': i = 0 for s in self._model.getListOfSpecies(): if misc.is_enzyme(s): continue self._add_param(p_type, p_value[i], reaction=None, species=s) i += 1 elif deps == 'r': for i, r in enumerate(self._model.getListOfReactions): self._add_param(p_type, p_value[i], reaction=r, species=None)
def _get_regulation(self, reaction): ''' get regulational term for a reaction @type reaction: libsbml.reaction @param reaction: reaction @rtype: tuple @return: (prefactor, denominator_term), where prefactor is a list of prefactors to the kinetic law and denominator term is a list of terms added to the denominator (one list entry per modifier) ''' prefacs = [] denom_terms = [] # generate one term for each modifier for m in reaction.getListOfModifiers(): if misc.is_enzyme(self._model.getSpecies(m.getSpecies())): continue # get the ids for the possiby involved parameters ka = self.param2options['k_a_vec'][2].replace( '$REAC$', reaction.getId()).replace('$SPECIES$', m.getSpecies()) ki = self.param2options['k_i_vec'][2].replace( '$REAC$', reaction.getId()).replace('$SPECIES$', m.getSpecies()) act_ratio = self.param2options['act_ratio_vec'][2].replace( '$REAC$', reaction.getId()).replace('$SPECIES$', m.getSpecies()) inh_ratio = self.param2options['inh_ratio_vec'][2].replace( '$REAC$', reaction.getId()).replace('$SPECIES$', m.getSpecies()) act_term = '(%s/%s)' % (m.getSpecies(), ka) inh_term = '(%s/%s)' % (m.getSpecies(), ki) # decide for regulation type sbo = m.getSBOTerm() try: reg_type = self.sbo2type[sbo] except: if reaction.getKineticLaw().getParameter(ka): reg_type = self._default_act elif reaction.getKineticLaw().getParameter(ki): reg_type = self._default_inh else: continue if 'act' in reg_type: if not reaction.getKineticLaw().getParameter(ka): raise Exception('Parameter %s not given' % ka) if 'inh' in reg_type: if not reaction.getKineticLaw().getParameter(ki): raise Exception('Parameter %s not given' % ki) if reg_type == 'partial_act' \ and not reaction.getKineticLaw().getParameter(act_ratio): raise Exception('Parameter %s not given' % act_ratio) if reg_type == 'partial_inh' \ and not reaction.getKineticLaw().getParameter(inh_ratio): raise Exception('Parameter %s not given' % inh_ratio) reaction.getKineticLaw().setSBOTerm(self.type2sbo[reg_type]) # generate the actual terms if reg_type == 'partial_act': term = '(%s + (1 - %s) * ( (%s) / (1 + %s)))' % ( act_ratio, act_ratio, act_term, act_term) elif reg_type == 'partial_inh': term = '(%s + (1 - %s) * ( 1 / (1 + %s)))' % ( inh_ratio, inh_ratio, inh_term) elif reg_type == 'complete_act': term = '((%s)/(1 + %s))' % (act_term, act_term) elif reg_type == 'complete_inh': term = '(1/(1 + %s))' % (inh_term) elif reg_type == 'specific_act': t = '(%s/%s)' % (ka, m.getSpecies()) denom_terms.append(t) continue elif reg_type == 'specific_inh': denom_terms.append(inh_term) continue else: raise Exception("Unknown regulation type: typo in code") prefacs.append(term) prefac = ' * '.join(prefacs) denom_term = ' + '.join(denom_terms) return (prefac, denom_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_regulation(self, reaction): ''' get regulational term for a reaction @type reaction: libsbml.reaction @param reaction: reaction @rtype: tuple @return: (prefactor, denominator_term), where prefactor is a list of prefactors to the kinetic law and denominator term is a list of terms added to the denominator (one list entry per modifier) ''' prefacs = [] denom_terms = [] # generate one term for each modifier for m in reaction.getListOfModifiers(): if misc.is_enzyme(self._model.getSpecies(m.getSpecies())): continue # get the ids for the possiby involved parameters ka = self.param2options['k_a_vec'][2].replace('$REAC$', reaction.getId()).replace('$SPECIES$', m.getSpecies()) ki = self.param2options['k_i_vec'][2].replace('$REAC$', reaction.getId()).replace('$SPECIES$', m.getSpecies()) act_ratio = self.param2options['act_ratio_vec'][2].replace('$REAC$', reaction.getId()).replace('$SPECIES$', m.getSpecies()) inh_ratio = self.param2options['inh_ratio_vec'][2].replace('$REAC$', reaction.getId()).replace('$SPECIES$', m.getSpecies()) act_term = '(%s/%s)' % (m.getSpecies(), ka) inh_term = '(%s/%s)' % (m.getSpecies(), ki) # decide for regulation type sbo = m.getSBOTerm() try: reg_type = self.sbo2type[sbo] except: if reaction.getKineticLaw().getParameter(ka): reg_type = self._default_act elif reaction.getKineticLaw().getParameter(ki): reg_type = self._default_inh else: continue if 'act' in reg_type: if not reaction.getKineticLaw().getParameter(ka): raise Exception('Parameter %s not given' % ka) if 'inh' in reg_type: if not reaction.getKineticLaw().getParameter(ki): raise Exception('Parameter %s not given' % ki) if reg_type == 'partial_act' \ and not reaction.getKineticLaw().getParameter(act_ratio): raise Exception('Parameter %s not given' % act_ratio) if reg_type == 'partial_inh' \ and not reaction.getKineticLaw().getParameter(inh_ratio): raise Exception('Parameter %s not given' % inh_ratio) reaction.getKineticLaw().setSBOTerm(self.type2sbo[reg_type]) # generate the actual terms if reg_type == 'partial_act': term = '(%s + (1 - %s) * ( (%s) / (1 + %s)))' % (act_ratio, act_ratio, act_term, act_term) elif reg_type == 'partial_inh': term = '(%s + (1 - %s) * ( 1 / (1 + %s)))' % (inh_ratio, inh_ratio, inh_term) elif reg_type == 'complete_act': term = '((%s)/(1 + %s))' % (act_term, act_term) elif reg_type == 'complete_inh': term = '(1/(1 + %s))' % (inh_term) elif reg_type == 'specific_act': t = '(%s/%s)' % (ka, m.getSpecies()) denom_terms.append(t) continue elif reg_type == 'specific_inh': denom_terms.append(inh_term) continue else: raise Exception("Unknown regulation type: typo in code") prefacs.append(term) prefac = ' * '.join(prefacs) denom_term = ' + '.join(denom_terms) return (prefac, denom_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)