def SSAnetwork(fn,y0in,param,adjacency):
    """
    This is the network-level SSA model, with coupling. Call with:
        SSAcoupled,state_names,param_names = SSAmodelC(ODEmodel(),y0in,param)
    
    To uncouple the model, set adjacency matrix to zeros    
    """
    
    #Converts concentration to population
    y0in_ssa = (vol*y0in).astype(int)
    
    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = []
    state_names=[]
    if randomy0==False:
        y0in_pop = []
    

    #coupling section===========================
    for indx in range(cellcount):
        index = '_'+str(indx)+'_0'
        #loops to include all species, normally this is the only line needed without index
        species_array = species_array + [fn.inputSX(cs.DAE_X)[i].getDescription()+index
                        for i in xrange(EqCount)]
        state_names = state_names + [fn.inputSX(cs.DAE_X)[i].getDescription()+index
                        for i in xrange(EqCount)]  
        if randomy0==False:                
            y0in_pop = np.append(y0in_pop, y0in_ssa)       
                
    if randomy0 == True:
        #random initial locations
        y0in_pop = 1*np.ones(EqCount*cellcount)
        for i in range(len(y0in_pop)):
            y0in_pop[i] = vol*4*random.random()

    #===========================================
            
    param_array   = [fn.inputSX(cs.DAE_P)[i].getDescription()
                    for i in xrange(ParamCount)]
    param_names   = [fn.inputSX(cs.DAE_P)[i].getDescription()
                    for i in xrange(ParamCount)]
    #Names model
    SSAmodel = stk.StochKitModel(name=modelversion)
    
    #creates SSAmodel class object
    SSA_builder = mb.SSA_builder(species_array,param_array,y0in_pop,param,SSAmodel,vol)
    

    #coupling section
    for indx in range(cellcount):
            
        index = '_'+str(indx)+'_0'
        
        #Coupled terms - - -------------------------------------------------
        #loops for all cells accumulating their input
        avg = '0'
        mcount = 0
        for fromcell in range(cellcount):
            if adjacency[fromcell,indx]!= 0:
                #The Coupling Part
                mcount = mcount+1
                avg = avg+'+M_'+str(fromcell)+'_0'

        
        weight = 1.0/mcount
        #FIXES PARAMETERS FROM DETERMINISTIC TO STOCHASTIC VALUES
        if (str(SSA_builder.pvaldict['vs0']) ==
                        SSA_builder.SSAmodel.listOfParameters['vs0'].expression):
                SSA_builder.SSAmodel.setParameter('vs0',
                                SSA_builder.SSAmodel.listOfParameters['vs0'].expression+'*('+str(SSA_builder.vol)+')')
        if (str(SSA_builder.pvaldict['k1']) ==
                        SSA_builder.SSAmodel.listOfParameters['k1'].expression):
                SSA_builder.SSAmodel.setParameter('k1',
                                SSA_builder.SSAmodel.listOfParameters['k1'].expression+'*('+str(SSA_builder.vol)+')')
        
        if (str(SSA_builder.pvaldict['alocal']) ==
                        SSA_builder.SSAmodel.listOfParameters['alocal'].expression):
                SSA_builder.SSAmodel.setParameter('alocal',
                                SSA_builder.SSAmodel.listOfParameters['alocal'].expression+'*('+str(SSA_builder.vol)+')')
        #####
        #Adds reaction for coupling
        rxn=stk.Reaction(name='Cell'+str(indx)+'_Reaction0',
                         reactants={},
                        products={'M_'+str(indx)+'_0':1},
                        propensity_function=('std::max(0.0,(vs0+alocal*(('+avg+')*'
                                    +str(weight)+'-M_'+str(indx)+'_0)))'+ 
                                    '*pow(k1,n)/(pow(k1,n)+pow(Pn_'+str(indx)+'_0,n))'),annotation='')#
   
        SSAmodel.addReaction(rxn)
        #-------------------------------------------------------------------
        
        # REACTIONS
        SSA_builder.SSA_MM('Cell'+str(indx)+'_Reaction1','vm',
                           km=['km'],Rct=['M'+index])
        
        SSA_builder.SSA_MA_tln('Cell'+str(indx)+'_Reaction2', 'Pc'+index,
                               'ks','M'+index)
        
        SSA_builder.SSA_MM('Cell'+str(indx)+'_Reaction3','vd',
                           km=['kd'],Rct=['Pc'+index])
        
        #The complexing four:
        SSA_builder.SSA_MA_cytonuc('Cell'+str(indx)+'_Reaction4','Pc'+index,
                                   'Pn'+index,'k1_','k2_')
        

    return SSAmodel,state_names,param_names
