Ejemplo n.º 1
0
def main(tup, remote_subject_dir, args, flags):
    (subject, mri_subject), inverse_method = tup
    evoked, epochs = None, None
    fname_format, fname_format_cond, conditions = meg.init_main(subject, mri_subject, args)
    meg.init_globals_args(subject, mri_subject, fname_format, fname_format_cond, SUBJECTS_EEG_DIR, SUBJECTS_MRI_DIR,
                     MMVT_DIR, args)
    meg.MEG_DIR = SUBJECTS_EEG_DIR
    meg.FWD = meg.FWD_EEG
    meg.INV = meg.INV_EEG
    stat = meg.STAT_AVG if len(conditions) == 1 else meg.STAT_DIFF

    if utils.should_run(args, 'read_eeg_sensors_layout'):
        flags['read_eeg_sensors_layout'] = read_eeg_sensors_layout(subject, mri_subject, args)

    flags = meg.calc_evoked_wrapper(subject, conditions, args, flags)

    if utils.should_run(args, 'create_eeg_mesh'):
        flags['create_eeg_mesh'] = create_eeg_mesh(mri_subject, args.eeg_electrodes_excluded_from_mesh)

    if utils.should_run(args, 'save_evoked_to_blender'):
        flags['save_evoked_to_blender'] = save_evoked_to_blender(mri_subject, conditions, args, evoked)
    if not op.isfile(meg.COR):
        eeg_cor = op.join(meg.SUBJECT_MEG_FOLDER, '{}-cor-trans.fif'.format(subject))
        if not op.isfile(eeg_cor):
            raise Exception("Can't find head-MRI transformation matrix. Should be in {} or in {}".format(meg.COR, eeg_cor))
        meg.COR = eeg_cor
    flags = meg.calc_fwd_inv_wrapper(subject, mri_subject, conditions, args, flags)
    flags = meg.calc_stc_per_condition_wrapper(subject, conditions, inverse_method, args, flags)
    return flags
Ejemplo n.º 2
0
def main(subject, args):
    utils.make_dir(op.join(BLENDER_ROOT_DIR, subject, 'electrodes'))
    utils.make_dir(op.join(BLENDER_ROOT_DIR, subject, 'coloring'))
    utils.make_dir(op.join(BLENDER_ROOT_DIR, subject))
    args = set_args(args)

    if utils.should_run(args, 'convert_electrodes_file_to_npy'):
        convert_electrodes_coordinates_file_to_npy(
            subject, bipolar=args.bipolar, ras_xls_sheet_name=args.ras_xls_sheet_name)

    if utils.should_run(args, 'sort_electrodes_groups'):
        sort_electrodes_groups(subject, args.bipolar, do_plot=args.do_plot)

    if utils.should_run(args, 'create_electrode_data_file') and not args.task is None:
        create_electrode_data_file(subject, args.task, args.from_t_ind, args.to_t_ind, args.stat, args.conditions,
                                   args.bipolar, args.electrodes_names_field, args.moving_average_window_size,
                                   args.input_matlab_fname, args.input_type, args.field_cond_template)

    if utils.should_run(args, 'create_electrodes_labeling_coloring'):
        create_electrodes_labeling_coloring(subject, args.bipolar, args.atlas)

    if utils.should_run(args, 'transform_electrodes_to_mni'):
        transform_electrodes_to_mni(subject, args)

    if 'show_image' in args.function:
        legend_name = 'electrodes{}_coloring_legend.jpg'.format('_bipolar' if args.bipolar else '')
        utils.show_image(op.join(BLENDER_ROOT_DIR, subject, 'coloring', legend_name))

    if 'create_raw_data_for_blender' in args.function and not args.task is None:
        create_raw_data_for_blender(subject, args.raw_data_fname, args.conditions, do_plot=args.do_plot)
Ejemplo n.º 3
0
def main(subject, mri_subject, inverse_method, args):

    fname_format, fname_format_cond, conditions = meg.get_fname_format_args(
        args)
    meg.init_globals_args(subject, mri_subject, fname_format,
                          fname_format_cond, SUBJECTS_EEG_DIR,
                          SUBJECTS_MRI_DIR, MMVT_DIR, args)
    meg.SUBJECTS_MEG_DIR = SUBJECTS_EEG_DIR
    stat = meg.STAT_AVG if len(conditions) == 1 else meg.STAT_DIFF
    evoked, epochs = None, None
    flags = {}

    if utils.should_run(args, 'read_eeg_sensors_layout'):
        flags['read_eeg_sensors_layout'] = read_eeg_sensors_layout(mri_subject)

    if utils.should_run(args, 'calc_evoked'):
        necessary_files = meg.calc_evoked_necessary_files(args)
        meg.get_meg_files(subject, necessary_files, args, conditions)
        flags['calc_evoked'], evoked, epochs = meg.calc_evoked_args(
            conditions, args)

    if utils.should_run(args, 'save_evoked_to_blender'):
        flags['save_evoked_to_blender'] = save_evoked_to_blender(
            mri_subject, conditions, evoked)

    return flags
Ejemplo n.º 4
0
def main(subject, args):
    os.environ['SUBJECT'] = subject
    volume_name = args.volume_name if args.volume_name != '' else args.volume_name
    fol = op.join(FMRI_DIR, args.task, args.subject[0])
    fmri_contrast_file_template = op.join(fol, 'bold', '{contrast_name}.sm05.{hemi}'.format(
        contrast_name=args.contrast_name, hemi='{hemi}'), '{contrast}', 'sig.{format}')

    # todo: should find automatically the existing_format
    if 'fmri_pipeline' in args.func:
        fmri_pipeline(subject, args.atlas, None, fmri_contrast_file_template, t_val=args.threshold,
                      existing_format=args.existing_format, volume_type=args.volume_type,
                      load_labels_from_annotation=True, surface_name=args.surface_name, n_jobs=args.n_jobs)

    if utils.should_run(args, 'project_volume_to_surface'):
        project_volume_to_surface(subject, fol, args.threshold, volume_name, args.ontrast,
                                  existing_format=args.existing_format)

    if utils.should_run(args, 'find_clusters'):
        find_clusters(subject, args.contrast, args.threshold, args.atlas, volume_name)

    if 'calc_meg_activity' in args.func:
        meg_subject = args.meg_subject
        if meg_subject == '':
            print('You must set MEG subject (--meg_subject) to run calc_meg_activity function!')
        else:
            calc_meg_activity_for_functional_rois(
                subject, meg_subject, args.atlas, args.task, args.contrast_name, args.contrast, args.inverse_method)
    if 'copy_volumes' in args.func:
        copy_volumes(subject, fmri_contrast_file_template)
Ejemplo n.º 5
0
def main(subject, args):
    if utils.should_run(args, 'save_rois_connectivity'):
        save_rois_connectivity(subject, args)

    if utils.should_run(args, 'save_electrodes_coh'):
        # todo: Add the necessary parameters
        save_electrodes_coh(subject, args.conditions, args.mat_fname, args.t_max, args.stat, args.threshold)
Ejemplo n.º 6
0
def main(args):
    # 1) Create links
    if utils.should_run(args, 'create_links'):
        links_created = create_links(args.links, args.gui)
        if not links_created:
            print('Not all the links were created! Make sure all the links are created before running MMVT.')

    # 2) Copy resources files
    if utils.should_run(args, 'copy_resources_files'):
        links_dir = utils.get_links_dir(args.links)
        mmvt_root_dir = utils.get_link_dir(links_dir, 'mmvt')
        resource_file_exist = copy_resources_files(mmvt_root_dir)
        if not resource_file_exist:
            print('Not all the resources files were copied to the MMVT folder.\n'.format(mmvt_root_dir) +
                  'Please copy them manually from the mmvt_code/resources folder')

    # 3) Install the addon in Blender (depends on resources and links)
    if utils.should_run(args, 'install_addon'):
        from src.mmvt_addon.scripts import install_addon
        install_addon.wrap_blender_call()

    # 4) Install dependencies from requirements.txt (created using pipreqs)
    if utils.should_run(args, 'install_reqs'):
        install_reqs()
        print('Finish!')
Ejemplo n.º 7
0
def main(subject, args):
    if utils.should_run(args, 'save_rois_connectivity'):
        save_rois_connectivity(subject, args)

    if utils.should_run(args, 'save_electrodes_coh'):
        # todo: Add the necessary parameters
        save_electrodes_coh(subject, args.conditions, args.mat_fname,
                            args.t_max, args.stat, args.threshold)
Ejemplo n.º 8
0
Archivo: ct.py Proyecto: keshava/mmvt
def main(subject, remote_subject_dir, args, flags):

    if utils.should_run(args, 'convert_ct_to_mgz'):
        flags['convert_ct_to_mgz'] = convert_ct_to_mgz(
            subject, args.ct_raw_input_fol, args.ct_fol, args.ct_org_name,
            args.overwrite, args.print_only, args.ask_before)

    if utils.should_run(args, 'register_to_mr'):
        flags['register_to_mr'] = register_to_mr(
            subject, args.ct_fol, args.ct_org_name, args.nnv_ct_name,
            args.register_ct_name, args.negative_threshold,
            args.register_cost_function, args.overwrite, args.print_only)

    if utils.should_run(args, 'save_subject_ct_trans'):
        flags['save_subject_ct_trans'] = save_subject_ct_trans(
            subject, args.register_ct_name, args.overwrite)

    if utils.should_run(args, 'save_images_data_and_header'):
        flags['save_images_data_and_header'] = save_images_data_and_header(
            subject, args.register_ct_name, 'ct_data', args.no_negatives,
            args.overwrite)

    if 'find_electrodes' in args.function:
        flags['find_electrodes'] = find_electrodes(
            subject, args.n_components, args.n_groups, args.register_ct_name,
            args.brain_mask_fname, args.output_fol, args.clustering_method,
            args.max_iters, args.cylinder_error_radius, args.min_elcs_for_lead,
            args.max_dist_between_electrodes, args.min_cylinders_ang,
            args.ct_thresholds, args.min_joined_items_num,
            args.min_distance_beteen_electrodes, args.overwrite, args.debug)

    if 'isotropization' in args.function:
        flags['isotropization'] = isotropization(
            subject,
            args.ct_org_name,
            args.ct_fol,
            isotropization_type=args.isotropization_type,
            iso_vector_override=None)

    if 'save_electrode_ct_pics' in args.function:
        flags['save_electrode_ct_pics'] = save_electrode_ct_pics(
            subject,
            args.voxel,
            args.elc_name,
            args.pixels_around_voxel,
            args.interactive,
            fig_fname=args.fig_name)

    if 'save_electrodes_group_ct_pics' in args.function:
        flags['save_electrodes_group_ct_pics'] = save_electrodes_group_ct_pics(
            subject, args.voxels, args.group_name, args.electrodes_names,
            args.pixels_around_voxel)

    if utils.should_run(args, 'merge_t1_with_ct'):
        flags['merge_t1_with_ct'] = merge_t1_with_ct(subject,
                                                     args.ct_threshold)

    return flags
Ejemplo n.º 9
0
def main(subject, remote_subject_dir, args, flags):
    if utils.should_run(args, 'save_rois_connectivity'):
        flags['save_rois_connectivity'] = save_rois_connectivity(subject, args)

    if utils.should_run(args, 'save_electrodes_coh'):
        # todo: Add the necessary parameters
        flags['save_electrodes_coh'] = save_electrodes_coh(subject, args)

    return flags
Ejemplo n.º 10
0
def main(tup, remote_subject_dir, args, flags):
    (subject, mri_subject), inverse_method = tup
    evoked, epochs = None, None
    conditions, stat = init(subject, args, mri_subject, remote_subject_dir)

    if utils.should_run(args, 'read_sensors_layout'):
        flags['read_sensors_layout'] = read_sensors_layout_args(
            mri_subject, args)

    flags, evoked, epochs = meg.calc_evokes_wrapper(subject,
                                                    conditions,
                                                    args,
                                                    flags,
                                                    mri_subject=mri_subject)

    flags = meg.calc_fwd_inv_wrapper(subject, args, conditions, flags,
                                     mri_subject)

    flags, stcs_conds, stcs_num = meg.calc_stc_per_condition_wrapper(
        subject, conditions, inverse_method, args, flags)

    flags = meg.calc_labels_avg_per_condition_wrapper(subject, conditions,
                                                      args.atlas,
                                                      inverse_method,
                                                      stcs_conds, args, flags,
                                                      stcs_num, None, epochs)

    if 'calc_stc_zvals' in args.function:
        flags['calc_stc_zvals'] = meg.calc_stc_zvals(
            subject, args.stc_name, args.baseline_stc_name, 'eeg',
            args.use_abs, args.from_index, args.to_index, args.stc_zvals_name,
            False, args.overwrite_stc)

    if utils.should_run(args, 'create_helmet_mesh'):
        flags['create_helmet_mesh'] = create_helmet_mesh(
            mri_subject, args.eeg_electrodes_excluded_from_mesh)

    if utils.should_run(args, 'save_evoked_to_blender'):
        flags['save_evoked_to_blender'] = save_evoked_to_blender(
            mri_subject, conditions, args, evoked)

    if utils.should_run(args, 'calc_minmax'):
        flags['calc_minmax'] = calc_minmax(mri_subject, args)

    if 'plot_evoked' in args.function:
        flags['plot_evoked'], _ = plot_evoked(args.evo_fname, args.evoked_key,
                                              args.pick_meg, args.pick_eeg,
                                              args.pick_eog, args.ssp_proj,
                                              args.spatial_colors,
                                              args.window_title, args.hline,
                                              args.channels_to_exclude)

    if 'snap_sensors_to_outer_skin' in args.function:
        flags['snap_sensors_to_outer_skin'] = snap_sensors_to_outer_skin(
            mri_subject)

    return flags
