A key feature of SNT is its extensibility via scripts.This section provides an overview to the ever-growing list of SNT scripts. These can be accessed through the Plugins › NeuroAnatomy › Neuroanatomy Shortcut Window, the Scripts menu in the main dialog, or the Templates › Neuroanatomy menu of Fiji’s Script Editor. Typically, holding ⇧ Shift while selecting a script from a menu outside the Script Editor will open it.
SNT Scripts are intentionally written in multiple languages to demonstrate flexibility, but the majority is written in Groovy and Python (Jython), for no other reason that those seem to be the most commonly used language by its developers. script parameters are typically used for rapid development.
There are ~50 scripts currently bundled in SNT. These are organized into non-rigid categories: Analysis (typically handling quantifications) , Batch (Bulk processing of files), Render (visualization), Skeletons & ROIs (pixel-based analyses), Tracing (Tracing-related tasks), and Demos.
Your script can also be bundled with SNT, or made available through the Neuroanatomy update site. Did you write a useful routine? Please announce it, or submit a pull request so that it can be distributed with Fiji!
Adding Scripts to SNT
There are a couple of ways to have your own scripts appear in SNT’s Scripts menu:
Any script saved into Fiji’s “scripts” sub-directory containing SNT in the filename (e.g., C:\Users\user\Desktop\Fiji.app\scripts\My_SNT_Script.py or /home/user/Fiji.app/scripts/My_SNT_Script.py) will be listed in Scripts menu:
Go to Scripts › New… from the SNT dialog. You can choose to open an instance of Fiji’s Script Editor with pre-loaded boilerplate code in the scripting language of your choice or to assemble your boilerplate using the Script Recorder
Save the script in Fiji.app/scripts/ including ‘SNT’ anywhere in its file name
Run Scripts › Reload…, and your new script should appear in the full list of scripts found at Scripts › Full List….
SNT features a script recorder that similarly to ImageJ’s macro recorder converts menu and button clicks into executable code. Note however that while the recorder captures simple commands well, it struggles to capture those that are more complex or particularly interactive.
The goal of the recorder is twofold: 1) simplify prototyping of new scripts and 2) Log your actions during a tracing session. This is particularly useful to assemble reproducible records.
There are two ways to start the recorder: Scripts › New › Record… or by pressing the Record button in Command Palette.
As a rule-of-thumb, commands that are simple or do not involve prompts record flawlessly. This includes setting filters for visibility of tags, applying Tags, or filtering paths in the Path Manager. Commands for fully automated reconstructions, or generating secondary layers should work well. However, many others remain limited.
Some of SNT’s functionality is conveniently accessible in the Script Interpreter. Here is an example:
Direct access to the SNT API from the Python programming language is made possible through the PyImageJ module. This enables full integration between SNT and any library in the Python ecosystem (numpy, scipy, etc.). The Notebooks directory in the SNT repository contains several examples at different complexity levels.
Then, one import the needed SNT (Java) classes. E.g., to download a neuron reconstruction from the MouseLight database and calculate summary statistics on it, you would import the MouseLightLoader and TreeStatistics classes:
Now you can access all the attributes and methods these classes offer. Let’s get a summary of the inter-node distances for a specific mouse cortical motor neuron (ID = “AA0100” in the MouseLight database).
Scripting in Fiji’s script editor is perhaps best done using Groovy and python. The latter as quite good autocompletion for objects that are not script parameters. The best way to start a new script is by choosing a boilerplate Scripts › New › From Template… in SNT or Neuroanatomy › Boilerplate in the script Editor. These templates hold boilerplate code in several programming languages (namely BeanShell, Groovy and Jython), and include the most essential imports and script parameters to facilitate rapid development.
Programmatic control over an open instance of Reconstruction Viewer (either called from within SNT or as a standalone application) can be achieved by selecting the Tools & Utilities › Script This Viewer… command. It will then open an instance of Fiji’s script editor with a boilerplate template containing the most essential imports and script parameters. The default programming language for this template can be chosen from the drop-down menu of the Preferred Language option.
The following script exemplifies how to extend the boilerplate template to control the Viewer in real-time.