|
53 | 53 | import nibabel as nb
|
54 | 54 | import os, os.path as op # system functions
|
55 | 55 | import cmp # connectome mapper
|
56 |
| - |
57 |
| -""" |
58 |
| -We import several voxel, data, and affine grabbing functions from the Camino workflows, as well as |
59 |
| -some functions to select the correct files (in our case, aparc+aseg.mgz) from the list outputted by the FreeSurferSource interfaces. |
60 |
| -""" |
61 |
| - |
62 |
| -from nipype.workflows.camino.connectivity_mapping import (get_vox_dims, get_data_dims, |
63 |
| - get_affine, select_aparc, select_aparc_annot, get_first_image) |
| 56 | +from nipype.workflows.camino.connectivity_mapping import select_aparc_annot, get_first_image |
| 57 | +from nipype.workflows.mrtrix.diffusion import get_vox_dims_as_tuple |
64 | 58 |
|
65 | 59 | """
|
66 | 60 | This needs to point to the freesurfer subjects directory (Recon-all must have been run on subj1 from the FSL course data)
|
|
177 | 171 |
|
178 | 172 | fsl2mrtrix = pe.Node(interface=mrtrix.FSL2MRTrix(),name='fsl2mrtrix')
|
179 | 173 |
|
| 174 | +""" |
| 175 | +Distortions induced by eddy currents are corrected prior to fitting the tensors. |
| 176 | +The first image is used as a reference for which to warp the others. |
| 177 | +""" |
| 178 | + |
| 179 | +eddycorrect = pe.Node(interface=fsl.EddyCorrect(),name='eddycorrect') |
| 180 | +eddycorrect.inputs.ref_num = 1 |
| 181 | + |
180 | 182 | """
|
181 | 183 | Tensors are fitted to each voxel in the diffusion-weighted image and from these three maps are created:
|
182 | 184 | * Major eigenvector in each voxel
|
|
252 | 254 | tracks2prob = pe.Node(interface=mrtrix.Tracks2Prob(),name='tracks2prob')
|
253 | 255 | tracks2prob.inputs.colour = True
|
254 | 256 | tck2trk = pe.Node(interface=mrtrix.MRTrix2TrackVis(),name='tck2trk')
|
| 257 | +tck2trk.inputs.flipy = True |
| 258 | +tck2trk.inputs.flipz = True |
255 | 259 |
|
256 | 260 | """
|
257 | 261 | Structural segmentation nodes
|
|
283 | 287 | inverse.inputs.interp = ('nearestneighbour')
|
284 | 288 | inverse.inputs.apply_xfm = True
|
285 | 289 | inverse_AparcAseg = inverse.clone('inverse_AparcAseg')
|
| 290 | +inverseROIsToB0 = inverse.clone('inverseROIsToB0') |
286 | 291 |
|
287 | 292 | """
|
288 | 293 | Parcellation is performed given the aparc+aseg image from Freesurfer.
|
|
403 | 408 |
|
404 | 409 | mapping.connect([(inputnode, fsl2mrtrix, [("bvecs", "bvec_file"),
|
405 | 410 | ("bvals", "bval_file")])])
|
406 |
| -mapping.connect([(inputnode, dwi2tensor,[("dwi","in_file")])]) |
| 411 | +mapping.connect([(inputnode, eddycorrect,[("dwi","in_file")])]) |
| 412 | +mapping.connect([(eddycorrect, dwi2tensor,[("eddy_corrected","in_file")])]) |
407 | 413 | mapping.connect([(fsl2mrtrix, dwi2tensor,[("encoding_file","encoding_file")])])
|
408 | 414 |
|
409 | 415 | mapping.connect([(dwi2tensor, tensor2vector,[['tensor','in_file']]),
|
|
417 | 423 | fractional anisotropy image, and thresholds it to get the single-fiber voxels.
|
418 | 424 | """
|
419 | 425 |
|
420 |
| -mapping.connect([(inputnode, MRconvert,[("dwi","in_file")])]) |
| 426 | +mapping.connect([(eddycorrect, MRconvert,[("eddy_corrected","in_file")])]) |
421 | 427 | mapping.connect([(MRconvert, threshold_b0,[("converted","in_file")])])
|
422 | 428 | mapping.connect([(threshold_b0, median3d,[("out_file","in_file")])])
|
423 | 429 | mapping.connect([(median3d, erode_mask_firstpass,[("out_file","in_file")])])
|
|
430 | 436 | Here the thresholded white matter mask is created for seeding the tractography.
|
431 | 437 | """
|
432 | 438 |
|
433 |
| -mapping.connect([(inputnode, bet,[("dwi","in_file")])]) |
434 |
| -mapping.connect([(inputnode, gen_WM_mask,[("dwi","in_file")])]) |
| 439 | +mapping.connect([(eddycorrect, bet,[("eddy_corrected","in_file")])]) |
| 440 | +mapping.connect([(eddycorrect, gen_WM_mask,[("eddy_corrected","in_file")])]) |
435 | 441 | mapping.connect([(bet, gen_WM_mask,[("mask_file","binary_mask")])])
|
436 | 442 | mapping.connect([(fsl2mrtrix, gen_WM_mask,[("encoding_file","encoding_file")])])
|
437 | 443 | mapping.connect([(gen_WM_mask, threshold_wmmask,[("WMprobabilitymap","in_file")])])
|
|
440 | 446 | Next we estimate the fiber response distribution.
|
441 | 447 | """
|
442 | 448 |
|
443 |
| -mapping.connect([(inputnode, estimateresponse,[("dwi","in_file")])]) |
| 449 | +mapping.connect([(eddycorrect, estimateresponse,[("eddy_corrected","in_file")])]) |
444 | 450 | mapping.connect([(fsl2mrtrix, estimateresponse,[("encoding_file","encoding_file")])])
|
445 | 451 | mapping.connect([(threshold_FA, estimateresponse,[("out_file","mask_image")])])
|
446 | 452 |
|
447 | 453 | """
|
448 | 454 | Run constrained spherical deconvolution.
|
449 | 455 | """
|
450 | 456 |
|
451 |
| -mapping.connect([(inputnode, csdeconv,[("dwi","in_file")])]) |
| 457 | +mapping.connect([(eddycorrect, csdeconv,[("eddy_corrected","in_file")])]) |
452 | 458 | mapping.connect([(gen_WM_mask, csdeconv,[("WMprobabilitymap","mask_image")])])
|
453 | 459 | mapping.connect([(estimateresponse, csdeconv,[("response","response_file")])])
|
454 | 460 | mapping.connect([(fsl2mrtrix, csdeconv,[("encoding_file","encoding_file")])])
|
|
460 | 466 | mapping.connect([(threshold_wmmask, probCSDstreamtrack,[("out_file","seed_file")])])
|
461 | 467 | mapping.connect([(csdeconv, probCSDstreamtrack,[("spherical_harmonics_image","in_file")])])
|
462 | 468 | mapping.connect([(probCSDstreamtrack, tracks2prob,[("tracked","in_file")])])
|
463 |
| -mapping.connect([(inputnode, tracks2prob,[("dwi","template_file")])]) |
| 469 | +mapping.connect([(eddycorrect, tracks2prob,[("eddy_corrected","template_file")])]) |
464 | 470 |
|
465 | 471 | """
|
466 | 472 | Structural Processing
|
467 | 473 | ---------------------
|
468 | 474 | First, we coregister the structural image to the diffusion image and then obtain the inverse of transformation.
|
469 | 475 | """
|
470 | 476 |
|
471 |
| -mapping.connect([(inputnode, coregister,[('dwi','in_file')])]) |
| 477 | +mapping.connect([(eddycorrect, coregister,[("eddy_corrected","in_file")])]) |
472 | 478 | mapping.connect([(mri_convert_Brain, coregister,[('out_file','reference')])])
|
473 | 479 | mapping.connect([(coregister, convertxfm,[('out_matrix_file','in_file')])])
|
474 |
| -mapping.connect([(inputnode, inverse,[('dwi','reference')])]) |
| 480 | +mapping.connect([(eddycorrect, inverse,[("eddy_corrected","reference")])]) |
475 | 481 | mapping.connect([(convertxfm, inverse,[('out_file','in_matrix_file')])])
|
476 | 482 | mapping.connect([(mri_convert_Brain, inverse,[('out_file','in_file')])])
|
477 | 483 |
|
478 | 484 | """
|
479 | 485 | The b0 image is upsampled to the same dimensions as the parcellated structural image to improve their coregistration.
|
480 | 486 | """
|
481 | 487 |
|
482 |
| -mapping.connect([(inputnode, resampleb0,[(('dwi', get_first_image), 'in_file')])]) |
| 488 | +mapping.connect([(eddycorrect, resampleb0,[(('eddy_corrected', get_first_image), 'in_file')])]) |
483 | 489 | mapping.connect([(resampleb0, inverse_AparcAseg,[('out_file','reference')])])
|
484 | 490 | mapping.connect([(convertxfm, inverse_AparcAseg,[('out_file','in_matrix_file')])])
|
| 491 | +mapping.connect([(eddycorrect, inverseROIsToB0,[(('eddy_corrected', get_first_image), 'reference')])]) |
| 492 | +mapping.connect([(convertxfm, inverseROIsToB0,[('out_file','in_matrix_file')])]) |
485 | 493 |
|
486 | 494 | """
|
487 | 495 | The parcellation is connected for transformation into diffusion space.
|
488 | 496 | """
|
489 | 497 |
|
490 | 498 | mapping.connect([(inputnode, parcellate,[("subject_id","subject_id")])])
|
491 | 499 | mapping.connect([(parcellate, inverse_AparcAseg,[('roi_file','in_file')])])
|
| 500 | +mapping.connect([(parcellate, inverseROIsToB0,[('roi_file','in_file')])]) |
492 | 501 |
|
493 | 502 | """
|
494 | 503 | The MRtrix-tracked fibers are converted to TrackVis format (with voxel and data dimensions grabbed from the DWI).
|
495 | 504 | The connectivity matrix is created with the .trk fibers and the coregistered parcellation file.
|
496 | 505 | """
|
497 | 506 |
|
498 |
| -mapping.connect([(inputnode, tck2trk,[("dwi","image_file")])]) |
| 507 | +mapping.connect([(eddycorrect, tck2trk,[("eddy_corrected","image_file")])]) |
499 | 508 | mapping.connect([(probCSDstreamtrack, tck2trk,[("tracked","in_file")])])
|
500 | 509 | mapping.connect([(tck2trk, creatematrix,[("out_file","tract_file")])])
|
501 | 510 | mapping.connect([(inputnode, creatematrix,[("subject_id","out_matrix_file")])])
|
|
519 | 528 | mapping.connect([(mris_convertLHlabels, giftiLabels,[("converted","in1")])])
|
520 | 529 | mapping.connect([(mris_convertRHlabels, giftiLabels,[("converted","in2")])])
|
521 | 530 |
|
522 |
| -mapping.connect([(inputnode, niftiVolumes,[("dwi","in2")])]) |
| 531 | +mapping.connect([(eddycorrect, niftiVolumes,[("eddy_corrected","in2")])]) |
| 532 | + |
523 | 533 | mapping.connect([(mri_convert_Brain, niftiVolumes,[("out_file","in3")])])
|
524 | 534 | mapping.connect([(inverse_AparcAseg, niftiVolumes,[("out_file","in1")])])
|
525 | 535 |
|
|
0 commit comments