示例#2
0
def FullModel(Stoch=False):

    # Variable Assignments
    X = cs.ssym("X")
    Y = cs.ssym("Y")

    sys = cs.vertcat([X, Y])  # vector version of y

    # Parameter Assignments
    P = cs.ssym("P")
    kt = cs.ssym("kt")
    kd = cs.ssym("kd")
    a0 = cs.ssym("a0")
    a1 = cs.ssym("a1")
    a2 = cs.ssym("a2")
    kdx = cs.ssym("kdx")

    paramset = cs.vertcat([P, kt, kd, a0, a1, a2, kdx])

    # Time
    t = cs.ssym("t")

    ode = [[]] * EqCount
    ode[0] = 1 / (1 + Y**P) - kdx * X
    ode[1] = kt * X - kd * Y - Y / (a0 + a1 * Y + a2 * Y**2)

    ode = cs.vertcat(ode)

    fn = cs.SXFunction(cs.daeIn(t=t, x=sys, p=paramset), cs.daeOut(ode=ode))

    fn.setOption("name", "2state")

    #==================================================================
    # Stochastic Model Portion
    #==================================================================

    if Stoch == True:
        print 'Now converting model to StochKit XML format...'

        #Converts concentration to population
        y0in_pop = (vol * y0in).astype(int)

        #collects state and parameter array to be converted to species and parameter objects
        species_array = [
            fn.inputSX(cs.DAE_X)[i].getDescription() for i in xrange(EqCount)
        ]
        param_array = [
            fn.inputSX(cs.DAE_P)[i].getDescription()
            for i in xrange(ParamCount)
        ]

        #Names model
        SSAmodel = stk.StochKitModel(name=modelversion)

        #creates SSAmodel class object
        SSA_builder = mb.SSA_builder(species_array, param_array, y0in_pop,
                                     param, SSAmodel, vol)

        # REACTIONS
        SSA_builder.SSA_tyson_x('x prod nonlinear term', 'X', 'Y', 'P')
        SSA_builder.SSA_MA_deg('x degradation', 'X', 'kdx')

        SSA_builder.SSA_MA_tln('y creation', 'Y', 'kt', 'X')
        SSA_builder.SSA_MA_deg('y degradation, linear', 'Y', 'kd')
        SSA_builder.SSA_tyson_y('y nonlinear term', 'Y', 'a0', 'a1', 'a2')

        # END REACTIONS

    state_names = [
        fn.inputSX(cs.DAE_X)[i].getDescription() for i in xrange(EqCount)
    ]
    param_names = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]

    return fn, SSAmodel, state_names, param_names
示例#3
0
def SSAmodel(fn,y0in,param):
    """
    This is the network-level SSA model, with coupling. Call with:
    SSAcoupled,state_names,param_names = SSAmodelC(ODEmodel(),y0in,param)
    By default, there is no coupling in this model.    
    """
    
    #Converts concentration to population
    y0in_pop = (vol*y0in).astype(int)
    
    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = [fn.inputExpr(cs.DAE_X)[i].getName()
                    for i in xrange(EqCount)]
    param_array   = [fn.inputExpr(cs.DAE_P)[i].getName()
                    for i in xrange(ParamCount)]
    
    state_names = [fn.inputExpr(cs.DAE_X)[i].getName()
                        for i in xrange(EqCount)]  
    param_names   = [fn.inputExpr(cs.DAE_P)[i].getName()
                        for i in xrange(ParamCount)]

    #creates SSAmodel class object    
    SSAmodel = stk.StochKitModel(name=modelversion)
    SSA_builder = mb.SSA_builder(species_array,param_array,y0in_pop,param,SSAmodel,vol)
    

    #FIXES PARAMETERS FROM DETERMINISTIC TO STOCHASTIC VALUES
    if (str(SSA_builder.pvaldict['vs0']) ==
                    SSA_builder.SSAmodel.listOfParameters['vs0'].expression):
            SSA_builder.SSAmodel.setParameter('vs0',
                            SSA_builder.SSAmodel.listOfParameters['vs0'].expression+'*('+str(SSA_builder.vol)+')')
    if (str(SSA_builder.pvaldict['k1']) ==
                    SSA_builder.SSAmodel.listOfParameters['k1'].expression):
            SSA_builder.SSAmodel.setParameter('k1',
                            SSA_builder.SSAmodel.listOfParameters['k1'].expression+'*('+str(SSA_builder.vol)+')')
    
    if (str(SSA_builder.pvaldict['alocal']) ==
                    SSA_builder.SSAmodel.listOfParameters['alocal'].expression):
            SSA_builder.SSAmodel.setParameter('alocal',
                            SSA_builder.SSAmodel.listOfParameters['alocal'].expression+'*('+str(SSA_builder.vol)+')')
    
    
    # REACTIONS
    rxn0=stk.Reaction(name='Reaction0',
                         reactants={},
                        products={'M':1},
                        propensity_function=(
                        'vs0*pow(k1,n)/(pow(k1,n)+pow(Pn,n))'),annotation='')
   
    SSAmodel.addReaction(rxn0)    
    
    SSA_builder.SSA_MM('Reaction1','vm',
                       km=['km'],Rct=['M'])
    
    SSA_builder.SSA_MA_tln('Reaction2', 'Pc',
                           'ks','M')
    
    SSA_builder.SSA_MM('Reaction3','vd',
                       km=['kd'],Rct=['Pc'])

    SSA_builder.SSA_MA_cytonuc('Reaction4','Pc',
                               'Pn','k1_','k2_')
        

    return SSAmodel,state_names,param_names
示例#4
0
def SSAmodelC(fn, y0in, param):
    """
    This is the network-level SSA model, with coupling. Call with:
        SSAcoupled,state_names,param_names = SSAmodelC(ODEmodel(),y0in,param)
    
    To uncouple the model, set parameter 35 (last parameter) to 0, and also 
    set VIP production to 0.
    
    """

    #Converts concentration to population
    y0in_ssa = (vol * y0in).astype(int)

    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = []
    state_names = []
    if randomy0 == False:
        y0in_pop = []

    #coupling section===========================
    for indx in range(xlen):
        for indy in range(ylen):
            index = '_' + str(indx) + '_' + str(indy)
            #loops to include all species, normally this is the only line needed without index
            species_array = species_array + [
                fn.inputSX(cs.DAE_X)[i].getDescription() + index
                for i in xrange(EqCount)
            ]
            state_names = state_names + [
                fn.inputSX(cs.DAE_X)[i].getDescription() + index
                for i in xrange(EqCount)
            ]
            if randomy0 == False:
                y0in_pop = np.append(y0in_pop, y0in_ssa)

    if randomy0 == True:
        #random initial locations
        y0in_pop = 1 * np.ones(EqCount * xlen * ylen)
        for i in range(len(y0in_pop)):
            y0in_pop[i] = vol * 1 * random.random()

    #===========================================

    param_array = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]
    param_names = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]
    #Names model
    SSAmodel = stk.StochKitModel(name=modelversion)

    #creates SSAmodel class object
    SSA_builder = mb.SSA_builder(species_array, param_array, y0in_pop, param,
                                 SSAmodel, vol)

    #coupling section
    for indx in range(xlen):
        for indy in range(ylen):

            index = '_' + str(indx) + '_' + str(indy)

            # REACTIONS

            #per mRNA

            SSA_builder.SSA_PR16f('per mRNA activation' + index, 'p' + index,
                                  'CREB' + index, 'C1P' + index, 'C2P' + index,
                                  'vtpr', 'vtpp', 'knpr')
            SSA_builder.SSA_MM('per mRNA degradation' + index,
                               'vdp',
                               km=['kdp'],
                               Rct=['p' + index])

            #cry1 mRNA
            SSA_builder.SSA_MM('c1 mRNA repression' + index,
                               'vtc1r',
                               km=['kncr'],
                               Prod=['c1' + index],
                               Rep=['C1P' + index, 'C2P' + index])
            SSA_builder.SSA_MM('c1 mRNA degradation' + index,
                               'vdc1',
                               km=['kdc'],
                               Rct=['c1' + index])

            #cry2 mRNA
            SSA_builder.SSA_MM('c2 mRNA repression' + index,
                               'vtc2r',
                               km=['kncr'],
                               Prod=['c2' + index],
                               Rep=['C1P' + index, 'C2P' + index])
            SSA_builder.SSA_MM('c2 mRNA degradation' + index,
                               'vdc2',
                               km=['kdc'],
                               Rct=['c2' + index])

            #vip mRNA
            SSA_builder.SSA_MM('vip mRNA repression' + index,
                               'vtvr',
                               km=['knvr'],
                               Prod=['vip' + index],
                               Rep=['C1P' + index, 'C2P' + index])
            SSA_builder.SSA_MM('vip mRNA degradation' + index,
                               'vdv',
                               km=['kdv'],
                               Rct=['vip' + index])

            #CRY1, CRY2, PER, VIP creation and degradation
            SSA_builder.SSA_MA_tln('PER translation' + index, 'P' + index,
                                   'ktlnp', 'p' + index)
            SSA_builder.SSA_MA_tln('CRY1 translation' + index, 'C1' + index,
                                   'ktlnc', 'c1' + index)
            SSA_builder.SSA_MA_tln('CRY2 translation' + index, 'C2' + index,
                                   'ktlnc', 'c2' + index)
            SSA_builder.SSA_MA_tln('VIP translation' + index, 'eVIP' + index,
                                   'ktlnv', 'vip' + index)

            SSA_builder.SSA_MM('PER degradation' + index,
                               'vdP',
                               km=['kdP'],
                               Rct=['P' + index])
            SSA_builder.SSA_MM('C1 degradation' + index,
                               'vdC1',
                               km=['kdC'],
                               Rct=['C1' + index])
            SSA_builder.SSA_MM('C2 degradation' + index,
                               'vdC2',
                               km=['kdC'],
                               Rct=['C2' + index])
            SSA_builder.SSA_MA_deg('eVIP degradation' + index, 'eVIP' + index,
                                   'kdVIP')

            #CRY1 CRY2 complexing
            SSA_builder.SSA_MA_complex('CRY1-P complex' + index, 'C1' + index,
                                       'P' + index, 'C1P' + index, 'vaCP',
                                       'vdCP')
            SSA_builder.SSA_MA_complex('CRY2-P complex' + index, 'C2' + index,
                                       'P' + index, 'C2P' + index, 'vaCP',
                                       'vdCP')
            SSA_builder.SSA_MM('C1P degradation' + index,
                               'vdC1n',
                               km=['kdCn'],
                               Rct=['C1P' + index, 'C2P' + index])
            SSA_builder.SSA_MM('C2P degradation' + index,
                               'vdC2n',
                               km=['kdCn'],
                               Rct=['C2P' + index, 'C1P' + index])

            #VIP/CREB Pathway
            SSA_builder.SSA_MM('CREB formation' + index,
                               'vgpka',
                               km=['kgpka'],
                               Prod=['CREB' + index],
                               Act=['eVIP' + index])
            SSA_builder.SSA_MM('CREB degradation' + index,
                               'vdCREB',
                               km=['kdCREB'],
                               Rct=['CREB' + index])

            SSA_builder.SSA_MA_meanfield('eVIP', indx, xlen, indy, ylen,
                                         'kcouple')

    return SSAmodel, state_names, param_names
