Liu-Hy's picture
Add files using upload-large-folder tool
6f366b0 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Telomere_Length"
# Input paths
tcga_root_dir = "../DATA/TCGA"
# Output paths
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"
# Get list of available cohorts
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('.')]
# Initialize flags to track telomere data availability
found_telomere_data = False
telomere_clinical_data = None
telomere_genetic_data = None
# Check each cohort for telomere length data
for cohort in available_cohorts:
if cohort.startswith('.'): # Skip hidden directories
continue
cohort_dir = os.path.join(tcga_root_dir, cohort)
try:
# Get file paths
clinical_path, genetic_path = tcga_get_relevant_filepaths(cohort_dir)
# Load data
clinical_df = pd.read_csv(clinical_path, sep='\t', index_col=0)
genetic_df = pd.read_csv(genetic_path, sep='\t', index_col=0)
# Check for telomere-related measurements
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
# Record findings
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.")