Friday, May 6, 2011

Sample python script for doing perturbation experiments

# we are just going to change all the parameters that begin with the phrase 'synthconst'

items = tc_allItems()
params = tc_getParameters(items)


p = ""   #parameter name

#just count how many there are

total = 0  
for i in range(0,params.rows):
    p = tc_getRowName(params, i)
    if p.count('synthconst') > 0:
    total += 1

#for each parameter
j = 0
for i in range(0,params.rows):
    p = tc_getRowName(params, i)
    if p.count('synthconst') > 0:   #check parameter name
        tc_showProgress("DREAM automation", int((100.0 * j)/total))  #progress meter
        j += 1
        #perturb
        s = ""
        FILE = open(p + '.perturb.txt','w+')  #save to file
        p0 = tc_getMatrixValue(params, i, 0)  #original parameter value
        for q in [100, 10, 2, 1]:        #perturbations
            tc_setMatrixValue(params, i, 0, p0/q)
            tc_setParameters(params,0)
            m = tc_getSteadyState() #steady state
            s += str(p0/q)
            for i in range(0,m.rows):  #for each output value
                if tc_getRowName(m,i).count('m') > 0: #if name starts with m
                    s += "\t"
                    s += str(tc_getMatrixValue(m, i, 0))
                    s += "\n"
            FILE.write(s)
            FILE.close()
#done
tc_showProgress("DREAM automation", 100)  #close progress meter

No comments: