Skip to content

Commit

Permalink
🔀 Merge filt/downstream into test/filters
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed Oct 9, 2023
2 parents 26af04c + 64d3bdc commit d824df4
Show file tree
Hide file tree
Showing 25 changed files with 886 additions and 275 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Some automatic handling of user-provided BIDSy atlas names.
- `sig_imports` static method decorator for `Function` nodes, to accommodate type hinting in signatures of `Function` node functions.
- String representations for NodeBlock and ResourcePool class instances
- `switch_is_off`, `switch_is_on` and `switch_is_on_off` methods to `Configuration` class

## Fixed

- Fixed a bug where some connectivity matrices wouldn't generate if anatomical and functional outputs were in different resolutions.
- Handling of `3dECM` outputs for AFNI ≥ 21.1.1.
- Fixed a bug where sparsity thresholds were not being scaled for network centrality.

### Changed

Expand All @@ -40,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `click-aliases`
- `dc`
- `semver`

### Removed dependencies

Expand Down
40 changes: 24 additions & 16 deletions CPAC/func_preproc/func_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@
name='calc_motion_stats',
switch=[['functional_preproc', 'run'],
['functional_preproc', 'motion_estimates_and_correction', 'run'],
['functional_preproc', 'motion_estimates_and_correction', 'motion_estimates', 'calculate_motion_after']],
inputs=[('desc-preproc_bold', 'space-bold_desc-brain_mask', 'movement-parameters', 'max-displacement',
'rels-displacement', 'coordinate-transformation'), 'subject', 'scan'],
outputs=['framewise-displacement-power', 'framewise-displacement-jenkinson', 'dvars', 'power-params',
['functional_preproc', 'motion_estimates_and_correction',
'motion_estimates', 'calculate_motion_after']],
inputs=[('desc-preproc_bold', 'space-bold_desc-brain_mask',
'movement-parameters', 'max-displacement', 'rels-displacement',
'filtered-coordinate-transformation',
'coordinate-transformation'), 'subject', 'scan'],
outputs=['framewise-displacement-power',
'framewise-displacement-jenkinson', 'dvars', 'power-params',
'motion-params']
)
def calc_motion_stats(wf, cfg, strat_pool, pipe_num, opt=None):
Expand All @@ -57,8 +61,7 @@ def calc_motion_stats(wf, cfg, strat_pool, pipe_num, opt=None):
gen_motion_stats = motion_power_statistics(
name=f'gen_motion_stats_{pipe_num}',
motion_correct_tool=motion_correct_tool,
filtered='motion_estimate_filter' in str(
strat_pool.get_cpac_provenance(coordinate_transformation)))
filtered=strat_pool.filtered_movement)

# Special case where the workflow is not getting outputs from
# resource pool but is connected to functional datasource
Expand All @@ -70,8 +73,7 @@ def calc_motion_stats(wf, cfg, strat_pool, pipe_num, opt=None):
gen_motion_stats, 'inputspec.motion_correct')
wf.connect(*strat_pool.get_data('space-bold_desc-brain_mask'),
gen_motion_stats, 'inputspec.mask')
wf.connect(*strat_pool.get_data(['filtered-movement-parameters',
'movement-parameters']),
wf.connect(*strat_pool.get_data('movement-parameters'),
gen_motion_stats, 'inputspec.movement_parameters')
wf.connect(*strat_pool.get_data('max-displacement'),
gen_motion_stats, 'inputspec.max_displacement')
Expand Down Expand Up @@ -155,7 +157,6 @@ def estimate_reference_image(in_file):
_MOTION_PARAM_OUTPUTS = {
"max-displacement": {},
"rels-displacement": {},
"filtered-movement-parameters": {"Description": "UNFILTERED"},
"movement-parameters": {
"Description": "Each line contains for one timepoint a 6-DOF "
"rigid transform parameters in the format "
Expand Down Expand Up @@ -223,7 +224,6 @@ def func_motion_estimates(wf, cfg, strat_pool, pipe_num, opt=None):
['coordinate-transformation',
'filtered-coordinate-transformation',
'max-displacement',
'filtered-movement-parameters',
'movement-parameters',
'rels-displacement']))

Expand Down Expand Up @@ -517,7 +517,6 @@ def motion_correct_3dvolreg(wf, cfg, strat_pool, pipe_num):
'max-displacement': (out_md1d, 'out_file'),
'movement-parameters': (out_oned, 'out_file'),
'coordinate-transformation': (out_oned_matrix, 'out_file'),
'filtered-movement-parameters': (out_oned, 'out_file'),
'filtered-coordinate-transformation': (out_oned_matrix, 'out_file')
}

