File size: 1,910 Bytes
933cd71 | 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 | # Path Configuration
from tools.preprocess import *
# Processing context
trait = "Asthma"
# Input paths
tcga_root_dir = "../DATA/TCGA"
# Output paths
out_data_file = "./output/z1/preprocess/Asthma/TCGA.csv"
out_gene_data_file = "./output/z1/preprocess/Asthma/gene_data/TCGA.csv"
out_clinical_data_file = "./output/z1/preprocess/Asthma/clinical_data/TCGA.csv"
json_path = "./output/z1/preprocess/Asthma/cohort_info.json"
# Step 1: Initial Data Loading
import os
import pandas as pd
# Step 1: Identify a TCGA cohort relevant to the trait "Asthma"
subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
# Define strict synonyms for asthma; avoid overly broad respiratory terms to prevent mismatches (e.g., lung cancers)
asthma_terms = {"asthma", "bronchial_asthma", "asthmatic"}
candidates = []
for d in subdirs:
name_lower = d.lower()
if any(term in name_lower for term in asthma_terms):
candidates.append(d)
selected_dir = None
if candidates:
# Choose the most specific (shortest name as a heuristic)
selected_dir = sorted(candidates, key=lambda x: len(x))[0]
if selected_dir is None:
print("No suitable TCGA cohort found for Asthma. Skipping this trait.")
_ = validate_and_save_cohort_info(
is_final=False,
cohort="TCGA",
info_path=json_path,
is_gene_available=False,
is_trait_available=False
)
else:
# Step 2: Locate clinical and genetic files
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
# Step 3: Load both files
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 clinical column names
print(list(clinical_df.columns)) |