File size: 2,018 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
# Path Configuration
from tools.preprocess import *

# Processing context
trait = "Depression"

# Input paths
tcga_root_dir = "../DATA/TCGA"

# Output paths
out_data_file = "./output/z2/preprocess/Depression/TCGA.csv"
out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/TCGA.csv"
out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/TCGA.csv"
json_path = "./output/z2/preprocess/Depression/cohort_info.json"


# Step 1: Initial Data Loading
import os
import pandas as pd

# Step 1: Select TCGA subdirectory relevant to the trait "Depression"
keywords = [
    'depress', 'mdd', 'major_depress', 'depressive', 'mood',
    'psychi', 'mental', 'affective', 'sadness'
]

subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
matches = []
for d in subdirs:
    name_l = d.lower()
    if any(k in name_l for k in keywords):
        matches.append(d)

selected_tcga_dir = None
if len(matches) > 0:
    # Choose the most specific match by the longest directory name (heuristic for specificity)
    selected_tcga_dir = max(matches, key=len)
else:
    # No suitable cohort for depression in TCGA cancer cohorts; record and skip this trait
    print("No suitable TCGA cohort found for trait 'Depression'. Skipping preprocessing for this trait.")
    _ = validate_and_save_cohort_info(
        is_final=False,
        cohort="TCGA",
        info_path=json_path,
        is_gene_available=False,
        is_trait_available=False
    )

# Step 2-4: If a directory was selected, identify files, load data, and print clinical column names
clinical_df, genetic_df = None, None
if selected_tcga_dir is not None:
    cohort_dir = os.path.join(tcga_root_dir, selected_tcga_dir)
    clinical_path, genetic_path = tcga_get_relevant_filepaths(cohort_dir)

    clinical_df = pd.read_csv(clinical_path, sep="\t", index_col=0, low_memory=False)
    genetic_df = pd.read_csv(genetic_path, sep="\t", index_col=0, low_memory=False)

    print(list(clinical_df.columns))