当前位置: 首页>>代码示例>>Python>>正文


Python bng.generate_equations函数代码示例

本文整理汇总了Python中pysb.bng.generate_equations函数的典型用法代码示例。如果您正苦于以下问题:Python generate_equations函数的具体用法?Python generate_equations怎么用?Python generate_equations使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了generate_equations函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parameter_sweep

def parameter_sweep(model, sigma, ns):
    generate_equations(model)
    logp = [numpy.log10(p.value) for p in model.parameters]
    ts = numpy.linspace(0, 20*3600, 20*60)
    solver = Solver(model, ts)
    pf.set_fig_params()
    plt.figure(figsize=(1.8, 1), dpi=300)
    for i in range(ns):
        psample = sample_params(logp, 0.05)
        res = solver.run(param_values=psample)
        signal = res.observables['p53_active']
        plt.plot(signal, color=(0.7, 0.7, 0.7), alpha=0.3)
    # Highlighted
    colors = ['g', 'y', 'c']
    for c in colors:
        psample = sample_params(logp, 0.05)
        res = solver.run(param_values=psample)
        signal = res.observables['p53_active']
        plt.plot(signal, c)

    # Nominal
    solver = Solver(model, ts)
    res = solver.run()
    signal = res.observables['p53_active']
    plt.plot(signal, 'r')

    plt.xticks([])
    plt.xlabel('Time (a.u.)', fontsize=7)
    plt.ylabel('Active p53', fontsize=7)
    plt.yticks([])
    plt.ylim(ymin=0)
    pf.format_axis(plt.gca())
    plt.savefig(model.name + '_sample.pdf')
开发者ID:johnbachman,项目名称:indra,代码行数:33,代码来源:param_analysis.py

示例2: __init__

    def __init__(self, solver, values_to_sample, objective_function,
                 observable):
        self._model = solver.model
        self._logger = get_logger(__name__, model=self._model)
        self._logger.info('%s created for observable %s' % (
            self.__class__.__name__, observable))
        generate_equations(self._model)
        self._ic_params_of_interest_cache = None
        self._values_to_sample = values_to_sample
        if solver is None or not isinstance(solver,
                                            pysb.simulator.base.Simulator):
            raise(TypeError, "solver must be a pysb.simulator object")
        self._solver = solver
        self.objective_function = objective_function
        self.observable = observable

        # Outputs
        self.b_matrix = []
        self.b_prime_matrix = []
        self.p_prime_matrix = np.zeros(self._size_of_matrix)
        self.p_matrix = np.zeros(self._size_of_matrix)

        self._original_initial_conditions = np.zeros(len(self._model.species))
        self._index_of_species_of_interest = self._create_index_of_species()
        self.simulation_initials = self._setup_simulations()
        # Stores the objective function value for the original unperturbed
        # model
        self._objective_fn_standard = None
开发者ID:alubbock,项目名称:pysb,代码行数:28,代码来源:sensitivity_analysis.py

示例3: test_simres_observable

def test_simres_observable():
    """ Test on demand observable evaluation """
    models = [tyson_oscillator.model, robertson.model,
              expression_observables.model, earm_1_3.model,
              bax_pore_sequential.model, bax_pore.model,
              bngwiki_egfr_simple.model]
    for model in models:
        generate_equations(model)
        spm = SpeciesPatternMatcher(model)
        for obs in model.observables:
            dyn_obs = spm.match(pattern=obs.reaction_pattern, index=True,
                                counts=True)

            # Need to sort by species numerical order for comparison purposes
            dyn_obs = collections.OrderedDict(sorted(dyn_obs.items()))

            dyn_species = list(dyn_obs.keys())

            if obs.match == 'species':
                dyn_coeffs = [1] * len(dyn_obs)
            else:
                dyn_coeffs = list(dyn_obs.values())

            assert dyn_species == obs.species
            assert dyn_coeffs == obs.coefficients
开发者ID:LoLab-VU,项目名称:pysb,代码行数:25,代码来源:test_simulationresult.py

