Skip to content

Commit cfb9bc5

Browse files
author
Mathieu Dubois
committed
Merge branch 'fix_tutorials' of https://github.com/duboism/nipype into fix_tutorials
Conflicts: doc/devel/cmd_interface_devel.rst doc/devel/matlab_interface_devel.rst doc/users/tutorial_101.rst examples/fmri_ants_openfmri.py examples/rsfmri_vol_surface_preprocessing_nipy.py
2 parents b4d0eee + cb80e24 commit cfb9bc5

File tree

5 files changed

+100
-26
lines changed

5 files changed

+100
-26
lines changed

doc/devel/cmd_interface_devel.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ above example we have used the ``desc`` metadata which holds human readable
3939
description of the input. The ``mandatory`` flag forces Nipype to throw an
4040
exception if the input was not set. ``exists`` is a special flag that works only
4141
for ``File traits`` and checks if the provided file exists. More details can be
42+
<<<<<<< HEAD
4243
found at :doc:`interface_specs`.
44+
=======
45+
found at :ref:`interface_specs`.
46+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
4347

4448
The input and output specifications have to be connected to the our example
4549
interface class:

doc/devel/matlab_interface_devel.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Example 2
2121
+++++++++
2222

2323
By subclassing :class:`nipype.interfaces.matlab.MatlabCommand` for your main class, and :class:`nipype.interfaces.matlab.MatlabInputSpec` for your input spec, you gain access to some useful MATLAB hooks
24+
<<<<<<< HEAD
2425

2526
.. literalinclude:: matlab_example2.py
2627

@@ -29,4 +30,13 @@ By subclassing :class:`nipype.interfaces.matlab.MatlabCommand` for your main cla
2930
You can download :download:`the source code of this example <matlab_example2.py>`.
3031

3132
.. include:: ../links_names.txt
33+
=======
3234

35+
.. literalinclude:: matlab_example2.py
36+
37+
.. admonition:: Example source code
38+
39+
You can download :download:`the source code of this example <matlab_example2.py>`.
40+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
41+
42+
.. include:: ../links_names.txt

doc/users/tutorial_101.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ This would be equivalent to:
4343
.. testcode::
4444

4545
realigner = pe.Node(interface=spm.Realign(infile=os.abspath('somefuncrun.nii'),
46+
<<<<<<< HEAD
4647
register_to_mean = True),
48+
=======
49+
register_to_mean = True),
50+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
4751
name='realign')
4852

4953
In Pythonic terms, this is saying that interface option in Node accepts
@@ -93,8 +97,13 @@ This results in a workflow containing two isolated nodes:
9397

9498
**5. Connecting nodes to each other**
9599

100+
<<<<<<< HEAD
96101
We want to connect the output produced by the node realignment to the input of
97102
the node smoothing. This is done as follows:
103+
=======
104+
We want to connect the output produced by realignment to the input of
105+
smoothing. This is done as follows:
106+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
98107

99108
.. literalinclude:: tutorial_101.py
100109
:lines: 31

examples/fmri_ants_openfmri.py

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def median(in_files):
7676
7777
out_file: a 3D Nifti file
7878
"""
79+
7980
average = None
8081
for idx, filename in enumerate(filename_to_list(in_files)):
8182
img = nb.load(filename)
@@ -111,6 +112,13 @@ def create_reg_workflow(name='registration'):
111112
outputspec.anat2target_transform : FLIRT+FNIRT transform
112113
outputspec.transformed_files : transformed files in target space
113114
outputspec.transformed_mean : mean image in target space
115+
<<<<<<< HEAD
116+
=======
117+
118+
Example
119+
-------
120+
See code below
121+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
114122
"""
115123

116124
register = pe.Workflow(name=name)
@@ -196,11 +204,12 @@ def create_reg_workflow(name='registration'):
196204

