def test_load_layout(layout_synthetic_nodb, db_dir): db_path = str(db_dir / 'tmp_db') layout_synthetic_nodb.save(db_path) reloaded = BIDSLayout.load(db_path) assert sorted(layout_synthetic_nodb.get(return_type='file')) == \ sorted(reloaded.get(return_type='file')) assert layout_synthetic_nodb._init_args == reloaded._init_args
def test_load_layout(layout_synthetic_nodb, db_dir): db_path = str(db_dir / 'tmp_db') layout_synthetic_nodb.save(db_path) reloaded = BIDSLayout.load(db_path) assert sorted(layout_synthetic_nodb.get(return_type='file')) == \ sorted(reloaded.get(return_type='file')) cm1 = layout_synthetic_nodb.connection_manager cm2 = reloaded.connection_manager for attr in ['root', 'absolute_paths', 'config', 'derivatives']: assert getattr(cm1.layout_info, attr) == getattr(cm2.layout_info, attr)
def _run_interface(self, runtime): from bids.layout import BIDSLayout from bids.modeling import BIDSStatsModelsGraph layout = BIDSLayout.load(database_path=self.inputs.database_path) selectors = self.inputs.selectors graph = BIDSStatsModelsGraph(layout, self.inputs.model) graph.load_collections(**selectors) self._results['all_specs'] = self._load_graph(runtime, graph) return runtime
def _run_interface(self, runtime): from bids.analysis import Analysis from bids.layout import BIDSLayout layout = BIDSLayout.load(database_path=self.inputs.database_path) selectors = self.inputs.selectors analysis = Analysis(model=self.inputs.model, layout=layout) analysis.setup(drop_na=False, **selectors) self._load_level1(runtime, analysis) self._load_higher_level(runtime, analysis) return runtime
def _run_interface(self, runtime): from bids.layout import BIDSLayout layout = BIDSLayout.load(database_path=self.inputs.database_path) bold_files = [] mask_files = [] entities = [] for ents in self.inputs.entities: selectors = {'desc': 'preproc', **ents, **self.inputs.selectors} bold_file = layout.get(**selectors) if len(bold_file) == 0: raise FileNotFoundError( "Could not find BOLD file in {} with entities {}" "".format(layout.root, selectors) ) elif len(bold_file) > 1: raise ValueError( "Non-unique BOLD file in {} with entities {}.\n" "Matches:\n\t{}" "".format( layout.root, selectors, "\n\t".join( '{} ({})'.format(f.path, layout.files[f.path].entities) for f in bold_file ), ) ) # Select exactly matching mask file (may be over-cautious) bold_ents = layout.parse_file_entities(bold_file[0].path) bold_ents['suffix'] = 'mask' bold_ents['desc'] = 'brain' bold_ents['extension'] = ['.nii', '.nii.gz'] mask_file = layout.get(**bold_ents) bold_ents.pop('suffix') bold_ents.pop('desc') bold_files.append(bold_file[0].path) mask_files.append(mask_file[0].path if mask_file else None) entities.append(bold_ents) self._results['bold_files'] = bold_files self._results['mask_files'] = mask_files self._results['entities'] = entities return runtime