コード例 #1
0
ファイル: tools.py プロジェクト: jniznan/rbm-photosynthesis
def copy_no_rules(model):
    '''
    Copies a model without rules.

    Parameters
    ----------
    model : pysb.Model
        Model to copy.
    '''
    m = Model(_export=False)
    for comp in model.all_components():
        if comp.__class__ is not Rule:
            m.add_component(comp)
    for ini in model.initial_conditions:
        m.initial(*ini)
    return m
コード例 #2
0
def build_model(mek_seq_rand, mkp_seq_rand, erk_dimerization, mkp_activation):
    Model()
    mapk_model.mapk_monomers()
    if mek_seq_rand == 'seq':
        mapk_model.mek_phos_erk_seq()
    else:
        mapk_model.mek_phos_erk_random()
    if mkp_seq_rand == 'seq':
        mapk_model.mkp_dephos_erk_seq()
    else:
        mapk_model.mkp_dephos_erk_random()
    if erk_dimerization == 'any':
        mapk_model.erk_dimerize_any()
    elif erk_dimerization == 'uT':
        mapk_model.erk_dimerize_uT()
    elif erk_dimerization == 'phos':
        mapk_model.erk_dimerize_phos()
    if erk_dimerization:
        mapk_model.erk_autophos()
    if mkp_activation:
        mapk_model.erk_activate_mkp()

    mapk_model.mapk_initials()
    mapk_model.mapk_observables()
    model.name = 'mek_%s_mkp_%s_erkauto_%s_mkpact_%s' % \
        (mek_seq_rand, mkp_seq_rand, erk_dimerization, mkp_activation)
    return model
コード例 #3
0
def generate_per_sample_pretraining_problems(
        ae: MechanisticAutoEncoder) -> Dict[str, PetabImporterPysb]:
    """
    Creates a pypesto problem that can be used to train the
    mechanistic model individually on every sample

    :param ae:
        Mechanistic autoencoder that will be pretrained

    :returns:
        Dict of pypesto problems. Keys are sample names.
    """
    # construct problem based on petab for pypesto subproblem
    ae.petab_importer.petab_problem.parameter_df['estimate'] = [
        not x.startswith(MODEL_FEATURE_PREFIX)
        and ae.petab_importer.petab_problem.parameter_df['estimate'][x]
        for x in ae.petab_importer.petab_problem.parameter_df.index
    ]
    pp = ae.petab_importer.petab_problem
    pp.parameter_df[petab.LOWER_BOUND] /= 10**ae.par_modulation_scale
    pp.parameter_df[petab.UPPER_BOUND] *= 10**ae.par_modulation_scale
    # create fresh model from scratch since the petab imported one already
    # has the observables added and this might lead to issues.
    clean_model = load_pathway('pw_' + ae.pathway_name)

    samples = [
        c for c in pp.condition_df.index if c in pp.measurement_df[
            petab.PREEQUILIBRATION_CONDITION_ID].unique()
    ]

    return {
        sample: PetabImporterPysb(PysbPetabProblem(
            parameter_df=pp.parameter_df[[
                not name.startswith(MODEL_FEATURE_PREFIX)
                or name.endswith(sample) for name in pp.parameter_df.index
            ]],
            observable_df=pp.observable_df,
            measurement_df=pp.measurement_df[pp.measurement_df[
                petab.PREEQUILIBRATION_CONDITION_ID] == sample],
            condition_df=pp.condition_df[[
                name.startswith(sample) for name in pp.condition_df.index
            ]],
            visualization_df=pd.read_csv(os.path.join(
                'data', f'{ae.data_name}__'
                f'{sample}__visualization.tsv'),
                                         sep='\t'),
            pysb_model=Model(base=clean_model, name=pp.pysb_model.name),
        ),
                                  output_folder=os.path.join(
                                      basedir, 'amici_models',
                                      f'{pp.pysb_model.name}_'
                                      f'{ae.data_name}_petab'))
        for sample in samples
    }
コード例 #4
0
ファイル: pysb_assembler.py プロジェクト: lidiaiprou/indra
 def make_model(self, initial_conditions=True, policies=None):
     model = Model()
     # Keep track of which policies we're using
     self.policies = policies
     self.agent_set = BaseAgentSet()
     # Collect information about the monomers/self.agent_set from the
     # statements
     for stmt in self.statements:
         stmt.monomers(self.agent_set, policies=policies)
     # Add the monomers to the model based on our BaseAgentSet
     for agent_name, agent in self.agent_set.iteritems():
         m = Monomer(agent_name, agent.sites, agent.site_states)
         model.add_component(m)
     # Iterate over the statements to generate rules
     for stmt in self.statements:
         stmt.assemble(model, self.agent_set, policies=policies)
     # Add initial conditions
     if initial_conditions:
         add_default_initial_conditions(model)
     return model
コード例 #5
0
ファイル: pysb_assembler.py プロジェクト: decarlin/indra
 def make_model(self, initial_conditions=True, policies=None):
     model = Model()
     # Keep track of which policies we're using
     self.policies = policies
     self.agent_set = BaseAgentSet()
     # Collect information about the monomers/self.agent_set from the
     # statements
     for stmt in self.statements:
         stmt.monomers(self.agent_set, policies=policies)
     # Add the monomers to the model based on our BaseAgentSet
     for agent_name, agent in self.agent_set.iteritems():
         m = Monomer(agent_name, agent.sites, agent.site_states)
         model.add_component(m)
     # Iterate over the statements to generate rules
     for stmt in self.statements:
         stmt.assemble(model, self.agent_set, policies=policies)
     # Add initial conditions
     if initial_conditions:
         add_default_initial_conditions(model)
     return model
コード例 #6
0
ファイル: pysb_assembler.py プロジェクト: abassobl/indra
 def make_model(self, initial_conditions=True):
     self.model = Model()
     self.agent_set = BaseAgentSet()
     # Collect information about the monomers/self.agent_set from the
     # statements
     self.monomers()
     # Add the monomers to the model based on our BaseAgentSet
     for agent_name, agent in self.agent_set.iteritems():
         m = Monomer(agent_name, agent.sites, agent.site_states)
         self.model.add_component(m)
         for db_name, db_ref in agent.db_refs.iteritems():
             a = get_annotation(m, db_name, db_ref)
             if a is not None:
                 self.model.add_annotation(a)
     # Iterate over the statements to generate rules
     self.assemble()
     # Add initial conditions
     if initial_conditions:
         add_default_initial_conditions(self.model)
     return self.model
コード例 #7
0
def _get_gk_model():
    SelfExporter.do_export = True
    Model()
    Monomer('DUSP6', ['mapk1'])
    Monomer('MAP2K1', ['mapk1'])
    Monomer('MAPK1', ['phospho', 'map2k1', 'dusp6'], {'phospho': ['u', 'p']})

    Parameter('kf_mm_bind_1', 1e-06)
    Parameter('kr_mm_bind_1', 0.001)
    Parameter('kc_mm_phos_1', 0.001)
    Parameter('kf_dm_bind_1', 1e-06)
    Parameter('kr_dm_bind_1', 0.001)
    Parameter('kc_dm_dephos_1', 0.001)
    Parameter('DUSP6_0', 100.0)
    Parameter('MAP2K1_0', 100.0)
    Parameter('MAPK1_0', 100.0)

    Rule('MAP2K1_phospho_bind_MAPK1_phospho_1', MAP2K1(mapk1=None) + \
         MAPK1(phospho='u', map2k1=None) >>
         MAP2K1(mapk1=1) % MAPK1(phospho='u', map2k1=1), kf_mm_bind_1)
    Rule('MAP2K1_phospho_MAPK1_phospho_1', MAP2K1(mapk1=1) % \
         MAPK1(phospho='u', map2k1=1) >>
        MAP2K1(mapk1=None) + MAPK1(phospho='p', map2k1=None), kc_mm_phos_1)
    Rule(
        'MAP2K1_dissoc_MAPK1',
        MAP2K1(mapk1=1) % MAPK1(map2k1=1) >>
        MAP2K1(mapk1=None) + MAPK1(map2k1=None), kr_mm_bind_1)
    Rule(
        'DUSP6_dephos_bind_MAPK1_phospho_1',
        DUSP6(mapk1=None) + MAPK1(phospho='p', dusp6=None) >>
        DUSP6(mapk1=1) % MAPK1(phospho='p', dusp6=1), kf_dm_bind_1)
    Rule(
        'DUSP6_dephos_MAPK1_phospho_1',
        DUSP6(mapk1=1) % MAPK1(phospho='p', dusp6=1) >>
        DUSP6(mapk1=None) + MAPK1(phospho='u', dusp6=None), kc_dm_dephos_1)
    Rule(
        'DUSP6_dissoc_MAPK1',
        DUSP6(mapk1=1) % MAPK1(dusp6=1) >>
        DUSP6(mapk1=None) + MAPK1(dusp6=None), kr_dm_bind_1)

    Initial(DUSP6(mapk1=None), DUSP6_0)
    Initial(MAP2K1(mapk1=None), MAP2K1_0)
    Initial(MAPK1(phospho='u', map2k1=None, dusp6=None), MAPK1_0)
    SelfExporter.do_export = False
    return model
コード例 #8
0
ファイル: pysb_assembler.py プロジェクト: gberriz/indra
 def make_model(self, initial_conditions=True):
     self.model = Model()
     self.agent_set = BaseAgentSet()
     # Collect information about the monomers/self.agent_set from the
     # statements
     self.monomers()
     # Add the monomers to the model based on our BaseAgentSet
     for agent_name, agent in self.agent_set.iteritems():
         m = Monomer(agent_name, agent.sites, agent.site_states)
         self.model.add_component(m)
         for db_name, db_ref in agent.db_refs.iteritems():
             a = get_annotation(m, db_name, db_ref)
             if a is not None:
                 self.model.add_annotation(a)
     # Iterate over the statements to generate rules
     self.assemble()
     # Add initial conditions
     if initial_conditions:
         add_default_initial_conditions(self.model)
     return self.model
コード例 #9
0
ファイル: pysb_assembler.py プロジェクト: abassobl/indra
class PysbAssembler(object):
    def __init__(self, policies=None):
        self.statements = []
        self.agent_set = None
        self.model = None
        if policies is None:
            self.policies = {'other': 'default'}
        elif isinstance(policies, basestring):
            self.policies = {'other': policies}
        else:
            self.policies = {'other': 'default'}
            self.policies.update(policies)

    def statement_exists(self, stmt):
        for s in self.statements:
            if stmt == s:
                return True
        return False

    def add_statements(self, stmts):
        for stmt in stmts:
            if not self.statement_exists(stmt):
                self.statements.append(stmt)

    def dispatch(self, stmt, stage, *args):
        class_name = stmt.__class__.__name__
        try:
            policy = self.policies[class_name]
        except KeyError:
            policy = self.policies['other']
        func_name = '%s_%s_%s' % (class_name.lower(), stage, policy)
        func = globals().get(func_name)
        if func is None:
            raise UnknownPolicyError('%s function %s not defined' %
                                     (stage, func_name))
        return func(stmt, *args)

    def monomers(self):
        """Calls the appropriate monomers method based on policies."""
        for stmt in self.statements:
            self.dispatch(stmt, 'monomers', self.agent_set)

    def assemble(self):
        for stmt in self.statements:
            self.dispatch(stmt, 'assemble', self.model, self.agent_set)

    def make_model(self, initial_conditions=True):
        self.model = Model()
        self.agent_set = BaseAgentSet()
        # Collect information about the monomers/self.agent_set from the
        # statements
        self.monomers()
        # Add the monomers to the model based on our BaseAgentSet
        for agent_name, agent in self.agent_set.iteritems():
            m = Monomer(agent_name, agent.sites, agent.site_states)
            self.model.add_component(m)
            for db_name, db_ref in agent.db_refs.iteritems():
                a = get_annotation(m, db_name, db_ref)
                if a is not None:
                    self.model.add_annotation(a)
        # Iterate over the statements to generate rules
        self.assemble()
        # Add initial conditions
        if initial_conditions:
            add_default_initial_conditions(self.model)
        return self.model

    def print_model(self, fname='pysb_model.py'):
        if self.model is not None:
            with open(fname, 'wt') as fh:
                fh.write(pysb.export.export(self.model, 'pysb_flat'))

    def print_rst(self, fname='pysb_model.rst', module_name='pysb_module'):
        if self.model is not None:
            with open(fname, 'wt') as fh:
                fh.write('.. _%s:\n\n' % module_name)
                fh.write('Module\n======\n\n')
                fh.write('INDRA-assembled model\n---------------------\n\n')
                fh.write('::\n\n')
                model_str = pysb.export.export(self.model, 'pysb_flat')
                model_str = '\t' + model_str.replace('\n', '\n\t')
                fh.write(model_str)
コード例 #10
0
from pysb import Model

from mEncoder.mechanistic_model import (
    add_monomer_synth_deg, generate_pathway, add_activation,
    add_abundance_observables, add_phospho_observables
)

model = Model('FLT3_MAPK')

# FLT3
for rtkf_name in ['FL']:
    add_monomer_synth_deg(rtkf_name)


rtk_cascade = [
    ('FLT3',  {'Y843': ['FL']}),
]
generate_pathway(model, rtk_cascade)

# ERK
for ras_name in ['HRAS', 'KRAS', 'NRAS']:
    add_monomer_synth_deg(ras_name, nsites=['N'])
    add_activation(
        model, ras_name, 'N', 'nucleotide_exchange',
        ['FLT3__Y843_p']
    )

mapk_cascade = [
    ('RAF1',   {'S338':      ['KRAS__N_gtp', 'HRAS__N_gtp', 'NRAS__N_gtp']}),
    ('BRAF',   {'S447':      ['KRAS__N_gtp', 'HRAS__N_gtp', 'NRAS__N_gtp']}),
    ('MAP2K1', {'S218_S222': ['RAF1__S338_p', 'BRAF__S447_p']}),
コード例 #11
0
ファイル: pysb_assembler.py プロジェクト: gberriz/indra
class PysbAssembler(object):
    def __init__(self, policies=None):
        self.statements = []
        self.agent_set = None
        self.model = None
        if policies is None:
            self.policies = {'other': 'default'}
        elif isinstance(policies, basestring):
            self.policies = {'other': policies}
        else:
            self.policies = {'other': 'default'}
            self.policies.update(policies)

    def statement_exists(self, stmt):
        for s in self.statements:
            if stmt == s:
                return True
        return False

    def add_statements(self, stmts):
        for stmt in stmts:
            if not self.statement_exists(stmt):
                self.statements.append(stmt)

    def dispatch(self, stmt, stage, *args):
        class_name = stmt.__class__.__name__
        try:
            policy = self.policies[class_name]
        except KeyError:
            policy = self.policies['other']
        func_name = '%s_%s_%s' % (class_name.lower(), stage, policy)
        func = globals().get(func_name)
        if func is None:
            raise UnknownPolicyError('%s function %s not defined' %
                                     (stage, func_name))
        return func(stmt, *args)

    def monomers(self):
        """Calls the appropriate monomers method based on policies."""
        for stmt in self.statements:
            self.dispatch(stmt, 'monomers', self.agent_set)

    def assemble(self):
        for stmt in self.statements:
            self.dispatch(stmt, 'assemble', self.model, self.agent_set)

    def make_model(self, initial_conditions=True):
        self.model = Model()
        self.agent_set = BaseAgentSet()
        # Collect information about the monomers/self.agent_set from the
        # statements
        self.monomers()
        # Add the monomers to the model based on our BaseAgentSet
        for agent_name, agent in self.agent_set.iteritems():
            m = Monomer(agent_name, agent.sites, agent.site_states)
            self.model.add_component(m)
            for db_name, db_ref in agent.db_refs.iteritems():
                a = get_annotation(m, db_name, db_ref)
                if a is not None:
                    self.model.add_annotation(a)
        # Iterate over the statements to generate rules
        self.assemble()
        # Add initial conditions
        if initial_conditions:
            add_default_initial_conditions(self.model)
        return self.model

    def print_model(self, fname='pysb_model.py'):
        if self.model is not None:
            with open(fname, 'wt') as fh:
                fh.write(pysb.export.export(self.model, 'pysb_flat'))

    def print_rst(self, fname='pysb_model.rst', module_name='pysb_module'):
        if self.model is not None:
            with open(fname, 'wt') as fh:
                fh.write('.. _%s:\n\n' % module_name)
                fh.write('Module\n======\n\n')
                fh.write('INDRA-assembled model\n---------------------\n\n')
                fh.write('::\n\n')
                model_str = pysb.export.export(self.model, 'pysb_flat')
                model_str = '\t' + model_str.replace('\n', '\n\t')
                fh.write(model_str)
コード例 #12
0
from pysb import Monomer, Parameter, Initial, Rule, Observable, Model
from pysb.simulator import ScipyOdeSimulator
from pylab import linspace, plot, xlabel, ylabel, show

# A simple model with a reversible binding rule
model = Model(name="t1", base=)

# Declare the monomers
L = Model.monomers('L', ['s'])
R = Monomer('R', ['s'])

# Declare the parameters
L_0 = Parameter('L_0', 100)
R_0 = Parameter('R_0', 200)
kf = Parameter('kf', 1e-3)
kr = Parameter('kr', 1e-3)

# Declare the initial conditions
Initial(L(s=None), L_0)
Initial(R(s=None), R_0)

# Declare the binding rule
Rule('L_binds_R', L(s=None) + R(s=None) | L(s=1) % R(s=1), kf, kr)

# Observe the complex
Observable('LR', L(s=1) % R(s=1))

if __name__ == '__main__':
    # Simulate the model through 40 seconds
    time = linspace(0, 40, 100)
    print("Simulating...")
コード例 #13
0
from pysb import Model, Observable

from mEncoder.mechanistic_model import (add_monomer_synth_deg,
                                        generate_pathway, add_activation,
                                        add_observables, add_inhibitor,
                                        add_gf_bolus, cleanup_unused)

model = Model('EGFR_MAPK')

rtkfs = ['EGF']

# EGFR
for rtkf_name in rtkfs:
    add_monomer_synth_deg(rtkf_name)
    add_gf_bolus(model, rtkf_name, [rtkf_name])

erbb_cascade = [
    ('EGFR', {
        'Y1173': ['EGF']
    }),
    ('ERBB2', {
        'Y1248': ['EGFR__Y1173_p']
    }),
]
generate_pathway(model, erbb_cascade)

active_rtks = ['EGFR__Y1173_p', 'ERBB2__Y1248_p']

mapk_cascade = [
    ('RAF1', {
        'S338': active_rtks + ['EGF']
コード例 #14
0
from mEncoder.mechanistic_model import (
    add_monomer_synth_deg, generate_pathway, add_activation,
    add_abundance_observables, add_phospho_observables
)

from pysb import Model

model = Model('FLT3_MAPK_AKT_STAT')

# FLT3
for rtkf_name in ['FL']:
    add_monomer_synth_deg(rtkf_name)


rtk_cascade = [
    ('FLT3',  {'Y843': ['FL']}),
]
generate_pathway(model, rtk_cascade)

# STAT
stat_cascade = [
    ('STAT1', {'Y701':  ['FLT3__Y843_p']}),
    ('STAT3', {'Y705':  ['FLT3__Y843_p']}),
    ('STAT5A', {'Y694': ['FLT3__Y843_p']}),
    ('STAT5B', {'Y699': ['FLT3__Y843_p']}),
]
generate_pathway(model, stat_cascade)

# ERK
for ras_name in ['HRAS', 'KRAS', 'NRAS']:
    add_monomer_synth_deg(ras_name, nsites=['N'])
コード例 #15
0
from pysb import Model, Observable

from mEncoder.mechanistic_model import (add_monomer_synth_deg,
                                        generate_pathway, add_activation,
                                        add_observables, add_inhibitor,
                                        add_gf_bolus)

model = Model('EGFR_MAPK_AKT_STAT')

rtkfs = ['EGF']

# EGFR
for rtkf_name in rtkfs:
    add_monomer_synth_deg(rtkf_name)
    add_gf_bolus(model, rtkf_name, [rtkf_name])

erbb_cascade = [
    ('EGFR', {
        'Y1173': ['EGF']
    }),
    ('ERBB2', {
        'Y1248': ['EGF']
    }),
]
generate_pathway(model, erbb_cascade)

active_rtks = ['EGFR__Y1173_p', 'ERBB2__Y1248_p']
stat_rtks = ['EGFR__Y1173_p', 'ERBB2__Y1248_p']

# MAPK
for ras_name in ['HRAS', 'KRAS', 'NRAS']:
コード例 #16
0
from model_cell_cycle_no_M import model
from pysb import Model, Parameter, Rule

model = Model('cell_cycle_no_M_washout', base=model)

Rule('washout', model.monomers.dead_cell() >> None, Parameter('kwash', 0.1))
コード例 #17
0
from pysb import Model, Observable

from mEncoder.mechanistic_model import (add_monomer_synth_deg,
                                        generate_pathway, add_activation,
                                        add_observables, add_inhibitor,
                                        add_gf_bolus)

model = Model('ERBB_MAPK_AKT_STAT')

rtkfs = ['EGF', 'HGF', 'INSULIN', 'IGF1', 'FGF', 'NRG1']

# EGFR
for rtkf_name in rtkfs:
    add_monomer_synth_deg(rtkf_name)
    add_gf_bolus(model, rtkf_name, [rtkf_name])

erbb_cascade = [('EGFR', {
    'Y1173_Y992': ['EGF', 'NRG1']
}), ('ERBB2', {
    'Y1248': ['EGF', 'NRG1']
}), ('ERBB3', {
    'Y1289': ['NRG1']
}), ('ERBB4', {
    'Y733': ['EGF', 'NRG1']
}), ('IGF1R', {
    'Y1135_Y1136': ['INSULIN', 'IGF1']
}), ('CMET', {
    'Y1234_Y1235': ['HGF']
}), ('FGFR', {
    'Y653': ['FGF']
})]
コード例 #18
0
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))

コード例 #19
0
ファイル: corm.py プロジェクト: LoLab-VU/pydyno
# -*- coding: utf-8 -*-
"""
Created on Mon Dec  8 19:56:12 2014

@author: Erin
"""

from pysb import Model, Monomer, Parameter, Initial, Rule, Observable
from pysb.macros import bind, bind_complex, catalyze

Model()

#Define individual species in model
Monomer('COX2', ['allo', 'cat'])  #Cyclooxygenase-2 enzyme
Monomer('AG', ['b'])  #2-arachidonoylglycerol, a substrate of COX2
Monomer('AA', ['b'])  #arachidonic acid, a substrate of COX2
Monomer('PG')  #Prostaglandin, product of COX2 turnover of AA
Monomer('PGG')  #Prostaglandin glycerol, product of COX2 turnover of 2-AG

#Initial starting concentrations in micromolar
Parameter('COX2_0', 15e-3)
Parameter('AG_0', 16)
Parameter('AA_0', 16)
Parameter('PG_0', 0)
Parameter('PGG_0', 0)

Initial(COX2(allo=None, cat=None), COX2_0)
Initial(AG(b=None), AG_0)
Initial(AA(b=None), AA_0)
Initial(PG(), PG_0)
Initial(PGG(), PGG_0)
コード例 #20
0
from pysb import (Model, Monomer, Parameter, Expression, Observable, Rule,
                  Initial)

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)))