Expand Down Expand Up @@ -564,7 +563,6 @@ def motion_correct_mcflirt(wf, cfg, strat_pool, pipe_num):
'rels-displacement': (get_rms_abs, 'rels_file'),
'movement-parameters': (normalize_motion_params, 'out_file'),
'coordinate-transformation': (func_motion_correct_A, 'mat_file'),
'filtered-movement-parameters': (normalize_motion_params, 'out_file'),
'filtered-coordinate-transformation': (func_motion_correct_A,
'mat_file')
}
Expand Down Expand Up @@ -609,9 +607,12 @@ def motion_correct_connections(wf, cfg, strat_pool, pipe_num, opt):
" not seem to affect framewise"
" displacement calculation, for which"
" this matrix is used."},
"filtered-movement-parameters": {
"movement-parameters": {
"Description": "Filtered movement parameters"
" (3 rotation, 3 translation)."},
"unfiltered-movement-parameters": {
"Description": "Unfiltered movement parameters"
" (3 rotation, 3 translation)."},
"motion-filter-info": {},
"motion-filter-plot": {}})
def motion_estimate_filter(wf, cfg, strat_pool, pipe_num, opt=None):
Expand Down Expand Up @@ -654,8 +655,9 @@ def motion_estimate_filter(wf, cfg, strat_pool, pipe_num, opt=None):
notch.inputs.lowpass_cutoff = opt.get('lowpass_cutoff')
notch.inputs.filter_order = opt.get('filter_order')

node, out = strat_pool.get_data('movement-parameters')
wf.connect(node, out, notch, 'motion_params')
movement_parameters = strat_pool.node_data('movement-parameters')
wf.connect(movement_parameters.node, movement_parameters.out,
notch, 'motion_params')

node, out = strat_pool.get_data('TR')
wf.connect(node, out, notch, 'TR')
Expand All @@ -671,9 +673,15 @@ def motion_estimate_filter(wf, cfg, strat_pool, pipe_num, opt=None):
'filtered-coordinate-transformation': (affine, 'affine_file'),
'motion-filter-info': (notch, 'filter_info'),
'motion-filter-plot': (notch, 'filter_plot'),
'filtered-movement-parameters': (notch, 'filtered_motion_params')
'movement-parameters': (notch, 'filtered_motion_params')
}

if not cfg.switch_is_off(["functional_preproc",
"motion_estimates_and_correction",
"motion_estimate_filter", "run"]):
outputs['unfiltered-movement-parameters'] = (movement_parameters.node,
movement_parameters.out)

return (wf, outputs)


Expand Down
1 change: 1 addition & 0 deletions CPAC/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def get_cpac_gitversion():
"scikit-learn",
"scipy",
"sdcflows",
"semver",
"traits",
"voluptuous>=0.12.0",
"xvfbwrapper"
Expand Down
20 changes: 18 additions & 2 deletions CPAC/network_centrality/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
from .utils import convert_pvalue_to_r, merge_lists
# Copyright (C) 2012-2023 C-PAC Developers

__all__ = ['convert_pvalue_to_r', 'merge_lists']
# This file is part of C-PAC.

# C-PAC is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.

# C-PAC is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.
from .utils import convert_pvalue_to_r, create_merge_node

__all__ = ['convert_pvalue_to_r', 'create_merge_node']
Loading

0 comments on commit d824df4

Please sign in to comment.