@@ -184,20 +184,35 @@ class DerivativesDataSink(SimpleInterface):
184
184
Saves the `in_file` into a BIDS-Derivatives folder provided
185
185
by `base_directory`, given the input reference `source_file`.
186
186
187
+ >>> from pathlib import Path
187
188
>>> import tempfile
188
189
>>> from fmriprep.utils.bids import collect_data
189
- >>> tmpdir = tempfile.mkdtemp()
190
- >>> tmpfile = os.path.join( tmpdir, 'a_temp_file.nii.gz')
191
- >>> open(tmpfile, 'w').close() # "touch" the file
192
- >>> dsink = DerivativesDataSink(base_directory=tmpdir)
193
- >>> dsink.inputs.in_file = tmpfile
190
+ >>> tmpdir = Path( tempfile.mkdtemp() )
191
+ >>> tmpfile = tmpdir / 'a_temp_file.nii.gz'
192
+ >>> tmpfile. open('w').close() # "touch" the file
193
+ >>> dsink = DerivativesDataSink(base_directory=str( tmpdir) )
194
+ >>> dsink.inputs.in_file = str( tmpfile)
194
195
>>> dsink.inputs.source_file = collect_data('ds114', '01')[0]['t1w'][0]
195
196
>>> dsink.inputs.keep_dtype = True
196
197
>>> dsink.inputs.suffix = 'target-mni'
197
198
>>> res = dsink.run()
198
199
>>> res.outputs.out_file # doctest: +ELLIPSIS
199
200
'.../fmriprep/sub-01/ses-retest/anat/sub-01_ses-retest_target-mni_T1w.nii.gz'
200
201
202
+ >>> bids_dir = tmpdir / 'bidsroot' / 'sub-02' / 'ses-noanat' / 'func'
203
+ >>> bids_dir.mkdir(parents=True, exist_ok=True)
204
+ >>> tricky_source = bids_dir / 'sub-02_ses-noanat_task-rest_run-01_bold.nii.gz'
205
+ >>> tricky_source.open('w').close()
206
+ >>> dsink = DerivativesDataSink(base_directory=str(tmpdir))
207
+ >>> dsink.inputs.in_file = str(tmpfile)
208
+ >>> dsink.inputs.source_file = str(tricky_source)
209
+ >>> dsink.inputs.keep_dtype = True
210
+ >>> dsink.inputs.desc = 'preproc'
211
+ >>> res = dsink.run()
212
+ >>> res.outputs.out_file # doctest: +ELLIPSIS
213
+ '.../fmriprep/sub-02/ses-noanat/func/sub-02_ses-noanat_task-rest_run-01_\
214
+ desc-preproc_bold.nii.gz'
215
+
201
216
"""
202
217
input_spec = DerivativesDataSinkInputSpec
203
218
output_spec = DerivativesDataSinkOutputSpec
@@ -221,15 +236,7 @@ def _run_interface(self, runtime):
221
236
222
237
m = BIDS_NAME .search (src_fname )
223
238
224
- # TODO this quick and dirty modality detection needs to be implemented
225
- # correctly
226
- mod = 'func'
227
- if 'anat' in op .dirname (self .inputs .source_file ):
228
- mod = 'anat'
229
- elif 'dwi' in op .dirname (self .inputs .source_file ):
230
- mod = 'dwi'
231
- elif 'fmap' in op .dirname (self .inputs .source_file ):
232
- mod = 'fmap'
239
+ mod = op .basename (op .dirname (self .inputs .source_file ))
233
240
234
241
base_directory = runtime .cwd
235
242
if isdefined (self .inputs .base_directory ):
0 commit comments