def write_tsv_files(subjects_dir, subject_id): """ Generate statistics TSV files in `subjects_dir`/regional_measures folder for `subject_id`. Notes: We do not need to check the line "finished without error" in scripts/recon-all.log. If an error occurs, it will be detected by Nipype and the next nodes (i.e. write_tsv_files will not be called). """ import os import datetime from colorama import Fore from clinica.utils.stream import cprint from clinica.utils.freesurfer import generate_regional_measures, extract_image_id_from_longitudinal_segmentation image_id = extract_image_id_from_longitudinal_segmentation(subject_id) str_image_id = image_id.participant_id + '_' + image_id.session_id + '_' + image_id.long_id if os.path.isfile( os.path.join(subjects_dir, subject_id, 'mri', 'aparc+aseg.mgz')): generate_regional_measures(subjects_dir, subject_id) else: now = datetime.datetime.now().strftime('%H:%M:%S') cprint( '%s[%s] %s does not contain mri/aseg+aparc.mgz file. ' 'Creation of regional_measures/ folder will be skipped.%s' % (Fore.YELLOW, now, str_image_id.replace('_', ' | '), Fore.RESET)) return subject_id
def write_tsv_files(subjects_dir, image_id): """ Generate statistics TSV files in `subjects_dir`/regional_measures folder for `image_id`. Notes: We do not need to check the line "finished without error" in scripts/recon-all.log. If an error occurs, it will be detected by Nipype and the next nodes (including write_tsv_files will not be called). """ import os from clinica.utils.freesurfer import generate_regional_measures from clinica.utils.stream import cprint if os.path.isfile( os.path.join(subjects_dir, image_id, "mri", "aparc+aseg.mgz")): generate_regional_measures(subjects_dir, image_id) else: cprint( msg= (f"{image_id.replace('_', ' | ')} does not contain " f"mri/aseg+aparc.mgz file. Creation of regional_measures/ folder will be skipped." ), lvl="warning", ) return image_id
def write_tsv_files(subjects_dir, subject_id): """Generate statistics TSV files in `subjects_dir`/regional_measures folder for `subject_id`. Notes: We do not need to check the line "finished without error" in scripts/recon-all.log. If an error occurs, it will be detected by Nipype and the next nodes (i.e. write_tsv_files will not be called). """ import os from clinica.utils.freesurfer import ( extract_image_id_from_longitudinal_segmentation, generate_regional_measures, ) from clinica.utils.stream import cprint image_id = extract_image_id_from_longitudinal_segmentation(subject_id) str_image_id = (image_id.participant_id + "_" + image_id.session_id + "_" + image_id.long_id) if os.path.isfile( os.path.join(subjects_dir, subject_id, "mri", "aparc+aseg.mgz")): generate_regional_measures(subjects_dir, subject_id) else: cprint( msg= (f"{str_image_id.replace('_', ' | ')} does not contain mri/aseg+aparc.mgz file. " "Creation of regional_measures/ folder will be skipped."), lvl="warning", ) return subject_id
def write_tsv_files(subjects_dir, image_id): """ Generate statistics TSV files in `subjects_dir`/regional_measures folder for `image_id`. Notes: We do not need to check the line "finished without error" in scripts/recon-all.log. If an error occurs, it will be detected by Nipype and the next nodes (including write_tsv_files will not be called). """ import datetime import os from colorama import Fore from clinica.utils.freesurfer import generate_regional_measures from clinica.utils.stream import cprint if os.path.isfile( os.path.join(subjects_dir, image_id, "mri", "aparc+aseg.mgz")): generate_regional_measures(subjects_dir, image_id) else: now = datetime.datetime.now().strftime("%H:%M:%S") cprint( f"{Fore.YELLOW}[{now}] {image_id.replace('_', ' | ')} does not contain " f"mri/aseg+aparc.mgz file. Creation of regional_measures/ folder will be skipped.{Fore.RESET}" ) return image_id
def write_tsv_files(subject_id, output_dir): """ Generate statistics TSV files for a given subject. """ import os from clinica.utils.freesurfer import generate_regional_measures participant_id = subject_id.split('_')[0] session_id = subject_id.split('_')[1] path_segmentation = os.path.join(os.path.expanduser(output_dir), 'subjects', participant_id, session_id, 't1', 'freesurfer_cross_sectional') generate_regional_measures(path_segmentation, subject_id)
def write_stats_files(in_subject, in_session, in_symlink_path, in_longitudinal_result): """Generate statistics TSV files for a given {subject,session}. Statistics are derived from recon-all's own .stats files and are meant to provide a summary of those. Args: in_subject (string): participant_id in_session (string): session_id in_symlink_path (string): paths to subject-specific folder containing all session symlinks for subject_id associated to in_reconalllong_flags. Used for 1) retrieving the path to recon-all generated .tsv files 2) write stats files in a subfolder of the folder containing the symlink to {subject,session} in_longitudinal_result (Boolean): Used to force longitudinal recon-all to be run before generating the .tsv files from the longitudinal processing Returns: out_stats_path (string): path to the folder containing all the .tsv stats files for {subject,session} """ import os from clinica.utils.freesurfer import generate_regional_measures # get path to longitudinal folder in working dir (where recon-all # results are stored, including .stats files) seg_path = os.path.expanduser(in_symlink_path) # define output dir for the .tsv files subses_long_id = '{0}_{1}.long.{0}'.format(in_subject, in_session) subses_long_stats_subdir = "{0}_stats".format(subses_long_id) out_stats_path = os.path.join(seg_path, subses_long_stats_subdir) # generate the .tsv files from .stats files subses_id = '{0}_{1}'.format(in_subject, in_session) generate_regional_measures(seg_path, subses_id, output_dir=out_stats_path, longitudinal=True) return out_stats_path