|
| 1 | +import nipype.pipeline.engine as pe |
| 2 | +import nipype.interfaces.freesurfer as fs |
| 3 | +import nipype.interfaces.utility as niu |
| 4 | + |
| 5 | +def create_skullstripped_recon_flow(name="skullstripped_recon_all"): |
| 6 | + """Performs recon-all on voulmes that are already skull stripped. |
| 7 | + FreeSurfer failes to perform skullstrippig on some volumes (especially |
| 8 | + MP2RAGE). This can be avoided by doing skullstripping before runnig recon-all |
| 9 | + (using for example SPECTRE algorithm) |
| 10 | +
|
| 11 | + Example |
| 12 | + ------- |
| 13 | + >>> from nipype.workflows.smri.freesurfer import create_skullstripped_recon_flow |
| 14 | + >>> recon_flow = create_skullstripped_recon_flow() |
| 15 | + >>> recon_flow.inputs.inputspec.subject_id = 'subj1' |
| 16 | + >>> recon_flow.inputs.inputspec.T1_files = 'T1.nii.gz' |
| 17 | + >>> recon_flow.run() # doctest: +SKIP |
| 18 | +
|
| 19 | +
|
| 20 | + Inputs:: |
| 21 | + inputspec.T1_files : skullstripped T1_files (mandatory) |
| 22 | + inputspec.subject_id : freesurfer subject id (optional) |
| 23 | + inputspec.subjects_dir : freesurfer subjects directory (optional) |
| 24 | +
|
| 25 | + Outputs:: |
| 26 | +
|
| 27 | + outputspec.subject_id : freesurfer subject id |
| 28 | + outputspec.subjects_dir : freesurfer subjects directory |
| 29 | + """ |
| 30 | + wf = pe.Workflow(name=name) |
| 31 | + |
| 32 | + inputnode = pe.Node(niu.IdentityInterface(fields=['subject_id', |
| 33 | + 'subjects_dir', |
| 34 | + 'T1_files']), |
| 35 | + name='inputspec') |
| 36 | + |
| 37 | + autorecon1 = pe.Node(fs.ReconAll(), name="autorecon1") |
| 38 | + autorecon1.plugin_args={'submit_specs': 'request_memory = 2500'} |
| 39 | + autorecon1.inputs.directive = "autorecon1" |
| 40 | + autorecon1.inputs.args = "-noskullstrip" |
| 41 | + autorecon1._interface._can_resume = False |
| 42 | + |
| 43 | + wf.connect(inputnode, "T1_files", autorecon1, "T1_files") |
| 44 | + wf.connect(inputnode, "subjects_dir", autorecon1, "subjects_dir") |
| 45 | + wf.connect(inputnode, "subject_id", autorecon1, "subject_id") |
| 46 | + |
| 47 | + |
| 48 | + def link_masks(subjects_dir, subject_id): |
| 49 | + import os |
| 50 | + os.symlink(os.path.join(subjects_dir, subject_id, "mri", "T1.mgz"), |
| 51 | + os.path.join(subjects_dir, subject_id, "mri", "brainmask.auto.mgz")) |
| 52 | + os.symlink(os.path.join(subjects_dir, subject_id, "mri", "brainmask.auto.mgz"), |
| 53 | + os.path.join(subjects_dir, subject_id, "mri", "brainmask.mgz")) |
| 54 | + return subjects_dir, subject_id |
| 55 | + |
| 56 | + masks = pe.Node(niu.Function(input_names=['subjects_dir', 'subject_id'], |
| 57 | + output_names=['subjects_dir', 'subject_id'], |
| 58 | + function=link_masks), name="link_masks") |
| 59 | + |
| 60 | + wf.connect(autorecon1, "subjects_dir", masks, "subjects_dir") |
| 61 | + wf.connect(autorecon1, "subject_id", masks, "subject_id") |
| 62 | + |
| 63 | + |
| 64 | + autorecon_resume = pe.Node(fs.ReconAll(), name="autorecon_resume") |
| 65 | + autorecon_resume.plugin_args={'submit_specs': 'request_memory = 2500'} |
| 66 | + autorecon_resume.inputs.args = "-no-isrunning" |
| 67 | + wf.connect(masks, "subjects_dir", autorecon_resume, "subjects_dir") |
| 68 | + wf.connect(masks, "subject_id", autorecon_resume, "subject_id") |
| 69 | + |
| 70 | + outputnode = pe.Node(niu.IdentityInterface(fields=['subject_id', |
| 71 | + 'subjects_dir']), |
| 72 | + name='outputspec') |
| 73 | + |
| 74 | + wf.connect(autorecon_resume, "subjects_dir", outputnode, "subjects_dir") |
| 75 | + wf.connect(autorecon_resume, "subject_id", outputnode, "subject_id") |
| 76 | + return wf |
0 commit comments