File size: 45,107 Bytes
58f02a5 |
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 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "197031cb",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:18:30.834728Z",
"iopub.status.busy": "2025-03-25T06:18:30.834535Z",
"iopub.status.idle": "2025-03-25T06:18:31.002182Z",
"shell.execute_reply": "2025-03-25T06:18:31.001839Z"
}
},
"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 = \"Acute_Myeloid_Leukemia\"\n",
"cohort = \"GSE235070\"\n",
"\n",
"# Input paths\n",
"in_trait_dir = \"../../input/GEO/Acute_Myeloid_Leukemia\"\n",
"in_cohort_dir = \"../../input/GEO/Acute_Myeloid_Leukemia/GSE235070\"\n",
"\n",
"# Output paths\n",
"out_data_file = \"../../output/preprocess/Acute_Myeloid_Leukemia/GSE235070.csv\"\n",
"out_gene_data_file = \"../../output/preprocess/Acute_Myeloid_Leukemia/gene_data/GSE235070.csv\"\n",
"out_clinical_data_file = \"../../output/preprocess/Acute_Myeloid_Leukemia/clinical_data/GSE235070.csv\"\n",
"json_path = \"../../output/preprocess/Acute_Myeloid_Leukemia/cohort_info.json\"\n"
]
},
{
"cell_type": "markdown",
"id": "efa49416",
"metadata": {},
"source": [
"### Step 1: Initial Data Loading"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3cc7c5ae",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:18:31.003603Z",
"iopub.status.busy": "2025-03-25T06:18:31.003460Z",
"iopub.status.idle": "2025-03-25T06:18:31.050153Z",
"shell.execute_reply": "2025-03-25T06:18:31.049855Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Background Information:\n",
"!Series_title\t\"Ferritinophagy is a Druggable Vulnerability of Quiescent Leukemic Stem Cells\"\n",
"!Series_summary\t\"This SuperSeries is composed of the SubSeries listed below.\"\n",
"!Series_overall_design\t\"Refer to individual Series\"\n",
"Sample Characteristics Dictionary:\n",
"{0: ['disease state: patient with AML']}\n"
]
}
],
"source": [
"from tools.preprocess import *\n",
"# 1. Identify the paths to the SOFT file and the matrix file\n",
"soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
"\n",
"# 2. Read the matrix file to obtain background information and sample characteristics data\n",
"background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']\n",
"clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']\n",
"background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)\n",
"\n",
"# 3. Obtain the sample characteristics dictionary from the clinical dataframe\n",
"sample_characteristics_dict = get_unique_values_by_row(clinical_data)\n",
"\n",
"# 4. Explicitly print out all the background information and the sample characteristics dictionary\n",
"print(\"Background Information:\")\n",
"print(background_info)\n",
"print(\"Sample Characteristics Dictionary:\")\n",
"print(sample_characteristics_dict)\n"
]
},
{
"cell_type": "markdown",
"id": "574fa913",
"metadata": {},
"source": [
"### Step 2: Dataset Analysis and Clinical Feature Extraction"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f655195c",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:18:31.051176Z",
"iopub.status.busy": "2025-03-25T06:18:31.051072Z",
"iopub.status.idle": "2025-03-25T06:18:31.059996Z",
"shell.execute_reply": "2025-03-25T06:18:31.059719Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Preview of selected clinical features:\n",
"{'GSM7494217': [1.0], 'GSM7494218': [1.0], 'GSM7494219': [1.0], 'GSM7494220': [1.0], 'GSM7494221': [1.0], 'GSM7494222': [1.0], 'GSM7494223': [1.0], 'GSM7494224': [1.0], 'GSM7494249': [1.0], 'GSM7494250': [1.0], 'GSM7494251': [1.0], 'GSM7494252': [1.0], 'GSM7494253': [1.0], 'GSM7494254': [1.0], 'GSM7494255': [1.0], 'GSM7494256': [1.0], 'GSM7494509': [1.0], 'GSM7494510': [1.0], 'GSM7494511': [1.0], 'GSM7494512': [1.0], 'GSM7494513': [1.0], 'GSM7494514': [1.0], 'GSM7494515': [1.0], 'GSM7494516': [1.0], 'GSM7494517': [1.0], 'GSM7494518': [1.0], 'GSM7494519': [1.0], 'GSM7494520': [1.0], 'GSM7494521': [1.0], 'GSM7494522': [1.0], 'GSM7494523': [1.0], 'GSM7494524': [1.0]}\n",
"Clinical data saved to ../../output/preprocess/Acute_Myeloid_Leukemia/clinical_data/GSE235070.csv\n"
]
}
],
"source": [
"import pandas as pd\n",
"import os\n",
"import json\n",
"import numpy as np\n",
"from typing import Optional, Callable, Dict, Any, List\n",
"\n",
"# 1. Gene Expression Data Availability\n",
"# Based on the background information, this appears to be primarily about leukemic stem cells.\n",
"# However, without more specific information about the data structure, we should be cautious.\n",
"is_gene_available = True # Assuming gene expression data is available for AML studies\n",
"\n",
"# 2. Variable Availability and Data Type Conversion\n",
"# 2.1 Data Availability\n",
"trait_row = 0 # The dataset has AML disease state information (row 0)\n",
"age_row = None # Age information is not provided in the sample characteristics\n",
"gender_row = None # Gender information is not provided in the sample characteristics\n",
"\n",
"# 2.2 Data Type Conversion Functions\n",
"def convert_trait(value):\n",
" \"\"\"Convert AML trait value to binary (1 = has AML, 0 = control)\"\"\"\n",
" if value is None:\n",
" return None\n",
" \n",
" # Extract the value part (after colon if present)\n",
" if isinstance(value, str) and ':' in value:\n",
" value = value.split(':', 1)[1].strip()\n",
" \n",
" # Check if the value indicates AML\n",
" if 'AML' in value.upper() or 'ACUTE MYELOID LEUKEMIA' in value.upper() or 'patient' in value.lower():\n",
" return 1\n",
" elif 'control' in value.lower() or 'healthy' in value.lower() or 'normal' in value.lower():\n",
" return 0\n",
" else:\n",
" return None\n",
"\n",
"def convert_age(value):\n",
" \"\"\"Convert age to numerical value\"\"\"\n",
" # This function is included for completeness, but age data is not available\n",
" if value is None:\n",
" return None\n",
" \n",
" # Extract the value part (after colon if present)\n",
" if isinstance(value, str) and ':' in value:\n",
" value = value.split(':', 1)[1].strip()\n",
" \n",
" # Try to extract numerical age\n",
" try:\n",
" # Extract digits if embedded in text\n",
" import re\n",
" age_match = re.search(r'(\\d+)', value)\n",
" if age_match:\n",
" return float(age_match.group(1))\n",
" return float(value)\n",
" except (ValueError, TypeError):\n",
" return None\n",
"\n",
"def convert_gender(value):\n",
" \"\"\"Convert gender to binary (0 = female, 1 = male)\"\"\"\n",
" # This function is included for completeness, but gender data is not available\n",
" if value is None:\n",
" return None\n",
" \n",
" # Extract the value part (after colon if present)\n",
" if isinstance(value, str) and ':' in value:\n",
" value = value.split(':', 1)[1].strip().lower()\n",
" \n",
" if isinstance(value, str):\n",
" value = value.lower()\n",
" if 'female' in value or 'f' == value:\n",
" return 0\n",
" elif 'male' in value or 'm' == value:\n",
" return 1\n",
" \n",
" return None\n",
"\n",
"# 3. Save Metadata - Initial filtering\n",
"is_trait_available = trait_row is not None\n",
"validate_and_save_cohort_info(\n",
" is_final=False,\n",
" cohort=cohort,\n",
" info_path=json_path,\n",
" is_gene_available=is_gene_available,\n",
" is_trait_available=is_trait_available\n",
")\n",
"\n",
"# 4. Clinical Feature Extraction\n",
"if trait_row is not None:\n",
" # Assuming clinical_data is available from previous steps\n",
" try:\n",
" # Check if clinical_data is available\n",
" if 'clinical_data' in locals() or 'clinical_data' in globals():\n",
" # Extract clinical features\n",
" selected_clinical_df = geo_select_clinical_features(\n",
" clinical_df=clinical_data,\n",
" trait=trait,\n",
" trait_row=trait_row,\n",
" convert_trait=convert_trait,\n",
" age_row=age_row,\n",
" convert_age=convert_age if age_row is not None else None,\n",
" gender_row=gender_row,\n",
" convert_gender=convert_gender if gender_row is not None else None\n",
" )\n",
" \n",
" # Preview the extracted clinical features\n",
" preview = preview_df(selected_clinical_df)\n",
" print(\"Preview of selected clinical features:\")\n",
" print(preview)\n",
" \n",
" # Create directory if it doesn't exist\n",
" os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n",
" \n",
" # Save the extracted clinical features\n",
" selected_clinical_df.to_csv(out_clinical_data_file, index=False)\n",
" print(f\"Clinical data saved to {out_clinical_data_file}\")\n",
" else:\n",
" print(\"Clinical data not available from previous steps\")\n",
" except NameError:\n",
" print(\"Clinical data not available from previous steps\")\n",
"else:\n",
" print(\"Trait data not available, skipping clinical feature extraction\")\n"
]
},
{
"cell_type": "markdown",
"id": "24f3e36d",
"metadata": {},
"source": [
"### Step 3: Gene Data Extraction"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ad267703",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:18:31.060961Z",
"iopub.status.busy": "2025-03-25T06:18:31.060858Z",
"iopub.status.idle": "2025-03-25T06:18:31.124991Z",
"shell.execute_reply": "2025-03-25T06:18:31.124668Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['TC0100006437.hg.1', 'TC0100006476.hg.1', 'TC0100006479.hg.1',\n",
" 'TC0100006480.hg.1', 'TC0100006483.hg.1', 'TC0100006486.hg.1',\n",
" 'TC0100006490.hg.1', 'TC0100006492.hg.1', 'TC0100006494.hg.1',\n",
" 'TC0100006497.hg.1', 'TC0100006499.hg.1', 'TC0100006501.hg.1',\n",
" 'TC0100006502.hg.1', 'TC0100006514.hg.1', 'TC0100006516.hg.1',\n",
" 'TC0100006517.hg.1', 'TC0100006524.hg.1', 'TC0100006540.hg.1',\n",
" 'TC0100006548.hg.1', 'TC0100006550.hg.1'],\n",
" dtype='object', name='ID')\n"
]
}
],
"source": [
"# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.\n",
"gene_data = get_genetic_data(matrix_file)\n",
"\n",
"# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.\n",
"print(gene_data.index[:20])\n"
]
},
{
"cell_type": "markdown",
"id": "869602a5",
"metadata": {},
"source": [
"### Step 4: Gene Identifier Review"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "4045d6af",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:18:31.126184Z",
"iopub.status.busy": "2025-03-25T06:18:31.126074Z",
"iopub.status.idle": "2025-03-25T06:18:31.127870Z",
"shell.execute_reply": "2025-03-25T06:18:31.127599Z"
}
},
"outputs": [],
"source": [
"# These identifiers \"TC0100006437.hg.1\" appear to be Affymetrix transcript cluster IDs \n",
"# from a microarray platform, not standard human gene symbols.\n",
"# They need to be mapped to human gene symbols for better interpretability and consistency.\n",
"\n",
"requires_gene_mapping = True\n"
]
},
{
"cell_type": "markdown",
"id": "58b6a7d6",
"metadata": {},
"source": [
"### Step 5: Gene Annotation"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "470c22fa",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:18:31.128842Z",
"iopub.status.busy": "2025-03-25T06:18:31.128743Z",
"iopub.status.idle": "2025-03-25T06:18:33.030702Z",
"shell.execute_reply": "2025-03-25T06:18:33.030327Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gene annotation preview:\n",
"{'ID': ['TC0100006437.hg.1', 'TC0100006476.hg.1', 'TC0100006479.hg.1', 'TC0100006480.hg.1', 'TC0100006483.hg.1'], 'probeset_id': ['TC0100006437.hg.1', 'TC0100006476.hg.1', 'TC0100006479.hg.1', 'TC0100006480.hg.1', 'TC0100006483.hg.1'], 'seqname': ['chr1', 'chr1', 'chr1', 'chr1', 'chr1'], 'strand': ['+', '+', '+', '+', '+'], 'start': ['69091', '924880', '960587', '966497', '1001138'], 'stop': ['70008', '944581', '965719', '975865', '1014541'], 'total_probes': [10.0, 10.0, 10.0, 10.0, 10.0], 'category': ['main', 'main', 'main', 'main', 'main'], 'SPOT_ID': ['Coding', 'Multiple_Complex', 'Multiple_Complex', 'Multiple_Complex', 'Multiple_Complex'], 'SPOT_ID.1': ['NM_001005484 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000335137 // ENSEMBL // olfactory receptor, family 4, subfamily F, member 5 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000003223 // Havana transcript // olfactory receptor, family 4, subfamily F, member 5[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aal.1 // UCSC Genes // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS30547.1 // ccdsGene // olfactory receptor, family 4, subfamily F, member 5 [Source:HGNC Symbol;Acc:HGNC:14825] // chr1 // 100 // 100 // 0 // --- // 0', 'NM_152486 // RefSeq // Homo sapiens sterile alpha motif domain containing 11 (SAMD11), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000341065 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000342066 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000420190 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000437963 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000455979 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000464948 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000466827 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000474461 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000478729 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:processed_transcript] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000616016 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000616125 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000617307 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618181 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618323 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618779 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000620200 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000622503 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC024295 // GenBank // Homo sapiens sterile alpha motif domain containing 11, mRNA (cDNA clone MGC:39333 IMAGE:3354502), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// BC033213 // GenBank // Homo sapiens sterile alpha motif domain containing 11, mRNA (cDNA clone MGC:45873 IMAGE:5014368), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097860 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097862 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097863 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097865 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:processed_transcript] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097866 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097867 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097868 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000276866 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000316521 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS2.2 // ccdsGene // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009185 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009186 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009187 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009188 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009189 // circbase // Salzman2013 ALT_DONOR, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009190 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009191 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009192 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009193 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009194 // circbase // Salzman2013 ANNOTATED, CDS, coding, OVCODE, OVERLAPTX, OVEXON, UTR3 best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009195 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001abw.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pjt.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pju.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkg.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkh.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkk.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkm.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pko.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axs.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axt.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axu.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axv.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axw.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axx.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axy.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axz.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057aya.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000212 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000212 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000213 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000213 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_198317 // RefSeq // Homo sapiens kelch-like family member 17 (KLHL17), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000338591 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000463212 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000466300 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:nonsense_mediated_decay] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000481067 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000622660 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097875 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097877 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097878 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:nonsense_mediated_decay] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097931 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// BC166618 // GenBank // Synthetic construct Homo sapiens clone IMAGE:100066344, MGC:195481 kelch-like 17 (Drosophila) (KLHL17) mRNA, encodes complete protein. // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS30550.1 // ccdsGene // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009209 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_198317 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aca.3 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acb.2 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayg.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayh.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayi.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayj.1 // UCSC Genes // N/A // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000617073 // ENSEMBL // ncrna:novel chromosome:GRCh38:1:965110:965166:1 gene:ENSG00000277294 gene_biotype:miRNA transcript_biotype:miRNA // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000216 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000216 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_001160184 // RefSeq // Homo sapiens pleckstrin homology domain containing, family N member 1 (PLEKHN1), transcript variant 2, mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// NM_032129 // RefSeq // Homo sapiens pleckstrin homology domain containing, family N member 1 (PLEKHN1), transcript variant 1, mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379407 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379409 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379410 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000480267 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000491024 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC101386 // GenBank // Homo sapiens pleckstrin homology domain containing, family N member 1, mRNA (cDNA clone MGC:120613 IMAGE:40026400), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// BC101387 // GenBank // Homo sapiens pleckstrin homology domain containing, family N member 1, mRNA (cDNA clone MGC:120616 IMAGE:40026404), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097940 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097941 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097942 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000473255 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000473256 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS4.1 // ccdsGene // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS53256.1 // ccdsGene // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// PLEKHN1.aAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 84069 // chr1 // 100 // 100 // 0 // --- // 0 /// PLEKHN1.bAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 84069, RefSeq ID(s) NM_032129 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acd.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001ace.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acf.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayk.1 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayl.1 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000217 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000217 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_005101 // RefSeq // Homo sapiens ISG15 ubiquitin-like modifier (ISG15), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379389 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000624652 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000624697 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC009507 // GenBank // Homo sapiens ISG15 ubiquitin-like modifier, mRNA (cDNA clone MGC:3945 IMAGE:3545944), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097989 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000479384 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000479385 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS6.1 // ccdsGene // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009211 // circbase // Salzman2013 ANNOTATED, CDS, coding, OVCODE, OVEXON, UTR3 best transcript NM_005101 // chr1 // 100 // 100 // 0 // --- // 0 /// ISG15.bAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 9636 // chr1 // 100 // 100 // 0 // --- // 0 /// ISG15.cAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 9636 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acj.5 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayq.1 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayr.1 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0']}\n"
]
}
],
"source": [
"# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.\n",
"gene_annotation = get_gene_annotation(soft_file)\n",
"\n",
"# 2. Use the 'preview_df' function from the library to preview the data and print out the results.\n",
"print(\"Gene annotation preview:\")\n",
"print(preview_df(gene_annotation))\n"
]
},
{
"cell_type": "markdown",
"id": "c04d3293",
"metadata": {},
"source": [
"### Step 6: Gene Identifier Mapping"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "60741312",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:18:33.031974Z",
"iopub.status.busy": "2025-03-25T06:18:33.031855Z",
"iopub.status.idle": "2025-03-25T06:18:35.400654Z",
"shell.execute_reply": "2025-03-25T06:18:35.400197Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Original data shape (probes): 85633 genes × 32 samples\n",
"First 5 gene symbols after mapping:\n",
"Index(['A-', 'A-1', 'A-2', 'A-52', 'A-E'], dtype='object', name='Gene')\n"
]
}
],
"source": [
"# 1. Analyze the gene annotation dataframe to identify columns containing probe IDs and gene symbols\n",
"# From the preview, we can see that 'ID' matches the gene identifiers in gene_data's index (TC01... format)\n",
"# For gene symbols, we need to extract them from the 'SPOT_ID.1' column which contains transcript info\n",
"\n",
"# 2. Create the gene mapping dataframe using the appropriate columns\n",
"# ID column already matches the probe IDs\n",
"mapping_df = get_gene_mapping(gene_annotation, 'ID', 'SPOT_ID.1')\n",
"\n",
"# 3. Apply the gene mapping to convert probe-level data to gene expression data\n",
"gene_data = apply_gene_mapping(gene_data, mapping_df)\n",
"\n",
"# Print information about the mapped data\n",
"print(f\"Original data shape (probes): {len(gene_data.index)} genes × {len(gene_data.columns)} samples\")\n",
"print(\"First 5 gene symbols after mapping:\")\n",
"print(gene_data.index[:5])\n"
]
},
{
"cell_type": "markdown",
"id": "0795b6f3",
"metadata": {},
"source": [
"### Step 7: Data Normalization and Linking"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "5fe389ed",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:18:35.402168Z",
"iopub.status.busy": "2025-03-25T06:18:35.402059Z",
"iopub.status.idle": "2025-03-25T06:18:41.818178Z",
"shell.execute_reply": "2025-03-25T06:18:41.817853Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Normalized gene data saved to ../../output/preprocess/Acute_Myeloid_Leukemia/gene_data/GSE235070.csv\n",
"Clinical data shape: (1, 33)\n",
"Sample characteristics dictionary:\n",
"{0: ['disease state: patient with AML']}\n",
"Clinical data preview:\n",
"{'GSM7494217': [1.0], 'GSM7494218': [1.0], 'GSM7494219': [1.0], 'GSM7494220': [1.0], 'GSM7494221': [1.0], 'GSM7494222': [1.0], 'GSM7494223': [1.0], 'GSM7494224': [1.0], 'GSM7494249': [1.0], 'GSM7494250': [1.0], 'GSM7494251': [1.0], 'GSM7494252': [1.0], 'GSM7494253': [1.0], 'GSM7494254': [1.0], 'GSM7494255': [1.0], 'GSM7494256': [1.0], 'GSM7494509': [1.0], 'GSM7494510': [1.0], 'GSM7494511': [1.0], 'GSM7494512': [1.0], 'GSM7494513': [1.0], 'GSM7494514': [1.0], 'GSM7494515': [1.0], 'GSM7494516': [1.0], 'GSM7494517': [1.0], 'GSM7494518': [1.0], 'GSM7494519': [1.0], 'GSM7494520': [1.0], 'GSM7494521': [1.0], 'GSM7494522': [1.0], 'GSM7494523': [1.0], 'GSM7494524': [1.0]}\n",
"Clinical data saved to ../../output/preprocess/Acute_Myeloid_Leukemia/clinical_data/GSE235070.csv\n",
"Linked data shape: (32, 19976)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data shape after handling missing values: (32, 19976)\n",
"Quartiles for 'Acute_Myeloid_Leukemia':\n",
" 25%: 1.0\n",
" 50% (Median): 1.0\n",
" 75%: 1.0\n",
"Min: 1.0\n",
"Max: 1.0\n",
"The distribution of the feature 'Acute_Myeloid_Leukemia' in this dataset is severely biased.\n",
"\n",
"Dataset not usable due to bias in trait distribution. Data not saved.\n"
]
}
],
"source": [
"# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.\n",
"normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n",
"os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n",
"normalized_gene_data.to_csv(out_gene_data_file)\n",
"print(f\"Normalized gene data saved to {out_gene_data_file}\")\n",
"\n",
"# Let's first check what's actually in the clinical_data to avoid errors\n",
"print(\"Clinical data shape:\", clinical_data.shape)\n",
"print(\"Sample characteristics dictionary:\")\n",
"sample_characteristics_dict = get_unique_values_by_row(clinical_data)\n",
"print(sample_characteristics_dict)\n",
"\n",
"# Define the trait conversion function based on the actual available data\n",
"def convert_trait(value):\n",
" \"\"\"Convert AML status to binary (1 = has AML, 0 = control/healthy)\"\"\"\n",
" if value is None:\n",
" return None\n",
" \n",
" # Extract the value part (after colon if present)\n",
" if isinstance(value, str) and ':' in value:\n",
" value = value.split(':', 1)[1].strip()\n",
" \n",
" # In this dataset, all samples appear to be AML patients\n",
" if 'AML' in value.upper() or 'patient' in value.lower():\n",
" return 1\n",
" elif 'control' in value.lower() or 'healthy' in value.lower() or 'normal' in value.lower():\n",
" return 0\n",
" else:\n",
" return None\n",
"\n",
"# Use the correct row index based on the sample characteristics dictionary\n",
"trait_row = 0 # The only row available (disease state: patient with AML)\n",
"age_row = None # Age information not available\n",
"gender_row = None # Gender information not available\n",
"\n",
"# Check if clinical_data actually contains data before proceeding\n",
"if clinical_data.shape[0] > 0:\n",
" # Extract clinical features\n",
" selected_clinical_data = geo_select_clinical_features(\n",
" clinical_df=clinical_data,\n",
" trait=trait,\n",
" trait_row=trait_row,\n",
" convert_trait=convert_trait,\n",
" age_row=None,\n",
" convert_age=None,\n",
" gender_row=None,\n",
" convert_gender=None\n",
" )\n",
" \n",
" print(\"Clinical data preview:\")\n",
" print(preview_df(selected_clinical_data))\n",
" os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n",
" selected_clinical_data.to_csv(out_clinical_data_file)\n",
" print(f\"Clinical data saved to {out_clinical_data_file}\")\n",
"\n",
" # 2. Link the clinical and genetic data\n",
" linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)\n",
" print(f\"Linked data shape: {linked_data.shape}\")\n",
"\n",
" # 3. Handle missing values in the linked data\n",
" linked_data = handle_missing_values(linked_data, trait)\n",
" print(f\"Data shape after handling missing values: {linked_data.shape}\")\n",
"\n",
" # 4. Determine whether the trait and some demographic features are severely biased\n",
" is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)\n",
"\n",
" # 5. Conduct quality check and save the cohort information\n",
" note = \"Dataset contains only AML patients without controls, which may limit its utility for some analyses\"\n",
" is_usable = validate_and_save_cohort_info(\n",
" is_final=True, \n",
" cohort=cohort, \n",
" info_path=json_path, \n",
" is_gene_available=True, \n",
" is_trait_available=True, \n",
" is_biased=is_trait_biased, \n",
" df=unbiased_linked_data,\n",
" note=note\n",
" )\n",
"\n",
" # 6. If the linked data is usable, save it\n",
" if is_usable:\n",
" os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n",
" unbiased_linked_data.to_csv(out_data_file)\n",
" print(f\"Processed dataset saved to {out_data_file}\")\n",
" else:\n",
" print(\"Dataset not usable due to bias in trait distribution. Data not saved.\")\n",
"else:\n",
" print(\"No clinical data available. Cannot proceed with linking and subsequent steps.\")\n",
" # Still need to save the cohort info indicating the dataset isn't usable\n",
" validate_and_save_cohort_info(\n",
" is_final=True, \n",
" cohort=cohort, \n",
" info_path=json_path, \n",
" is_gene_available=True, \n",
" is_trait_available=False, \n",
" is_biased=None, \n",
" df=pd.DataFrame(),\n",
" note=\"Dataset doesn't contain usable clinical data for trait analysis\"\n",
" )"
]
}
],
"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
}
|