def atlas_statistics(file_list, atlas_list): """ For each atlas name provided it Ć’calculates for the input image the mean for each region in the atlas and saves it to a TSV file. :param in_image: A Nifti image :param in_atlas_list: List of names of atlas to be applied :return: List of paths to tsv files """ from os import getcwd from os.path import abspath, join from nipype.utils.filemanip import split_filename from clinica.utils.atlas import AtlasAbstract from clinica.utils.statistics import statistics_on_atlas from clinica.utils.stream import cprint orig_dir, base, ext = split_filename(file_list) atlas_classes = AtlasAbstract.__subclasses__() atlas_statistics_list = [] for atlas in atlas_list: for atlas_class in atlas_classes: if atlas_class.get_name_atlas() == atlas: #out_atlas_statistics = abspath(join(getcwd(), base + '_space-' + atlas + '_map-graymatter_statistics.tsv')) out_atlas_statistics = abspath( join('./' + base + '_space-' + atlas + '_map-graymatter_statistics.tsv')) cprint(out_atlas_statistics) statistics_on_atlas(file_list, atlas_class(), out_atlas_statistics) atlas_statistics_list.append(out_atlas_statistics) break return atlas_statistics_list
def atlas_statistics(in_image, atlas_list): """ For each atlas name provided it calculates for the input image the mean for each region in the atlas and saves it to a TSV file. Args: in_image: A Nifti image atlas_list: List of names of atlas to be applied Returns: List of paths to TSV files """ from os.path import abspath, join from nipype.utils.filemanip import split_filename from clinica.utils.atlas import AtlasAbstract from clinica.utils.statistics import statistics_on_atlas from clinica.utils.filemanip import get_subject_id from clinica.utils.ux import print_end_image subject_id = get_subject_id(in_image) orig_dir, base, ext = split_filename(in_image) atlas_classes = AtlasAbstract.__subclasses__() atlas_statistics_list = [] for atlas in atlas_list: for atlas_class in atlas_classes: if atlas_class.get_name_atlas() == atlas: out_atlas_statistics = abspath( join('./' + base + '_space-' + atlas + '_map-graymatter_statistics.tsv')) statistics_on_atlas(in_image, atlas_class(), out_atlas_statistics) atlas_statistics_list.append(out_atlas_statistics) print_end_image(subject_id) return atlas_statistics_list
def statistics_on_atlases(in_registered_map, name_map, prefix_file=None): """Computes a list of statistics files for each atlas. Args: in_registered_map (str): Map already registered on atlases. name_map (str): Name of the registered map in CAPS format. prefix_file (Opt[str]): <prefix_file>_space-<atlas_name>_map-<name_map>_statistics.tsv Returns: List of paths leading to the statistics TSV files. """ import os from nipype.utils.filemanip import split_filename from clinica.utils.atlas import ( AtlasAbstract, JHUDTI811mm, JHUTracts01mm, JHUTracts251mm, ) from clinica.utils.statistics import statistics_on_atlas in_atlas_list = [JHUDTI811mm(), JHUTracts01mm(), JHUTracts251mm()] atlas_statistics_list = [] for atlas in in_atlas_list: if not isinstance(atlas, AtlasAbstract): raise TypeError("Atlas element must be an AtlasAbstract type") if prefix_file is None: _, base, _ = split_filename(in_registered_map) filename = ( f"{base}_space-{atlas.get_name_atlas()}" f"_res-{atlas.get_spatial_resolution()}_map-{name_map}_statistics.tsv" ) else: filename = ( f"{prefix_file}_space-{atlas.get_name_atlas()}" f"_res-{atlas.get_spatial_resolution()}_map-{name_map}_statistics.tsv" ) out_atlas_statistics = os.path.abspath( os.path.join(os.getcwd(), filename)) statistics_on_atlas(in_registered_map, atlas, out_atlas_statistics) atlas_statistics_list.append(out_atlas_statistics) return atlas_statistics_list
def statistics_on_atlases(in_registered_map, name_map, prefix_file=None): """ Computes a list of statistics files for each atlas. Args: in_registered_map (str): Map already registered on atlases. name_map (str): Name of the registered map in CAPS format. prefix_file (Opt[str]): <prefix_file>_space-<atlas_name>_map-<name_map>_statistics.tsv Returns: List of paths leading to the statistics TSV files. """ from os import getcwd from os.path import abspath, join from nipype.utils.filemanip import split_filename from clinica.utils.atlas import (AtlasAbstract, JHUDTI811mm, JHUTracts01mm, JHUTracts251mm, JHUTracts501mm) from clinica.utils.statistics import statistics_on_atlas # atlas_classes = AtlasAbstract.__subclasses__() in_atlas_list = [JHUDTI811mm(), JHUTracts01mm(), JHUTracts251mm()] atlas_statistics_list = [] for atlas in in_atlas_list: if not isinstance(atlas, AtlasAbstract): raise TypeError("Atlas element must be an AtlasAbstract type") if prefix_file is None: _, base, _ = split_filename(in_registered_map) out_atlas_statistics = abspath( join(getcwd(), '%s_space-%s_res-%s_map-%s_statistics.tsv' % (base, atlas.get_name_atlas(), atlas.get_spatial_resolution(), name_map))) else: out_atlas_statistics = abspath( join(getcwd(), '%s_space-%s_res-%s_map-%s_statistics.tsv' % (prefix_file, atlas.get_name_atlas(), atlas.get_spatial_resolution(), name_map))) statistics_on_atlas(in_registered_map, atlas, out_atlas_statistics) atlas_statistics_list.append(out_atlas_statistics) return atlas_statistics_list
def atlas_statistics(in_image, in_atlas_list): """Generate regional measure from atlas_list in TSV files. For each atlas name provided it calculates for the input image the mean for each region in the atlas and saves it to a TSV file. Args: in_image: A Nifti image in_atlas_list: List of names of atlas to be applied Returns: List of paths to TSV files """ from os import getcwd from os.path import abspath, join from nipype.utils.filemanip import split_filename from clinica.utils.atlas import AtlasAbstract from clinica.utils.statistics import statistics_on_atlas orig_dir, base, ext = split_filename(in_image) atlas_classes = AtlasAbstract.__subclasses__() atlas_statistics_list = [] for atlas in in_atlas_list: for atlas_class in atlas_classes: if atlas_class.get_name_atlas() == atlas: out_atlas_statistics = abspath( join(getcwd(), base + "_space-" + atlas + "_statistics.tsv")) statistics_on_atlas(in_image, atlas_class(), out_atlas_statistics) atlas_statistics_list.append(out_atlas_statistics) break return atlas_statistics_list