66import niwrap_helper
77
88from rbc .core .common import reorient
9- from rbc .core .functional import truncate_trs , generate_motion_reference , motion_correction
9+ from rbc .core .functional import (
10+ generate_motion_reference ,
11+ motion_correction ,
12+ truncate_trs ,
13+ )
1014from rbc .core .utils import get_base_entities , rename , save_directory
1115
1216
13-
1417def single_session (in_bold : Path , output_dir : Path , start_tr : int = 2 ) -> None :
1518 """Workflow for preprocessing functional data.
16-
19+
1720 Args:
1821 in_bold: Input BOLD timeseries to process.
1922 output_dir: Parent output directory to save data to.
2023 start_tr: Number of initial TRs to remove (default: 2).
2124 """
22-
2325 bids_entities = get_base_entities (in_bold )
2426 bids = partial (niwrap_helper .bids_path , ** bids_entities )
25-
27+
2628 reoriented_bold = reorient (
2729 in_file = in_bold ,
28- output_fname = str (bids (desc = "reoriented" , suffix = "bold" , ext = ".nii.gz" ))
30+ output_fname = str (bids (desc = "reoriented" , suffix = "bold" , ext = ".nii.gz" )),
2931 )
3032
3133 truncated_bold = truncate_trs (
3234 in_file = reoriented_bold .out_file ,
3335 output_fname = str (bids (suffix = "bold" , ext = ".nii.gz" )),
34- start_tr = start_tr
35- )
36-
37- motion_reference = generate_motion_reference (
36+ start_tr = start_tr ,
37+ )
38+
39+ motion_reference = generate_motion_reference (
3840 in_file = truncated_bold .output_file ,
39- output_fname = str (bids (suffix = "sbref" , ext = ".nii.gz" ))
41+ output_fname = str (bids (suffix = "sbref" , ext = ".nii.gz" )),
4042 )
4143
4244 motion_corrected = motion_correction (
4345 in_file = truncated_bold .output_file ,
4446 ref_file = motion_reference .output_file ,
45- output_prefix = str (bids ())
47+ output_prefix = str (bids ()),
4648 )
4749
4850 # Prep files to save
@@ -54,20 +56,22 @@ def single_session(in_bold: Path, output_dir: Path, start_tr: int = 2) -> None:
5456 (motion_corrected .par , "movementParameters" , "motion" , ".1D" ),
5557 (motion_corrected .rms_rel , "relsDisplacement" , "motion" , ".rms" ),
5658 (motion_corrected .rms_abs , "absDisplacement" , "motion" , ".rms" ),
57- ]
59+ ]
5860
5961 func_out_dir = output_dir / bids (datatype = "func" , directory = True )
6062
6163 save_directory (
62- motion_corrected .mat_dir ,
63- func_out_dir ,
64- bids (desc = "motion" , suffix = "mat" )
64+ motion_corrected .mat_dir , func_out_dir , bids (desc = "motion" , suffix = "mat" )
6565 )
6666
6767 renamed_files = [
68- rename (out_file , bids (desc = desc , suffix = suffix , ext = ext ) if desc else bids (suffix = suffix , ext = ext ))
68+ rename (
69+ out_file ,
70+ bids (desc = desc , suffix = suffix , ext = ext )
71+ if desc
72+ else bids (suffix = suffix , ext = ext ),
73+ )
6974 for out_file , desc , suffix , ext in outputs
7075 ]
7176
7277 niwrap_helper .save (renamed_files , out_dir = func_out_dir )
73-
0 commit comments