示例#5
0
def SSAcell(fn, y0in, param):
    """
    This is the single cell-level SSA model. Call with:
        SSAuncoupled,state_names,param_names = SSAmodelU(ODEmodel(),y0in,param)  
    """
    #Converts concentration to population
    y0in_pop = (vol * y0in).astype(int)

    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = [
        fn.inputSX(cs.DAE_X)[i].getDescription() for i in xrange(EqCount)
    ]
    param_array = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]

    #Names model
    SSAmodel = stk.StochKitModel(name=modelversion)
    #SSAmodel.units='concentration'

    #creates SSAmodel class object
    SSA_builder = mb.SSA_builder(species_array, param_array, y0in_pop, param,
                                 SSAmodel, vol)
    # REACTIONS

    #per mRNA

    SSA_builder.SSA_PR16f('per mRNA activation', 'p', 'CREB', 'C1P', 'C2P',
                          'vtpr', 'vtpp', 'knpr')
    SSA_builder.SSA_MM('per mRNA degradation', 'vdp', km=['kdp'], Rct=['p'])

    #cry1 mRNA
    SSA_builder.SSA_MM('c1 mRNA repression',
                       'vtc1r',
                       km=['kncr'],
                       Prod=['c1'],
                       Rep=['C1P', 'C2P'])
    SSA_builder.SSA_MM('c1 mRNA degradation', 'vdc1', km=['kdc'], Rct=['c1'])

    #cry2 mRNA
    SSA_builder.SSA_MM('c2 mRNA repression',
                       'vtc2r',
                       km=['kncr'],
                       Prod=['c2'],
                       Rep=['C1P', 'C2P'])
    SSA_builder.SSA_MM('c2 mRNA degradation', 'vdc2', km=['kdc'], Rct=['c2'])

    #vip mRNA
    SSA_builder.SSA_MM('vip mRNA repression',
                       'vtvr',
                       km=['knvr'],
                       Prod=['vip'],
                       Rep=['C1P', 'C2P'])
    SSA_builder.SSA_MM('vip mRNA degradation', 'vdv', km=['kdv'], Rct=['vip'])

    #CRY1, CRY2, PER, VIP creation and degradation
    SSA_builder.SSA_MA_tln('PER translation', 'P', 'ktlnp', 'p')
    SSA_builder.SSA_MA_tln('CRY1 translation', 'C1', 'ktlnc', 'c1')
    SSA_builder.SSA_MA_tln('CRY2 translation', 'C2', 'ktlnc', 'c2')
    SSA_builder.SSA_MA_tln('VIP translation', 'eVIP', 'ktlnv', 'vip')

    SSA_builder.SSA_MM('PER degradation', 'vdP', km=['kdP'], Rct=['P'])
    SSA_builder.SSA_MM('C1 degradation', 'vdC1', km=['kdC'], Rct=['C1'])
    SSA_builder.SSA_MM('C2 degradation', 'vdC2', km=['kdC'], Rct=['C2'])
    SSA_builder.SSA_MA_deg('eVIP degradation', 'eVIP', 'kdVIP')

    #CRY1 CRY2 complexing
    SSA_builder.SSA_MA_complex('CRY1-P complex', 'C1', 'P', 'C1P', 'vaCP',
                               'vdCP')
    SSA_builder.SSA_MA_complex('CRY2-P complex', 'C2', 'P', 'C2P', 'vaCP',
                               'vdCP')
    SSA_builder.SSA_MM('C1P degradation',
                       'vdC1n',
                       km=['kdCn'],
                       Rct=['C1P', 'C2P'])
    SSA_builder.SSA_MM('C2P degradation',
                       'vdC2n',
                       km=['kdCn'],
                       Rct=['C2P', 'C1P'])

    #VIP/CREB Pathway
    SSA_builder.SSA_MM('CREB formation',
                       'vgpka',
                       km=['kgpka'],
                       Prod=['CREB'],
                       Act=['eVIP'])
    SSA_builder.SSA_MM('CREB degradation',
                       'vdCREB',
                       km=['kdCREB'],
                       Rct=['CREB'])

    state_names = [
        fn.inputSX(cs.DAE_X)[i].getDescription() for i in xrange(EqCount)
    ]
    param_names = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]
    return SSAmodel, state_names, param_names
