| | |
| | from tools.preprocess import * |
| |
|
| | |
| | trait = "Bone_Density" |
| |
|
| | |
| | tcga_root_dir = "../DATA/TCGA" |
| |
|
| | |
| | out_data_file = "./output/z2/preprocess/Bone_Density/TCGA.csv" |
| | out_gene_data_file = "./output/z2/preprocess/Bone_Density/gene_data/TCGA.csv" |
| | out_clinical_data_file = "./output/z2/preprocess/Bone_Density/clinical_data/TCGA.csv" |
| | json_path = "./output/z2/preprocess/Bone_Density/cohort_info.json" |
| |
|
| |
|
| | |
| | import os |
| | import pandas as pd |
| |
|
| | |
| | all_subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))] |
| |
|
| | |
| | keywords = ['bone', 'bmd', 'osteop', 'skelet', 'bone_density', 'bone mineral density', 'osteopenia'] |
| |
|
| | def is_relevant(name: str, kws) -> bool: |
| | lname = name.lower() |
| | return any(kw in lname for kw in kws) |
| |
|
| | candidate_dirs = [d for d in all_subdirs if is_relevant(d, keywords)] |
| |
|
| | selected_cohort_dir = None |
| | if candidate_dirs: |
| | |
| | selected_cohort_dir = sorted(candidate_dirs, key=len, reverse=True)[0] |
| | cohort_path = os.path.join(tcga_root_dir, selected_cohort_dir) |
| |
|
| | |
| | clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_path) |
| |
|
| | |
| | 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)) |
| | else: |
| | print(f"No suitable TCGA cohort 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 |
| | ) |
| | |
| | clinical_df = pd.DataFrame() |
| | genetic_df = pd.DataFrame() |