Ejemplo n.º 11
0
def main(subject, args):
    os.environ['SUBJECT'] = subject
    volume_name = args.volume_name if args.volume_name != '' else args.volume_name
    fol = op.join(FMRI_DIR, args.task, args.subject[0])
    fmri_contrast_file_template = op.join(
        fol, 'bold',
        '{contrast_name}.sm05.{hemi}'.format(contrast_name=args.contrast_name,
                                             hemi='{hemi}'), '{contrast}',
        'sig.{format}')

    # todo: should find automatically the existing_format
    if 'fmri_pipeline' in args.func:
        fmri_pipeline(subject,
                      args.atlas,
                      None,
                      fmri_contrast_file_template,
                      t_val=args.threshold,
                      existing_format=args.existing_format,
                      volume_type=args.volume_type,
                      load_labels_from_annotation=True,
                      surface_name=args.surface_name,
                      n_jobs=args.n_jobs)

    if utils.should_run(args, 'project_volume_to_surface'):
        project_volume_to_surface(subject,
                                  fol,
                                  args.threshold,
                                  volume_name,
                                  args.ontrast,
                                  existing_format=args.existing_format)

    if utils.should_run(args, 'find_clusters'):
        find_clusters(subject, args.contrast, args.threshold, args.atlas,
                      volume_name)

    if 'calc_meg_activity' in args.func:
        meg_subject = args.meg_subject
        if meg_subject == '':
            print(
                'You must set MEG subject (--meg_subject) to run calc_meg_activity function!'
            )
        else:
            calc_meg_activity_for_functional_rois(subject, meg_subject,
                                                  args.atlas, args.task,
                                                  args.contrast_name,
                                                  args.contrast,
                                                  args.inverse_method)
    if 'copy_volumes' in args.func:
        copy_volumes(subject, fmri_contrast_file_template)
Ejemplo n.º 12
0
def main(subject, remote_subject_dir, args, flags):
    utils.make_dir(op.join(MMVT_DIR, subject, 'electrodes'))
    stim_data = None

    if utils.should_run(args, 'load_stim_file'):
        stim_data = load_stim_file(subject, args)
        flags['load_stim_file'] = not stim_data is None

    if utils.should_run(args, 'create_stim_electrodes_positions'):
        labels = stim_data['labels'] if stim_data else None
        flags['create_stim_electrodes_positions'] = create_stim_electrodes_positions(subject, args, labels)

    if utils.should_run(args, 'set_labels_colors'):
        flags['set_labels_colors'] = set_labels_colors(subject, args, stim_data)

    return flags
Ejemplo n.º 13
0
def main(subject, remote_subject_dir, args, flags):
    utils.make_dir(op.join(MMVT_DIR, subject, 'electrodes'))
    stim_data = None

    if utils.should_run(args, 'load_stim_file'):
        stim_data = load_stim_file(subject, args)
        flags['load_stim_file'] = not stim_data is None

    if utils.should_run(args, 'create_stim_electrodes_positions'):
        labels = stim_data['labels'] if stim_data else None
        flags[
            'create_stim_electrodes_positions'] = create_stim_electrodes_positions(
                subject, args, labels)

    if utils.should_run(args, 'set_labels_colors'):
        flags['set_labels_colors'] = set_labels_colors(subject, args,
                                                       stim_data)

    return flags
