Created
June 14, 2023 20:42
-
-
Save tferr/fc5888fe4635135cceee46e6b38429a4 to your computer and use it in GitHub Desktop.
SNT script for bulk export of soma coordinates of MouseLight Neurons to a CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sc.fiji.snt.analysis import SNTTable | |
from sc.fiji.snt.io import MouseLightQuerier, MouseLightLoader | |
""" | |
Jython script for bulk export of soma coordinates of MouseLight Neurons to a CSV file. | |
To Run this script: | |
- Download Fiji and install SNT (by subscribing to Fiji's Neuroanatomy update site) | |
- Edit the 'destination' variable and run this script from Fiji's Script Editor | |
(using Python as language) | |
- For instructions on how to run SNT from a native python environment have a look at | |
https://github.com/morphonets/SNT | |
- For details on SNT, have a look at https://imagej.net/plugins/snt | |
""" | |
destination = '/path/to/CSV/file.csv' | |
table = SNTTable() | |
ids = MouseLightQuerier.getAllIDs() | |
for id in ids: | |
print("Parsing %s..." % id) | |
loader = MouseLightLoader(id) | |
try: | |
# If soma is a well-defined neuronal compartment use it (MouseLight uses | |
# single-node soma definitions), otherwise retrive it as the root of the | |
# full neuronal arbor | |
tree = loader.getTree("soma") | |
if not tree: | |
tree = loader.getTree() | |
root = tree.getRoot() | |
except: | |
# internet connection lost!? | |
table.save(destination) | |
print("Exception occured. See Console for details...") | |
table.insertRow(id) | |
table.appendToLastRow("X", root.getX()) | |
table.appendToLastRow("Y", root.getY()) | |
table.appendToLastRow("Z", root.getZ()) | |
table.appendToLastRow("Comp", root.getAnnotation()) | |
parsed.append(id) | |
table.save(destination) | |
print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment