Liu-Hy's picture
Add files using upload-large-folder tool
d818561 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Bone_Density"
# Input paths
tcga_root_dir = "../DATA/TCGA"
# Output paths
out_data_file = "./output/z2/preprocess/Bone_Density/TCGA.csv"
out_gene_data_file = "./output/z2/preprocess/Bone_Density/gene_data/TCGA.csv"
out_clinical_data_file = "./output/z2/preprocess/Bone_Density/clinical_data/TCGA.csv"
json_path = "./output/z2/preprocess/Bone_Density/cohort_info.json"
# Step 1: Initial Data Loading
import os
import pandas as pd
# Step 1: List subdirectories and select the most relevant cohort for Bone_Density
all_subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
# Keywords indicative of bone density-related traits
keywords = ['bone', 'bmd', 'osteop', 'skelet', 'bone_density', 'bone mineral density', 'osteopenia']
def is_relevant(name: str, kws) -> bool:
lname = name.lower()
return any(kw in lname for kw in kws)
candidate_dirs = [d for d in all_subdirs if is_relevant(d, keywords)]
selected_cohort_dir = None
if candidate_dirs:
# Choose the most specific (longest name) if multiple matches
selected_cohort_dir = sorted(candidate_dirs, key=len, reverse=True)[0]
cohort_path = os.path.join(tcga_root_dir, selected_cohort_dir)
# Step 2: Identify clinical and genetic file paths
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_path)
# Step 3: Load both files as DataFrames
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False)
genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False)
# Step 4: Print the column names of the clinical data
print(list(clinical_df.columns))
else:
print(f"No suitable TCGA cohort found for trait '{trait}'. Skipping this trait.")
# Record unavailability in cohort info
validate_and_save_cohort_info(
is_final=False,
cohort="TCGA",
info_path=json_path,
is_gene_available=False,
is_trait_available=False
)
# Define empty placeholders to avoid potential NameErrors downstream
clinical_df = pd.DataFrame()
genetic_df = pd.DataFrame()