Ejemplo n.º 14
0
def main(tup, remote_subject_dir, args, flags):
    (subject, mri_subject), inverse_method = tup
    evoked, epochs = None, None
    conditions, stat = init(subject, args, mri_subject, remote_subject_dir)

    if utils.should_run(args, 'read_eeg_sensors_layout'):
        flags['read_eeg_sensors_layout'] = read_eeg_sensors_layout(
            subject, mri_subject, args)

    flags, evoked, epochs = meg.calc_evokes_wrapper(subject,
                                                    conditions,
                                                    args,
                                                    flags,
                                                    mri_subject=mri_subject)

    if utils.should_run(args, 'create_eeg_mesh'):
        flags['create_eeg_mesh'] = create_eeg_mesh(
            mri_subject, args.eeg_electrodes_excluded_from_mesh)

    if utils.should_run(args, 'save_evoked_to_blender'):
        flags['save_evoked_to_blender'] = save_evoked_to_blender(
            mri_subject, conditions, args, evoked)

    if utils.should_run(args, 'calc_minmax'):
        flags['calc_minmax'] = calc_minmax(mri_subject, args)

    if not op.isfile(meg.COR):
        eeg_cor = op.join(meg.SUBJECT_MEG_FOLDER,
                          '{}-cor-trans.fif'.format(subject))
        if op.isfile(eeg_cor):
            meg.COR = eeg_cor
            flags = meg.calc_fwd_inv_wrapper(subject, args, conditions, flags,
                                             mri_subject)
            flags = meg.calc_stc_per_condition_wrapper(subject, conditions,
                                                       inverse_method, args,
                                                       flags)
        else:
            print(
                "Can't find head-MRI transformation matrix. Should be in {} or in {}"
                .format(meg.COR, eeg_cor))

    return flags
Ejemplo n.º 15
0
def main(subject, remote_subject_dir, args, flags):
    utils.make_dir(op.join(MMVT_DIR, subject, 'freeview'))
    args.elecs_pos, args.elecs_names = read_electrodes_pos(subject, args)

    if utils.should_run(args, 'copy_T1'):
        flags['copy_T1'] = copy_T1(subject)

    if utils.should_run(args, 'create_freeview_cmd'):
        flags['create_freeview_cmd'] = create_freeview_cmd(subject, args)

    if utils.should_run(args, 'create_electrodes_points'):
        flags['create_electrodes_points'] = create_electrodes_points(subject, args)

    if utils.should_run(args, 'create_aparc_aseg_file'):
        flags['create_aparc_aseg_file'] = create_aparc_aseg_file(subject, args)

    if utils.should_run(args, 'create_lut_file_for_atlas'):
        flags['create_lut_file_for_atlas'] = create_lut_file_for_atlas(subject, args.atlas)

    return flags
Ejemplo n.º 16
0
def main(subject, remote_subject_dir, args, flags):
    utils.make_dir(op.join(MMVT_DIR, subject, 'freeview'))
    args.elecs_pos, args.elecs_names = read_electrodes_pos(subject, args)

    if utils.should_run(args, 'copy_T1'):
        flags['copy_T1'] = copy_T1(subject)

    if utils.should_run(args, 'create_freeview_cmd'):
        flags['create_freeview_cmd'] = create_freeview_cmd(subject, args)

    if utils.should_run(args, 'create_electrodes_points'):
        flags['create_electrodes_points'] = create_electrodes_points(subject, args)

    if utils.should_run(args, 'create_aparc_aseg_file'):
        flags['create_aparc_aseg_file'] = create_aparc_aseg_file(subject, args.atlas, args.overwrite_aseg_file)

    if utils.should_run(args, 'create_lut_file_for_atlas'):
        flags['create_lut_file_for_atlas'] = create_lut_file_for_atlas(subject, args.atlas)

    return flags
