The most up-to-date SNT API can be found at https://morphonets.github.io/SNT.
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, but the majority is written in Groovyand Python (Jython), for no other reason that those seem to be the most commonly used language by its developers
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.,
/home/user/Fiji.app/scripts/My_SNT_Script.py) will be listed in Scripts menu:
Go to Scripts › New… from the SNT dialog. This will open an instance of Fiji’s Script Editor with pre-loaded boilerplate code in the scripting language of your choice.
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….
Did you write a useful script? Please submit a pull request on GitHub so that it can be distributed with Fiji!
Some of SNT’s functionality is accessible in the Script Interpreter. Here is an example:
These typically demonstrate various aspects of analysis, tracing, image processing and batch processing routines.
Analysis_Demo_(Interactive).py Exemplifies how to programmatically interact with a running instance of SNT to analyze traced data. Because of all the GUI updates, this approach is significantly slower than analyzing reconstructions directly (see Analysis_Demo.py for comparison)
Analysis_Demo.py A Jython demo of how SNT can analyze neuronal reconstructions fetched from online databases such as MouseLight, NeuroMorpho or FlyCircuit.
Download_ML_Data.groovy Exemplifies how to programmatically retrieve data from MouseLight’s database at [//ml-neuronbrowser.janelia.org ml-neuronbrowser.janelia.org]: It iterates through all the neurons in the server and downloads data (both JSON and SWC formats) for cells with soma associated with the specified Allen Reference Atlas (ARA) compartment. Downloaded files will contain all metadata associated with the cell (i.e., labeling used, strain, etc.)
Get_Branch_Points_in_Brain_Compartment.groovy Exemplifies how to extract morphometric properties of a MouseLight cell associated with a specific brain region/neuropil compartment. Requires internet connection.
Graph_Analysis.py Demonstrates how to handle neurons as graph structures Graph theory in which nodes connected by edges define the morphology of the neuron. SNT represents neurons as directed graphs (assuming the root -typically the soma- as origin) and allows data be processed using the powerful jgrapht library. In this demo, the graph diameter (i.e., the length of the longest shortest path or the longest graph geodesic) of a cellular compartment is computed for a neuron fetched from the MouseLight database.
Reconstruction_Viewer_Demo.py Exemplifies how to render reconstructions and neuropil annotations in a stand-alone Reconstruction Viewer.
SciView_Demo.groovy Exemplifies how bridge SNT with sciview.
Extensive_Sholl_Stats.groovy Exemplifies how to perform linear and polynomial regression on tabular Sholl data.
These scripts hold extensible boilerplate code in several programming languages, namely BeanShell, Groovy and Jython. The most essential imports and script parameters are included to facilitate rapid development.
Scripted_Tracing_Demo.py Exemplifies how to programmatically perform A* tracing between two points without GUI interaction, which allows for automated tracing of relatively simple structures (e.g., neurospheres neurites, microtubule bundles, etc). In this demo, points are retrieved from the SWC file of SNT’s “demo tree”, effectively recreating the initial SWC data.
Scripted_Tracing_Demo_(Interactive).py Exemplifies how to programmatically interact with a running instance of SNT to perform auto-tracing tasks.
Take_Snapshot.py Displays a WYSIWYG image of a tracing canvas. Exemplifies how to script SNT using SNTService.
This menu hosts scripts that process files in bulk. Namely:
Convert_Traces_to_SWC.py Converts all .traces files in a directory into SWC.
Filter_Multiple_Images.py Bulk filtering of image files using Frangi Vesselness.
Measure_Multiple_Files.py/Measure_Multiple_Files_(With_Options).groovy Bulk measurements of reconstruction files.
Render_Cell_Collection.groovy Exemplifies how to quickly render large collections of cells from a directory of files in Reconstruction Viewer.
Render_Cell_Collection_(MultiPanel_Figure).groovy Exemplifies how to generate a publication-quality multi-panel figure in which multiple reconstructions are sorted and color-coded by a specified morphometric trait (e.g., cable length).
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.
Here, we will only exemplify basic functionality. Please refer to the complete examples for more details. Once the Python environment is properly setup, one can initialize Fiji:
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 Reconstruction Viewer
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.