def get_dicom_info(c): """Get the dicom information for each subject """ import nipype.interfaces.utility as util import nipype.interfaces.io as nio import nipype.interfaces.freesurfer as fs import nipype.pipeline.engine as pe subjnode = pe.Node(interface=util.IdentityInterface(fields=['subject_id']), name='subjinfo') if c.test_mode: subjnode.iterables = ('subject_id', [c.subjects[0]]) else: subjnode.iterables = ('subject_id', c.subjects) infonode = pe.Node(interface=fs.ParseDICOMDir(sortbyrun=True, summarize=True), name='dicominfo') datasink = pe.Node(interface=nio.DataSink(parameterization=False), name='datasink') datasink.inputs.base_directory = c.sink_dir infopipe = pe.Workflow(name='extractinfo') infopipe.base_dir = os.path.join(c.working_dir,'workdir') infopipe.connect([(subjnode, datasink,[('subject_id','container')]), (subjnode, infonode,[(('subject_id', get_subjectdcmdir, os.path.join(c.base_dir,c.dicom_dir_template)), 'dicom_dir')]), (infonode, datasink,[('dicom_info_file','@info')]), ]) #infopipe.config = {'execution' : {'stop_on_first_crash' : True}} if c.run_using_plugin: infopipe.run(plugin=c.plugin,plugin_args=c.plugin_args) else: infopipe.run()
def test_parsedicomdir(): input_map = dict( args=dict(argstr='%s', ), dicom_dir=dict( mandatory=True, argstr='--d %s', ), dicom_info_file=dict(argstr='--o %s', ), environ=dict(), sortbyrun=dict(argstr='--sortbyrun', ), subjects_dir=dict(), summarize=dict(argstr='--summarize', ), ) instance = freesurfer.ParseDICOMDir() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(instance.inputs.traits()[key], metakey), value
dicom2nifti.terminal_output = 'file' # store nifti files output dicom2nifti.inputs.output_dir = experiment_dir + data_dir # specify optional inputs #dicom2nifti.inputs.file_mapping = [('nifti', '*.nii'), ('info', 'dicom.txt'), ('dti', '*dti.bv*')] #dicom2nifti.inputs.out_type = 'nii' #dicom2nifti.inputs.subject_dir_template = '%s' #------------------------------------------------------------ # Node ParseDICOMDIR - creates a nicer nifti overview textfile #------------------------------------------------------------ dcminfo = pe.Node(interface = fs.ParseDICOMDir(), name = 'dcminfo') dcminfo.inputs.sortbyrun = True dcminfo.inputs.summarize = True dcminfo.inputs.dicom_info_file = 'nifti_overview.txt' #------------------------------------------------------------ # Initiation of preparation pipeline #------------------------------------------------------------ prepareflow = pe.Workflow(name = 'prepareflow') #Define where the workingdir of the all_consuming_workflow should be stored at prepareflow.base_dir = experiment_dir + 'workingdir_prepareflow' def pathfinder(subjectname, foldername): import os