示例4: __init__

    def __init__(self, model, inputs=None, stop_time=1000,
                 outside_name_map=None):
        self.model = model
        generate_equations(model)

        self.inputs = inputs if inputs else []
        self.stop_time = stop_time
        self.outside_name_map = outside_name_map if outside_name_map else {}

        self.dt = numpy.array(10.0)
        self.units = 'seconds'
        self.sim = None
        self.attributes = copy.copy(default_attributes)
        self.species_name_map = {}
        for idx, species in enumerate(self.model.species):
            monomer = species.monomer_patterns[0].monomer
            self.species_name_map[monomer.name] = idx
        self.input_vars = self._get_input_vars()
        # These attributes are related to the simulation state
        self.state = numpy.array([100.0 for s in self.species_name_map.keys()])
        self.time = numpy.array(0.0)
        self.status = 'start'
        self.time_course = [(self.time, self.state)]
        # EMELI needs a DONE attribute
        self.DONE = False
开发者ID:johnbachman,项目名称:indra,代码行数:25,代码来源:bmi_wrapper.py

示例5: stoichiometry_matrix

def stoichiometry_matrix(model):
    generate_equations(model)
    sm = np.zeros((len(model.species), len(model.reactions)))
    for i_s, sp in enumerate(model.species):
        for i_r, r in enumerate(model.reactions):
            sm[i_s][i_r] = r['products'].count(i_s) - r['reactants'].count(i_s)
    return sm
开发者ID:LoLab-VU,项目名称:tropical,代码行数:7,代码来源:stoichiometry_conservation_laws.py

示例6: setUp

    def setUp(self):
        Monomer('A', ['a'])
        Monomer('B', ['b'])

        Parameter('ksynthA', 100)
        Parameter('ksynthB', 100)
        Parameter('kbindAB', 100)

        Parameter('A_init', 0)
        Parameter('B_init', 0)

        Initial(A(a=None), A_init)
        Initial(B(b=None), B_init)

        Observable("A_free", A(a=None))
        Observable("B_free", B(b=None))
        Observable("AB_complex", A(a=1) % B(b=1))

        Rule('A_synth', None >> A(a=None), ksynthA)
        Rule('B_synth', None >> B(b=None), ksynthB)
        Rule('AB_bind', A(a=None) + B(b=None) >> A(a=1) % B(b=1), kbindAB)

        self.model = model
        generate_equations(self.model)

        # Convenience shortcut for accessing model monomer objects
        self.mon = lambda m: self.model.monomers[m]

        # This timespan is chosen to be enough to trigger a Jacobian evaluation
        # on the various solvers.
        self.time = np.linspace(0, 1)
        self.sim = BngSimulator(self.model, tspan=self.time)
开发者ID:alubbock,项目名称:pysb,代码行数:32,代码来源:test_simulator_bng.py

示例7: stoichimetry_matrix_passengers

def stoichimetry_matrix_passengers(model, pruned_system):
    generate_equations(model)
    sm = np.zeros((len(pruned_system.keys()), len(model.reactions)))
    for i_s, pa in enumerate(pruned_system.keys()):
        for i_r, r in enumerate(model.reactions):
            if r['rate'] in pruned_system[pa].as_coefficients_dict().keys():
                sm[i_s][i_r] = r['products'].count(pa) - r['reactants'].count(pa)
    return sm
开发者ID:LoLab-VU,项目名称:tropical,代码行数:8,代码来源:stoichiometry_conservation_laws.py

示例8: test_non_python_name_phos

def test_non_python_name_phos():
    st = Phosphorylation(Agent('14-3-3'), Agent('BRAF kinase'))
    pa = PysbAssembler([st])
    pa.make_model()
    names = [m.name for m in pa.model.monomers]
    assert 'BRAF_kinase' in names
    assert 'p14_3_3' in names
    bng.generate_equations(pa.model)
开发者ID:johnbachman,项目名称:indra,代码行数:8,代码来源:test_pysb_assembler.py

示例9: create_model_files

def create_model_files(model, model_name, directory=None):
    curr_dir = os.getcwd()
    if not model.odes:
        generate_equations(model)
    
    if directory != None:
        os.chdir(directory)
    
    file_basename = model_name+'_model'
    dill.dump(model, open(file_basename+'.p', 'wb'))
    
    os.chdir(curr_dir)
开发者ID:LoLab-VU,项目名称:NightMare,代码行数:12,代码来源:helper_fxns.py

示例10: build_all_models

def build_all_models():
    mek_seq_rand = ['seq', 'random']
    mkp_seq_rand = ['seq', 'random']
    erk_dimerization = [False, 'any', 'uT', 'phos']
    mkp_activation = [False, True]

    model_combinations = itertools.product(*(mek_seq_rand, mkp_seq_rand,
                                             erk_dimerization, mkp_activation))

    models = {}
    for mc in model_combinations:
        model = build_model(*mc)
        generate_equations(model)
        models[model.name] = model
    return models
开发者ID:bgyori,项目名称:erk_invitro,代码行数:15,代码来源:build_mapk_models.py

示例11: __init__

    def __init__(self, solver, values_to_sample, objective_function,
                 observable, sens_type='initials', sample_list=None):
        if not isinstance(solver, pysb.simulator.base.Simulator):
            raise TypeError("solver must be a pysb.simulator object")
        self._model = solver.model
        self._logger = get_logger(__name__, model=self._model)
        self._logger.info('%s created for observable %s' % (
            self.__class__.__name__, observable))
        generate_equations(self._model)
        self._values_to_sample = values_to_sample
        self._solver = solver
        self.objective_function = objective_function
        self._observable = observable
        self._sens_type = sens_type
        if self._sens_type not in ('params', 'initials', 'all'):
            if sample_list is None:
                raise ValueError("Please provide 'sens_type' or 'sample_list'")
        if sample_list is not None:
            _valid_options = [i.name for i in self._model.parameters]
            for i in sample_list:
                if i not in _valid_options:
                    raise ValueError("{} not in model.parameters".format(i))
            self.index = sample_list
        elif self._sens_type == 'params':
            self.index = [i.name for i in self._model.parameters_rules()]
        elif self._sens_type == 'initials':
            self.index = [i[1].name for i in self._model.initial_conditions]
        elif self._sens_type == 'all':
            self.index = [i.name for i in self._model.parameters]

        self.orig_vals = [i.value for i in self._model.parameters]
        self.index_of_param = {i.name: n for n, i in
                               enumerate(self._model.parameters)}
        self._n_sam = len(self._values_to_sample)
        self._n_species = len(self.index)
        self._nm = self._n_species * self._n_sam
        self._size_of_matrix = self._nm ** 2
        self._shape_of_matrix = self._nm, self._nm

        # Outputs
        self.b_matrix = []
        self.b_prime_matrix = []
        self.params_to_run = self._setup_simulations()
        self.p_prime_matrix = np.zeros(self._size_of_matrix)
        self.p_matrix = np.zeros(self._size_of_matrix)
        # Stores the objective function value for the original unperturbed
        # model
        self._objective_fn_standard = None
开发者ID:LoLab-VU,项目名称:pysb,代码行数:48,代码来源:sensitivity_analysis.py

示例12: print_model_stats

def print_model_stats(model):
    """ provides stats for the models

    :param model:
    """
    generate_equations(model)
    print("Information about model {0}".format(model.name))
    print("Number of rules {0}".format(len(model.rules)))
    print("Number of parameters {0}".format(len(model.parameters)))
    print(
    "Number of parameter rules {0}".format(len(model.parameters_rules())))
    print("Number of reactions {0}".format(len(model.reactions)))
    print(
    "Number of initial conditions {0}".format(len(model.initial_conditions)))
    print("Number of species {0}".format(len(model.species)))
    print('{}'.format('-' * 24))
开发者ID:LoLab-VU,项目名称:PySB_cupSODA_Bioinfo2016,代码行数:16,代码来源:plot_observables_all_models.py

