1
1
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2
2
# vi: set ft=python sts=4 ts=4 sw=4 et:
3
+ #
4
+ # STATEMENT OF CHANGES: This file is derived from sources licensed under the Apache-2.0 terms,
5
+ # and this file has been changed.
6
+ # The original file this work derives from is found at:
7
+ # https://github.com/nipreps/fmriprep/blob/a4fd718/fmriprep/workflows/bold/base.py
8
+ #
9
+ # [January 2022] CHANGES:
10
+ # * `init_nibabies_wf` now takes in a dictionary composed of participant/session key/values.
11
+ # * `init_single_subject_wf` now differentiates between participant sessions.
12
+ # This change is to treat sessions as a "first-class" identifier, to better handle the
13
+ # potential rapid changing of brain morphometry.
14
+ #
15
+ # Copyright 2021 The NiPreps Developers <[email protected] >
16
+ #
17
+ # Licensed under the Apache License, Version 2.0 (the "License");
18
+ # you may not use this file except in compliance with the License.
19
+ # You may obtain a copy of the License at
20
+ #
21
+ # http://www.apache.org/licenses/LICENSE-2.0
22
+ #
23
+ # Unless required by applicable law or agreed to in writing, software
24
+ # distributed under the License is distributed on an "AS IS" BASIS,
25
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ # See the License for the specific language governing permissions and
27
+ # limitations under the License.
28
+ #
29
+ # We support and encourage derived works from this project, please read
30
+ # about our expectations at
31
+ #
32
+ # https://www.nipreps.org/community/licensing/
33
+ #
3
34
"""
4
35
NiBabies base processing workflows
5
36
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24
55
from .bold import init_func_preproc_wf
25
56
26
57
27
- def init_nibabies_wf ():
58
+ def init_nibabies_wf (participants_table ):
28
59
"""
29
60
Build *NiBabies*'s pipeline.
30
61
@@ -44,6 +75,10 @@ def init_nibabies_wf():
44
75
with mock_config():
45
76
wf = init_nibabies_wf()
46
77
78
+ Parameters
79
+ ----------
80
+ participants_table: :obj:`dict`
81
+ Keys of participant labels and values of the sessions to process.
47
82
"""
48
83
from niworkflows .engine .workflows import LiterateWorkflow as Workflow
49
84
from niworkflows .interfaces .bids import BIDSFreeSurferDir
@@ -66,32 +101,40 @@ def init_nibabies_wf():
66
101
if config .execution .fs_subjects_dir is not None :
67
102
fsdir .inputs .subjects_dir = str (config .execution .fs_subjects_dir .absolute ())
68
103
69
- for subject_id in config .execution .participant_label :
70
- single_subject_wf = init_single_subject_wf (subject_id )
104
+ for subject_id , sessions in participants_table .items ():
105
+ for session_id in sessions :
106
+ single_subject_wf = init_single_subject_wf (subject_id , session_id = session_id )
71
107
72
- single_subject_wf .config ["execution" ]["crashdump_dir" ] = str (
73
- config .execution .nibabies_dir / f"sub-{ subject_id } " / "log" / config .execution .run_uuid
74
- )
75
- for node in single_subject_wf ._get_all_nodes ():
76
- node .config = deepcopy (single_subject_wf .config )
77
- if freesurfer :
78
- nibabies_wf .connect (fsdir , "subjects_dir" , single_subject_wf , "inputnode.subjects_dir" )
79
- else :
80
- nibabies_wf .add_nodes ([single_subject_wf ])
81
-
82
- # Dump a copy of the config file into the log directory
83
- log_dir = (
84
- config .execution .nibabies_dir / f"sub-{ subject_id } " / "log" / config .execution .run_uuid
85
- )
86
- log_dir .mkdir (exist_ok = True , parents = True )
87
- config .to_filename (log_dir / "nibabies.toml" )
108
+ bids_level = [f"sub-{ subject_id } " ]
109
+ if session_id :
110
+ bids_level .append (f"ses-{ session_id } " )
111
+
112
+ log_dir = (
113
+ config .execution .nibabies_dir .joinpath (* bids_level )
114
+ / "log"
115
+ / config .execution .run_uuid
116
+ )
117
+
118
+ single_subject_wf .config ["execution" ]["crashdump_dir" ] = str (log_dir )
119
+ for node in single_subject_wf ._get_all_nodes ():
120
+ node .config = deepcopy (single_subject_wf .config )
121
+ if freesurfer :
122
+ nibabies_wf .connect (
123
+ fsdir , "subjects_dir" , single_subject_wf , "inputnode.subjects_dir"
124
+ )
125
+ else :
126
+ nibabies_wf .add_nodes ([single_subject_wf ])
127
+
128
+ # Dump a copy of the config file into the log directory
129
+ log_dir .mkdir (exist_ok = True , parents = True )
130
+ config .to_filename (log_dir / "nibabies.toml" )
88
131
89
132
return nibabies_wf
90
133
91
134
92
- def init_single_subject_wf (subject_id ):
135
+ def init_single_subject_wf (subject_id , session_id = None ):
93
136
"""
94
- Organize the preprocessing pipeline for a single subject.
137
+ Organize the preprocessing pipeline for a single subject, at a single session .
95
138
96
139
It collects and reports information about the subject, and prepares
97
140
sub-workflows to perform anatomical and functional preprocessing.
@@ -114,6 +157,8 @@ def init_single_subject_wf(subject_id):
114
157
----------
115
158
subject_id : :obj:`str`
116
159
Subject label for this single-subject workflow.
160
+ session_id : :obj:`str` or None
161
+ Session identifier.
117
162
118
163
Inputs
119
164
------
@@ -130,10 +175,15 @@ def init_single_subject_wf(subject_id):
130
175
from ..utils .misc import fix_multi_source_name
131
176
from .anatomical import init_infant_anat_wf
132
177
133
- name = "single_subject_%s_wf" % subject_id
178
+ name = (
179
+ f"single_subject_{ subject_id } _{ session_id } _wf"
180
+ if session_id
181
+ else f"single_subject_{ subject_id } _wf"
182
+ )
134
183
subject_data = collect_data (
135
184
config .execution .layout ,
136
185
subject_id ,
186
+ session_id = session_id ,
137
187
task = config .execution .task_id ,
138
188
echo = config .execution .echo_idx ,
139
189
bids_filters = config .execution .bids_filters ,
@@ -350,6 +400,7 @@ def init_single_subject_wf(subject_id):
350
400
fmap_estimators = find_estimators (
351
401
layout = config .execution .layout ,
352
402
subject = subject_id ,
403
+ sessions = session_id ,
353
404
fmapless = False , # config.workflow.use_syn,
354
405
force_fmapless = False , # config.workflow.force_syn,
355
406
)
@@ -374,7 +425,11 @@ def init_single_subject_wf(subject_id):
374
425
# 3) total readout time
375
426
from niworkflows .workflows .epi .refmap import init_epi_reference_wf
376
427
377
- _ , bold_groupings = group_bolds_ref (layout = config .execution .layout , subject = subject_id )
428
+ _ , bold_groupings = group_bolds_ref (
429
+ layout = config .execution .layout ,
430
+ subject = subject_id ,
431
+ session_id = session_id ,
432
+ )
378
433
if any (not x for x in bold_groupings ):
379
434
print ("No BOLD files found for one or more reference groupings" )
380
435
return workflow
0 commit comments