Skip to content

Commit 9767c23

Browse files
authored
Merge pull request #20 from harvard-nrg/truncate_qsiprep_fmaps
add argument to optionally truncate fmap volume for qsiprep
2 parents 7379076 + c6c296e commit 9767c23

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

dwiqc/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'dwiqc'
22
__description__ = 'Quality Assurance Pipeline for Diffusion MR Data'
33
__url__ = 'https://github.com/harvard-nrg/dwiqc'
4-
__version__ = '1.6.4'
4+
__version__ = '1.6.5'
55
__author__ = 'Neuroinformatics Research Group'
66
__author_email__ = 'info@neuroinfo.org'

dwiqc/cli/process.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def do(args):
112112
outdir=qsiprep_outdir,
113113
qsiprep_config=args.qsiprep_config,
114114
fs_license=args.fs_license,
115+
truncate_fmap=args.truncate_qsiprep_fmap,
115116
container_dir = args.container_dir,
116117
custom_eddy=args.custom_eddy,
117118
no_gpu=args.no_gpu,

dwiqc/tasks/qsiprep.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626

2727

2828
class Task(tasks.BaseTask):
29-
def __init__(self, sub, ses, run, bids, outdir, qsiprep_config, fs_license, container_dir=None, custom_eddy=False, no_gpu=False, output_resolution=None, tempdir=None, pipenv=None):
29+
def __init__(self, sub, ses, run, bids, outdir, qsiprep_config, fs_license, truncate_fmap=False, container_dir=None, custom_eddy=False, no_gpu=False, output_resolution=None, tempdir=None, pipenv=None):
3030
self._sub = sub
3131
self._ses = ses
3232
self._run = run
3333
self._bids = bids
3434
self._qsiprep_config = qsiprep_config
3535
self._fs_license = fs_license
36+
self._truncate_fmap = truncate_fmap
3637
self._container_dir = container_dir
3738
self._custom_eddy = custom_eddy
3839
self._no_gpu = no_gpu
@@ -329,7 +330,7 @@ def extract_vols(self, dwi_full_path, dwi_basename):
329330

330331
epi_output_path = epi_output.replace('/dwi/', '/fmap/')
331332

332-
self.run_extract(dwi_full_path, bval, epi_output_path)
333+
fmap_path = self.run_extract(dwi_full_path, bval, epi_output_path)
333334

334335

335336
# create an output file path for the new fmap's json file
@@ -352,6 +353,20 @@ def extract_vols(self, dwi_full_path, dwi_basename):
352353

353354
self.insert_json_value('IntendedFor', f'ses-{self._ses}/dwi/{dwi_basename}', fmap_json_file_path)
354355

356+
if self._truncate_fmap:
357+
shape = nib.load(fmap_path).get_fdata().shape
358+
if len(shape) == 4:
359+
num_vols = shape[3]
360+
middle_vol = num_vols // 2
361+
362+
self.run_fslroi(fmap_path, middle_vol)
363+
364+
def run_fslroi(self, fmap, volume):
365+
vol_index = int(volume) - 1
366+
split_command = f'singularity exec /{self._fsl_sif} /APPS/fsl/bin/fslroi {fmap} {fmap} {volume} {str(vol_index)}'
367+
logger.info(f'executing {split_command}')
368+
proc1 = subprocess.check_output(split_command, shell=True, stderr=subprocess.STDOUT, text=True)
369+
355370
def run_extract(self, dwi_full_path, bval_path, epi_out_path):
356371

357372
bvec_path = bval_path.replace('.bval', '.bvec')
@@ -395,6 +410,7 @@ def run_extract(self, dwi_full_path, bval_path, epi_out_path):
395410
logger.critical(f'fslselectvols failed to produce "{epi_out_path}"')
396411
raise subprocess.CalledProcessError(returncode=1, cmd=extract_command)
397412
logger.info(f'found fslselectvols derived file "{epi_out_path}"')
413+
return epi_out_path
398414
except subprocess.CalledProcessError as e:
399415
print(e.stdout)
400416
raise e

scripts/dwiQC.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def main():
106106
help='List of cluster nodes to exclude from use.')
107107
parser_process.add_argument('--work-dir',
108108
help='Working directory that is shared across compute cluster')
109+
parser_process.add_argument('--truncate-qsiprep-fmap', action='store_true',
110+
help='Truncate the fmap created from the main diffusion scan to just one b0 volume.')
109111
parser_process.set_defaults(func=cli.process.do)
110112

111113
# tandem mode
@@ -164,6 +166,8 @@ def main():
164166
help='List of cluster nodes to exclude from use.')
165167
parser_tandem.add_argument('--work-dir',
166168
help='Working directory that is shared across compute cluster')
169+
parser_tandem.add_argument('--truncate-qsiprep-fmap', action='store_true',
170+
help='Truncate the fmap created from the main diffusion scan to just one b0 volume.')
167171
parser_tandem.set_defaults(func=cli.tandem.do)
168172
args = parser.parse_args()
169173

0 commit comments

Comments
 (0)