Ejemplo n.º 1
0
def dfs(model, up_to_cee=False):
    '''
    Performs a depth-first search in a space of equivalent models given by
    syntactic operations. Two models are considered equivalent if they
    generate the same reaction network.
    Returns a model that cannot be further simplified by syntactic operations.

    Parameters
    ----------
    model : pysb.Model
        Initial model.
    up_to_cee : bool
        If True, then it performes only bidirectional merging and context
        enumeration elimination.
    '''
    # fast, finds one fix point
    sort_key = get_rule_sort_key(model)
    rn1 = parse_reaction_network(bng.generate_network(model))
    node = model
    while node:
        m1 = node
        node = None
        for edge, m2 in search_model(m1, sort_key=sort_key,
                                     up_to_cee=up_to_cee):
            rn2 = parse_reaction_network(bng.generate_network(m2))
            if rn1 == rn2:
                print edge
                node = m2
                break
    return m1
Ejemplo n.º 2
0
def check_generate_network(model):
    """Tests that network generation runs without error for the given model"""
    success = False
    try:
        generate_network(model)
        success = True
    except:
        pass
    assert success, "Network generation failed on model %s:\n-----\n%s" % \
                (model.name, traceback.format_exc())
Ejemplo n.º 3
0
def check_generate_network(model):
    """Tests that network generation occurs without error for the given
    model."""

    success = False

    try:
        generate_network(model)
        success = True
    except:
        pass

    assert success, "Network generation failed on model %s:\n-----\n%s" % \
                (model.name, traceback.format_exc())
Ejemplo n.º 4
0
def check_generate_network(model):
    """Tests that network generation runs without error for the given model"""
    success = False
    try:
        generate_network(model)
        success = True
    except Exception as e:
        # Some example models are deliberately incomplete, so here we will treat
        # any of these "expected" exceptions as a success.
        model_base_name = model.name.rsplit('.', 1)[1]
        exception_class = expected_exceptions.get(model_base_name)
        if exception_class and isinstance(e, exception_class):
            success = True
    assert success, "Network generation failed on model %s:\n-----\n%s" % \
                (model.name, traceback.format_exc())
Ejemplo n.º 5
0
def check_generate_network(model):
    """Tests that network generation runs without error for the given model"""
    success = False
    try:
        generate_network(model)
        success = True
    except Exception as e:
        # Some example models are deliberately incomplete, so here we will treat
        # any of these "expected" exceptions as a success.
        model_base_name = model.name.rsplit('.', 1)[1]
        exception_classes = expected_exceptions.get(model_base_name)
        if exception_classes and isinstance(e, exception_classes):
            success = True
    assert success, "Network generation failed on model %s:\n-----\n%s" % \
                (model.name, traceback.format_exc())
Ejemplo n.º 6
0
def reaction_network(m):
    '''
    Call BNG to construct the reaction network of the model.
    The resulting network is then parsed.

    Parameters
    ----------
    m : pysb.Model
        Model from which the reaction net is to be constructed.
    '''
    return parse_reaction_network(bng.generate_network(m))
Ejemplo n.º 7
0
    def export(self):
        """Generate the BNGL NET file for the PySB model associated with
        the exporter. A wrapper around :py:func:`pysb.bng.generate_network`.

        Returns
        -------
        string
            The NET file output for the model, generated by BNG.
        """
        net_str = ''
        if self.docstring:
            net_str += '# ' + self.docstring.replace('\n', '\n# ') + '\n'
        net_str += generate_network(self.model, append_stdout=True)
        return net_str
Ejemplo n.º 8
0
 def test_generate_network(self):
     generate_network(m8a.model)
Ejemplo n.º 9
0
from pysb.macros import *
from pysb import *
from pysb.bng import generate_network

Model()

Monomer('subunit', ['s1', 's2'])

assemble_pore_sequential(subunit, 's1', 's2', 4, [[1, 1], [1, 1], [1, 1]])

Initial(subunit(s1=None, s2=None), Parameter('subunit_0', 1))

Observable('sub', subunit())

generate_network(model)
Ejemplo n.º 10
0
def run(model):
    return generate_network(model, append_stdout=True)
Ejemplo n.º 11
0

Model()

Monomer('C8', ['bf'])
Monomer('Bid', ['bf', 'state'], {'state': ['U', 'T']})

klist = [Parameter('kf', 1), Parameter('kr', 1), Parameter('kc', 1)]

Initial(C8(bf=None), Parameter('C8_0', 100))
Initial(Bid(bf=None, state='U'), Parameter('Bid_0', 100))

# This is the code shown for "Example Macro Call" (not printed here)
catalyze(C8, 'bf', Bid(state='U'), 'bf', Bid(state='T'), klist)

bng_code = generate_network(model)
# Merge continued lines
bng_code = bng_code.replace('\\\n', '')
generate_equations(model)

num_rules = len(model.rules)
num_odes = len(model.odes)

print("BNGL Rules")
print("==========")
for line in bng_code.split("\n"):
    for rule in model.rules:
        match = re.match(r'^\s*%s:\s*(.*)' % rule.name, line)
        if match:
            print(match.group(1))
print()
Ejemplo n.º 12
0
Archivo: fig2a.py Proyecto: Talqa/pysb

Model()

Monomer("C8", ["bf"])
Monomer("Bid", ["bf", "state"], {"state": ["U", "T"]})

klist = [Parameter("kf", 1), Parameter("kr", 1), Parameter("kc", 1)]

Initial(C8(bf=None), Parameter("C8_0", 100))
Initial(Bid(bf=None, state="U"), Parameter("Bid_0", 100))

# This is the code shown for "Example Macro Call" (not printed here)
catalyze(C8, "bf", Bid(state="U"), "bf", Bid(state="T"), klist)

bng_code = generate_network(model)
# Merge continued lines
bng_code = bng_code.replace("\\\n", "")
generate_equations(model)

num_rules = len(model.rules)
num_odes = len(model.odes)

print "BNGL Rules"
print "=========="
for line in bng_code.split("\n"):
    for rule in model.rules:
        match = re.match(r"^\s*%s:\s*(.*)" % rule.name, line)
        if match:
            print match.group(1)
print
from pysb import *
from pysb.macros import catalyze_one_step
from pysb.bng import generate_network, generate_equations

Model()

Monomer("C8", ["bf"])
Monomer("Bid", ["bf", "state"], {"state": ["U", "T"]})

kf = Parameter("kf", 1)

catalyze_one_step(C8(bf=None), Bid(state="U", bf=None), Bid(state="T", bf=None), kf)

Initial(C8(bf=None), Parameter("C8_0", 100))
Initial(Bid(bf=None, state="U"), Parameter("Bid_0", 100))

print(generate_network(model))
generate_equations(model)

print(zip(model.species, model.odes))
    # Degrade the activated Apaf1 caspase 9 complex
    Rule('degrade_Apaf1_C9c_XIAP', Apaf1(bC9=1) % C9(bXIAP=2, bApaf1=1, m='c') % XIAP(bC9C3=2) >> None, degrade_Apaf1_C9c_XIAP_kd)
    # Degrade the activated Apaf1 caspase 9 XIAP complex


# ______________________________________________________________________________________________________________________________________________________________________________________________#


"""Set the observables and Setup a Simulation"""
Observable('ObsC3c', C3(bXIAP=None, m='c'))
Observable('Apaf1_obs', Apaf1(bC9=None))




generate_network(model)
generate_equations(model)
print(model.species)
for i,sp in enumerate(list(model.species)):
    print i,":",sp

# for i,ode in enumerate(list(model.odes)):
#     print i, ":", ode

#Dictionary to substitute in species names
species_dict = {0 : 'Apaf1',
                1 : 'C9p',
                2 : 'XIAP',
                3 : 'C3p',
                4 : 'Apaf1-C9p',
                5 : 'C9p-XIAP',