def create_cpac_data_config(bids_dir, participant_label=None, aws_input_creds=None, skip_bids_validator=False): from bids_utils import collect_bids_files_configs, bids_gen_cpac_sublist print("Parsing {0}..".format(bids_dir)) (file_paths, config) = collect_bids_files_configs(bids_dir, aws_input_creds) if participant_label: file_paths = [ file_path for file_path in file_paths if any(participant_label in file_path for participant_label in participant_labels) ] if not file_paths: print("Did not find data for {0}".format(", ".join(participant_label))) sys.exit(1) raise_error = not skip_bids_validator sub_list = bids_gen_cpac_sublist(bids_dir, file_paths, config, aws_input_creds, raise_error=raise_error) if not sub_list: print("Did not find data in {0}".format(bids_dir)) sys.exit(1) return sub_list
def test_gen_bids_sublist(bids_dir, test_yml, creds_path, dbg=False): (img_files, config) = collect_bids_files_configs(bids_dir, creds_path) print("Found %d config files for %d image files" % (len(config), len(img_files))) sublist = bids_gen_cpac_sublist(bids_dir, img_files, config, creds_path, dbg) with open(test_yml, "w") as ofd: yaml.dump(sublist, ofd, encoding='utf-8') sublist = bids_gen_cpac_sublist(bids_dir, img_files, None, creds_path, dbg) test_yml = test_yml.replace(".yml", "_no_param.yml") with open(test_yml, "w") as ofd: yaml.dump(sublist, ofd, encoding='utf-8') assert sublist
if 'sub-' not in pt: pt = 'sub-' + pt pt_file_paths += [fp for fp in file_paths if pt in fp] file_paths = pt_file_paths if not file_paths: print("Did not find any files to process") sys.exit(1) # TODO: once CPAC is updated to use per-scan parameters from subject list, # change the 3rd arguement to the config dict returned from # collect_bids_files_configs sub_list = bids_gen_cpac_sublist(args.bids_dir, file_paths, [], args.aws_input_creds) if not sub_list: print("Did not find data in {0}".format(args.bids_dir)) sys.exit(1) else: # load the file as a check to make sure it is available and readable sub_list = yaml.load(open(os.path.realpath(args.data_config_file), 'r')) if args.participant_label: t_sub_list = [] for sub_dict in sub_list: if sub_dict["participant_id"] in args.participant_label or \ sub_dict["participant_id"].replace("sub-", "") in args.participant_label: t_sub_list.append(sub_dict)
file_paths = [ file_path for file_path in file_paths if any(participant_label in file_path for participant_label in participant_labels) ] if not file_paths: print("Did not find data for {0}".format(", ".join( args.participant_label))) sys.exit(1) raise_error = not args.skip_bids_validator sub_list = bids_gen_cpac_sublist(args.bids_dir, file_paths, config, args.aws_input_creds, raise_error=raise_error) if not sub_list: print("Did not find data in {0}".format(args.bids_dir)) sys.exit(1) else: # load the file as a check to make sure it is available and readable sub_list = load_yaml_config(args.data_config_file, args.aws_input_creds) if args.participant_label: sub_list = [
pt_file_paths = [] for pt in args.participant_label: if 'sub-' not in pt: pt = 'sub-' + pt pt_file_paths += [fp for fp in file_paths if pt in fp] file_paths = pt_file_paths if not file_paths: print("Did not find any files to process") sys.exit(1) sub_list = bids_gen_cpac_sublist(args.bids_dir, file_paths, config, args.aws_input_creds) if not sub_list: print("Did not find data in {0}".format(args.bids_dir)) sys.exit(1) else: # load the file as a check to make sure it is available and readable sub_list = load_yaml_config(args.data_config_file, args.aws_input_creds) if args.participant_label: t_sub_list = [] for sub_dict in sub_list: if sub_dict["subject_id"] in args.participant_label or \ sub_dict["subject_id"].replace("sub-", "") in args.participant_label: t_sub_list.append(sub_dict)