|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Eczema" |
|
|
|
|
|
tcga_root_dir = "../DATA/TCGA" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Eczema/TCGA.csv" |
|
out_gene_data_file = "./output/preprocess/3/Eczema/gene_data/TCGA.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Eczema/clinical_data/TCGA.csv" |
|
json_path = "./output/preprocess/3/Eczema/cohort_info.json" |
|
|
|
|
|
cohort_dir = os.path.join(tcga_root_dir, "TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)") |
|
|
|
|
|
clinical_file, genetic_file = tcga_get_relevant_filepaths(cohort_dir) |
|
|
|
|
|
clinical_df = pd.read_csv(clinical_file, sep='\t', index_col=0) |
|
genetic_df = pd.read_csv(genetic_file, sep='\t', index_col=0) |
|
|
|
|
|
print("\nClinical data columns:") |
|
print(clinical_df.columns.tolist()) |
|
|
|
|
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort="TCGA", |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available='eczema_history' in clinical_df.columns |
|
) |
|
|
|
candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'days_to_birth', 'first_diagnosis_age_asth_ecz_hay_fev_mold_dust', 'first_diagnosis_age_of_animal_insect_allergy', 'first_diagnosis_age_of_food_allergy'] |
|
candidate_gender_cols = ['gender'] |
|
|
|
|
|
cohort_dir = os.path.join(tcga_root_dir, "TCGA_Breast_Cancer_(BRCA)") |
|
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) |
|
clinical_df = pd.read_csv(clinical_file_path, index_col=0) |
|
|
|
|
|
age_preview = clinical_df[candidate_age_cols].head(5).to_dict(orient='list') |
|
print("\nAge columns preview:") |
|
print(age_preview) |
|
|
|
|
|
gender_preview = clinical_df[candidate_gender_cols].head(5).to_dict(orient='list') |
|
print("\nGender columns preview:") |
|
print(gender_preview) |
|
|
|
print("Directory contents:") |
|
print(os.listdir(tcga_root_dir)) |
|
|
|
|
|
for subdir in os.listdir(tcga_root_dir): |
|
full_path = os.path.join(tcga_root_dir, subdir) |
|
if os.path.isdir(full_path): |
|
print(f"\nFiles in {subdir}:") |
|
print(os.listdir(full_path)[:5]) |
|
|
|
first_cohort_dir = os.path.join(tcga_root_dir, 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)') |
|
clinical_file, _ = tcga_get_relevant_filepaths(first_cohort_dir) |
|
clinical_df = pd.read_csv(clinical_file, sep='\t', index_col=0) |
|
|
|
|
|
candidate_age_cols = ['_age_at_initial_pathologic_diagnosis', 'age_at_initial_pathologic_diagnosis'] |
|
candidate_gender_cols = ['gender'] |
|
|
|
|
|
age_df = clinical_df[candidate_age_cols[0] if candidate_age_cols[0] in clinical_df.columns else candidate_age_cols[1]] |
|
gender_df = clinical_df[candidate_gender_cols[0]] |
|
|
|
print("Age column preview:") |
|
print(preview_df(pd.DataFrame(age_df))) |
|
print("\nGender column preview:") |
|
print(preview_df(pd.DataFrame(gender_df))) |
|
|
|
age_col = "age_at_initial_pathologic_diagnosis" |
|
gender_col = "gender" |
|
|
|
|
|
print(f"Selected age column: {age_col}") |
|
print(f"Selected gender column: {gender_col}") |
|
|
|
clinical_features = tcga_select_clinical_features( |
|
clinical_df, |
|
trait=trait, |
|
age_col="age_at_initial_pathologic_diagnosis", |
|
gender_col="gender" |
|
) |
|
|
|
|
|
clinical_features.to_csv(out_clinical_data_file) |
|
|
|
|
|
normalized_gene_data = normalize_gene_symbols_in_index(genetic_df) |
|
normalized_gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
linked_data = pd.merge( |
|
clinical_features, |
|
normalized_gene_data.T, |
|
left_index=True, |
|
right_index=True, |
|
how='inner' |
|
) |
|
|
|
|
|
linked_data = handle_missing_values(linked_data, trait) |
|
|
|
|
|
is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait) |
|
|
|
|
|
notes = "Using TCGA lower grade glioma and glioblastoma (GBMLGG) data. Normal samples serve as controls, tumor samples as disease cases." |
|
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=is_trait_biased, |
|
df=linked_data, |
|
note=notes |
|
) |
|
|
|
|
|
if is_usable: |
|
linked_data.to_csv(out_data_file) |