def run_command(self, args): """Run the pipeline with defined args.""" from networkx import Graph from clinica.pipelines.pet_volume.pet_volume_pipeline import PETVolume from clinica.utils.ux import print_end_pipeline, print_crash_files_and_exit parameters = { 'group_label': args.group_label, 'acq_label': args.acq_label, 'suvr_reference_region': args.suvr_reference_region, 'pvc_psf_tsv': self.absolute_path(args.pvc_psf_tsv), 'mask_tissues': args.mask_tissues, 'mask_threshold': args.mask_threshold, 'pvc_mask_tissues': args.pvc_mask_tissues, 'smooth': args.smooth, } pipeline = PETVolume( bids_directory=self.absolute_path(args.bids_directory), caps_directory=self.absolute_path(args.caps_directory), tsv_file=self.absolute_path(args.subjects_sessions_tsv), base_dir=self.absolute_path(args.working_directory), parameters=parameters, name=self.name) if args.n_procs: exec_pipeline = pipeline.run(plugin='MultiProc', plugin_args={'n_procs': args.n_procs}) else: exec_pipeline = pipeline.run() if isinstance(exec_pipeline, Graph): print_end_pipeline(self.name, pipeline.base_dir, pipeline.base_dir_was_specified) else: print_crash_files_and_exit(args.logname, pipeline.base_dir)
def test_run_PETVolume(cmdopt): from os.path import dirname, join, abspath import shutil from clinica.pipelines.pet_volume.pet_volume_pipeline import PETVolume working_dir = cmdopt root = dirname(abspath(join(abspath(__file__), pardir))) root = join(root, 'data', 'PETVolume') clean_folder(join(root, 'out', 'caps'), recreate=False) clean_folder(join(working_dir, 'PETVolume')) shutil.copytree(join(root, 'in', 'caps'), join(root, 'out', 'caps')) parameters = { 'group_label': 'UnitTest', 'acq_label': 'fdg', 'suvr_reference_region': 'pons' } pipeline = PETVolume(bids_directory=join(root, 'in', 'bids'), caps_directory=join(root, 'out', 'caps'), tsv_file=join(root, 'in', 'subjects.tsv'), base_dir=join(working_dir, 'PETVolume'), parameters=parameters) pipeline.build() pipeline.run(plugin='MultiProc', plugin_args={'n_procs': 4}, bypass_check=True) subjects = [ 'sub-ADNI011S4105', 'sub-ADNI023S4020', 'sub-ADNI035S4082', 'sub-ADNI128S4832' ] out_files = [ join( root, 'out/caps/subjects/' + sub + '/ses-M00/pet/preprocessing/group-UnitTest', sub + '_ses-M00_task-rest_acq-fdg_pet_space-Ixi549Space_suvr-pons_mask-brain_fwhm-8mm_pet.nii.gz' ) for sub in subjects ] ref_files = [ join( root, 'ref', sub + '_ses-M00_task-rest_acq-fdg_pet_space-Ixi549Space_suvr-pons_mask-brain_fwhm-8mm_pet.nii.gz' ) for sub in subjects ] for i in range(len(out_files)): assert likeliness_measure(out_files[i], ref_files[i], (1e-2, 0.25), (1e-1, 0.001)) clean_folder(join(root, 'out', 'caps'), recreate=False) clean_folder(join(working_dir, 'PETVolume'), recreate=False)
def run_command(self, args): """Run the pipeline with defined args.""" from networkx import Graph from clinica.pipelines.pet_volume.pet_volume_pipeline import PETVolume from clinica.utils.check_dependency import verify_cat12_atlases from clinica.utils.ux import print_end_pipeline, print_crash_files_and_exit parameters = { 'group_id': args.group_id, 'psf_tsv': self.absolute_path(args.psf_tsv), 'pet_tracer': args.pet_tracer, 'mask_tissues': args.mask_tissues, 'mask_threshold': args.mask_threshold, 'pvc_mask_tissues': args.pvc_mask_tissues, 'smooth': args.smooth, 'atlases': args.atlases, } # If the user wants to use any of the atlases of CAT12 and has not installed it, we just remove it from the list # of the computed atlases parameters['atlases'] = verify_cat12_atlases(args.atlases) pipeline = PETVolume( bids_directory=self.absolute_path(args.bids_directory), caps_directory=self.absolute_path(args.caps_directory), tsv_file=self.absolute_path(args.subjects_sessions_tsv), base_dir=self.absolute_path(args.working_directory), parameters=parameters, name=self.name) if args.n_procs: exec_pipeline = pipeline.run(plugin='MultiProc', plugin_args={'n_procs': args.n_procs}) else: exec_pipeline = pipeline.run() if isinstance(exec_pipeline, Graph): print_end_pipeline(self.name, pipeline.base_dir, pipeline.base_dir_was_specified) else: print_crash_files_and_exit(args.logname, pipeline.base_dir)
def run_command(self, args): """ """ from tempfile import mkdtemp from clinica.utils.stream import cprint from clinica.pipelines.pet_volume.pet_volume_pipeline import PETVolume pipeline = PETVolume( bids_directory=self.absolute_path(args.bids_directory), caps_directory=self.absolute_path(args.caps_directory), tsv_file=self.absolute_path(args.subjects_sessions_tsv), group_id=args.group_id, fwhm_tsv=self.absolute_path(args.psf_tsv)) pipeline.parameters.update({ 'pet_type': args.pet_tracer, 'mask_tissues': args.mask_tissues, 'mask_threshold': args.mask_threshold, 'pvc_mask_tissues': args.pvc_mask_tissues, 'smooth': args.smooth, 'atlas_list': args.atlases }) if args.working_directory is None: args.working_directory = mkdtemp() pipeline.base_dir = self.absolute_path(args.working_directory) if args.n_procs: pipeline.run(plugin='MultiProc', plugin_args={'n_procs': args.n_procs}) else: pipeline.run() cprint( "The " + self._name + " pipeline has completed. You can now delete the working directory (" + args.working_directory + ").")
def cli( bids_directory: str, caps_directory: str, group_label: str, acq_label: str, suvr_reference_region: Optional[str] = None, pvc_psf_tsv: Optional[str] = None, mask_tissues: List[int] = (1, 2, 3), mask_threshold: float = 0.3, pvc_mask_tissues: List[int] = (1, 2, 3), smooth: List[int] = (8, 8), subjects_sessions_tsv: Optional[str] = None, working_directory: Optional[str] = None, n_procs: Optional[int] = None, yes: bool = False, ) -> None: """SPM-based pre-processing of PET images. GROUP_LABEL is an user-defined identifier to target a specific group of subjects. For this pipeline, it is associated to the DARTEL template that you had created when running the t1-volume pipeline. ACQ_LABEL corresponds to the label given to the PET acquisition, specifying the tracer used. Frequently used values are 'fdg' or 'av45'. The reference region must be precised to perform intensity normalization. Accepted values include: 'pons', 'cerebellumPons', 'pons2', 'cerebellumPons2'. Prerequisite: You need to have performed the t1-volume pipeline on your T1-weighted MR images. See https://aramislab.paris.inria.fr/clinica/docs/public/latest/Pipelines/PET_Volume/ """ from networkx import Graph from clinica.pipelines.pet_volume.pet_volume_pipeline import PETVolume from clinica.utils.ux import print_end_pipeline parameters = { "group_label": group_label, "acq_label": acq_label, "suvr_reference_region": suvr_reference_region, "pvc_psf_tsv": pvc_psf_tsv, "mask_tissues": mask_tissues, "mask_threshold": mask_threshold, "pvc_mask_tissues": pvc_mask_tissues, "smooth": smooth, "skip_question": yes, } pipeline = PETVolume( bids_directory=bids_directory, caps_directory=caps_directory, tsv_file=subjects_sessions_tsv, base_dir=working_directory, parameters=parameters, name=pipeline_name, ) exec_pipeline = ( pipeline.run(plugin="MultiProc", plugin_args={"n_procs": n_procs}) if n_procs else pipeline.run() ) if isinstance(exec_pipeline, Graph): print_end_pipeline( pipeline_name, pipeline.base_dir, pipeline.base_dir_was_specified )
def test_run_PETVolume(cmdopt): import shutil from os.path import abspath, dirname, join from clinica.pipelines.pet_volume.pet_volume_pipeline import PETVolume working_dir = cmdopt root = dirname(abspath(join(abspath(__file__), pardir, pardir))) root = join(root, "data", "PETVolume") clean_folder(join(root, "out", "caps"), recreate=False) clean_folder(join(working_dir, "PETVolume")) shutil.copytree(join(root, "in", "caps"), join(root, "out", "caps")) parameters = { "group_label": "UnitTest", "acq_label": "fdg", "suvr_reference_region": "pons", } pipeline = PETVolume( bids_directory=join(root, "in", "bids"), caps_directory=join(root, "out", "caps"), tsv_file=join(root, "in", "subjects.tsv"), base_dir=join(working_dir, "PETVolume"), parameters=parameters, ) pipeline.build() pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 4}, bypass_check=True) subjects = [ "sub-ADNI011S4105", "sub-ADNI023S4020", "sub-ADNI035S4082", "sub-ADNI128S4832", ] out_files = [ join( root, "out/caps/subjects/" + sub + "/ses-M00/pet/preprocessing/group-UnitTest", sub + "_ses-M00_task-rest_acq-fdg_pet_space-Ixi549Space_suvr-pons_mask-brain_fwhm-8mm_pet.nii.gz", ) for sub in subjects ] ref_files = [ join( root, "ref", sub + "_ses-M00_task-rest_acq-fdg_pet_space-Ixi549Space_suvr-pons_mask-brain_fwhm-8mm_pet.nii.gz", ) for sub in subjects ] for i in range(len(out_files)): assert likeliness_measure(out_files[i], ref_files[i], (1e-2, 0.25), (1e-1, 0.001)) clean_folder(join(root, "out", "caps"), recreate=False) clean_folder(join(working_dir, "PETVolume"), recreate=False)
def run_PETVolume( input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path ) -> None: import shutil from clinica.pipelines.pet_volume.pet_volume_pipeline import PETVolume # Arrange shutil.copytree(input_dir / "caps", output_dir / "caps", copy_function=shutil.copy) parameters = { "group_label": "UnitTest", "acq_label": "fdg", "suvr_reference_region": "pons", "skip_question": False, } pipeline = PETVolume( bids_directory=fspath(input_dir / "bids"), caps_directory=fspath(output_dir / "caps"), tsv_file=fspath(input_dir / "subjects.tsv"), base_dir=fspath(working_dir), parameters=parameters, ) # Acte pipeline.build() pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 4}, bypass_check=True) # Assert subjects = [ "sub-ADNI011S4105", "sub-ADNI023S4020", "sub-ADNI035S4082", "sub-ADNI128S4832", ] out_files = [ fspath( output_dir / "caps" / "subjects" / sub / "ses-M00/pet/preprocessing/group-UnitTest" / ( sub + "_ses-M00_task-rest_acq-fdg_pet_space-Ixi549Space_suvr-pons_mask-brain_fwhm-8mm_pet.nii.gz" ) ) for sub in subjects ] ref_files = [ fspath( ref_dir / ( sub + "_ses-M00_task-rest_acq-fdg_pet_space-Ixi549Space_suvr-pons_mask-brain_fwhm-8mm_pet.nii.gz" ) ) for sub in subjects ] for i in range(len(out_files)): assert likeliness_measure( out_files[i], ref_files[i], (1e-2, 0.25), (1e-1, 0.001) )