| |
| from tools.preprocess import * |
|
|
| |
| trait = "Alcohol_Flush_Reaction" |
|
|
| |
| tcga_root_dir = "../DATA/TCGA" |
|
|
| |
| 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" |
|
|
|
|
| |
| import os |
| import pandas as pd |
|
|
| |
| 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 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: |
| |
| 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) |
|
|
| |
| 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) |
|
|
| |
| print(list(clinical_df.columns)) |