コード例 #1
0
def simulateGlobalStateSpace(args):
    """
    PROG  Update shared dict of global state
    """
    NutrientStates = args['NutrientStates']
    strain = args['strain']
    print(strain['name'])
    modelpath = args['modelpath']
    fname = args['fname']
    cutoffs = args['cutoffs']
    paramdict = args['paramdict']

    simargs = dict(SIMARGS)

    if SIMULATOR == 'cpp':
        simargs['simfilename'] = cleanfname(strain['name']) + '.dat'

    model = get_simulator(modelpath=modelpath, simulator=SIMULATOR, **simargs)

    collect = {}
    model.set_attr(pars=paramdict)

    for ninput in NutrientStates:
        shiftspec = {
            'pars': {
                'Carbon': ninput['C'],
                'ATP': ninput['C'],
                'Glutamine_ext': ninput['Gln'],
                'Proline': ninput['Pro'],
                'NH4': ninput['NH4']
            }
        }
        deletion_par = strain['pars']
        deletion_par.update(shiftspec['pars'])

        deletion_ics = strain['ics']
        model.set_attr(pars=deletion_par, ics=deletion_ics)
        ss = model.get_ss()
        ss.update(deletion_ics)

        ss_b = tfStates(ss, READOUTS, cutoffs)
        outstr = ''.join([str(ss_b[r]['dec']) for r in READOUTS])
        collect[ninput['name']] = {strain['name']: outstr}

    collectdf = pd.DataFrame(collect)
    collectdf.to_csv(DESTINATION + fname)
コード例 #2
0
def getMutantSpecs(modelpath):
    """
    Create a list =mutationSpecs= with each element being a dictionary
    like follows: {'pars': {}, 'ics':{}, 'name': name}
    """
    simargs = dict(SIMARGS)
    model = get_simulator(modelpath=modelpath, simulator=SIMULATOR, **simargs)

    nodel = ['cAMP', 'Protein', 'Rib', \
             'Glutamine','Gis1','Rtg13',
             'Gcn4','Gln3','Mig1',
             'Gln1','Dot6','Trehalase','eIF',
             'Tps1']
    remove_interaction = [
        ['w_gcn_torc', 'Sch9-inhibit-gcn2'],
        ['w_gln_snf', 'Snf1-activates-nGln3'],
        ['w_gln_sit', 'TORC1-inhibits-Gln3'],
        ['w_pka_sch9', 'Sch9-inhibits-PKA'],
        ['w_ras_pka', 'PKA-inhibits-Ras'],
    ]
    mutationSpecs = [{'name': 'wt', 'pars': {}, 'ics': {}}]

    for v in model.get_variables():
        if v not in nodel:
            mutationSpecs.append({
                'pars': {
                    v + '_T': 0.0
                },
                'ics': {
                    v: 0.0
                },
                'name': v
            })

    for p in remove_interaction:
        if p[0] in model.get_pars():
            mutationSpecs.append({
                'pars': {
                    p[0]: 0.0
                },
                'ics': {},
                'name': p[1]
            })
    return (mutationSpecs)
コード例 #3
0
def simulate_strain_and_nutrient_condition(ns, pset={}, mut={}):
    """
    Simulates a single strain using a parameter set if specified.
    Requires a nutrient condition specification
    """
    model = sim.get_simulator(modelpath=MODELPATH,
                              simulator="cpp",
                              executable=SIMARGS['executable'])
    tmax = 90
    # Set preshift parameters
    if ns['name'] == 'LCLN':
        preshift = {'Carbon': 1.0, "Glutamine_ext": 1.0, "ATP": 1.0}
    else:
        preshift = {'Carbon': 0.0, "Glutamine_ext": 1.0, "ATP": 0.0}
    # initialize with pset
    deletion_par = {}
    if type(pset) != dict:
        deletion_par.update(pset.to_dict())
    deletion_par.update(mut.get('pars', {}))
    deletion_par.update(preshift)
    deletion_ics = mut.get('ics', {})

    model.set_attr(pars=deletion_par, ics=deletion_ics, tdata=[0, 90])
    # Reinitialize the parameter specification
    # NOTE This can be cleaner
    deletion_par = {}
    if type(pset) != dict:
        deletion_par.update(pset.to_dict())
    deletion_par.update(mut.get('pars', {}))
    postshift = {
        'Carbon': ns['C'],
        "ATP": ns['C'],
        "Glutamine_ext": ns['Gln'],
        "NH4": ns['NH4'],
        "Proline": ns['Pro']
    }

    deletion_par.update(postshift)
    model.set_attr(ics=model.simulate_and_get_ss(),
                   pars=deletion_par,
                   tdata=[0, tmax])

    points = model.simulate_and_get_points()
    return (points)
コード例 #4
0
def define_state_space(modelpath):
    statedict = {r: [] for r in READOUTS}

    nut = [{
        'Carbon': 0.0,
        'ATP': 0.0,
        'Glutamine_ext': 0.0
    }, {
        'Carbon': 0.0,
        'ATP': 0.0,
        'Glutamine_ext': 1.0
    }, {
        'Carbon': 1.0,
        'ATP': 1.0,
        'Glutamine_ext': 0.0
    }, {
        'Carbon': 1.0,
        'ATP': 1.0,
        'Glutamine_ext': 1.0
    }, {
        'Carbon': 0.0,
        'ATP': 0.0,
        'Glutamine_ext': 0.0,
        'Proline': 0.0,
        'NH4': 1.0
    }, {
        'Carbon': 1.0,
        'ATP': 1.0,
        'Glutamine_ext': 0.0,
        'Proline': 0.0,
        'NH4': 1.0
    }, {
        'Carbon': 0.0,
        'ATP': 0.0,
        'Glutamine_ext': 0.0,
        'Proline': 1.0,
        'NH4': 0.0
    }, {
        'Carbon': 1.0,
        'ATP': 1.0,
        'Glutamine_ext': 0.0,
        'Proline': 1.0,
        'NH4': 0.0
    }]
    model = get_simulator(modelpath=modelpath, simulator=SIMULATOR, **SIMARGS)
    for n in nut:
        model.set_attr(pars=n, tdata=[0, 200])
        P = model.get_ss()
        for k in statedict.keys():
            statedict[k].append(P[k])

    cutoffs = {}
    for k, v in statedict.items():
        if k in ['Mig1', 'Dot6']:
            lo = np.log10((min(v)) / (1 - min(v)))
            hi = np.log10((max(v)) / (1 - max(v)))
        else:
            lo = min(v)
            hi = max(v)
        mean = (lo + hi) / 2.
        print(k, round(lo, 3), round(hi, 3), round(mean, 3))
        cutoffs[k] = mean
    return statedict, cutoffs
コード例 #5
0
                                      'Glutamine_ext':1.0},
                        'inconds':{}}}
]

plotsettings = [{'style':'k--','label':'Model 1'}, # 'Snf1 -| TORC1'
                {'style':'#bbbbbb','label':'Model 2'}] #'no interaction'

MODELPATH = 'data/2018-9-26-12-3-no-sigma/'

for exp, axis in zip(experiments, ax):
    # For each experiment, create a wt  and mutant object,
    # where the mutant strain lacks the TORC1-Snf1 interaction.
    # Simulate the shift defined in the experiment, plot
    # the time courses
    wt = get_simulator(modelpath=MODELPATH,
                      SIMULATOR = 'cpp',
                      SIMARGS = {'executable':'robust.o'})

    mut = get_simulator(modelpath=MODELPATH,
                        SIMULATOR = 'cpp',
                        SIMARGS = {'executable':'robust.o'})
    mut.set_attr(pars={'w_torc_snf':0.0})
    strains = [wt, mut]
    for model, setting in zip(strains, plotsettings):
        # For both models, set the preshift parameters and ics
        model.set_attr(pars=exp['pre']['parameters'],
                       ics=exp['pre']['inconds'])
        ss = model.get_ss()
        model.set_attr(pars=exp['post']['parameters'],
                       ics=model.get_ss(),
                       tdata=[0,30])
