trfit is a program for fitting time-domain (Time Correlated Single Photon Counting, TCSPC) fluorescence data with various mathematical models. This page should help you to get up to speed with it. One caveat upfront: trfit is command-line driven, which means that you need to drop your mouse and type commands like
trfit mode=fit data=*.dat model=exp1 tau=2 izero=4
into a console window (on Windows this is called a command prompt). This may take some getting used to, but is in some ways more effective than a graphical user interface.
1. Install the prerequisites
trfit requires several the following pieces of software:
These are not included in trfit, so you have to install them yourself. The installation procedure depends on your system.
Windows: If you haven't used Python previously, Python most likely isn't installed. Download the installers from the above websites and run them in sequence. Take care to match the versions of all libraries to that of the main Python version. As of July 2009, the main version of Python is 2.6. The matplotlib site offers an '.egg' installer up front - avoid this foul egg and instead click your way the .exe installer.
After running the installers, open a command prompt (DOS) window and type
python <enter>. If you see some message and an
>>> prompt, Python started; if you get an error message
instead, you have to add Python's root directory (c:\Python26 or similar by
default) to the system's path: Control panel -> advanced -> environmental
variables, PATH -> edit: Append ;c:\Python26 and save. Close
and re-open the DOS window and try again.
As an alternative to the stepwise installation, you might consider the Enthought or the Python(x,y) distributions, which include Python and all prerequisites in one single installer, along with huge amounts of other stuff you may never need. I have not tried either myself.
Linux: On most Linux distributions, Python will already be installed, and the libraries should be just a few mouse clicks away in your package manager. (Debian Linux has lots of software for scientific computing. Try it.)
Mac: I have no Mac and therefore I won't give any hypothetical instructions here. However, I have been told that trfit worked on a Python 2.6 install on a Mac.
2. Install trfit
On both Linux and Windows: Download the trfit zip file, save in a convenient location and unzip. Open a console window and change into the directory trfit-1.1 that you just created by unzipping. Type python setup.py install and hit Enter. Note that this step usually requires administrator privileges. cd back to your home directory and try to run trfit. If you see a short blurb describing the program, everything should work now. If you get an error instead, try appending the trfit directory to the system path (see above for Windows; Linux users are supposed to know how to do it). If it still doesn't work, installation failed - may be a permission problem. Become root (Linux) or log on as a user with administrator privileges (Windows) and try installation again.
Installation reportedly has succeeded on Macs, too, but I have not done it myself.
This tutorial assumes that you are already familiar with the TCSPC technique. Just to make certain that we are on the same page with respect to terminology:
Now, let's get started.
The directory that you created when unzipping trfit also contains an example directory. Inside this directory, you will find a couple of actual experimental fluorescence decays, all named using the extension dat, another data file (named irf) that contains the matching instrument response function, and a couple of command files. We will use these to quickly illustrate the program's functionality.
The command you just typed caused trfit to read the instructions
contained in the file named showfiles. Close the curve displays
and have a look at the content of this file by typing the command cat
showfiles (Linux) or type showfiles (Windows). The file
contains both instructions and some explanations (prefixed with
#). If you want to read more on an individual parameter, type
e.g. trfit help timestart. For an overview of all parameters, type
trfit help parameters.
You should look at the content of the other files discussed here, too - the comments will give you additional hints on how to use trfit effectively.
notepad
showfiles). model=exp2 to apply a two-exponential model. The chi-square is
much lower now, but you may notice that the fitted baseline is not ideally
placed in the first part of the curve. To allow trfit to
optimize the baseline, addfloatbaseline=yes. You
may want to try model=exp3 or model=exp4 as well.
So far, the initial parameters for the fits were guessed by
trfit automaticaly. Type trfit cmd=fitshow
mode=calc,show to see the initial guesses applied without fitting.
(Yeah, pretty bad.) File fitshow2 illustrates how to supply explicit values
for the parameters. With simple models such as exp1 and exp2, there should
be no need for this, but fits that use more complex models may require some
reasonable starting values to succeed.
trfit cmd=fitshow mode=fit,dump dumpext=csv. No graphics
will show up, but you will now find a new file with the extension
.csv appended. This file contains all experimental data points,
the corresponding fitted values, and the residuals, in a format that is
easily imported into spreadsheets or other plotting software. trfit cmd=fitbatch. This fits all files that match the
pattern eNOSpep*mM.dat to the two-exponential model. trfit cmd=fitglobal. A global fit will be performed
for parameters tau and tau2, meaning that the same values
for these parameters are applied across all data files, and the overall
chi-square is minimized. The other two parameters (izero and
izero2) remain individually variable for each data file, however.
Because each data file has to be fitted many times over, this global fit
takes a while to run, but it's not too bad, really, thanks to the hard work
of the people at Numeric Python - and the Fortran programmers that supplied
the underlying libraries. This short tour of trfit has already illustrated most of its functionality. For additional info, have a look at the output of trfit help parameters, trfit help reports and trfit help models.
trfit mode=show data=yourfile
on it. You should see at least one curve, which should be the decay; if you
see two curves, the second one should be the IRF. If you don't see
anything, try opening the file in a text editor. If it is human-readable
and not a garbled (binary) mess, see whether you can figure out whether you
can adjust the xcolumn, ycolumn andirfcolumn
parameters to read the file (specifying a separate irf file as needed). If
everything fails, send me an example file (mpalmer at uwaterloo dot ca).
tau=1,0.5,1.5 and tau2=4,3,6 to
restrict the range of these parameters to 0.5-1.5 and 3-6 respectively; in
this way, you can ensure that tau will always remain the shorter of the two
lifetime components. You may have noticed that the mathematical models that come with this distribution are a little limited. How can you use other models, tailored to your needs? There are two possibilities:
To pursue option 1, have a look at modules numericmodels.py and model.py. Your own models will most likely inherit from class model.ExponentialModel. This class works as follows:
calculateExponentials calculates a list of 2-tuples,
each of which contains one pre-exponential and its associated lifetime.
Most of the time, you will need to override this method; look at classes
models numericmodels.ConstrainedTriple and
numericmodels.NormalDistribution for examples. applyExponentials will expand and accumulate all
these lifetime components; it should not normally need to be overridden.
Where should you keep your own models? You might save them in the
trfit source directory; the problem then is that they might
get lost inadvertently when you upgrade trfit. So, you probably want to keep
them in a location elsewhere along your Python path. trfit
assists you with this by trying to run from usermodels import *
during program startup, and likewise from userreports import *.
If you are familiar with python, you will know how about the various ways to
make any such modules visible to trfit.
You may also want to develop your own customized reports. A good, concise description of how reports work is beyond my powers of narration; however, a look at module reports.py and its immediate buddies may tell you enough about how to accomplish at least some simple customizations.
Lastly, if you have written a new model or report class, I'd like to hear from you, so that it can be included in future releases of trfit. Of course, if you find bugs or have suggestions for improvement, I'd appreciate a message, too.
Here, I describe some of trfit's inner workings. This information may be of interest if you are considering to extend trfit with added functionality. It will only make sense to you if you are familiar with the Python language, or rather, it won't if you aren't ;-)
trfit really does not much more than string together the mathematical library functions supplied by the Scientific Python / Numerical Python libraries. Likewise, the graphical display is adopted wholesale from matplotlib. These underlying libraries, in turn, rely to a large extend on C- and Fortran-coded libraries, which lets trfit benefit from the efficiency of those languages. Such library functions are used at various stages:
trfit uses a heuristic approach to the parsing of data files, which employs the following rules:
Input parsing is implemented in module loaddata.py.
The results of numerical fits can be post-processed for presentation or
evaluation. For an overview for all 'raw' output available, run a fit with the
option report=fulltable. Examples of post-processed output can be
seen with report=normtable. For each file that was fitted, this
output is passed around as a list of (name, value) tuples. In addition, there
is a list that contains global information, such as the average chi-square.
The base classes dealing with all of this are implemented in processresults.py, while the special subclasses are found in resultprocessors.py.
Maintained by Michael Palmer, University of Waterloo