File size: 2,475 Bytes
6b8ee1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | # Path Configuration
from tools.preprocess import *
# Processing context
trait = "Duchenne_Muscular_Dystrophy"
# Input paths
tcga_root_dir = "../DATA/TCGA"
# Output paths
out_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/TCGA.csv"
out_gene_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/gene_data/TCGA.csv"
out_clinical_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/TCGA.csv"
json_path = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/cohort_info.json"
# Step 1: Initial Data Loading
import os
import pandas as pd
# Discover available subdirectories (cohorts)
subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
# Try to find a TCGA cohort relevant to Duchenne Muscular Dystrophy (DMD) — TCGA is cancer-focused, so expect none.
terms = ["duchenne muscular dystrophy", "dystrophin", "dmd"]
lower_map = {d.lower(): d for d in subdirs}
def score_dir(name: str) -> int:
name_l = name.lower()
score = 0
if "duchenne muscular dystrophy" in name_l:
score += 3
if "dystrophin" in name_l:
score += 2
if "dmd" in name_l:
score += 1
return score
scored = [(score_dir(d), d) for d in subdirs]
scored = [item for item in scored if item[0] > 0]
if len(scored) == 0:
print("No suitable TCGA cohort matches Duchenne Muscular Dystrophy. Skipping this trait for TCGA.")
# Record unusable dataset for this trait within TCGA
validate_and_save_cohort_info(
is_final=False,
cohort="TCGA_Duchenne_Muscular_Dystrophy",
info_path=json_path,
is_gene_available=False,
is_trait_available=False
)
# Prepare empty placeholders to avoid downstream NameErrors if any
clinical_df = pd.DataFrame()
genetic_df = pd.DataFrame()
else:
# Select the best-matching cohort
selected_dir = sorted(scored, key=lambda x: (-x[0], len(x[1])))[0][1]
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
print(f"Selected TCGA cohort: {selected_dir}")
# Identify relevant file paths
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
# Load clinical and genetic data
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)
# Print clinical column names
print(list(clinical_df.columns)) |