# Path Configuration from tools.preprocess import * # Processing context trait = "Aniridia" # Input paths tcga_root_dir = "../DATA/TCGA" # Output paths out_data_file = "./output/z1/preprocess/Aniridia/TCGA.csv" out_gene_data_file = "./output/z1/preprocess/Aniridia/gene_data/TCGA.csv" out_clinical_data_file = "./output/z1/preprocess/Aniridia/clinical_data/TCGA.csv" json_path = "./output/z1/preprocess/Aniridia/cohort_info.json" # Step 1: Initial Data Loading import os import pandas as pd # 1) Select the most relevant TCGA cohort directory for the trait "Aniridia" subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))] # Heuristic keyword scoring to approximate phenotypic overlap with "Aniridia" keywords_weights = [ ("aniridia", 10), ("iris", 6), ("ocular", 5), ("eye", 4), ("uveal", 4), ("uvea", 4), ("retina", 3), ("optic", 2), ("ophthalm", 2) ] def score_dir(name: str) -> int: ln = name.lower() return sum(w for k, w in keywords_weights if k in ln) scored = [(d, score_dir(d)) for d in subdirs] 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: # No suitable cohort; record and exit step gracefully 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 directory found for the trait. Skipping.") else: cohort_dir = os.path.join(tcga_root_dir, selected_dir) # 2) Identify clinical and genetic file paths clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) # 3) Load both files as DataFrames clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False, compression='infer') genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False, compression='infer') # Keep references for downstream steps SELECTED_TCGA_DIR = selected_dir SELECTED_CLINICAL_PATH = clinical_file_path SELECTED_GENETIC_PATH = genetic_file_path TCGA_CLINICAL_DF = clinical_df TCGA_GENETIC_DF = genetic_df # 4) Print the column names of the clinical data print(list(clinical_df.columns))