| |
| from tools.preprocess import * |
|
|
| |
| trait = "Duchenne_Muscular_Dystrophy" |
|
|
| |
| tcga_root_dir = "../DATA/TCGA" |
|
|
| |
| out_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/TCGA.csv" |
| out_gene_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/gene_data/TCGA.csv" |
| out_clinical_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/TCGA.csv" |
| json_path = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/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))] |
|
|
| |
| terms = ["duchenne muscular dystrophy", "dystrophin", "dmd"] |
| lower_map = {d.lower(): d for d in subdirs} |
|
|
| def score_dir(name: str) -> int: |
| name_l = name.lower() |
| score = 0 |
| if "duchenne muscular dystrophy" in name_l: |
| score += 3 |
| if "dystrophin" in name_l: |
| score += 2 |
| if "dmd" in name_l: |
| score += 1 |
| return score |
|
|
| scored = [(score_dir(d), d) for d in subdirs] |
| scored = [item for item in scored if item[0] > 0] |
|
|
| if len(scored) == 0: |
| print("No suitable TCGA cohort matches Duchenne Muscular Dystrophy. Skipping this trait for TCGA.") |
| |
| validate_and_save_cohort_info( |
| is_final=False, |
| cohort="TCGA_Duchenne_Muscular_Dystrophy", |
| info_path=json_path, |
| is_gene_available=False, |
| is_trait_available=False |
| ) |
| |
| clinical_df = pd.DataFrame() |
| genetic_df = pd.DataFrame() |
| else: |
| |
| selected_dir = sorted(scored, key=lambda x: (-x[0], len(x[1])))[0][1] |
| cohort_dir = os.path.join(tcga_root_dir, selected_dir) |
| print(f"Selected TCGA cohort: {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)) |