def test_stop_if(): Model() Monomer('A') Rule('A_synth', None >> A(), Parameter('k', 1)) Observable('Atot', A()) Expression('exp_const', k + 1) Expression('exp_dyn', Atot + 1) sim = BngSimulator(model, verbose=5) tspan = np.linspace(0, 100, 101) x = sim.run(tspan, stop_if='Atot>9', seed=_BNG_SEED) # All except the last Atot value should be <=9 assert all(x.observables['Atot'][:-1] <= 9) assert x.observables['Atot'][-1] > 9 # Starting with Atot > 9 should terminate simulation immediately y = sim.run(tspan, initials=x.species[-1], stop_if='Atot>9') assert len(y.observables) == 1
def test_integrate_with_expression(): """Ensure a model with Expressions simulates.""" Monomer('s1') Monomer('s9') Monomer('s16') Monomer('s20') # Parameters should be able to contain s(\d+) without error Parameter('ks0', 2e-5) Parameter('ka20', 1e5) Initial(s9(), Parameter('s9_0', 10000)) Observable('s1_obs', s1()) Observable('s9_obs', s9()) Observable('s16_obs', s16()) Observable('s20_obs', s20()) Expression('keff', (ks0 * ka20) / (ka20 + s9_obs)) Rule('R1', None >> s16(), ks0) Rule('R2', None >> s20(), ks0) Rule('R3', s16() + s20() >> s16() + s1(), keff) time = np.linspace(0, 40) x = odesolve(model, time)
def test_integrate_with_expression(): """Ensure a model with Expressions simulates.""" Monomer('s1') Monomer('s9') Monomer('s16') Monomer('s20') # Parameters should be able to contain s(\d+) without error Parameter('ks0', 2e-5) Parameter('ka20', 1e5) Initial(s9(), Parameter('s9_0', 10000)) Observable('s1_obs', s1()) Observable('s9_obs', s9()) Observable('s16_obs', s16()) Observable('s20_obs', s20()) Expression('keff', (ks0 * ka20) / (ka20 + s9_obs)) Rule('R1', None >> s16(), ks0) Rule('R2', None >> s20(), ks0) Rule('R3', s16() + s20() >> s16() + s1(), keff) time = np.linspace(0, 40) sim = ScipyOdeSimulator(model, tspan=time) simres = sim.run() keff_vals = simres.expressions['keff'] assert len(keff_vals) == len(time) assert np.allclose(keff_vals, 1.8181818181818182e-05)
def test_integrate_with_expression(): """Ensure a model with Expressions simulates.""" Monomer('s1') Monomer('s9') Monomer('s16') Monomer('s20') # Parameters should be able to contain s(\d+) without error Parameter('ks0', 2e-5) Parameter('ka20', 1e5) Initial(s9(), Parameter('s9_0', 10000)) Observable('s1_obs', s1()) Observable('s9_obs', s9()) Observable('s16_obs', s16()) Observable('s20_obs', s20()) Expression('keff', (ks0 * ka20) / (ka20 + s9_obs)) Rule('R1', None >> s16(), ks0) Rule('R2', None >> s20(), ks0) Rule('R3', s16() + s20() >> s16() + s1(), keff) time = np.linspace(0, 40) solver = Solver(model, time) solver.run() assert solver.yexpr_view.shape == (len(time), len(model.expressions_dynamic())) assert solver.yobs_view.shape == (len(time), len(model.observables))
def test_unicode_exprname_nonascii(): """Ensure non-ascii unicode expression names error in python 2.""" t = np.linspace(0, 100) rob_copy = copy.deepcopy(robertson.model) ab = rob_copy.observables['A_total'] + rob_copy.observables['B_total'] expr = Expression(u'A_plus_B\u1234', ab, _export=False) rob_copy.add_component(expr) sim = ScipyOdeSimulator(rob_copy) simres = sim.run(tspan=t)
def add_gf_bolus(model, name: str, created_monomers: List[str]): bolus = Monomer(f'{name}_ext') Initial(bolus(), Parameter(f'{name}_0', 0.0), fixed=True) for created_monomer in created_monomers: koff = Parameter(f'{name}_{created_monomer}_koff', 0.1) kd = Parameter(f'{name}_{created_monomer}_kd', 1.0) kon = Expression(f'{name}_{created_monomer}_kon', kd * koff) Rule(f'{name}_ext_to_{created_monomer}', bolus() | model.monomers[created_monomer](inh=None), kon, koff)
def add_abundance_observables(model): """ Adds an observable that tracks the normalized absolute abundance of a protein """ for monomer in model.monomers: obs = Observable(f'total_{monomer.name}', monomer()) scale = Parameter(f't{monomer.name}_scale', 1.0) offset = Parameter(f't{monomer.name}_offset', 1.0) Expression(f't{monomer.name}_obs', sp.log(scale * (obs + offset)))
def test_unicode_exprname_ascii(): """Ensure ascii-convetible unicode expression names are handled.""" t = np.linspace(0, 100) rob_copy = copy.deepcopy(robertson.model) ab = rob_copy.observables['A_total'] + rob_copy.observables['B_total'] expr = Expression(u'A_plus_B', ab, _export=False) rob_copy.add_component(expr) sim = ScipyOdeSimulator(rob_copy) simres = sim.run(tspan=t) simres.all simres.dataframe
def add_phospho_observables(model): """ Adds an observable that tracks the normalized absolute abundance of a phosphorylated site """ for monomer in model.monomers: for site in monomer.site_states: if re.match(r'[YTS][0-9]+$', site): obs = Observable(f'p{monomer.name}_{site}', monomer(**{site: 'p'})) scale = Parameter(f'p{monomer.name}_{site}_scale', 1.0) offset = Parameter(f'p{monomer.name}_{site}_offset', 1.0) Expression(f'p{monomer.name}_{site}_obs', sp.log(scale * (obs + offset)))
def add_inhibitor(model: Model, name: str, targets: List[str]): inh = Parameter(f'{name}_0', 0.0) kd = Parameter(f'{name}_kd', 0.0) affinities = { target: Expression(f'inh_{target}', Observable(f'target_{target}', model.monomers[target]) / kd) for target in targets } for expr in model.expressions: if expr.name.startswith('inh_'): continue target = next( (next(mp.monomer.name for cp in s.reaction_pattern.complex_patterns for mp in cp.monomer_patterns if mp.monomer.name in targets) for s in expr.expr.free_symbols if isinstance(s, Observable) and any( mp.monomer.name in targets for cp in s.reaction_pattern.complex_patterns for mp in cp.monomer_patterns)), None) if target is None: continue expr.expr *= 1 / (1 + inh * affinities[target])
def add_activation(model: Model, m_name: str, site: str, activation_type: str, activators: Optional[Iterable[str]] = None, deactivators: Optional[Iterable[str]] = None): """ Adds activation/deactivation rules to a specific site :param model: model to which the rules will be added :param m_name: monomer name :param site: site name :param activation_type: type of activation, valid values are {`phosphorylation`, `nucleotide_exchange`, `tf_activation`} :param activators: molecular species that activate the respective site, format according to modulator format in :py:func:`add_or_get_modulator_obs` :param deactivators: molecular species that deactivate the respective site, format according to modulator format in :py:func:`add_or_get_modulator_obs` """ if activators is None: activators = [] if deactivators is None: deactivators = [] if m_name not in model.monomers.keys(): raise ValueError(f'{m_name} is not a monomer in the model.') mono = model.monomers[m_name] if activation_type == 'phosphorylation': valid_states = ['u', 'p'] elif activation_type == 'nucleotide_exchange': valid_states = ['gdp', 'gtp'] elif activation_type == 'tf_activation': valid_states = ['active', 'inactive'] else: raise ValueError(f'Invalid activation type {activation_type}.') sites = [site for site in site.split('_')] for site in sites: if site not in mono.site_states \ or len(mono.site_states[site]) != len(valid_states) \ or any(state not in mono.site_states[site] for state in valid_states): raise ValueError(f'{site} is not a valid target for ' f'{activation_type}.') if activation_type == 'phosphorylation': forward = 'phosphorylation' backward = 'dephosphorylation' fstate = {site: 'u' for site in sites} rstate = {site: 'p' for site in sites} elif activation_type == 'nucleotide_exchange': forward = 'gtp_exchange' backward = 'gdp_exchange' fstate = {site: 'gdp' for site in sites} rstate = {site: 'gtp' for site in sites} else: raise ValueError(f'Invalid activation type {activation_type}.') for label, educts, products, modulators in zip( [forward, backward], [mono(**fstate), mono(**rstate)], [mono(**rstate), mono(**fstate)], [activators, deactivators], ): for modulator in modulators: kcat = Parameter(f'{m_name}_{label}_{site}_{modulator}_kcat', 1.0) rate_expr = kcat * add_or_get_modulator_obs(model, modulator) # if label == forward: rate_expr *= get_autoencoder_modulator(kcat) rate = Expression(f'{m_name}_{label}_{site}_{modulator}_rate', rate_expr) Rule(F'{m_name}_{label}_{site}_{modulator}', educts >> products, rate)
# Rulebender to PySB. This is just a model file - must be run from a run file from pysb import Model, Parameter, Expression, Initial, Monomer, Observable, Rule, WILD # Begin Model Model() # ============================================================================= # # Parameters # ============================================================================= Parameter('NA', 6.022E23) # Avogadro's number (molecues/mol) Parameter('PI', 3.142) # no unit Parameter('rad_cell', 30E-6) # radius of cell in m approx 30 micron Parameter('cell_thickness', 8E-6) # height, m Parameter('cell_dens', 1E5) # density of cells , /L Parameter('width_PM', 1E-6) # effective width of membrane , m Expression('volEC', 1 / cell_dens) # vol. extracellular space , L Expression( 'volPM', 2 * rad_cell**2 + rad_cell * cell_thickness * 4) # virtual vol. of plasma membrane , L Expression('volCP', cell_thickness * rad_cell**2) # vol. of cytoplasm , L Parameter('IFN', 1E-9) # initial concentration in Molar Expression('I', IFN * volEC * NA) # number of copies per cell (~ 6.022e8 copies per cell) Expression('Ia', I) #Expression('Ib', I) #Parameter('r', 0) # Receptor assymmetry #Parameter('R', 0) # Parameter('R1', 2000) #(2000/7.2e-15)*volCP#(8000/2.76e-9)*volPM#R -r# Parameter( 'R2', 2000
Parameter('MAP2K2_phosphorylation_S226_BRAF__S445_p_kcat', 1.0) Parameter('INPUT_MAP2K2_phosphorylation_S226_BRAF__S445_p_kcat', 0.0) Parameter('MAPK1_phosphorylation_Y187_MAP2K1__S218_p__S222_p_kcat', 1.0) Parameter('INPUT_MAPK1_phosphorylation_Y187_MAP2K1__S218_p__S222_p_kcat', 0.0) Parameter('MAPK1_phosphorylation_Y187_MAP2K2__S222_p__S226_p_kcat', 1.0) Parameter('INPUT_MAPK1_phosphorylation_Y187_MAP2K2__S222_p__S226_p_kcat', 0.0) Parameter('MAPK3_phosphorylation_Y204_MAP2K1__S218_p__S222_p_kcat', 1.0) Parameter('INPUT_MAPK3_phosphorylation_Y204_MAP2K1__S218_p__S222_p_kcat', 0.0) Parameter('MAPK3_phosphorylation_Y204_MAP2K2__S222_p__S226_p_kcat', 1.0) Parameter('INPUT_MAPK3_phosphorylation_Y204_MAP2K2__S222_p__S226_p_kcat', 0.0) Parameter('iEGFR_0', 0.0) Parameter('iEGFR_kd', 0.0) Parameter('iMEK_0', 0.0) Parameter('iMEK_kd', 0.0) Expression('EGF_EGF_kon', EGF_EGF_kd * EGF_EGF_koff) Expression( 'EGFR_dephosphorylation_Y1173_base_rate', EGFR_dephosphorylation_Y1173_base_kcat * INPUT_EGFR_dephosphorylation_Y1173_base_kcat) Expression( 'ERBB2_dephosphorylation_Y1248_base_rate', ERBB2_dephosphorylation_Y1248_base_kcat * INPUT_ERBB2_dephosphorylation_Y1248_base_kcat) Expression( 'RAF1_dephosphorylation_S338_base_rate', INPUT_RAF1_dephosphorylation_S338_base_kcat * RAF1_dephosphorylation_S338_base_kcat) Expression( 'BRAF_dephosphorylation_S445_base_rate', BRAF_dephosphorylation_S445_base_kcat *
Monomer('R', ['r', 'i']) #RAF Monomer('I', ['r']) #RAF inhibitor #Kinetic parameters, koff /s/M, kon /s Parameter('koff_RR', 10**-1) Parameter('kon_RR', 10**-2) Parameter('koff_RI', 10**-1) Parameter('kon_RI', 10) #Thermodynamic factors, no units Parameter('f', 1) Parameter('g', 1) #Rate distribution parameter, no units Parameter('phi', 0.5) #Standard free energy of formation, kJ/mol. Expression('Gf_RR', getGfRT(kon_RR, koff_RR)) Expression('Gf_RI', getGfRT(kon_RI, koff_RI)) Expression('f_Gf', getTGfRT(f)) Expression('g_Gf', getTGfRT(g)) #Baseline activation energy, kJ/mol. Expression('Ea0_RR', getEa0RT(kon_RR, koff_RR, phi)) Expression('Ea0_RI', getEa0RT(kon_RI, koff_RI, phi)) #RAF dimerization EnergyPattern('ep_RR', R(r=1) % R(r=1), Gf_RR) Rule('RR_binding', R(r=None) + R(r=None) | R(r=1) % R(r=1), phi, Ea0_RR, energy=True)
def add_monomer_synth_deg(m_name: str, psites: Optional[Iterable[str]] = None, nsites: Optional[Iterable[str]] = None, asites: Optional[Iterable[str]] = None, asite_states: Optional[Iterable[str]] = None): """ Adds the respective monomer plus synthesis rules and basal activation/deactivation rules for all activateable sites :param m_name: monomer name :param psites: phospho sites :param nsites: nucleotide sites :param asites: other activity encoding sites """ if psites is None: psites = [] else: psites = list({site for psite in psites for site in psite.split('_')}) if nsites is None: nsites = [] if asites is None: asites = [] if asite_states is None: asite_states = ['inactive', 'active'] sites = psites + nsites + asites + ['inh'] m = Monomer(m_name, sites=sites, site_states={ site: ['u', 'p'] if site in psites else ['gdp', 'gtp'] if site in nsites else asite_states for site in sites if site in psites + nsites + asites }) #kdeg = Parameter(f'{m_name}_degradation_kdeg', 1.0) t = Parameter(f'{m_name}_eq', 100.0) #ksyn = Expression(f'{m_name}_synthesis_ksyn', t*kdeg) #syn_rate = Expression(f'{m_name}_synthesis_rate', # ksyn * get_autoencoder_modulator(t)) syn_prod = m( **{ site: 'u' if site in psites else 'gdp' if site in nsites else None if site is 'inh' else asite_states[0] for site in sites }) #Rule(f'synthesis_{m_name}', None >> syn_prod, syn_rate) #deg_rate = Expression(f'{m_name}_degradation_rate', kdeg) #Rule(f'degradation_{m_name}', m() >> None, deg_rate) #t_ss = Expression(f'{m_name}_ss', syn_rate/deg_rate) Initial(syn_prod, t) # basal activation for sites, labels, fstate, rstate in zip( [psites, nsites, asites], [('phosphorylation', 'dephosphorylation'), ('gtp_exchange', 'gdp_exchange'), ('activation', 'deactivation')], ['p', 'gtp', asite_states[1]], ['u', 'gdp', asite_states[0]]): for site in sites: kcats = [ Parameter(f'{m_name}_{label}_{site}_base_kcat', 1.0) for label in labels[1:] ] rates = [ Expression(f'{m_name}_{label}_{site}_base_rate', kcat * get_autoencoder_modulator(kcat)) for kcat, label in zip(kcats, labels[1:]) ] #Rule(F'{m_name}_{site}_base', # m(**{site: rstate}) | m(**{site: fstate}), *rates) Rule(F'{m_name}_{site}_base', m(**{site: fstate}) >> m(**{site: rstate}), *rates) return m
Parameter('MAP2K1_phosphorylation_S222_BRAF__S447_p_kcat', 1.0) Parameter('INPUT_MAP2K1_phosphorylation_S222_BRAF__S447_p_kcat', 0.0) Parameter('MAP2K2_phosphorylation_S226_RAF1__S338_p_kcat', 1.0) Parameter('INPUT_MAP2K2_phosphorylation_S226_RAF1__S338_p_kcat', 0.0) Parameter('MAP2K2_phosphorylation_S226_BRAF__S447_p_kcat', 1.0) Parameter('INPUT_MAP2K2_phosphorylation_S226_BRAF__S447_p_kcat', 0.0) Parameter('MAPK1_phosphorylation_Y187_MAP2K1__S218_p__S222_p_kcat', 1.0) Parameter('INPUT_MAPK1_phosphorylation_Y187_MAP2K1__S218_p__S222_p_kcat', 0.0) Parameter('MAPK1_phosphorylation_Y187_MAP2K2__S222_p__S226_p_kcat', 1.0) Parameter('INPUT_MAPK1_phosphorylation_Y187_MAP2K2__S222_p__S226_p_kcat', 0.0) Parameter('MAPK3_phosphorylation_Y204_MAP2K1__S218_p__S222_p_kcat', 1.0) Parameter('INPUT_MAPK3_phosphorylation_Y204_MAP2K1__S218_p__S222_p_kcat', 0.0) Parameter('MAPK3_phosphorylation_Y204_MAP2K2__S222_p__S226_p_kcat', 1.0) Parameter('INPUT_MAPK3_phosphorylation_Y204_MAP2K2__S222_p__S226_p_kcat', 0.0) Expression('FLT3_dephosphorylation_Y843_base_rate', FLT3_dephosphorylation_Y843_base_kcat*INPUT_FLT3_dephosphorylation_Y843_base_kcat) Expression('HRAS_gdp_exchange_N_base_rate', HRAS_gdp_exchange_N_base_kcat*INPUT_HRAS_gdp_exchange_N_base_kcat) Expression('KRAS_gdp_exchange_N_base_rate', INPUT_KRAS_gdp_exchange_N_base_kcat*KRAS_gdp_exchange_N_base_kcat) Expression('NRAS_gdp_exchange_N_base_rate', INPUT_NRAS_gdp_exchange_N_base_kcat*NRAS_gdp_exchange_N_base_kcat) Expression('RAF1_dephosphorylation_S338_base_rate', INPUT_RAF1_dephosphorylation_S338_base_kcat*RAF1_dephosphorylation_S338_base_kcat) Expression('BRAF_dephosphorylation_S447_base_rate', BRAF_dephosphorylation_S447_base_kcat*INPUT_BRAF_dephosphorylation_S447_base_kcat) Expression('MAP2K1_dephosphorylation_S222_base_rate', INPUT_MAP2K1_dephosphorylation_S222_base_kcat*MAP2K1_dephosphorylation_S222_base_kcat) Expression('MAP2K1_dephosphorylation_S218_base_rate', INPUT_MAP2K1_dephosphorylation_S218_base_kcat*MAP2K1_dephosphorylation_S218_base_kcat) Expression('MAP2K2_dephosphorylation_S222_base_rate', INPUT_MAP2K2_dephosphorylation_S222_base_kcat*MAP2K2_dephosphorylation_S222_base_kcat) Expression('MAP2K2_dephosphorylation_S226_base_rate', INPUT_MAP2K2_dephosphorylation_S226_base_kcat*MAP2K2_dephosphorylation_S226_base_kcat) Expression('MAPK1_dephosphorylation_T185_base_rate', INPUT_MAPK1_dephosphorylation_T185_base_kcat*MAPK1_dephosphorylation_T185_base_kcat) Expression('MAPK1_dephosphorylation_Y187_base_rate', INPUT_MAPK1_dephosphorylation_Y187_base_kcat*MAPK1_dephosphorylation_Y187_base_kcat) Expression('MAPK3_dephosphorylation_Y204_base_rate', INPUT_MAPK3_dephosphorylation_Y204_base_kcat*MAPK3_dephosphorylation_Y204_base_kcat) Expression('MAPK3_dephosphorylation_T202_base_rate', INPUT_MAPK3_dephosphorylation_T202_base_kcat*MAPK3_dephosphorylation_T202_base_kcat) Observable('FL_obs', FL(inh=None))
Parameter('EGF_eq', 100.0) Parameter('INPUT_EGF_eq', 0.0) Parameter('EGF_0', 0.0) Parameter('EGF_EGF_koff', 0.1) Parameter('EGF_EGF_kd', 1.0) Parameter('ERBB2_degradation_kdeg', 1.0) Parameter('ERBB2_eq', 100.0) Parameter('INPUT_ERBB2_eq', 0.0) Parameter('ERBB2_phosphorylation_Y1248_base_kcat', 1.0) Parameter('ERBB2_dephosphorylation_Y1248_base_kcat', 1.0) Parameter('INPUT_ERBB2_phosphorylation_Y1248_base_kcat', 0.0) Parameter('INPUT_ERBB2_dephosphorylation_Y1248_base_kcat', 0.0) Parameter('ERBB2_phosphorylation_Y1248_EGF_kcat', 1.0) Parameter('INPUT_ERBB2_phosphorylation_Y1248_EGF_kcat', 0.0) Expression('EGF_synthesis_ksyn', EGF_degradation_kdeg*EGF_eq) Expression('EGF_synthesis_rate', EGF_synthesis_ksyn*INPUT_EGF_eq) Expression('EGF_degradation_rate', EGF_degradation_kdeg) Expression('EGF_ss', EGF_synthesis_rate/EGF_degradation_rate) Expression('EGF_EGF_kon', EGF_EGF_kd*EGF_EGF_koff) Expression('ERBB2_synthesis_ksyn', ERBB2_degradation_kdeg*ERBB2_eq) Expression('ERBB2_synthesis_rate', ERBB2_synthesis_ksyn*INPUT_ERBB2_eq) Expression('ERBB2_degradation_rate', ERBB2_degradation_kdeg) Expression('ERBB2_ss', ERBB2_synthesis_rate/ERBB2_degradation_rate) Expression('ERBB2_phosphorylation_Y1248_base_rate', ERBB2_phosphorylation_Y1248_base_kcat*INPUT_ERBB2_phosphorylation_Y1248_base_kcat) Expression('ERBB2_dephosphorylation_Y1248_base_rate', ERBB2_dephosphorylation_Y1248_base_kcat*INPUT_ERBB2_dephosphorylation_Y1248_base_kcat) Observable('EGF_obs', EGF(inh=None)) Observable('tEGF', EGF()) Observable('tEGF_ext', EGF_ext()) Observable('tERBB2', ERBB2())
Parameter('pMAPK3_Y204_scale', 1.0) Parameter('pMAPK3_Y204_offset', 1.0) Parameter('pAKT1_T308_scale', 1.0) Parameter('pAKT1_T308_offset', 1.0) Parameter('pAKT1_S473_scale', 1.0) Parameter('pAKT1_S473_offset', 1.0) Parameter('pAKT2_T308_scale', 1.0) Parameter('pAKT2_T308_offset', 1.0) Parameter('pAKT2_S473_scale', 1.0) Parameter('pAKT2_S473_offset', 1.0) Parameter('pAKT3_T308_scale', 1.0) Parameter('pAKT3_T308_offset', 1.0) Parameter('pAKT3_S473_scale', 1.0) Parameter('pAKT3_S473_offset', 1.0) Expression('FL_synthesis_ksyn', FL_degradation_kdeg * FL_eq) Expression('FL_synthesis_rate', FL_synthesis_ksyn * INPUT_FL_eq) Expression('FL_degradation_rate', FL_degradation_kdeg) Expression('FLT3_synthesis_ksyn', FLT3_degradation_kdeg * FLT3_eq) Expression('FLT3_synthesis_rate', FLT3_synthesis_ksyn * INPUT_FLT3_eq) Expression('FLT3_degradation_rate', FLT3_degradation_kdeg) Expression( 'FLT3_phosphorylation_Y843_base_rate', FLT3_phosphorylation_Y843_base_kcat * INPUT_FLT3_phosphorylation_Y843_base_kcat) Expression( 'FLT3_dephosphorylation_Y843_base_rate', FLT3_dephosphorylation_Y843_base_kcat * INPUT_FLT3_dephosphorylation_Y843_base_kcat) Expression('STAT1_synthesis_ksyn', STAT1_degradation_kdeg * STAT1_eq) Expression('STAT1_synthesis_rate', STAT1_synthesis_ksyn * INPUT_STAT1_eq)
def add_monomer_synth_deg( m_name: str, psites: Optional[Iterable[str]] = None, nsites: Optional[Iterable[str]] = None, asites: Optional[Iterable[str]] = None, ): """ Adds the respective monomer plus synthesis rules and basal activation/deactivation rules for all activateable sites :param m_name: monomer name :param psites: phospho sites :param nsites: nucleotide sites :param asites: other activity encoding sites """ if psites is None: psites = [] else: psites = [site for psite in psites for site in psite.split('_')] if nsites is None: nsites = [] if asites is None: asites = [] sites = psites + nsites + asites m = Monomer( m_name, sites=[psite for psite in sites], site_states={ site: ['u', 'p'] if site in psites else ['gdp', 'gtp'] if site in nsites else ['inactive', 'active'] for site in sites }) kdeg = Parameter(f'{m_name}_degradation_kdeg', 1.0) t = Parameter(f'{m_name}_eq', 100.0) ksyn = Expression(f'{m_name}_synthesis_ksyn', t * kdeg) syn_rate = Expression(f'{m_name}_synthesis_rate', ksyn * get_autoencoder_modulator(t)) Rule( f'synthesis_{m_name}', None >> m( **{ site: 'u' if site in psites else 'gdp' if site in nsites else 'inactive' for site in sites }), syn_rate) deg_rate = Expression(f'{m_name}_degradation_rate', kdeg) Rule(f'degradation_{m_name}', m() >> None, deg_rate) # basal activation for sites, labels, fstate, rstate in zip( [psites, nsites, asites], [('phosphorylation', 'dephosphorylation'), ('gtp_exchange', 'gdp_exchange'), ('activation', 'deactivation')], ['p', 'gtp', 'active'], ['u', 'gdp', 'indactive']): for site in sites: kcats = [ Parameter(f'{m_name}_{label}_{site}_base_kcat', 1.0) for label in labels ] rates = [ Expression(f'{m_name}_{label}_{site}_base_rate', kcat * get_autoencoder_modulator(kcat)) for kcat, label in zip(kcats, labels) ] Rule(F'{m_name}_{site}_base', m(**{site: fstate}) | m(**{site: rstate}), *rates) return m
Parameter('Vm_f6', 0.18) Parameter('Vm_f5', 0.22) Parameter('k_f16', 0.01) Parameter('k_f17', 0.014) Parameter('kex_f7', 0.61) Parameter('kin_f7', 0.046) Parameter('kex_f10', 0.54) Parameter('kin_f10', 0.04) Parameter('kex_f9', 0.018) Parameter('kin_f9', 0.0086) Parameter('kex_f8', 0.26) Parameter('kin_f8', 0.035) Parameter('kex_f11', 0.013) Parameter('kin_f11', 0.007) Expression('Vext', 9.4e-13 * f) Expression('Vcyt', 9.4e-13 * f) Expression('Vnuc', 2.2e-13 * f) Expression('Egf_0', 6.8e-7 * Vext * NA) Expression('Egfr_0', 1.0e-7 * Vcyt * NA) Expression('PLCg_0', 1.05e-7 * Vcyt * NA) Expression('Shc_0', 1.5e-7 * Vcyt * NA) Expression('Grb2_0', 8.5e-8 * Vcyt * NA) Expression('Sos_0', 3.4e-8 * Vcyt * NA) Expression('kp1', 3000000.0 * Vext**(-1) * NA**(-1)) Expression('kp2', 10000000.0 * Vcyt**(-1) * NA**(-1)) Expression('kp5', 30000000.0 * Vcyt**(-1) * NA**(-1)) Expression('kp7', 3000000.0 * Vcyt**(-1) * NA**(-1)) Expression('kp9', 1500000.0 * Vcyt**(-1) * NA**(-1)) Expression('kp10', 10000000.0 * Vcyt**(-1) * NA**(-1)) Expression('kp11', 2250000.0 * Vcyt**(-1) * NA**(-1))
Parameter('bind_DUSP_ERKphosphop_kf', 10.0) Parameter('bind_DUSP_ERKphosphop_kD', 0.01) Parameter('catalyze_DUSP_ERK_u_kcatr', 1.0) Parameter('BRAF_0', 0.0) Parameter('CRAF_0', 0.0) Parameter('RAS_0', 0.0) Parameter('MEK_0', 0.0) Parameter('ERK_0', 0.0) Parameter('GRB2_0', 0.0) Parameter('SOS1_0', 0.0) Parameter('pMEK_IF_scale', 1.0) Parameter('pMEK_IF_offset', 0.1) Parameter('pERK_IF_scale', 1.0) Parameter('pERK_IF_offset', 0.1) Expression('N_Avogadro', 6.02214076000000e+23) Expression('volume', 1.00000000000000e-12) Expression('m_Da_EGF', 6200.00000000000) Expression('initRAFi', RAFi_0) Expression('initMEKi', MEKi_0) Expression('initEGF', 6.02214085854916e+23 * EGF_0 * (m_Da_EGF * N_Avogadro)**(-1)) Expression('bind_EGF_EGFR_kr', bind_EGF_EGFR_kD * bind_EGF_EGFR_kf) Expression('Gf_bind_EGF_EGFR', log(bind_EGF_EGFR_kD)) Expression('Ea0_bind_EGF_EGFR', -bind_EGF_EGFR_phi * log(bind_EGF_EGFR_kD) - log(bind_EGF_EGFR_kf)) Expression('bind_EGFR_EGFR_kr', bind_EGFR_EGFR_kD * bind_EGFR_EGFR_kf) Expression('Gf_bind_EGFR_EGFR', log(bind_EGFR_EGFR_kD)) Expression( 'Ea0_bind_EGFR_EGFR', -bind_EGFR_EGFR_phi * log(bind_EGFR_EGFR_kD) - log(bind_EGFR_EGFR_kf))
from model_cell_cycle_no_M import model from sympy import log from pysb import Expression, Model model = Model('cell_cycle_no_M_ridge', base=model) for par in model.parameters: if par.name.startswith('r'): Expression(f'{par.name}_obs', log(par))
def energyrule(name, pattern, phi, deltag): if not isinstance(phi, (Parameter, Expression)): phi = Expression('expr_%s_phi' % name, phi) if not isinstance(deltag, (Parameter, Expression)): deltag = Expression('expr_%s_deltag' % name, deltag) return Rule(name, pattern, phi, deltag, energy=True)
Parameter('pMAP2K1_S222_scale', 1.0) Parameter('pMAP2K1_S222_offset', 1.0) Parameter('pMAP2K2_S222_scale', 1.0) Parameter('pMAP2K2_S222_offset', 1.0) Parameter('pMAP2K2_S226_scale', 1.0) Parameter('pMAP2K2_S226_offset', 1.0) Parameter('pMAPK1_T185_scale', 1.0) Parameter('pMAPK1_T185_offset', 1.0) Parameter('pMAPK1_Y187_scale', 1.0) Parameter('pMAPK1_Y187_offset', 1.0) Parameter('pMAPK3_T202_scale', 1.0) Parameter('pMAPK3_T202_offset', 1.0) Parameter('pMAPK3_Y204_scale', 1.0) Parameter('pMAPK3_Y204_offset', 1.0) Expression('FL_synthesis_ksyn', FL_degradation_kdeg * FL_eq) Expression('FL_synthesis_rate', FL_synthesis_ksyn * INPUT_FL_eq) Expression('FL_degradation_rate', FL_degradation_kdeg) Expression('FLT3_synthesis_ksyn', FLT3_degradation_kdeg * FLT3_eq) Expression('FLT3_synthesis_rate', FLT3_synthesis_ksyn * INPUT_FLT3_eq) Expression('FLT3_degradation_rate', FLT3_degradation_kdeg) Expression( 'FLT3_phosphorylation_Y843_base_rate', FLT3_phosphorylation_Y843_base_kcat * INPUT_FLT3_phosphorylation_Y843_base_kcat) Expression( 'FLT3_dephosphorylation_Y843_base_rate', FLT3_dephosphorylation_Y843_base_kcat * INPUT_FLT3_dephosphorylation_Y843_base_kcat) Expression('HRAS_synthesis_ksyn', HRAS_degradation_kdeg * HRAS_eq) Expression('HRAS_synthesis_rate', HRAS_synthesis_ksyn * INPUT_HRAS_eq)
Observable('Atot', A()) Observable('Btot', B()) Observable('Ctot', C()) Observable('AB0', A(b=MultiState(None, None, None)), match='species') Observable('AB1', A(b=MultiState(1, None, None)) % B(a=1), match='species') Observable('AB2', A(b=MultiState(1, 2, None)) % B(a=1) % B(a=2), match='species') Observable('AB3', A(b=MultiState(1, 2, 3)) % B(a=1) % B(a=2) % B(a=3), match='species') Observable('AB_motif', A(b=1) % B(a=1)) Tag('x') Expression('f_synth', k_synthC * AB_motif(x)**2) # A synthesizes C with rate dependent on bound B Rule('_R1', A() @ x >> A() @ x + C(), f_synth) # A binds B Rule('_R2', A(b=None) + B(a=None) | A(b=1) % B(a=1), kp, km) # degradation of C Rule('_R3', C() >> None, k_degrC) Initial(A(b=MultiState(None, None, None)), Ab_b_b_0) Initial(B(a=None), Ba_0) Initial(C(), C_0)
model = Model('cell_cycle_no_M') C = Monomer('live_cell', sites=['cycle'], site_states={'cycle': ['G1', 'G2', 'S']}) D = Monomer('dead_cell') Observable('G1_obs', C(cycle='G1')) Observable('S_obs', C(cycle='S')) Observable('G2_plus_M_obs', C(cycle='G2')) Observable('D_obs', D()) Rule('G1_S', C(cycle='G1') >> C(cycle='S'), Expression('rateG1S', Parameter('kG1S', 0.1) * Parameter('rG1S', 0.1))) Rule('S_G2', C(cycle='S') >> C(cycle='G2'), Expression('rateSG2', Parameter('kSG2', 0.1) * Parameter('rSG2', 0.1))) Rule( 'G2_M_G1', C(cycle='G2') >> C(cycle='G1') + C(cycle='G1'), Expression('rateG2MG1', Parameter('kG2MG1', 0.1) * Parameter('rG2MG1', 0.1))) Rule('death', C() >> D(), Expression('ratedeath',