File size: 18,240 Bytes
736e4a0 |
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "fe8cf253",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:32:16.809171Z",
"iopub.status.busy": "2025-03-25T06:32:16.808928Z",
"iopub.status.idle": "2025-03-25T06:32:16.977623Z",
"shell.execute_reply": "2025-03-25T06:32:16.977272Z"
}
},
"outputs": [],
"source": [
"import sys\n",
"import os\n",
"sys.path.append(os.path.abspath(os.path.join(os.getcwd(), '../..')))\n",
"\n",
"# Path Configuration\n",
"from tools.preprocess import *\n",
"\n",
"# Processing context\n",
"trait = \"Anxiety_disorder\"\n",
"\n",
"# Input paths\n",
"tcga_root_dir = \"../../input/TCGA\"\n",
"\n",
"# Output paths\n",
"out_data_file = \"../../output/preprocess/Anxiety_disorder/TCGA.csv\"\n",
"out_gene_data_file = \"../../output/preprocess/Anxiety_disorder/gene_data/TCGA.csv\"\n",
"out_clinical_data_file = \"../../output/preprocess/Anxiety_disorder/clinical_data/TCGA.csv\"\n",
"json_path = \"../../output/preprocess/Anxiety_disorder/cohort_info.json\"\n"
]
},
{
"cell_type": "markdown",
"id": "cb928a35",
"metadata": {},
"source": [
"### Step 1: Initial Data Loading"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0a3480f2",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:32:16.978852Z",
"iopub.status.busy": "2025-03-25T06:32:16.978709Z",
"iopub.status.idle": "2025-03-25T06:32:18.596990Z",
"shell.execute_reply": "2025-03-25T06:32:18.596660Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Available TCGA subdirectories: ['TCGA_Liver_Cancer_(LIHC)', 'TCGA_Lower_Grade_Glioma_(LGG)', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Mesothelioma_(MESO)', 'TCGA_Ocular_melanomas_(UVM)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Sarcoma_(SARC)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Thymoma_(THYM)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Uterine_Carcinosarcoma_(UCS)', '.DS_Store', 'CrawlData.ipynb', 'TCGA_Acute_Myeloid_Leukemia_(LAML)', 'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Bile_Duct_Cancer_(CHOL)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Cervical_Cancer_(CESC)', 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Endometrioid_Cancer_(UCEC)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Glioblastoma_(GBM)', 'TCGA_Head_and_Neck_Cancer_(HNSC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)']\n",
"Selected directory: TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG) - this dataset may contain clinical information about psychiatric conditions including anxiety\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Clinical data columns:\n",
"['_INTEGRATION', '_PANCAN_CNA_PANCAN_K8', '_PANCAN_Cluster_Cluster_PANCAN', '_PANCAN_DNAMethyl_PANCAN', '_PANCAN_RPPA_PANCAN_K8', '_PANCAN_UNC_RNAseq_PANCAN_K16', '_PANCAN_mutation_PANCAN', '_PATIENT', '_cohort', '_primary_disease', '_primary_site', 'additional_pharmaceutical_therapy', 'additional_radiation_therapy', 'additional_surgery_locoregional_procedure', 'additional_surgery_metastatic_procedure', 'age_at_initial_pathologic_diagnosis', 'animal_insect_allergy_history', 'animal_insect_allergy_types', 'asthma_history', 'bcr_followup_barcode', 'bcr_patient_barcode', 'bcr_sample_barcode', 'days_to_additional_surgery_locoregional_procedure', 'days_to_additional_surgery_metastatic_procedure', 'days_to_birth', 'days_to_collection', 'days_to_death', 'days_to_initial_pathologic_diagnosis', 'days_to_last_followup', 'days_to_new_tumor_event_additional_surgery_procedure', 'days_to_new_tumor_event_after_initial_treatment', 'days_to_performance_status_assessment', 'eastern_cancer_oncology_group', 'eczema_history', 'family_history_of_cancer', 'family_history_of_primary_brain_tumor', 'first_diagnosis_age_asth_ecz_hay_fev_mold_dust', 'first_diagnosis_age_of_animal_insect_allergy', 'first_diagnosis_age_of_food_allergy', 'first_presenting_symptom', 'first_presenting_symptom_longest_duration', 'followup_case_report_form_submission_reason', 'followup_treatment_success', 'food_allergy_history', 'food_allergy_types', 'form_completion_date', 'gender', 'hay_fever_history', 'headache_history', 'histological_type', 'history_ionizing_rt_to_head', 'history_of_neoadjuvant_treatment', 'icd_10', 'icd_o_3_histology', 'icd_o_3_site', 'informed_consent_verified', 'inherited_genetic_syndrome_found', 'inherited_genetic_syndrome_result', 'initial_pathologic_diagnosis_method', 'initial_weight', 'intermediate_dimension', 'is_ffpe', 'karnofsky_performance_score', 'laterality', 'ldh1_mutation_found', 'ldh1_mutation_test_method', 'ldh1_mutation_tested', 'longest_dimension', 'lost_follow_up', 'mental_status_changes', 'mold_or_dust_allergy_history', 'motor_movement_changes', 'neoplasm_histologic_grade', 'new_neoplasm_event_type', 'new_tumor_event_additional_surgery_procedure', 'new_tumor_event_after_initial_treatment', 'oct_embedded', 'other_dx', 'pathology_report_file_name', 'patient_id', 'performance_status_scale_timing', 'person_neoplasm_cancer_status', 'postoperative_rx_tx', 'preoperative_antiseizure_meds', 'preoperative_corticosteroids', 'primary_therapy_outcome_success', 'prior_glioma', 'radiation_therapy', 'sample_type', 'sample_type_id', 'seizure_history', 'sensory_changes', 'shortest_dimension', 'supratentorial_localization', 'targeted_molecular_therapy', 'tissue_prospective_collection_indicator', 'tissue_retrospective_collection_indicator', 'tissue_source_site', 'tumor_location', 'tumor_tissue_site', 'vial_number', 'visual_changes', 'vital_status', 'year_of_initial_pathologic_diagnosis', '_GENOMIC_ID_TCGA_GBMLGG_exp_HiSeqV2', '_GENOMIC_ID_TCGA_GBMLGG_PDMarrayCNV', '_GENOMIC_ID_TCGA_GBMLGG_mutation', '_GENOMIC_ID_TCGA_GBMLGG_hMethyl450', '_GENOMIC_ID_TCGA_GBMLGG_PDMarray', '_GENOMIC_ID_TCGA_GBMLGG_gistic2', '_GENOMIC_ID_TCGA_GBMLGG_PDMRNAseq', '_GENOMIC_ID_TCGA_GBMLGG_exp_HiSeqV2_PANCAN', '_GENOMIC_ID_TCGA_GBMLGG_PDMRNAseqCNV', '_GENOMIC_ID_TCGA_GBMLGG_gistic2thd', '_GENOMIC_ID_TCGA_GBMLGG_exp_HiSeqV2_exon']\n"
]
},
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n",
"\n",
"# Step 1: Look for directories related to Anxiety disorder\n",
"tcga_subdirs = os.listdir(tcga_root_dir)\n",
"print(f\"Available TCGA subdirectories: {tcga_subdirs}\")\n",
"\n",
"# Look for directory related to Anxiety disorder\n",
"# Anxiety disorder might be found as a comorbidity in neurological or brain-related cancers\n",
"# Examine if any directories might contain data relevant to anxiety disorders\n",
"\n",
"# While anxiety is common in cancer patients, it's not a primary cancer type\n",
"# After reviewing all subdirectories, we need to determine if any datasets might contain \n",
"# anxiety-related clinical information\n",
"\n",
"# For this analysis, we'll use the brain cancer datasets as they may be more likely to \n",
"# contain psychiatric comorbidity data\n",
"potential_matches = [\n",
" 'TCGA_Glioblastoma_(GBM)',\n",
" 'TCGA_Lower_Grade_Glioma_(LGG)',\n",
" 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)'\n",
"]\n",
"\n",
"# Select the most comprehensive dataset from potential matches\n",
"target_dir = 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)'\n",
"target_path = os.path.join(tcga_root_dir, target_dir)\n",
"\n",
"print(f\"Selected directory: {target_dir} - this dataset may contain clinical information about psychiatric conditions including anxiety\")\n",
"\n",
"# Step 2: Get the clinical and genetic data file paths\n",
"clinical_path, genetic_path = tcga_get_relevant_filepaths(target_path)\n",
"\n",
"# Step 3: Load the datasets\n",
"clinical_df = pd.read_csv(clinical_path, sep='\\t', index_col=0)\n",
"genetic_df = pd.read_csv(genetic_path, sep='\\t', index_col=0)\n",
"\n",
"# Step 4: Print column names of clinical data\n",
"print(\"\\nClinical data columns:\")\n",
"print(clinical_df.columns.tolist())\n",
"\n",
"# Check if we have both gene data and potential trait data\n",
"has_gene_data = not genetic_df.empty\n",
"has_potential_trait_data = not clinical_df.empty\n",
"\n",
"# Record our initial assessment\n",
"validate_and_save_cohort_info(\n",
" is_final=False, \n",
" cohort=\"TCGA\", \n",
" info_path=json_path, \n",
" is_gene_available=has_gene_data, \n",
" is_trait_available=has_potential_trait_data\n",
")\n"
]
},
{
"cell_type": "markdown",
"id": "d7241c54",
"metadata": {},
"source": [
"### Step 2: Find Candidate Demographic Features"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a7a14e08",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:32:18.598815Z",
"iopub.status.busy": "2025-03-25T06:32:18.598670Z",
"iopub.status.idle": "2025-03-25T06:32:18.613769Z",
"shell.execute_reply": "2025-03-25T06:32:18.613461Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Age columns preview:\n",
"{'age_at_initial_pathologic_diagnosis': [44.0, 50.0, 59.0, 56.0, 40.0], 'days_to_birth': [-16179.0, -18341.0, -21617.0, -20516.0, -14806.0], 'first_diagnosis_age_asth_ecz_hay_fev_mold_dust': [nan, nan, nan, nan, nan], 'first_diagnosis_age_of_animal_insect_allergy': [nan, nan, nan, nan, nan], 'first_diagnosis_age_of_food_allergy': [nan, nan, nan, nan, nan]}\n",
"\n",
"Gender columns preview:\n",
"{'gender': ['FEMALE', 'MALE', 'MALE', 'FEMALE', 'FEMALE']}\n"
]
}
],
"source": [
"# Identify candidate age and gender columns\n",
"candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'days_to_birth', 'first_diagnosis_age_asth_ecz_hay_fev_mold_dust', \n",
" 'first_diagnosis_age_of_animal_insect_allergy', 'first_diagnosis_age_of_food_allergy']\n",
"candidate_gender_cols = ['gender']\n",
"\n",
"# Get the first TCGA dataset from the directory to examine the candidates\n",
"cohort_dir = os.path.join(tcga_root_dir, 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)')\n",
"clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)\n",
"\n",
"# Load the clinical data\n",
"clinical_df = pd.read_csv(clinical_file_path, sep='\\t', index_col=0)\n",
"\n",
"# Extract and preview age columns\n",
"age_preview = {}\n",
"if candidate_age_cols:\n",
" for col in candidate_age_cols:\n",
" if col in clinical_df.columns:\n",
" age_preview[col] = clinical_df[col].head(5).tolist()\n",
"\n",
"# Extract and preview gender columns\n",
"gender_preview = {}\n",
"if candidate_gender_cols:\n",
" for col in candidate_gender_cols:\n",
" if col in clinical_df.columns:\n",
" gender_preview[col] = clinical_df[col].head(5).tolist()\n",
"\n",
"print(\"Age columns preview:\")\n",
"print(age_preview)\n",
"print(\"\\nGender columns preview:\")\n",
"print(gender_preview)\n"
]
},
{
"cell_type": "markdown",
"id": "2c04f702",
"metadata": {},
"source": [
"### Step 3: Select Demographic Features"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bfe8d56c",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:32:18.615546Z",
"iopub.status.busy": "2025-03-25T06:32:18.615410Z",
"iopub.status.idle": "2025-03-25T06:32:18.618707Z",
"shell.execute_reply": "2025-03-25T06:32:18.618419Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Selected age column: age_at_initial_pathologic_diagnosis\n",
"Selected gender column: gender\n"
]
}
],
"source": [
"# Selecting the most appropriate age column\n",
"age_columns = {\n",
" 'age_at_initial_pathologic_diagnosis': [44.0, 50.0, 59.0, 56.0, 40.0], \n",
" 'days_to_birth': [-16179.0, -18341.0, -21617.0, -20516.0, -14806.0], \n",
" 'first_diagnosis_age_asth_ecz_hay_fev_mold_dust': [float('nan'), float('nan'), float('nan'), float('nan'), float('nan')], \n",
" 'first_diagnosis_age_of_animal_insect_allergy': [float('nan'), float('nan'), float('nan'), float('nan'), float('nan')], \n",
" 'first_diagnosis_age_of_food_allergy': [float('nan'), float('nan'), float('nan'), float('nan'), float('nan')]\n",
"}\n",
"\n",
"# 'age_at_initial_pathologic_diagnosis' has meaningful values with no missing values\n",
"age_col = 'age_at_initial_pathologic_diagnosis'\n",
"\n",
"# Selecting the most appropriate gender column\n",
"gender_columns = {\n",
" 'gender': ['FEMALE', 'MALE', 'MALE', 'FEMALE', 'FEMALE']\n",
"}\n",
"\n",
"# 'gender' is the only column and has meaningful values\n",
"gender_col = 'gender'\n",
"\n",
"# Print the chosen columns\n",
"print(f\"Selected age column: {age_col}\")\n",
"print(f\"Selected gender column: {gender_col}\")\n"
]
},
{
"cell_type": "markdown",
"id": "487f8c4d",
"metadata": {},
"source": [
"### Step 4: Feature Engineering and Validation"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "4122ad33",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:32:18.620290Z",
"iopub.status.busy": "2025-03-25T06:32:18.620184Z",
"iopub.status.idle": "2025-03-25T06:32:20.152807Z",
"shell.execute_reply": "2025-03-25T06:32:20.152354Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Potential anxiety-related columns: ['mental_status_changes']\n",
"Other potentially relevant columns: ['mental_status_changes', 'seizure_history', 'headache_history']\n",
"\n",
"Values in mental_status_changes:\n",
"mental_status_changes\n",
"NO 353\n",
"YES 120\n",
"Name: count, dtype: int64\n",
"\n",
"Values in seizure_history:\n",
"seizure_history\n",
"YES 311\n",
"NO 183\n",
"Name: count, dtype: int64\n",
"\n",
"Values in headache_history:\n",
"headache_history\n",
"NO 302\n",
"YES 177\n",
"Name: count, dtype: int64\n",
"\n",
"No direct anxiety disorder indicator found in the TCGA dataset\n",
"Dataset usability status: False\n",
"Processing completed. No data saved as anxiety disorder information is not available in TCGA datasets.\n"
]
}
],
"source": [
"# Step 1: Extract and standardize the clinical features\n",
"# Get file paths - use the brain cancer dataset identified earlier\n",
"cohort_dir = os.path.join(tcga_root_dir, 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)')\n",
"clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)\n",
"\n",
"# Load data\n",
"clinical_df = pd.read_csv(clinical_file_path, sep='\\t', index_col=0)\n",
"genetic_df = pd.read_csv(genetic_file_path, sep='\\t', index_col=0)\n",
"\n",
"# Look for any anxiety-related columns in the clinical data\n",
"anxiety_related_cols = [col for col in clinical_df.columns if any(term in col.lower() for term in \n",
" ['anxiety', 'mental', 'psychiatric', 'psychological', 'mood'])]\n",
"print(f\"Potential anxiety-related columns: {anxiety_related_cols}\")\n",
"\n",
"# Check for other columns that might indirectly relate to anxiety\n",
"other_relevant_cols = ['mental_status_changes', 'seizure_history', 'headache_history']\n",
"existing_relevant_cols = [col for col in other_relevant_cols if col in clinical_df.columns]\n",
"print(f\"Other potentially relevant columns: {existing_relevant_cols}\")\n",
"\n",
"# Examine these columns if they exist\n",
"for col in existing_relevant_cols:\n",
" print(f\"\\nValues in {col}:\")\n",
" print(clinical_df[col].value_counts())\n",
"\n",
"# While mental_status_changes exists, it's not a specific indicator of anxiety disorder\n",
"print(\"\\nNo direct anxiety disorder indicator found in the TCGA dataset\")\n",
"\n",
"# Set flags to indicate that anxiety disorder trait is not available\n",
"is_gene_available = True # We do have gene data\n",
"is_trait_available = False # But we don't have anxiety disorder data\n",
"\n",
"# Validate and save this information - use is_final=False since we're just recording unavailability\n",
"is_usable = validate_and_save_cohort_info(\n",
" is_final=False,\n",
" cohort=\"TCGA\",\n",
" info_path=json_path,\n",
" is_gene_available=is_gene_available,\n",
" is_trait_available=is_trait_available\n",
")\n",
"\n",
"print(f\"Dataset usability status: {is_usable}\")\n",
"print(\"Processing completed. No data saved as anxiety disorder information is not available in TCGA datasets.\")"
]
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|