Tuesday, April 22, 2008

Getting to grips with Scientific Computing Tools on a MAC-osX


For somebody who spent time (and I am not proud of it) on a win32 machine and was quite happy even from a 64bit machine to keep programming 32bit, and sending off code to the big UNIX machines, its a bit of a mixed bag to be sitting at a Mac OS X terminal. MacBookPro. For one it needs a lot of beer.
Then it needs Octave - for which there is a binary installer available. But to plot anything you need gnuplot- anybody with Linux or Cygwin will tell you that- how on Mac I pray- well get the gnuplot precompiled file. Set the .profile files to set the path to the applications:

alias gnuplot="/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot"
alias octave="/Applications/Gnuplot.app/Contents/Resources/bin/octave"

Oh, and as you might discover you have bash shell (mac OS X 10.5.*) but no .profile or .bash_profile file, then make it and add those lines to it. Kippis! Shanti.

Well. The Octave user list was VERY useful in fixing that. Here is the fix:

//------------------------
The alias command sets up a variable that applies only in your shell.
It won't help octave find gnuplot. You probably need to set up a symbolic
link to gnuplot in some directory on your path. Try:

ln -s /Applications/gnuplot/Gnuplot.app/Contents/Resources/bin/gnuplot \
/usr/local/bin/gnuplot

If this complains about permission precede this with a sudo and enter your
password when prompted.
//------------------------
"Mein f******, I can plot again", to rephrase Dr. Stragelove or Doktor Merkwuerdigliebe from Dr. Strangelove.

Wednesday, April 09, 2008

Compiling AgentCell

So it works! And it was a SIMPLE little fix:

===========
# Note the file list.
filelist="c:/cygwin"$PWD"/filelist"
===========
All else remains the same. So the final javacompile file looks like this:

----------------------------------------------------------------------
#!/bin/bash -x

# Note the initial directory.
calldir=$PWD

# Note the file list.
filelist="c:/cygwin"$PWD"/filelist"

# Move to the initial directory.
cd $calldir

#DEFINE the win32 native java install using cygdrive reference to drive C:\
#JPATH=/cygdrive/c/Java/jdk1.6.0_05

# Find the available Java files.
find edu -name *.java -print > $filelist
find uchicago -name *.java -print >> $filelist

#show filelist
#cat $filelist

# Compile the available Java files.
javac -classpath .:lib/repast.jar:lib/colt.jar:lib/commons-collections.jar:lib/commons-logging.jar:lib/geotools.jar:lib/jakarta-poi.jar:lib/jgl3.1.0.jar:lib/jh.jar:lib/jmf.jar:lib/JTS.jar:lib/junit.jar:lib/log4j.jar:lib/mediaplayer.jar:lib/multiplayer.jar:lib/plot.jar:lib/sound.jar:lib/trove.jar:lib/xerces.jar:lib/hdf4.jar:lib/jhdf4obj.jar:lib/jhdf.jar:lib/jhdfobj.jar @$filelist
#javac -cp .:lib/repast.jar:lib/colt.jar:lib/commons-collections.jar:lib/commons-logging.jar:lib/geotools.jar:lib/jakarta-poi.jar:lib/jgl3.1.0.jar:lib/jh.jar:lib/jmf.jar:lib/JTS.jar:lib/junit.jar:lib/log4j.jar:lib/mediaplayer.jar:lib/multiplayer.jar:lib/plot.jar:lib/sound.jar:lib/trove.jar:lib/xerces.jar:lib/hdf4.jar:lib/jhdf4obj.jar:lib/jhdf.jar:lib/jhdfobj.jar:./edu/*:./uchicago/*


# Clean up.
rm $filelist

----------------------------------------------------------------------

Now to actually try to do the calculations the AgentCell bactertial paper did. Somehow my first tries aren't too promising! :) More later.

-------------------
However, it seems that the RePast libraries aren't being properly recognized. Since I had a good experience working with RePast and Eclipse as an IDE, decided to switch to that. Imported the source file structure. It compiles, and linked stochsim.dll with the following command to the VM:

-Djava.library.path=$libstochsimpath

Oddly the example doesn't compile asking for an output folder etc. So to all obvious purposes that part works.

Tuesday, April 01, 2008

Stochastic Reactions and Agent-Cells

