File size: 30,512 Bytes
e4183cf |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1731fd45",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:37.723056Z",
"iopub.status.busy": "2025-03-25T08:13:37.722821Z",
"iopub.status.idle": "2025-03-25T08:13:37.888276Z",
"shell.execute_reply": "2025-03-25T08:13:37.887811Z"
}
},
"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 = \"Cervical_Cancer\"\n",
"cohort = \"GSE138079\"\n",
"\n",
"# Input paths\n",
"in_trait_dir = \"../../input/GEO/Cervical_Cancer\"\n",
"in_cohort_dir = \"../../input/GEO/Cervical_Cancer/GSE138079\"\n",
"\n",
"# Output paths\n",
"out_data_file = \"../../output/preprocess/Cervical_Cancer/GSE138079.csv\"\n",
"out_gene_data_file = \"../../output/preprocess/Cervical_Cancer/gene_data/GSE138079.csv\"\n",
"out_clinical_data_file = \"../../output/preprocess/Cervical_Cancer/clinical_data/GSE138079.csv\"\n",
"json_path = \"../../output/preprocess/Cervical_Cancer/cohort_info.json\"\n"
]
},
{
"cell_type": "markdown",
"id": "2c2a4afe",
"metadata": {},
"source": [
"### Step 1: Initial Data Loading"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "1e60cb50",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:37.889704Z",
"iopub.status.busy": "2025-03-25T08:13:37.889557Z",
"iopub.status.idle": "2025-03-25T08:13:38.072504Z",
"shell.execute_reply": "2025-03-25T08:13:38.072017Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Background Information:\n",
"!Series_title\t\"Identification of deregulated pathways, key regulators, and novel miRNA-mRNA interactions in HPV-mediated transformation. [mRNA cell lines-Agilent]\"\n",
"!Series_summary\t\"Next to a persistent infection with high-risk human papillomavirus (HPV), molecular changes are required for the development of cervical cancer. To identify which molecular alterations drive carcinogenesis, we performed a comprehensive and longitudinal molecular characterization of HPV-transformed keratinocyte cell lines. Comparative genomic hybridization, mRNA, and miRNA expression analysis of four HPV-containing keratinocyte cell lines at eight different time points was performed. Data was analyzed using unsupervised hierarchical clustering, integrated longitudinal expression analysis, and pathway enrichment analysis. Biological relevance of identified key regulatory genes was evaluated in vitro and dual-luciferase assays were used to confirm predicted miRNA-mRNA interactions. We show that the acquisition of anchorage independence of HPV-containing keratinocyte cell lines is particularly associated with copy number alterations. Approximately one third of differentially expressed mRNAs and miRNAs was directly attributable to copy number alterations. Focal adhesion, TGF-beta signaling, and mTOR signaling pathways were enriched among these genes. PITX2 was identified as key regulator of TGF-beta signaling and inhibited cell growth in vitro, most likely by inducing cell cycle arrest and apoptosis. Predicted miRNA-mRNA interactions miR-221-3p_BRWD3, miR-221-3p_FOS, and miR-138-5p_PLXNB2 were confirmed in vitro. Integrated longitudinal analysis of our HPV-induced carcinogenesis model pinpointed relevant interconnected molecular changes and crucial signaling pathways in HPV-mediated transformation.\"\n",
"!Series_overall_design\t\"Expression profiles of 8 sequential passages of 4 HPV-transformed human foreskin primary keratinocyte cell lines either treated with or without demethylation agent DAC were analyzed using whole human genome oligo microarrays (G4112A, mRNA 4x44K; Agilent).\"\n",
"Sample Characteristics Dictionary:\n",
"{0: ['cell type: primary human foreskin keratinocytes transfected with HPV16', 'cell type: primary human foreskin keratinocytes transfected with HPV18'], 1: ['transformation stage: immortal', 'transformation stage: anchorage independent', 'transformation stage: extended lifespan'], 2: ['timepoint: timepoint 1', 'timepoint: timepoint 2', 'timepoint: timepoint 3', 'timepoint: timepoint 4', 'timepoint: timepoint 5', 'timepoint: timepoint 6', 'timepoint: timepoint 7', 'timepoint: timepoint 8'], 3: ['treatment: no treatment', 'treatment: 5000 nM 5-aza-2’-deoxycytidine (DAC)']}\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": "e515f670",
"metadata": {},
"source": [
"### Step 2: Dataset Analysis and Clinical Feature Extraction"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8a08dba2",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:38.073938Z",
"iopub.status.busy": "2025-03-25T08:13:38.073829Z",
"iopub.status.idle": "2025-03-25T08:13:38.079980Z",
"shell.execute_reply": "2025-03-25T08:13:38.079618Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"import os\n",
"import json\n",
"from typing import Callable, Dict, Any, Optional\n",
"\n",
"# 1. Gene Expression Data Availability\n",
"# Based on the Series_title and Series_summary, this data contains mRNA microarray data from Agilent\n",
"is_gene_available = True\n",
"\n",
"# 2. Variable Availability and Data Type Conversion\n",
"\n",
"# 2.1 Data Availability\n",
"# For trait: The \"transformation stage\" in index 1 indicates different stages of cancer development\n",
"trait_row = 1\n",
"\n",
"# For age: Not available in the sample characteristics\n",
"age_row = None\n",
"\n",
"# For gender: Not explicitly available, but this is from male foreskin samples\n",
"gender_row = None\n",
"\n",
"# 2.2 Data Type Conversion Functions\n",
"def convert_trait(value: str) -> int:\n",
" \"\"\"Convert transformation stage to binary: 1 for anchorage independent (more advanced cancer stage), 0 otherwise.\"\"\"\n",
" if isinstance(value, str):\n",
" # Extract the value after colon\n",
" if ':' in value:\n",
" value = value.split(':', 1)[1].strip()\n",
" \n",
" # Binary classification based on transformation stage\n",
" if 'anchorage independent' in value.lower():\n",
" return 1 # Advanced transformation stage\n",
" elif 'immortal' in value.lower() or 'extended lifespan' in value.lower():\n",
" return 0 # Earlier transformation stage\n",
" return None\n",
"\n",
"def convert_age(value: str) -> Optional[float]:\n",
" \"\"\"Convert age to continuous value.\"\"\"\n",
" # Not used as age is not available\n",
" return None\n",
"\n",
"def convert_gender(value: str) -> Optional[int]:\n",
" \"\"\"Convert gender to binary (0 for female, 1 for male).\"\"\"\n",
" # Not used as gender is not explicitly available\n",
" return None\n",
"\n",
"# 3. Save Metadata\n",
"# trait_row is not None, meaning trait data is available\n",
"is_trait_available = trait_row is not None\n",
"\n",
"# Initial filtering on usability\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",
"# Since this is a cell line study and not a human cohort study, and we don't have \n",
"# access to the clinical_data variable from a previous step, we'll skip the clinical \n",
"# feature extraction step for now. The trait information would need to be processed \n",
"# when we have access to the actual data.\n"
]
},
{
"cell_type": "markdown",
"id": "26c53110",
"metadata": {},
"source": [
"### Step 3: Gene Data Extraction"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c3e863d5",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:38.081210Z",
"iopub.status.busy": "2025-03-25T08:13:38.081106Z",
"iopub.status.idle": "2025-03-25T08:13:38.359188Z",
"shell.execute_reply": "2025-03-25T08:13:38.358548Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23',\n",
" '24', '25', '26', '27', '28', '29', '30', '31'],\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": "db9f686c",
"metadata": {},
"source": [
"### Step 4: Gene Identifier Review"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "560f2027",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:38.360971Z",
"iopub.status.busy": "2025-03-25T08:13:38.360850Z",
"iopub.status.idle": "2025-03-25T08:13:38.363266Z",
"shell.execute_reply": "2025-03-25T08:13:38.362826Z"
}
},
"outputs": [],
"source": [
"# Looking at the gene identifiers, these appear to be numerical identifiers (12, 13, 14, etc.)\n",
"# rather than human gene symbols like BRCA1, TP53, etc.\n",
"# These are likely probe IDs or array-specific identifiers that need to be mapped to gene symbols\n",
"\n",
"requires_gene_mapping = True\n"
]
},
{
"cell_type": "markdown",
"id": "b8281f79",
"metadata": {},
"source": [
"### Step 5: Gene Annotation"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "f950ad5d",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:38.364842Z",
"iopub.status.busy": "2025-03-25T08:13:38.364737Z",
"iopub.status.idle": "2025-03-25T08:13:42.580336Z",
"shell.execute_reply": "2025-03-25T08:13:42.579687Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gene annotation preview:\n",
"{'ID': ['1', '2', '3', '4', '5'], 'COL': ['266', '266', '266', '266', '266'], 'ROW': [170.0, 168.0, 166.0, 164.0, 162.0], 'NAME': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner'], 'SPOT_ID': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner'], 'CONTROL_TYPE': ['pos', 'pos', 'pos', 'pos', 'pos'], 'REFSEQ': [nan, nan, nan, nan, nan], 'GB_ACC': [nan, nan, nan, nan, nan], 'GENE': [nan, nan, nan, nan, nan], 'GENE_SYMBOL': [nan, nan, nan, nan, nan], 'GENE_NAME': [nan, nan, nan, nan, nan], 'UNIGENE_ID': [nan, nan, nan, nan, nan], 'ENSEMBL_ID': [nan, nan, nan, nan, nan], 'TIGR_ID': [nan, nan, nan, nan, nan], 'ACCESSION_STRING': [nan, nan, nan, nan, nan], 'CHROMOSOMAL_LOCATION': [nan, nan, nan, nan, nan], 'CYTOBAND': [nan, nan, nan, nan, nan], 'DESCRIPTION': [nan, nan, nan, nan, nan], 'GO_ID': [nan, nan, nan, nan, nan], 'SEQUENCE': [nan, nan, nan, nan, nan], 'SPOT_ID.1': [nan, nan, nan, nan, nan], 'ORDER': [1.0, 2.0, 3.0, 4.0, 5.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": "598beb17",
"metadata": {},
"source": [
"### Step 6: Gene Identifier Mapping"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "606ad1ac",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:42.582174Z",
"iopub.status.busy": "2025-03-25T08:13:42.582052Z",
"iopub.status.idle": "2025-03-25T08:13:42.921531Z",
"shell.execute_reply": "2025-03-25T08:13:42.920857Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Available columns in gene annotation:\n",
"['ID', 'COL', 'ROW', 'NAME', 'SPOT_ID', 'CONTROL_TYPE', 'REFSEQ', 'GB_ACC', 'GENE', 'GENE_SYMBOL', 'GENE_NAME', 'UNIGENE_ID', 'ENSEMBL_ID', 'TIGR_ID', 'ACCESSION_STRING', 'CHROMOSOMAL_LOCATION', 'CYTOBAND', 'DESCRIPTION', 'GO_ID', 'SEQUENCE', 'SPOT_ID.1', 'ORDER']\n",
"\n",
"Sample of gene annotation data with non-null gene symbols:\n",
"{'ID': ['12', '14', '15', '16', '18'], 'COL': ['266', '266', '266', '266', '266'], 'ROW': [148.0, 144.0, 142.0, 140.0, 136.0], 'NAME': ['A_24_P66027', 'A_23_P212522', 'A_24_P934473', 'A_24_P9671', 'A_24_P801451'], 'SPOT_ID': ['A_24_P66027', 'A_23_P212522', 'A_24_P934473', 'A_24_P9671', 'A_24_P801451'], 'CONTROL_TYPE': ['FALSE', 'FALSE', 'FALSE', 'FALSE', 'FALSE'], 'REFSEQ': ['NM_004900', 'NM_014616', nan, 'NM_001539', 'NM_006709'], 'GB_ACC': ['NM_004900', 'NM_014616', 'AK092846', 'NM_001539', 'NM_006709'], 'GENE': [9582.0, 23200.0, 100132006.0, 3301.0, 10919.0], 'GENE_SYMBOL': ['APOBEC3B', 'ATP11B', 'LOC100132006', 'DNAJA1', 'EHMT2'], 'GENE_NAME': ['apolipoprotein B mRNA editing enzyme, catalytic polypeptide-like 3B', 'ATPase, class VI, type 11B', 'hypothetical protein LOC100132006', 'DnaJ (Hsp40) homolog, subfamily A, member 1', 'euchromatic histone-lysine N-methyltransferase 2'], 'UNIGENE_ID': ['Hs.226307', 'Hs.478429', 'Hs.593666', 'Hs.445203', 'Hs.709218'], 'ENSEMBL_ID': ['ENST00000407298', 'ENST00000323116', nan, 'ENST00000330899', 'ENST00000375537'], 'TIGR_ID': ['NP075413', 'THC2580543', 'THC2483825', 'THC2482967', 'THC2496448'], 'ACCESSION_STRING': ['ref|NM_004900|ref|NM_145699|ens|ENST00000407298|ens|ENST00000333467', 'ref|NM_014616|ens|ENST00000323116|gb|AB023173|gb|AL133061', 'gb|AK092846|gb|AX747763|thc|THC2483825', 'ref|NM_001539|gb|AY186741|ens|ENST00000330899|gb|BT007292', 'ref|NM_006709|ref|NM_025256|gb|BC018718|ens|ENST00000375537'], 'CHROMOSOMAL_LOCATION': ['chr22:37717484-37717543', 'chr3:184121316-184121375', 'chr16:8649039-8649098', 'chr9:33026682-33027066', 'unmapped'], 'CYTOBAND': ['hs|22q13.1', 'hs|3q26.33', 'hs|16p13.2', 'hs|9p13.3', nan], 'DESCRIPTION': ['Homo sapiens apolipoprotein B mRNA editing enzyme, catalytic polypeptide-like 3B (APOBEC3B), mRNA [NM_004900]', 'Homo sapiens ATPase, class VI, type 11B (ATP11B), mRNA [NM_014616]', 'Homo sapiens cDNA FLJ35527 fis, clone SPLEN2001781. [AK092846]', 'Homo sapiens DnaJ (Hsp40) homolog, subfamily A, member 1 (DNAJA1), mRNA [NM_001539]', 'Homo sapiens euchromatic histone-lysine N-methyltransferase 2 (EHMT2), transcript variant NG36/G9a, mRNA [NM_006709]'], 'GO_ID': ['GO:0003723(RNA binding)|GO:0005575(cellular_component)|GO:0008150(biological_process)|GO:0008270(zinc ion binding)|GO:0016787(hydrolase activity)|GO:0016814(hydrolase activity, acting on carbon-nitrogen (but not peptide) bonds, in cyclic amidines)|GO:0046872(metal ion binding)', 'GO:0000166(nucleotide binding)|GO:0000287(magnesium ion binding)|GO:0004012(phospholipid-translocating ATPase activity)|GO:0005524(ATP binding)|GO:0005637(nuclear inner membrane)|GO:0006754(ATP biosynthetic process)|GO:0006811(ion transport)|GO:0008152(metabolic process)|GO:0015075(ion transmembrane transporter activity)|GO:0015662(ATPase activity, coupled to transmembrane movement of ions, phosphorylative mechanism)|GO:0015914(phospholipid transport)|GO:0015917(aminophospholipid transport)|GO:0016020(membrane)|GO:0016021(integral to membrane)|GO:0016787(hydrolase activity)|GO:0016820(hydrolase activity, acting on acid anhydrides, catalyzing transmembrane movement of substances)', nan, 'GO:0005737(cytoplasm)|GO:0005856(cytoskeleton)|GO:0006457(protein folding)|GO:0006986(response to unfolded protein)|GO:0007283(spermatogenesis)|GO:0008270(zinc ion binding)|GO:0016020(membrane)|GO:0030317(sperm motility)|GO:0030521(androgen receptor signaling pathway)|GO:0031072(heat shock protein binding)|GO:0046872(metal ion binding)|GO:0050750(low-density lipoprotein receptor binding)|GO:0051082(unfolded protein binding)', 'GO:0000122(negative regulation of transcription from RNA polymerase II promoter)|GO:0000239(pachytene)|GO:0005515(protein binding)|GO:0005575(cellular_component)|GO:0005634(nucleus)|GO:0007130(synaptonemal complex assembly)|GO:0007286(spermatid development)|GO:0008150(biological_process)|GO:0008168(methyltransferase activity)|GO:0008270(zinc ion binding)|GO:0009566(fertilization)|GO:0016568(chromatin modification)|GO:0016740(transferase activity)|GO:0018024(histone-lysine N-methyltransferase activity)|GO:0035265(organ growth)|GO:0046872(metal ion binding)|GO:0051567(histone H3-K9 methylation)'], 'SEQUENCE': ['GCTGCCCGCATCTATGATTACGACCCCCTATATAAGGAGGCGCTGCAAATGCTGCGGGAT', 'ATTTTCTAACTGTCCTCTTTCTTGGGTCTAAAGCTCATAATACACAAAGGCTTCCAGACC', 'AAGCCAAGTACTTTAGAGAAGAAAAACGGTCTCAGCTGAACCTGTAGTGAGAGCATGCAG', 'ATCCAGGTCAGATTGTCAAGCATGGAGATATCAAGTGTGTACTAAATGAAGGCATGCCAA', 'AAATCGGGCCATCCGCACCAGAGGAAGATCATTCTGCCGGGACGTGGCTCGGGGCTATGA'], 'SPOT_ID.1': [nan, nan, nan, nan, nan], 'ORDER': [12.0, 14.0, 15.0, 16.0, 18.0]}\n",
"\n",
"Gene mapping dataframe:\n",
"{'ID': ['12', '14', '15', '16', '18'], 'Gene': ['APOBEC3B', 'ATP11B', 'LOC100132006', 'DNAJA1', 'EHMT2']}\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Converted gene expression data:\n",
"{'GSM4098797': [11.295818278999999, 4.511519006, 4.029339788, 7.998331606, 3.529187489], 'GSM4098798': [11.311701529, 4.350843151, 3.829114997, 6.938423613, 3.403435718], 'GSM4098799': [11.490747099, 3.940382921, 3.518664325, 8.071803433, 3.703306235], 'GSM4098800': [10.62815242, 4.278446209, 3.952369234, 7.445960991, 4.175610589], 'GSM4098801': [11.425336329, 4.211956199, 3.755241441, 7.389486419, 3.693382222], 'GSM4098802': [11.309095206, 3.807001272, 3.779241628, 8.267602906, 3.980138411], 'GSM4098803': [10.929429424, 3.925654364, 3.833418791, 8.355437797, 3.735606345], 'GSM4098804': [10.700006593000001, 4.314044971, 3.658411735, 7.448207267, 3.828141668], 'GSM4098805': [11.592457953, 3.520838128, 3.908003521, 7.832426589, 3.520838128], 'GSM4098806': [9.173432164000001, 4.137373263, 2.928105386, 8.132917185, 3.335657835], 'GSM4098807': [11.6466158, 4.51745926, 3.900382259, 8.405353632, 3.930806637], 'GSM4098808': [12.349148621, 4.781086546, 3.085499595, 8.276549505, 3.163182708], 'GSM4098809': [11.668675356, 4.036497385, 3.7901343, 8.222292761, 4.074914684], 'GSM4098810': [12.122596969, 4.134970053, 4.05199999, 8.051823544, 3.235740223], 'GSM4098811': [12.495397475, 4.101323054, 3.644023212, 7.634603293, 3.463214042], 'GSM4098812': [12.218892765, 4.595064891, 3.427753343, 7.684041323, 4.018747086], 'GSM4098813': [9.685849347, 4.22606317, 4.325947699, 7.562952071, 3.331314104], 'GSM4098814': [10.0964321, 4.867040912, 4.532427035, 7.256587897, 3.597141516], 'GSM4098815': [11.212807124, 4.23800568, 3.183184688, 7.921425237, 3.781316708], 'GSM4098816': [11.756302245, 4.374955768, 3.143092663, 8.429888285, 3.896505162], 'GSM4098817': [11.480266855, 4.644577848, 3.275647524, 7.337444716, 3.275647524], 'GSM4098818': [11.572050526, 4.216746355, 3.132219007, 8.030310185, 3.764970611], 'GSM4098819': [12.111974762, 4.871226415, 4.395134425, 8.383003976, 4.41419136], 'GSM4098820': [11.797386841, 4.357093025, 3.741237359, 7.488852897, 3.344227418], 'GSM4098821': [11.022180294, 4.528972801, 3.781929803, 8.127972724, 2.901117994], 'GSM4098822': [9.985806461, 4.334899168, 4.691320904, 8.08196884, 3.566150133], 'GSM4098823': [10.955167297, 3.988884942, 3.870179586, 7.627231669, 4.178270066], 'GSM4098824': [11.519869761, 3.560649062, 4.054721721, 8.318647838, 3.560649062], 'GSM4098825': [11.50559043, 4.354759526, 3.913857056, 8.252489038, 3.986446731], 'GSM4098826': [11.521872274, 4.162068735, 3.99068833, 7.49736804, 3.9320142], 'GSM4098827': [11.530309796000001, 4.258577062, 3.876582889, 7.638285155, 3.798833313], 'GSM4098828': [11.650405668, 4.588559402, 3.844650541, 7.649147453, 3.753795349], 'GSM4098829': [11.439998252999999, 4.569085095, 4.930172588, 8.660099047, 4.148122963], 'GSM4098830': [11.774968708000001, 4.475843846, 5.006921531, 8.306217473, 3.611226197], 'GSM4098831': [11.678834608999999, 3.992244703, 4.468223005, 8.725613368, 3.984856471], 'GSM4098832': [13.36665025, 4.663087485, 4.1664225, 7.613446924, 3.731352081], 'GSM4098833': [12.313311616, 4.346523659, 5.099913979, 8.275625494, 3.945911967], 'GSM4098834': [12.060811490999999, 4.256161059, 4.55451106, 8.202508423, 3.966656535], 'GSM4098835': [11.724259242, 4.12452232, 4.209760987, 8.452567683, 3.884865532], 'GSM4098836': [11.290614289, 4.416970969, 4.283844755, 7.950836689, 3.777055871], 'GSM4098837': [11.671444767999999, 4.70877685, 3.468851143, 7.662878274, 4.133964458], 'GSM4098838': [12.383108663, 4.247671487, 3.620601132, 8.539622569, 4.578953058], 'GSM4098839': [12.529668529, 4.662650635, 4.289667541, 8.474277445, 4.148552504], 'GSM4098840': [12.163355781, 4.763055707, 4.609645595, 8.260846839, 3.881485497], 'GSM4098841': [12.196179489999999, 4.237644549, 3.939796283, 9.030725874, 4.300612679], 'GSM4098842': [12.492096591, 4.359883689, 4.468801492, 7.923179402, 4.223197571], 'GSM4098843': [12.492539869, 4.067942975, 3.826995086, 7.624608546, 3.457999265], 'GSM4098844': [12.640559166, 4.277883701, 4.132814383, 8.098631342, 3.802210543], 'GSM4098845': [10.515985308, 4.428130209, 5.640199416, 8.424042297, 4.159216319], 'GSM4098846': [10.72859967, 4.545376526, 5.43525345, 8.116347941, 3.959945264], 'GSM4098847': [12.588295016, 4.252219424, 4.565555293, 8.229620491, 3.876710204], 'GSM4098848': [12.856335031, 4.837687313, 4.476784638, 8.59978321, 3.782853842], 'GSM4098849': [12.482955217, 4.410063383, 3.112111144, 7.688118613, 3.484341798], 'GSM4098850': [12.175504981, 4.525790096, 3.835247245, 8.192688326, 3.56097626], 'GSM4098851': [12.600100614999999, 4.792830166, 3.575349359, 8.635279662, 4.100254296], 'GSM4098852': [12.561666092, 4.402865814, 3.602970048, 8.325050001, 3.566874369], 'GSM4098853': [11.732715874, 4.649540088, 5.771464833, 8.48636833, 3.710872842], 'GSM4098854': [11.89072243, 4.280776313, 5.88416279, 8.784441166, 4.096685464], 'GSM4098855': [11.612091881, 3.987538223, 4.154718691, 8.135290914, 4.328919317], 'GSM4098856': [12.379367429999999, 4.596680653, 4.046847858, 8.006627098, 3.830326299], 'GSM4098857': [11.803956761, 4.698200208, 4.380661404, 8.690838172, 4.107066454], 'GSM4098858': [12.737503504, 3.667374991, 4.345379919, 8.318647024, 4.319829603], 'GSM4098859': [13.0600405, 4.769800866, 4.181172288, 8.374885971, 3.827799923], 'GSM4098860': [12.161425048, 4.629566597, 4.041705826, 7.91833211, 3.650639297]}\n"
]
}
],
"source": [
"# 1. Identify relevant columns from the gene annotation data for mapping\n",
"# The gene identifiers in gene_data are numeric IDs\n",
"# From the preview, we need to map 'ID' in the annotation to a gene symbol column\n",
"\n",
"# Looking at the columns in gene_annotation\n",
"print(\"Available columns in gene annotation:\")\n",
"print(gene_annotation.columns.tolist())\n",
"\n",
"# Let's get a better look at the annotation data beyond the first few rows\n",
"# to find rows that actually have gene symbol information\n",
"print(\"\\nSample of gene annotation data with non-null gene symbols:\")\n",
"sample_with_genes = gene_annotation[gene_annotation['GENE_SYMBOL'].notna()].head(5)\n",
"print(preview_df(sample_with_genes))\n",
"\n",
"# 2. Create the gene mapping dataframe\n",
"# Based on the data, we'll map 'ID' to 'GENE_SYMBOL'\n",
"mapping_df = get_gene_mapping(gene_annotation, 'ID', 'GENE_SYMBOL')\n",
"print(\"\\nGene mapping dataframe:\")\n",
"print(preview_df(mapping_df))\n",
"\n",
"# 3. Apply the gene mapping to convert probe-level measurements to gene expression\n",
"gene_data_mapped = apply_gene_mapping(gene_data, mapping_df)\n",
"\n",
"# Normalize gene symbols to ensure consistency\n",
"gene_data = normalize_gene_symbols_in_index(gene_data_mapped)\n",
"\n",
"# Preview the result\n",
"print(\"\\nConverted gene expression data:\")\n",
"print(preview_df(gene_data))\n"
]
},
{
"cell_type": "markdown",
"id": "72a8d3cd",
"metadata": {},
"source": [
"### Step 7: Data Normalization and Linking"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ff461b59",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:42.923358Z",
"iopub.status.busy": "2025-03-25T08:13:42.923235Z",
"iopub.status.idle": "2025-03-25T08:13:52.345716Z",
"shell.execute_reply": "2025-03-25T08:13:52.344636Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Normalized gene data saved to ../../output/preprocess/Cervical_Cancer/gene_data/GSE138079.csv\n",
"Clinical data saved to ../../output/preprocess/Cervical_Cancer/clinical_data/GSE138079.csv\n",
"Linked data shape: (64, 17902)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"For the feature 'Cervical_Cancer', the least common label is '0.0' with 23 occurrences. This represents 35.94% of the dataset.\n",
"The distribution of the feature 'Cervical_Cancer' in this dataset is fine.\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Linked data saved to ../../output/preprocess/Cervical_Cancer/GSE138079.csv\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",
"# Create clinical features directly from clinical_data using the conversion functions defined earlier\n",
"clinical_features_df = geo_select_clinical_features(\n",
" 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,\n",
" gender_row=gender_row,\n",
" convert_gender=convert_gender\n",
")\n",
"\n",
"# Save the clinical data\n",
"os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n",
"clinical_features_df.to_csv(out_clinical_data_file)\n",
"print(f\"Clinical data saved to {out_clinical_data_file}\")\n",
"\n",
"# Now link the clinical and genetic data\n",
"linked_data = geo_link_clinical_genetic_data(clinical_features_df, normalized_gene_data)\n",
"print(\"Linked data shape:\", linked_data.shape)\n",
"\n",
"# Handle missing values in the linked data\n",
"linked_data = handle_missing_values(linked_data, trait)\n",
"\n",
"# 4. Determine whether the trait and some demographic features are severely biased, and remove biased features.\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",
"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=\"This is an HPV-transformed keratinocyte cell line study focusing on transformation stages: 1 for anchorage independent (more advanced cancer stage), 0 for earlier stages.\"\n",
")\n",
"\n",
"# 6. If the linked data is usable, save it as a CSV file to 'out_data_file'.\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\"Linked data saved to {out_data_file}\")\n",
"else:\n",
" print(\"Data was determined to be unusable and was not saved\")"
]
}
],
"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
}
|