|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Kidney_stones" |
|
|
|
|
|
tcga_root_dir = "../DATA/TCGA" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Kidney_stones/TCGA.csv" |
|
out_gene_data_file = "./output/preprocess/3/Kidney_stones/gene_data/TCGA.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Kidney_stones/clinical_data/TCGA.csv" |
|
json_path = "./output/preprocess/3/Kidney_stones/cohort_info.json" |
|
|
|
|
|
trait_dir = 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)' |
|
cohort_dir = os.path.join(tcga_root_dir, trait_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'] |
|
|
|
|
|
tcga_brca_dir = os.path.join(tcga_root_dir, 'BRCA') |
|
clinical_file_path, _ = tcga_get_relevant_filepaths(tcga_brca_dir) |
|
clinical_df = pd.read_csv(clinical_file_path, index_col=0) |
|
|
|
|
|
age_preview = clinical_df[candidate_age_cols].head() |
|
print("\nAge columns preview:", preview_df(age_preview)) |
|
|
|
|
|
gender_preview = clinical_df[candidate_gender_cols].head() |
|
print("\nGender columns preview:", preview_df(gender_preview)) |
|
import pandas as pd |
|
|
|
|
|
cohort_dir = os.path.join(tcga_root_dir, "KIRC") |
|
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) |
|
|
|
|
|
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0) |
|
|
|
|
|
candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'days_to_birth'] |
|
candidate_gender_cols = ['gender'] |
|
|
|
|
|
age_preview = {} |
|
for col in candidate_age_cols: |
|
if col in clinical_df.columns: |
|
age_preview[col] = clinical_df[col].head().tolist() |
|
|
|
|
|
gender_preview = {} |
|
for col in candidate_gender_cols: |
|
if col in clinical_df.columns: |
|
gender_preview[col] = clinical_df[col].head().tolist() |
|
|
|
candidate_age_cols = [] |
|
candidate_gender_cols = [] |
|
|
|
|
|
|
|
age_col = None |
|
gender_col = None |
|
|
|
print(f"Selected age column: {age_col}") |
|
print(f"Selected gender column: {gender_col}") |
|
|
|
trait_dir = 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)' |
|
cohort_dir = os.path.join(tcga_root_dir, trait_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'] |
|
|
|
|
|
print("\nIdentified candidate columns:") |
|
print(f"candidate_age_cols = {candidate_age_cols}") |
|
print(f"candidate_gender_cols = {candidate_gender_cols}") |
|
|
|
|
|
clinical_file_path, _ = tcga_get_relevant_filepaths(os.path.join(tcga_root_dir, 'KIRP/')) |
|
clinical_df = pd.read_csv(clinical_file_path, index_col=0) |
|
|
|
|
|
age_preview = preview_df(clinical_df[candidate_age_cols]) |
|
print("\nAge columns preview:") |
|
print(age_preview) |
|
|
|
gender_preview = preview_df(clinical_df[candidate_gender_cols]) |
|
print("\nGender columns preview:") |
|
print(gender_preview) |
|
|
|
candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'days_to_birth'] |
|
candidate_gender_cols = ['gender'] |
|
|
|
|
|
available_cohorts = os.listdir(tcga_root_dir) |
|
|
|
|
|
kidney_cohorts = [c for c in available_cohorts if "TCGA_Kidney" in c] |
|
|
|
if kidney_cohorts: |
|
|
|
cohort_dir = os.path.join(tcga_root_dir, kidney_cohorts[0]) |
|
|
|
|
|
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') |
|
|
|
|
|
age_preview = {} |
|
for col in candidate_age_cols: |
|
if col in clinical_df.columns: |
|
age_preview[col] = clinical_df[col].head().tolist() |
|
print("Age columns preview:", age_preview) |
|
|
|
|
|
gender_preview = {} |
|
for col in candidate_gender_cols: |
|
if col in clinical_df.columns: |
|
gender_preview[col] = clinical_df[col].head().tolist() |
|
print("Gender columns preview:", gender_preview) |
|
else: |
|
print("No kidney-related cohorts found") |
|
|
|
|
|
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_df['Kidney_stones'] = clinical_df.index.map(tcga_convert_trait) |
|
|
|
|
|
selected_clinical_df = tcga_select_clinical_features(clinical_df, 'Kidney_stones', age_col, gender_col) |
|
|
|
|
|
normalized_gene_df = normalize_gene_symbols_in_index(genetic_df) |
|
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
|
normalized_gene_df.to_csv(out_gene_data_file) |
|
|
|
|
|
linked_data = pd.concat([selected_clinical_df, normalized_gene_df.T], axis=1, join='inner') |
|
|
|
|
|
linked_data = handle_missing_values(linked_data, 'Kidney_stones') |
|
|
|
|
|
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, 'Kidney_stones') |
|
|
|
|
|
note = "Using kidney papillary cell carcinoma (KIRP) data from TCGA for kidney stone analysis." |
|
is_usable = validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort="TCGA_KIRP", |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=True, |
|
is_biased=trait_biased, |
|
df=linked_data, |
|
note=note |
|
) |
|
|
|
|
|
if is_usable: |
|
os.makedirs(os.path.dirname(out_data_file), exist_ok=True) |
|
linked_data.to_csv(out_data_file) |