示例13: __init__

 def __init__(self, model, tspan=None, initials=None,
              param_values=None, verbose=False, **kwargs):
     super(StochKitSimulator, self).__init__(model,
                                             tspan=tspan,
                                             initials=initials,
                                             param_values=param_values,
                                             verbose=verbose,
                                             **kwargs)
     self.cleanup = kwargs.pop('cleanup', True)
     if kwargs:
         raise ValueError('Unknown keyword argument(s): {}'.format(
             ', '.join(kwargs.keys())
         ))
     self._outdir = None
     generate_equations(self._model,
                        cleanup=self.cleanup,
                        verbose=self.verbose)
开发者ID:alubbock,项目名称:pysb,代码行数:17,代码来源:stochkit.py

示例14: convert_odes

def convert_odes(model, p_name_map, s_name_map_by_pattern):
    """Substitutes species and parameter names using the given name mappings.

    Parameters
    ----------
    model : pysb.core.Model
        The model to be converted.
    p_name_map : dict
        A dict where the keys are the parameter names of the PySB model and the
        values are the parameter names of the original model, e.g.
        {'bind_BidT_Bcl2_kf': 'ka_tBid_Bcl2'}
    s_name_map : dict
        A dict where the keys are the string representations of the species
        from the PySB model, generated by calling str(species), and the values
        are the species names in the original model, e.g.
        {'Bid(bf=None, state=T)': 'Act'}

    Returns
    -------
    A list of strings, with one entry for each ODE in the model. Each ODE
    is represented as a string, e.g. "d[Act]/dt = ..."
    """

    generate_equations(model)

    # Get the index of each species
    s_name_map_by_num = {}
    for i, s in enumerate(model.species):
        for key in s_name_map_by_pattern:
            if key == str(s):
                s_name_map_by_num['s%d' % i] = s_name_map_by_pattern[key]

    name_map = {}
    name_map.update(p_name_map)
    name_map.update(s_name_map_by_num)

    # Substitute new names into the ODEs
    ode_list = {} 
    for i, ode in enumerate(model.odes):
        new_ode = ode.subs(name_map)
        ode_species = s_name_map_by_pattern[str(model.species[i])]
        ode_list[ode_species] = str(new_ode)
        #new_ode = 'd[%s]/dt = %s' % (s_name_map_by_num['s%d' % i], str(new_ode))
        #ode_list.append(new_ode)

    return ode_list
开发者ID:rouxery,项目名称:earm,代码行数:46,代码来源:test_shen_models.py

示例15: run_one_model

def run_one_model(model, data, prior_vals, ns, pool=None):
    # Vector of estimated parameters
    pe = [p for p in model.parameters if p.name.startswith('k')]

    # Generate model equations
    generate_equations(model)
    Solver._use_inline = True
    sol = Solver(model, numpy.linspace(0,10,10))
    sol.run()

    # Number of temperatures, dimensions and walkers
    ntemps = 20
    ndim = len(pe)
    blocksize = 48
    nwalkers = get_num_walkers(ndim, blocksize)
    print 'Running %d walkers at %d temperatures for %d steps.' %\
          (nwalkers, ntemps, ns)

    sampler = emcee.PTSampler(ntemps, nwalkers, ndim, likelihood, prior,
         threads=1, pool=pool, betas=None, a=2.0, Tmax=None,
         loglargs=[model, data], logpargs=[model, prior_vals],
         loglkwargs={}, logpkwargs={})

    # Random initial parameters for walkers
    p0 = numpy.ones((ntemps, nwalkers, ndim))
    for i in range(ntemps):
        for j in range(nwalkers):
            for k, pp in enumerate(pe):
                p0[i, j, k] = prior_vals.vals[j][pp.name]
    print p0
    # Run sampler
    fname = scratch_path + 'chain_%s.dat' % model.name
    step = 0
    for result in sampler.sample(p0, iterations=ns, storechain=True):
        print '---'
        position = result[0]
        with open(fname, 'a') as fh:
            for w in range(nwalkers):
                for t in range(ntemps):
                    pos_str = '\t'.join(['%f' % p for p in position[t][w]])
                    fh.write('%d\t%d\t%d\t%s\n' % (step, w, t, pos_str))
        step += 1
    return sampler
开发者ID:bgyori,项目名称:erk_invitro,代码行数:43,代码来源:run_mapk_mcmc.py


注:本文中的pysb.bng.generate_equations函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。