Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions halfpipe2bids/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from halfpipe2bids.utils import regex_to_regressor


def test_regex_to_regressor():
regex_confounds = [
"c_comp_cor_0[0-4]",
"(trans|rot)_[xyz]",
"global_signal",
"motion_outlier[0-9]+",
]
confounds_columns = [
"c_comp_cor_00",
"c_comp_cor_01",
"a_comp_cor_00",
"global_signal",
"global_signal_derivative1",
"white_matter",
"trans_x",
"trans_x_derivative1",
"rot_y",
"rot_x_derivative1",
"motion_outlier1",
"motion_outlier2",
]
matched = regex_to_regressor(regex_confounds, confounds_columns)
assert matched == [
"c_comp_cor_00",
"c_comp_cor_01",
"global_signal",
"trans_x",
"rot_y",
"motion_outlier1",
"motion_outlier2",
]
17 changes: 17 additions & 0 deletions halfpipe2bids/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
from nilearn.signal import clean
from nilearn import plotting
import re

hp2b_log = logging.getLogger("halfpipe2bids")
hp2b_url = "https://github.com/pbergeret12/HalfPipe2Bids/"
Expand Down Expand Up @@ -45,6 +46,22 @@ def get_strategy_confounds(spec_path):
return strategy_confounds


def regex_to_regressor(regex_confounds, confounds_columns):
"""
Convert the list of regex patterns from HALFpipe to a list of regressors.
Args:
regex_confounds (list): List of regex patterns.
confounds_columns (list): List of column names from confound file.
Returns:
list: List of confound columns based on fmriprep confound file.
"""
# TODO: To be merged with get_strategy_confounds

# Compile the regex pattern
pattern = re.compile("|".join(regex_confounds))
return [col for col in confounds_columns if pattern.fullmatch(col)]


def impute_and_clean(df):
# TODO: documentation and what's the imputation method?
row_means = df.mean(axis=1, skipna=True)
Expand Down
Loading