from pathlib import Path import sys sys.path.append(str(Path(__file__).resolve().parent.parent)) project_root_path = Path(__file__).resolve().parent.parent import utils import shutil def copy_one_resp_pair(one_id): sync_type = "Sync" org_bcg_file_path = sync_bcg_path / f"{one_id}" dest_bcg_file_path = pair_file_path / f"{one_id}" dest_bcg_file_path.mkdir(parents=True, exist_ok=True) if not list(org_bcg_file_path.glob("OrgBCG_Sync_*.txt")): if not list(org_bcg_file_path.glob("OrgBCG_RoughCut_*.txt")): print(f"No OrgBCG files found for ID {one_id}.") return else: sync_type = "RoughCut" print(f"Using RoughCut files for ID {one_id}.") for file in org_bcg_file_path.glob(f"OrgBCG_{sync_type}_*.txt"): shutil.copyfile(file, dest_bcg_file_path / f"{one_id}_{file.name}".replace("_RoughCut", "").replace("_Sync", "")) psg_file_path = sync_psg_path / f"{one_id}" dest_psg_file_path = pair_file_path / f"{one_id}" dest_psg_file_path.mkdir(parents=True, exist_ok=True) # 检查上面的文件是否存在 psg_file_patterns = [ f"5_class_{sync_type}_*.txt", f"Effort Abd_{sync_type}_*.txt", f"Effort Tho_{sync_type}_*.txt", f"Flow P_{sync_type}_*.txt", f"Flow T_{sync_type}_*.txt", f"SA Label_Sync.csv", f"SpO2_{sync_type}_*.txt" ] for pattern in psg_file_patterns: if not list(psg_file_path.glob(pattern)): print(f"No PSG files found for ID {one_id} with pattern {pattern}.") return for pattern in psg_file_patterns: for file in psg_file_path.glob(pattern): shutil.copyfile(file, dest_psg_file_path / f"{one_id}_{file.name.replace('_RoughCut', '').replace('_Sync', '')}") if __name__ == '__main__': yaml_path = project_root_path / "dataset_config/RESP_PAIR_ZD5Y_config.yaml" conf = utils.load_dataset_conf(yaml_path) select_ids = conf["select_ids"] root_path = Path(conf["root_path"]) sync_bcg_path = root_path / "OrgBCG_Aligned" sync_psg_path = root_path / "PSG_Aligned" pair_file_path = Path(conf["pair_file_path"]) # copy_one_resp_pair(961) for samp_id in select_ids: print(f"Processing {samp_id}...") copy_one_resp_pair(samp_id)