本文整理汇总了Python中nipype.pipeline.engine.Workflow.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Workflow.connect方法的具体用法?Python Workflow.connect怎么用?Python Workflow.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nipype.pipeline.engine.Workflow
的用法示例。
在下文中一共展示了Workflow.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_ants_registration_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_ants_registration_pipeline(name='ants_registration'):
# set fsl output type
fsl.FSLCommand.set_default_output_type('NIFTI_GZ')
# initiate workflow
ants_registration = Workflow(name='ants_registration')
# inputnode
inputnode=Node(util.IdentityInterface(fields=['denoised_ts',
'ants_affine',
'ants_warp',
'ref'
]),
name='inputnode')
# outputnode
outputnode=Node(util.IdentityInterface(fields=['ants_reg_ts',
]),
name='outputnode')
#also transform to mni space
collect_transforms = Node(interface = util.Merge(2),name='collect_transforms')
ants_reg = Node(ants.ApplyTransforms(input_image_type = 3, dimension = 3, interpolation = 'Linear'), name='ants_reg')
ants_registration.connect([
(inputnode, ants_reg, [('denoised_ts', 'input_image')]),
(inputnode, ants_reg, [('ref', 'reference_image')]),
(inputnode, collect_transforms, [('ants_affine', 'in1')]),
(inputnode, collect_transforms, [('ants_warp', 'in2')]),
(collect_transforms, ants_reg, [('out', 'transforms')]),
(ants_reg, outputnode, [('output_image', 'ants_reg_ts')])
])
return ants_registration
示例2: create_normalize_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_normalize_pipeline(name='normalize'):
# workflow
normalize = Workflow(name='normalize')
# Define nodes
inputnode = Node(interface=util.IdentityInterface(fields=['epi_coreg',
'tr']),
name='inputnode')
outputnode = Node(interface=util.IdentityInterface(fields=[
'normalized_file']),
name='outputnode')
# time-normalize scans
normalize_time = Node(util.Function(input_names=['in_file', 'tr'],
output_names=['out_file'],
function=time_normalizer),
name='normalize_time')
normalize_time.plugin_args = {'submit_specs': 'request_memory = 17000'}
normalize.connect([(inputnode, normalize_time, [('tr', 'tr')]),
(inputnode, normalize_time, [('epi_coreg', 'in_file')]),
(normalize_time, outputnode, [('out_file', 'normalized_file')])
])
# time-normalize scans
return normalize
示例3: create_smoothing_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_smoothing_pipeline(name='smoothing'):
# set fsl output type
fsl.FSLCommand.set_default_output_type('NIFTI')
# initiate workflow
smoothing = Workflow(name='smoothing')
# inputnode
inputnode=Node(util.IdentityInterface(fields=['ts_transformed',
'fwhm'
]),
name='inputnode')
# outputnode
outputnode=Node(util.IdentityInterface(fields=['ts_smoothed'
]),
name='outputnode')
#apply smoothing
smooth = Node(fsl.Smooth(),name = 'smooth')
smoothing.connect([
(inputnode, smooth, [
('ts_transformed', 'in_file'),
('fwhm', 'fwhm')]
),
(smooth, outputnode, [('smoothed_file', 'ts_smoothed')]
)
])
return smoothing
示例4: gICA_AROMA
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def gICA_AROMA():
flow = Workflow('denoise_ica_aroma')
inputnode = Node(util.IdentityInterface(fields=['fslDir', 'inFile', 'mask', 'dim', 'TR', 'mc', 'denType']),
name = 'inputnode')
outputnode = Node(util.IdentityInterface(fields=['denoised']),
name = 'outputnode')
aroma = Node(util.Function(input_names = ['fslDir', 'inFile', 'mask',
'dim', 'TR', 'mc', 'denType'],
output_names =['denoised'],
function =ica_aroma_denoise),
name ='ICA_AROMA')
flow.connect(inputnode, 'fslDir', aroma, 'fslDir' )
flow.connect(inputnode, 'inFile', aroma, 'inFile' )
flow.connect(inputnode, 'mask', aroma, 'mask' )
flow.connect(inputnode, 'dim', aroma, 'dim' )
flow.connect(inputnode, 'TR', aroma, 'TR' )
flow.connect(inputnode, 'mc', aroma, 'mc' )
flow.connect(inputnode, 'denType', aroma, 'denType' )
flow.connect(aroma, 'denoised', outputnode,'denoised' )
return flow
示例5: create_reconall_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_reconall_pipeline(name='reconall'):
reconall=Workflow(name='reconall')
#inputnode
inputnode=Node(util.IdentityInterface(fields=['anat',
'fs_subjects_dir',
'fs_subject_id'
]),
name='inputnode')
outputnode=Node(util.IdentityInterface(fields=['fs_subjects_dir',
'fs_subject_id']),
name='outputnode')
# run reconall
recon_all = create_skullstripped_recon_flow()
# function to replace / in subject id string with a _
def sub_id(sub_id):
return sub_id.replace('/','_')
reconall.connect([(inputnode, recon_all, [('fs_subjects_dir', 'inputspec.subjects_dir'),
('anat', 'inputspec.T1_files'),
(('fs_subject_id', sub_id), 'inputspec.subject_id')]),
(recon_all, outputnode, [('outputspec.subject_id', 'fs_subject_id'),
('outputspec.subjects_dir', 'fs_subjects_dir')])
])
return reconall
示例6: create_slice_timing_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_slice_timing_pipeline(name='slicetiming'):
# set fsl output type
fsl.FSLCommand.set_default_output_type('NIFTI')
# initiate workflow
slicetiming = Workflow(name='slicetiming')
# inputnode
inputnode = Node(util.IdentityInterface(fields=['ts'
]),
name='inputnode')
# outputnode
outputnode = Node(util.IdentityInterface(fields=['ts_slicetcorrected'
]),
name='outputnode')
# use FSL slicetiming (default ascending bottom to top)
timer = Node(fsl.SliceTimer(), name='timer')
timer.inputs.time_repetition = 2.0
slicetiming.connect([
(inputnode, timer, [
('ts', 'in_file')]
),
(timer, outputnode, [('slice_time_corrected_file', 'ts_slicetcorrected')]
)
])
return slicetiming
示例7: create_visualize_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_visualize_pipeline(name='visualize'):
# initiate workflow
visualize = Workflow(name='visualize')
# inputnode
inputnode=Node(util.IdentityInterface(fields=['ts_transformed',
'mni_template'
]),
name='inputnode')
# outputnode
outputnode=Node(util.IdentityInterface(fields=['output_image'
]),
name='outputnode')
#apply smoothing
slicer = Node(fsl.Slicer(sample_axial=6, image_width=750),name = 'smooth')
visualize.connect([
(inputnode, slicer, [('ts_transformed', 'in_file'),('mni_template', 'image_edges')]),
(slicer, outputnode,[('out_file', 'output_image')])
])
return visualize
示例8: func2mni_wf
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def func2mni_wf():
mni_skull_2mm = '/usr/share/fsl/5.0/data/standard/MNI152_T1_2mm.nii.gz'
mni_brain_2mm = '/usr/share/fsl/5.0/data/standard/MNI152_T1_2mm_brain.nii.gz'
flow = Workflow('func2mni_nonlinear')
inputnode = Node(util.IdentityInterface(fields=['func_image',
'reference_image',
'func2anat_affine',
'anat2mni_warp']),name = 'inputnode')
outputnode = Node(util.IdentityInterface(fields=['func2mni_2mm',
'func2mni_4mm']),name = 'outputnode')
applywarp = Node(fsl.ApplyWarp(), name = 'apply_warp',)
applywarp.inputs.ref_file = mni_brain_2mm
flirt4mm = Node(fsl.FLIRT(), name = 'resample_4mm')
flirt4mm.inputs.reference = mni_brain_2mm
flirt4mm.inputs.apply_isoxfm = 4.0
flow.connect(inputnode, 'func_image' , applywarp, 'in_file')
flow.connect(inputnode, 'anat2mni_warp' , applywarp, 'field_file')
flow.connect(inputnode, 'func2anat_affine' , applywarp, 'premat')
flow.connect(applywarp, 'out_file' , flirt4mm, 'in_file')
flow.connect(applywarp, 'out_file' , outputnode, 'func2mni_2mm')
flow.connect(flirt4mm, 'out_file' , outputnode, 'func2mni_4mm')
return flow
示例9: create_reconall_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_reconall_pipeline(name='reconall'):
reconall = Workflow(name='reconall')
# inputnode
inputnode = Node(util.IdentityInterface(fields=['anat',
'fs_subjects_dir',
'fs_subject_id'
]),
name='inputnode')
outputnode = Node(util.IdentityInterface(fields=['fs_subjects_dir',
'fs_subject_id']),
name='outputnode')
# run reconall
recon_all = Node(fs.ReconAll(args='-autorecon2 -nuiterations 7 -no-isrunning -hippo-subfields'),
name="recon_all")
# recon_all.inputs.directive= 'autorecon2-wm' # -autorecon3
recon_all.plugin_args = {'submit_specs': 'request_memory = 9000'}
# function to replace / in subject id string with a _
def sub_id(sub_id):
return sub_id.replace('/', '_')
reconall.connect([(inputnode, recon_all, [('fs_subjects_dir', 'subjects_dir'),
('anat', 'T1_files'),
(('fs_subject_id', sub_id), 'subject_id')]),
(recon_all, outputnode, [('subject_id', 'fs_subject_id'),
('subjects_dir', 'fs_subjects_dir')])
])
return reconall
示例10: create_dcmconvert_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_dcmconvert_pipeline(name='dcmconvert'):
from nipype.pipeline.engine import Node, Workflow
import nipype.interfaces.utility as util
from nipype.interfaces.dcmstack import DcmStack
# workflow
dcmconvert = Workflow(name='dcmconvert')
#inputnode
inputnode=Node(util.IdentityInterface(fields=['dicoms',
'filename']),
name='inputnode')
# outputnode
outputnode=Node(util.IdentityInterface(fields=['nifti']),
name='outputnode')
# conversion node
converter = Node(DcmStack(embed_meta=True),
name='converter')
# connections
dcmconvert.connect([(inputnode, converter, [('dicoms', 'dicom_files'),
('filename','out_format')]),
(converter, outputnode, [('out_file','nifti')])])
return dcmconvert
示例11: create_mgzconvert_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_mgzconvert_pipeline(name='mgzconvert'):
# workflow
mgzconvert = Workflow(name='mgzconvert')
# inputnode
inputnode = Node(util.IdentityInterface(fields=['fs_subjects_dir', 'fs_subject_id']), name='inputnode')
# outputnode
outputnode = Node(util.IdentityInterface(fields=['anat_head',
'anat_brain',
'anat_brain_mask',
'wmseg',
'wmedge']),
name='outputnode')
# import files from freesurfer
fs_import = Node(interface=nio.FreeSurferSource(),
name='fs_import')
# convert Freesurfer T1 file to nifti
head_convert = Node(fs.MRIConvert(out_type='niigz',
out_file='T1.nii.gz'),
name='head_convert')
# create brainmask from aparc+aseg with single dilation
def get_aparc_aseg(files):
for name in files:
if 'aparc+aseg' in name:
return name
# create brain by converting only freesurfer output
brain_convert = Node(fs.MRIConvert(out_type='niigz',
out_file='brain.nii.gz'),
name='brain_convert')
brain_binarize = Node(fsl.ImageMaths(op_string='-bin -fillh', out_file='T1_brain_mask.nii.gz'), name='brain_binarize')
# cortical and cerebellar white matter volumes to construct wm edge
# [lh cerebral wm, lh cerebellar wm, rh cerebral wm, rh cerebellar wm, brain stem]
wmseg = Node(fs.Binarize(out_type='nii.gz',
match=[2, 7, 41, 46, 16],
binary_file='T1_brain_wmseg.nii.gz'),
name='wmseg')
# make edge from wmseg to visualize coregistration quality
edge = Node(fsl.ApplyMask(args='-edge -bin',
out_file='T1_brain_wmedge.nii.gz'),
name='edge')
# connections
mgzconvert.connect([(inputnode, fs_import, [('fs_subjects_dir', 'subjects_dir'),
('fs_subject_id', 'subject_id')]),
(fs_import, head_convert, [('T1', 'in_file')]),
(fs_import, wmseg, [(('aparc_aseg', get_aparc_aseg), 'in_file')]),
(fs_import, brain_convert, [('brainmask', 'in_file')]),
(wmseg, edge, [('binary_file', 'in_file'),
('binary_file', 'mask_file')]),
(head_convert, outputnode, [('out_file', 'anat_head')]),
(brain_convert, outputnode, [('out_file', 'anat_brain')]),
(brain_convert, brain_binarize, [('out_file', 'in_file')]),
(brain_binarize, outputnode, [('out_file', 'anat_brain_mask')]),
(wmseg, outputnode, [('binary_file', 'wmseg')]),
(edge, outputnode, [('out_file', 'wmedge')])
])
return mgzconvert
示例12: create_normalize_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_normalize_pipeline(name='normalize'):
# workflow
normalize=Workflow(name='normalize')
# inputnode
inputnode=Node(util.IdentityInterface(fields=['anat',
'standard']),
name='inputnode')
# outputnode
outputnode=Node(util.IdentityInterface(fields=['anat2std_transforms',
'anat2std',
'std2anat_transforms',
'std2anat']),
name='outputnode')
# normalization with ants
antsreg= Node(ants.Registration(dimension=3,
transforms=['Rigid','Affine','SyN'],
metric=['MI','MI','CC'],
metric_weight=[1,1,1],
number_of_iterations=[[1000,500,250,100],[1000,500,250,100],[100,70,50,20]],
convergence_threshold=[1e-6,1e-6,1e-6],
convergence_window_size=[10,10,10],
shrink_factors=[[8,4,2,1],[8,4,2,1],[8,4,2,1]],
smoothing_sigmas=[[3,2,1,0],[3,2,1,0],[3,2,1,0]],
sigma_units=['vox','vox','vox'],
initial_moving_transform_com=1,
transform_parameters=[(0.1,),(0.1,),(0.1,3.0,0.0)],
sampling_strategy=['Regular', 'Regular', 'None'],
sampling_percentage=[0.25,0.25,1],
radius_or_number_of_bins=[32,32,4],
num_threads=1,
interpolation='Linear',
winsorize_lower_quantile=0.005,
winsorize_upper_quantile=0.995,
collapse_output_transforms=True,
output_inverse_warped_image=True,
output_warped_image=True,
use_histogram_matching=True,
),
name='antsreg')
# connections
normalize.connect([(inputnode, antsreg, [('anat', 'moving_image'),
('standard', 'fixed_image')]),
(antsreg, outputnode, [('forward_transforms', 'anat2std_transforms'),
('reverse_transforms', 'std2anat_transforms'),
('warped_image', 'anat2std'),
('inverse_warped_image', 'std2anat')])
])
return normalize
示例13: create_mp2rage_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_mp2rage_pipeline(name='mp2rage'):
# workflow
mp2rage = Workflow('mp2rage')
# inputnode
inputnode=Node(util.IdentityInterface(fields=['inv2',
'uni',
't1map']),
name='inputnode')
# outputnode
outputnode=Node(util.IdentityInterface(fields=['uni_masked',
'background_mask',
'uni_stripped',
#'skullstrip_mask',
#'uni_reoriented'
]),
name='outputnode')
# remove background noise
background = Node(JistIntensityMp2rageMasking(outMasked=True,
outMasked2=True,
outSignal2=True),
name='background')
# skullstrip
strip = Node(MedicAlgorithmSPECTRE2010(outStripped=True,
outMask=True,
outOriginal=True,
inOutput='true',
inFind='true',
inMMC=4
),
name='strip')
# connections
mp2rage.connect([(inputnode, background, [('inv2', 'inSecond'),
('t1map', 'inQuantitative'),
('uni', 'inT1weighted')]),
(background, strip, [('outMasked2','inInput')]),
(background, outputnode, [('outMasked2','uni_masked'),
('outSignal2','background_mask')]),
(strip, outputnode, [('outStripped','uni_stripped'),
#('outMask', 'skullstrip_mask'),
#('outOriginal','uni_reoriented')
])
])
return mp2rage
示例14: create_converter_structural_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_converter_structural_pipeline(working_dir, ds_dir, name="converter_struct"):
# initiate workflow
converter_wf = Workflow(name=name)
converter_wf.base_dir = os.path.join(working_dir, "LeiCA_resting")
# set fsl output
fsl.FSLCommand.set_default_output_type("NIFTI_GZ")
# inputnode
inputnode = Node(util.IdentityInterface(fields=["t1w_dicom"]), name="inputnode")
outputnode = Node(util.IdentityInterface(fields=["t1w"]), name="outputnode")
niftisink = Node(nio.DataSink(), name="niftisink")
niftisink.inputs.base_directory = os.path.join(ds_dir, "raw_niftis")
# convert to nifti
# todo check if geometry bugs attac. use dcm2nii?
converter_t1w = Node(DcmStack(embed_meta=True), name="converter_t1w")
converter_t1w.plugin_args = {"submit_specs": "request_memory = 2000"}
converter_t1w.inputs.out_format = "t1w"
converter_wf.connect(inputnode, "t1w_dicom", converter_t1w, "dicom_files")
# reorient to standard orientation
reor_2_std = Node(fsl.Reorient2Std(), name="reor_2_std")
converter_wf.connect(converter_t1w, "out_file", reor_2_std, "in_file")
converter_wf.connect(reor_2_std, "out_file", outputnode, "t1w")
# save original niftis
converter_wf.connect(reor_2_std, "out_file", niftisink, "sMRI")
converter_wf.write_graph(dotfilename="converter_struct", graph2use="flat", format="pdf")
return converter_wf
示例15: create_brainextract_pipeline
# 需要导入模块: from nipype.pipeline.engine import Workflow [as 别名]
# 或者: from nipype.pipeline.engine.Workflow import connect [as 别名]
def create_brainextract_pipeline(name='brainextract'):
# workflow
brainextract = Workflow(name='brainextract')
#inputnode
inputnode=Node(util.IdentityInterface(fields=['anat', 'fraction']),
name='inputnode')
#outputnode
outputnode=Node(util.IdentityInterface(fields=['anat_brain', 'anat_brain_mask']),
name='outputnode')
#use bet brain extraction
bet = Node(interface=fsl.BET(mask=True),
name = 'bet')
# connections
brainextract.connect([(inputnode, bet, [('anat','in_file'),
('fraction', 'frac')]),
(bet, outputnode, [('out_file', 'anat_brain')]),
(bet, outputnode, [('mask_file', 'anat_brain_mask')])
])
return brainextract