|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Retinoblastoma" |
|
|
|
|
|
tcga_root_dir = "../DATA/TCGA" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Retinoblastoma/TCGA.csv" |
|
out_gene_data_file = "./output/preprocess/3/Retinoblastoma/gene_data/TCGA.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Retinoblastoma/clinical_data/TCGA.csv" |
|
json_path = "./output/preprocess/3/Retinoblastoma/cohort_info.json" |
|
|
|
|
|
available_cohorts = os.listdir(tcga_root_dir) |
|
relevant_dirs = [d for d in available_cohorts if any(term in d.lower() for term in ['eye', 'ocular', 'retina', 'retinoblastoma'])] |
|
|
|
|
|
if len(relevant_dirs) == 0: |
|
|
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort="TCGA", |
|
info_path=json_path, |
|
is_gene_available=False, |
|
is_trait_available=False |
|
) |
|
|
|
clinical_df = pd.DataFrame() |
|
genetic_df = pd.DataFrame() |
|
else: |
|
|
|
selected_dir = relevant_dirs[0] |
|
cohort_dir = os.path.join(tcga_root_dir, selected_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()) |
|
|
|
|
|
is_gene_available = len(genetic_df.columns) > 0 |
|
is_trait_available = len(clinical_df.columns) > 0 |
|
|
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort="TCGA", |
|
info_path=json_path, |
|
is_gene_available=is_gene_available, |
|
is_trait_available=is_trait_available |
|
) |
|
|
|
candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'days_to_birth'] |
|
candidate_gender_cols = ['gender'] |
|
|
|
|
|
cohorts = os.listdir(tcga_root_dir) |
|
|
|
|
|
clinical_df = None |
|
for cohort in cohorts: |
|
cohort_dir = os.path.join(tcga_root_dir, cohort) |
|
if os.path.isdir(cohort_dir): |
|
try: |
|
clinical_file_path, _ = tcga_get_relevant_filepaths(cohort_dir) |
|
temp_df = pd.read_csv(clinical_file_path, index_col=0) |
|
if any('retinoblastoma' in str(col).lower() for col in temp_df.columns): |
|
clinical_df = temp_df |
|
break |
|
except: |
|
continue |
|
|
|
if clinical_df is not None: |
|
|
|
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 clinical data found containing Retinoblastoma information") |