File size: 20,121 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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4fd343ca",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:21:44.674675Z",
     "iopub.status.busy": "2025-03-25T06:21:44.674576Z",
     "iopub.status.idle": "2025-03-25T06:21:44.833426Z",
     "shell.execute_reply": "2025-03-25T06:21:44.833081Z"
    }
   },
   "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 = \"Adrenocortical_Cancer\"\n",
    "cohort = \"GSE67766\"\n",
    "\n",
    "# Input paths\n",
    "in_trait_dir = \"../../input/GEO/Adrenocortical_Cancer\"\n",
    "in_cohort_dir = \"../../input/GEO/Adrenocortical_Cancer/GSE67766\"\n",
    "\n",
    "# Output paths\n",
    "out_data_file = \"../../output/preprocess/Adrenocortical_Cancer/GSE67766.csv\"\n",
    "out_gene_data_file = \"../../output/preprocess/Adrenocortical_Cancer/gene_data/GSE67766.csv\"\n",
    "out_clinical_data_file = \"../../output/preprocess/Adrenocortical_Cancer/clinical_data/GSE67766.csv\"\n",
    "json_path = \"../../output/preprocess/Adrenocortical_Cancer/cohort_info.json\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fba3c008",
   "metadata": {},
   "source": [
    "### Step 1: Initial Data Loading"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a7477333",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:21:44.834816Z",
     "iopub.status.busy": "2025-03-25T06:21:44.834673Z",
     "iopub.status.idle": "2025-03-25T06:21:44.935306Z",
     "shell.execute_reply": "2025-03-25T06:21:44.934984Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Background Information:\n",
      "!Series_title\t\"Cancer Cells Hijack PRC2 to Modify Multiple Cytokine Pathways\"\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: ['cell line: SW-13']}\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": "b82f7e2a",
   "metadata": {},
   "source": [
    "### Step 2: Dataset Analysis and Clinical Feature Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "68687736",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:21:44.936424Z",
     "iopub.status.busy": "2025-03-25T06:21:44.936317Z",
     "iopub.status.idle": "2025-03-25T06:21:44.941011Z",
     "shell.execute_reply": "2025-03-25T06:21:44.940741Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. Gene Expression Data Availability\n",
    "# Based on the series title and summary, we cannot definitively determine if gene expression data is available\n",
    "# The sample characteristics only mention \"cell line: SW-13\" which doesn't tell us about the type of data\n",
    "# Since there's no clear indication that this is gene expression data (vs miRNA or methylation)\n",
    "# and the series is described as a \"SuperSeries composed of the SubSeries\", \n",
    "# we should err on the cautious side\n",
    "is_gene_available = False\n",
    "\n",
    "# 2. Variable Availability and Data Type Conversion\n",
    "# 2.1 Data Availability\n",
    "# There's no trait data specific to Adrenocortical_Cancer in the sample characteristics\n",
    "trait_row = None\n",
    "\n",
    "# Age is not available in the sample characteristics\n",
    "age_row = None\n",
    "\n",
    "# Gender is not available in the sample characteristics\n",
    "gender_row = None\n",
    "\n",
    "# 2.2 Data Type Conversion\n",
    "# Define conversion functions for completeness, though they won't be used in this case\n",
    "def convert_trait(value):\n",
    "    # This won't be used as trait_row is None\n",
    "    return None\n",
    "\n",
    "def convert_age(value):\n",
    "    # This won't be used as age_row is None\n",
    "    return None\n",
    "\n",
    "def convert_gender(value):\n",
    "    # This won't be used as gender_row is None\n",
    "    return None\n",
    "\n",
    "# 3. Save Metadata\n",
    "# Conduct initial filtering and save the 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",
    "# Since trait_row is None, we skip this substep\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7cfcf769",
   "metadata": {},
   "source": [
    "### Step 3: Gene Data Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cbbef164",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:21:44.942025Z",
     "iopub.status.busy": "2025-03-25T06:21:44.941918Z",
     "iopub.status.idle": "2025-03-25T06:21:45.059467Z",
     "shell.execute_reply": "2025-03-25T06:21:45.059097Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First 20 gene/probe identifiers:\n",
      "Index(['ILMN_1343291', 'ILMN_1343295', 'ILMN_1651199', 'ILMN_1651209',\n",
      "       'ILMN_1651210', 'ILMN_1651221', 'ILMN_1651228', 'ILMN_1651229',\n",
      "       'ILMN_1651230', 'ILMN_1651232', 'ILMN_1651235', 'ILMN_1651236',\n",
      "       'ILMN_1651237', 'ILMN_1651238', 'ILMN_1651249', 'ILMN_1651253',\n",
      "       'ILMN_1651254', 'ILMN_1651259', 'ILMN_1651260', 'ILMN_1651262'],\n",
      "      dtype='object', name='ID')\n"
     ]
    }
   ],
   "source": [
    "# 1. First get the file paths again to access the matrix file\n",
    "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
    "\n",
    "# 2. Use the get_genetic_data function from the library to get the gene_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) for future observation\n",
    "print(\"First 20 gene/probe identifiers:\")\n",
    "print(gene_data.index[:20])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7f57d1c",
   "metadata": {},
   "source": [
    "### Step 4: Gene Identifier Review"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "003b77d8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:21:45.060757Z",
     "iopub.status.busy": "2025-03-25T06:21:45.060651Z",
     "iopub.status.idle": "2025-03-25T06:21:45.062498Z",
     "shell.execute_reply": "2025-03-25T06:21:45.062232Z"
    }
   },
   "outputs": [],
   "source": [
    "# Examining the gene identifiers in the gene expression data\n",
    "# The identifiers starting with \"ILMN_\" are Illumina BeadArray probe IDs, not human gene symbols\n",
    "# These are proprietary identifiers used by Illumina microarray platforms\n",
    "# They need to be mapped to standard human gene symbols for proper analysis\n",
    "\n",
    "requires_gene_mapping = True\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d00ee47d",
   "metadata": {},
   "source": [
    "### Step 5: Gene Annotation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "712ec6a1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:21:45.063608Z",
     "iopub.status.busy": "2025-03-25T06:21:45.063509Z",
     "iopub.status.idle": "2025-03-25T06:22:00.397054Z",
     "shell.execute_reply": "2025-03-25T06:22:00.396402Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gene annotation preview:\n",
      "{'ID': ['ILMN_1825594', 'ILMN_1810803', 'ILMN_1722532', 'ILMN_1884413', 'ILMN_1906034'], 'Species': ['Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens'], 'Source': ['Unigene', 'RefSeq', 'RefSeq', 'Unigene', 'Unigene'], 'Search_Key': ['ILMN_89282', 'ILMN_35826', 'ILMN_25544', 'ILMN_132331', 'ILMN_105017'], 'Transcript': ['ILMN_89282', 'ILMN_35826', 'ILMN_25544', 'ILMN_132331', 'ILMN_105017'], 'ILMN_Gene': ['HS.388528', 'LOC441782', 'JMJD1A', 'HS.580150', 'HS.540210'], 'Source_Reference_ID': ['Hs.388528', 'XM_497527.2', 'NM_018433.3', 'Hs.580150', 'Hs.540210'], 'RefSeq_ID': [nan, 'XM_497527.2', 'NM_018433.3', nan, nan], 'Unigene_ID': ['Hs.388528', nan, nan, 'Hs.580150', 'Hs.540210'], 'Entrez_Gene_ID': [nan, '441782', '55818', nan, nan], 'GI': ['23525203', '89042416', '46358420', '7376124', '5437312'], 'Accession': ['BU678343', 'XM_497527.2', 'NM_018433.3', 'AW629334', 'AI818233'], 'Symbol': [nan, 'LOC441782', 'JMJD1A', nan, nan], 'Protein_Product': [nan, 'XP_497527.2', 'NP_060903.2', nan, nan], 'Array_Address_Id': [1740241.0, 1850750.0, 1240504.0, 4050487.0, 2190598.0], 'Probe_Type': ['S', 'S', 'S', 'S', 'S'], 'Probe_Start': [349.0, 902.0, 4359.0, 117.0, 304.0], 'SEQUENCE': ['CTCTCTAAAGGGACAACAGAGTGGACAGTCAAGGAACTCCACATATTCAT', 'GGGGTCAAGCCCAGGTGAAATGTGGATTGGAAAAGTGCTTCCCTTGCCCC', 'CCAGGCTGTAAAAGCAAAACCTCGTATCAGCTCTGGAACAATACCTGCAG', 'CCAGACAGGAAGCATCAAGCCCTTCAGGAAAGAATATGCGAGAGTGCTGC', 'TGTGCAGAAAGCTGATGGAAGGGAGAAAGAATGGAAGTGGGTCACACAGC'], 'Chromosome': [nan, nan, '2', nan, nan], 'Probe_Chr_Orientation': [nan, nan, '+', nan, nan], 'Probe_Coordinates': [nan, nan, '86572991-86573040', nan, nan], 'Cytoband': [nan, nan, '2p11.2e', nan, nan], 'Definition': ['UI-CF-EC0-abi-c-12-0-UI.s1 UI-CF-EC0 Homo sapiens cDNA clone UI-CF-EC0-abi-c-12-0-UI 3, mRNA sequence', 'PREDICTED: Homo sapiens similar to spectrin domain with coiled-coils 1 (LOC441782), mRNA.', 'Homo sapiens jumonji domain containing 1A (JMJD1A), mRNA.', 'hi56g05.x1 Soares_NFL_T_GBC_S1 Homo sapiens cDNA clone IMAGE:2976344 3, mRNA sequence', 'wk77d04.x1 NCI_CGAP_Pan1 Homo sapiens cDNA clone IMAGE:2421415 3, mRNA sequence'], 'Ontology_Component': [nan, nan, 'nucleus [goid 5634] [evidence IEA]', nan, nan], 'Ontology_Process': [nan, nan, 'chromatin modification [goid 16568] [evidence IEA]; transcription [goid 6350] [evidence IEA]; regulation of transcription, DNA-dependent [goid 6355] [evidence IEA]', nan, nan], 'Ontology_Function': [nan, nan, 'oxidoreductase activity [goid 16491] [evidence IEA]; oxidoreductase activity, acting on single donors with incorporation of molecular oxygen, incorporation of two atoms of oxygen [goid 16702] [evidence IEA]; zinc ion binding [goid 8270] [evidence IEA]; metal ion binding [goid 46872] [evidence IEA]; iron ion binding [goid 5506] [evidence IEA]', nan, nan], 'Synonyms': [nan, nan, 'JHMD2A; JMJD1; TSGA; KIAA0742; DKFZp686A24246; DKFZp686P07111', nan, nan], 'GB_ACC': ['BU678343', 'XM_497527.2', 'NM_018433.3', 'AW629334', 'AI818233']}\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": "28d7a2ac",
   "metadata": {},
   "source": [
    "### Step 6: Gene Identifier Mapping"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e835bebf",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:22:00.398970Z",
     "iopub.status.busy": "2025-03-25T06:22:00.398836Z",
     "iopub.status.idle": "2025-03-25T06:22:00.784161Z",
     "shell.execute_reply": "2025-03-25T06:22:00.783510Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gene mapping preview (first 5 rows):\n",
      "             ID       Gene\n",
      "1  ILMN_1810803  LOC441782\n",
      "2  ILMN_1722532     JMJD1A\n",
      "6  ILMN_1708805      NCOA3\n",
      "8  ILMN_1672526  LOC389834\n",
      "9  ILMN_2185604   C17orf77\n",
      "\n",
      "Gene expression data after mapping (first 5 genes):\n",
      "         GSM1652385  GSM1652386  GSM1652387  GSM1652388  GSM1652389  \\\n",
      "Gene                                                                  \n",
      "A1BG      229.98830   248.54450   237.17420   248.39860   249.26820   \n",
      "A2BP1     318.77866   332.46035   345.21173   338.50507   351.49917   \n",
      "A2M        70.80764    70.58915    63.49310    75.62191    72.35401   \n",
      "A2ML1      73.61642    70.96689    79.69693    71.65809    74.31523   \n",
      "A3GALT2   206.22774   193.16380   218.59780   188.89192   202.47758   \n",
      "\n",
      "         GSM1652390  GSM1652391  GSM1652392  GSM1652393  GSM1652394  ...  \\\n",
      "Gene                                                                 ...   \n",
      "A1BG      244.07600   258.36630   263.38710   258.61440   258.33540  ...   \n",
      "A2BP1     345.69635   346.11921   361.47327   354.68587   359.69274  ...   \n",
      "A2M       108.32530    72.16235   135.00630    79.80496    82.38654  ...   \n",
      "A2ML1      73.23978    77.67924    72.64681    70.11669    69.30971  ...   \n",
      "A3GALT2   207.16097   206.89650   197.30278   205.58321   204.26970  ...   \n",
      "\n",
      "         GSM1652399  GSM1652400  GSM1652401  GSM1652402  GSM1652403  \\\n",
      "Gene                                                                  \n",
      "A1BG      220.35480   219.74660   218.51810   237.50740   224.25190   \n",
      "A2BP1     336.92718   318.65626   341.50960   333.50831   320.01791   \n",
      "A2M        71.92281   123.33600    73.92870    94.54202    70.73442   \n",
      "A2ML1      73.53131    66.09079    64.53247    69.09312    69.25777   \n",
      "A3GALT2   196.39571   199.43877   179.84575   179.21808   188.58534   \n",
      "\n",
      "         GSM1652404  GSM1652405  GSM1652406  GSM1652407  GSM1652408  \n",
      "Gene                                                                 \n",
      "A1BG      256.08970   243.24950   202.08701   223.68940   212.66030  \n",
      "A2BP1     323.68906   367.63241   314.59370   347.27794   304.38977  \n",
      "A2M        84.44023    75.40449   118.87620    68.69892   108.61290  \n",
      "A2ML1      72.47518    74.04777    81.68905    70.02788    70.21660  \n",
      "A3GALT2   212.61490   176.39538   173.74357   151.66942   190.38029  \n",
      "\n",
      "[5 rows x 24 columns]\n",
      "\n",
      "Shape of gene expression data: (18838, 24)\n"
     ]
    }
   ],
   "source": [
    "# 1. Identifying the key columns for gene mapping\n",
    "# From the annotation preview, we can see that:\n",
    "# - 'ID' column contains ILMN identifiers that match our gene expression data\n",
    "# - 'Symbol' column contains the gene symbols we want to map to\n",
    "\n",
    "# 2. Create the gene mapping dataframe\n",
    "prob_col = 'ID'\n",
    "gene_col = 'Symbol'\n",
    "mapping_df = get_gene_mapping(gene_annotation, prob_col, gene_col)\n",
    "\n",
    "# Print a preview of the mapping\n",
    "print(\"Gene mapping preview (first 5 rows):\")\n",
    "print(mapping_df.head())\n",
    "\n",
    "# 3. Apply the gene mapping to convert probe-level measurements to gene-level expression\n",
    "gene_data = apply_gene_mapping(gene_data, mapping_df)\n",
    "\n",
    "# Print the first few gene symbols and their data\n",
    "print(\"\\nGene expression data after mapping (first 5 genes):\")\n",
    "print(gene_data.head())\n",
    "\n",
    "# Print the shape of the gene expression data\n",
    "print(f\"\\nShape of gene expression data: {gene_data.shape}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25fb85c8",
   "metadata": {},
   "source": [
    "### Step 7: Data Normalization and Linking"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "eaf507b6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:22:00.786038Z",
     "iopub.status.busy": "2025-03-25T06:22:00.785911Z",
     "iopub.status.idle": "2025-03-25T06:22:01.112972Z",
     "shell.execute_reply": "2025-03-25T06:22:01.112346Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Normalizing gene symbols using NCBI Gene database...\n",
      "After normalization, gene data shape: (17551, 24)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Normalized gene expression data saved to ../../output/preprocess/Adrenocortical_Cancer/gene_data/GSE67766.csv\n",
      "Clinical data not available, dataset marked as unusable for trait-gene association studies.\n",
      "Dataset is not usable for trait-gene association studies.\n"
     ]
    }
   ],
   "source": [
    "# 1. Normalize gene symbols in the gene expression data\n",
    "print(\"Normalizing gene symbols using NCBI Gene database...\")\n",
    "gene_data = normalize_gene_symbols_in_index(gene_data)\n",
    "print(f\"After normalization, gene data shape: {gene_data.shape}\")\n",
    "\n",
    "# Save the normalized gene data\n",
    "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n",
    "gene_data.to_csv(out_gene_data_file)\n",
    "print(f\"Normalized gene expression data saved to {out_gene_data_file}\")\n",
    "\n",
    "# Since we already determined that trait data is not available (is_trait_available=False in step 2),\n",
    "# we should not attempt to link clinical and genetic data or process them further\n",
    "print(\"Clinical data not available, dataset marked as unusable for trait-gene association studies.\")\n",
    "\n",
    "# Since we cannot perform final validation without clinical data, we need to use is_final=False\n",
    "# We're recording information about gene data availability but not performing full validation\n",
    "is_usable = 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",
    "print(\"Dataset is not usable for trait-gene association 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
}