|
80 | 80 | },
|
81 | 81 | {
|
82 | 82 | "cell_type": "code",
|
83 |
| - "execution_count": null, |
| 83 | + "execution_count": 5, |
84 | 84 | "metadata": {
|
85 | 85 | "collapsed": false,
|
86 | 86 | "deletable": true,
|
|
91 | 91 | "from nipype import DataGrabber, Node\n",
|
92 | 92 | "\n",
|
93 | 93 | "# Create DataGrabber node\n",
|
94 |
| - "dg = Node(DataGrabber(infields=['subject_id', 'task_name'],\n", |
| 94 | + "dg = Node(DataGrabber(infields=['subject_id', 'ses_name', 'task_name'],\n", |
95 | 95 | " outfields=['anat', 'func']),\n",
|
96 | 96 | " name='datagrabber')\n",
|
97 | 97 | "\n",
|
|
112 | 112 | "source": [
|
113 | 113 | "Second, we know that the two files we desire are the the following location:\n",
|
114 | 114 | "\n",
|
115 |
| - " anat = /data/ds000114/sub-01/anat/sub-01_T1w.nii.gz\n", |
116 |
| - " func = /data/ds000114/sub-01/func/sub-01_task-fingerfootlips_bold.nii.gz\n", |
| 115 | + " anat = /data/ds000114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz\n", |
| 116 | + " func = /data/ds000114/sub-01/ses-test/func/sub-01_ses-test_task-fingerfootlips_bold.nii.gz\n", |
117 | 117 | "\n",
|
118 |
| - "We see that the two files only have two dynamic parameters between subjects and task names:\n", |
| 118 | + "We see that the two files only have three dynamic parameters between subjects and task names:\n", |
119 | 119 | "\n",
|
120 | 120 | " subject_id: in this case 'sub-01'\n",
|
121 | 121 | " task_name: in this case fingerfootlips\n",
|
| 122 | + " ses_name: test\n", |
122 | 123 | "\n",
|
123 | 124 | "This means that we can rewrite the paths as follows:\n",
|
124 | 125 | "\n",
|
125 |
| - " anat = /data/ds102/[subject_id]/anat/[subject_id]_T1w.nii.gz\n", |
126 |
| - " func = /data/ds102/[subject_id]/func/[subject_id]_task-[task_name]_bold.nii.gz\n", |
| 126 | + " anat = /data/ds102/[subject_id]/ses-[ses_name]/anat/sub-[subject_id]_ses-[ses_name]_T1w.nii.gz\n", |
| 127 | + " func = /data/ds102/[subject_id]/ses-[ses_name]/func/sub-[subject_id]_ses-[ses_name]_task-[task_name]_bold.nii.gz\n", |
127 | 128 | "\n",
|
128 |
| - "Therefore, we need the parameter ``subject_id`` for the anatomical image and the parameter ``subject_id`` and ``task_name`` for the functional image. In the context of DataGabber, this is specified as follows:" |
| 129 | + "Therefore, we need the parameters ``subject_id`` and ``ses_name`` for the anatomical image and the parameters ``subject_id``, ``ses_name`` and ``task_name`` for the functional image. In the context of DataGabber, this is specified as follows:" |
129 | 130 | ]
|
130 | 131 | },
|
131 | 132 | {
|
132 | 133 | "cell_type": "code",
|
133 |
| - "execution_count": null, |
| 134 | + "execution_count": 6, |
134 | 135 | "metadata": {
|
135 | 136 | "collapsed": true,
|
136 | 137 | "deletable": true,
|
137 | 138 | "editable": true
|
138 | 139 | },
|
139 | 140 | "outputs": [],
|
140 | 141 | "source": [
|
141 |
| - "dg.inputs.template_args = {'anat': [['subject_id']],\n", |
142 |
| - " 'func': [['subject_id', 'task_name']]}" |
| 142 | + "dg.inputs.template_args = {'anat': [['subject_id', 'ses_name']],\n", |
| 143 | + " 'func': [['subject_id', 'ses_name', 'task_name']]}" |
143 | 144 | ]
|
144 | 145 | },
|
145 | 146 | {
|
|
154 | 155 | },
|
155 | 156 | {
|
156 | 157 | "cell_type": "code",
|
157 |
| - "execution_count": null, |
| 158 | + "execution_count": 7, |
158 | 159 | "metadata": {
|
159 | 160 | "collapsed": true,
|
160 | 161 | "deletable": true,
|
161 | 162 | "editable": true
|
162 | 163 | },
|
163 | 164 | "outputs": [],
|
164 | 165 | "source": [
|
165 |
| - "dg.inputs.field_template = {'anat': 'sub-%02d/anat/*_T1w.nii.gz',\n", |
166 |
| - " 'func': 'sub-%02d/func/*task-%s_bold.nii.gz'}" |
| 166 | + "dg.inputs.field_template = {'anat': 'sub-%02d/ses-%s/anat/*_T1w.nii.gz',\n", |
| 167 | + " 'func': 'sub-%02d/ses-%s/func/*task-%s_bold.nii.gz'}" |
167 | 168 | ]
|
168 | 169 | },
|
169 | 170 | {
|
|
173 | 174 | "editable": true
|
174 | 175 | },
|
175 | 176 | "source": [
|
176 |
| - "You'll notice that we use ``%s``, ``%02d`` and ``*`` for placeholders in the data paths. ``%s`` is a placeholder for a string and is filled out by ``task_name``. ``%02d`` is a placeholder for a integer number and is filled out by ``subject_id``. ``*`` is used as a wild card, e.g. a placeholder for any possible string combination. This is all to set up the ``DataGrabber`` node." |
| 177 | + "You'll notice that we use ``%s``, ``%02d`` and ``*`` for placeholders in the data paths. ``%s`` is a placeholder for a string and is filled out by ``task_name`` or ``ses_name``. ``%02d`` is a placeholder for a integer number and is filled out by ``subject_id``. ``*`` is used as a wild card, e.g. a placeholder for any possible string combination. This is all to set up the ``DataGrabber`` node." |
177 | 178 | ]
|
178 | 179 | },
|
179 | 180 | {
|
|
183 | 184 | "editable": true
|
184 | 185 | },
|
185 | 186 | "source": [
|
186 |
| - "Now it is up to you how you want to feed the dynamic parameters into the node. You can either do this by using another node (e.g. ``IdentityInterface``) and feed ``subject_id`` and ``task_name`` as connections to the ``DataGrabber`` node or specify them directly as node inputs." |
| 187 | + "Now it is up to you how you want to feed the dynamic parameters into the node. You can either do this by using another node (e.g. ``IdentityInterface``) and feed ``subject_id``, ``ses_name`` and ``task_name`` as connections to the ``DataGrabber`` node or specify them directly as node inputs." |
187 | 188 | ]
|
188 | 189 | },
|
189 | 190 | {
|
190 | 191 | "cell_type": "code",
|
191 |
| - "execution_count": null, |
| 192 | + "execution_count": 8, |
192 | 193 | "metadata": {
|
193 | 194 | "collapsed": false,
|
194 | 195 | "deletable": true,
|
|
201 | 202 | "infosource = Node(IdentityInterface(fields=['subject_id', 'task_name']),\n",
|
202 | 203 | " name=\"infosource\")\n",
|
203 | 204 | "infosource.inputs.task_name = \"fingerfootlips\"\n",
|
| 205 | + "infosource.inputs.ses_name = \"test\"\n", |
204 | 206 | "subject_id_list = [1, 2]\n",
|
205 | 207 | "infosource.iterables = [('subject_id', subject_id_list)]"
|
206 | 208 | ]
|
|
222 | 224 | "editable": true
|
223 | 225 | },
|
224 | 226 | "source": [
|
225 |
| - "If you specify the inputs to the ``DataGrabber`` node directly, you can do this as follows:" |
| 227 | + "You can also provide the inputs to the ``DataGrabber`` node directly, for one subject you can do this as follows:" |
226 | 228 | ]
|
227 | 229 | },
|
228 | 230 | {
|
229 | 231 | "cell_type": "code",
|
230 |
| - "execution_count": null, |
| 232 | + "execution_count": 9, |
231 | 233 | "metadata": {
|
232 | 234 | "collapsed": true,
|
233 | 235 | "deletable": true,
|
|
237 | 239 | "source": [
|
238 | 240 | "# Specifying the input fields of DataGrabber directly\n",
|
239 | 241 | "dg.inputs.subject_id = 1\n",
|
| 242 | + "dg.inputs.ses_name = \"test\"\n", |
240 | 243 | "dg.inputs.task_name = \"fingerfootlips\""
|
241 | 244 | ]
|
242 | 245 | },
|
|
252 | 255 | },
|
253 | 256 | {
|
254 | 257 | "cell_type": "code",
|
255 |
| - "execution_count": null, |
| 258 | + "execution_count": 10, |
256 | 259 | "metadata": {
|
257 | 260 | "collapsed": false,
|
258 | 261 | "deletable": true,
|
|
263 | 266 | "name": "stdout",
|
264 | 267 | "output_type": "stream",
|
265 | 268 | "text": [
|
266 |
| - "170716-08:56:43,740 workflow INFO:\n", |
267 |
| - "\t Executing node datagrabber in dir: /tmp/tmplw952u04/datagrabber\n" |
| 269 | + "170727-19:13:54,954 workflow INFO:\n", |
| 270 | + "\t Executing node datagrabber in dir: /tmp/tmpzh0nl8du/datagrabber\n" |
268 | 271 | ]
|
269 | 272 | },
|
270 | 273 | {
|
271 | 274 | "data": {
|
272 | 275 | "text/plain": [
|
273 | 276 | "\n",
|
274 |
| - "anat = /data/ds000114/sub-01/anat/sub-01_T1w.nii.gz\n", |
275 |
| - "func = /data/ds000114/sub-01/func/sub-01_task-fingerfootlips_bold.nii.gz" |
| 277 | + "anat = /data/ds000114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz\n", |
| 278 | + "func = /data/ds000114/sub-01/ses-test/func/sub-01_ses-test_task-fingerfootlips_bold.nii.gz" |
276 | 279 | ]
|
277 | 280 | },
|
278 |
| - "execution_count": null, |
| 281 | + "execution_count": 10, |
279 | 282 | "metadata": {},
|
280 | 283 | "output_type": "execute_result"
|
281 | 284 | }
|
|
297 | 300 | "\n",
|
298 | 301 | "Let's focus again on the data we want to import:\n",
|
299 | 302 | "\n",
|
300 |
| - " anat = /data/ds000114/sub-01/anat/sub-01_T1w.nii.gz\n", |
301 |
| - " func = /data/ds000114/sub-01/func/sub-01_task-fingerfootlips_bold.nii.gz\n", |
| 303 | + " anat = /data/ds000114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz\n", |
| 304 | + " func = /data/ds000114/sub-01/ses-test/func/sub-01_ses-test_task-fingerfootlips_bold.nii.gz\n", |
302 | 305 | " \n",
|
303 | 306 | "Now, we can replace those paths with the accoridng {}-based strings.\n",
|
304 | 307 | "\n",
|
305 |
| - " anat = /data/ds000114/sub-{subject_id}/anat/sub-{subject_id}_T1w.nii.gz\n", |
306 |
| - " func = /data/ds000114/sub-{subject_id}/func/sub-{subject_id}_task-{task_name}_bold.nii.gz\n", |
| 308 | + " anat = /data/ds000114/sub-{subject_id}/ses-{ses_name}/anat/sub-{subject_id}_ses-{ses_name}_T1w.nii.gz\n", |
| 309 | + " func = /data/ds000114/sub-{subject_id}/ses-{ses_name}/func/ \\\n", |
| 310 | + " sub-{subject_id}_ses-{ses_name}_task-{task_name}_bold.nii.gz\n", |
307 | 311 | "\n",
|
308 | 312 | "How would this look like as a `SelectFiles` node?"
|
309 | 313 | ]
|
310 | 314 | },
|
311 | 315 | {
|
312 | 316 | "cell_type": "code",
|
313 |
| - "execution_count": null, |
| 317 | + "execution_count": 12, |
314 | 318 | "metadata": {
|
315 | 319 | "collapsed": false,
|
316 | 320 | "deletable": true,
|
|
321 | 325 | "from nipype import SelectFiles, Node\n",
|
322 | 326 | "\n",
|
323 | 327 | "# String template with {}-based strings\n",
|
324 |
| - "templates = {'anat': 'sub-{subject_id}/anat/sub-{subject_id}_T1w.nii.gz',\n", |
325 |
| - " 'func': 'sub-{subject_id}/func/sub-{subject_id}_task-{task_name}_bold.nii.gz'}\n", |
| 328 | + "templates = {'anat': 'sub-{subject_id}/ses-{ses_name}/anat/sub-{subject_id}_ses-{ses_name}_T1w.nii.gz',\n", |
| 329 | + " 'func': 'sub-{subject_id}/ses-{ses_name}/func/sub-{subject_id}_ses-{ses_name}_task-{task_name}_bold.nii.gz'}\n", |
326 | 330 | "\n",
|
327 | 331 | "# Create SelectFiles node\n",
|
328 | 332 | "sf = Node(SelectFiles(templates),\n",
|
|
333 | 337 | "\n",
|
334 | 338 | "# Feed {}-based placeholder strings with values\n",
|
335 | 339 | "sf.inputs.subject_id = '01'\n",
|
| 340 | + "sf.inputs.ses_name = \"test\"\n", |
336 | 341 | "sf.inputs.task_name = 'fingerfootlips'"
|
337 | 342 | ]
|
338 | 343 | },
|
|
348 | 353 | },
|
349 | 354 | {
|
350 | 355 | "cell_type": "code",
|
351 |
| - "execution_count": null, |
| 356 | + "execution_count": 13, |
352 | 357 | "metadata": {
|
353 | 358 | "collapsed": false,
|
354 | 359 | "deletable": true,
|
|
359 | 364 | "name": "stdout",
|
360 | 365 | "output_type": "stream",
|
361 | 366 | "text": [
|
362 |
| - "170716-08:57:26,899 workflow INFO:\n", |
363 |
| - "\t Executing node selectfiles in dir: /tmp/tmpys0agcu4/selectfiles\n" |
| 367 | + "170727-19:18:15,247 workflow INFO:\n", |
| 368 | + "\t Executing node selectfiles in dir: /tmp/tmpkxrlth4a/selectfiles\n" |
364 | 369 | ]
|
365 | 370 | },
|
366 | 371 | {
|
367 | 372 | "data": {
|
368 | 373 | "text/plain": [
|
369 | 374 | "\n",
|
370 |
| - "anat = /data/ds000114/sub-01/anat/sub-01_T1w.nii.gz\n", |
371 |
| - "func = /data/ds000114/sub-01/func/sub-01_task-fingerfootlips_bold.nii.gz" |
| 375 | + "anat = /data/ds000114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz\n", |
| 376 | + "func = /data/ds000114/sub-01/ses-test/func/sub-01_ses-test_task-fingerfootlips_bold.nii.gz" |
372 | 377 | ]
|
373 | 378 | },
|
374 |
| - "execution_count": null, |
| 379 | + "execution_count": 13, |
375 | 380 | "metadata": {},
|
376 | 381 | "output_type": "execute_result"
|
377 | 382 | }
|
|
398 | 403 | },
|
399 | 404 | {
|
400 | 405 | "cell_type": "code",
|
401 |
| - "execution_count": null, |
| 406 | + "execution_count": 15, |
402 | 407 | "metadata": {
|
403 | 408 | "collapsed": false,
|
404 | 409 | "deletable": true,
|
|
409 | 414 | "name": "stdout",
|
410 | 415 | "output_type": "stream",
|
411 | 416 | "text": [
|
412 |
| - "170716-08:57:41,262 workflow INFO:\n", |
413 |
| - "\t Executing node selectfiles in dir: /tmp/tmpet7ix46z/selectfiles\n" |
| 417 | + "170727-19:21:09,233 workflow INFO:\n", |
| 418 | + "\t Executing node selectfiles in dir: /tmp/tmphih2czqa/selectfiles\n" |
414 | 419 | ]
|
415 | 420 | },
|
416 | 421 | {
|
417 | 422 | "data": {
|
418 | 423 | "text/plain": [
|
419 | 424 | "\n",
|
420 |
| - "anat = ['/data/ds000114/sub-01/anat/sub-01_T1w.nii.gz', '/data/ds000114/sub-02/anat/sub-02_T1w.nii.gz']" |
| 425 | + "anat = ['/data/ds000114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz', '/data/ds000114/sub-02/ses-test/anat/sub-02_ses-test_T1w.nii.gz']" |
421 | 426 | ]
|
422 | 427 | },
|
423 |
| - "execution_count": null, |
| 428 | + "execution_count": 15, |
424 | 429 | "metadata": {},
|
425 | 430 | "output_type": "execute_result"
|
426 | 431 | }
|
|
430 | 435 | "from os.path import abspath as opap\n",
|
431 | 436 | "\n",
|
432 | 437 | "# String template with {}-based strings\n",
|
433 |
| - "templates = {'anat': 'sub-0[1,2]/anat/sub-0[1,2]_T1w.nii.gz'}\n", |
| 438 | + "templates = {'anat': 'sub-0[1,2]/ses-{ses_name}/anat/sub-0[1,2]_ses-{ses_name}_T1w.nii.gz'}\n", |
434 | 439 | "\n",
|
435 | 440 | "\n",
|
436 | 441 | "# Create SelectFiles node\n",
|
|
440 | 445 | "# Location of the dataset folder\n",
|
441 | 446 | "sf.inputs.base_directory = '/data/ds000114'\n",
|
442 | 447 | "\n",
|
| 448 | + "# Feed {}-based placeholder strings with values\n", |
| 449 | + "sf.inputs.ses_name = 'test'\n", |
| 450 | + "\n", |
443 | 451 | "# Print SelectFiles output\n",
|
444 | 452 | "sf.run().outputs"
|
445 | 453 | ]
|
|
453 | 461 | "source": [
|
454 | 462 | "As you can see, now `anat` contains two file paths, one for the first and one for the second subject. As a side node, you could have also gotten them same thing with the wild card `*`:\n",
|
455 | 463 | "\n",
|
456 |
| - " 'sub-0*/anat/sub-0*_T1w.nii.gz'" |
| 464 | + " 'sub-0*/ses-test/anat/sub-0*_ses-test_T1w.nii.gz'" |
457 | 465 | ]
|
458 | 466 | },
|
459 | 467 | {
|
|
686 | 694 | "name": "python",
|
687 | 695 | "nbconvert_exporter": "python",
|
688 | 696 | "pygments_lexer": "ipython3",
|
689 |
| - "version": "3.5.2" |
| 697 | + "version": "3.6.2" |
690 | 698 | }
|
691 | 699 | },
|
692 | 700 | "nbformat": 4,
|
693 |
| - "nbformat_minor": 1 |
| 701 | + "nbformat_minor": 2 |
694 | 702 | }
|
0 commit comments