Skip to main content Skip to navigation

Calling LineageTracker from a macro

From version 1.1.4 onwards, it became possible to control LineageTracker using ImageJ macro commands.

Creating Experiments

The Create Experiment module has been extended to take macro parameters to specify which experiment is to be created. To use:

  1. Load the images into ImageJ
  2. Call the "Create From Open" command, passing a single string with the following details:
    • expdir=/path/to/data/directory
    • filename=name of experiment
    • segment=true/false
    • channels=[1 2 etc] (channels to use in segmentation) or miss out the brackets, eg. channels=1, if only using one channel
    • method= full class name of segmentation method

e.g.

run("Create From Open","expdir=/Users/data/,filename=test1,segment=true,channels=[1],method=segmentation.RadialGrowth_Segmentation");

The segmentation method requires the full java class name. If no segmentation method is provided, the last used method will be used. Segmentation parameters are taken from the last used values stored in IJ_prefs.txt
Adding 'close=true' will close the imported images once the experiment has been created – this will reduce the amount of memory required.

Running the Segmentation module

To re-segment an experiment, or to perform segmentation if an experiment was set up as above but 'segment=false' was used, the segmentation can be performed from a macro as follows:

run("Segmentation","dir=/Users/data/,exp=test1,run=true");

Calling the 'Segmentation' plugin with run=false will open the window without performing segmentation.

Running Tracking

The 'Run Tracking' plugin allows tracking to be run or re-run independently of segmentation and viewing, either by opening the dialog box from the 'Plugins->LineageTracker->Run Tracking' menu item or through macro commands. To call from a macro, run:

run("Run Tracking","expdir=/Users/data/,filename=test1,method=Tracking (No Divisions),settings=[]");

The 'method' is the textual representation of the tracking method, unlike the Segmentation plugin which uses the java class method. The settings array holds the tracking parameters in the following order:
Distance Weight, Distance Threshold,Size Weight, Size Threshold,Intensity Weight (same for all channels), Intensity Threshold.
e.g. [0.75 25 0.5 50 0.5 50]

Viewing and Saving Results

The data analysis and reporting plugins are all called from the Experiment Viewer, which has been modified so only a single instance can be open at once. This is to ensure that macro commands can only go to a particular copy of the software. Open an experiment using:

run("Experiment Viewer", "dir=/Users/data/,exp=test1,ShowImages=false");

In most cases it is possible to use ShowImages=false to avoid loading the images. This improves both speed and memory usage. If any of the plugins require access to the image data then it will be necessary to use ShowImages=true.

Commands can be sent to the Experiment Viewer using the 'Run Plugin' command. This is used to run analysis plugins and to call some internal functions of the viewer itself.

Setting Channel Properties

The experiment stores information on the colour and visibility of the image channels. These may be changed using the command below. The new values will only be stored if the experiment info is saved (see below).

run("Run Plugin","channel=1,visible=false,colour=[0 255 255]")

Channel numbers start at 1. The mask channel is stored as the final channel, so will be channel 3 of a 2-channel experiment.

Running Plugins

Data analysis and reporting plugins may be called using

run("Run Plugin","plugin=plugin name");

where plugin name is the name displayed on screen in the Experiment Viewer. To redraw the window after calling the plugin, add 'redraw=true' to the end of the line, eg.

run("Run Plugin","plugin=plugin name,redraw=true");

For example,

run("Run Plugin","plugin=Highlight Dividing Cells,redraw=true");

will highlight cell divisions and redraw the screen.

Saving Results

There are three levels of data saving:

run("Run Plugin","save=info");
run("Run Plugin","save=data");
run("Run Plugin","save=all");
  1. 'save=info' only saves the experiment info file without saving the cell data. Use this if only the channel colour or visibility has been changed.
  2. 'save=data' saves the experiment info and the segmentation and tracking data.
  3. 'save=all' saves the above data and the image files. This is the same as clicking 'Save' in the experiment window.

To close the experiment window, run:

run("Run Plugin","close=true");

Editing Settings

Most LineageTracker settings are stored within the ImageJ Preferences file and can be accessed using the ij.Prefs framework. To change settings, use the 'call' macro command, for example

call("ij.Prefs.set","TrackApp.DEBUG","true");

will change the debug setting to true, which displays debug information to the Log window.

Changing Segmentation Settings

The values in the 'Segmentation Parameters' and 'Experiment Settings' windows can be changed using the commands below:

call("ij.Prefs.set","TrackApp.SEGMENTER","segmentation.RadialGrowth_Segmentation");
call("ij.Prefs.set","TrackApp.MaxTol","4");
call("ij.Prefs.set","TrackApp.GrowThresh","0.5");
call("ij.Prefs.set","TrackApp.GrowIter","30");
call("ij.Prefs.set","TrackApp.PreBlur","true");
call("ij.Prefs.set","TrackApp.PreBlurRadius","1.0");
call("ij.Prefs.set","TrackApp.BlurSigma","4");
call("ij.Prefs.set","TrackApp.USMwt","0");
call("ij.Prefs.set","TrackApp.USMwt","0");
call("ij.Prefs.set","TrackApp.MinSize","1");
call("ij.Prefs.set","TrackApp.MaxSize","10000");
call("ij.Prefs.set","TrackApp.MergeROIs","false");
call("ij.Prefs.set","TrackApp.BkgRadius","100");
call("ij.Prefs.set","TrackApp.DoBKG","false");
call("ij.Prefs.set","TrackApp.SegBKG","true");

Changing Tracking Settings

Tracking settings can be changed in a similar manner to above.

call("ij.Prefs.set","TrackApp.LastTracker","Division: Nearest Cell");
call("ij.Prefs.set","TrackApp.DistThresh","25");
call("ij.Prefs.set","TrackApp.DistWeight","1");
call("ij.Prefs.set","TrackApp.AreaThresh","50");
call("ij.Prefs.set","TrackApp.AreaWeight","0.5");
call("ij.Prefs.set","TrackApp.IntThresh","25");

It is possible to give different weights to the image channels using the following command:

call("ij.Prefs.set","TrackApp.IntWeight","0.75,0");

Example ImageJ Macro

// root is the folder holding the experiment folders
// expname is the experiment name
function runProcessing(root,expname){
run("Segmentation","dir="+root+",exp="+expname+",run=true,method=segmentation.RadialGrowth_Segmentation");
run("Run Tracking","expdir="+root+",filename="+expname+",method=Division: Nearest Cell");
// Load the experiment viewer and call some plugins
run("Experiment Viewer", "ShowImages=false,dir="+root+",exp="+expname);
run("Run Plugin","plugin=Save Divisions");
run("Run Plugin","save=data");
run("Run Plugin","close=true");
}

Since v1.2.0, run("LineageTracker Command"...) has been available as a synonym of run("Run Plugin"...).