Saturday, April 25, 2009

Improved way to convert Python and C into buttons and more

"menu.txt" has been replaced with "clibraries.txt" and "pythonscripts.txt", because the fashion in which C libraries and Python scripts were loaded into TinkerCell has been reconstructed. Both of the new files contain much more flexibility about where and how the C and Python programs run. The screenshot on the right shows Python scripts in the context menu and the tools.

Here is how it works now:

The DynamicLibraryMenu class provides the following functions:

addFunction : adds a function to the functions tree.
arguments: function category, name, and icon

addMenuItem : adds a function to the function menu at the top (play button).
arguments: function name and icon

addContextMenuItem : adds a function to the context menu (mouse right button) when items of a particular family are selected; optionally shows the graphical tool.
arguments: target family, function name and icon, and whether or not to show the graphical tool

Therefore, this class simply serves to add actions and buttons to the functions tree, tool bar, and context menu. The actual actions themselves are determined by two other classes:

The LoadCLibrary class performs the following tasks:
  1. read and parse clibraries.txt
  2. setup the signals and slots that call each function specified in clibraries.txt
  3. place actions and toolbuttons using DynamicLibraryMenu
This class can be summarized by the following logic:

text file ---> actions group
action triggered ---> get name ---> get library name ---> new LibraryThread

The PythonTool class performs the following tasks:
  1. read and parse pythonscripts.txt
  2. host the Python interpreter thread
  3. setup the signals and slots that call each script specified in pythonscripts.txt
  4. place actions and toolbuttons using DynamicLibraryMenu
This class can be summarized by the following logic:

text file ---> actions group
action triggered ---> get name ---> get file name ---> call runPy

Rationale for the new setup:

  1. More modular: if a new interpreter needs to be hosted, say Ruby, then it can use the same format at the PythonTool class.
  2. More GUI: a C and Python program can appear in up to four places, i.e. the functions tree, the main toolbar menu, context menu, graphical tools




Sunday, April 19, 2009

Data get/set C and Python routines

One of the chief design features in TinkerCell is the ability to store tables associated with items or the model. For example, a typical reaction would have a Numerical Data Table called "Stoichiometry" and a Text Data Table called "Rates". Most items have a Numerical Data Table called "Numerical Attributes", i.e. parameters. 

Now, there are certain plug-ins, e.g. the flux balance analysis plug-in, that store data in the model, not pertaining to any particular item. These data are stored in the scene->symbolsTable.modelItem item. 

Plug-ins may provide easier C and Python functions to access these tables, e.g. functions like stoichiometry(), setRates(), getRates(), etc.

But, the Core library provides generic Python and C functions to access any of these data:

use getNumericalDataNames(item) and getTextDataNames(item) to get the list of all table names for that item. Use a null argument to get the tables for the model item.

similarly, there is setNumericalData(item,tablename,rowname,colname,value), getNumericalDataMatrix(item,tablename), and a few other functions.

Saturday, April 18, 2009

Improved Plot Window


The plot window can show multiple plots, as shown above. 

The plot window provides an input box for users to write any set of functions and plot those functions. This feature should be useful when designing rate expressions or other functions in the model, i.e. the user can copy the rate expressions here and plot them to see what they look like.

The options on the right-hand side of the input box allow users to specify the variable on the x-axis and other details of the equations they want to plot.

Monday, March 16, 2009

Highlighting and Label items on the screen


The CLabelsTool allows labeling and highlighting (drawing circles) on objects on the screen. It also provides convenient C/Python API functions, allowing C and Python programs to label and/or highlight items on the screen. 

The C/Python functions are called displayText, displayNumber, and highlight. The C++ signals are also named the same.


Saturday, March 14, 2009

Search E.coli genetic network using RegulonDB

A python program, RegulonDB.py, loads the RegulonDB tab delimited files into hash tables. A second python program, searchRegulonDB.py, uses these hash tables to allow users to replace items on a model with items in the RegulonDB database. The interface makes use of the getFromList API function, which also includes the search feature.




With this python function, users can:
  • get RBS, terminator, or promoter sequences along with RegulonDB ID
  • get the list of regulatory parts for one or more selected transcription factor
  • get the list of transcription factors for one or more selected regulatory parts

Friday, March 13, 2009

Displaying List of Strings from C and Python

The C function tc_getFromList , or the equivalent python function pytc.getFromList allows C and Python programs to display either a list or a drop-down menu. When the user makes a selection, the index of the selection will be returned.

The following command generated the above dialog.

pytc.getFromList("What will you have for dinner?",("fruits and nuts", "bowl of cereal", "pasta and veggies", "sandwich", "oats and nuts"),0)


Changing the last argument will change the display to a drop-down menu (combo box), as shown below.

pytc.getFromList("What will you have for dinner?",("fruits and nuts", "bowl of cereal", "pasta and veggies", "sandwich", "oats and nuts"),1)



Flux Balanace Analaysis and generic C interfaces

It is difficult to create intricate interfaces using the C API. What is more practical is to just write a C++ plugin. So, suppose you need a relatively complicated interface for a C function, then the procedure is as follows:

  • design the interface using Qt C++
  • write the C program and make it into a dynamic library
  • make the C++ plugin call the C program using LibraryThread
  • place the C++ dynamic library in the "menu.txt" file so that it appears along with the other "functions".
The Flux Balance Analysis function is one such example. The interface is a regular plugin, but it calls the C program (lpsolve.c) when the run button is pressed. The plugin can therefore respond to selection events and other events. The plugin creates a matrix that is passed on to lpsolve.c as input.

Normal C dynamic libraries are loaded using the LibraryThread class. However, since these C++ programs are different, the LibraryThread performs a check to see whether the "loadTCTool" function exists in the library. If it does exist, then the library is loaded as a plugin on the main thread and not as a threaded C program, which is usually on a separate thread.



The diagram above shows how different libraries are loaded. Essentially, if the library contains the "run" function, it is assumed to be a C program. If it contains the "loadTCTool" function, it is assumed to be a C++ library that adds a new tool to the main window. The LibraryThread runs the C program on a separate thread and unloads the library when the program is finished. The C++ libraries represent widgets and other such tools which are only unloaded when TinkerCell exists.

Sunday, March 8, 2009

Integrated Antimony

Antimony script is now integrated into TinkerCell. The NetworkX python module is used to perform the layout, since Antimony scripts do not contain graphical information.

More importantly, the visual side and the script side (Antimony) can update one another. This allows a user to shift from script view to and from graphical view any time.

Linear Programming with LPsolve

The lpsolve library has been integrated into TinkerCell. The code is in c/lpsolve.c and the lpsolve package is included in the c/lpsolve directory. 

The generic outline of the code is as follows:

  • get selected connections (error if none)
  • get stoichiometry for all items
  • find columns of the stoichiometry corresponding to selected items
  • setup lpsolve with the selected connections as the objective 
  • setup lpsolve with the stoichiometry as the constraint
  • solve
  • get the optimal values and post them on the screen using tc_displayText

Symbols Table

Each GraphicsScene now contains a "symbols table". This table contains three hash tables:

1) handle FULL names ----> pointers to handles
2) handle FIRST names ----> list of all handles (pointer) with that name
3) data row and column name ----> list of pairs that indicates the handle and the tool (name of tool) where the row or column name comes from

The symbols tables are updates during each event (history update).
An example where the symbols tables are used is in the rate equations. When a user types a rate equation, the Stoichiometry Tool looks at the symbols table to determine whether the parameters in that rate equation already exist somewhere in the model. 

The container tool (which provides the Attributes View window) also uses the symbols table to get a list of all the handles.