| |
| from tools.preprocess import * |
|
|
| |
| trait = "Atrial_Fibrillation" |
|
|
| |
| tcga_root_dir = "../DATA/TCGA" |
|
|
| |
| out_data_file = "./output/z1/preprocess/Atrial_Fibrillation/TCGA.csv" |
| out_gene_data_file = "./output/z1/preprocess/Atrial_Fibrillation/gene_data/TCGA.csv" |
| out_clinical_data_file = "./output/z1/preprocess/Atrial_Fibrillation/clinical_data/TCGA.csv" |
| json_path = "./output/z1/preprocess/Atrial_Fibrillation/cohort_info.json" |
|
|
|
|
| |
| import os |
| import pandas as pd |
|
|
| |
| subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))] |
|
|
| |
| keywords = ['atrial_fibrillation', 'atrial fibrillation', 'a-fib', 'afib', 'arrhythmia', 'cardiac', 'heart'] |
| candidates = [] |
| for d in subdirs: |
| name_l = d.lower() |
| score = sum(1 for k in keywords if k in name_l) |
| if score > 0: |
| candidates.append((score, d)) |
|
|
| selected_dir = None |
| if candidates: |
| |
| candidates.sort(key=lambda x: (-x[0], len(x[1]))) |
| selected_dir = candidates[0][1] |
|
|
| 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 TCGA processing for this trait.") |
| else: |
| cohort_dir = os.path.join(tcga_root_dir, selected_dir) |
| clinical_path, genetic_path = tcga_get_relevant_filepaths(cohort_dir) |
|
|
| clinical_df = pd.read_csv(clinical_path, sep='\t', index_col=0, low_memory=False) |
| genetic_df = pd.read_csv(genetic_path, sep='\t', index_col=0, low_memory=False) |
|
|
| print(clinical_df.columns.tolist()) |