| |
| from tools.preprocess import * |
|
|
| |
| trait = "Anorexia_Nervosa" |
|
|
| |
| tcga_root_dir = "../DATA/TCGA" |
|
|
| |
| out_data_file = "./output/z1/preprocess/Anorexia_Nervosa/TCGA.csv" |
| out_gene_data_file = "./output/z1/preprocess/Anorexia_Nervosa/gene_data/TCGA.csv" |
| out_clinical_data_file = "./output/z1/preprocess/Anorexia_Nervosa/clinical_data/TCGA.csv" |
| json_path = "./output/z1/preprocess/Anorexia_Nervosa/cohort_info.json" |
|
|
|
|
| |
| import os |
| import pandas as pd |
|
|
| |
| all_entries = os.listdir(tcga_root_dir) |
| cohort_dirs = [d for d in all_entries if os.path.isdir(os.path.join(tcga_root_dir, d))] |
|
|
| |
| trait_keywords = { |
| "anorexia", "nervosa", "eating", "appetite", "weight", "body_mass", "bmi", "cachexia" |
| } |
|
|
| |
| def score_dir(name: str) -> int: |
| lname = name.lower() |
| return sum(1 for kw in trait_keywords if kw in lname) |
|
|
| scored = [(d, score_dir(d)) for d in cohort_dirs] |
| |
| scored.sort(key=lambda x: x[1], reverse=True) |
| selected_dir = scored[0][0] if scored and scored[0][1] > 0 else None |
|
|
| 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 |
| ) |
| clinical_df = None |
| genetic_df = None |
| print("No suitable TCGA cohort found for the trait; skipping TCGA for this trait.") |
| else: |
| cohort_path = os.path.join(tcga_root_dir, selected_dir) |
| clinical_fp, genetic_fp = tcga_get_relevant_filepaths(cohort_path) |
|
|
| |
| clinical_df = pd.read_csv(clinical_fp, sep='\t', index_col=0, low_memory=False) |
| genetic_df = pd.read_csv(genetic_fp, sep='\t', index_col=0, low_memory=False) |
|
|
| |
| print(clinical_df.columns.tolist()) |