| |
| from tools.preprocess import * |
|
|
| |
| trait = "Allergies" |
|
|
| |
| tcga_root_dir = "../DATA/TCGA" |
|
|
| |
| out_data_file = "./output/z1/preprocess/Allergies/TCGA.csv" |
| out_gene_data_file = "./output/z1/preprocess/Allergies/gene_data/TCGA.csv" |
| out_clinical_data_file = "./output/z1/preprocess/Allergies/clinical_data/TCGA.csv" |
| json_path = "./output/z1/preprocess/Allergies/cohort_info.json" |
|
|
|
|
| |
| import os |
| import pandas as pd |
|
|
| |
| |
| keywords = [ |
| "allerg", "hypersens", "atopy", "atopic", "asthma", "urticaria", "rhinitis", "eczema", "hayfever", "hay_fever" |
| ] |
|
|
| |
| available_subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))] |
|
|
| |
| candidates = [d for d in available_subdirs if any(k in d.lower() for k in keywords)] |
|
|
| selected_dir = None |
| if len(candidates) > 0: |
| |
| def score_dir(name: str) -> int: |
| lname = name.lower() |
| return sum(lname.count(k) for k in keywords) |
|
|
| candidates.sort(key=score_dir, reverse=True) |
| selected_dir = candidates[0] |
|
|
| |
| if selected_dir is None: |
| print("No TCGA cohort directory matches the target trait 'Allergies'. 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 = None |
| genetic_df = None |
| else: |
| print(f"Selected TCGA cohort directory: {selected_dir}") |
| cohort_dir = os.path.join(tcga_root_dir, selected_dir) |
|
|
| |
| clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) |
| print(f"Clinical file: {clinical_file_path}") |
| print(f"Genetic file: {genetic_file_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("Clinical data columns:") |
| print(list(clinical_df.columns)) |