def _run_interface(self, runtime): if isdefined(self.inputs.spec): spec = self.inputs.spec else: spec = pkgr.resource_filename('fmriprep', 'data/bids.json') bids_dict = collect_bids_data(self.inputs.bids_root, self.inputs.subject_id, spec=spec) self._results['out_dict'] = bids_dict self._results['t1w'] = bids_dict['t1w'] if not bids_dict['t1w']: raise FileNotFoundError( 'No T1w images found for subject sub-{}, bids_root={}'.format( self.inputs.subject_id, self.inputs.bids_root)) self._results['func'] = bids_dict['func'] if not bids_dict['func']: raise FileNotFoundError( 'No functional images found for subject sub-{}, bids_root={}'. format(self.inputs.subject_id, self.inputs.bids_root)) for imtype in ['fmap', 'sbref']: self._results[imtype] = bids_dict[imtype] if not bids_dict[imtype]: LOGGER.warn( 'No \'{}\' images found for sub-{} in BIDS dataset ({})'. format(imtype, self.inputs.subject_id, self.inputs.bids_root)) return runtime
def setUp(self): try: all_subjects = misc.collect_bids_data(c.DATASET) self.imaging_data = { self.subject_id: all_subjects[self.subject_id] } except Exception as e: url = "http://googledrive.com/host/0BxI12kyv2olZbl9GN3BIOVVoelE" raise_from(Exception("Couldn't find data at " + c.DATASET + ". Download from " + url), e)
def setUp(cls): if not os.path.exists(cls.fake_data_root_location): print("Downloading test data") url = "http://github.com/chrisfilo/BIDS-examples-1/archive/enh/ds054.zip" with urlopen(url) as zipresp: with ZipFile(BytesIO(zipresp.read())) as zfile: zfile.extractall(cls.fake_data_root_location) cls.imaging_data = { cls.subject_id: misc.collect_bids_data(os.path.join(cls.fake_ds_location), cls.subject_id) }
def base_workflow_generator(subject_id, task_id, settings): subject_data = collect_bids_data(settings['bids_root'], subject_id, task_id) settings["biggest_epi_file_size_gb"] = get_biggest_epi_file_size_gb(subject_data['func']) if subject_data['t1w'] == []: raise Exception("No T1w images found for participant %s. All workflows require T1w images."%subject_id) if (subject_data['sbref'] != [] and settings['workflow_type'] == "auto") or settings['workflow_type'] == "ds054": return wf_ds054_type(subject_data, settings, name=subject_id) elif (subject_data['sbref'] == [] and settings['workflow_type'] == "auto") or settings['workflow_type'] == "ds005": return wf_ds005_type(subject_data, settings, name=subject_id) else: raise Exception("Could not figure out what kind of workflow to run for this dataset.")
def init_single_subject_wf(subject_id, task_id, name, ignore, debug, anat_only, omp_nthreads, skull_strip_ants, reportlets_dir, output_dir, bids_dir, freesurfer, output_spaces, template, hires, bold2t1w_dof, fmap_bspline, fmap_demean, use_syn, force_syn, output_grid_ref, use_aroma, ignore_aroma_err): """ The adaptable fMRI preprocessing workflow """ if name == 'single_subject_wf': # for documentation purposes subject_data = { 'func': ['/completely/made/up/path/sub-01_task-nback_bold.nii.gz'] } layout = None else: layout = BIDSLayout(bids_dir) subject_data = collect_bids_data(bids_dir, subject_id, task_id) if not anat_only and subject_data['func'] == []: raise Exception( "No BOLD images found for participant {} and task {}. " "All workflows require BOLD images.".format( subject_id, task_id if task_id else '<all>')) if subject_data['t1w'] == []: raise Exception( "No T1w images found for participant {}. " "All workflows require T1w images.".format(subject_id)) workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['subjects_dir']), name='inputnode') bidssrc = pe.Node(BIDSDataGrabber(subject_data=subject_data, anat_only=anat_only), name='bidssrc') # Preprocessing of T1w (includes registration to MNI) anat_preproc_wf = init_anat_preproc_wf(name="anat_preproc_wf", skull_strip_ants=skull_strip_ants, output_spaces=output_spaces, template=template, debug=debug, omp_nthreads=omp_nthreads, freesurfer=freesurfer, hires=hires, reportlets_dir=reportlets_dir, output_dir=output_dir) workflow.connect([ (inputnode, anat_preproc_wf, [('subjects_dir', 'inputnode.subjects_dir')]), (bidssrc, anat_preproc_wf, [('t1w', 'inputnode.t1w'), ('t2w', 'inputnode.t2w')]), ]) if anat_only: return workflow for bold_file in subject_data['func']: func_preproc_wf = init_func_preproc_wf( bold_file=bold_file, layout=layout, ignore=ignore, freesurfer=freesurfer, bold2t1w_dof=bold2t1w_dof, reportlets_dir=reportlets_dir, output_spaces=output_spaces, template=template, output_dir=output_dir, omp_nthreads=omp_nthreads, fmap_bspline=fmap_bspline, fmap_demean=fmap_demean, use_syn=use_syn, force_syn=force_syn, debug=debug, output_grid_ref=output_grid_ref, use_aroma=use_aroma, ignore_aroma_err=ignore_aroma_err) workflow.connect([(anat_preproc_wf, func_preproc_wf, [('outputnode.t1_preproc', 'inputnode.t1_preproc'), ('outputnode.t1_brain', 'inputnode.t1_brain'), ('outputnode.t1_mask', 'inputnode.t1_mask'), ('outputnode.t1_seg', 'inputnode.t1_seg'), ('outputnode.t1_tpms', 'inputnode.t1_tpms'), ('outputnode.t1_2_mni_forward_transform', 'inputnode.t1_2_mni_forward_transform'), ('outputnode.t1_2_mni_reverse_transform', 'inputnode.t1_2_mni_reverse_transform')])]) if freesurfer: workflow.connect([ (anat_preproc_wf, func_preproc_wf, [('outputnode.subjects_dir', 'inputnode.subjects_dir'), ('outputnode.subject_id', 'inputnode.subject_id'), ('outputnode.fs_2_t1_transform', 'inputnode.fs_2_t1_transform')]), ]) return workflow
def init_single_subject_wf(subject_id, task_id, name, ignore, debug, anat_only, omp_nthreads, skull_strip_ants, reportlets_dir, output_dir, bids_dir, freesurfer, output_spaces, template, hires, bold2t1w_dof, fmap_bspline, fmap_demean, use_syn, force_syn, output_grid_ref, use_aroma, ignore_aroma_err): """ The adaptable fMRI preprocessing workflow """ if name == 'single_subject_wf': # for documentation purposes subject_data = {'func': ['/completely/made/up/path/sub-01_task-nback_bold.nii.gz']} layout = None else: layout = BIDSLayout(bids_dir) subject_data = collect_bids_data(bids_dir, subject_id, task_id) if not anat_only and subject_data['func'] == []: raise Exception("No BOLD images found for participant {} and task {}. " "All workflows require BOLD images.".format( subject_id, task_id if task_id else '<all>')) if not subject_data['t1w']: raise Exception("No T1w images found for participant {}. " "All workflows require T1w images.".format(subject_id)) workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['subjects_dir']), name='inputnode') bidssrc = pe.Node(BIDSDataGrabber(subject_data=subject_data, anat_only=anat_only), name='bidssrc') # Preprocessing of T1w (includes registration to MNI) anat_preproc_wf = init_anat_preproc_wf(name="anat_preproc_wf", skull_strip_ants=skull_strip_ants, output_spaces=output_spaces, template=template, debug=debug, omp_nthreads=omp_nthreads, freesurfer=freesurfer, hires=hires, reportlets_dir=reportlets_dir, output_dir=output_dir) workflow.connect([ (inputnode, anat_preproc_wf, [('subjects_dir', 'inputnode.subjects_dir')]), (bidssrc, anat_preproc_wf, [('t1w', 'inputnode.t1w'), ('t2w', 'inputnode.t2w')]), ]) if anat_only: return workflow for bold_file in subject_data['func']: func_preproc_wf = init_func_preproc_wf(bold_file=bold_file, layout=layout, ignore=ignore, freesurfer=freesurfer, bold2t1w_dof=bold2t1w_dof, reportlets_dir=reportlets_dir, output_spaces=output_spaces, template=template, output_dir=output_dir, omp_nthreads=omp_nthreads, fmap_bspline=fmap_bspline, fmap_demean=fmap_demean, use_syn=use_syn, force_syn=force_syn, debug=debug, output_grid_ref=output_grid_ref, use_aroma=use_aroma, ignore_aroma_err=ignore_aroma_err) workflow.connect([ (anat_preproc_wf, func_preproc_wf, [('outputnode.t1_preproc', 'inputnode.t1_preproc'), ('outputnode.t1_brain', 'inputnode.t1_brain'), ('outputnode.t1_mask', 'inputnode.t1_mask'), ('outputnode.t1_seg', 'inputnode.t1_seg'), ('outputnode.t1_tpms', 'inputnode.t1_tpms'), ('outputnode.t1_2_mni_forward_transform', 'inputnode.t1_2_mni_forward_transform'), ('outputnode.t1_2_mni_reverse_transform', 'inputnode.t1_2_mni_reverse_transform')]) ]) if freesurfer: workflow.connect([ (anat_preproc_wf, func_preproc_wf, [('outputnode.subjects_dir', 'inputnode.subjects_dir'), ('outputnode.subject_id', 'inputnode.subject_id'), ('outputnode.fs_2_t1_transform', 'inputnode.fs_2_t1_transform')]), ]) return workflow