コード例 #6
0
    },
    'mutant': {
        'c': 'r',
        'label': '$sit4$'
    }
}
timeAtTreatment = 60
timePostTreatment = 90

f, ax = plt.subplots(1, 1, figsize=(3.5, 3))
toplot = 'Gln3'

for strain in ['wt', 'mutant']:
    # Initialize
    model = get_simulator(modelpath=modelpath,
                          simulator='cpp',
                          execpath=modelpath + '/',
                          executable='nutsig.o')
    if strain == 'mutant':
        model.set_attr(pars=straindef)

    model.set_attr(pars=preshift, tdata=[0, 90])
    # preshift
    model.set_attr(ics=model.get_ss(), tdata=[0, timeAtTreatment])
    Pre = model.simulate_and_get_points()
    # treatment, start from previous ss
    model.set_attr(ics=model.get_ss(),
                   pars=treatment,
                   tdata=[0, timePostTreatment])
    Post = model.simulate_and_get_points()

    # Plot
コード例 #7
0
 def makeSimulator(self):
     simobj = get_simulator(self.modelpath, self.simulatortype)
     return simobj
コード例 #8
0
def do_experiment(expargs):
    """
    Carry out an in silico shift experiment with the given experiment
    specification.
    PROG: incomplete
    """

    experiment = expargs['experiment']
    shareddict = expargs['shareddict']
    cutoffs = expargs['cutoffs']
    paramdict = expargs['paramdict']
    outDir = expargs['outDir']
    singleRun = expargs.get('singleRun', False)

    if paramdict is None:
        paramdict = {}

    modelpath = expargs['modelpath']
    uid = str(experiment['id']) + '-' + experiment['strain']
    fname = str(uid)
    if SIMULATOR == 'cpp':
        SIMARGS['simfilename'] = cleanfname(uid) + '.dat'
    # Initialize model object
    model = get_simulator(modelpath=modelpath, simulator=SIMULATOR, **SIMARGS)
    model.set_attr(pars=paramdict)
    ## Do mutant simulation
    ## 1. If parameters are defined, set parameters
    ## 2. If initial conditions are specified, set initial conditions
    ## Else, leave at default, resulting in wt simulation
    if experiment['mutant']['pars'] is not None:
        mutpars = experiment['mutant']['pars']
        for k, v in mutpars.items():
            ## Simple check to implement a "X times" type of specification
            ## Update mutpars inplace
            if type(v) is str and 'x' in v:
                mutpars[k] = float(v.replace('x', '')) * model.pars[k]
        model.set_attr(pars=mutpars)

    if experiment['mutant']['ics'] is not None:
        model.set_attr(ics=experiment['mutant']['ics'])

    prepars = experiment['preshift']
    if prepars is None:
        prepars = {}
    postpars = experiment['postshift']
    if postpars is None:
        postpars = {}
    postics = experiment['postshiftics']
    if postics is None:
        postics = {}
    model.set_attr(pars=prepars, tdata=[0, 90])
    newics = model.get_ss()
    newics.update(postics)
    model.set_attr(pars=postpars, tdata=[0, 90], ics=model.get_ss())

    P = model.simulate_and_get_points()
    newss = model.get_ss()
    state = tfStates(newss, READOUTS, cutoffs)
    for rep in [' ', '\\']:
        if rep in fname:
            fname = fname.replace(rep, '')
    if singleRun:
        plotTfs(P, READOUTS, uid, cutoffs, fname, outDir)
    interpret_experiment(uid, state, expargs, fname, outDir)
