def run_createmergefile( input_dir: PathLike, output_dir: PathLike, ref_dir: PathLike ) -> None: import shutil from filecmp import cmp from os import remove from os.path import abspath, dirname, join import pandas as pd from clinica.iotools.utils import data_handling as dt # Arrange out_tsv = output_dir / "output_file.tsv" subject_session_tsv = input_dir / "subjects_sessions.tsv" caps_directory = output_dir / "caps" shutil.copytree(input_dir / "caps", caps_directory, copy_function=shutil.copy) # Act dt.create_merge_file( input_dir / "bids", out_tsv, caps_dir=caps_directory, tsv_file=subject_session_tsv, pipelines=None, atlas_selection=None, pvc_restriction=None, group_selection=None, ) # Assert ref_tsv = fspath(ref_dir / "output_file.tsv") out_df = pd.read_csv(out_tsv, sep="/") ref_df = pd.read_csv(ref_tsv, sep="/") assert out_df.equals(ref_df) assert cmp(out_tsv, ref_tsv)
def merge_tsv( bids_directory: str, output_tsv: str, caps_directory: Optional[str] = None, pipelines: Optional[List[str]] = None, volume_atlas_selection: Optional[List[str]] = None, freesurfer_atlas_selection: Optional[List[str]] = None, pvc_restriction: Optional[int] = None, pet_tracers_selection: Optional[List[str]] = None, group_selection: Optional[List[str]] = None, subjects_sessions_tsv: Optional[str] = None, ignore_scan_files: bool = False, ignore_session_scan_files: bool = False, ) -> None: """Merge clinical data into a single TSV file.""" from clinica.iotools.utils.data_handling import create_merge_file from clinica.utils.inputs import check_bids_folder check_bids_folder(bids_directory) create_merge_file( bids_directory, output_tsv, caps_dir=caps_directory, pipelines=pipelines, ignore_scan_files=ignore_scan_files, ignore_sessions_files=ignore_session_scan_files, volume_atlas_selection=volume_atlas_selection, freesurfer_atlas_selection=freesurfer_atlas_selection, pvc_restriction=pvc_restriction, tsv_file=subjects_sessions_tsv, group_selection=group_selection, tracers_selection=pet_tracers_selection, )
def test_run_CreateMergeFile(cmdopt): from os.path import join, dirname, abspath from os import remove from filecmp import cmp import shutil from clinica.iotools.utils import data_handling as dt root = join(dirname(abspath(__file__)), pardir, 'data', 'CreateMergeFile') bids_directory = join(root, 'in', 'bids') out_tsv = join(root, 'out', 'output_file.tsv') subject_session_tsv = join(root, 'in', 'subjects_sessions.tsv') clean_folder(join(root, 'out', 'caps'), recreate=False) shutil.copytree(join(root, 'in', 'caps'), join(root, 'out', 'caps')) caps_directory = join(root, 'out', 'caps') dt.create_merge_file(bids_directory, out_tsv, caps_dir=caps_directory, pipelines=None, atlas_selection=None, pvc_restriction=None, tsv_file=subject_session_tsv, group_selection=None) # Comparison step ref_tsv = join(root, 'ref', 'output_file.tsv') assert cmp(out_tsv, ref_tsv) remove(out_tsv)
def test_run_CreateMergeFile(cmdopt): import shutil from filecmp import cmp from os import remove from os.path import abspath, dirname, join from clinica.iotools.utils import data_handling as dt root = join(dirname(abspath(__file__)), pardir, pardir, "data", "CreateMergeFile") bids_directory = join(root, "in", "bids") out_tsv = join(root, "out", "output_file.tsv") subject_session_tsv = join(root, "in", "subjects_sessions.tsv") clean_folder(join(root, "out", "caps"), recreate=False) shutil.copytree(join(root, "in", "caps"), join(root, "out", "caps")) caps_directory = join(root, "out", "caps") dt.create_merge_file( bids_directory, out_tsv, caps_dir=caps_directory, tsv_file=subject_session_tsv, pipelines=None, atlas_selection=None, pvc_restriction=None, group_selection=None, ) # Comparison step ref_tsv = join(root, "ref", "output_file.tsv") assert cmp(out_tsv, ref_tsv) remove(out_tsv) clean_folder(join(root, "out", "caps"), recreate=False)
def run_command(self, args): from clinica.iotools.utils import data_handling as dt from clinica.utils.inputs import check_bids_folder check_bids_folder(args.bids_directory) dt.create_merge_file(args.bids_directory, args.out_tsv, caps_dir=args.caps_directory, pipelines=args.pipelines, atlas_selection=args.atlas_selection, pvc_restriction=args.pvc_restriction, tsv_file=args.subjects_sessions_tsv, group_selection=args.group_selection)
def run_command(self, args): from clinica.iotools.utils import data_handling as dt from clinica.utils.inputs import check_bids_folder check_bids_folder(args.bids_directory) dt.create_merge_file( args.bids_directory, args.out_tsv, caps_dir=args.caps_directory, pipelines=args.pipelines, ignore_scan_files=args.ignore_scan_files, ignore_sessions_files=args.ignore_session_scan_files, volume_atlas_selection=args.volume_atlas_selection, freesurfer_atlas_selection=args.freesurfer_atlas_selection, pvc_restriction=args.pvc_restriction, tsv_file=args.subjects_sessions_tsv, group_selection=args.group_selection, tracers_selection=args.pet_tracers_selection, )
def run_command(self, args): from clinica.iotools.utils import data_handling as dt dt.create_merge_file(args.bids_directory, args.out_directory, args.true_false_mode)