|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Colon_and_Rectal_Cancer" |
|
|
|
|
|
tcga_root_dir = "../DATA/TCGA" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Colon_and_Rectal_Cancer/TCGA.csv" |
|
out_gene_data_file = "./output/preprocess/3/Colon_and_Rectal_Cancer/gene_data/TCGA.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Colon_and_Rectal_Cancer/clinical_data/TCGA.csv" |
|
json_path = "./output/preprocess/3/Colon_and_Rectal_Cancer/cohort_info.json" |
|
|
|
|
|
|
|
candidate_age_cols = [] |
|
candidate_gender_cols = [] |
|
|
|
|
|
demo_data = pd.DataFrame() |
|
|
|
|
|
print("Age columns preview:", preview_df(demo_data[candidate_age_cols]) if candidate_age_cols else {}) |
|
print("Gender columns preview:", preview_df(demo_data[candidate_gender_cols]) if candidate_gender_cols else {}) |
|
|
|
cohort_dir = os.path.join(tcga_root_dir, 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)') |
|
|
|
|
|
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("Clinical data columns:") |
|
print(clinical_df.columns.tolist()) |
|
|
|
candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'days_to_birth'] |
|
candidate_gender_cols = ['gender'] |
|
|
|
|
|
clinical_file_path, _ = tcga_get_relevant_filepaths(os.path.join(tcga_root_dir, trait)) |
|
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("Age 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) |
|
|
|
age_columns_dict = { |
|
'age_at_initial_pathologic_diagnosis': [63, 77, 69, 59, 88], |
|
'_days_to_birth': [-23090, -28241, -25325, -21569, -32185] |
|
} |
|
|
|
|
|
gender_columns_dict = { |
|
'gender': ['MALE', 'FEMALE', 'MALE', 'FEMALE', 'MALE'], |
|
'sex': ['male', 'female', 'male', 'female', 'male'] |
|
} |
|
|
|
|
|
age_col = 'age_at_initial_pathologic_diagnosis' |
|
gender_col = 'gender' |
|
|
|
print("Selected demographic columns:") |
|
print(f"Age column: {age_col}") |
|
print(f"Gender column: {gender_col}") |
|
|
|
clinical_features = tcga_select_clinical_features( |
|
clinical_df, |
|
trait=trait, |
|
age_col=age_col, |
|
gender_col=gender_col |
|
) |
|
|
|
|
|
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 kidney cancer (KIRC) 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) |