コード例 #9
0
from nutrient_signaling.simulators import get_simulator
import matplotlib.pyplot as plt
import os
home = os.path.expanduser('~')
#modelpath = home + '/jalihal_projects/Research/nutrient-signaling/data/2019-02-26'
modelpath = home + '/jalihal_projects/Research/nutrient-signaling/data/2019-06-21'

f, ax = plt.subplots(1, 2)
# wt -3AT
model = get_simulator(modelpath=modelpath, simulator='py')

model.set_attr(pars={
    'Carbon': 1.0,
    'ATP': 1.0,
    'Glutamine_ext': 1.0
},
               tdata=[0, 90])
model.set_attr(pars={
    'Carbon': 1.0,
    'ATP': 1.0,
    'Glutamine_ext': 1.0
},
               ics=model.get_ss(),
               tdata=[0, 90])
P = model.simulate_and_get_points()
eIF = [(1 - e) / (e + 1e-3) for e in P['eIF']]
ax[0].plot(P['t'], eIF, 'k--', lw=3, label='wt')
# wt -3AT
model = get_simulator(modelpath=modelpath, simulator='py')

model.set_attr(pars={
コード例 #10
0
ファイル: cost.py プロジェクト: amoghpj/nutrient-signaling
    def compute_timecourse_cost(self,
                                paramset,
                                modelpath=None,
                                simulator=None,
                                executable=None,
                                simfilename=None):
        if modelpath is None:
            modelpath = self.modelpath
        if simulator is None:
            simulator = self.simulator
        if executable is None:
            executable = self.executable
        if simfilename is None:
            simfilename = self.simfilename
        cost = 0.
        timepoint_count = 0.

        for spec in self.timeCourseSpecList:
            exp_data_idx = self._get_list_item(spec, self.tc.data,
                                               'description')
            exp_data = self.tc.data[exp_data_idx]
            simspec = exp_data["spec"]
            expT = exp_data['time']
            expV = exp_data['value']
            if exp_data['tunits'] == 's':
                expT = [t / 60.0 for t in expT]

            if exp_data["ts_type"] == "ts":
                if np.isnan(exp_data['normalize']['lower']) and np.isnan(
                        exp_data['normalize']['upper']):
                    expV = utils.minmaxnorm(expV)
                else:
                    expV = utils.minmaxnorm_special(
                        expV, exp_data['normalize']['lower'],
                        exp_data['normalize']['upper'])

            varname = exp_data['readout']

            parameters = paramset.copy()
            parameters.update(simspec['preshift']['pars'])
            ## Simulation details
            model = sim.get_simulator(self.modelpath,
                                      simulator=simulator,
                                      executable=executable,
                                      simfilename=simfilename)
            preshift_ics = model.simulate_and_get_ss()
            preshift_ics.update(simspec["preshift"]["ics"])
            model.set_attr(tdata=[0, 90], pars=parameters, ics=preshift_ics)

            postshift_ics = model.simulate_and_get_ss()

            # post shift
            postshift_ics.update(simspec['postshift']['ics'])
            parameters.update(simspec['postshift']['pars'])
            model.set_attr(tdata=[0, expT[-1] + 10.],
                           pars=parameters,
                           ics=postshift_ics)

            pts = model.simulate_and_get_points()

            if 'func' in exp_data['ts_type']:
                predicted = self.tc.customFuncDef[exp_data['ts_type'].split(
                    ':')[1]](pts[varname])
            else:
                predicted = list(pts[varname])
            pred_time = pts['t']

            # for every time point in the ground truth, find
            # the corresponding index in the predicted time list,
            # and then compute the deviation for the predicted value
            #
            cost += sum([np.power(predicted[self._findindex(pred_time, et)] - ev, 2) \
                        for et, ev in zip(expT, expV)])
            timepoint_count += len(expT)
        return (cost / float(timepoint_count))
コード例 #11
0
 def makeSimulator(self, args):
     simobj = get_simulator(modelpath=self.modelpath,
                            simulator=self.simulatortype,
                            executable=self.executable,
                            simfilename=self.simfilename)
     return simobj