Ejemplo n.º 17
0
def run_on_subjects(args, main_func, subjects_itr=None, subject_func=None):
    if subjects_itr is None:
        subjects_itr = args.subject
    subjects_flags, subjects_errors = {}, {}
    args.n_jobs = utils.get_n_jobs(args.n_jobs)
    args.sftp_password = utils.get_sftp_password(
        args.subject, SUBJECTS_DIR, args.necessary_files, args.sftp_username, args.overwrite_fs_files) \
        if args.sftp else ''
    if '*' in args.subject:
        args.subject = [utils.namebase(fol) for fol in glob.glob(op.join(SUBJECTS_DIR, args.subject))]
    os.environ['SUBJECTS_DIR'] = SUBJECTS_DIR
    for tup in subjects_itr:
        subject = get_subject(tup, subject_func)
        utils.make_dir(op.join(MMVT_DIR, subject, 'mmvt'))
        remote_subject_dir = utils.build_remote_subject_dir(args.remote_subject_dir, subject)
        print('****************************************************************')
        print('subject: {}, atlas: {}'.format(subject, args.atlas))
        print('remote dir: {}'.format(remote_subject_dir))
        print('****************************************************************')
        os.environ['SUBJECT'] = subject
        flags = dict()
        if args.necessary_files == '':
            args.necessary_files = dict()
        try:
            if utils.should_run(args, 'prepare_local_subjects_folder'):
                # *) Prepare the local subject's folder
                flags['prepare_local_subjects_folder'] = prepare_local_subjects_folder(
                    subject, remote_subject_dir, args)
                if not flags['prepare_local_subjects_folder'] and not args.ignore_missing:
                    ans = input('Do you which to continue (y/n)? ')
                    if not au.is_true(ans):
                        continue

            flags = main_func(tup, remote_subject_dir, args, flags)
            subjects_flags[subject] = flags
        except:
            subjects_errors[subject] = traceback.format_exc()
            print('Error in subject {}'.format(subject))
            print(traceback.format_exc())

    errors = defaultdict(list)
    for subject, flags in subjects_flags.items():
        print('subject {}:'.format(subject))
        for flag_type, val in flags.items():
            print('{}: {}'.format(flag_type, val))
            if not val:
                errors[subject].append(flag_type)
    if len(errors) > 0:
        print('Errors:')
        for subject, error in errors.items():
            print('{}: {}'.format(subject, error))
Ejemplo n.º 18
0
def main(subject, args):
    if utils.should_run('do_something'):
        do_something(subject, args)
Ejemplo n.º 19
0
def main(subject, remote_subject_dir, args, flags):
    utils.make_dir(op.join(SUBJECTS_DIR, subject, 'mmvt'))

    # if utils.should_run(args, 'prepare_local_subjects_folder'):
    #     # *) Prepare the local subject's folder
    #     flags['prepare_local_subjects_folder'] = prepare_local_subjects_folder(subject, remote_subject_dir, args)
    #     if not flags['prepare_local_subjects_folder'] and not args.ignore_missing:
    #         ans = input('Do you which to continue (y/n)? ')
    #         if not au.is_true(ans):
    #             return flags

    if utils.should_run(args, 'freesurfer_surface_to_blender_surface'):
        # *) convert rh.pial and lh.pial to rh.pial.ply and lh.pial.ply
        flags['hemis'] = freesurfer_surface_to_blender_surface(subject, overwrite=args.overwrite_hemis_srf)

    if utils.should_run(args, 'create_annotation_from_template'):
        # *) Create annotation file from fsaverage
        flags['create_annotation_from_template'] = create_annotation_from_template(
            subject, args.atlas, args.template_subject, remote_subject_dir, args.overwrite_annotation, args.overwrite_morphing_labels,
            args.solve_labels_collisions, args.morph_labels_from_fsaverage, args.fs_labels_fol, args.n_jobs)

    if utils.should_run(args, 'parcelate_cortex'):
        # *) Calls Matlab 'splitting_cortical.m' script
        flags['parcelate_cortex'] = parcelate_cortex(
            subject, args.atlas, args.overwrite_labels_ply_files, args.overwrite_ply_files)

    if utils.should_run(args, 'subcortical_segmentation'):
        # *) Create srf files for subcortical structures
        flags['subcortical'] = subcortical_segmentation(subject, args.overwrite_subcorticals)

    if utils.should_run(args, 'calc_faces_verts_dic'):
        # *) Create a dictionary for verts and faces for both hemis
        flags['faces_verts'] = calc_faces_verts_dic(subject, args.atlas, args.overwrite_faces_verts)

    if utils.should_run(args, 'save_labels_vertices'):
        # *) Save the labels vertices for meg label plotting
        flags['labels_vertices'] = save_labels_vertices(subject, args.atlas)

    # if utils.should_run(args, 'calc_verts_neighbors_lookup'):
    #     *) Calc the vertices neighbors lookup
        # flags['calc_verts_neighbors_lookup'] = calc_verts_neighbors_lookup(subject)

    if utils.should_run(args, 'save_hemis_curv'):
        # *) Save the hemis curvs for the inflated brain
        flags['save_hemis_curv'] = save_hemis_curv(subject, args.atlas)

    # if utils.should_run(args, 'calc_verts_neighbors_lookup'):
    #     flags['calc_verts_neighbors_lookup'] = calc_verts_neighbors_lookup(subject)

    if utils.should_run(args, 'create_spatial_connectivity'):
        # *) Create the subject's connectivity
        flags['connectivity'] = create_spatial_connectivity(subject)

    # if utils.should_run(args, 'check_ply_files'):
    #     # *) Check the pial surfaces
    #     flags['ply_files'] = check_ply_files(subject)

    if utils.should_run(args, 'calc_labels_center_of_mass'):
        # *) Calc the labels center of mass
        flags['center_of_mass'] = calc_labels_center_of_mass(subject, args.atlas, args.surf_name)

    if utils.should_run(args, 'save_labels_coloring'):
        # *) Save a coloring file for the atlas's labels
        flags['save_labels_coloring'] = save_labels_coloring(subject, args.atlas, args.n_jobs)

    if 'cerebellum_segmentation' in args.function:
        flags['save_cerebellum_coloring'] = save_cerebellum_coloring(subject)
        flags['cerebellum_segmentation'] = cerebellum_segmentation(subject, remote_subject_dir, args)

    # for flag_type, val in flags.items():
    #     print('{}: {}'.format(flag_type, val))
    return flags
