Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhlegarreta/d90ff3b70b3d85271a4afc953d76be14 to your computer and use it in GitHub Desktop.
Save jhlegarreta/d90ff3b70b3d85271a4afc953d76be14 to your computer and use it in GitHub Desktop.
Compute tractography measures using Slicer FiberTractMeasurements module
# -*- coding: utf-8 -*-
import subprocess
#import slicer
#from slicer.ScriptedLoadableModule import *
def run_command(command, out_path):
out_fp = open(out_path + "stdout.txt", "w")
err_fp = open(out_path + "stderr.txt", "w")
exit_code = subprocess.Popen(command, stdout=out_fp, stderr=err_fp).wait()
out_fp.close()
err_fp.close()
if exit_code != 0:
print(f"Command exited with {exitCode}.")
print(command)
print(f"Output written to {outputBasePath}.")
return exit_code
def compute_fiber_tract_measurements(
in_fname,
out_path,
atlas_path,
slicer_bin_path,
fibertractmeasurements_module_path,
):
# Apply white matter analysis
print("WMA...")
command = [
"wm_apply_ORG_atlas_to_subject.sh",
"-i", f"{in_fname}",
"-o", f"{out_path}",
"-a", f"{atlas_path}",
"-s", f"{slicer_bin_path}",
"-d", "1",
"-m", f"{fibertractmeasurements_module_path}",
"-c", "2",
"-n", "4",
]
print(command)
_ = run_command(command, out_path)
print("Done.")
def main():
#ScriptedLoadableModuleLogic.__init__()
in_fname="/path/to/PQCed.vtk"
out_path="/path/to/out"
atlas_path="/path/to/org_atlas/ORG-Atlases-1.2"
slicer_bin_path="/opt/Slicer-5.2.2-linux-amd64/Slicer"
fibertractmeasurements_module_path="/opt/Slicer-5.2.2-linux-amd64/NA-MIC/Extensions-31382/SlicerDMRI/lib/Slicer-5.2/cli-modules/FiberTractMeasurements"
compute_fiber_tract_measurements(
in_fname,
out_path,
atlas_path,
slicer_bin_path,
fibertractmeasurements_module_path,
)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment