Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit b098aae

Browse files
committed
fix: filenames for pyafq
1 parent 7ae39a4 commit b098aae

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

run.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def run_preAFQ(dwi_file, bvec_file, working_dir, sink_dir):
1+
def run_preAFQ(dwi_file, bvec_file, bval_file, working_dir, sink_dir):
22
import nipype.interfaces.fsl as fsl
33
from nipype.interfaces.fsl.utils import AvScale
44
import nipype.pipeline.engine as pe
@@ -103,21 +103,29 @@ def rang(b):
103103

104104
datasink = pe.Node(nio.DataSink(),name="sinker")
105105
datasink.inputs.base_directory = sink_dir
106-
datasink.inputs.substitutions = [("vol0000_flirt_merged.nii.gz", dwi_filename+'_corrected.nii.gz'),
107-
("stats.vol0000_flirt_merged.txt", dwi_filename+".motion.txt"),
108-
("derivatives/dti", "derivatives/{}/dti".format(bids_subject_name))]
106+
datasink.inputs.substitutions = [("vol0000_flirt_merged.nii.gz", dwi_filename+'.nii.gz'),
107+
("stats.vol0000_flirt_merged.txt", dwi_filename+".art.json"),
108+
("motion_parameters.par", dwi_filename+".motion.txt"),
109+
("_rotated.bvec ", ".bvec"),
110+
("derivatives/dwi", "derivatives/{}/dwi".format(bids_subject_name))]
109111

110-
wf.connect(art, "statistic_files", datasink, "dti.@artstat")
111-
wf.connect(outputspec, "dmri_corrected", datasink, "dti.@corrected")
112-
wf.connect(outputspec,"bvec_rotated", datasink, "dti.@rotated")
112+
wf.connect(art, "statistic_files", datasink, "dwi.@artstat")
113+
wf.connect(outputspec, "dmri_corrected", datasink, "dwi.@corrected")
114+
wf.connect(outputspec,"bvec_rotated", datasink, "dwi.@rotated")
115+
wf.connect(getmotion, "motion_params", datasink, "dwi.@motion")
113116

114117
wf.base_dir = working_dir
115118
wf.run()
116119

117120
from glob import glob
118121
import os
122+
from shutil import copyfile
123+
124+
copyfile(bval_file, os.path.join(sink_dir, bids_subject_name, "dwi", os.path.split(bval_file)[1]))
119125

120-
dmri_corrected = glob(os.path.join(sink_dir, 'dti', '*.nii.gz'))[0]
121-
bvec_rotated = glob(os.path.join(sink_dir, 'dti', '*.bvec'))[0]
122-
motion_outliers = glob(os.path.join(sink_dir, 'dti', '*.txt'))[0]
123-
return dmri_corrected, bvec_rotated, motion_outliers
126+
dmri_corrected = glob(os.path.join(sink_dir, '*/dwi', '*.nii.gz'))[0]
127+
bvec_rotated = glob(os.path.join(sink_dir, '*/dwi', '*.bvec'))[0]
128+
bval_file = glob(os.path.join(sink_dir, '*/dwi', '*.bval'))[0]
129+
art_file = glob(os.path.join(sink_dir, '*/dwi', '*.art.json'))[0]
130+
motion_file = glob(os.path.join(sink_dir, '*/dwi', '*.motion.txt'))[0]
131+
return dmri_corrected, bvec_rotated, art_file, motion_file

0 commit comments

Comments
 (0)