def ssa_resync(fn, y0in_desync, param, cellcount, adjacency):
    """
    This is the network-level SSA model, with coupling. Call with:
        SSAcoupled,state_names,param_names = SSAmodelC(ODEmodel(),y0in,param)
    
    To uncouple the model, set adjacency matrix to zeros    
    """

    #Converts concentration to population
    y0in_ssa = (vol * y0in).astype(int)

    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = []
    state_names = []
    y0in_pop = y0in_desync

    #coupling section===========================
    for indx in range(cellcount):
        index = '_' + str(indx) + '_0'
        #loops to include all species, normally this is the only line needed without index
        species_array = species_array + [
            fn.inputExpr(cs.DAE_X)[i].getName() + index
            for i in xrange(EqCount)
        ]
        state_names = state_names + [
            fn.inputExpr(cs.DAE_X)[i].getName() + index
            for i in xrange(EqCount)
        ]
        if randomy0 == False:
            y0in_pop = np.append(y0in_pop, y0in_ssa)

    if randomy0 == True:
        #random initial locations
        y0in_pop = 1 * np.ones(EqCount * cellcount)
        for i in range(len(y0in_pop)):
            y0in_pop[i] = vol * 1 * random.random()

    #===========================================

    param_array = [
        fn.inputExpr(cs.DAE_P)[i].getName() for i in xrange(ParamCount)
    ]
    param_names = [
        fn.inputExpr(cs.DAE_P)[i].getName() for i in xrange(ParamCount)
    ]
    #Names model
    SSAmodel = stk.StochKitModel(name=modelversion)

    #creates SSAmodel class object
    SSA_builder = mb.SSA_builder(species_array, param_array, y0in_pop, param,
                                 SSAmodel, vol)

    #coupling section
    for indx in range(cellcount):

        index = '_' + str(indx) + '_0'

        # REACTIONS
        #per mRNA

        SSA_builder.SSA_PR16f('per mRNA activation' + index, 'p' + index,
                              'CREB' + index, 'C1P' + index, 'C2P' + index,
                              'vtpr', 'vtpp', 'knpr')
        SSA_builder.SSA_MM('per mRNA degradation' + index,
                           'vdp',
                           km=['kdp'],
                           Rct=['p' + index])

        #cry1 mRNA
        SSA_builder.SSA_MM('c1 mRNA repression' + index,
                           'vtc1r',
                           km=['kncr'],
                           Prod=['c1' + index],
                           Rep=['C1P' + index, 'C2P' + index])
        SSA_builder.SSA_MM('c1 mRNA degradation' + index,
                           'vdc1',
                           km=['kdc'],
                           Rct=['c1' + index])

        #cry2 mRNA
        SSA_builder.SSA_MM('c2 mRNA repression' + index,
                           'vtc2r',
                           km=['kncr'],
                           Prod=['c2' + index],
                           Rep=['C1P' + index, 'C2P' + index])
        SSA_builder.SSA_MM('c2 mRNA degradation' + index,
                           'vdc2',
                           km=['kdc'],
                           Rct=['c2' + index])

        #vip mRNA
        SSA_builder.SSA_MM('vip mRNA repression' + index,
                           'vtvr',
                           km=['knvr'],
                           Prod=['vip' + index],
                           Rep=['C1P' + index, 'C2P' + index])
        SSA_builder.SSA_MM('vip mRNA degradation' + index,
                           'vdv',
                           km=['kdv'],
                           Rct=['vip' + index])

        #CRY1, CRY2, PER, VIP creation and degradation
        SSA_builder.SSA_MA_tln('PER translation' + index, 'P' + index, 'ktlnp',
                               'p' + index)
        SSA_builder.SSA_MA_tln('CRY1 translation' + index, 'C1' + index,
                               'ktlnc', 'c1' + index)
        SSA_builder.SSA_MA_tln('CRY2 translation' + index, 'C2' + index,
                               'ktlnc', 'c2' + index)

        SSA_builder.SSA_MM('PER degradation' + index,
                           'vdP',
                           km=['kdP'],
                           Rct=['P' + index])
        SSA_builder.SSA_MM('C1 degradation' + index,
                           'vdC1',
                           km=['kdC'],
                           Rct=['C1' + index])
        SSA_builder.SSA_MM('C2 degradation' + index,
                           'vdC2',
                           km=['kdC'],
                           Rct=['C2' + index])
        SSA_builder.SSA_MA_deg('eVIP degradation' + index, 'eVIP' + index,
                               'kdVIP')

        #CRY1 CRY2 complexing
        SSA_builder.SSA_MA_complex('CRY1-P complex' + index, 'C1' + index,
                                   'P' + index, 'C1P' + index, 'vaCP', 'vdCP')
        SSA_builder.SSA_MA_complex('CRY2-P complex' + index, 'C2' + index,
                                   'P' + index, 'C2P' + index, 'vaCP', 'vdCP')
        SSA_builder.SSA_MM('C1P degradation' + index,
                           'vdC1n',
                           km=['kdCn'],
                           Rct=['C1P' + index, 'C2P' + index])
        SSA_builder.SSA_MM('C2P degradation' + index,
                           'vdC2n',
                           km=['kdCn'],
                           Rct=['C2P' + index, 'C1P' + index])

        #VIP/CREB Pathway
        SSA_builder.SSA_MM('CREB formation' + index,
                           'vgpka',
                           km=['kgpka'],
                           Prod=['CREB' + index],
                           Act=['eVIP' + index])
        SSA_builder.SSA_MM('CREB degradation' + index,
                           'vdCREB',
                           km=['kdCREB'],
                           Rct=['CREB' + index])

    for currentcell in range(cellcount):
        for affectedcell in range(cellcount):
            if adjacency[currentcell, affectedcell] != 0:
                #The Coupling Part
                rxn = stk.Reaction(
                    name='vip from ' + str(currentcell) + ' to ' +
                    str(affectedcell),
                    products={'eVIP_' + str(affectedcell) + '_0': 1},
                    propensity_function='vip_' + str(currentcell) + "_0*" +
                    'ktlnv' + '*' + str(adjacency[currentcell, affectedcell]),
                    annotation='')
                SSAmodel.addReaction(rxn)

    return SSAmodel, state_names, param_names
示例#7
0
def SSAmodel(fn, y0):

    #parameter initialization
    xlen = xdim
    ylen = ydim

    #Converts concentration to population
    y0in_ssa = (vol * y0).astype(int)

    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = []
    state_names = []
    y0in_pop = []

    #coupling section===========================
    for indx in range(xlen):
        for indy in range(ylen):
            index = '_' + str(indx) + '_' + str(indy)
            #loops to include all species, normally this is the only line needed without index
            species_array = species_array + [
                fn.inputSX(cs.DAE_X)[i].getDescription() + index
                for i in xrange(EqCount)
            ]
            state_names = state_names + [
                fn.inputSX(cs.DAE_X)[i].getDescription() + index
                for i in xrange(EqCount)
            ]

            y0in_pop = np.append(y0in_pop, y0in_ssa)

    #===========================================

    param_array = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]
    param_names = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]
    #Names model
    SSAmodel = stk.StochKitModel(name=modelversion)

    #creates SSAmodel class object
    SSA_builder = mb.SSA_builder(species_array, param_array, y0in_pop, param,
                                 SSAmodel, vol)

    #coupling section
    for indx in range(xlen):
        for indy in range(ylen):

            index = '_' + str(indx) + '_' + str(indy)

            # REACTIONS

            SSA_builder.SSA_tyson_x('x prod nonlinear term' + index,
                                    'X' + index, 'Y' + index, 'P')
            SSA_builder.SSA_MA_deg('x degradation' + index, 'X' + index, 'kdx')

            SSA_builder.SSA_MA_tln('y creation' + index, 'Y' + index, 'kt',
                                   'X' + index)
            SSA_builder.SSA_MA_deg('y degradation, linear' + index,
                                   'Y' + index, 'kd')
            SSA_builder.SSA_tyson_y('y nonlinear term' + index, 'Y' + index,
                                    'a0', 'a1', 'a2')

    return SSAmodel, state_names, param_names
示例#8
0
def PulseModel(fn, y0pulse):
    xlen = xdim
    ylen = ydim

    #Converts concentration to population
    y0in_pop_pulse = y0pulse.astype(int)

    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = []
    state_names = []

    parampulse = [2., 20., 1., 0.005, 0.05, 0.1, 0]
    #[P,  kt,  kd, a0,    a1,   a2,  kdx]

    #coupling section===========================
    for indx in range(xlen):
        for indy in range(ylen):
            index = '_' + str(indx) + '_' + str(indy)
            #loops to include all species, normally this is the only line needed without index
            species_array = species_array + [
                fn.inputSX(cs.DAE_X)[i].getDescription() + index
                for i in xrange(EqCount)
            ]
            state_names = state_names + [
                fn.inputSX(cs.DAE_X)[i].getDescription() + index
                for i in xrange(EqCount)
            ]
    #===========================================

    param_array = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]
    param_names = [
        fn.inputSX(cs.DAE_P)[i].getDescription() for i in xrange(ParamCount)
    ]
    #Names model
    PulseModel = stk.StochKitModel(name=modelversion)

    #creates SSAmodel class object
    Pulse_builder = mb.SSA_builder(species_array, param_array, y0in_pop_pulse,
                                   parampulse, PulseModel, vol)

    #coupling section
    for indx in range(xlen):
        for indy in range(ylen):

            index = '_' + str(indx) + '_' + str(indy)

            # REACTIONS

            Pulse_builder.SSA_tyson_x('x prod nonlinear term' + index,
                                      'X' + index, 'Y' + index, 'P')
            Pulse_builder.SSA_MA_deg('x degradation' + index, 'X' + index,
                                     'kdx')

            Pulse_builder.SSA_MA_tln('y creation' + index, 'Y' + index, 'kt',
                                     'X' + index)
            Pulse_builder.SSA_MA_deg('y degradation, linear' + index,
                                     'Y' + index, 'kd')
            Pulse_builder.SSA_tyson_y('y nonlinear term' + index, 'Y' + index,
                                      'a0', 'a1', 'a2')

    return PulseModel
示例#9
0
def ssa_resync(fn,
               y0in_desync,
               param,
               cellcount,
               adjacency,
               couplingstr=couplingstr,
               vol=40):
    """
    This is the network-level SSA model, with coupling. Call with:
        SSAcoupled,state_names,param_names = SSAmodelC(ODEmodel(),y0in,param)
    
    To uncouple the model, set adjacency matrix to zeros    
    """

    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = []
    state_names = []

    #coupling section===========================
    for indx in range(cellcount):
        index = '_' + str(indx) + '_0'
        #loops to include all species, normally this is the only line needed without index
        species_array = species_array + [
            fn.inputExpr(cs.DAE_X)[i].getName() + index
            for i in xrange(EqCount)
        ]
        state_names = state_names + [
            fn.inputExpr(cs.DAE_X)[i].getName() + index
            for i in xrange(EqCount)
        ]

    y0in_pop = y0in_desync

    #===========================================

    param_array = [
        fn.inputExpr(cs.DAE_P)[i].getName() for i in xrange(ParamCount)
    ]
    param_names = [
        fn.inputExpr(cs.DAE_P)[i].getName() for i in xrange(ParamCount)
    ]
    #Names model
    SSAmodel = stk.StochKitModel(name=modelversion)

    #creates SSAmodel class object
    SSA_builder = mb.SSA_builder(species_array, param_array, y0in_pop, param,
                                 SSAmodel, vol)

    # now set up mean field(?) coupling for all uncoupled cells

    #coupling section
    for indx in range(cellcount):

        index = '_' + str(indx) + '_0'

        #Coupled terms - - -------------------------------------------------
        #loops for all cells accumulating their input
        avg = 'M' + index
        mcount = 1

        for fromcell in range(cellcount):
            if adjacency[fromcell, indx] != 0:
                #The Coupling Part
                mcount = mcount + couplingstr
                avg = avg + '+M_' + str(fromcell) + '_0*' + str(couplingstr)
            if mcount == 1:
                # then the cell is "uncoupled" so we'll put it to a mean field
                for fromcell in range(cellcount):
                    mcount += couplingstr * 0.25 / cellcount
                    avg = avg + '+M_' + str(fromcell) + '_0*0.33*' + str(
                        couplingstr / cellcount)

        weight = 1.0 / mcount
        #FIXES PARAMETERS FROM DETERMINISTIC TO STOCHASTIC VALUES
        if (str(SSA_builder.pvaldict['vs0']) ==
                SSA_builder.SSAmodel.listOfParameters['vs0'].expression):
            SSA_builder.SSAmodel.setParameter(
                'vs0',
                SSA_builder.SSAmodel.listOfParameters['vs0'].expression +
                '*(' + str(SSA_builder.vol) + ')')
        if (str(SSA_builder.pvaldict['k1']) ==
                SSA_builder.SSAmodel.listOfParameters['k1'].expression):
            SSA_builder.SSAmodel.setParameter(
                'k1', SSA_builder.SSAmodel.listOfParameters['k1'].expression +
                '*(' + str(SSA_builder.vol) + ')')

        if (str(SSA_builder.pvaldict['alocal']) ==
                SSA_builder.SSAmodel.listOfParameters['alocal'].expression):
            SSA_builder.SSAmodel.setParameter(
                'alocal',
                SSA_builder.SSAmodel.listOfParameters['alocal'].expression +
                '*(' + str(SSA_builder.vol) + ')')
        #####
        #Adds reaction
        rxn = stk.Reaction(
            name='Cell' + str(indx) + '_Reaction0',
            reactants={},
            products={'M_' + str(indx) + '_0': 1},
            propensity_function=('std::max(0.0,(vs0+alocal*((' + avg + ')*' +
                                 str(weight) + '-M_' + str(indx) + '_0)))' +
                                 '*pow(k1,n)/(pow(k1,n)+pow(Pn_' + str(indx) +
                                 '_0,n))'),
            annotation='')  #

        SSAmodel.addReaction(rxn)
        #-------------------------------------------------------------------

        # REACTIONS
        SSA_builder.SSA_MM('Cell' + str(indx) + '_Reaction1',
                           'vm',
                           km=['km'],
                           Rct=['M' + index])

        SSA_builder.SSA_MA_tln('Cell' + str(indx) + '_Reaction2', 'Pc' + index,
                               'ks', 'M' + index)

        SSA_builder.SSA_MM('Cell' + str(indx) + '_Reaction3',
                           'vd',
                           km=['kd'],
                           Rct=['Pc' + index])

        #The complexing four:
        SSA_builder.SSA_MA_cytonuc('Cell' + str(indx) + '_Reaction4',
                                   'Pc' + index, 'Pn' + index, 'k1_', 'k2_')

    print 'weak, mean-field coupling'
    return SSAmodel, state_names, param_names
示例#10
0
def StochModel():

    #==================================================================
    # Stochastic Model Setup
    #==================================================================
    
    print 'Now converting model to StochKit XML format...'
    
    #Converts concentration to population for initial values
    y0in_stoch = (vol*y0in).astype(int)
    
    #collects state and parameter array to be converted to species and parameter objects,
    #makes copies of the names so that they are on record
    species_array = ['p', 'c1', 'c2', 'vip', 'P', 'C1', 'C2', 'eVIP', 'C1P', 'C2P', 'CREB']
                    
    param_array   = ['vtpr' , 'vtc1r' , 'vtc2r'  , 'knpr'   , 'kncr'   , 
                   'vdp'   , 'vdc1'  , 'vdc2'  , 'kdp'    , 'kdc'    ,
                   'vdP'   , 'kdP'   , 'vdC1'  , 'vdC2'   , 'kdC'    , 
                   'vdC1n' , 'vdC2n' , 'kdCn'  , 'vaCP'   , 'vdCP'   , 'ktlnp',
                   'vtpp'  , 'vtc1p' , 'vtc2p' , 'vtvp'   , 'vtvr'   , 
                   'knpp'  , 'kncp'  , 'knvp'  , 'knvr'   , 'vdv'    ,
                   'kdv'   , 'vdVIP' , 'kdVIP' , 'vgpcr'  , 'kgpcr'  , 
                   'vdCREB', 'kdCREB', 'ktlnv' , 'vdpka'  , 'vgpka'  , 
                   'kdpka' , 'kgpka' , 'kdc1'  , 'kdc2'   , 'ktlnc']
    
    #duplicated for names later
    state_names=species_array[:]
    param_names=param_array[:]
    
    #Names model
    SSAmodel = stk.StochKitModel(name=modelversion)
    #SSAmodel.units='concentration'
    
    #creates SSAmodel class object
    SSA_builder = mb.SSA_builder(species_array,param_array,y0in_stoch,param,SSAmodel,vol)
    
    # REACTIONS

    #per mRNA

    SSA_builder.SSA_MM('per mRNA activation','vtpp',km=['knpp'],Prod=['p'],Act=['CREB'])
    SSA_builder.SSA_MM('per mRNA repression','vtpr',km=['knpr'],Prod=['p'],Rep=['C1P','C2P'])
    SSA_builder.SSA_MM('per mRNA degradation','vdp',km=['kdp'],Rct=['p'])


    #cry1 mRNA
    SSA_builder.SSA_MM('c1 mRNA activation','vtc1p',km=['kncp'],Prod=['c1'],Act=['CREB'])
    SSA_builder.SSA_MM('c1 mRNA repression','vtc1r',km=['kncr'],Prod=['c1'],Rep=['C1P','C2P'])
    SSA_builder.SSA_MM('c1 mRNA degradation','vdc1',km=['kdc'],Rct=['c1'])
    
    #cry2 mRNA
    SSA_builder.SSA_MM('c2 mRNA activation','vtc2p',km=['kncp'],Prod=['c2'],Act=['CREB'])
    SSA_builder.SSA_MM('c2 mRNA repression','vtc2r',km=['kncr'],Prod=['c2'],Rep=['C1P','C2P'])
    SSA_builder.SSA_MM('c2 mRNA degradation','vdc2',km=['kdc'],Rct=['c2'])
    
    #vip mRNA
    SSA_builder.SSA_MM('vip mRNA activation','vtvp',km=['knvp'],Prod=['vip'],Act=['CREB'])
    SSA_builder.SSA_MM('vip mRNA repression','vtvr',km=['knvr'],Prod=['vip'],Rep=['C1P','C2P'])
    SSA_builder.SSA_MM('vip mRNA degradation','vdv',km=['kdv'],Rct=['vip'])
    
    #CRY1, CRY2, PER, VIP creation and degradation
    SSA_builder.SSA_MA_tln('PER translation' ,'P'   ,'ktlnp','p')
    SSA_builder.SSA_MA_tln('CRY1 translation','C1'  ,'ktlnc','c1')
    SSA_builder.SSA_MA_tln('CRY2 translation','C2'  ,'ktlnc','c2')
    SSA_builder.SSA_MA_tln('VIP translation' ,'eVIP','ktlnv','vip')
    
    SSA_builder.SSA_MM('PER degradation','vdP',km=['kdP'],Rct=['P'])
    SSA_builder.SSA_MM('C1 degradation','vdC1',km=['kdC'],Rct=['C1'])
    SSA_builder.SSA_MM('C2 degradation','vdC2',km=['kdC'],Rct=['C2'])
    SSA_builder.SSA_MA_deg('eVIP degradation','eVIP','kdVIP')
    
    #CRY1 CRY2 complexing
    SSA_builder.SSA_MA_complex('CRY1-P complex','C1','P','C1P','vaCP','vdCP')
    SSA_builder.SSA_MA_complex('CRY2-P complex','C2','P','C2P','vaCP','vdCP')
    SSA_builder.SSA_MM('C1P degradation','vdC1n',km=['kdCn'],Rct=['C1P','C2P'])
    SSA_builder.SSA_MM('C2P degradation','vdC2n',km=['kdCn'],Rct=['C2P','C1P'])
    
    #VIP/CREB Pathway
    SSA_builder.SSA_MM('CREB formation','vgpka',km=['kgpka'],Prod=['CREB'],Act=['eVIP'])
    SSA_builder.SSA_MM('CREB degradation','vdCREB',km=['kdCREB'],Rct=['CREB'])
    
    
    # END REACTIONS
    #stringSSAmodel = SSAmodel.serialize()
    #print stringSSAmodel

    return SSAmodel,state_names,param_names