Ejemplo n.º 20
0
def main(subject, args):
    flags = dict()
    utils.make_dir(op.join(SUBJECTS_DIR, subject, 'mmvt'))
    args.remote_subject_dir = utils.build_remote_subject_dir(args.remote_subject_dir, subject)

    if utils.should_run(args, 'prepare_local_subjects_folder'):
        # *) Prepare the local subject's folder
        flags['prepare_local_subjects_folder'] = prepare_local_subjects_folder(subject, args)
        if not flags['prepare_local_subjects_folder'] and not args.ignore_missing:
            return flags

    if utils.should_run(args, 'freesurfer_surface_to_blender_surface'):
        # *) convert rh.pial and lh.pial to rh.pial.ply and lh.pial.ply
        flags['hemis'] = freesurfer_surface_to_blender_surface(subject, overwrite=args.overwrite_hemis_srf)


    if utils.should_run(args, 'create_annotation_from_fsaverage'):
        # *) Create annotation file from fsaverage
        flags['annot'] = create_annotation_from_fsaverage(
            subject, args.atlas, args.fsaverage, args.remote_subject_dir, args.overwrite_annotation, args.overwrite_morphing_labels,
            args.solve_labels_collisions, args.morph_labels_from_fsaverage, args.fs_labels_fol, args.n_jobs)

    if utils.should_run(args, 'parcelate_cortex'):
        # *) Calls Matlab 'splitting_cortical.m' script
        flags['parc_cortex'] = parcelate_cortex(
            subject, args.atlas, args.overwrite_labels_ply_files, args.overwrite_ply_files)

    if utils.should_run(args, 'subcortical_segmentation'):
        # *) Create srf files for subcortical structures
        # !!! Should source freesurfer !!!
        # Remember that you need to have write permissions on SUBJECTS_DIR!!!
        flags['subcortical'] = subcortical_segmentation(subject)

    if utils.should_run(args, 'calc_faces_verts_dic'):
        # *) Create a dictionary for verts and faces for both hemis
        flags['faces_verts'] = calc_faces_verts_dic(subject, args.atlas, args.overwrite_faces_verts)

    if utils.should_run(args, 'save_labels_vertices'):
        # *) Save the labels vertices for meg label plotting
        flags['labels_vertices'] = save_labels_vertices(subject, args.atlas)

    # if utils.should_run(args, 'calc_verts_neighbors_lookup'):
    #     *) Calc the vertices neighbors lookup
        # flags['calc_verts_neighbors_lookup'] = calc_verts_neighbors_lookup(subject)

    if utils.should_run(args, 'save_hemis_curv'):
        # *) Save the hemis curvs for the inflated brain
        flags['save_hemis_curv'] = save_hemis_curv(subject, args.atlas)

    # if utils.should_run(args, 'calc_verts_neighbors_lookup'):
    #     flags['calc_verts_neighbors_lookup'] = calc_verts_neighbors_lookup(subject)

    if utils.should_run(args, 'create_spatial_connectivity'):
        # *) Create the subject's connectivity
        flags['connectivity'] = create_spatial_connectivity(subject)

    # if utils.should_run(args, 'check_ply_files'):
    #     # *) Check the pial surfaces
    #     flags['ply_files'] = check_ply_files(subject)

    if utils.should_run(args, 'calc_labels_center_of_mass'):
        # *) Calc the labels center of mass
        flags['center_of_mass'] = calc_labels_center_of_mass(subject, args.atlas, args.surf_name)

    if utils.should_run(args, 'save_labels_coloring'):
        # *) Save a coloring file for the atlas's labels
        flags['save_labels_coloring'] = save_labels_coloring(subject, args.atlas, args.n_jobs)

    # for flag_type, val in flags.items():
    #     print('{}: {}'.format(flag_type, val))
    return flags
