| |
| from tools.preprocess import * |
|
|
| |
| trait = "Endometrioid_Cancer" |
|
|
| |
| tcga_root_dir = "../DATA/TCGA" |
|
|
| |
| out_data_file = "./output/z2/preprocess/Endometrioid_Cancer/TCGA.csv" |
| out_gene_data_file = "./output/z2/preprocess/Endometrioid_Cancer/gene_data/TCGA.csv" |
| out_clinical_data_file = "./output/z2/preprocess/Endometrioid_Cancer/clinical_data/TCGA.csv" |
| json_path = "./output/z2/preprocess/Endometrioid_Cancer/cohort_info.json" |
|
|
|
|
| |
| |
| selected_cohort = "TCGA_Endometrioid_Cancer_(UCEC)" |
| cohort_path = os.path.join(tcga_root_dir, selected_cohort) |
|
|
| print(f"Selected cohort: {selected_cohort}") |
|
|
| |
| clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_path) |
|
|
| print(f"Clinical data file: {clinical_file_path}") |
| print(f"Genetic data file: {genetic_file_path}") |
|
|
| |
| clinical_data = pd.read_csv(clinical_file_path, index_col=0, sep='\t') |
|
|
| |
| genetic_data = pd.read_csv(genetic_file_path, index_col=0, sep='\t') |
|
|
| print(f"\nClinical data shape: {clinical_data.shape}") |
| print(f"Genetic data shape: {genetic_data.shape}") |
|
|
| print(f"\nClinical data column names:") |
| print(clinical_data.columns.tolist()) |
|
|
| |
| |
| candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'days_to_birth'] |
| candidate_gender_cols = ['gender'] |
|
|
| |
| clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(os.path.join(tcga_root_dir, "TCGA_Endometrioid_Cancer_(UCEC)")) |
| clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0) |
|
|
| |
| if candidate_age_cols: |
| age_data = clinical_df[candidate_age_cols] |
| print("Age candidate columns preview:") |
| print(preview_df(age_data, n=5)) |
| print() |
|
|
| |
| if candidate_gender_cols: |
| gender_data = clinical_df[candidate_gender_cols] |
| print("Gender candidate columns preview:") |
| print(preview_df(gender_data, n=5)) |
|
|
| |
| |
| |
| |
|
|
| |
| age_col = 'age_at_initial_pathologic_diagnosis' |
|
|
| |
| gender_col = 'gender' |
|
|
| print(f"Chosen age column: {age_col}") |
| print(f"Chosen gender column: {gender_col}") |
|
|
| |
| |
| clinical_features = tcga_select_clinical_features( |
| clinical_data, |
| trait=trait, |
| age_col=age_col, |
| gender_col=gender_col |
| ) |
|
|
| print(f"Clinical features shape: {clinical_features.shape}") |
| print(f"Clinical features columns: {clinical_features.columns.tolist()}") |
|
|
| |
| normalized_genetic_data = normalize_gene_symbols_in_index(genetic_data) |
| print(f"Normalized genetic data shape: {normalized_genetic_data.shape}") |
|
|
| |
| os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
| normalized_genetic_data.to_csv(out_gene_data_file) |
| print(f"Saved normalized genetic data to {out_gene_data_file}") |
|
|
| |
| genetic_data_transposed = normalized_genetic_data.T |
| print(f"Transposed genetic data shape: {genetic_data_transposed.shape}") |
|
|
| |
| common_samples = clinical_features.index.intersection(genetic_data_transposed.index) |
| print(f"Common samples between clinical and genetic data: {len(common_samples)}") |
|
|
| clinical_aligned = clinical_features.loc[common_samples] |
| genetic_aligned = genetic_data_transposed.loc[common_samples] |
|
|
| linked_data = pd.concat([clinical_aligned, genetic_aligned], axis=1) |
| print(f"Linked data shape: {linked_data.shape}") |
|
|
| |
| linked_data = handle_missing_values(linked_data, trait) |
| print(f"Data shape after handling missing values: {linked_data.shape}") |
|
|
| |
| trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait) |
| print(f"Final data shape: {linked_data.shape}") |
| print(f"Final columns: {linked_data.columns.tolist()[:10]}...") |
|
|
| |
| is_gene_available = len([col for col in linked_data.columns if col not in [trait, 'Age', 'Gender']]) > 0 |
| is_trait_available = trait in linked_data.columns and not linked_data[trait].isna().all() |
|
|
| |
| is_usable = validate_and_save_cohort_info( |
| is_final=True, |
| cohort="TCGA", |
| info_path=json_path, |
| is_gene_available=is_gene_available, |
| is_trait_available=is_trait_available, |
| is_biased=trait_biased, |
| df=linked_data, |
| note="INFO: TCGA Endometrioid Cancer cohort processed successfully" |
| ) |
|
|
| |
| os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True) |
| clinical_features.to_csv(out_clinical_data_file) |
| print(f"Saved clinical data to {out_clinical_data_file}") |
|
|
| |
| if is_usable: |
| os.makedirs(os.path.dirname(out_data_file), exist_ok=True) |
| linked_data.to_csv(out_data_file) |
| print(f"Dataset is usable. Saved linked data to {out_data_file}") |
| else: |
| print("Dataset is not usable. Linked data was not saved.") |