Thursday, June 30, 2011

Automatically test Design Variations

By using the tc_substituteEmptyModel and tc_substituteOriginalModel, it is possible to systematically remove each regulation from a design and check the results. The python plugin that does just that produces the following result. The code is given below. 

In the example below the input-output relationship is tested as different regulations in a feed-forward network are pruned.

category: Model Variations
name: Try Different Designs Automatically
descr: Try removing each individual regulation one at a time and see how that affects the model
menu: yes
icon: module.png
tool: no
from tinkercell import *

def runAll(indep, start, end, nclusters=0):
    items = tc_allItems()
    listOfModules = []
    moduleNames = []
    for i in range(0, items.length):
        item = tc_getItem(items, i)
        if tc_getParent(item) == 0:
            submodels = tc_listOfPossibleModels(item)
            if submodels.length > 0:
    n = len(listOfModules)
    if n > 0:
        tc_multiplot(2, int(1+n/2))
        tc_showProgress("Explore design variations", 0)
        for i in range(0,n):
            if indep.lower() == "time":
                m = tc_simulateDeterministic(start,end,100)
                tc_plot(m, moduleNames[i] + " removed")
                m = tc_steadyStateScan(indep, start,end,10)
                tc_plot(m, moduleNames[i] + " removed")
            tc_showProgress("Explore design variations", int(100*(i+1)/n))

        tc_showProgress("Explore design variations", 100)
        if nclusters > 1:
            m = tc_clusterPlots(nclusters)
            fout = open("designs.txt","w")
            for i in range(0, nclusters):
                s = "========\nCluster " + str(i+1) + "\n========\n"
                for j in range(0, n):
                    if tc_getMatrixValue(m, j, 0) == i+1:
                        s += " ,  " + moduleNames[j]
                        s += "\n"
                    s += "\n"
        if indep.lower() == "time":
            m = tc_simulateDeterministic(start,end,100)
            tc_plot(m, "steady state scan")
            m = tc_steadyStateScan(indep, start,end,10)
            tc_plot(m, "simulation")

params = tc_getParametersAndFixedVariables(tc_allItems())
list = fromTC(params.rownames)
inputWindow = tc_createMatrix(3, 1)
tc_setMatrixValue(inputWindow, 0, 0, 0)
tc_setMatrixValue(inputWindow, 1, 0, 0.0)
tc_setMatrixValue(inputWindow, 2, 0, 200.0)
tc_setMatrixValue(inputWindow, 3, 0, 4)
tc_setRowName(inputWindow, 0, "Independent variable")
tc_setRowName(inputWindow, 1, "Start")
tc_setRowName(inputWindow, 2, "Stop")
tc_setRowName(inputWindow, 3, "Clusters")
tc_createInputWindowForScript(inputWindow, "Explore design variations", "runAll")
tc_addInputWindowOptions("Explore design variations", 0, 0, toTC(list))

Friday, June 24, 2011

Optimize any Python Function using Particle Swarm

The code given below was used to generate parameter set for making a non-monotonic input-output steady state plot. The code uses Particle Swarm optimization algorithm. It allows multiple runs of the algorithm for finding multiple minima.

from tinkercell import *
from tc2py import *
from numpy import *
from PSO import *  #particle swarm optimization (included with TinkerCell)
nameOfInput ="INPUT" #name of input variable in the model
nameOfOutput ="OUTPUT" #name of output variable in the model
params = tc_createMatrix(1,1)
def Objective():
    tc_setMatrixValue(params, 0, 0, 0.1)
    ss = tc_getSteadyState()
    i = tc_getRowIndex(ss, nameOfOutput)
    x1 = tc_getMatrixValue(ss, i, 0)
    tc_setMatrixValue(params, 0, 0, 2)
    ss = tc_getSteadyState()
    x2 = tc_getMatrixValue(ss, i, 0)
    tc_setMatrixValue(params, 0, 0, 5)
    ss = tc_getSteadyState()
    x3 = tc_getMatrixValue(ss, i, 0)
    if x3 > x1: x1 = x3
    return (x2 - x1)
optimizer = ParticleSwarm()
#minimize or maximize?
optimizer.numpoints = 50
optimizer.maxiter = 10
optimizer.minimize = False
optimizer.title = "Nonmonotic test"
g =,10) #multiple runs

Saturday, June 18, 2011

Automatically test Model Variations

The is a new python plugin that tries all the different models for the same "diagram". For example, in the diagram below two enzymes catalyze the conversion to themselves, i.e. both are autocatalytic. One might suspect that such a system will become bistable, somewhat like the genetic toggle-swtich. However, this system is only bistable when modeled using steady state assumptions (i.e. Michaelis-Menten) and monostable when modeled using simple mass-action reactions. This python plugin can be used to varify such model-dependent behavior. This shows how models should be double-checked before trying to use them to make conclusions about the real system.

Improved Clustering Function

The tc_clusterPlots function now returns the results of the clustering. Earlier, it was just plotting the clusters. Now, plugins can use the returned values to identify which plot each of the inputs belong in. For example, the plugin uses this information to identify sub-models (e.g. whether or not to include mRNA, how to model transcription regulation) that are responsible for creating different behaviors. The plugin outputs the cluster plots and outputs the sub-models in each cluster in a file.

Cluster plots

and the sub-models for each cluster

...the file contains all the clusters, but those are not shown here.

Thursday, June 16, 2011

Composite Parts

Composite parts were present in TinkerCell for some time, but they did not behave nicely. Now they do. Composite parts are basically containers with other parts. They can be snapped together.

Tuesday, June 7, 2011

An architecture for incorporating experiments

The above diagram represents a general data-representation TinkerCell is assuming. TinkerCell represents the "biology" (not the mathematical model). There are methods such as numerical analysis or wet-lab experiments that take the biology and generate data. The middle area (i.e. experiments and simulations) should connect the biology to the data -- probably the main challenge.

Monday, June 6, 2011

Load GenBank & Data from

The above screenshots are from a python plugin that gets BioFAB ( parts and automatically places the parts on the screen. It also plots the experimental data available at BioFAB.

The next step is to automatically generate the model and perform basic parameter estimation.

"Dim" certain regions of the model

The "sun" icon next to the zoom icons in the top toolbar allows users to adjust the transparency of selected regions on the screen.