File size: 20,703 Bytes
f88156f |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "1a1daae1",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:53.371957Z",
"iopub.status.busy": "2025-03-25T08:13:53.371845Z",
"iopub.status.idle": "2025-03-25T08:13:53.536601Z",
"shell.execute_reply": "2025-03-25T08:13:53.536248Z"
}
},
"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 = \"GSE138080\"\n",
"\n",
"# Input paths\n",
"in_trait_dir = \"../../input/GEO/Cervical_Cancer\"\n",
"in_cohort_dir = \"../../input/GEO/Cervical_Cancer/GSE138080\"\n",
"\n",
"# Output paths\n",
"out_data_file = \"../../output/preprocess/Cervical_Cancer/GSE138080.csv\"\n",
"out_gene_data_file = \"../../output/preprocess/Cervical_Cancer/gene_data/GSE138080.csv\"\n",
"out_clinical_data_file = \"../../output/preprocess/Cervical_Cancer/clinical_data/GSE138080.csv\"\n",
"json_path = \"../../output/preprocess/Cervical_Cancer/cohort_info.json\"\n"
]
},
{
"cell_type": "markdown",
"id": "f3eaae2d",
"metadata": {},
"source": [
"### Step 1: Initial Data Loading"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "009305cd",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:53.538063Z",
"iopub.status.busy": "2025-03-25T08:13:53.537917Z",
"iopub.status.idle": "2025-03-25T08:13:53.630800Z",
"shell.execute_reply": "2025-03-25T08:13:53.630487Z"
}
},
"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 tissues-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 were analyzed in healthy cervical tissues (n=10), high-grade precancerous lesios (CIN2/3, n=15) and cervical squamous cell carcinomas (n=10) using whole human genome oligo microarrays (G4112A, mRNA 4x44K; Agilent Technologies).\"\n",
"Sample Characteristics Dictionary:\n",
"{0: ['cell type: normal cervical squamous epithelium', 'cell type: cervical intraepithelial neoplasia, grade 2-3', 'cell type: cervical squamous cell carcinoma'], 1: ['hpv: high-risk HPV-positive', 'hpv: HPV-negative']}\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": "650d5c7f",
"metadata": {},
"source": [
"### Step 2: Dataset Analysis and Clinical Feature Extraction"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "342596ea",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:53.631947Z",
"iopub.status.busy": "2025-03-25T08:13:53.631837Z",
"iopub.status.idle": "2025-03-25T08:13:53.639841Z",
"shell.execute_reply": "2025-03-25T08:13:53.639547Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Preview of extracted clinical features:\n",
"{'GSM4098861': [0.0], 'GSM4098862': [0.0], 'GSM4098863': [0.0], 'GSM4098864': [0.0], 'GSM4098865': [0.0], 'GSM4098866': [0.0], 'GSM4098867': [0.0], 'GSM4098868': [0.0], 'GSM4098869': [0.0], 'GSM4098870': [0.0], 'GSM4098871': [1.0], 'GSM4098872': [1.0], 'GSM4098873': [1.0], 'GSM4098874': [1.0], 'GSM4098875': [1.0], 'GSM4098876': [1.0], 'GSM4098877': [1.0], 'GSM4098878': [1.0], 'GSM4098879': [1.0], 'GSM4098880': [1.0], 'GSM4098881': [1.0], 'GSM4098882': [1.0], 'GSM4098883': [1.0], 'GSM4098884': [1.0], 'GSM4098885': [1.0], 'GSM4098886': [1.0], 'GSM4098887': [1.0], 'GSM4098888': [1.0], 'GSM4098889': [1.0], 'GSM4098890': [1.0], 'GSM4098891': [1.0], 'GSM4098892': [1.0], 'GSM4098893': [1.0], 'GSM4098894': [1.0], 'GSM4098895': [1.0]}\n",
"Clinical features saved to ../../output/preprocess/Cervical_Cancer/clinical_data/GSE138080.csv\n"
]
}
],
"source": [
"import os\n",
"import pandas as pd\n",
"import numpy as np\n",
"from typing import Optional, Callable, List, Dict, Any, Union\n",
"import json\n",
"\n",
"# 1. Gene Expression Data Assessment\n",
"# Based on the background information and series title, this appears to be mRNA expression data\n",
"is_gene_available = True\n",
"\n",
"# 2. Variable Availability and Data Type Conversion\n",
"# 2.1 Data Availability\n",
"# Examining the Sample Characteristics Dictionary\n",
"# The first key (0) contains information about cell types: normal, CIN2/3, and squamous cell carcinoma\n",
"# The second key (1) contains HPV status: high-risk HPV-positive or HPV-negative\n",
"\n",
"trait_row = 0 # Cell type information can be used to determine cervical cancer\n",
"age_row = None # No age information available\n",
"gender_row = None # No gender information available (though we can assume all samples are female, but it's not explicit)\n",
"\n",
"# 2.2 Data Type Conversion Functions\n",
"def convert_trait(value: str) -> Optional[int]:\n",
" \"\"\"\n",
" Convert cell type information to binary trait data for cervical cancer.\n",
" 0: normal tissue (control)\n",
" 1: cancer or precancerous lesion (case)\n",
" \"\"\"\n",
" if value is None:\n",
" return None\n",
" \n",
" # Extract value after colon if present\n",
" if ':' in value:\n",
" value = value.split(':', 1)[1].strip()\n",
" \n",
" value = value.lower()\n",
" \n",
" if 'normal' in value:\n",
" return 0\n",
" elif 'carcinoma' in value or 'neoplasia' in value:\n",
" return 1\n",
" else:\n",
" return None\n",
"\n",
"def convert_age(value: str) -> Optional[float]:\n",
" \"\"\"\n",
" Convert age information to continuous value.\n",
" Not used in this dataset as age information is not available.\n",
" \"\"\"\n",
" return None\n",
"\n",
"def convert_gender(value: str) -> Optional[int]:\n",
" \"\"\"\n",
" Convert gender information to binary.\n",
" Not used in this dataset as gender information is not available.\n",
" \"\"\"\n",
" return None\n",
"\n",
"# 3. Save Metadata\n",
"# Perform initial filtering and save metadata\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",
"# Check if trait_row is not None (meaning clinical data is available)\n",
"if trait_row is not None:\n",
" # We need to check if clinical_data is available in the environment\n",
" # This should have been loaded in a previous step\n",
" try:\n",
" # Extract clinical features using the library function\n",
" clinical_features_df = geo_select_clinical_features(\n",
" clinical_df=clinical_data, # Assuming clinical_data was loaded in previous step\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",
" # Preview the extracted clinical features\n",
" print(\"Preview of extracted clinical features:\")\n",
" preview = preview_df(clinical_features_df)\n",
" print(preview)\n",
" \n",
" # Create output directory if it doesn't exist\n",
" os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n",
" \n",
" # Save the clinical features to CSV\n",
" clinical_features_df.to_csv(out_clinical_data_file, index=True)\n",
" print(f\"Clinical features saved to {out_clinical_data_file}\")\n",
" except NameError:\n",
" print(\"Error: clinical_data not found. Please ensure it was loaded in a previous step.\")\n"
]
},
{
"cell_type": "markdown",
"id": "d1584944",
"metadata": {},
"source": [
"### Step 3: Gene Data Extraction"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "cc444e2e",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:53.640835Z",
"iopub.status.busy": "2025-03-25T08:13:53.640727Z",
"iopub.status.idle": "2025-03-25T08:13:53.762830Z",
"shell.execute_reply": "2025-03-25T08:13:53.762442Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['12', '14', '16', '17', '19', '22', '24', '25', '27', '30', '33', '35',\n",
" '37', '38', '40', '42', '45', '47', '49', '51'],\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": "e032ce41",
"metadata": {},
"source": [
"### Step 4: Gene Identifier Review"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1f83fb31",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:53.764141Z",
"iopub.status.busy": "2025-03-25T08:13:53.764024Z",
"iopub.status.idle": "2025-03-25T08:13:53.765920Z",
"shell.execute_reply": "2025-03-25T08:13:53.765642Z"
}
},
"outputs": [],
"source": [
"# The identifiers appear to be numeric values (likely probe IDs or some other non-gene symbol identifiers)\n",
"# These are not standard human gene symbols which are typically alphanumeric (e.g., TP53, BRCA1, etc.)\n",
"# Therefore, mapping to gene symbols would be required\n",
"\n",
"requires_gene_mapping = True\n"
]
},
{
"cell_type": "markdown",
"id": "01545ba8",
"metadata": {},
"source": [
"### Step 5: Gene Annotation"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6c17a5d0",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:53.767045Z",
"iopub.status.busy": "2025-03-25T08:13:53.766931Z",
"iopub.status.idle": "2025-03-25T08:13:55.911095Z",
"shell.execute_reply": "2025-03-25T08:13:55.910698Z"
}
},
"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": "885b3ed3",
"metadata": {},
"source": [
"### Step 6: Gene Identifier Mapping"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "6adba2d0",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:55.912472Z",
"iopub.status.busy": "2025-03-25T08:13:55.912346Z",
"iopub.status.idle": "2025-03-25T08:13:56.023449Z",
"shell.execute_reply": "2025-03-25T08:13:56.023007Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"First 10 gene symbols after mapping:\n",
"Index(['A1BG', 'A1CF', 'A2BP1', 'A2LD1', 'A2M', 'A2ML1', 'A4GALT', 'AAAS',\n",
" 'AACS', 'AADACL1'],\n",
" dtype='object', name='Gene')\n"
]
}
],
"source": [
"# 1. Identify the appropriate columns for mapping\n",
"# Based on observation: 'ID' column in gene_annotation contains probe IDs\n",
"# and 'GENE_SYMBOL' column contains the gene symbols\n",
"\n",
"# 2. Get a gene mapping dataframe by extracting the relevant columns \n",
"mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')\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 the first few gene symbols to verify the mapping worked\n",
"print(\"First 10 gene symbols after mapping:\")\n",
"print(gene_data.index[:10])\n"
]
},
{
"cell_type": "markdown",
"id": "ea894a50",
"metadata": {},
"source": [
"### Step 7: Data Normalization and Linking"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "73ee57de",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:13:56.024959Z",
"iopub.status.busy": "2025-03-25T08:13:56.024847Z",
"iopub.status.idle": "2025-03-25T08:14:00.632257Z",
"shell.execute_reply": "2025-03-25T08:14:00.631859Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Normalized gene data saved to ../../output/preprocess/Cervical_Cancer/gene_data/GSE138080.csv\n",
"Linked data shape: (35, 13053)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"For the feature 'Cervical_Cancer', the least common label is '0.0' with 10 occurrences. This represents 28.57% 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/GSE138080.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",
"# Load the clinical features from the previously saved file (reusing the data from Step 2)\n",
"clinical_features_df = pd.read_csv(out_clinical_data_file, index_col=0)\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=\"Dataset contains gene expression data comparing normal cervical tissue (n=10) to CIN2/3 lesions (n=15) and cervical squamous cell carcinomas (n=10).\"\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
}
|