|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Bile_Duct_Cancer" |
|
|
|
|
|
tcga_root_dir = "../DATA/TCGA" |
|
|
|
|
|
out_data_file = "./output/preprocess/1/Bile_Duct_Cancer/TCGA.csv" |
|
out_gene_data_file = "./output/preprocess/1/Bile_Duct_Cancer/gene_data/TCGA.csv" |
|
out_clinical_data_file = "./output/preprocess/1/Bile_Duct_Cancer/clinical_data/TCGA.csv" |
|
json_path = "./output/preprocess/1/Bile_Duct_Cancer/cohort_info.json" |
|
|
|
import os |
|
import pandas as pd |
|
|
|
|
|
search_terms = ["bile_duct", "bileduct", "chol"] |
|
dir_list = os.listdir(tcga_root_dir) |
|
matching_dir = None |
|
|
|
for d in dir_list: |
|
d_lower = d.lower() |
|
if any(term in d_lower for term in search_terms): |
|
|
|
matching_dir = d |
|
break |
|
|
|
if matching_dir is None: |
|
|
|
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, matching_dir) |
|
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) |
|
|
|
|
|
clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t') |
|
genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t') |
|
|
|
|
|
print("Clinical Data Columns:") |
|
print(clinical_df.columns.tolist()) |
|
|
|
candidate_age_cols = ["age_at_initial_pathologic_diagnosis", "days_to_birth"] |
|
candidate_gender_cols = ["gender"] |
|
|
|
|
|
age_cols_in_data = [col for col in candidate_age_cols if col in clinical_df.columns] |
|
gender_cols_in_data = [col for col in candidate_gender_cols if col in clinical_df.columns] |
|
|
|
if age_cols_in_data: |
|
age_preview_df = clinical_df[age_cols_in_data] |
|
print("Age Data Preview:", preview_df(age_preview_df, n=5)) |
|
else: |
|
print("Age Data Preview:", {}) |
|
|
|
if gender_cols_in_data: |
|
gender_preview_df = clinical_df[gender_cols_in_data] |
|
print("Gender Data Preview:", preview_df(gender_preview_df, n=5)) |
|
else: |
|
print("Gender Data Preview:", {}) |
|
|
|
|
|
|
|
age_col = "age_at_initial_pathologic_diagnosis" |
|
gender_col = "gender" |
|
|
|
print("Chosen Age Column:", age_col) |
|
print("Chosen Gender Column:", gender_col) |
|
|
|
selected_clinical_df = tcga_select_clinical_features( |
|
clinical_df=clinical_df, |
|
trait=trait, |
|
age_col=age_col, |
|
gender_col=gender_col |
|
) |
|
|
|
|
|
genetic_df_normalized = normalize_gene_symbols_in_index(genetic_df) |
|
genetic_df_normalized.to_csv(out_gene_data_file) |
|
|
|
|
|
gene_expr_t = genetic_df_normalized.T |
|
linked_data = selected_clinical_df.join(gene_expr_t, how='inner') |
|
|
|
|
|
linked_data = handle_missing_values(linked_data, trait) |
|
|
|
|
|
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait) |
|
|
|
|
|
is_usable = validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort="TCGA", |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=True, |
|
is_biased=trait_biased, |
|
df=linked_data, |
|
note="Prostate Cancer data from TCGA." |
|
) |
|
|
|
|
|
if is_usable: |
|
linked_data.to_csv(out_data_file) |
|
|
|
clinical_cols = [col for col in [trait, "Age", "Gender"] if col in linked_data.columns] |
|
if clinical_cols: |
|
linked_data[clinical_cols].to_csv(out_clinical_data_file) |