SNT comes pre-packaged with a variety of script templates demonstrating various analysis, tracing, image processing and utility routines.
Analysis_Demo.py A Jython demo of how SNT can analyze neuronal reconstructions fetched from online databases such as MouseLight, NeuroMorpho or FlyCircuit. This demo requires internet connection and assumes you've already ran Analysis_Demo_(Interactive).py
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)
Download_ML_Data.groovy Exemplifies how to programmatically retrieve data from MouseLight's database at 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.) For advanced queries, have a look at MouseLightQuerier.
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. Requires internet connection.
Render_Cell_Collection.groovy Exemplifies how to quickly render large collections of cells from a directory of files (900 MouseLight reconstructions rendered in ~30s on a 4 core i7 (ubuntu 18.10) without a discrete graphics card).
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 (cable length in this example). The script prompts for a directory containing the reconstruction files to be analyzed. If no directory is specified, the script will parse a collection of dendritic arbors from the MouseLight database instead.
SciView_Demo.groovy Exemplifies how bridge SNT with SciView.
Follow the instructions given here
To initialize Fiji from Python with GUI capabilities:
import imagej ij = imagej.init('sc.fiji:fiji', headless=False)
Then, use pyjnius (bundled with pyimagej) to import the SNT (Java) classes you need. For example, to download a neuron reconstruction from the MouseLight database and calculate summary statistics on it, you would import the MouseLightLoader and TreeStatistics classes:
from jnius import autoclass MouseLightLoader = autoclass('tracing.io.MouseLightLoader') TreeStatistics = autoclass('tracing.analysis.TreeStatistics')
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).
def run(): loader = MouseLightLoader("AA0100") if not loader.isDatabaseAvailable(): print("Could not connect to ML database", "Error") return if not loader.idExists(): print("Somehow the specified id was not found", "Error") return a_tree = loader.getTree('axon', None) # compartment, color s_stats = TreeStatistics(a_tree) metric = TreeStatistics.INTER_NODE_DISTANCE summary_stats = s_stats.getSummaryStats(metric) s_stats.getHistogram(metric).show() print("The average inter-node distance is %d" % summary_stats.getMean())
The Notebooks directory in the SNT GitHub repository contains examples which are executable on Binder. For example, to run the convex_hull notebook via mybinder.org, follow this link: convex_hull.ipynb