| |
| from tools.preprocess import * |
|
|
| |
| trait = "Craniosynostosis" |
|
|
| |
| tcga_root_dir = "../DATA/TCGA" |
|
|
| |
| out_data_file = "./output/z2/preprocess/Craniosynostosis/TCGA.csv" |
| out_gene_data_file = "./output/z2/preprocess/Craniosynostosis/gene_data/TCGA.csv" |
| out_clinical_data_file = "./output/z2/preprocess/Craniosynostosis/clinical_data/TCGA.csv" |
| json_path = "./output/z2/preprocess/Craniosynostosis/cohort_info.json" |
|
|
|
|
| |
| |
| subdirs = os.listdir(tcga_root_dir) |
|
|
| |
| keywords = [ |
| ("craniosynostosis", 5), |
| ("synostosis", 4), |
| ("cranio", 3), |
| ("skull", 2), |
| ("suture", 1), |
| ] |
|
|
| def score_dir(name: str) -> int: |
| lname = name.lower() |
| return max((w for k, w in keywords if k in lname), default=0) |
|
|
| scored = [(d, score_dir(d)) for d in subdirs] |
| |
| selected_dir = None |
| if scored: |
| best_dir, best_score = max(scored, key=lambda x: x[1]) |
| if best_score > 0: |
| selected_dir = best_dir |
|
|
| clinical_df, genetic_df = pd.DataFrame(), pd.DataFrame() |
|
|
| if selected_dir is None: |
| |
| _ = validate_and_save_cohort_info( |
| is_final=False, |
| cohort="TCGA", |
| info_path=json_path, |
| is_gene_available=False, |
| is_trait_available=False |
| ) |
| print("No suitable TCGA cohort found for the trait. Skipping. Clinical columns: []") |
| else: |
| |
| cohort_dir = os.path.join(tcga_root_dir, selected_dir) |
| clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) |
|
|
| |
| def read_tcga_file(path: str) -> pd.DataFrame: |
| compression = 'gzip' if path.endswith('.gz') else None |
| return pd.read_csv(path, sep='\t', index_col=0, low_memory=False, compression=compression) |
|
|
| clinical_df = read_tcga_file(clinical_file_path) |
| genetic_df = read_tcga_file(genetic_file_path) |
|
|
| |
| print(list(clinical_df.columns)) |