|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Telomere_Length" |
|
|
|
|
|
tcga_root_dir = "../DATA/TCGA" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Telomere_Length/TCGA.csv" |
|
out_gene_data_file = "./output/preprocess/3/Telomere_Length/gene_data/TCGA.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Telomere_Length/clinical_data/TCGA.csv" |
|
json_path = "./output/preprocess/3/Telomere_Length/cohort_info.json" |
|
|
|
|
|
available_cohorts = [d for d in os.listdir(tcga_root_dir) |
|
if os.path.isdir(os.path.join(tcga_root_dir, d)) and not d.startswith('.')] |
|
|
|
|
|
found_telomere_data = False |
|
telomere_clinical_data = None |
|
telomere_genetic_data = None |
|
|
|
|
|
for cohort in available_cohorts: |
|
if cohort.startswith('.'): |
|
continue |
|
|
|
cohort_dir = os.path.join(tcga_root_dir, cohort) |
|
try: |
|
|
|
clinical_path, genetic_path = tcga_get_relevant_filepaths(cohort_dir) |
|
|
|
|
|
clinical_df = pd.read_csv(clinical_path, sep='\t', index_col=0) |
|
genetic_df = pd.read_csv(genetic_path, sep='\t', index_col=0) |
|
|
|
|
|
clinical_telomere = any('telomere' in col.lower() for col in clinical_df.columns) |
|
genetic_telomere = any('telomere' in gene.lower() for gene in genetic_df.index) |
|
|
|
if clinical_telomere or genetic_telomere: |
|
found_telomere_data = True |
|
telomere_clinical_data = clinical_df |
|
telomere_genetic_data = genetic_df |
|
print(f"Found telomere data in cohort: {cohort}") |
|
print("\nClinical data columns:") |
|
print(clinical_df.columns.tolist()) |
|
break |
|
|
|
except Exception as e: |
|
print(f"Error processing cohort {cohort}: {str(e)}") |
|
continue |
|
|
|
|
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort='TCGA', |
|
info_path=json_path, |
|
is_gene_available=found_telomere_data, |
|
is_trait_available=found_telomere_data |
|
) |
|
|
|
if not found_telomere_data: |
|
print("\nNo telomere length measurements found in any TCGA cohort.") |