File size: 26,550 Bytes
92d2f89 |
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": "626ca0b1",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:29:27.437881Z",
"iopub.status.busy": "2025-03-25T06:29:27.437660Z",
"iopub.status.idle": "2025-03-25T06:29:27.607136Z",
"shell.execute_reply": "2025-03-25T06:29:27.606778Z"
}
},
"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 = \"Angelman_Syndrome\"\n",
"cohort = \"GSE43900\"\n",
"\n",
"# Input paths\n",
"in_trait_dir = \"../../input/GEO/Angelman_Syndrome\"\n",
"in_cohort_dir = \"../../input/GEO/Angelman_Syndrome/GSE43900\"\n",
"\n",
"# Output paths\n",
"out_data_file = \"../../output/preprocess/Angelman_Syndrome/GSE43900.csv\"\n",
"out_gene_data_file = \"../../output/preprocess/Angelman_Syndrome/gene_data/GSE43900.csv\"\n",
"out_clinical_data_file = \"../../output/preprocess/Angelman_Syndrome/clinical_data/GSE43900.csv\"\n",
"json_path = \"../../output/preprocess/Angelman_Syndrome/cohort_info.json\"\n"
]
},
{
"cell_type": "markdown",
"id": "c782edfb",
"metadata": {},
"source": [
"### Step 1: Initial Data Loading"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "5fdfc90d",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:29:27.608622Z",
"iopub.status.busy": "2025-03-25T06:29:27.608470Z",
"iopub.status.idle": "2025-03-25T06:29:27.676197Z",
"shell.execute_reply": "2025-03-25T06:29:27.675888Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Background Information:\n",
"!Series_title\t\"Co-ordinate inhibition of autism candidate genes by topoisomerase inhibitors\"\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: ['treatment: 1000nM_Topotecan', 'treatment: 150nM_Topotecan', 'treatment: 300nM_Topotecan', 'treatment: 30nM_Topotecan', 'treatment: 3nM_Topotecan', 'treatment: 500nM_Topotecan', 'treatment: Topotecan_dose_response_vehicle'], 1: ['cell type: cultured cortical neurons'], 2: ['strain: C57BL6']}\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": "8027ecc4",
"metadata": {},
"source": [
"### Step 2: Dataset Analysis and Clinical Feature Extraction"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "436e2862",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:29:27.677278Z",
"iopub.status.busy": "2025-03-25T06:29:27.677164Z",
"iopub.status.idle": "2025-03-25T06:29:27.682738Z",
"shell.execute_reply": "2025-03-25T06:29:27.682452Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A new JSON file was created at: ../../output/preprocess/Angelman_Syndrome/cohort_info.json\n"
]
},
{
"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",
"# Analysis of gene expression data availability\n",
"# Based on the background information, this is a study on gene expression in cultured neurons\n",
"# with various treatments. This suggests it likely contains gene expression data.\n",
"is_gene_available = True\n",
"\n",
"# Analysis of trait data availability\n",
"# From the characteristics, we don't see any Angelman Syndrome trait information.\n",
"# The data shows only treatment types, cell type, and strain with no human subjects.\n",
"trait_row = None # No trait data available\n",
"\n",
"# Since there's no human data, age and gender are not available\n",
"age_row = None\n",
"gender_row = None\n",
"\n",
"# Define conversion functions\n",
"def convert_trait(value):\n",
" # This function would extract and convert trait values if they were available\n",
" # Since there's no trait data, this is a placeholder function\n",
" if value is None:\n",
" return None\n",
" if ':' in str(value):\n",
" value = value.split(':', 1)[1].strip()\n",
" # Binary conversion would go here if data were available\n",
" return None\n",
"\n",
"def convert_age(value):\n",
" # Placeholder function since age data is not available\n",
" return None\n",
"\n",
"def convert_gender(value):\n",
" # Placeholder function since gender data is not available\n",
" return None\n",
"\n",
"# Save metadata about dataset usability\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",
"# Skip clinical feature extraction since trait_row is None\n",
"# If trait_row were not None, we would extract clinical features here\n"
]
},
{
"cell_type": "markdown",
"id": "e5dcd2b3",
"metadata": {},
"source": [
"### Step 3: Gene Data Extraction"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a2a8d4fd",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:29:27.683730Z",
"iopub.status.busy": "2025-03-25T06:29:27.683623Z",
"iopub.status.idle": "2025-03-25T06:29:27.731903Z",
"shell.execute_reply": "2025-03-25T06:29:27.731594Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"First 20 gene/probe identifiers:\n",
"Index(['10338001', '10338002', '10338003', '10338004', '10338005', '10338006',\n",
" '10338007', '10338008', '10338009', '10338010', '10338011', '10338012',\n",
" '10338013', '10338014', '10338015', '10338016', '10338017', '10338018',\n",
" '10338019', '10338020'],\n",
" dtype='object', name='ID')\n",
"\n",
"Gene data dimensions: 35556 genes × 10 samples\n"
]
}
],
"source": [
"# 1. Re-identify the SOFT and matrix files to ensure we have the correct paths\n",
"soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
"\n",
"# 2. Extract the gene expression data from the matrix file\n",
"gene_data = get_genetic_data(matrix_file)\n",
"\n",
"# 3. Print the first 20 row IDs (gene or probe identifiers)\n",
"print(\"\\nFirst 20 gene/probe identifiers:\")\n",
"print(gene_data.index[:20])\n",
"\n",
"# 4. Print the dimensions of the gene expression data\n",
"print(f\"\\nGene data dimensions: {gene_data.shape[0]} genes × {gene_data.shape[1]} samples\")\n",
"\n",
"# Note: we keep is_gene_available as True since we successfully extracted gene expression data\n",
"is_gene_available = True\n"
]
},
{
"cell_type": "markdown",
"id": "5bfeca4c",
"metadata": {},
"source": [
"### Step 4: Gene Identifier Review"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9e7f3015",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:29:27.733099Z",
"iopub.status.busy": "2025-03-25T06:29:27.732981Z",
"iopub.status.idle": "2025-03-25T06:29:27.734774Z",
"shell.execute_reply": "2025-03-25T06:29:27.734489Z"
}
},
"outputs": [],
"source": [
"# Looking at the gene identifiers, these are numerical identifiers that appear to be probe IDs, \n",
"# not standard human gene symbols. Human gene symbols would typically be alphabetical (like BRCA1, TP53, etc.)\n",
"# or alphanumeric identifiers. These numerical identifiers likely need to be mapped to gene symbols.\n",
"\n",
"requires_gene_mapping = True\n"
]
},
{
"cell_type": "markdown",
"id": "8541a68d",
"metadata": {},
"source": [
"### Step 5: Gene Annotation"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "06bf0824",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:29:27.735878Z",
"iopub.status.busy": "2025-03-25T06:29:27.735773Z",
"iopub.status.idle": "2025-03-25T06:29:32.714301Z",
"shell.execute_reply": "2025-03-25T06:29:32.713945Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gene annotation preview:\n",
"{'ID': ['1415670_at', '1415671_at', '1415672_at', '1415673_at', '1415674_a_at'], 'GB_ACC': ['BC024686', 'NM_013477', 'NM_020585', 'NM_133900', 'NM_021789'], 'SPOT_ID': [nan, nan, nan, nan, nan], 'Species Scientific Name': ['Mus musculus', 'Mus musculus', 'Mus musculus', 'Mus musculus', 'Mus musculus'], 'Annotation Date': ['Oct 6, 2014', 'Oct 6, 2014', 'Oct 6, 2014', 'Oct 6, 2014', 'Oct 6, 2014'], 'Sequence Type': ['Consensus sequence', 'Consensus sequence', 'Consensus sequence', 'Consensus sequence', 'Consensus sequence'], 'Sequence Source': ['GenBank', 'GenBank', 'GenBank', 'GenBank', 'GenBank'], 'Target Description': ['gb:BC024686.1 /DB_XREF=gi:19354080 /FEA=FLmRNA /CNT=416 /TID=Mm.26422.1 /TIER=FL+Stack /STK=110 /UG=Mm.26422 /LL=54161 /UG_GENE=Copg1 /DEF=Mus musculus, coatomer protein complex, subunit gamma 1, clone MGC:30335 IMAGE:3992144, mRNA, complete cds. /PROD=coatomer protein complex, subunit gamma 1 /FL=gb:AF187079.1 gb:BC024686.1 gb:NM_017477.1 gb:BC024896.1', 'gb:NM_013477.1 /DB_XREF=gi:7304908 /GEN=Atp6v0d1 /FEA=FLmRNA /CNT=197 /TID=Mm.1081.1 /TIER=FL+Stack /STK=114 /UG=Mm.1081 /LL=11972 /DEF=Mus musculus ATPase, H+ transporting, lysosomal 38kDa, V0 subunit D isoform 1 (Atp6v0d1), mRNA. /PROD=ATPase, H+ transporting, lysosomal 38kDa, V0subunit D isoform 1 /FL=gb:U21549.1 gb:U13840.1 gb:BC011075.1 gb:NM_013477.1', 'gb:NM_020585.1 /DB_XREF=gi:10181207 /GEN=AB041568 /FEA=FLmRNA /CNT=213 /TID=Mm.17035.1 /TIER=FL+Stack /STK=102 /UG=Mm.17035 /LL=57437 /DEF=Mus musculus hypothetical protein, MNCb-1213 (AB041568), mRNA. /PROD=hypothetical protein, MNCb-1213 /FL=gb:BC016894.1 gb:NM_020585.1', 'gb:NM_133900.1 /DB_XREF=gi:19527115 /GEN=AI480570 /FEA=FLmRNA /CNT=139 /TID=Mm.10623.1 /TIER=FL+Stack /STK=96 /UG=Mm.10623 /LL=100678 /DEF=Mus musculus expressed sequence AI480570 (AI480570), mRNA. /PROD=expressed sequence AI480570 /FL=gb:BC002251.1 gb:NM_133900.1', 'gb:NM_021789.1 /DB_XREF=gi:11140824 /GEN=Sbdn /FEA=FLmRNA /CNT=163 /TID=Mm.29814.1 /TIER=FL+Stack /STK=95 /UG=Mm.29814 /LL=60409 /DEF=Mus musculus synbindin (Sbdn), mRNA. /PROD=synbindin /FL=gb:NM_021789.1 gb:AF233340.1'], 'Representative Public ID': ['BC024686', 'NM_013477', 'NM_020585', 'NM_133900', 'NM_021789'], 'Gene Title': ['coatomer protein complex, subunit gamma 1', 'ATPase, H+ transporting, lysosomal V0 subunit D1', 'golgi autoantigen, golgin subfamily a, 7', 'phosphoserine phosphatase', 'trafficking protein particle complex 4'], 'Gene Symbol': ['Copg1', 'Atp6v0d1', 'Golga7', 'Psph', 'Trappc4'], 'ENTREZ_GENE_ID': ['54161', '11972', '57437', '100678', '60409'], 'RefSeq Transcript ID': ['NM_017477 /// NM_201244 /// XM_006506386', 'NM_013477', 'NM_001042484 /// NM_020585 /// XM_006509179', 'NM_133900 /// XM_006504274 /// XM_006504275', 'NM_021789 /// XM_006510523'], 'Gene Ontology Biological Process': ['0006810 // transport // inferred from electronic annotation /// 0006886 // intracellular protein transport // inferred from electronic annotation /// 0015031 // protein transport // inferred from electronic annotation /// 0016192 // vesicle-mediated transport // inferred from electronic annotation /// 0051683 // establishment of Golgi localization // not recorded /// 0072384 // organelle transport along microtubule // not recorded', '0006200 // ATP catabolic process // inferred from direct assay /// 0006810 // transport // inferred from electronic annotation /// 0006811 // ion transport // inferred from electronic annotation /// 0007420 // brain development // inferred from electronic annotation /// 0015991 // ATP hydrolysis coupled proton transport // inferred from electronic annotation /// 0015992 // proton transport // inferred from electronic annotation /// 0030030 // cell projection organization // inferred from electronic annotation /// 0042384 // cilium assembly // inferred from sequence or structural similarity /// 1902600 // hydrogen ion transmembrane transport // inferred from direct assay', '0006893 // Golgi to plasma membrane transport // not recorded /// 0018230 // peptidyl-L-cysteine S-palmitoylation // not recorded /// 0043001 // Golgi to plasma membrane protein transport // not recorded /// 0050821 // protein stabilization // not recorded', '0006563 // L-serine metabolic process // not recorded /// 0006564 // L-serine biosynthetic process // not recorded /// 0008152 // metabolic process // inferred from electronic annotation /// 0008652 // cellular amino acid biosynthetic process // inferred from electronic annotation /// 0009612 // response to mechanical stimulus // inferred from electronic annotation /// 0016311 // dephosphorylation // not recorded /// 0031667 // response to nutrient levels // inferred from electronic annotation /// 0033574 // response to testosterone // inferred from electronic annotation', '0006810 // transport // inferred from electronic annotation /// 0006888 // ER to Golgi vesicle-mediated transport // inferred from electronic annotation /// 0016192 // vesicle-mediated transport // traceable author statement /// 0016358 // dendrite development // inferred from direct assay /// 0045212 // neurotransmitter receptor biosynthetic process // traceable author statement'], 'Gene Ontology Cellular Component': ['0000139 // Golgi membrane // not recorded /// 0005634 // nucleus // inferred from electronic annotation /// 0005737 // cytoplasm // inferred from electronic annotation /// 0005794 // Golgi apparatus // inferred from electronic annotation /// 0005829 // cytosol // inferred from electronic annotation /// 0016020 // membrane // inferred from electronic annotation /// 0030117 // membrane coat // inferred from electronic annotation /// 0030126 // COPI vesicle coat // inferred from electronic annotation /// 0030663 // COPI-coated vesicle membrane // inferred from electronic annotation /// 0031410 // cytoplasmic vesicle // inferred from electronic annotation', '0005765 // lysosomal membrane // not recorded /// 0005769 // early endosome // inferred from direct assay /// 0005813 // centrosome // not recorded /// 0008021 // synaptic vesicle // not recorded /// 0016020 // membrane // not recorded /// 0016324 // apical plasma membrane // not recorded /// 0016471 // vacuolar proton-transporting V-type ATPase complex // not recorded /// 0033179 // proton-transporting V-type ATPase, V0 domain // inferred from electronic annotation /// 0043005 // neuron projection // not recorded /// 0043234 // protein complex // not recorded /// 0043679 // axon terminus // not recorded /// 0070062 // extracellular vesicular exosome // not recorded', '0000139 // Golgi membrane // not recorded /// 0002178 // palmitoyltransferase complex // not recorded /// 0005794 // Golgi apparatus // inferred from electronic annotation /// 0005795 // Golgi stack // not recorded /// 0016020 // membrane // inferred from electronic annotation /// 0031228 // intrinsic component of Golgi membrane // not recorded /// 0070062 // extracellular vesicular exosome // not recorded', '0005737 // cytoplasm // not recorded /// 0043005 // neuron projection // not recorded', '0005622 // intracellular // inferred from electronic annotation /// 0005783 // endoplasmic reticulum // inferred from electronic annotation /// 0005794 // Golgi apparatus // inferred from electronic annotation /// 0005795 // Golgi stack // inferred from direct assay /// 0005801 // cis-Golgi network // inferred from electronic annotation /// 0005886 // plasma membrane // inferred from electronic annotation /// 0008021 // synaptic vesicle // inferred from direct assay /// 0016020 // membrane // inferred from electronic annotation /// 0030008 // TRAPP complex // inferred from direct assay /// 0030054 // cell junction // inferred from electronic annotation /// 0030425 // dendrite // inferred from direct assay /// 0045202 // synapse // inferred from direct assay /// 0045211 // postsynaptic membrane // inferred from electronic annotation'], 'Gene Ontology Molecular Function': ['0005198 // structural molecule activity // inferred from electronic annotation /// 0005488 // binding // inferred from electronic annotation /// 0005515 // protein binding // inferred from electronic annotation', '0005515 // protein binding // inferred from electronic annotation /// 0008553 // hydrogen-exporting ATPase activity, phosphorylative mechanism // inferred from direct assay /// 0015078 // hydrogen ion transmembrane transporter activity // inferred from electronic annotation /// 0032403 // protein complex binding // not recorded', nan, \"0000287 // magnesium ion binding // not recorded /// 0004647 // phosphoserine phosphatase activity // not recorded /// 0005509 // calcium ion binding // not recorded /// 0008253 // 5'-nucleotidase activity // inferred from electronic annotation /// 0016787 // hydrolase activity // inferred from electronic annotation /// 0016791 // phosphatase activity // inferred from electronic annotation /// 0042803 // protein homodimerization activity // not recorded /// 0046872 // metal ion binding // inferred from electronic annotation\", '0005515 // protein binding // inferred from physical interaction']}\n"
]
}
],
"source": [
"# 1. First get the file paths using geo_get_relevant_filepaths function\n",
"soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
"\n",
"# 2. 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",
"# 3. 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": "9567fd64",
"metadata": {},
"source": [
"### Step 6: Gene Identifier Mapping"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "415ffd90",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:29:32.715696Z",
"iopub.status.busy": "2025-03-25T06:29:32.715571Z",
"iopub.status.idle": "2025-03-25T06:29:32.910965Z",
"shell.execute_reply": "2025-03-25T06:29:32.910582Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gene expression data index preview:\n",
"['10338001', '10338002', '10338003', '10338004', '10338005']\n",
"\n",
"Gene annotation ID preview:\n",
"['1415670_at', '1415671_at', '1415672_at', '1415673_at', '1415674_a_at']\n",
"\n",
"This appears to be a mouse dataset with platform mismatch between expression data and annotation.\n",
"Will save the original probe-level data for further analysis.\n",
"\n",
"Saved gene expression data to ../../output/preprocess/Angelman_Syndrome/gene_data/GSE43900.csv\n",
"Gene data shape (using original probe IDs): (35556, 10)\n",
"\n",
"Preserving original probe-level data for downstream analysis.\n"
]
}
],
"source": [
"# 1. Look at what's in our gene expression data versus annotation data\n",
"print(\"Gene expression data index preview:\")\n",
"print(gene_data.index[:5].tolist())\n",
"\n",
"print(\"\\nGene annotation ID preview:\")\n",
"print(gene_annotation['ID'][:5].tolist())\n",
"\n",
"# The gene expression data uses numerical IDs while the annotation uses different format IDs\n",
"# Since there's a platform mismatch, we'll use the original probe data but normalize it\n",
"print(\"\\nThis appears to be a mouse dataset with platform mismatch between expression data and annotation.\")\n",
"print(\"Will save the original probe-level data for further analysis.\")\n",
"\n",
"# Check if the gene expression data has any rows\n",
"if gene_data.shape[0] > 0:\n",
" # Save the gene expression data with the original probe IDs\n",
" # Ensure the output directory exists\n",
" os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n",
" gene_data.to_csv(out_gene_data_file)\n",
" \n",
" print(f\"\\nSaved gene expression data to {out_gene_data_file}\")\n",
" print(f\"Gene data shape (using original probe IDs): {gene_data.shape}\")\n",
" \n",
" # Set the flag to indicate gene data is available\n",
" is_gene_available = True\n",
"else:\n",
" print(\"\\nNo gene expression data was found.\")\n",
" is_gene_available = False\n",
"\n",
"# Keep the gene data in its original form for further steps\n",
"mapped_gene_data = gene_data.copy()\n",
"print(\"\\nPreserving original probe-level data for downstream analysis.\")\n"
]
},
{
"cell_type": "markdown",
"id": "ddb2dc65",
"metadata": {},
"source": [
"### Step 7: Data Normalization and Linking"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "b6a7f679",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T06:29:32.912269Z",
"iopub.status.busy": "2025-03-25T06:29:32.912151Z",
"iopub.status.idle": "2025-03-25T06:29:33.093943Z",
"shell.execute_reply": "2025-03-25T06:29:33.093617Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Normalization returned empty results - keeping original gene data.\n",
"Gene data shape to be saved: (35556, 10)\n",
"First 5 gene/probe IDs: ['10338001', '10338002', '10338003', '10338004', '10338005']\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Gene data saved to ../../output/preprocess/Angelman_Syndrome/gene_data/GSE43900.csv\n",
"Trait data is unavailable in this dataset.\n",
"Abnormality detected in the cohort: GSE43900. Preprocessing failed.\n",
"Dataset deemed not usable for human trait associational studies.\n"
]
}
],
"source": [
"# 1. The normalized gene data was empty, which suggests that the normalization was unsuccessful.\n",
"# Let's keep the original gene data instead of attempting to normalize it.\n",
"print(\"Normalization returned empty results - keeping original gene data.\")\n",
"gene_data_to_save = gene_data\n",
"print(f\"Gene data shape to be saved: {gene_data_to_save.shape}\")\n",
"print(f\"First 5 gene/probe IDs: {gene_data_to_save.index[:5].tolist()}\")\n",
"\n",
"# Save the gene data\n",
"os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n",
"gene_data_to_save.to_csv(out_gene_data_file)\n",
"print(f\"Gene data saved to {out_gene_data_file}\")\n",
"\n",
"# Since we previously determined that trait data is not available in this dataset,\n",
"# we won't attempt to load or create clinical data that doesn't exist\n",
"is_trait_available = False\n",
"print(\"Trait data is unavailable in this dataset.\")\n",
"\n",
"# Since this is mouse data and doesn't contain human trait (Angelman Syndrome) information,\n",
"# the dataset is not usable for our human trait association studies\n",
"is_biased = True # Set to True to indicate dataset is not suitable\n",
"\n",
"# Create a minimal valid DataFrame for metadata using gene data sample IDs\n",
"sample_df = pd.DataFrame(index=gene_data.columns)\n",
"\n",
"# Validate and save cohort info with appropriate values\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=is_trait_available,\n",
" is_biased=is_biased, # Providing a value even when trait is not available\n",
" df=sample_df,\n",
" note=\"This dataset contains mouse neuron gene expression data with various treatments, but no human Angelman Syndrome trait information.\"\n",
")\n",
"\n",
"# No linked data to save since trait data is not available\n",
"print(\"Dataset deemed not usable for human trait associational studies.\")"
]
}
],
"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
}
|