Skip to content

Commit

Permalink
Use user-requested parameters in regression (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Oct 20, 2022
1 parent 27d79a7 commit 9000864
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
44 changes: 34 additions & 10 deletions .circleci/tests/test_Reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@
def test_Reg_Nifti(data_dir):
"""Test NIFTI regression."""
# Specify inputs
in_file = data_dir + "/fmriprep/sub-colornest001/ses-1/func/" \
in_file = (
data_dir + "/fmriprep/sub-colornest001/ses-1/func/"
"sub-colornest001_ses-1_task-rest_run-1_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz"
confounds = data_dir + "/fmriprep/sub-colornest001/ses-1/func/" \
)
confounds = (
data_dir + "/fmriprep/sub-colornest001/ses-1/func/"
"sub-colornest001_ses-1_task-rest_run-2_desc-confounds_timeseries.tsv"
)
TR = 0.5
mask = data_dir + "/fmriprep/sub-colornest001/ses-1/func/" \
mask = (
data_dir + "/fmriprep/sub-colornest001/ses-1/func/"
"sub-colornest001_ses-1_task-rest_run-1_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz"
)
# Run regression
test_nifti = Regress(mask=mask, in_file=in_file,
original_file=in_file, confounds=confounds, TR=TR)
test_nifti = Regress(
mask=mask,
in_file=in_file,
original_file=in_file,
confounds=confounds,
TR=TR,
params="36P",
)
results = test_nifti.run()

# Read in_file and regression results in, but ignore the 'Unnamed:0' column if present
Expand Down Expand Up @@ -50,16 +62,28 @@ def test_Reg_Nifti(data_dir):
def test_Reg_Cifti(data_dir):
"""Test CIFTI regression."""
# Specify inputs
in_file = data_dir + "/fmriprep/sub-colornest001/ses-1/func/" \
in_file = (
data_dir + "/fmriprep/sub-colornest001/ses-1/func/"
"sub-colornest001_ses-1_task-rest_run-1_space-fsLR_den-91k_bold.dtseries.nii"
confounds = data_dir + "/fmriprep/sub-colornest001/ses-1/func/" \
)
confounds = (
data_dir + "/fmriprep/sub-colornest001/ses-1/func/"
"sub-colornest001_ses-1_task-rest_run-1_desc-confounds_timeseries.tsv"
)
TR = 0.5
mask = data_dir + "/fmriprep/sub-colornest001/ses-1/func/" \
mask = (
data_dir + "/fmriprep/sub-colornest001/ses-1/func/"
"sub-colornest001_ses-1_task-rest_run-1_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz"
)
# Run regression
test_cifti = Regress(mask=mask, in_file=in_file,
original_file=in_file, confounds=confounds, TR=TR)
test_cifti = Regress(
mask=mask,
in_file=in_file,
original_file=in_file,
confounds=confounds,
TR=TR,
params="36P",
)
results = test_cifti.run()

# Read in_file and regression results in, but ignore the 'Unnamed:0' column if present
Expand Down
22 changes: 15 additions & 7 deletions xcp_d/interfaces/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class _RegressInputSpec(BaseInterfaceInputSpec):
exists=True,
mandatory=True,
desc="The fMRIPrep confounds tsv after censoring")
# TODO: Use Enum maybe?
params = traits.Str(exists=True, mandatory=True, desc="Parameter set to use.")
TR = traits.Float(exists=True, mandatory=True, desc="Repetition time")
mask = File(exists=False, mandatory=False, desc="Brain mask for nifti files")
original_file = traits.Str(exists=True, mandatory=False,
Expand Down Expand Up @@ -69,14 +71,20 @@ def _run_interface(self, runtime):
# Get the confound matrix
# Do we have custom confounds?
if self.inputs.custom_confounds and exists(self.inputs.custom_confounds):
confound = load_confound_matrix(original_file=self.inputs.original_file,
datafile=self.inputs.in_file,
custom_confounds=self.inputs.custom_confounds,
confound_tsv=self.inputs.confounds)
confound = load_confound_matrix(
original_file=self.inputs.original_file,
datafile=self.inputs.in_file,
custom_confounds=self.inputs.custom_confounds,
confound_tsv=self.inputs.confounds,
params=self.inputs.params,
)
else: # No custom confounds
confound = load_confound_matrix(original_file=self.inputs.original_file,
datafile=self.inputs.in_file,
confound_tsv=self.inputs.confounds)
confound = load_confound_matrix(
original_file=self.inputs.original_file,
datafile=self.inputs.in_file,
confound_tsv=self.inputs.confounds,
params=self.inputs.params,
)
# for testing, let's write out the confounds file:
confounds_file_output_name = fname_presuffix(
self.inputs.confounds,
Expand Down
4 changes: 2 additions & 2 deletions xcp_d/utils/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def square_confound(confound):

@fill_doc
def load_confound_matrix(
datafile, original_file, custom_confounds=None, confound_tsv=None, params="36P"
datafile, original_file, params, custom_confounds=None, confound_tsv=None
):
"""Load a subset of the confounds associated with a given file.
Expand All @@ -310,11 +310,11 @@ def load_confound_matrix(
BOLD file whose confounds we want.
original_file :
File used to find confounds json.
%(params)s
custom_confounds : str or None, optional
Custom confounds TSV if there is one. Default is None.
confound_tsv : str or None, optional
The path to the confounds TSV file. Default is None.
%(params)s
Returns
-------
Expand Down
3 changes: 1 addition & 2 deletions xcp_d/workflow/bold.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ def init_boldpostprocess_wf(
n_procs=omp_nthreads)

regression_wf = pe.Node(
Regress(TR=TR,
original_file=bold_file),
Regress(TR=TR, original_file=bold_file, params=params),
name="regression_wf",
mem_gb=mem_gbx['timeseries'],
n_procs=omp_nthreads)
Expand Down
3 changes: 1 addition & 2 deletions xcp_d/workflow/cifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ def init_ciftipostprocess_wf(
n_procs=omp_nthreads)

regression_wf = pe.Node(
Regress(TR=TR,
original_file=bold_file),
Regress(TR=TR, original_file=bold_file, params=params),
name="regression_wf",
mem_gb=mem_gbx['timeseries'],
n_procs=omp_nthreads)
Expand Down

0 comments on commit 9000864

Please sign in to comment.