Skip to content

Commit

Permalink
Write out correlations when --create-matrices doesn't include "all" (
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Nov 20, 2024
1 parent 07a38ca commit 0e07ef1
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 149 deletions.
37 changes: 8 additions & 29 deletions xcp_d/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def _build_parser():
g_dcan.add_argument(
'--create-matrices',
'--create_matrices',
dest='dcan_correlation_lengths',
dest='correlation_lengths',
required=False,
default=None,
nargs='+',
Expand Down Expand Up @@ -967,9 +967,7 @@ def _validate_parameters(opts, build_log, parser):
opts.confounds_config = (
'36P' if (opts.confounds_config == 'auto') else opts.confounds_config
)
opts.dcan_correlation_lengths = (
[] if opts.dcan_correlation_lengths is None else opts.dcan_correlation_lengths
)
opts.correlation_lengths = opts.correlation_lengths if opts.correlation_lengths else []
opts.despike = True if (opts.despike == 'auto') else opts.despike
opts.fd_thresh = 0.3 if (opts.fd_thresh == 'auto') else opts.fd_thresh
opts.file_format = 'cifti' if (opts.file_format == 'auto') else opts.file_format
Expand All @@ -978,23 +976,18 @@ def _validate_parameters(opts, build_log, parser):
opts.min_coverage = 0.5 if opts.min_coverage == 'auto' else opts.min_coverage
if opts.motion_filter_type is None:
error_messages.append(f"'--motion-filter-type' is required for '{opts.mode}' mode.")
opts.output_correlations = True if 'all' in opts.dcan_correlation_lengths else False
if opts.output_type == 'censored':
error_messages.append(f"'--output-type' cannot be 'censored' for '{opts.mode}' mode.")
opts.output_type = 'interpolated'
opts.process_surfaces = True if opts.process_surfaces == 'auto' else opts.process_surfaces
opts.smoothing = 6 if opts.smoothing == 'auto' else opts.smoothing
# Remove "all" from the list of correlation lengths
opts.dcan_correlation_lengths = [c for c in opts.dcan_correlation_lengths if c != 'all']
elif opts.mode == 'hbcd':
opts.abcc_qc = True if (opts.abcc_qc == 'auto') else opts.abcc_qc
opts.combine_runs = True if (opts.combine_runs == 'auto') else opts.combine_runs
opts.confounds_config = (
'36P' if (opts.confounds_config == 'auto') else opts.confounds_config
)
opts.dcan_correlation_lengths = (
[] if opts.dcan_correlation_lengths is None else opts.dcan_correlation_lengths
)
opts.correlation_lengths = opts.correlation_lengths if opts.correlation_lengths else []
opts.despike = True if (opts.despike == 'auto') else opts.despike
opts.fd_thresh = 0.3 if (opts.fd_thresh == 'auto') else opts.fd_thresh
opts.file_format = 'cifti' if (opts.file_format == 'auto') else opts.file_format
Expand All @@ -1003,14 +996,11 @@ def _validate_parameters(opts, build_log, parser):
opts.min_coverage = 0.5 if opts.min_coverage == 'auto' else opts.min_coverage
if opts.motion_filter_type is None:
error_messages.append(f"'--motion-filter-type' is required for '{opts.mode}' mode.")
opts.output_correlations = True if 'all' in opts.dcan_correlation_lengths else False
if opts.output_type == 'censored':
error_messages.append(f"'--output-type' cannot be 'censored' for '{opts.mode}' mode.")
opts.output_type = 'interpolated'
opts.process_surfaces = True if opts.process_surfaces == 'auto' else opts.process_surfaces
opts.smoothing = 6 if opts.smoothing == 'auto' else opts.smoothing
# Remove "all" from the list of correlation lengths
opts.dcan_correlation_lengths = [c for c in opts.dcan_correlation_lengths if c != 'all']
elif opts.mode == 'linc':
opts.abcc_qc = False if (opts.abcc_qc == 'auto') else opts.abcc_qc
opts.combine_runs = False if opts.combine_runs == 'auto' else opts.combine_runs
Expand All @@ -1023,37 +1013,33 @@ def _validate_parameters(opts, build_log, parser):
opts.input_type = 'fmriprep' if opts.input_type == 'auto' else opts.input_type
opts.linc_qc = True if (opts.linc_qc == 'auto') else opts.linc_qc
opts.min_coverage = 0.5 if opts.min_coverage == 'auto' else opts.min_coverage
opts.output_correlations = True
if opts.output_type == 'interpolated':
error_messages.append(
f"'--output-type' cannot be 'interpolated' for '{opts.mode}' mode."
)
opts.output_type = 'censored'
opts.process_surfaces = False if opts.process_surfaces == 'auto' else opts.process_surfaces
opts.smoothing = 6 if opts.smoothing == 'auto' else opts.smoothing
if opts.dcan_correlation_lengths is not None:
if opts.correlation_lengths is not None:
error_messages.append(f"'--create-matrices' is not supported for '{opts.mode}' mode.")
# Patch 'all' into the list of correlation lengths
opts.correlation_lengths = ['all']
elif opts.mode == 'nichart':
opts.abcc_qc = False if (opts.abcc_qc == 'auto') else opts.abcc_qc
opts.combine_runs = False if opts.combine_runs == 'auto' else opts.combine_runs
opts.confounds_config = (
'36P' if (opts.confounds_config == 'auto') else opts.confounds_config
)
opts.dcan_correlation_lengths = (
'all' if opts.dcan_correlation_lengths is None else opts.dcan_correlation_lengths
)
opts.correlation_lengths = opts.correlation_lengths if opts.correlation_lengths else 'all'
opts.despike = True if (opts.despike == 'auto') else opts.despike
opts.fd_thresh = 0 if (opts.fd_thresh == 'auto') else opts.fd_thresh
opts.file_format = 'nifti' if (opts.file_format == 'auto') else opts.file_format
opts.input_type = 'fmriprep' if opts.input_type == 'auto' else opts.input_type
opts.linc_qc = True if (opts.linc_qc == 'auto') else opts.linc_qc
opts.min_coverage = 0.4 if opts.min_coverage == 'auto' else opts.min_coverage
opts.output_correlations = True if 'all' in opts.dcan_correlation_lengths else False
opts.output_type = 'censored' if opts.output_type == 'auto' else opts.output_type
opts.process_surfaces = False if opts.process_surfaces == 'auto' else opts.process_surfaces
opts.smoothing = 0 if opts.smoothing == 'auto' else opts.smoothing
# Remove "all" from the list of correlation lengths
opts.dcan_correlation_lengths = [c for c in opts.dcan_correlation_lengths if c != 'all']
elif opts.mode == 'none':
if opts.abcc_qc == 'auto':
error_messages.append("'--abcc-qc' (y or n) is required for 'none' mode.")
Expand All @@ -1064,9 +1050,7 @@ def _validate_parameters(opts, build_log, parser):
if opts.confounds_config == 'auto':
error_messages.append("'--nuisance-regressors' is required for 'none' mode.")

opts.dcan_correlation_lengths = (
[] if opts.dcan_correlation_lengths is None else opts.dcan_correlation_lengths
)
opts.correlation_lengths = opts.correlation_lengths if opts.correlation_lengths else []

if opts.despike == 'auto':
error_messages.append("'--despike' (y or n) is required for 'none' mode.")
Expand All @@ -1090,8 +1074,6 @@ def _validate_parameters(opts, build_log, parser):
if opts.motion_filter_type is None:
error_messages.append("'--motion-filter-type' is required for 'none' mode.")

opts.output_correlations = True if 'all' in opts.dcan_correlation_lengths else False

if opts.output_type == 'auto':
error_messages.append("'--output-type' is required for 'none' mode.")

Expand All @@ -1103,9 +1085,6 @@ def _validate_parameters(opts, build_log, parser):
if opts.smoothing == 'auto':
error_messages.append("'--smoothing' is required for 'none' mode.")

# Remove "all" from the list of correlation lengths
opts.dcan_correlation_lengths = [c for c in opts.dcan_correlation_lengths if c != 'all']

# Load the confound configuration file
if opts.confounds_config == 'none':
opts.confounds_config = None
Expand Down
2 changes: 1 addition & 1 deletion xcp_d/cli/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _float_or_auto_or_none(string, is_parser=True):

if floatarg < 0:
raise error('Float argument must be nonnegative.')
return floatarg
return str(floatarg)


def _restricted_float(x):
Expand Down
8 changes: 4 additions & 4 deletions xcp_d/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ class workflow(_Config):
"""Full-width at half-maximum (FWHM) of the smoothing kernel."""
output_interpolated = None
"""Output interpolated data, not censored data."""
output_correlations = None
"""Output correlations from censored data. This doesn't affect exact_scans."""
combine_runs = None
"""Combine runs of the same task."""
motion_filter_type = None
Expand All @@ -590,8 +588,10 @@ class workflow(_Config):
"""Order of the band-pass filter."""
min_coverage = None
"""Coverage threshold to apply to parcels in each atlas."""
dcan_correlation_lengths = None
"""Produce correlation matrices limited to each requested amount of time."""
correlation_lengths = None
"""Produce correlation matrices limited to each requested amount of time.
If this list includes 'all' then correlations from the full (censored) time series will
be produced."""
process_surfaces = None
"""Warp fsnative-space surfaces to the MNI space."""
abcc_qc = None
Expand Down
2 changes: 1 addition & 1 deletion xcp_d/data/tests/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ low_pass = 0.1
bpf_order = 2
atlases = []
min_coverage = 0.5
dcan_correlation_lengths = []
correlation_lengths = []
process_surfaces = false
abcc_qc = false

Expand Down
Loading

0 comments on commit 0e07ef1

Please sign in to comment.