Skip to content

Commit 0e7a8a7

Browse files
committed
some updates to basic input, input-bids and output after updating dataset; after adding derivatives input requires more updates
1 parent f56e1b0 commit 0e7a8a7

File tree

3 files changed

+1409
-286
lines changed

3 files changed

+1409
-286
lines changed

notebooks/basic_data_input.ipynb

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
},
8181
{
8282
"cell_type": "code",
83-
"execution_count": null,
83+
"execution_count": 5,
8484
"metadata": {
8585
"collapsed": false,
8686
"deletable": true,
@@ -91,7 +91,7 @@
9191
"from nipype import DataGrabber, Node\n",
9292
"\n",
9393
"# 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",
9595
" outfields=['anat', 'func']),\n",
9696
" name='datagrabber')\n",
9797
"\n",
@@ -112,34 +112,35 @@
112112
"source": [
113113
"Second, we know that the two files we desire are the the following location:\n",
114114
"\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",
117117
"\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",
119119
"\n",
120120
" subject_id: in this case 'sub-01'\n",
121121
" task_name: in this case fingerfootlips\n",
122+
" ses_name: test\n",
122123
"\n",
123124
"This means that we can rewrite the paths as follows:\n",
124125
"\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",
127128
"\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:"
129130
]
130131
},
131132
{
132133
"cell_type": "code",
133-
"execution_count": null,
134+
"execution_count": 6,
134135
"metadata": {
135136
"collapsed": true,
136137
"deletable": true,
137138
"editable": true
138139
},
139140
"outputs": [],
140141
"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']]}"
143144
]
144145
},
145146
{
@@ -154,16 +155,16 @@
154155
},
155156
{
156157
"cell_type": "code",
157-
"execution_count": null,
158+
"execution_count": 7,
158159
"metadata": {
159160
"collapsed": true,
160161
"deletable": true,
161162
"editable": true
162163
},
163164
"outputs": [],
164165
"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'}"
167168
]
168169
},
169170
{
@@ -173,7 +174,7 @@
173174
"editable": true
174175
},
175176
"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."
177178
]
178179
},
179180
{
@@ -183,12 +184,12 @@
183184
"editable": true
184185
},
185186
"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."
187188
]
188189
},
189190
{
190191
"cell_type": "code",
191-
"execution_count": null,
192+
"execution_count": 8,
192193
"metadata": {
193194
"collapsed": false,
194195
"deletable": true,
@@ -201,6 +202,7 @@
201202
"infosource = Node(IdentityInterface(fields=['subject_id', 'task_name']),\n",
202203
" name=\"infosource\")\n",
203204
"infosource.inputs.task_name = \"fingerfootlips\"\n",
205+
"infosource.inputs.ses_name = \"test\"\n",
204206
"subject_id_list = [1, 2]\n",
205207
"infosource.iterables = [('subject_id', subject_id_list)]"
206208
]
@@ -222,12 +224,12 @@
222224
"editable": true
223225
},
224226
"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:"
226228
]
227229
},
228230
{
229231
"cell_type": "code",
230-
"execution_count": null,
232+
"execution_count": 9,
231233
"metadata": {
232234
"collapsed": true,
233235
"deletable": true,
@@ -237,6 +239,7 @@
237239
"source": [
238240
"# Specifying the input fields of DataGrabber directly\n",
239241
"dg.inputs.subject_id = 1\n",
242+
"dg.inputs.ses_name = \"test\"\n",
240243
"dg.inputs.task_name = \"fingerfootlips\""
241244
]
242245
},
@@ -252,7 +255,7 @@
252255
},
253256
{
254257
"cell_type": "code",
255-
"execution_count": null,
258+
"execution_count": 10,
256259
"metadata": {
257260
"collapsed": false,
258261
"deletable": true,
@@ -263,19 +266,19 @@
263266
"name": "stdout",
264267
"output_type": "stream",
265268
"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"
268271
]
269272
},
270273
{
271274
"data": {
272275
"text/plain": [
273276
"\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"
276279
]
277280
},
278-
"execution_count": null,
281+
"execution_count": 10,
279282
"metadata": {},
280283
"output_type": "execute_result"
281284
}
@@ -297,20 +300,21 @@
297300
"\n",
298301
"Let's focus again on the data we want to import:\n",
299302
"\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",
302305
" \n",
303306
"Now, we can replace those paths with the accoridng {}-based strings.\n",
304307
"\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",
307311
"\n",
308312
"How would this look like as a `SelectFiles` node?"
309313
]
310314
},
311315
{
312316
"cell_type": "code",
313-
"execution_count": null,
317+
"execution_count": 12,
314318
"metadata": {
315319
"collapsed": false,
316320
"deletable": true,
@@ -321,8 +325,8 @@
321325
"from nipype import SelectFiles, Node\n",
322326
"\n",
323327
"# 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",
326330
"\n",
327331
"# Create SelectFiles node\n",
328332
"sf = Node(SelectFiles(templates),\n",
@@ -333,6 +337,7 @@
333337
"\n",
334338
"# Feed {}-based placeholder strings with values\n",
335339
"sf.inputs.subject_id = '01'\n",
340+
"sf.inputs.ses_name = \"test\"\n",
336341
"sf.inputs.task_name = 'fingerfootlips'"
337342
]
338343
},
@@ -348,7 +353,7 @@
348353
},
349354
{
350355
"cell_type": "code",
351-
"execution_count": null,
356+
"execution_count": 13,
352357
"metadata": {
353358
"collapsed": false,
354359
"deletable": true,
@@ -359,19 +364,19 @@
359364
"name": "stdout",
360365
"output_type": "stream",
361366
"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"
364369
]
365370
},
366371
{
367372
"data": {
368373
"text/plain": [
369374
"\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"
372377
]
373378
},
374-
"execution_count": null,
379+
"execution_count": 13,
375380
"metadata": {},
376381
"output_type": "execute_result"
377382
}
@@ -398,7 +403,7 @@
398403
},
399404
{
400405
"cell_type": "code",
401-
"execution_count": null,
406+
"execution_count": 15,
402407
"metadata": {
403408
"collapsed": false,
404409
"deletable": true,
@@ -409,18 +414,18 @@
409414
"name": "stdout",
410415
"output_type": "stream",
411416
"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"
414419
]
415420
},
416421
{
417422
"data": {
418423
"text/plain": [
419424
"\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']"
421426
]
422427
},
423-
"execution_count": null,
428+
"execution_count": 15,
424429
"metadata": {},
425430
"output_type": "execute_result"
426431
}
@@ -430,7 +435,7 @@
430435
"from os.path import abspath as opap\n",
431436
"\n",
432437
"# 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",
434439
"\n",
435440
"\n",
436441
"# Create SelectFiles node\n",
@@ -440,6 +445,9 @@
440445
"# Location of the dataset folder\n",
441446
"sf.inputs.base_directory = '/data/ds000114'\n",
442447
"\n",
448+
"# Feed {}-based placeholder strings with values\n",
449+
"sf.inputs.ses_name = 'test'\n",
450+
"\n",
443451
"# Print SelectFiles output\n",
444452
"sf.run().outputs"
445453
]
@@ -453,7 +461,7 @@
453461
"source": [
454462
"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",
455463
"\n",
456-
" 'sub-0*/anat/sub-0*_T1w.nii.gz'"
464+
" 'sub-0*/ses-test/anat/sub-0*_ses-test_T1w.nii.gz'"
457465
]
458466
},
459467
{
@@ -686,9 +694,9 @@
686694
"name": "python",
687695
"nbconvert_exporter": "python",
688696
"pygments_lexer": "ipython3",
689-
"version": "3.5.2"
697+
"version": "3.6.2"
690698
}
691699
},
692700
"nbformat": 4,
693-
"nbformat_minor": 1
701+
"nbformat_minor": 2
694702
}

0 commit comments

Comments
 (0)