# Path Configuration from tools.preprocess import * # Processing context trait = "Alcohol_Flush_Reaction" # Input paths tcga_root_dir = "../DATA/TCGA" # Output paths out_data_file = "./output/z1/preprocess/Alcohol_Flush_Reaction/TCGA.csv" out_gene_data_file = "./output/z1/preprocess/Alcohol_Flush_Reaction/gene_data/TCGA.csv" out_clinical_data_file = "./output/z1/preprocess/Alcohol_Flush_Reaction/clinical_data/TCGA.csv" json_path = "./output/z1/preprocess/Alcohol_Flush_Reaction/cohort_info.json" # Step 1: Initial Data Loading import os import pandas as pd # Step 1: Identify the best-matching TCGA cohort directory for the trait "Alcohol_Flush_Reaction" keywords = { 'alcohol', 'ethanol', 'flush', 'flushing', 'reaction', 'erythema', 'aldehyde', 'dehydrogenase', 'aldh2', 'acetaldehyde', 'intolerance', 'sensitivity' } subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))] def normalize_name(name: str) -> str: return name.replace('_', ' ').replace('(', ' ').replace(')', ' ').lower() matches = [] for d in subdirs: norm = normalize_name(d) hit_count = sum(1 for k in keywords if k in norm) if hit_count > 0: matches.append((d, hit_count, len(norm))) # If no suitable directory is found, mark as completed (skip this trait) if not matches: _ = validate_and_save_cohort_info( is_final=False, cohort="TCGA", info_path=json_path, is_gene_available=False, is_trait_available=False ) selected_dir = None clinical_df = None genetic_df = None else: # Choose the most specific match: highest hit_count, then shortest name matches.sort(key=lambda x: (-x[1], x[2])) selected_dir = matches[0][0] cohort_dir = os.path.join(tcga_root_dir, selected_dir) clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) # Step 3: Load the clinical and genetic data clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False) genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False) # Step 4: Print clinical column names print(list(clinical_df.columns))