File size: 2,363 Bytes
d818561 | 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 | # Path Configuration
from tools.preprocess import *
# Processing context
trait = "Cardiovascular_Disease"
# Input paths
tcga_root_dir = "../DATA/TCGA"
# Output paths
out_data_file = "./output/z2/preprocess/Cardiovascular_Disease/TCGA.csv"
out_gene_data_file = "./output/z2/preprocess/Cardiovascular_Disease/gene_data/TCGA.csv"
out_clinical_data_file = "./output/z2/preprocess/Cardiovascular_Disease/clinical_data/TCGA.csv"
json_path = "./output/z2/preprocess/Cardiovascular_Disease/cohort_info.json"
# Step 1: Initial Data Loading
import os
import pandas as pd
# Step 1: Find a TCGA cohort directory relevant to cardiovascular disease (CVD)
subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
cvd_terms = [
'cardio', 'cardiovascular', 'heart', 'cardiac', 'coronary', 'artery',
'arterial', 'vascular', 'cvd', 'atherosclerosis', 'myocard', 'stroke'
]
def match_score(name: str) -> int:
name_l = name.lower()
return sum(term in name_l for term in cvd_terms)
scored = [(d, match_score(d)) for d in subdirs]
# Select the directory with the highest match score; if tie, keep the first in list order
scored_sorted = sorted(scored, key=lambda x: x[1], reverse=True)
selected_dir = scored_sorted[0][0] if scored_sorted and scored_sorted[0][1] > 0 else None
clinical_df = None
genetic_df = None
clinical_path = None
genetic_path = None
selected_dir_path = None
if selected_dir is None:
# No suitable cohort; record and skip further processing
validate_and_save_cohort_info(
is_final=False,
cohort='TCGA',
info_path=json_path,
is_gene_available=False,
is_trait_available=False
)
print(f"No suitable TCGA cohort found for trait: {trait}. Skipping.")
else:
# Step 2: Identify clinical and genetic file paths within the selected cohort directory
selected_dir_path = os.path.join(tcga_root_dir, selected_dir)
clinical_path, genetic_path = tcga_get_relevant_filepaths(selected_dir_path)
# Step 3: Load both files as DataFrames
clinical_df = pd.read_csv(clinical_path, sep='\t', index_col=0, compression='infer', low_memory=False)
genetic_df = pd.read_csv(genetic_path, sep='\t', index_col=0, compression='infer', low_memory=False)
# Step 4: Print the column names of the clinical data
print(list(clinical_df.columns)) |