197205
"""
198206
Compute registration between the subject's structural and MNI template
199-
This is currently set to perform a very quick registration. However, the
200-
registration can be made significantly more accurate for cortical
201-
structures by increasing the number of iterations
202-
All parameters are set using the example from:
203-
#https://github.com/stnava/ANTs/blob/master/Scripts/newAntsExample.sh
207+
208+
* All parameters are set using the example from: \
209+
`newAntsExample.sh <https://github.com/stnava/ANTs/blob/master/Scripts/newAntsExample.sh>`_
210+
* This is currently set to perform a very quick registration. However,\
211+
the registration can be made significantly more accurate for cortical\
212+
structures by increasing the number of iterations.
204213
"""
205214

206215
reg = pe.Node(ants.Registration(), name='antsRegister')
@@ -242,7 +251,11 @@ def create_reg_workflow(name='registration'):
242251

243252
merge = pe.Node(niu.Merge(2), iterfield=['in2'], name='mergexfm')
244253
register.connect(convert2itk, 'itk_transform', merge, 'in2')
254+
<<<<<<< HEAD
245255
register.connect(reg, 'composite_transform', merge, 'in1')
256+
=======
257+
register.connect(reg, ('composite_transform', pickfirst), merge, 'in1')
258+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
246259

247260
"""
248261
Transform the mean image. First to anatomical and then to target
@@ -292,32 +305,46 @@ def create_reg_workflow(name='registration'):
292305
return register
293306

294307
def get_aparc_aseg(files):
295-
"""Return the aparc+aseg.mgz file"""
308+
"""
309+
Return the aparc+aseg.mgz file
310+
"""
311+
296312
for name in files:
297313
if 'aparc+aseg.mgz' in name:
298314
return name
299315
raise ValueError('aparc+aseg.mgz not found')
300316

317+
301318
def create_fs_reg_workflow(name='registration'):
302319
"""Create a FEAT preprocessing workflow together with freesurfer
303320
304321
Parameters
305322
----------
323+
<<<<<<< HEAD
306324
325+
=======
326+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
307327
name : name of workflow (default: 'registration')
308328
309-
Inputs::
329+
Inputs:
310330
311331
inputspec.source_files : files (filename or list of filenames to register)
312332
inputspec.mean_image : reference image to use
313333
inputspec.target_image : registration target
314334
315-
Outputs::
335+
Outputs:
316336
317337
outputspec.func2anat_transform : FLIRT transform
318338
outputspec.anat2target_transform : FLIRT+FNIRT transform
319339
outputspec.transformed_files : transformed files in target space
320340
outputspec.transformed_mean : mean image in target space
341+
<<<<<<< HEAD
342+
=======
343+
344+
Example
345+
-------
346+
See code below
347+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
321348
"""
322349

323350
register = Workflow(name=name)
@@ -354,8 +381,13 @@ def create_fs_reg_workflow(name='registration'):
354381
register.connect(fssource, 'T1', convert, 'in_file')
355382

356383
# Coregister the median to the surface
384+
<<<<<<< HEAD
357385
bbregister = Node(freesurfer.BBRegister(registered_file=True),
358386
name='bbregister')
387+
=======
388+
bbregister = Node(freesurfer.BBRegister(),
389+
name='bbregister')
390+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
359391
bbregister.inputs.init = 'fsl'
360392
bbregister.inputs.contrast_type = 't2'
361393
bbregister.inputs.out_fsl_file = True
@@ -375,7 +407,7 @@ def create_fs_reg_workflow(name='registration'):
375407
binarize = Node(fs.Binarize(min=0.5, out_type="nii.gz", dilate=1), name="binarize_aparc")
376408
register.connect(fssource, ("aparc_aseg", get_aparc_aseg), binarize, "in_file")
377409

378-
stripper = Node(fsl.ApplyMask(), name ='stripper')
410+
stripper = Node(fsl.ApplyMask(), name='stripper')
379411
register.connect(binarize, "binary_file", stripper, "mask_file")
380412
register.connect(convert, 'out_file', stripper, 'in_file')
381413

@@ -400,16 +432,17 @@ def create_fs_reg_workflow(name='registration'):
400432
convert2itk.inputs.fsl2ras = True
401433
convert2itk.inputs.itk_transform = True
402434
register.connect(bbregister, 'out_fsl_file', convert2itk, 'transform_file')
403-
register.connect(inputnode, 'mean_image',convert2itk, 'source_file')
435+
register.connect(inputnode, 'mean_image', convert2itk, 'source_file')
404436
register.connect(stripper, 'out_file', convert2itk, 'reference_file')
405437

406438
"""
407439
Compute registration between the subject's structural and MNI template
408-
This is currently set to perform a very quick registration. However, the
409-
registration can be made significantly more accurate for cortical
410-
structures by increasing the number of iterations
411-
All parameters are set using the example from:
412-
#https://github.com/stnava/ANTs/blob/master/Scripts/newAntsExample.sh
440+
441+
* All parameters are set using the example from: \
442+
`newAntsExample.sh <https://github.com/stnava/ANTs/blob/master/Scripts/newAntsExample.sh>`_
443+
* This is currently set to perform a very quick registration. However,\
444+
the registration can be made significantly more accurate for cortical\
445+
structures by increasing the number of iterations.
413446
"""
414447

415448
reg = Node(ants.Registration(), name='antsRegister')
@@ -441,7 +474,11 @@ def create_fs_reg_workflow(name='registration'):
441474
reg.plugin_args = {'qsub_args': '-pe orte 4',
442475
'sbatch_args': '--mem=6G -c 4'}
443476
register.connect(stripper, 'out_file', reg, 'moving_image')
477+
<<<<<<< HEAD
444478
register.connect(inputnode,'target_image', reg,'fixed_image')
479+
=======
480+
register.connect(inputnode, 'target_image', reg, 'fixed_image')
481+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
445482

446483
"""
447484
Concatenate the affine and ants transforms into a list
@@ -451,7 +488,11 @@ def create_fs_reg_workflow(name='registration'):
451488

452489
merge = Node(Merge(2), iterfield=['in2'], name='mergexfm')
453490
register.connect(convert2itk, 'itk_transform', merge, 'in2')
491+
<<<<<<< HEAD
454492
register.connect(reg, 'composite_transform', merge, 'in1')
493+
=======
494+
register.connect(reg, ('composite_transform', pickfirst), merge, 'in1')
495+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
455496

456497
"""
457498
Transform the mean image. First to anatomical and then to target
@@ -463,8 +504,6 @@ def create_fs_reg_workflow(name='registration'):
463504
warpmean.inputs.invert_transform_flags = [False, False]
464505
warpmean.inputs.terminal_output = 'file'
465506
warpmean.inputs.args = '--float'
466-
#warpmean.inputs.num_threads = 4
467-
#warpmean.plugin_args = {'sbatch_args': '--mem=4G -c 4'}
468507

469508
"""
470509
Transform the remaining images. First to anatomical and then to target
@@ -488,11 +527,11 @@ def create_fs_reg_workflow(name='registration'):
488527
register.connect(warpmean, 'output_image', outputnode, 'transformed_mean')
489528
register.connect(warpall, 'output_image', outputnode, 'transformed_files')
490529

491-
register.connect(inputnode,'target_image', warpmean,'reference_image')
530+
register.connect(inputnode, 'target_image', warpmean, 'reference_image')
492531
register.connect(inputnode, 'mean_image', warpmean, 'input_image')
493532
register.connect(merge, 'out', warpmean, 'transforms')
494-
register.connect(inputnode,'target_image', warpall,'reference_image')
495-
register.connect(inputnode,'source_files', warpall, 'input_image')
533+
register.connect(inputnode, 'target_image', warpall, 'reference_image')
534+
register.connect(inputnode, 'source_files', warpall, 'input_image')
496535
register.connect(merge, 'out', warpall, 'transforms')
497536

498537
"""
@@ -545,6 +584,7 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
545584
TR : float
546585
Repetition time
547586
"""
587+
548588
from glob import glob
549589
import os
550590
import numpy as np
@@ -574,17 +614,17 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
574614
runs = [int(val[-3:]) for val in files]
575615
run_ids.insert(idx, runs)
576616
json_info = os.path.join(base_dir, subject_id, 'BOLD',
577-
'task%03d_run%03d' % (task_id, run_ids[task_id - 1][0]),
578-
'bold_scaninfo.json')
617+
'task%03d_run%03d' % (task_id, run_ids[task_id - 1][0]),
618+
'bold_scaninfo.json')
579619
if os.path.exists(json_info):
580620
import json
581621
with open(json_info, 'rt') as fp:
582622
data = json.load(fp)
583623
TR = data['global']['const']['RepetitionTime']/1000.
584624
else:
585625
task_scan_key = os.path.join(base_dir, subject_id, 'BOLD',
586-
'task%03d_run%03d' % (task_id, run_ids[task_id - 1][0]),
587-
'scan_key.txt')
626+
'task%03d_run%03d' % (task_id, run_ids[task_id - 1][0]),
627+
'scan_key.txt')
588628
if os.path.exists(task_scan_key):
589629
TR = np.genfromtxt(task_scan_key)[1]
590630
else:
@@ -1087,7 +1127,7 @@ def get_subs(subject_id, conds, run_id, model_id, task_id):
10871127
help="FreeSurfer subjects directory (if available)")
10881128
parser.add_argument("--target", dest="target_file",
10891129
help=("Target in MNI space. Best to use the MindBoggle "
1090-
"template - only used with FreeSurfer"
1130+
"template - only used with FreeSurfer "
10911131
"OASIS-30_Atropos_template_in_MNI152_2mm.nii.gz"))
10921132
args = parser.parse_args()
10931133
outdir = args.outdir

examples/rsfmri_vol_surface_preprocessing_nipy.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,11 @@ def create_reg_workflow(name='registration'):
528528

529529
merge = Node(Merge(2), iterfield=['in2'], name='mergexfm')
530530
register.connect(convert2itk, 'itk_transform', merge, 'in2')
531+
<<<<<<< HEAD
531532
register.connect(reg, 'composite_transform', merge, 'in1')
533+
=======
534+
register.connect(reg, ('composite_transform', pickfirst), merge, 'in1')
535+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
532536

533537
"""
534538
Transform the mean image. First to anatomical and then to target
@@ -619,15 +623,20 @@ def create_workflow(files,
619623
name='median')
620624
wf.connect(tsnr, 'detrended_file', calc_median, 'in_files')
621625

622-
"""Segment and Register
623626
"""
627+
<<<<<<< HEAD
628+
=======
629+
Segment and Register
630+
"""
631+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
624632

625633
registration = create_reg_workflow(name='registration')
626634
wf.connect(calc_median, 'median_file', registration, 'inputspec.mean_image')
627635
registration.inputs.inputspec.subject_id = subject_id
628636
registration.inputs.inputspec.subjects_dir = subjects_dir
629637
registration.inputs.inputspec.target_image = target_file
630638

639+
<<<<<<< HEAD
631640
"""Quantify TSNR in each freesurfer ROI
632641
"""
633642

@@ -637,6 +646,8 @@ def create_workflow(files,
637646
wf.connect(tsnr, 'tsnr_file', get_roi_tsnr, 'in_file')
638647
wf.connect(registration, 'outputspec.aparc', get_roi_tsnr, 'segmentation_file')
639648

649+
=======
650+
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693
640651
"""Use :class:`nipype.algorithms.rapidart` to determine which of the
641652
images in the functional series are outliers based on deviations in
642653
intensity or movement.

0 commit comments

Comments
 (0)