| |
| from tools.preprocess import * |
|
|
| |
| trait = "Arrhythmia" |
|
|
| |
| tcga_root_dir = "../DATA/TCGA" |
|
|
| |
| out_data_file = "./output/z1/preprocess/Arrhythmia/TCGA.csv" |
| out_gene_data_file = "./output/z1/preprocess/Arrhythmia/gene_data/TCGA.csv" |
| out_clinical_data_file = "./output/z1/preprocess/Arrhythmia/clinical_data/TCGA.csv" |
| json_path = "./output/z1/preprocess/Arrhythmia/cohort_info.json" |
|
|
|
|
| |
| import os |
| import pandas as pd |
|
|
| |
| available_subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))] |
|
|
| |
| keywords_specific = [ |
| 'arrhythmia', 'atrial_fibrillation', 'brugada', 'long_qt', 'ventricular_tachycardia', |
| 'supraventricular', 'cardiac_conduction', 'torsades', 'wolff', 'wolff-parkinson-white' |
| ] |
| keywords_general = ['cardiac', 'cardio', 'heart', 'myocard'] |
|
|
| def find_best_cohort(subdirs, specific_kw, general_kw): |
| scored = [] |
| for sd in subdirs: |
| sdl = sd.lower() |
| score = 0 |
| if any(k in sdl for k in specific_kw): |
| score += 2 |
| if any(k in sdl for k in general_kw): |
| score += 1 |
| if score > 0: |
| scored.append((score, sd)) |
| if not scored: |
| return None |
| scored.sort(reverse=True) |
| return scored[0][1] |
|
|
| selected_subdir = find_best_cohort(available_subdirs, keywords_specific, keywords_general) |
|
|
| if selected_subdir is None: |
| print(f"No suitable TCGA cohort directory found for trait '{trait}'. Skipping this trait.") |
| |
| validate_and_save_cohort_info( |
| is_final=False, |
| cohort="TCGA", |
| info_path=json_path, |
| is_gene_available=False, |
| is_trait_available=False |
| ) |
| else: |
| cohort_dir = os.path.join(tcga_root_dir, selected_subdir) |
| 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(f"Selected cohort directory: {selected_subdir}") |
| print("Clinical data columns:") |
| print(list(clinical_df.columns)) |