Skip to content

Instantly share code, notes, and snippets.

@tferr
Forked from mhl/Convert_Traces_to_SWC.py
Created October 27, 2016 17:26
Show Gist options
  • Save tferr/26e7672d7a884a70ad9ea2529cff90a0 to your computer and use it in GitHub Desktop.
Save tferr/26e7672d7a884a70ad9ea2529cff90a0 to your computer and use it in GitHub Desktop.
Batch convert Simple Neurite Tracer's .traces files to SWC format
import os
import re
from tracing import PathAndFillManager
# An example script showing how to convert all the .traces
# files in a directory to SWC files. (The .traces format
# is the native file format of Simple Neurite Tracer.)
def run():
d = IJ.getDirectory("Choose your directory of .traces files...")
if not d:
return
for e in os.listdir(d):
if not e.endswith(".traces"):
continue
traces_filename = os.path.join(d,e)
swc_filename_prefix = re.sub(r'\.traces', '-exported', traces_filename)
IJ.log("Converting %s to %s-*.swc" % (traces_filename,
swc_filename_prefix))
pafm = PathAndFillManager()
pafm.loadGuessingType(traces_filename)
if pafm.checkOKToWriteAllAsSWC(swc_filename_prefix):
pafm.exportAllAsSWC(swc_filename_prefix)
run()
@tferr
Copy link
Author

tferr commented Oct 27, 2016

An implementation of this has been added to the hIPNAT toolbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment