Skip to content

Commit 10b3cc4

Browse files
committed
Merge pull request #1 from nicholsn/docs/rsfmri-example
fix: documentation indentation and highlighting
2 parents 54fefed + 8b89b73 commit 10b3cc4

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

examples/rsfmri_vol_surface_preprocessing_nipy.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
4141
specifically the 2mm versions of:
4242
43-
- `Joint Fusion Atlas <http://mindboggle.info/data/atlases/jointfusion/OASIS-TRT-20_jointfusion_DKT31_CMA_labels_in_MNI152_2mm_v2.nii.gz>`_
44-
- `MNI template <http://mindboggle.info/data/templates/ants/OASIS-30_Atropos_template_in_MNI152_2mm.nii.gz>`_
43+
* `Joint Fusion Atlas <http://mindboggle.info/data/atlases/jointfusion/OASIS-TRT-20_jointfusion_DKT31_CMA_labels_in_MNI152_2mm_v2.nii.gz>`_
44+
* `MNI template <http://mindboggle.info/data/templates/ants/OASIS-30_Atropos_template_in_MNI152_2mm.nii.gz>`_
4545
46+
Import necessary modules from nipype.
4647
"""
4748

4849
import os
@@ -71,6 +72,10 @@
7172
import scipy as sp
7273
import nibabel as nb
7374

75+
"""
76+
A list of modules and functions to import inside of nodes
77+
"""
78+
7479
imports = ['import os',
7580
'import nibabel as nb',
7681
'import numpy as np',
@@ -79,6 +84,10 @@
7984
'from scipy.special import legendre'
8085
]
8186

87+
"""
88+
Define utility functions for use in workflow nodes
89+
"""
90+
8291

8392
def get_info(dicom_files):
8493
"""Given a Siemens dicom file return metadata
@@ -341,25 +350,26 @@ def combine_hemi(left, right):
341350
fmt=','.join(['%d'] + ['%.10f'] * (all_data.shape[1] - 1)))
342351
return os.path.abspath(filename)
343352

353+
"""
354+
Create a Registration Workflow
355+
"""
356+
344357

345358
def create_reg_workflow(name='registration'):
346359
"""Create a FEAT preprocessing workflow together with freesurfer
347360
348361
Parameters
349362
----------
350-
351-
::
352-
353363
name : name of workflow (default: 'registration')
354364
355-
Inputs::
365+
Inputs:
356366
357367
inputspec.source_files : files (filename or list of filenames to register)
358368
inputspec.mean_image : reference image to use
359369
inputspec.anatomical_image : anatomical image to coregister to
360370
inputspec.target_image : registration target
361371
362-
Outputs::
372+
Outputs:
363373
364374
outputspec.func2anat_transform : FLIRT transform
365375
outputspec.anat2target_transform : FLIRT+FNIRT transform
@@ -368,7 +378,7 @@ def create_reg_workflow(name='registration'):
368378
369379
Example
370380
-------
371-
381+
See code below
372382
"""
373383

374384
register = Workflow(name=name)
@@ -438,6 +448,7 @@ def create_reg_workflow(name='registration'):
438448
"""
439449
Apply inverse transform to take segmentations to functional space
440450
"""
451+
441452
applyxfm = MapNode(freesurfer.ApplyVolTransform(inverse=True,
442453
interp='nearest'),
443454
iterfield=['target_file'],
@@ -450,6 +461,7 @@ def create_reg_workflow(name='registration'):
450461
"""
451462
Apply inverse transform to aparc file
452463
"""
464+
453465
aparcxfm = Node(freesurfer.ApplyVolTransform(inverse=True,
454466
interp='nearest'),
455467
name='aparc_inverse_transform')
@@ -467,16 +479,17 @@ def create_reg_workflow(name='registration'):
467479
convert2itk.inputs.fsl2ras = True
468480
convert2itk.inputs.itk_transform = True
469481
register.connect(bbregister, 'out_fsl_file', convert2itk, 'transform_file')
470-
register.connect(inputnode, 'mean_image',convert2itk, 'source_file')
482+
register.connect(inputnode, 'mean_image', convert2itk, 'source_file')
471483
register.connect(stripper, 'out_file', convert2itk, 'reference_file')
472484

473485
"""
474486
Compute registration between the subject's structural and MNI template
475-
This is currently set to perform a very quick registration. However, the
476-
registration can be made significantly more accurate for cortical
477-
structures by increasing the number of iterations
478-
All parameters are set using the example from:
479-
#https://github.com/stnava/ANTs/blob/master/Scripts/newAntsExample.sh
487+
488+
* All parameters are set using the example from: \
489+
`newAntsExample.sh <https://github.com/stnava/ANTs/blob/master/Scripts/newAntsExample.sh>`_
490+
* This is currently set to perform a very quick registration. However,\
491+
the registration can be made significantly more accurate for cortical\
492+
structures by increasing the number of iterations.
480493
"""
481494

482495
reg = Node(ants.Registration(), name='antsRegister')
@@ -509,7 +522,6 @@ def create_reg_workflow(name='registration'):
509522
register.connect(stripper, 'out_file', reg, 'moving_image')
510523
register.connect(inputnode,'target_image', reg,'fixed_image')
511524

512-
513525
"""
514526
Concatenate the affine and ants transforms into a list
515527
"""
@@ -520,10 +532,10 @@ def create_reg_workflow(name='registration'):
520532
register.connect(convert2itk, 'itk_transform', merge, 'in2')
521533
register.connect(reg, ('composite_transform', pickfirst), merge, 'in1')
522534

523-
524535
"""
525536
Transform the mean image. First to anatomical and then to target
526537
"""
538+
527539
warpmean = Node(ants.ApplyTransforms(), name='warpmean')
528540
warpmean.inputs.input_image_type = 3
529541
warpmean.inputs.interpolation = 'BSpline'
@@ -536,7 +548,6 @@ def create_reg_workflow(name='registration'):
536548
register.connect(inputnode, 'mean_image', warpmean, 'input_image')
537549
register.connect(merge, 'out', warpmean, 'transforms')
538550

539-
540551
"""
541552
Assign all the output files
542553
"""
@@ -557,7 +568,6 @@ def create_reg_workflow(name='registration'):
557568

558569
return register
559570

560-
561571
"""
562572
Creates the main preprocessing workflow
563573
"""
@@ -607,15 +617,16 @@ def create_workflow(files,
607617
name='median')
608618
wf.connect(tsnr, 'detrended_file', calc_median, 'in_files')
609619

610-
"""Segment and Register
611620
"""
621+
Segment and Register
622+
"""
623+
612624
registration = create_reg_workflow(name='registration')
613625
wf.connect(calc_median, 'median_file', registration, 'inputspec.mean_image')
614626
registration.inputs.inputspec.subject_id = subject_id
615627
registration.inputs.inputspec.subjects_dir = subjects_dir
616628
registration.inputs.inputspec.target_image = target_file
617629

618-
619630
"""Use :class:`nipype.algorithms.rapidart` to determine which of the
620631
images in the functional series are outliers based on deviations in
621632
intensity or movement.
@@ -629,7 +640,6 @@ def create_workflow(files,
629640
art.inputs.mask_type = 'spm_global'
630641
art.inputs.parameter_source = 'NiPy'
631642

632-
633643
"""Here we are connecting all the nodes together. Notice that we add the merge node only if you choose
634644
to use 4D. Also `get_vox_dims` function is passed along the input volume of normalise to set the optimal
635645
voxel sizes.

0 commit comments

Comments
 (0)