Skip to content

Commit

Permalink
add argument to optionally truncate fmap volume for qsiprep
Browse files Browse the repository at this point in the history
  • Loading branch information
danielasay committed Jun 27, 2024
1 parent 7379076 commit c6c296e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dwiqc/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'dwiqc'
__description__ = 'Quality Assurance Pipeline for Diffusion MR Data'
__url__ = 'https://github.com/harvard-nrg/dwiqc'
__version__ = '1.6.4'
__version__ = '1.6.5'
__author__ = 'Neuroinformatics Research Group'
__author_email__ = 'info@neuroinfo.org'
1 change: 1 addition & 0 deletions dwiqc/cli/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def do(args):
outdir=qsiprep_outdir,
qsiprep_config=args.qsiprep_config,
fs_license=args.fs_license,
truncate_fmap=args.truncate_qsiprep_fmap,
container_dir = args.container_dir,
custom_eddy=args.custom_eddy,
no_gpu=args.no_gpu,
Expand Down
20 changes: 18 additions & 2 deletions dwiqc/tasks/qsiprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@


class Task(tasks.BaseTask):
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):
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):
self._sub = sub
self._ses = ses
self._run = run
self._bids = bids
self._qsiprep_config = qsiprep_config
self._fs_license = fs_license
self._truncate_fmap = truncate_fmap
self._container_dir = container_dir
self._custom_eddy = custom_eddy
self._no_gpu = no_gpu
Expand Down Expand Up @@ -329,7 +330,7 @@ def extract_vols(self, dwi_full_path, dwi_basename):

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

self.run_extract(dwi_full_path, bval, epi_output_path)
fmap_path = self.run_extract(dwi_full_path, bval, epi_output_path)


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

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

if self._truncate_fmap:
shape = nib.load(fmap_path).get_fdata().shape
if len(shape) == 4:
num_vols = shape[3]
middle_vol = num_vols // 2

self.run_fslroi(fmap_path, middle_vol)

def run_fslroi(self, fmap, volume):
vol_index = int(volume) - 1
split_command = f'singularity exec /{self._fsl_sif} /APPS/fsl/bin/fslroi {fmap} {fmap} {volume} {str(vol_index)}'
logger.info(f'executing {split_command}')
proc1 = subprocess.check_output(split_command, shell=True, stderr=subprocess.STDOUT, text=True)

def run_extract(self, dwi_full_path, bval_path, epi_out_path):

bvec_path = bval_path.replace('.bval', '.bvec')
Expand Down Expand Up @@ -395,6 +410,7 @@ def run_extract(self, dwi_full_path, bval_path, epi_out_path):
logger.critical(f'fslselectvols failed to produce "{epi_out_path}"')
raise subprocess.CalledProcessError(returncode=1, cmd=extract_command)
logger.info(f'found fslselectvols derived file "{epi_out_path}"')
return epi_out_path
except subprocess.CalledProcessError as e:
print(e.stdout)
raise e
Expand Down
4 changes: 4 additions & 0 deletions scripts/dwiQC.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def main():
help='List of cluster nodes to exclude from use.')
parser_process.add_argument('--work-dir',
help='Working directory that is shared across compute cluster')
parser_process.add_argument('--truncate-qsiprep-fmap', action='store_true',
help='Truncate the fmap created from the main diffusion scan to just one b0 volume.')
parser_process.set_defaults(func=cli.process.do)

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

Expand Down

0 comments on commit c6c296e

Please sign in to comment.