I have decided to branch back (off... can't think of the right preposition) to spatial pattern formation with agents. I had previously worked with an Agent Toolkit- RePast- Recursive Porous Agent Simulation Toolkit. At that point I had implemented a Network and Compartment class in the general agent simulator to model mass balance kinetics with an ODE (Athale et al. 2005). The original multi-agent model to model tumor expansion was work done by Yuri Mansury (Mansury et al. 2002). However the Network implementation was rather crude- Euler finite time stepping forward integration scheme. About the time I moved back to single-cell and possibly experimentally tractable, however phenomenologically less rich systems, a library of agent based simulations Agent-Cell was released (Emonet et al. 2005). Michael North, one of the co-authors on this paper, is also one of the developers of RePast. The big leap from RePast was an integration with numerical ODE solver libraries and bindings to a real stochastic reaction simulator- StochSim. The tool was used to examine bacterial chemotaxis models- for a single bacterium and allow for bacterial swimming behaviour to be simulated.

I am now trying to compile the package (2008-04-01, 20:15:00) and see if I can modify it to my purposes. My goal is to levarage my experience (and joy) in working with agent based systems and model eukaryotic cellular processes with it. Possibly the stochastic simulator might be the right tool to address issues of stochasticity and multi-stability in reaction networks while at the same time studying spatial patterns!

The initial part is done. StochSim compiles with some flags changed in the makefile for CYGWIN under win32. Here are the modifications:

######################################################
# Options to build the release version with
# cygwin on windows assuming that C:\cygwin\BIN is on
# the path.
# If you are using eclipse, make sure to append
# C:\cygwin\BIN to the PATH in
# project->Properties->C/C++ Make->Environment
######################################################
# ### Shell
SHELL = /bin/sh

# ### Copy
CP = cp

# ### Remove
RM = rm -f

# ### Java
#JAVA_HOME = /cygdrive/c/Program\ Files/Java/j2sdk1.4.2_10
#JAVA_HOME = /cygdrive/c/Program\ Files/Java/jdk1.5.0_06
JAVA_HOME = /cygdrive/c/Java/jdk1.6.0_05
# ### Compiler
CXX = g++
OPTS = -D_STD_CPP -D_UNIX -D_DYNAMIC_UPDATE
CXXFLAGS = -mno-cygwin -O3 -Wall -Wno-deprecated \
-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32
OPTS = -D_DEBUG -D_STD_CPP -D_UNIX
CXXFLAGS = -g -mno-cygwin -Wall -Wno-deprecated \
-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32



# ### Linker
LD = g++
LDFLAGS = $(CXXFLAGS) -L$(JAVA_HOME)/lib -ljvm
#LDFLAGS = $(CXXFLAGS)
STOCHSIM_EXE = stochsim.exe

# ### Library
MKLIB = g++
LIBFLAGS = $(CXXFLAGS) -Wl,--add-stdcall-alias -shared
STOCHSIM_LIB = stochsim.dll

# ### Installation
BINDIR = ../bin/
LIBDIR = ../lib/


=============================================================

The agent-cell compile still doesn't work! But maybe the answer lies in the post from the AgentCell website for Win32 instructions:

Hi Iqbal,

AgentCell is written in Java so it will work on any platform. However it
includes StochSim that is written in C++ and therefore must be
compiled for the platform you are using.
I have never used AgentCell on windows. The way I would go about it is
as follows:
1) Install cygwin (http://www.cygwin.com/) on windows. Cygwin will
provide a "Linux" under windows. When you install cygwin make sure to
include the development tools. In particular the compilker gcc (or
g++)
(but not the java extensions to gcc: you want to use the native java
compiler from the Java SDK instead).

2) Open a cygwin prompt window and install the Linux version of Java
SDK
1.4 (http://java.sun.com/j2se/1.4.2/downloads/index.html) under Cygwin

3) Open a cygwin prompt window and install AgentCell following the
instructions we give for Linux.

Thierry

================= Maybe there be hope? ===============
We shall see.

I already have the latest java compiler from Sun, but its a Win32 install- therefore it understands only win32 native paths eg: C:\Java\etc. However Cygwin is Unix based and understands UNIX paths eg: C:/Java/etc. Further complicating the matter is a call from under Cygwin to the Windows javac.

The solution appears to be to use

cygpath -u for UNIX
cygpath -w for WIN

and to criss-cross as necessary. Lets see if this works.

The javacompile file is fairly mutilated by now!









References


  1. Athale C, Mansury Y, Deisboeck TS. (2005) Simulating the impact of a molecular 'decision-process' on cellular phenotype and multicellular patterns in brain tumors. J Theor Biol. 2005 Apr 21;233(4):469-81. Erratum in: J Theor Biol. 2006 Apr 21;239(4):516-7.


  2. Mansury Y, Kimura M, Lobo J, Deisboeck TS. (2002) Emerging patterns in tumor systems: simulating the dynamics of multicellular clusters with an agent-based spatial agglomeration model. J Theor Biol. 2002 Dec 7;219(3):343-70.


  3. Thierry Emonet 1,*, Charles M. Macal 2, Michael J. North 2, Charles E. Wickersham 1 and Philippe Cluzel (2005) "AgentCell: a digital single-cell assay for bacterial chemotaxis", Bioinformatics 21(11), 2714-2721 (online)