@@ -89,17 +89,41 @@ def run(command, env={}, ignore_errors=False):
8989run ("bids-validator " + args .bids_dir )
9090
9191subject_dirs = glob (os .path .join (args .bids_dir , "sub-*" ))
92+
9293if args .acquisition_label :
9394 acq_tpl = "*acq-%s*" % args .acquisition_label
9495else :
9596 acq_tpl = "*"
9697
98+ # if there are session folders, check if study is truly longitudinal by
99+ # searching for the first subject with more than one valid sessions
100+ multi_session_study = False
101+ if glob (os .path .join (args .bids_dir , "sub-*" , "ses-*" )):
102+ subjects = [subject_dir .split ("-" )[- 1 ] for subject_dir in subject_dirs ]
103+ for subject_label in subjects :
104+ session_dirs = glob (os .path .join (args .bids_dir ,"sub-%s" % subject_label ,"ses-*" ))
105+ sessions = [os .path .split (dr )[- 1 ].split ("-" )[- 1 ] for dr in session_dirs ]
106+ n_valid_sessions = 0
107+ for session_label in sessions :
108+ if glob (os .path .join (args .bids_dir , "sub-%s" % subject_label ,
109+ "ses-%s" % session_label ,
110+ "anat" ,
111+ "%s_T1w.nii*" % acq_tpl )):
112+ n_valid_sessions += 1
113+ if n_valid_sessions > 1 :
114+ multi_session_study = True
115+ break
116+
117+ if multi_session_study and (args .multiple_sessions == "longitudinal" ):
118+ longitudinal_study = True
119+ else :
120+ longitudinal_study = False
121+
97122if args .refine_pial_acquisition_label :
98123 acq_t2 = "*acq-%s*" % args .refine_pial_acquisition_label
99124else :
100125 acq_t2 = "*"
101126
102-
103127subjects_to_analyze = []
104128# only for a subset of subjects
105129if args .participant_label :
@@ -125,23 +149,10 @@ def run(command, env={}, ignore_errors=False):
125149 ignore_errors = True )
126150
127151 for subject_label in subjects_to_analyze :
128-
129- # Check for multiple sessions to combine as a multiday session or as a longitudinal stream
130152 session_dirs = glob (os .path .join (args .bids_dir ,"sub-%s" % subject_label ,"ses-*" ))
131153 sessions = [os .path .split (dr )[- 1 ].split ("-" )[- 1 ] for dr in session_dirs ]
132- longitudinal_study = False
133- n_valid_sessions = 0
134- for session_label in sessions :
135- if glob (os .path .join (args .bids_dir , "sub-%s" % subject_label ,
136- "ses-%s" % session_label ,
137- "anat" ,
138- "%s_T1w.nii*" % acq_tpl )):
139- n_valid_sessions += 1
140- if n_valid_sessions > 1 and args .multiple_sessions == "longitudinal" :
141- longitudinal_study = True
142154
143155 timepoints = []
144-
145156 if len (sessions ) > 0 and longitudinal_study == True :
146157 # Running each session separately, prior to doing longitudinal pipeline
147158 for session_label in sessions :
0 commit comments