Ejemplo n.º 21
0
def main(subject, args):
    flags = dict()
    utils.make_dir(op.join(SUBJECTS_DIR, subject, 'mmvt'))
    if args.remote_subjects_dir != '':
        args.remote_subject_dir = op.join(args.remote_subjects_dir, subject)
    elif '{subject}' in args.remote_subject_dir:
        args.remote_subject_dir = build_remote_subject_dir(args.remote_subject_dir, subject)

    if utils.should_run(args, 'prepare_local_subjects_folder'):
        # *) Prepare the local subject's folder
        flags['prepare_local_subjects_folder'] = prepare_local_subjects_folder(subject, args)
        if not flags['prepare_local_subjects_folder'] and not args.ignore_missing:
            return flags

    if utils.should_run(args, 'freesurfer_surface_to_blender_surface'):
        # *) convert rh.pial and lh.pial to rh.pial.ply and lh.pial.ply
        flags['hemis'] = freesurfer_surface_to_blender_surface(subject, overwrite=args.overwrite_hemis_srf)

    if utils.should_run(args, 'create_annotation_from_fsaverage'):
        # *) Create annotation file from fsaverage
        flags['annot'] = create_annotation_from_fsaverage(
            subject, args.atlas, args.fsaverage, args.overwrite_annotation, args.overwrite_morphing_labels,
            args.solve_labels_collisions, args.morph_labels_from_fsaverage, args.fs_labels_fol, args.n_jobs)

    if utils.should_run(args, 'parcelate_cortex'):
        # *) Calls Matlab 'splitting_cortical.m' script
        flags['parc_cortex'] = parcelate_cortex(
            subject, args.atlas, args.overwrite_labels_ply_files, args.overwrite_ply_files)

    if utils.should_run(args, 'subcortical_segmentation'):
        # *) Create srf files for subcortical structures
        # !!! Should source freesurfer !!!
        # Remember that you need to have write permissions on SUBJECTS_DIR!!!
        flags['subcortical'] = subcortical_segmentation(subject)

    if utils.should_run(args, 'calc_faces_verts_dic'):
        # *) Create a dictionary for verts and faces for both hemis
        flags['faces_verts'] = calc_faces_verts_dic(subject, args.overwrite_faces_verts)

    if utils.should_run(args, 'save_labels_vertices'):
        # *) Save the labels vertices for meg label plotting
        flags['labels_vertices'] = save_labels_vertices(subject, args.atlas)

    if utils.should_run(args, 'create_spatial_connectivity'):
        # *) Create the subject's connectivity
        flags['connectivity'] = create_spatial_connectivity(subject)

    if utils.should_run(args, 'check_ply_files'):
        # *) Check the pial surfaces
        flags['ply_files'] = check_ply_files(subject)

    if utils.should_run(args, 'calc_labels_center_of_mass'):
        # *) Calc the labels center of mass
        flags['center_of_mass'] = calc_labels_center_of_mass(subject, args.atlas, args.surf_name)

    if utils.should_run(args, 'save_labels_coloring'):
        # *) Save a coloring file for the atlas's labels
        flags['save_labels_coloring'] = save_labels_coloring(subject, args.atlas, args.n_jobs)

    for flag_type, val in flags.items():
        print('{}: {}'.format(flag_type, val))
    return flags
Ejemplo n.º 22
0
def main(subject, remote_subject_dir, args, flags):
    if utils.should_run('do_something'):
        flags['do_something'] = do_something(subject, args)
    return flags
Ejemplo n.º 23
0
def main(subject, remote_subject_dir, args, flags):
    if utils.should_run(args, 'do_something'):
        flags['do_something'] = do_something(subject, args)
    return flags
Ejemplo n.º 24
0
def main(subject, args):
    if utils.should_run('do_something'):
        do_something(subject, args)