File size: 106,365 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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3835e969",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:35:44.483494Z",
     "iopub.status.busy": "2025-03-25T08:35:44.483265Z",
     "iopub.status.idle": "2025-03-25T08:35:44.652479Z",
     "shell.execute_reply": "2025-03-25T08:35:44.652127Z"
    }
   },
   "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 = \"Cystic_Fibrosis\"\n",
    "cohort = \"GSE60690\"\n",
    "\n",
    "# Input paths\n",
    "in_trait_dir = \"../../input/GEO/Cystic_Fibrosis\"\n",
    "in_cohort_dir = \"../../input/GEO/Cystic_Fibrosis/GSE60690\"\n",
    "\n",
    "# Output paths\n",
    "out_data_file = \"../../output/preprocess/Cystic_Fibrosis/GSE60690.csv\"\n",
    "out_gene_data_file = \"../../output/preprocess/Cystic_Fibrosis/gene_data/GSE60690.csv\"\n",
    "out_clinical_data_file = \"../../output/preprocess/Cystic_Fibrosis/clinical_data/GSE60690.csv\"\n",
    "json_path = \"../../output/preprocess/Cystic_Fibrosis/cohort_info.json\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "617aaec5",
   "metadata": {},
   "source": [
    "### Step 1: Initial Data Loading"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cf96486b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:35:44.653921Z",
     "iopub.status.busy": "2025-03-25T08:35:44.653777Z",
     "iopub.status.idle": "2025-03-25T08:35:45.016592Z",
     "shell.execute_reply": "2025-03-25T08:35:45.016193Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Background Information:\n",
      "!Series_title\t\"Gene Expression in Transformed Lymphocytes Reveals Phenotype-Modifying Pathways in Cystic Fibrosis\"\n",
      "!Series_summary\t\"Heritable genetic variants modify cystic fibrosis (CF) clinical phenotypes, e.g., lung disease, age-of-onset of persistent Pseudomonas aeruginosa (P. aeruginosa), and meconium ileus (MI).  Previous genome wide association studies (GWAS) have begun to inform the genetic architecture of CF phenotypes.  Analyses of gene expression will complement GWAS, as demonstrated by analyses of gene expression in lymphoblastoid cell lines (LCLs) to identify disease-related pathophysiological processes for non-CF complex traits.  In this study, global gene expression was measured in RNA from LCLs from 754 CF patients and analyzed for association with lung disease severity, age-of-onset of persistent P. aeruginosa pulmonary infection, and MI at birth.  Each phenotype displayed distinct expression associations.  Most pathways significantly associated with lung disease were related to membranes, vesicle traffic, and Golgi/endoplasmic reticulum (ER).  Pathways containing HLA genes (Class I and II) were significantly associated with both lung and P. aeruginosa phenotypes, but they displayed qualitative differences between phenotypes.  MI associated with pathways involving oxidative phosphorylation.  The results support the concept that gene expression associated with heritable variation acts to modify phenotypes in CF.\"\n",
      "!Series_overall_design\t\"754 samples were analyzed; 2 control samples were plated by Expression Analysis per plate and 1 pooled sample from the patient set was added to one well on each plate.\"\n",
      "Sample Characteristics Dictionary:\n",
      "{0: ['Sex: Male', 'Sex: Female'], 1: ['consortium lung phenotype: 0.92156', 'consortium lung phenotype: -0.79274', 'consortium lung phenotype: 2.33374', 'consortium lung phenotype: -1.36666', 'consortium lung phenotype: 2.86073', 'consortium lung phenotype: 1.08383', 'consortium lung phenotype: 1.15792', 'consortium lung phenotype: 1.51600', 'consortium lung phenotype: -0.77528', 'consortium lung phenotype: -0.35251', 'consortium lung phenotype: 0.95176', 'consortium lung phenotype: -0.78019', 'consortium lung phenotype: -0.45468', 'consortium lung phenotype: 1.14497', 'consortium lung phenotype: -0.47971', 'consortium lung phenotype: 0.08552', 'consortium lung phenotype: -0.74197', 'consortium lung phenotype: -1.29147', 'consortium lung phenotype: 0.81747', 'consortium lung phenotype: 1.52976', 'consortium lung phenotype: 1.78443', 'consortium lung phenotype: 0.85150', 'consortium lung phenotype: 1.98295', 'consortium lung phenotype: 0.86374', 'consortium lung phenotype: 0.94161', 'consortium lung phenotype: 1.10084', 'consortium lung phenotype: -0.55910', 'consortium lung phenotype: 0.84926', 'consortium lung phenotype: 0.86596', 'consortium lung phenotype: 1.37640'], 2: ['age of enrollment: 38.2', 'age of enrollment: 9.2', 'age of enrollment: 22.5', 'age of enrollment: 14.4', 'age of enrollment: 33.8', 'age of enrollment: 18.6', 'age of enrollment: 27.7', 'age of enrollment: 33.5', 'age of enrollment: 17.8', 'age of enrollment: 24.1', 'age of enrollment: 16.4', 'age of enrollment: 8.7', 'age of enrollment: 10.4', 'age of enrollment: 46.3', 'age of enrollment: 19.0', 'age of enrollment: 17.1', 'age of enrollment: 10.2', 'age of enrollment: 16.7', 'age of enrollment: 39.7', 'age of enrollment: 39.3', 'age of enrollment: 25.4', 'age of enrollment: 41.2', 'age of enrollment: 18.1', 'age of enrollment: 21.5', 'age of enrollment: 17.3', 'age of enrollment: 32.4', 'age of enrollment: 19.8', 'age of enrollment: 34.3', 'age of enrollment: 25.3', 'age of enrollment: 46.7'], 3: ['cftr genotype: DF508/DF508', 'cftr genotype: DF508/UNK', 'cftr genotype: UNK/UNK', 'cftr genotype: DF508/R553X'], 4: ['persistent ps aer status: 1', 'persistent ps aer status: 0', 'persistent ps aer status: NA'], 5: ['age of onset of persistent ps aer or censored age: 25', 'age of onset of persistent ps aer or censored age: 15', 'age of onset of persistent ps aer or censored age: 19', 'age of onset of persistent ps aer or censored age: 2', 'age of onset of persistent ps aer or censored age: NA', 'age of onset of persistent ps aer or censored age: 14', 'age of onset of persistent ps aer or censored age: 22', 'age of onset of persistent ps aer or censored age: 1', 'age of onset of persistent ps aer or censored age: 4', 'age of onset of persistent ps aer or censored age: 30', 'age of onset of persistent ps aer or censored age: 5', 'age of onset of persistent ps aer or censored age: 32', 'age of onset of persistent ps aer or censored age: 35', 'age of onset of persistent ps aer or censored age: 24', 'age of onset of persistent ps aer or censored age: 3', 'age of onset of persistent ps aer or censored age: 29', 'age of onset of persistent ps aer or censored age: 0.6', 'age of onset of persistent ps aer or censored age: 18', 'age of onset of persistent ps aer or censored age: 8', 'age of onset of persistent ps aer or censored age: 26', 'age of onset of persistent ps aer or censored age: 50', 'age of onset of persistent ps aer or censored age: 21', 'age of onset of persistent ps aer or censored age: 16', 'age of onset of persistent ps aer or censored age: 12', 'age of onset of persistent ps aer or censored age: 20', 'age of onset of persistent ps aer or censored age: 9', 'age of onset of persistent ps aer or censored age: 10', 'age of onset of persistent ps aer or censored age: 28', 'age of onset of persistent ps aer or censored age: 7', 'age of onset of persistent ps aer or censored age: 11'], 6: ['meconium ileus status: No', 'meconium ileus status: Yes', 'meconium ileus status: UNKNOWN'], 7: ['genotype pc1: 0.0245', 'genotype pc1: -0.0236', 'genotype pc1: -0.0024', 'genotype pc1: -0.0055', 'genotype pc1: -0.0065', 'genotype pc1: -0.0079', 'genotype pc1: -0.0207', 'genotype pc1: 0.055', 'genotype pc1: -0.0229', 'genotype pc1: -0.0036', 'genotype pc1: -0.0119', 'genotype pc1: 0.0127', 'genotype pc1: -0.0002', 'genotype pc1: 0.0823', 'genotype pc1: -0.014', 'genotype pc1: -0.0009', 'genotype pc1: 0.0278', 'genotype pc1: -0.0165', 'genotype pc1: -0.0122', 'genotype pc1: -0.0077', 'genotype pc1: -0.0193', 'genotype pc1: -0.0221', 'genotype pc1: 0.0994', 'genotype pc1: -0.0145', 'genotype pc1: -0.0233', 'genotype pc1: -0.0149', 'genotype pc1: -0.0033', 'genotype pc1: 0.0435', 'genotype pc1: -0.0531', 'genotype pc1: -0.0057'], 8: ['genotype pc2: -0.0369', 'genotype pc2: -0.0304', 'genotype pc2: 0.0001', 'genotype pc2: 0.011', 'genotype pc2: -0.0039', 'genotype pc2: -0.014', 'genotype pc2: 0.033', 'genotype pc2: -0.0112', 'genotype pc2: 0.0169', 'genotype pc2: -0.0375', 'genotype pc2: -0.006', 'genotype pc2: -0.0301', 'genotype pc2: -0.0047', 'genotype pc2: -0.0084', 'genotype pc2: 0.0105', 'genotype pc2: 0.0198', 'genotype pc2: -0.0247', 'genotype pc2: -0.0099', 'genotype pc2: -0.0219', 'genotype pc2: 0.006', 'genotype pc2: 0.0265', 'genotype pc2: 0.012', 'genotype pc2: -0.0288', 'genotype pc2: 0.023', 'genotype pc2: 0.0059', 'genotype pc2: 0.0284', 'genotype pc2: -0.0013', 'genotype pc2: 0.0154', 'genotype pc2: -0.0225', 'genotype pc2: 0.0387'], 9: ['genotype pc3: -0.0153', 'genotype pc3: 0.0064', 'genotype pc3: 0.0051', 'genotype pc3: -0.0438', 'genotype pc3: 0.013', 'genotype pc3: 0.0287', 'genotype pc3: -0.0004', 'genotype pc3: 0.0398', 'genotype pc3: -0.0183', 'genotype pc3: 0.0084', 'genotype pc3: -0.0125', 'genotype pc3: -0.0464', 'genotype pc3: 0.0132', 'genotype pc3: 0.0004', 'genotype pc3: 0', 'genotype pc3: -0.0216', 'genotype pc3: 0.0198', 'genotype pc3: -0.0172', 'genotype pc3: -0.0096', 'genotype pc3: -0.0283', 'genotype pc3: 0.01', 'genotype pc3: -0.0174', 'genotype pc3: -0.0015', 'genotype pc3: 0.0073', 'genotype pc3: -0.0337', 'genotype pc3: 0.0023', 'genotype pc3: -0.0091', 'genotype pc3: -0.0151', 'genotype pc3: -0.0273', 'genotype pc3: -0.0185'], 10: ['genotype pc4: 0.0321', 'genotype pc4: -0.0008', 'genotype pc4: 0.014', 'genotype pc4: 0.0225', 'genotype pc4: 0.0116', 'genotype pc4: 0.0245', 'genotype pc4: -0.0633', 'genotype pc4: -0.003', 'genotype pc4: 0.0182', 'genotype pc4: -0.0184', 'genotype pc4: 0.006', 'genotype pc4: -0.0055', 'genotype pc4: 0.0137', 'genotype pc4: 0.0415', 'genotype pc4: 0.009', 'genotype pc4: 0.0231', 'genotype pc4: 0.0268', 'genotype pc4: -0.0271', 'genotype pc4: -0.0013', 'genotype pc4: 0.0369', 'genotype pc4: -0.0178', 'genotype pc4: -0.0079', 'genotype pc4: 0.0083', 'genotype pc4: -0.0157', 'genotype pc4: -0.0327', 'genotype pc4: 0.0164', 'genotype pc4: 0.0279', 'genotype pc4: -0.0533', 'genotype pc4: -0.0138', 'genotype pc4: 0.0208'], 11: ['genotype pc5: 0.0402', 'genotype pc5: -0.0199', 'genotype pc5: -0.0068', 'genotype pc5: 0.0167', 'genotype pc5: 0.0053', 'genotype pc5: -0.0388', 'genotype pc5: -0.0093', 'genotype pc5: -0.041', 'genotype pc5: -0.0324', 'genotype pc5: 0.0023', 'genotype pc5: -0.0036', 'genotype pc5: 0.0158', 'genotype pc5: -0.0897', 'genotype pc5: 0.0379', 'genotype pc5: 0.0564', 'genotype pc5: 0.015', 'genotype pc5: -0.0433', 'genotype pc5: 0.0431', 'genotype pc5: -0.0179', 'genotype pc5: -0.0184', 'genotype pc5: 0.0287', 'genotype pc5: -0.0033', 'genotype pc5: -0.0165', 'genotype pc5: -0.019', 'genotype pc5: -0.014', 'genotype pc5: 0.0111', 'genotype pc5: 0.0392', 'genotype pc5: 0.0098', 'genotype pc5: -0.0067', 'genotype pc5: 0.0245'], 12: ['genotype pc6: 0.0132', 'genotype pc6: -0.017', 'genotype pc6: 0.0118', 'genotype pc6: 0.0442', 'genotype pc6: 0.0365', 'genotype pc6: 0.0007', 'genotype pc6: -0.012', 'genotype pc6: -0.0024', 'genotype pc6: -0.0202', 'genotype pc6: 0.0079', 'genotype pc6: 0.0053', 'genotype pc6: -0.0166', 'genotype pc6: 0.0412', 'genotype pc6: 0.0182', 'genotype pc6: -0.0021', 'genotype pc6: 0.0136', 'genotype pc6: 0.0059', 'genotype pc6: 0.0211', 'genotype pc6: -0.035', 'genotype pc6: 0.0051', 'genotype pc6: -0.0129', 'genotype pc6: 0.0187', 'genotype pc6: 0.0128', 'genotype pc6: 0.0607', 'genotype pc6: 0.0028', 'genotype pc6: -0.0259', 'genotype pc6: 0.0374', 'genotype pc6: -0.036', 'genotype pc6: 0.0449', 'genotype pc6: -0.0363'], 13: ['genotype pc7: 0.0231', 'genotype pc7: -0.0408', 'genotype pc7: 0.0046', 'genotype pc7: -0.0074', 'genotype pc7: 0.0261', 'genotype pc7: -0.0025', 'genotype pc7: -0.0273', 'genotype pc7: 0.0293', 'genotype pc7: -0.0176', 'genotype pc7: -0.0331', 'genotype pc7: 0.0249', 'genotype pc7: 0.0045', 'genotype pc7: -0.0775', 'genotype pc7: 0.0422', 'genotype pc7: 0.0187', 'genotype pc7: -0.0164', 'genotype pc7: 0.0087', 'genotype pc7: 0.0171', 'genotype pc7: 0.0081', 'genotype pc7: -0.0216', 'genotype pc7: -0.0114', 'genotype pc7: -0.0096', 'genotype pc7: 0.0136', 'genotype pc7: 0.0518', 'genotype pc7: 0.016', 'genotype pc7: -0.0022', 'genotype pc7: 0.0109', 'genotype pc7: 0.0338', 'genotype pc7: -0.0209', 'genotype pc7: -0.0515'], 14: ['plate: 1', 'plate: 2', 'plate: 3', 'plate: 4', 'plate: 5', 'plate: 6', 'plate: 7', 'plate: 8', 'plate: 9', 'plate: 10', 'plate: 11'], 15: ['consortium lung phenotype surrogate variable: -0.007666824', 'consortium lung phenotype surrogate variable: 0.034873757', 'consortium lung phenotype surrogate variable: 0.042322659', 'consortium lung phenotype surrogate variable: -0.019835408', 'consortium lung phenotype surrogate variable: 0.014540293', 'consortium lung phenotype surrogate variable: 0.033267948', 'consortium lung phenotype surrogate variable: -0.007735849', 'consortium lung phenotype surrogate variable: 0.002391609', 'consortium lung phenotype surrogate variable: -0.027495632', 'consortium lung phenotype surrogate variable: 0.028345537', 'consortium lung phenotype surrogate variable: -0.039899205', 'consortium lung phenotype surrogate variable: 0.024014483', 'consortium lung phenotype surrogate variable: -0.039072979', 'consortium lung phenotype surrogate variable: 0.025505444', 'consortium lung phenotype surrogate variable: -0.080515612', 'consortium lung phenotype surrogate variable: -0.051896794', 'consortium lung phenotype surrogate variable: -0.065684118', 'consortium lung phenotype surrogate variable: 0.016629621', 'consortium lung phenotype surrogate variable: 0.015330356', 'consortium lung phenotype surrogate variable: 0.009777207', 'consortium lung phenotype surrogate variable: -0.038826792', 'consortium lung phenotype surrogate variable: 0.012684366', 'consortium lung phenotype surrogate variable: 0.011989911', 'consortium lung phenotype surrogate variable: 0.012664639', 'consortium lung phenotype surrogate variable: 0.024951683', 'consortium lung phenotype surrogate variable: -0.006402057', 'consortium lung phenotype surrogate variable: 0.0191642', 'consortium lung phenotype surrogate variable: -0.008777918', 'consortium lung phenotype surrogate variable: 0.011153824', 'consortium lung phenotype surrogate variable: -0.008548007'], 16: ['pseudomonas aeruginosa surrogate variable 1: -0.006474146', 'pseudomonas aeruginosa surrogate variable 1: 0.045926197', 'pseudomonas aeruginosa surrogate variable 1: 0.053951823', 'pseudomonas aeruginosa surrogate variable 1: -0.022694379', 'meconium ileus surrogate variable 1: 0.014932598', 'pseudomonas aeruginosa surrogate variable 1: 0.042960438', 'meconium ileus surrogate variable 1: -0.006839056', 'pseudomonas aeruginosa surrogate variable 1: 0.004742906', 'pseudomonas aeruginosa surrogate variable 1: -0.033807162', 'meconium ileus surrogate variable 1: 0.02863847', 'pseudomonas aeruginosa surrogate variable 1: -0.045141616', 'pseudomonas aeruginosa surrogate variable 1: 0.03191877', 'pseudomonas aeruginosa surrogate variable 1: -0.045991894', 'pseudomonas aeruginosa surrogate variable 1: 0.037435759', 'pseudomonas aeruginosa surrogate variable 1: -0.099047062', 'meconium ileus surrogate variable 1: -0.051591385', 'pseudomonas aeruginosa surrogate variable 1: -0.078504781', 'pseudomonas aeruginosa surrogate variable 1: 0.020560644', 'pseudomonas aeruginosa surrogate variable 1: 0.022574507', 'pseudomonas aeruginosa surrogate variable 1: 0.015723838', 'meconium ileus surrogate variable 1: -0.037920814', 'pseudomonas aeruginosa surrogate variable 1: 0.015722162', 'meconium ileus surrogate variable 1: 0.011418511', 'meconium ileus surrogate variable 1: 0.012625291', 'pseudomonas aeruginosa surrogate variable 1: 0.031057644', 'meconium ileus surrogate variable 1: -0.006772336', 'pseudomonas aeruginosa surrogate variable 1: 0.028351724', 'meconium ileus surrogate variable 1: -0.00796125', 'pseudomonas aeruginosa surrogate variable 1: 0.016830311', 'pseudomonas aeruginosa surrogate variable 1: -0.011285192'], 17: ['meconium ileus surrogate variable 1: -0.007259556', 'meconium ileus surrogate variable 1: 0.035562995', 'meconium ileus surrogate variable 1: 0.041574357', 'meconium ileus surrogate variable 1: -0.020240499', 'meconium ileus surrogate variable 2: -0.030352802', 'meconium ileus surrogate variable 1: 0.032674446', 'meconium ileus surrogate variable 2: 0.045354696', 'meconium ileus surrogate variable 1: 0.002411729', 'meconium ileus surrogate variable 1: -0.028308101', 'meconium ileus surrogate variable 2: 0.043356511', 'meconium ileus surrogate variable 1: -0.039854241', 'meconium ileus surrogate variable 1: 0.023860011', 'meconium ileus surrogate variable 1: -0.039367619', 'meconium ileus surrogate variable 1: 0.025904872', 'meconium ileus surrogate variable 1: -0.080613051', 'meconium ileus surrogate variable 2: -0.025827481', 'meconium ileus surrogate variable 1: -0.065212665', 'meconium ileus surrogate variable 1: 0.015897934', 'meconium ileus surrogate variable 1: 0.015679656', 'meconium ileus surrogate variable 1: 0.00984179', 'meconium ileus surrogate variable 2: 0.027578387', 'meconium ileus surrogate variable 1: 0.01136519', 'meconium ileus surrogate variable 2: -0.036128236', 'meconium ileus surrogate variable 2: -0.035298795', 'meconium ileus surrogate variable 1: 0.025123616', 'meconium ileus surrogate variable 2: -0.031015884', 'meconium ileus surrogate variable 1: 0.019682345', 'meconium ileus surrogate variable 2: -0.036555365', 'meconium ileus surrogate variable 1: 0.011284547', 'meconium ileus surrogate variable 1: -0.00923367'], 18: ['meconium ileus surrogate variable 2: 0.04704748', 'meconium ileus surrogate variable 2: 0.036888174', 'meconium ileus surrogate variable 2: 0.040772015', 'meconium ileus surrogate variable 2: -0.02869714', 'meconium ileus surrogate variable 3: 0.015527635', 'meconium ileus surrogate variable 2: -0.030278696', 'meconium ileus surrogate variable 3: -0.071288719', 'meconium ileus surrogate variable 2: -0.032546195', 'meconium ileus surrogate variable 2: -0.03033024', 'meconium ileus surrogate variable 3: 0.034132217', 'meconium ileus surrogate variable 2: 0.041546903', 'meconium ileus surrogate variable 2: -0.035656587', 'meconium ileus surrogate variable 2: -0.033591713', 'meconium ileus surrogate variable 2: -0.035150683', 'meconium ileus surrogate variable 2: 0.044868885', 'meconium ileus surrogate variable 3: -0.030840542', 'meconium ileus surrogate variable 2: -0.02871954', 'meconium ileus surrogate variable 2: 0.040118755', 'meconium ileus surrogate variable 2: -0.034120281', 'meconium ileus surrogate variable 2: 0.041626045', 'meconium ileus surrogate variable 3: 0.019030471', 'meconium ileus surrogate variable 2: 0.046601608', 'meconium ileus surrogate variable 3: -0.020213695', 'meconium ileus surrogate variable 3: -0.055550766', 'meconium ileus surrogate variable 2: 0.036155343', 'meconium ileus surrogate variable 3: 0.01970194', 'meconium ileus surrogate variable 2: 0.040452182', 'meconium ileus surrogate variable 3: -0.047582576', 'meconium ileus surrogate variable 2: -0.025403174', 'meconium ileus surrogate variable 2: -0.034264077'], 19: ['meconium ileus surrogate variable 3: -0.042906917', 'meconium ileus surrogate variable 3: 0.042291829', 'meconium ileus surrogate variable 3: 0.003895659', 'meconium ileus surrogate variable 3: -0.022803753', 'meconium ileus surrogate variable 4: -0.038303562', 'meconium ileus surrogate variable 3: -0.011523139', 'meconium ileus surrogate variable 4: -0.048308051', 'meconium ileus surrogate variable 3: -0.002448346', 'meconium ileus surrogate variable 3: -0.007995854', 'meconium ileus surrogate variable 4: -0.028732199', 'meconium ileus surrogate variable 3: -0.0363941', 'meconium ileus surrogate variable 3: 0.00744259', 'meconium ileus surrogate variable 3: -0.009686904', 'meconium ileus surrogate variable 3: -0.065752441', 'meconium ileus surrogate variable 3: -0.008836405', 'meconium ileus surrogate variable 4: -0.027858948', 'meconium ileus surrogate variable 3: -0.027624756', 'meconium ileus surrogate variable 3: 0.024199555', 'meconium ileus surrogate variable 3: -0.057226107', 'meconium ileus surrogate variable 3: -0.047981035', 'meconium ileus surrogate variable 4: -0.036422339', 'meconium ileus surrogate variable 3: 0.026022201', 'meconium ileus surrogate variable 4: -0.001507287', 'meconium ileus surrogate variable 4: -0.036383887', 'meconium ileus surrogate variable 3: 0.039841907', 'meconium ileus surrogate variable 4: -0.064630994', 'meconium ileus surrogate variable 3: -0.046326633', 'meconium ileus surrogate variable 4: 0.03902113', 'meconium ileus surrogate variable 3: -0.02623294', 'meconium ileus surrogate variable 3: -0.006735359'], 20: ['meconium ileus surrogate variable 4: -0.002479522', 'meconium ileus surrogate variable 4: -0.012934442', 'meconium ileus surrogate variable 4: 0.045819189', 'meconium ileus surrogate variable 4: -0.06646753', 'meconium ileus surrogate variable 5: 0.02509852', 'meconium ileus surrogate variable 4: -0.044316698', 'meconium ileus surrogate variable 5: 0.024370194', 'meconium ileus surrogate variable 4: -0.092786706', 'meconium ileus surrogate variable 4: -0.079987325', 'meconium ileus surrogate variable 5: 0.060722177', 'meconium ileus surrogate variable 4: -0.003729546', 'meconium ileus surrogate variable 4: -0.026948089', 'meconium ileus surrogate variable 4: -0.011213126', 'meconium ileus surrogate variable 4: 0.011746922', 'meconium ileus surrogate variable 4: -0.054551354', 'meconium ileus surrogate variable 5: 0.081687296', 'meconium ileus surrogate variable 4: -0.028863621', 'meconium ileus surrogate variable 4: -0.015774071', 'meconium ileus surrogate variable 4: 0.018055929', 'meconium ileus surrogate variable 4: 0.017996933', 'meconium ileus surrogate variable 5: 0.045572709', 'meconium ileus surrogate variable 4: -0.101609503', 'meconium ileus surrogate variable 5: 0.00946913', 'meconium ileus surrogate variable 5: 0.020666795', 'meconium ileus surrogate variable 4: -0.021234742', 'meconium ileus surrogate variable 5: 0.070536904', 'meconium ileus surrogate variable 4: -0.022114389', 'meconium ileus surrogate variable 5: 0.037903237', 'meconium ileus surrogate variable 4: -0.061555444', 'meconium ileus surrogate variable 4: -0.026691223'], 21: ['meconium ileus surrogate variable 5: 0.070743301', 'meconium ileus surrogate variable 5: 0.022315193', 'meconium ileus surrogate variable 5: 0.044520431', 'meconium ileus surrogate variable 5: 0.030849078', 'meconium ileus surrogate variable 6: -0.013039097', 'meconium ileus surrogate variable 5: 0.025417257', 'meconium ileus surrogate variable 6: -0.098987223', 'meconium ileus surrogate variable 5: -0.001865049', 'meconium ileus surrogate variable 5: 0.01449101', 'meconium ileus surrogate variable 6: -0.021497686', 'meconium ileus surrogate variable 5: 0.022392449', 'meconium ileus surrogate variable 5: 0.052825271', 'meconium ileus surrogate variable 5: 0.132617496', 'meconium ileus surrogate variable 5: 0.013028918', 'meconium ileus surrogate variable 5: 0.019759143', 'meconium ileus surrogate variable 6: -0.058088641', 'meconium ileus surrogate variable 5: 0.063646558', 'meconium ileus surrogate variable 5: 0.054621474', 'meconium ileus surrogate variable 5: 0.018194809', 'meconium ileus surrogate variable 5: 0.001566891', 'meconium ileus surrogate variable 6: 0.011454368', 'meconium ileus surrogate variable 5: -0.046768364', 'meconium ileus surrogate variable 6: -0.021606167', 'meconium ileus surrogate variable 6: 0.001518027', 'meconium ileus surrogate variable 5: 0.080213238', 'meconium ileus surrogate variable 6: -0.024250195', 'meconium ileus surrogate variable 5: -0.001685017', 'meconium ileus surrogate variable 6: 0.02429084', 'meconium ileus surrogate variable 5: -0.027434641', 'meconium ileus surrogate variable 5: 0.042755379'], 22: ['meconium ileus surrogate variable 6: -0.029433061', 'meconium ileus surrogate variable 6: 0.011176869', 'meconium ileus surrogate variable 6: 0.006397831', 'meconium ileus surrogate variable 6: 0.009434544', 'meconium ileus surrogate variable 7: -0.064958909', 'meconium ileus surrogate variable 6: -0.026793306', 'meconium ileus surrogate variable 7: 0.004429269', 'meconium ileus surrogate variable 6: 0.035594776', 'meconium ileus surrogate variable 6: 0.009179052', 'meconium ileus surrogate variable 7: -0.047986024', 'meconium ileus surrogate variable 6: 0.021841134', 'meconium ileus surrogate variable 6: -0.00414369', 'meconium ileus surrogate variable 6: -0.037886459', 'meconium ileus surrogate variable 6: 0.006537276', 'meconium ileus surrogate variable 6: 0.072791854', 'meconium ileus surrogate variable 7: 0.011707649', 'meconium ileus surrogate variable 6: -0.013100834', 'meconium ileus surrogate variable 6: -0.012979994', 'meconium ileus surrogate variable 6: 0.027211948', 'meconium ileus surrogate variable 6: 0.035990148', 'meconium ileus surrogate variable 7: 0.010667192', 'meconium ileus surrogate variable 6: -0.000707387', 'meconium ileus surrogate variable 7: 0.002814865', 'meconium ileus surrogate variable 7: 0.07142213', 'meconium ileus surrogate variable 6: -0.002341684', 'meconium ileus surrogate variable 7: -0.020477913', 'meconium ileus surrogate variable 6: -0.013903906', 'meconium ileus surrogate variable 7: 0.011767712', 'meconium ileus surrogate variable 6: 0.023193247', 'meconium ileus surrogate variable 6: -0.014499269'], 23: ['meconium ileus surrogate variable 7: 0.059670721', 'meconium ileus surrogate variable 7: -0.014615113', 'meconium ileus surrogate variable 7: -0.01437584', 'meconium ileus surrogate variable 7: 0.079091286', 'meconium ileus surrogate variable 8: 0.025545595', 'meconium ileus surrogate variable 7: 0.012200915', 'meconium ileus surrogate variable 8: 0.013481208', 'meconium ileus surrogate variable 7: 0.043113135', 'meconium ileus surrogate variable 7: 0.077275428', 'meconium ileus surrogate variable 8: -0.005923367', 'meconium ileus surrogate variable 7: -0.035261318', 'meconium ileus surrogate variable 7: 0.016757963', 'meconium ileus surrogate variable 7: 0.01035876', 'meconium ileus surrogate variable 7: 0.013132081', 'meconium ileus surrogate variable 7: 0.069522855', 'meconium ileus surrogate variable 8: -0.026176429', 'meconium ileus surrogate variable 7: -0.030367621', 'meconium ileus surrogate variable 7: -0.002171803', 'meconium ileus surrogate variable 7: 0.003521297', 'meconium ileus surrogate variable 7: 0.008030826', 'meconium ileus surrogate variable 8: -0.011098935', 'meconium ileus surrogate variable 7: -0.031264846', 'meconium ileus surrogate variable 8: 0.043771454', 'meconium ileus surrogate variable 8: -0.069168167', 'meconium ileus surrogate variable 7: -0.012051044', 'meconium ileus surrogate variable 8: -0.014415022', 'meconium ileus surrogate variable 7: 0.027485061', 'meconium ileus surrogate variable 8: 0.011505508', 'meconium ileus surrogate variable 7: -0.003195995', 'meconium ileus surrogate variable 7: -0.019870282'], 24: ['meconium ileus surrogate variable 8: -0.011348177', 'meconium ileus surrogate variable 8: 0.027284669', 'meconium ileus surrogate variable 8: 0.014914093', 'meconium ileus surrogate variable 8: 0.044945759', 'meconium ileus surrogate variable 9: 0.065640376', 'meconium ileus surrogate variable 8: -0.017487673', 'meconium ileus surrogate variable 9: -0.019172405', 'meconium ileus surrogate variable 8: -0.021666678', 'meconium ileus surrogate variable 8: 0.085729085', 'meconium ileus surrogate variable 9: 0.021607981', 'meconium ileus surrogate variable 8: 0.037372774', 'meconium ileus surrogate variable 8: 0.004743801', 'meconium ileus surrogate variable 8: -0.013716264', 'meconium ileus surrogate variable 8: -0.015298715', 'meconium ileus surrogate variable 8: 0.074949817', 'meconium ileus surrogate variable 9: 0.028439879', 'meconium ileus surrogate variable 8: 0.048475058', 'meconium ileus surrogate variable 8: 0.009560071', 'meconium ileus surrogate variable 8: -0.078917822', 'meconium ileus surrogate variable 8: -0.006340655', 'meconium ileus surrogate variable 9: 0.043012811', 'meconium ileus surrogate variable 8: -0.042487992', 'meconium ileus surrogate variable 9: -0.021579328', 'meconium ileus surrogate variable 9: 0.008108035', 'meconium ileus surrogate variable 8: -0.051673512', 'meconium ileus surrogate variable 9: -0.01315019', 'meconium ileus surrogate variable 8: -0.013965427', 'meconium ileus surrogate variable 9: -0.049912317', 'meconium ileus surrogate variable 8: -0.069530421', 'meconium ileus surrogate variable 8: -0.02914925'], 25: ['meconium ileus surrogate variable 9: 0.06776575', 'meconium ileus surrogate variable 9: 0.083477176', 'meconium ileus surrogate variable 9: -0.053887761', 'meconium ileus surrogate variable 9: 0.002841287', 'meconium ileus surrogate variable 10: -0.023015628', 'meconium ileus surrogate variable 9: -0.040050095', 'meconium ileus surrogate variable 10: -0.024684259', 'meconium ileus surrogate variable 9: 0.02681684', 'meconium ileus surrogate variable 9: 0.006930392', 'meconium ileus surrogate variable 10: -0.04187222', 'meconium ileus surrogate variable 9: -0.008389812', 'meconium ileus surrogate variable 9: -0.041827173', 'meconium ileus surrogate variable 9: -0.025257532', 'meconium ileus surrogate variable 9: 0.021103097', 'meconium ileus surrogate variable 9: -0.024277029', 'meconium ileus surrogate variable 10: 0.044837718', 'meconium ileus surrogate variable 9: 0.002060787', 'meconium ileus surrogate variable 9: 0.038863346', 'meconium ileus surrogate variable 9: 0.010449287', 'meconium ileus surrogate variable 9: -0.005826962', 'meconium ileus surrogate variable 10: 0.017863514', 'meconium ileus surrogate variable 9: 0.023154473', 'meconium ileus surrogate variable 10: 0.018558621', 'meconium ileus surrogate variable 10: -0.020759905', 'meconium ileus surrogate variable 9: 0.009007212', 'meconium ileus surrogate variable 10: -0.018053518', 'meconium ileus surrogate variable 9: -0.000347424', 'meconium ileus surrogate variable 10: 0.01884706', 'meconium ileus surrogate variable 9: 0.024381123', 'meconium ileus surrogate variable 9: 0.037999912'], 26: ['meconium ileus surrogate variable 10: -0.035847231', 'meconium ileus surrogate variable 10: -0.044129324', 'meconium ileus surrogate variable 10: -0.003154707', 'meconium ileus surrogate variable 10: -0.019363918', 'meconium ileus surrogate variable 11: 0.013379262', 'meconium ileus surrogate variable 10: 0.038841561', 'meconium ileus surrogate variable 11: 0.036712134', 'meconium ileus surrogate variable 10: -0.00044391', 'meconium ileus surrogate variable 10: 0.003097939', 'meconium ileus surrogate variable 11: 0.014872321', 'meconium ileus surrogate variable 10: 0.016867937', 'meconium ileus surrogate variable 10: 0.010914222', 'meconium ileus surrogate variable 10: -0.005616023', 'meconium ileus surrogate variable 10: 0.04514386', 'meconium ileus surrogate variable 10: 0.008568568', 'meconium ileus surrogate variable 11: 0.015039785', 'meconium ileus surrogate variable 10: 0.01683823', 'meconium ileus surrogate variable 10: -0.003422554', 'meconium ileus surrogate variable 10: 0.022145686', 'meconium ileus surrogate variable 10: 0.041597074', 'meconium ileus surrogate variable 11: 0.022702348', 'meconium ileus surrogate variable 10: -0.001927848', 'meconium ileus surrogate variable 11: 0.026634625', 'meconium ileus surrogate variable 11: 0.008438625', 'meconium ileus surrogate variable 10: -0.031039349', 'meconium ileus surrogate variable 11: 0.018590554', 'meconium ileus surrogate variable 10: -0.011807237', 'meconium ileus surrogate variable 11: 0.02252415', 'meconium ileus surrogate variable 10: 0.104856541', 'meconium ileus surrogate variable 10: 0.024583878'], 27: ['meconium ileus surrogate variable 11: 0.011902911', 'meconium ileus surrogate variable 11: 0.027260851', 'meconium ileus surrogate variable 11: -0.049970745', 'meconium ileus surrogate variable 11: 0.055660568', 'meconium ileus surrogate variable 12: -0.093855724', 'meconium ileus surrogate variable 11: 0.020160363', 'meconium ileus surrogate variable 12: 0.025596904', 'meconium ileus surrogate variable 11: 0.033540893', 'meconium ileus surrogate variable 11: -0.070781941', 'meconium ileus surrogate variable 12: -0.035549538', 'meconium ileus surrogate variable 11: 0.019757518', 'meconium ileus surrogate variable 11: 0.005257067', 'meconium ileus surrogate variable 11: -0.052433395', 'meconium ileus surrogate variable 11: -0.007424559', 'meconium ileus surrogate variable 11: 0.000863609', 'meconium ileus surrogate variable 12: -0.028441815', 'meconium ileus surrogate variable 11: 0.01898962', 'meconium ileus surrogate variable 11: -0.007064184', 'meconium ileus surrogate variable 11: 0.011002651', 'meconium ileus surrogate variable 11: -0.070270421', 'meconium ileus surrogate variable 12: -0.020210162', 'meconium ileus surrogate variable 11: -0.062866725', 'meconium ileus surrogate variable 12: -0.046306498', 'meconium ileus surrogate variable 12: -0.034464707', 'meconium ileus surrogate variable 11: 0.004978503', 'meconium ileus surrogate variable 12: 0.019830429', 'meconium ileus surrogate variable 11: 0.027340228', 'meconium ileus surrogate variable 12: -0.001049948', 'meconium ileus surrogate variable 11: -0.003453994', 'meconium ileus surrogate variable 11: -0.011949324'], 28: ['meconium ileus surrogate variable 12: -0.032603014', 'meconium ileus surrogate variable 12: 0.041347488', 'meconium ileus surrogate variable 12: -0.092192962', 'meconium ileus surrogate variable 12: 0.006123792', 'meconium ileus surrogate variable 13: 0.030657352', 'meconium ileus surrogate variable 12: -0.045521337', 'meconium ileus surrogate variable 13: -0.045538586', 'meconium ileus surrogate variable 12: -0.010659068', 'meconium ileus surrogate variable 12: 0.005567125', 'meconium ileus surrogate variable 13: -0.060506929', 'meconium ileus surrogate variable 12: -0.005489816', 'meconium ileus surrogate variable 12: -0.006328213', 'meconium ileus surrogate variable 12: 0.006085812', 'meconium ileus surrogate variable 12: 0.026481574', 'meconium ileus surrogate variable 12: 0.002018392', 'meconium ileus surrogate variable 13: -0.022945292', 'meconium ileus surrogate variable 12: 0.003085823', 'meconium ileus surrogate variable 12: -0.065232953', 'meconium ileus surrogate variable 12: -0.027479599', 'meconium ileus surrogate variable 12: -0.018153543', 'meconium ileus surrogate variable 13: 0.088150667', 'meconium ileus surrogate variable 12: -0.162622313', 'meconium ileus surrogate variable 13: 0.038012466', 'meconium ileus surrogate variable 13: -0.020211715', 'meconium ileus surrogate variable 12: 0.044194789', 'meconium ileus surrogate variable 13: 0.048635926', 'meconium ileus surrogate variable 12: 0.043499952', 'meconium ileus surrogate variable 13: -0.053173114', 'meconium ileus surrogate variable 12: 0.001024819', 'meconium ileus surrogate variable 12: -0.066789885'], 29: ['meconium ileus surrogate variable 13: 0.000279458', 'meconium ileus surrogate variable 13: 0.002882449', 'meconium ileus surrogate variable 13: -0.034693302', 'meconium ileus surrogate variable 13: 0.083227899', 'meconium ileus surrogate variable 14: 0.023465259', 'meconium ileus surrogate variable 13: -0.055278445', 'meconium ileus surrogate variable 14: 0.048381577', 'meconium ileus surrogate variable 13: -0.06581775', 'meconium ileus surrogate variable 13: 0.005882539', 'meconium ileus surrogate variable 14: -0.006079553', 'meconium ileus surrogate variable 13: -0.03315172', 'meconium ileus surrogate variable 13: 0.040131858', 'meconium ileus surrogate variable 13: -0.003260951', 'meconium ileus surrogate variable 13: -0.026683469', 'meconium ileus surrogate variable 13: 0.043851587', 'meconium ileus surrogate variable 14: -0.003659751', 'meconium ileus surrogate variable 13: 0.002988096', 'meconium ileus surrogate variable 13: -0.035961169', 'meconium ileus surrogate variable 13: -0.01822632', 'meconium ileus surrogate variable 13: -0.086637411', 'meconium ileus surrogate variable 14: 0.117347147', 'meconium ileus surrogate variable 13: 0.020868551', 'meconium ileus surrogate variable 14: 0.025396625', 'meconium ileus surrogate variable 14: -0.023860644', 'meconium ileus surrogate variable 13: -0.004067736', 'meconium ileus surrogate variable 14: -0.018288402', 'meconium ileus surrogate variable 13: -0.015580485', 'meconium ileus surrogate variable 14: -0.025274012', 'meconium ileus surrogate variable 13: -0.010689642', 'meconium ileus surrogate variable 13: -0.045459856'], 30: ['meconium ileus surrogate variable 14: 0.018835624', 'meconium ileus surrogate variable 14: 0.021366235', 'meconium ileus surrogate variable 14: 0.027513853', 'meconium ileus surrogate variable 14: 0.150448573', 'meconium ileus surrogate variable 15: 0.034161924', 'meconium ileus surrogate variable 14: -0.001467058', 'meconium ileus surrogate variable 15: 0.050442386', 'meconium ileus surrogate variable 14: 0.022378603', 'meconium ileus surrogate variable 14: -0.060551351', 'meconium ileus surrogate variable 15: 0.000464121', 'meconium ileus surrogate variable 14: 0.013607407', 'meconium ileus surrogate variable 14: 0.014409375', 'meconium ileus surrogate variable 14: -0.026178738', 'meconium ileus surrogate variable 14: 0.025851615', 'meconium ileus surrogate variable 14: 0.029211502', 'meconium ileus surrogate variable 15: 0.023514481', 'meconium ileus surrogate variable 14: 0.024388265', 'meconium ileus surrogate variable 14: -0.013905566', 'meconium ileus surrogate variable 14: 0.05139835', 'meconium ileus surrogate variable 14: 0.025424861', 'meconium ileus surrogate variable 15: -0.035958889', 'meconium ileus surrogate variable 14: 0.021108904', 'meconium ileus surrogate variable 15: -0.017425988', 'meconium ileus surrogate variable 15: 0.00464061', 'meconium ileus surrogate variable 14: -0.002331169', 'meconium ileus surrogate variable 15: 0.017339792', 'meconium ileus surrogate variable 14: -0.001669722', 'meconium ileus surrogate variable 15: -8.22e-05', 'meconium ileus surrogate variable 14: 0.022571098', 'meconium ileus surrogate variable 14: -0.0150495'], 31: ['meconium ileus surrogate variable 15: -0.042837703', 'meconium ileus surrogate variable 15: 0.030943762', 'meconium ileus surrogate variable 15: -0.023413509', 'meconium ileus surrogate variable 15: -0.020250735', 'meconium ileus surrogate variable 16: -0.030836236', 'meconium ileus surrogate variable 15: -0.012303689', 'meconium ileus surrogate variable 16: 0.018568614', 'meconium ileus surrogate variable 15: 0.070523372', 'meconium ileus surrogate variable 15: -0.080291033', 'meconium ileus surrogate variable 16: -0.01237048', 'meconium ileus surrogate variable 15: -0.058802227', 'meconium ileus surrogate variable 15: -0.088964548', 'meconium ileus surrogate variable 15: 0.021106102', 'meconium ileus surrogate variable 15: -0.02103754', 'meconium ileus surrogate variable 15: -0.042017043', 'meconium ileus surrogate variable 16: 0.003742721', 'meconium ileus surrogate variable 15: 0.019895276', 'meconium ileus surrogate variable 15: 0.021763727', 'meconium ileus surrogate variable 15: -0.001674842', 'meconium ileus surrogate variable 15: 0.014347824', 'meconium ileus surrogate variable 16: 0.009638901', 'meconium ileus surrogate variable 15: 0.024302641', 'meconium ileus surrogate variable 16: 0.049491721', 'meconium ileus surrogate variable 16: -0.008570991', 'meconium ileus surrogate variable 15: 0.020218176', 'meconium ileus surrogate variable 16: -0.004954029', 'meconium ileus surrogate variable 15: 0.009176281', 'meconium ileus surrogate variable 16: -0.009297229', 'meconium ileus surrogate variable 15: -0.04497447', 'meconium ileus surrogate variable 15: -0.002693968'], 32: ['meconium ileus surrogate variable 16: -0.029363761', 'meconium ileus surrogate variable 16: 0.004852692', 'meconium ileus surrogate variable 16: 0.029658774', 'meconium ileus surrogate variable 16: 0.022073899', 'meconium ileus surrogate variable 17: -0.000311039', 'meconium ileus surrogate variable 16: -0.028628881', 'meconium ileus surrogate variable 17: -0.0425142', 'meconium ileus surrogate variable 16: 0.039868741', 'meconium ileus surrogate variable 16: -0.077555818', 'meconium ileus surrogate variable 17: 0.021923316', 'meconium ileus surrogate variable 16: 0.043000664', 'meconium ileus surrogate variable 16: -0.009183631', 'meconium ileus surrogate variable 16: 0.060575665', 'meconium ileus surrogate variable 16: -0.038448711', 'meconium ileus surrogate variable 16: -0.045343016', 'meconium ileus surrogate variable 17: 0.016773865', 'meconium ileus surrogate variable 16: -0.009866777', 'meconium ileus surrogate variable 16: 0.003758217', 'meconium ileus surrogate variable 16: -0.048885854', 'meconium ileus surrogate variable 16: -0.011927657', 'meconium ileus surrogate variable 17: 0.015646169', 'meconium ileus surrogate variable 16: 0.02636236', 'meconium ileus surrogate variable 17: -0.03104418', 'meconium ileus surrogate variable 17: 0.02960341', 'meconium ileus surrogate variable 16: -0.021778105', 'meconium ileus surrogate variable 17: 0.016368665', 'meconium ileus surrogate variable 16: 0.061135537', 'meconium ileus surrogate variable 17: 0.028022953', 'meconium ileus surrogate variable 16: 0.005505131', 'meconium ileus surrogate variable 16: 0.000395428'], 33: ['meconium ileus surrogate variable 17: 0.052859335', 'meconium ileus surrogate variable 17: 0.089621793', 'meconium ileus surrogate variable 17: -0.01137253', 'meconium ileus surrogate variable 17: -0.020612745', 'meconium ileus surrogate variable 18: 0.082787985', 'meconium ileus surrogate variable 17: 0.027201108', 'meconium ileus surrogate variable 18: -0.012988363', 'meconium ileus surrogate variable 17: 0.009692036', 'meconium ileus surrogate variable 17: -0.030235794', 'meconium ileus surrogate variable 18: 0.035828725', 'meconium ileus surrogate variable 17: -0.016867502', 'meconium ileus surrogate variable 17: 0.018767948', 'meconium ileus surrogate variable 17: 0.001206606', 'meconium ileus surrogate variable 17: -0.064299625', 'meconium ileus surrogate variable 17: 0.020464035', 'meconium ileus surrogate variable 18: -0.003156057', 'meconium ileus surrogate variable 17: 0.01600057', 'meconium ileus surrogate variable 17: 0.061622372', 'meconium ileus surrogate variable 17: 0.021635643', 'meconium ileus surrogate variable 17: -0.031724567', 'meconium ileus surrogate variable 18: -0.045486166', 'meconium ileus surrogate variable 17: 0.017397249', 'meconium ileus surrogate variable 18: 0.060251272', 'meconium ileus surrogate variable 18: -0.008392181', 'meconium ileus surrogate variable 17: -0.000521178', 'meconium ileus surrogate variable 18: 0.020119685', 'meconium ileus surrogate variable 17: -0.00609887', 'meconium ileus surrogate variable 18: -0.045847099', 'meconium ileus surrogate variable 17: -0.01120844', 'meconium ileus surrogate variable 17: 0.003961305'], 34: ['meconium ileus surrogate variable 18: -0.022230941', 'meconium ileus surrogate variable 18: 0.022108154', 'meconium ileus surrogate variable 18: 0.03801499', 'meconium ileus surrogate variable 18: 0.039908138', 'meconium ileus surrogate variable 19: 0.001357801', 'meconium ileus surrogate variable 18: -0.015862578', 'meconium ileus surrogate variable 19: 0.032033125', 'meconium ileus surrogate variable 18: -0.033567371', 'meconium ileus surrogate variable 18: -0.036823693', 'meconium ileus surrogate variable 19: 0.015217321', 'meconium ileus surrogate variable 18: -0.007793215', 'meconium ileus surrogate variable 18: -0.030581772', 'meconium ileus surrogate variable 18: 0.062646954', 'meconium ileus surrogate variable 18: 0.031391787', 'meconium ileus surrogate variable 18: 0.031951384', 'meconium ileus surrogate variable 19: -0.022674318', 'meconium ileus surrogate variable 18: -0.026298686', 'meconium ileus surrogate variable 18: -0.026063908', 'meconium ileus surrogate variable 18: 0.058272372', 'meconium ileus surrogate variable 18: -0.01249048', 'meconium ileus surrogate variable 19: -0.053727211', 'meconium ileus surrogate variable 18: 0.037271619', 'meconium ileus surrogate variable 19: -0.008713855', 'meconium ileus surrogate variable 19: -0.049351346', 'meconium ileus surrogate variable 18: 0.032566807', 'meconium ileus surrogate variable 19: -0.02824207', 'meconium ileus surrogate variable 18: -0.060526961', 'meconium ileus surrogate variable 19: -0.073259172', 'meconium ileus surrogate variable 18: 0.043236436', 'meconium ileus surrogate variable 18: 0.007875273'], 35: ['meconium ileus surrogate variable 19: 0.094673712', 'meconium ileus surrogate variable 19: -0.007872588', 'meconium ileus surrogate variable 19: 0.024791508', 'meconium ileus surrogate variable 19: -0.033650073', 'meconium ileus surrogate variable 20: 0.050740228', 'meconium ileus surrogate variable 19: -0.012510207', 'meconium ileus surrogate variable 20: -0.067587778', 'meconium ileus surrogate variable 19: 0.007562042', 'meconium ileus surrogate variable 19: -0.008062042', 'meconium ileus surrogate variable 20: -0.001030615', 'meconium ileus surrogate variable 19: 0.042039302', 'meconium ileus surrogate variable 19: 0.007859936', 'meconium ileus surrogate variable 19: 0.016517404', 'meconium ileus surrogate variable 19: -0.042588754', 'meconium ileus surrogate variable 19: -0.004745686', 'meconium ileus surrogate variable 20: 0.000569858', 'meconium ileus surrogate variable 19: 0.004518047', 'meconium ileus surrogate variable 19: -0.027441449', 'meconium ileus surrogate variable 19: 0.005208217', 'meconium ileus surrogate variable 19: -0.002089191', 'meconium ileus surrogate variable 20: 0.01233271', 'meconium ileus surrogate variable 19: 0.050750573', 'meconium ileus surrogate variable 20: -0.025389618', 'meconium ileus surrogate variable 20: -0.086374173', 'meconium ileus surrogate variable 19: 6.6e-05', 'meconium ileus surrogate variable 20: 0.056055597', 'meconium ileus surrogate variable 19: 0.004610336', 'meconium ileus surrogate variable 20: 0.028434853', 'meconium ileus surrogate variable 19: -0.074076367', 'meconium ileus surrogate variable 19: -0.008981818'], 36: ['meconium ileus surrogate variable 20: -0.027587126', 'meconium ileus surrogate variable 20: -0.033106277', 'meconium ileus surrogate variable 20: -0.049486378', 'meconium ileus surrogate variable 20: 0.097439331', 'meconium ileus surrogate variable 21: -0.084245236', 'meconium ileus surrogate variable 20: -0.028353419', 'meconium ileus surrogate variable 21: 0.003659287', 'meconium ileus surrogate variable 20: 0.009958408', 'meconium ileus surrogate variable 20: -0.015562764', 'meconium ileus surrogate variable 21: 0.018867216', 'meconium ileus surrogate variable 20: -0.035351918', 'meconium ileus surrogate variable 20: -0.042618006', 'meconium ileus surrogate variable 20: 0.057781115', 'meconium ileus surrogate variable 20: 0.042798535', 'meconium ileus surrogate variable 20: 0.000859891', 'meconium ileus surrogate variable 21: 0.045219346', 'meconium ileus surrogate variable 20: -0.042793313', 'meconium ileus surrogate variable 20: 0.029117151', 'meconium ileus surrogate variable 20: -0.035487329', 'meconium ileus surrogate variable 20: 0.038639266', 'meconium ileus surrogate variable 21: 0.019056261', 'meconium ileus surrogate variable 20: -0.02729532', 'meconium ileus surrogate variable 21: -0.001159551', 'meconium ileus surrogate variable 21: 0.029760953', 'meconium ileus surrogate variable 20: -0.073703805', 'meconium ileus surrogate variable 21: 0.021496803', 'meconium ileus surrogate variable 20: 0.008724422', 'meconium ileus surrogate variable 21: 0.036789245', 'meconium ileus surrogate variable 20: 0.007478542', 'meconium ileus surrogate variable 20: 0.005359433'], 37: ['meconium ileus surrogate variable 21: 0.008519579', 'meconium ileus surrogate variable 21: -0.002264658', 'meconium ileus surrogate variable 21: 0.025719769', 'meconium ileus surrogate variable 21: 0.052545614', 'meconium ileus surrogate variable 22: 0.001849799', 'meconium ileus surrogate variable 21: 0.003701947', 'meconium ileus surrogate variable 22: 0.047210968', 'meconium ileus surrogate variable 21: -0.064628034', 'meconium ileus surrogate variable 21: 0.062059945', 'meconium ileus surrogate variable 22: -0.015923313', 'meconium ileus surrogate variable 21: 0.033220445', 'meconium ileus surrogate variable 21: -0.012024833', 'meconium ileus surrogate variable 21: 0.016669435', 'meconium ileus surrogate variable 21: 0.004312071', 'meconium ileus surrogate variable 21: 0.015594218', 'meconium ileus surrogate variable 22: 0.009831084', 'meconium ileus surrogate variable 21: 0.04378624', 'meconium ileus surrogate variable 21: 0.004101531', 'meconium ileus surrogate variable 21: 0.002435568', 'meconium ileus surrogate variable 21: 0.001481432', 'meconium ileus surrogate variable 22: -0.020579291', 'meconium ileus surrogate variable 21: 0.083146454', 'meconium ileus surrogate variable 22: 0.04204285', 'meconium ileus surrogate variable 22: 0.077512624', 'meconium ileus surrogate variable 21: 0.033216266', 'meconium ileus surrogate variable 22: -0.017878192', 'meconium ileus surrogate variable 21: 0.021755438', 'meconium ileus surrogate variable 22: -0.008311413', 'meconium ileus surrogate variable 21: -0.00169153', 'meconium ileus surrogate variable 21: 0.002364753'], 38: ['meconium ileus surrogate variable 22: -0.033925752', 'meconium ileus surrogate variable 22: -0.008625904', 'meconium ileus surrogate variable 22: 0.004138045', 'meconium ileus surrogate variable 22: 0.045180914', 'meconium ileus surrogate variable 23: -0.021618832', 'meconium ileus surrogate variable 22: 0.014609966', 'meconium ileus surrogate variable 23: -0.01569482', 'meconium ileus surrogate variable 22: 0.078411867', 'meconium ileus surrogate variable 22: -0.117103393', 'meconium ileus surrogate variable 23: -0.037685491', 'meconium ileus surrogate variable 22: -0.031535277', 'meconium ileus surrogate variable 22: -0.029169765', 'meconium ileus surrogate variable 22: -0.017047484', 'meconium ileus surrogate variable 22: -0.015950207', 'meconium ileus surrogate variable 22: -0.021458144', 'meconium ileus surrogate variable 23: 0.005358981', 'meconium ileus surrogate variable 22: 0.030214929', 'meconium ileus surrogate variable 22: -0.012049343', 'meconium ileus surrogate variable 22: -0.016055394', 'meconium ileus surrogate variable 22: -0.041533726', 'meconium ileus surrogate variable 23: 0.014544866', 'meconium ileus surrogate variable 22: 0.030352751', 'meconium ileus surrogate variable 23: 0.008498044', 'meconium ileus surrogate variable 23: 0.028691151', 'meconium ileus surrogate variable 22: -0.000692506', 'meconium ileus surrogate variable 23: 0.008478499', 'meconium ileus surrogate variable 22: 0.072025637', 'meconium ileus surrogate variable 23: 0.0197435', 'meconium ileus surrogate variable 22: -0.025966445', 'meconium ileus surrogate variable 22: -0.036949714'], 39: ['meconium ileus surrogate variable 23: 0.054784155', 'meconium ileus surrogate variable 23: 0.045514366', 'meconium ileus surrogate variable 23: -0.014058228', 'meconium ileus surrogate variable 23: -0.014004677', 'meconium ileus surrogate variable 24: 0.056247906', 'meconium ileus surrogate variable 23: -0.021599635', 'meconium ileus surrogate variable 24: -0.021652807', 'meconium ileus surrogate variable 23: -0.001730111', 'meconium ileus surrogate variable 23: 0.079871149', 'meconium ileus surrogate variable 24: -0.01459298', 'meconium ileus surrogate variable 23: 0.031062706', 'meconium ileus surrogate variable 23: 0.003326659', 'meconium ileus surrogate variable 23: -0.029131435', 'meconium ileus surrogate variable 23: -0.008133983', 'meconium ileus surrogate variable 23: -0.025557468', 'meconium ileus surrogate variable 24: -0.008711217', 'meconium ileus surrogate variable 23: 0.047625379', 'meconium ileus surrogate variable 23: -0.024172533', 'meconium ileus surrogate variable 23: 0.002437431', 'meconium ileus surrogate variable 23: -0.006391104', 'meconium ileus surrogate variable 24: 0.005477834', 'meconium ileus surrogate variable 23: -0.004434659', 'meconium ileus surrogate variable 24: 0.016986256', 'meconium ileus surrogate variable 24: -0.035867203', 'meconium ileus surrogate variable 23: -0.013757461', 'meconium ileus surrogate variable 24: -0.044332722', 'meconium ileus surrogate variable 23: 0.033624025', 'meconium ileus surrogate variable 24: 0.006832497', 'meconium ileus surrogate variable 23: -0.045658601', 'meconium ileus surrogate variable 23: 0.038810281'], 40: ['meconium ileus surrogate variable 24: -0.012126151', 'meconium ileus surrogate variable 24: 0.007709351', 'meconium ileus surrogate variable 24: 0.023530416', 'meconium ileus surrogate variable 24: 0.030935275', 'meconium ileus surrogate variable 25: 0.034584078', 'meconium ileus surrogate variable 24: 0.022782518', 'meconium ileus surrogate variable 25: 0.047710943', 'meconium ileus surrogate variable 24: 0.018311943', 'meconium ileus surrogate variable 24: 0.039110614', 'meconium ileus surrogate variable 25: -0.005475813', 'meconium ileus surrogate variable 24: -0.015365524', 'meconium ileus surrogate variable 24: -0.01896601', 'meconium ileus surrogate variable 24: 0.005466374', 'meconium ileus surrogate variable 24: -0.005705346', 'meconium ileus surrogate variable 24: 0.034007101', 'meconium ileus surrogate variable 25: 0.003157102', 'meconium ileus surrogate variable 24: -0.00144867', 'meconium ileus surrogate variable 24: -0.046696781', 'meconium ileus surrogate variable 24: 0.075561187', 'meconium ileus surrogate variable 24: 0.009804686', 'meconium ileus surrogate variable 25: 0.058721203', 'meconium ileus surrogate variable 24: 0.085612418', 'meconium ileus surrogate variable 25: 0.010776902', 'meconium ileus surrogate variable 25: -0.010201882', 'meconium ileus surrogate variable 24: -0.04612986', 'meconium ileus surrogate variable 25: -0.007338404', 'meconium ileus surrogate variable 24: -0.055186818', 'meconium ileus surrogate variable 25: 0.053378539', 'meconium ileus surrogate variable 24: 0.009223683', 'meconium ileus surrogate variable 24: -0.00111154'], 41: ['meconium ileus surrogate variable 25: 0.009373499', 'meconium ileus surrogate variable 25: 0.009839911', 'meconium ileus surrogate variable 25: -0.021179984', 'meconium ileus surrogate variable 25: -0.000224405', 'meconium ileus surrogate variable 26: 0.028004349', 'meconium ileus surrogate variable 25: 0.022320256', 'meconium ileus surrogate variable 26: 0.02405044', 'meconium ileus surrogate variable 25: 0.04894409', 'meconium ileus surrogate variable 25: 0.040853121', 'meconium ileus surrogate variable 26: -0.024893028', 'meconium ileus surrogate variable 25: 0.016860119', 'meconium ileus surrogate variable 25: 0.003607067', 'meconium ileus surrogate variable 25: 0.024338212', 'meconium ileus surrogate variable 25: -0.029352306', 'meconium ileus surrogate variable 25: 0.006834013', 'meconium ileus surrogate variable 26: 0.004157112', 'meconium ileus surrogate variable 25: 0.042207039', 'meconium ileus surrogate variable 25: -0.029601736', 'meconium ileus surrogate variable 25: 0.043935924', 'meconium ileus surrogate variable 25: 0.057040727', 'meconium ileus surrogate variable 26: -0.026079887', 'meconium ileus surrogate variable 25: 0.044546277', 'meconium ileus surrogate variable 26: -0.04168071', 'meconium ileus surrogate variable 26: 0.029365791', 'meconium ileus surrogate variable 25: 0.011143514', 'meconium ileus surrogate variable 26: -0.065727549', 'meconium ileus surrogate variable 25: -0.05232444', 'meconium ileus surrogate variable 26: 0.091078637', 'meconium ileus surrogate variable 25: 0.04553387', 'meconium ileus surrogate variable 25: 0.073785304'], 42: ['meconium ileus surrogate variable 26: -0.048490673', 'meconium ileus surrogate variable 26: 0.017599981', 'meconium ileus surrogate variable 26: 0.015463287', 'meconium ileus surrogate variable 26: -0.026993106', nan, 'meconium ileus surrogate variable 26: -0.06611799', 'meconium ileus surrogate variable 26: 0.032591446', 'meconium ileus surrogate variable 26: 0.010756697', 'meconium ileus surrogate variable 26: -0.043710692', 'meconium ileus surrogate variable 26: -0.019499298', 'meconium ileus surrogate variable 26: -0.004688529', 'meconium ileus surrogate variable 26: -0.029816919', 'meconium ileus surrogate variable 26: 0.041410103', 'meconium ileus surrogate variable 26: -0.043203389', 'meconium ileus surrogate variable 26: 0.004675266', 'meconium ileus surrogate variable 26: -0.013340063', 'meconium ileus surrogate variable 26: 0.047808688', 'meconium ileus surrogate variable 26: 0.052023134', 'meconium ileus surrogate variable 26: 0.000975237', 'meconium ileus surrogate variable 26: 0.068213259', 'meconium ileus surrogate variable 26: -0.021981704', 'meconium ileus surrogate variable 26: 0.041546965', 'meconium ileus surrogate variable 26: -0.023527074', 'meconium ileus surrogate variable 26: -0.023677039', 'meconium ileus surrogate variable 26: 0.06977081', 'meconium ileus surrogate variable 26: -0.008859509', 'meconium ileus surrogate variable 26: 0.029586803', 'meconium ileus surrogate variable 26: -0.032701477', 'meconium ileus surrogate variable 26: 0.035869537', 'meconium ileus surrogate variable 26: -0.047327057']}\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": "d7e7a3d5",
   "metadata": {},
   "source": [
    "### Step 2: Dataset Analysis and Clinical Feature Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1c55fb72",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:35:45.017896Z",
     "iopub.status.busy": "2025-03-25T08:35:45.017774Z",
     "iopub.status.idle": "2025-03-25T08:35:45.030889Z",
     "shell.execute_reply": "2025-03-25T08:35:45.030585Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preview of selected clinical features:\n",
      "0: [0.92156, 38.2, 1.0]\n",
      "1: [-0.79274, 9.2, 0.0]\n",
      "2: [2.33374, 22.5, nan]\n",
      "3: [-1.36666, 14.4, nan]\n",
      "4: [2.86073, 33.8, nan]\n",
      "5: [1.08383, 18.6, nan]\n",
      "6: [1.15792, 27.7, nan]\n",
      "7: [1.516, 33.5, nan]\n",
      "8: [-0.77528, 17.8, nan]\n",
      "9: [-0.35251, 24.1, nan]\n",
      "10: [0.95176, 16.4, nan]\n",
      "11: [-0.78019, 8.7, nan]\n",
      "12: [-0.45468, 10.4, nan]\n",
      "13: [1.14497, 46.3, nan]\n",
      "14: [-0.47971, 19.0, nan]\n",
      "15: [0.08552, 17.1, nan]\n",
      "16: [-0.74197, 10.2, nan]\n",
      "17: [-1.29147, 16.7, nan]\n",
      "18: [0.81747, 39.7, nan]\n",
      "19: [1.52976, 39.3, nan]\n",
      "20: [1.78443, 25.4, nan]\n",
      "21: [0.8515, 41.2, nan]\n",
      "22: [1.98295, 18.1, nan]\n",
      "23: [0.86374, 21.5, nan]\n",
      "24: [0.94161, 17.3, nan]\n",
      "25: [1.10084, 32.4, nan]\n",
      "26: [-0.5591, 19.8, nan]\n",
      "27: [0.84926, 34.3, nan]\n",
      "28: [0.86596, 25.3, nan]\n",
      "29: [1.3764, 46.7, nan]\n",
      "Clinical data saved to: ../../output/preprocess/Cystic_Fibrosis/clinical_data/GSE60690.csv\n"
     ]
    }
   ],
   "source": [
    "# 1. Gene Expression Data Availability\n",
    "# Based on the title and summary, this dataset analyzes gene expression in LCLs from CF patients\n",
    "# This is not miRNA or methylation data, but gene expression analysis\n",
    "is_gene_available = True\n",
    "\n",
    "# 2. Variable Availability and Data Type Conversion\n",
    "# 2.1 Identifying rows\n",
    "trait_row = 1  # \"consortium lung phenotype\" has numeric values and is related to CF lung disease severity\n",
    "age_row = 2    # \"age of enrollment\" contains patient ages\n",
    "gender_row = 0  # \"Sex\" has Male/Female values\n",
    "\n",
    "# 2.2 Creating conversion functions\n",
    "def convert_trait(value):\n",
    "    \"\"\"Convert trait (lung phenotype) value to continuous numeric value.\"\"\"\n",
    "    if not value or pd.isna(value):\n",
    "        return None\n",
    "    \n",
    "    # Extract numeric value after colon\n",
    "    if \":\" in value:\n",
    "        try:\n",
    "            return float(value.split(\": \")[1].strip())\n",
    "        except (ValueError, IndexError):\n",
    "            return None\n",
    "    return None\n",
    "\n",
    "def convert_age(value):\n",
    "    \"\"\"Convert age value to continuous numeric value.\"\"\"\n",
    "    if not value or pd.isna(value):\n",
    "        return None\n",
    "    \n",
    "    # Extract numeric value after colon\n",
    "    if \":\" in value:\n",
    "        try:\n",
    "            return float(value.split(\": \")[1].strip())\n",
    "        except (ValueError, IndexError):\n",
    "            return None\n",
    "    return None\n",
    "\n",
    "def convert_gender(value):\n",
    "    \"\"\"Convert gender value to binary (0=female, 1=male).\"\"\"\n",
    "    if not value or pd.isna(value):\n",
    "        return None\n",
    "    \n",
    "    # Extract value after colon\n",
    "    if \":\" in value:\n",
    "        value = value.split(\": \")[1].strip().lower()\n",
    "        if \"female\" in value:\n",
    "            return 0\n",
    "        elif \"male\" in value:\n",
    "            return 1\n",
    "        else:\n",
    "            return None\n",
    "    return None\n",
    "\n",
    "# 3. Save Metadata\n",
    "# Conduct initial filtering\n",
    "is_trait_available = trait_row is not None\n",
    "validate_and_save_cohort_info(\n",
    "    is_final=False,\n",
    "    cohort=cohort,\n",
    "    info_path=json_path,\n",
    "    is_gene_available=is_gene_available,\n",
    "    is_trait_available=is_trait_available\n",
    ")\n",
    "\n",
    "# 4. Clinical Feature Extraction (only if trait_row is not None)\n",
    "if trait_row is not None:\n",
    "    # Create a DataFrame from the sample characteristics dictionary\n",
    "    # The dictionary is structured with row indices as keys and lists of values as values\n",
    "    sample_characteristics = {0: ['Sex: Male', 'Sex: Female'], \n",
    "                             1: ['consortium lung phenotype: 0.92156', 'consortium lung phenotype: -0.79274', 'consortium lung phenotype: 2.33374', 'consortium lung phenotype: -1.36666', 'consortium lung phenotype: 2.86073', 'consortium lung phenotype: 1.08383', 'consortium lung phenotype: 1.15792', 'consortium lung phenotype: 1.51600', 'consortium lung phenotype: -0.77528', 'consortium lung phenotype: -0.35251', 'consortium lung phenotype: 0.95176', 'consortium lung phenotype: -0.78019', 'consortium lung phenotype: -0.45468', 'consortium lung phenotype: 1.14497', 'consortium lung phenotype: -0.47971', 'consortium lung phenotype: 0.08552', 'consortium lung phenotype: -0.74197', 'consortium lung phenotype: -1.29147', 'consortium lung phenotype: 0.81747', 'consortium lung phenotype: 1.52976', 'consortium lung phenotype: 1.78443', 'consortium lung phenotype: 0.85150', 'consortium lung phenotype: 1.98295', 'consortium lung phenotype: 0.86374', 'consortium lung phenotype: 0.94161', 'consortium lung phenotype: 1.10084', 'consortium lung phenotype: -0.55910', 'consortium lung phenotype: 0.84926', 'consortium lung phenotype: 0.86596', 'consortium lung phenotype: 1.37640'],\n",
    "                             2: ['age of enrollment: 38.2', 'age of enrollment: 9.2', 'age of enrollment: 22.5', 'age of enrollment: 14.4', 'age of enrollment: 33.8', 'age of enrollment: 18.6', 'age of enrollment: 27.7', 'age of enrollment: 33.5', 'age of enrollment: 17.8', 'age of enrollment: 24.1', 'age of enrollment: 16.4', 'age of enrollment: 8.7', 'age of enrollment: 10.4', 'age of enrollment: 46.3', 'age of enrollment: 19.0', 'age of enrollment: 17.1', 'age of enrollment: 10.2', 'age of enrollment: 16.7', 'age of enrollment: 39.7', 'age of enrollment: 39.3', 'age of enrollment: 25.4', 'age of enrollment: 41.2', 'age of enrollment: 18.1', 'age of enrollment: 21.5', 'age of enrollment: 17.3', 'age of enrollment: 32.4', 'age of enrollment: 19.8', 'age of enrollment: 34.3', 'age of enrollment: 25.3', 'age of enrollment: 46.7']}\n",
    "    \n",
    "    # Convert to DataFrame\n",
    "    clinical_data = pd.DataFrame()\n",
    "    \n",
    "    # For each sample characteristic row\n",
    "    for row_idx, values in sample_characteristics.items():\n",
    "        # Create a temporary Series for this row\n",
    "        row_data = pd.Series(values, name=row_idx)\n",
    "        \n",
    "        # Add to the DataFrame\n",
    "        clinical_data = pd.concat([clinical_data, row_data.to_frame().T])\n",
    "    \n",
    "    # Extract clinical features\n",
    "    selected_clinical_df = geo_select_clinical_features(\n",
    "        clinical_df=clinical_data,\n",
    "        trait=trait,\n",
    "        trait_row=trait_row,\n",
    "        convert_trait=convert_trait,\n",
    "        age_row=age_row,\n",
    "        convert_age=convert_age,\n",
    "        gender_row=gender_row,\n",
    "        convert_gender=convert_gender\n",
    "    )\n",
    "    \n",
    "    # Preview the dataframe\n",
    "    preview_result = preview_df(selected_clinical_df)\n",
    "    print(\"Preview of selected clinical features:\")\n",
    "    for key, value in preview_result.items():\n",
    "        print(f\"{key}: {value}\")\n",
    "    \n",
    "    # Save the clinical data\n",
    "    selected_clinical_df.to_csv(out_clinical_data_file)\n",
    "    print(f\"Clinical data saved to: {out_clinical_data_file}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c351f7a",
   "metadata": {},
   "source": [
    "### Step 3: Gene Data Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "26f90215",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:35:45.032146Z",
     "iopub.status.busy": "2025-03-25T08:35:45.032033Z",
     "iopub.status.idle": "2025-03-25T08:35:45.821532Z",
     "shell.execute_reply": "2025-03-25T08:35:45.821148Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found data marker at line 97\n",
      "Header line: \"ID_REF\"\t\"GSM1485230\"\t\"GSM1485231\"\t\"GSM1485232\"\t\"GSM1485233\"\t\"GSM1485234\"\t\"GSM1485235\"\t\"GSM1485236\"\t\"GSM1485237\"\t\"GSM1485238\"\t\"GSM1485239\"\t\"GSM1485240\"\t\"GSM1485241\"\t\"GSM1485242\"\t\"GSM1485243\"\t\"GSM1485244\"\t\"GSM1485245\"\t\"GSM1485246\"\t\"GSM1485247\"\t\"GSM1485248\"\t\"GSM1485249\"\t\"GSM1485250\"\t\"GSM1485251\"\t\"GSM1485252\"\t\"GSM1485253\"\t\"GSM1485254\"\t\"GSM1485255\"\t\"GSM1485256\"\t\"GSM1485257\"\t\"GSM1485258\"\t\"GSM1485259\"\t\"GSM1485260\"\t\"GSM1485261\"\t\"GSM1485262\"\t\"GSM1485263\"\t\"GSM1485264\"\t\"GSM1485265\"\t\"GSM1485266\"\t\"GSM1485267\"\t\"GSM1485268\"\t\"GSM1485269\"\t\"GSM1485270\"\t\"GSM1485271\"\t\"GSM1485272\"\t\"GSM1485273\"\t\"GSM1485274\"\t\"GSM1485275\"\t\"GSM1485276\"\t\"GSM1485277\"\t\"GSM1485278\"\t\"GSM1485279\"\t\"GSM1485280\"\t\"GSM1485281\"\t\"GSM1485282\"\t\"GSM1485283\"\t\"GSM1485284\"\t\"GSM1485285\"\t\"GSM1485286\"\t\"GSM1485287\"\t\"GSM1485288\"\t\"GSM1485289\"\t\"GSM1485290\"\t\"GSM1485291\"\t\"GSM1485292\"\t\"GSM1485293\"\t\"GSM1485294\"\t\"GSM1485295\"\t\"GSM1485296\"\t\"GSM1485297\"\t\"GSM1485298\"\t\"GSM1485299\"\t\"GSM1485300\"\t\"GSM1485301\"\t\"GSM1485302\"\t\"GSM1485303\"\t\"GSM1485304\"\t\"GSM1485305\"\t\"GSM1485306\"\t\"GSM1485307\"\t\"GSM1485308\"\t\"GSM1485309\"\t\"GSM1485310\"\t\"GSM1485311\"\t\"GSM1485312\"\t\"GSM1485313\"\t\"GSM1485314\"\t\"GSM1485315\"\t\"GSM1485316\"\t\"GSM1485317\"\t\"GSM1485318\"\t\"GSM1485319\"\t\"GSM1485320\"\t\"GSM1485321\"\t\"GSM1485322\"\t\"GSM1485323\"\t\"GSM1485324\"\t\"GSM1485325\"\t\"GSM1485326\"\t\"GSM1485327\"\t\"GSM1485328\"\t\"GSM1485329\"\t\"GSM1485330\"\t\"GSM1485331\"\t\"GSM1485332\"\t\"GSM1485333\"\t\"GSM1485334\"\t\"GSM1485335\"\t\"GSM1485336\"\t\"GSM1485337\"\t\"GSM1485338\"\t\"GSM1485339\"\t\"GSM1485340\"\t\"GSM1485341\"\t\"GSM1485342\"\t\"GSM1485343\"\t\"GSM1485344\"\t\"GSM1485345\"\t\"GSM1485346\"\t\"GSM1485347\"\t\"GSM1485348\"\t\"GSM1485349\"\t\"GSM1485350\"\t\"GSM1485351\"\t\"GSM1485352\"\t\"GSM1485353\"\t\"GSM1485354\"\t\"GSM1485355\"\t\"GSM1485356\"\t\"GSM1485357\"\t\"GSM1485358\"\t\"GSM1485359\"\t\"GSM1485360\"\t\"GSM1485361\"\t\"GSM1485362\"\t\"GSM1485363\"\t\"GSM1485364\"\t\"GSM1485365\"\t\"GSM1485366\"\t\"GSM1485367\"\t\"GSM1485368\"\t\"GSM1485369\"\t\"GSM1485370\"\t\"GSM1485371\"\t\"GSM1485372\"\t\"GSM1485373\"\t\"GSM1485374\"\t\"GSM1485375\"\t\"GSM1485376\"\t\"GSM1485377\"\t\"GSM1485378\"\t\"GSM1485379\"\t\"GSM1485380\"\t\"GSM1485381\"\t\"GSM1485382\"\t\"GSM1485383\"\t\"GSM1485384\"\t\"GSM1485385\"\t\"GSM1485386\"\t\"GSM1485387\"\t\"GSM1485388\"\t\"GSM1485389\"\t\"GSM1485390\"\t\"GSM1485391\"\t\"GSM1485392\"\t\"GSM1485393\"\t\"GSM1485394\"\t\"GSM1485395\"\t\"GSM1485396\"\t\"GSM1485397\"\t\"GSM1485398\"\t\"GSM1485399\"\t\"GSM1485400\"\t\"GSM1485401\"\t\"GSM1485402\"\t\"GSM1485403\"\t\"GSM1485404\"\t\"GSM1485405\"\t\"GSM1485406\"\t\"GSM1485407\"\t\"GSM1485408\"\t\"GSM1485409\"\t\"GSM1485410\"\t\"GSM1485411\"\t\"GSM1485412\"\t\"GSM1485413\"\t\"GSM1485414\"\t\"GSM1485415\"\t\"GSM1485416\"\t\"GSM1485417\"\t\"GSM1485418\"\t\"GSM1485419\"\t\"GSM1485420\"\t\"GSM1485421\"\t\"GSM1485422\"\t\"GSM1485423\"\t\"GSM1485424\"\t\"GSM1485425\"\t\"GSM1485426\"\t\"GSM1485427\"\t\"GSM1485428\"\t\"GSM1485429\"\t\"GSM1485430\"\t\"GSM1485431\"\t\"GSM1485432\"\t\"GSM1485433\"\t\"GSM1485434\"\t\"GSM1485435\"\t\"GSM1485436\"\t\"GSM1485437\"\t\"GSM1485438\"\t\"GSM1485439\"\t\"GSM1485440\"\t\"GSM1485441\"\t\"GSM1485442\"\t\"GSM1485443\"\t\"GSM1485444\"\t\"GSM1485445\"\t\"GSM1485446\"\t\"GSM1485447\"\t\"GSM1485448\"\t\"GSM1485449\"\t\"GSM1485450\"\t\"GSM1485451\"\t\"GSM1485452\"\t\"GSM1485453\"\t\"GSM1485454\"\t\"GSM1485455\"\t\"GSM1485456\"\t\"GSM1485457\"\t\"GSM1485458\"\t\"GSM1485459\"\t\"GSM1485460\"\t\"GSM1485461\"\t\"GSM1485462\"\t\"GSM1485463\"\t\"GSM1485464\"\t\"GSM1485465\"\t\"GSM1485466\"\t\"GSM1485467\"\t\"GSM1485468\"\t\"GSM1485469\"\t\"GSM1485470\"\t\"GSM1485471\"\t\"GSM1485472\"\t\"GSM1485473\"\t\"GSM1485474\"\t\"GSM1485475\"\t\"GSM1485476\"\t\"GSM1485477\"\t\"GSM1485478\"\t\"GSM1485479\"\t\"GSM1485480\"\t\"GSM1485481\"\t\"GSM1485482\"\t\"GSM1485483\"\t\"GSM1485484\"\t\"GSM1485485\"\t\"GSM1485486\"\t\"GSM1485487\"\t\"GSM1485488\"\t\"GSM1485489\"\t\"GSM1485490\"\t\"GSM1485491\"\t\"GSM1485492\"\t\"GSM1485493\"\t\"GSM1485494\"\t\"GSM1485495\"\t\"GSM1485496\"\t\"GSM1485497\"\t\"GSM1485498\"\t\"GSM1485499\"\t\"GSM1485500\"\t\"GSM1485501\"\t\"GSM1485502\"\t\"GSM1485503\"\t\"GSM1485504\"\t\"GSM1485505\"\t\"GSM1485506\"\t\"GSM1485507\"\t\"GSM1485508\"\t\"GSM1485509\"\t\"GSM1485510\"\t\"GSM1485511\"\t\"GSM1485512\"\t\"GSM1485513\"\t\"GSM1485514\"\t\"GSM1485515\"\t\"GSM1485516\"\t\"GSM1485517\"\t\"GSM1485518\"\t\"GSM1485519\"\t\"GSM1485520\"\t\"GSM1485521\"\t\"GSM1485522\"\t\"GSM1485523\"\t\"GSM1485524\"\t\"GSM1485525\"\t\"GSM1485526\"\t\"GSM1485527\"\t\"GSM1485528\"\t\"GSM1485529\"\t\"GSM1485530\"\t\"GSM1485531\"\t\"GSM1485532\"\t\"GSM1485533\"\t\"GSM1485534\"\t\"GSM1485535\"\t\"GSM1485536\"\t\"GSM1485537\"\t\"GSM1485538\"\t\"GSM1485539\"\t\"GSM1485540\"\t\"GSM1485541\"\t\"GSM1485542\"\t\"GSM1485543\"\t\"GSM1485544\"\t\"GSM1485545\"\t\"GSM1485546\"\t\"GSM1485547\"\t\"GSM1485548\"\t\"GSM1485549\"\t\"GSM1485550\"\t\"GSM1485551\"\t\"GSM1485552\"\t\"GSM1485553\"\t\"GSM1485554\"\t\"GSM1485555\"\t\"GSM1485556\"\t\"GSM1485557\"\t\"GSM1485558\"\t\"GSM1485559\"\t\"GSM1485560\"\t\"GSM1485561\"\t\"GSM1485562\"\t\"GSM1485563\"\t\"GSM1485564\"\t\"GSM1485565\"\t\"GSM1485566\"\t\"GSM1485567\"\t\"GSM1485568\"\t\"GSM1485569\"\t\"GSM1485570\"\t\"GSM1485571\"\t\"GSM1485572\"\t\"GSM1485573\"\t\"GSM1485574\"\t\"GSM1485575\"\t\"GSM1485576\"\t\"GSM1485577\"\t\"GSM1485578\"\t\"GSM1485579\"\t\"GSM1485580\"\t\"GSM1485581\"\t\"GSM1485582\"\t\"GSM1485583\"\t\"GSM1485584\"\t\"GSM1485585\"\t\"GSM1485586\"\t\"GSM1485587\"\t\"GSM1485588\"\t\"GSM1485589\"\t\"GSM1485590\"\t\"GSM1485591\"\t\"GSM1485592\"\t\"GSM1485593\"\t\"GSM1485594\"\t\"GSM1485595\"\t\"GSM1485596\"\t\"GSM1485597\"\t\"GSM1485598\"\t\"GSM1485599\"\t\"GSM1485600\"\t\"GSM1485601\"\t\"GSM1485602\"\t\"GSM1485603\"\t\"GSM1485604\"\t\"GSM1485605\"\t\"GSM1485606\"\t\"GSM1485607\"\t\"GSM1485608\"\t\"GSM1485609\"\t\"GSM1485610\"\t\"GSM1485611\"\t\"GSM1485612\"\t\"GSM1485613\"\t\"GSM1485614\"\t\"GSM1485615\"\t\"GSM1485616\"\t\"GSM1485617\"\t\"GSM1485618\"\t\"GSM1485619\"\t\"GSM1485620\"\t\"GSM1485621\"\t\"GSM1485622\"\t\"GSM1485623\"\t\"GSM1485624\"\t\"GSM1485625\"\t\"GSM1485626\"\t\"GSM1485627\"\t\"GSM1485628\"\t\"GSM1485629\"\t\"GSM1485630\"\t\"GSM1485631\"\t\"GSM1485632\"\t\"GSM1485633\"\t\"GSM1485634\"\t\"GSM1485635\"\t\"GSM1485636\"\t\"GSM1485637\"\t\"GSM1485638\"\t\"GSM1485639\"\t\"GSM1485640\"\t\"GSM1485641\"\t\"GSM1485642\"\t\"GSM1485643\"\t\"GSM1485644\"\t\"GSM1485645\"\t\"GSM1485646\"\t\"GSM1485647\"\t\"GSM1485648\"\t\"GSM1485649\"\t\"GSM1485650\"\t\"GSM1485651\"\t\"GSM1485652\"\t\"GSM1485653\"\t\"GSM1485654\"\t\"GSM1485655\"\t\"GSM1485656\"\t\"GSM1485657\"\t\"GSM1485658\"\t\"GSM1485659\"\t\"GSM1485660\"\t\"GSM1485661\"\t\"GSM1485662\"\t\"GSM1485663\"\t\"GSM1485664\"\t\"GSM1485665\"\t\"GSM1485666\"\t\"GSM1485667\"\t\"GSM1485668\"\t\"GSM1485669\"\t\"GSM1485670\"\t\"GSM1485671\"\t\"GSM1485672\"\t\"GSM1485673\"\t\"GSM1485674\"\t\"GSM1485675\"\t\"GSM1485676\"\t\"GSM1485677\"\t\"GSM1485678\"\t\"GSM1485679\"\t\"GSM1485680\"\t\"GSM1485681\"\t\"GSM1485682\"\t\"GSM1485683\"\t\"GSM1485684\"\t\"GSM1485685\"\t\"GSM1485686\"\t\"GSM1485687\"\t\"GSM1485688\"\t\"GSM1485689\"\t\"GSM1485690\"\t\"GSM1485691\"\t\"GSM1485692\"\t\"GSM1485693\"\t\"GSM1485694\"\t\"GSM1485695\"\t\"GSM1485696\"\t\"GSM1485697\"\t\"GSM1485698\"\t\"GSM1485699\"\t\"GSM1485700\"\t\"GSM1485701\"\t\"GSM1485702\"\t\"GSM1485703\"\t\"GSM1485704\"\t\"GSM1485705\"\t\"GSM1485706\"\t\"GSM1485707\"\t\"GSM1485708\"\t\"GSM1485709\"\t\"GSM1485710\"\t\"GSM1485711\"\t\"GSM1485712\"\t\"GSM1485713\"\t\"GSM1485714\"\t\"GSM1485715\"\t\"GSM1485716\"\t\"GSM1485717\"\t\"GSM1485718\"\t\"GSM1485719\"\t\"GSM1485720\"\t\"GSM1485721\"\t\"GSM1485722\"\t\"GSM1485723\"\t\"GSM1485724\"\t\"GSM1485725\"\t\"GSM1485726\"\t\"GSM1485727\"\t\"GSM1485728\"\t\"GSM1485729\"\t\"GSM1485730\"\t\"GSM1485731\"\t\"GSM1485732\"\t\"GSM1485733\"\t\"GSM1485734\"\t\"GSM1485735\"\t\"GSM1485736\"\t\"GSM1485737\"\t\"GSM1485738\"\t\"GSM1485739\"\t\"GSM1485740\"\t\"GSM1485741\"\t\"GSM1485742\"\t\"GSM1485743\"\t\"GSM1485744\"\t\"GSM1485745\"\t\"GSM1485746\"\t\"GSM1485747\"\t\"GSM1485748\"\t\"GSM1485749\"\t\"GSM1485750\"\t\"GSM1485751\"\t\"GSM1485752\"\t\"GSM1485753\"\t\"GSM1485754\"\t\"GSM1485755\"\t\"GSM1485756\"\t\"GSM1485757\"\t\"GSM1485758\"\t\"GSM1485759\"\t\"GSM1485760\"\t\"GSM1485761\"\t\"GSM1485762\"\t\"GSM1485763\"\t\"GSM1485764\"\t\"GSM1485765\"\t\"GSM1485766\"\t\"GSM1485767\"\t\"GSM1485768\"\t\"GSM1485769\"\t\"GSM1485770\"\t\"GSM1485771\"\t\"GSM1485772\"\t\"GSM1485773\"\t\"GSM1485774\"\t\"GSM1485775\"\t\"GSM1485776\"\t\"GSM1485777\"\t\"GSM1485778\"\t\"GSM1485779\"\t\"GSM1485780\"\t\"GSM1485781\"\t\"GSM1485782\"\t\"GSM1485783\"\t\"GSM1485784\"\t\"GSM1485785\"\t\"GSM1485786\"\t\"GSM1485787\"\t\"GSM1485788\"\t\"GSM1485789\"\t\"GSM1485790\"\t\"GSM1485791\"\t\"GSM1485792\"\t\"GSM1485793\"\t\"GSM1485794\"\t\"GSM1485795\"\t\"GSM1485796\"\t\"GSM1485797\"\t\"GSM1485798\"\t\"GSM1485799\"\t\"GSM1485800\"\t\"GSM1485801\"\t\"GSM1485802\"\t\"GSM1485803\"\t\"GSM1485804\"\t\"GSM1485805\"\t\"GSM1485806\"\t\"GSM1485807\"\t\"GSM1485808\"\t\"GSM1485809\"\t\"GSM1485810\"\t\"GSM1485811\"\t\"GSM1485812\"\t\"GSM1485813\"\t\"GSM1485814\"\t\"GSM1485815\"\t\"GSM1485816\"\t\"GSM1485817\"\t\"GSM1485818\"\t\"GSM1485819\"\t\"GSM1485820\"\t\"GSM1485821\"\t\"GSM1485822\"\t\"GSM1485823\"\t\"GSM1485824\"\t\"GSM1485825\"\t\"GSM1485826\"\t\"GSM1485827\"\t\"GSM1485828\"\t\"GSM1485829\"\t\"GSM1485830\"\t\"GSM1485831\"\t\"GSM1485832\"\t\"GSM1485833\"\t\"GSM1485834\"\t\"GSM1485835\"\t\"GSM1485836\"\t\"GSM1485837\"\t\"GSM1485838\"\t\"GSM1485839\"\t\"GSM1485840\"\t\"GSM1485841\"\t\"GSM1485842\"\t\"GSM1485843\"\t\"GSM1485844\"\t\"GSM1485845\"\t\"GSM1485846\"\t\"GSM1485847\"\t\"GSM1485848\"\t\"GSM1485849\"\t\"GSM1485850\"\t\"GSM1485851\"\t\"GSM1485852\"\t\"GSM1485853\"\t\"GSM1485854\"\t\"GSM1485855\"\t\"GSM1485856\"\t\"GSM1485857\"\t\"GSM1485858\"\t\"GSM1485859\"\t\"GSM1485860\"\t\"GSM1485861\"\t\"GSM1485862\"\t\"GSM1485863\"\t\"GSM1485864\"\t\"GSM1485865\"\t\"GSM1485866\"\t\"GSM1485867\"\t\"GSM1485868\"\t\"GSM1485869\"\t\"GSM1485870\"\t\"GSM1485871\"\t\"GSM1485872\"\t\"GSM1485873\"\t\"GSM1485874\"\t\"GSM1485875\"\t\"GSM1485876\"\t\"GSM1485877\"\t\"GSM1485878\"\t\"GSM1485879\"\t\"GSM1485880\"\t\"GSM1485881\"\t\"GSM1485882\"\t\"GSM1485883\"\t\"GSM1485884\"\t\"GSM1485885\"\t\"GSM1485886\"\t\"GSM1485887\"\t\"GSM1485888\"\t\"GSM1485889\"\t\"GSM1485890\"\t\"GSM1485891\"\t\"GSM1485892\"\t\"GSM1485893\"\t\"GSM1485894\"\t\"GSM1485895\"\t\"GSM1485896\"\t\"GSM1485897\"\t\"GSM1485898\"\t\"GSM1485899\"\t\"GSM1485900\"\t\"GSM1485901\"\t\"GSM1485902\"\t\"GSM1485903\"\t\"GSM1485904\"\t\"GSM1485905\"\t\"GSM1485906\"\t\"GSM1485907\"\t\"GSM1485908\"\t\"GSM1485909\"\t\"GSM1485910\"\t\"GSM1485911\"\t\"GSM1485912\"\t\"GSM1485913\"\t\"GSM1485914\"\t\"GSM1485915\"\t\"GSM1485916\"\t\"GSM1485917\"\t\"GSM1485918\"\t\"GSM1485919\"\t\"GSM1485920\"\t\"GSM1485921\"\t\"GSM1485922\"\t\"GSM1485923\"\t\"GSM1485924\"\t\"GSM1485925\"\t\"GSM1485926\"\t\"GSM1485927\"\t\"GSM1485928\"\t\"GSM1485929\"\t\"GSM1485930\"\t\"GSM1485931\"\t\"GSM1485932\"\t\"GSM1485933\"\t\"GSM1485934\"\t\"GSM1485935\"\t\"GSM1485936\"\t\"GSM1485937\"\t\"GSM1485938\"\t\"GSM1485939\"\t\"GSM1485940\"\t\"GSM1485941\"\t\"GSM1485942\"\t\"GSM1485943\"\t\"GSM1485944\"\t\"GSM1485945\"\t\"GSM1485946\"\t\"GSM1485947\"\t\"GSM1485948\"\t\"GSM1485949\"\t\"GSM1485950\"\t\"GSM1485951\"\t\"GSM1485952\"\t\"GSM1485953\"\t\"GSM1485954\"\t\"GSM1485955\"\t\"GSM1485956\"\t\"GSM1485957\"\t\"GSM1485958\"\t\"GSM1485959\"\t\"GSM1485960\"\t\"GSM1485961\"\t\"GSM1485962\"\t\"GSM1485963\"\t\"GSM1485964\"\t\"GSM1485965\"\t\"GSM1485966\"\t\"GSM1485967\"\t\"GSM1485968\"\t\"GSM1485969\"\t\"GSM1485970\"\t\"GSM1485971\"\t\"GSM1485972\"\t\"GSM1485973\"\t\"GSM1485974\"\t\"GSM1485975\"\t\"GSM1485976\"\t\"GSM1485977\"\t\"GSM1485978\"\t\"GSM1485979\"\t\"GSM1485980\"\t\"GSM1485981\"\t\"GSM1485982\"\t\"GSM1485983\"\n",
      "First data line: 2315554\t7.9952\t7.200455\t7.245345\t7.88229\t7.342465\t7.59618\t7.82468\t7.511645\t7.74852\t7.538935\t7.55865\t7.566\t8.02493\t7.608995\t7.956825\t8.280115\t8.17586\t7.44704\t7.446545\t7.09185\t7.502455\t7.54732\t7.524365\t7.54174\t7.70331\t7.697955\t7.21934\t7.51804\t7.327025\t7.75593\t7.92926\t8.017715\t7.4109\t7.63274\t7.67619\t8.134625\t7.71649\t7.73755\t7.826325\t8.03975\t8.046375\t7.3114\t7.343455\t7.92082\t7.330095\t7.27612\t7.384155\t7.72533\t7.78248\t7.397695\t7.82648\t7.56049\t7.58967\t7.77906\t7.82683\t7.740005\t7.815105\t7.76544\t7.13119\t7.86581\t7.513395\t7.36879\t8.12344\t7.360625\t7.33089\t7.857745\t7.90203\t7.64738\t7.520105\t7.92726\t7.46746\t7.24749\t7.502655\t7.37753\t7.09671\t7.45531\t7.365195\t7.535385\t7.62639\t7.60384\t6.951085\t7.60712\t7.35075\t7.76701\t7.256245\t7.71351\t7.492955\t7.585855\t7.286605\t7.65397\t7.453745\t7.74583\t7.666455\t7.40676\t7.51899\t7.817165\t7.34713\t8.132835\t7.163715\t7.15181\t7.496635\t8.051805\t7.954885\t7.54707\t7.409495\t7.618225\t7.362655\t7.64223\t7.785605\t7.360625\t7.875975\t7.541415\t7.72122\t7.472185\t7.46144\t7.19798\t7.230955\t7.45974\t7.14518\t7.50725\t7.14809\t7.93187\t7.371545\t7.16415\t7.629145\t7.53196\t7.356265\t7.246585\t7.632435\t7.382345\t7.53516\t7.79417\t7.41886\t7.55839\t7.749275\t7.05582\t7.302045\t7.353085\t7.491595\t7.393925\t7.06395\t7.31785\t7.312445\t6.81418\t7.103705\t7.068445\t7.41986\t7.18126\t7.05054\t7.07769\t7.41071\t7.213025\t7.251885\t7.048615\t6.905605\t7.169235\t7.514075\t7.1257\t7.072315\t6.86598\t7.23888\t7.47119\t7.079955\t7.00853\t7.227155\t7.09245\t7.27788\t7.251105\t7.200455\t7.32571\t7.07537\t7.17134\t7.29038\t7.206385\t6.99225\t6.99852\t7.146655\t7.132875\t7.058805\t7.070425\t7.427865\t7.20967\t7.47283\t7.21002\t7.318365\t7.323315\t7.18658\t7.161685\t7.1327\t7.29721\t7.75198\t7.346755\t7.383195\t7.240245\t7.35083\t6.97945\t7.00485\t7.1925\t7.211415\t7.27578\t7.18442\t7.34652\t7.268845\t7.04697\t6.953285\t6.93375\t7.175325\t7.146405\t7.50026\t7.088725\t7.373365\t6.844235\t7.661185\t7.582575\t7.337055\t7.406385\t7.210685\t6.920585\t7.259945\t7.1654\t7.0237\t7.074805\t7.0883\t7.225525\t7.139285\t6.96815\t7.38256\t7.05246\t7.27612\t6.967695\t7.335315\t7.270645\t7.56049\t7.33089\t7.094595\t7.33386\t7.46437\t7.10732\t7.333695\t7.014405\t7.071435\t7.22923\t7.18746\t7.41886\t7.320495\t6.952635\t7.09792\t7.13563\t7.19545\t7.21884\t7.089715\t7.27134\t7.15287\t7.2606\t7.17319\t7.18548\t7.538935\t7.061295\t7.25232\t7.67619\t7.354505\t7.127905\t7.31269\t7.38211\t7.29977\t7.55955\t6.89127\t7.159805\t7.109295\t7.125235\t7.278905\t7.51899\t7.0677\t6.95796\t7.117215\t7.529655\t7.036965\t7.05582\t7.694435\t7.715145\t7.49539\t7.42359\t7.60712\t7.52342\t7.4646\t8.235285\t7.204415\t7.255955\t7.29387\t7.001805\t7.593565\t7.18936\t7.66953\t7.292285\t7.652705\t7.2188\t7.163375\t7.22084\t7.217085\t7.085365\t7.538935\t7.213025\t7.254395\t7.08663\t7.939975\t7.078405\t7.26954\t7.067225\t7.234645\t7.259945\t7.04898\t7.113055\t6.997925\t7.91302\t7.48222\t7.323495\t7.44073\t7.446545\t7.10259\t6.76068\t7.245795\t7.67518\t7.27788\t6.81464\t7.090495\t7.331935\t7.287785\t6.82183\t7.615505\t6.86323\t7.066125\t7.38868\t7.34037\t6.817775\t7.0944\t7.275645\t7.068005\t7.204855\t7.297505\t7.288065\t7.07744\t7.2846\t7.240745\t7.61527\t7.26574\t7.433695\t7.477125\t7.48935\t7.14411\t7.423905\t7.155955\t7.54474\t7.608515\t7.3143\t7.437875\t7.279275\t6.887885\t6.87075\t7.11908\t7.245345\t7.19545\t7.59618\t7.720485\t7.437875\t7.212865\t7.00027\t7.07686\t7.388205\t7.161125\t7.32949\t7.122495\t7.032975\t7.71009\t7.26623\t7.41393\t7.537495\t7.5592\t7.24708\t7.355725\t7.40676\t7.353085\t7.16788\t7.179145\t7.232095\t7.25019\t7.30034\t7.48412\t7.358695\t7.541415\t7.19901\t7.193085\t7.18593\t7.429325\t6.911595\t7.05996\t6.9879\t7.307535\t6.925685\t7.323495\t7.33469\t7.031155\t7.011095\t7.10392\t7.1327\t7.115495\t7.725735\t7.97524\t7.563845\t7.46633\t7.24643\t7.20413\t7.85552\t7.575855\t7.603415\t7.36676\t7.027315\t7.230795\t7.48462\t8.007405\t7.44808\t7.617825\t7.241235\t7.193085\t7.276465\t7.469\t7.22397\t7.28991\t7.339675\t7.529905\t7.25934\t7.3744\t7.030595\t7.320495\t7.686795\t7.15287\t7.692945\t7.497445\t7.52342\t7.2978\t7.601335\t7.550005\t7.675895\t7.36237\t7.479255\t7.14722\t7.35346\t7.348605\t7.917205\t7.38342\t7.3556\t7.900645\t7.537495\t7.35363\t7.2846\t7.41886\t7.536415\t7.28348\t7.47084\t7.061295\t6.973105\t7.399795\t7.330095\t7.349515\t7.35478\t7.319855\t7.261205\t7.50107\t7.16596\t7.07537\t7.47283\t7.397125\t7.823015\t7.41986\t7.317325\t7.333695\t7.7184\t7.85259\t7.47677\t7.36159\t7.541415\t7.48352\t7.617115\t7.39043\t7.40676\t7.75274\t7.39751\t7.119375\t7.08259\t7.93904\t7.569895\t7.467755\t7.168055\t7.384915\t7.50754\t7.011445\t7.637445\t7.53148\t7.251105\t7.46409\t7.51477\t7.44353\t7.672595\t7.23921\t7.669425\t7.73604\t7.337185\t7.369425\t7.352195\t7.20782\t7.40026\t7.547875\t7.188825\t7.510815\t7.63914\t7.43922\t7.56521\t7.966645\t7.733035\t7.34231\t7.25853\t7.501765\t7.179245\t7.52031\t7.487535\t7.520105\t7.001805\t7.270405\t7.418605\t7.27174\t7.612415\t7.37685\t7.690495\t7.41121\t7.240745\t7.429325\t7.22539\t7.36676\t7.29038\t7.43733\t7.208955\t7.167315\t7.376685\t7.532965\t7.18936\t7.279275\t7.268635\t7.73755\t7.67355\t7.04227\t7.50386\t7.251105\t7.78703\t7.38654\t7.292665\t7.52805\t7.42403\t7.52757\t7.292925\t7.35075\t7.550845\t7.502455\t7.516995\t7.244165\t7.3008\t7.047925\t7.587035\t8.0671\t7.516545\t7.837815\t7.224255\t7.36879\t7.33029\t7.583755\t7.60645\t7.490505\t7.984685\t7.332255\t7.82438\t7.31392\t7.749715\t7.655525\t8.16308\t7.273555\t7.803805\t7.56123\t7.59056\t7.806265\t7.82907\t7.32869\t7.35363\t7.581905\t7.564295\t7.251405\t7.51804\t7.892745\t7.19174\t7.100515\t7.41422\t7.24944\t7.35331\t7.553605\t7.535945\t7.096265\t7.127905\t7.33386\t7.3853\t7.335025\t7.996615\t7.933475\t7.26483\t7.467105\t7.31224\t7.75593\t7.499285\t7.664575\t7.57694\t7.447275\t7.18586\t7.458675\t7.484895\t7.58752\t7.483645\t7.412525\t7.680245\t7.997955\t7.306335\t7.375255\t7.48412\t7.55955\t7.146655\t7.349265\t7.782185\t7.24254\t7.837705\t7.35331\t7.59073\t7.601335\t7.4109\t7.07812\t7.55655\t7.34083\t7.806785\t7.332515\t7.217365\t7.435885\t7.09971\t7.389035\t7.34218\t7.21196\t7.63914\t7.144895\t7.281465\t8.054145\t7.58889\t8.119615\t7.244165\t7.54732\t7.223595\t7.438235\t7.82381\t7.823225\t7.35721\t7.56976\t7.291025\t7.088725\t7.48412\t8.190675\t7.38692\t7.715145\t7.50606\t7.391375\t7.854145\t7.49609\t7.86454\t7.51933\t7.32949\t7.2632\t7.314135\t7.47972\t7.60083\t7.40692\t7.568395\t7.61527\t7.456385\t7.38069\t7.55125\t7.51899\t7.414075\t7.319475\t7.02428\t7.51899\t7.353085\t7.30669\t7.178345\t7.077925\t6.91319\t7.435225\t7.210685\t7.696015\t7.566\t7.394585\t7.350185\t7.242915\t7.02496\t7.435885\t7.455825\t7.273555\t7.01048\t7.72722\t7.413245\t7.3561\t7.277415\t7.600315\t7.57738\t7.45181\t7.320685\t7.772845\t7.516735\t7.581905\t7.448725\t7.306595\t7.52342\t7.323315\t7.772845\t7.516735\t7.34803\t7.49585\t7.38342\t7.440325\t7.49585\t7.335315\t7.45531\t7.37917\t7.66988\t7.47842\t7.535575\t7.71182\t7.2376\t7.38459\t7.487175\t7.35083\t7.72533\t7.693135\t7.369665\t7.345845\t7.632435\t7.46601\t7.8393\t7.675895\t7.63569\t7.462865\t7.319475\t7.5592\t7.605705\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['2315554', '2315633', '2315674', '2315739', '2315894', '2315918',\n",
      "       '2315951', '2316218', '2316245', '2316379', '2316558', '2316605',\n",
      "       '2316746', '2316905', '2316953', '2317246', '2317317', '2317434',\n",
      "       '2317472', '2317512'],\n",
      "      dtype='object', name='ID')\n"
     ]
    }
   ],
   "source": [
    "# 1. Get the file paths for the SOFT file and matrix file\n",
    "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
    "\n",
    "# 2. First, let's examine the structure of the matrix file to understand its format\n",
    "import gzip\n",
    "\n",
    "# Peek at the first few lines of the file to understand its structure\n",
    "with gzip.open(matrix_file, 'rt') as file:\n",
    "    # Read first 100 lines to find the header structure\n",
    "    for i, line in enumerate(file):\n",
    "        if '!series_matrix_table_begin' in line:\n",
    "            print(f\"Found data marker at line {i}\")\n",
    "            # Read the next line which should be the header\n",
    "            header_line = next(file)\n",
    "            print(f\"Header line: {header_line.strip()}\")\n",
    "            # And the first data line\n",
    "            first_data_line = next(file)\n",
    "            print(f\"First data line: {first_data_line.strip()}\")\n",
    "            break\n",
    "        if i > 100:  # Limit search to first 100 lines\n",
    "            print(\"Matrix table marker not found in first 100 lines\")\n",
    "            break\n",
    "\n",
    "# 3. Now try to get the genetic data with better error handling\n",
    "try:\n",
    "    gene_data = get_genetic_data(matrix_file)\n",
    "    print(gene_data.index[:20])\n",
    "except KeyError as e:\n",
    "    print(f\"KeyError: {e}\")\n",
    "    \n",
    "    # Alternative approach: manually extract the data\n",
    "    print(\"\\nTrying alternative approach to read the gene data:\")\n",
    "    with gzip.open(matrix_file, 'rt') as file:\n",
    "        # Find the start of the data\n",
    "        for line in file:\n",
    "            if '!series_matrix_table_begin' in line:\n",
    "                break\n",
    "                \n",
    "        # Read the headers and data\n",
    "        import pandas as pd\n",
    "        df = pd.read_csv(file, sep='\\t', index_col=0)\n",
    "        print(f\"Column names: {df.columns[:5]}\")\n",
    "        print(f\"First 20 row IDs: {df.index[:20]}\")\n",
    "        gene_data = df\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99eca388",
   "metadata": {},
   "source": [
    "### Step 4: Gene Identifier Review"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4522ce15",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:35:45.822962Z",
     "iopub.status.busy": "2025-03-25T08:35:45.822834Z",
     "iopub.status.idle": "2025-03-25T08:35:45.824744Z",
     "shell.execute_reply": "2025-03-25T08:35:45.824450Z"
    }
   },
   "outputs": [],
   "source": [
    "# Examining the gene identifiers in the dataset\n",
    "# The IDs appear to be numeric probe identifiers (e.g., \"2315554\")\n",
    "# These are not standard human gene symbols and would need mapping\n",
    "\n",
    "requires_gene_mapping = True\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1452bd2",
   "metadata": {},
   "source": [
    "### Step 5: Gene Annotation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "bc0a7e17",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:35:45.825981Z",
     "iopub.status.busy": "2025-03-25T08:35:45.825863Z",
     "iopub.status.idle": "2025-03-25T08:35:56.604917Z",
     "shell.execute_reply": "2025-03-25T08:35:56.604525Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gene annotation preview:\n",
      "{'ID': ['2315100', '2315106', '2315109', '2315111', '2315113'], 'GB_LIST': ['NR_024005,NR_034090,NR_024004,AK093685', 'DQ786314', nan, nan, 'DQ786265'], 'SPOT_ID': ['chr1:11884-14409', 'chr1:14760-15198', 'chr1:19408-19712', 'chr1:25142-25532', 'chr1:27563-27813'], 'seqname': ['chr1', 'chr1', 'chr1', 'chr1', 'chr1'], 'RANGE_GB': ['NC_000001.10', 'NC_000001.10', 'NC_000001.10', 'NC_000001.10', 'NC_000001.10'], 'RANGE_STRAND': ['+', '+', '+', '+', '+'], 'RANGE_START': ['11884', '14760', '19408', '25142', '27563'], 'RANGE_STOP': ['14409', '15198', '19712', '25532', '27813'], 'total_probes': ['20', '8', '4', '4', '4'], 'gene_assignment': ['NR_024005 // DDX11L2 // DEAD/H (Asp-Glu-Ala-Asp/His) box polypeptide 11 like 2 // 2q13 // 84771 /// NR_034090 // DDX11L9 // DEAD/H (Asp-Glu-Ala-Asp/His) box polypeptide 11 like 9 // 15q26.3 // 100288486 /// NR_024004 // DDX11L2 // DEAD/H (Asp-Glu-Ala-Asp/His) box polypeptide 11 like 2 // 2q13 // 84771 /// AK093685 // DDX11L2 // DEAD/H (Asp-Glu-Ala-Asp/His) box polypeptide 11 like 2 // 2q13 // 84771', '---', '---', '---', '---'], 'mrna_assignment': ['NR_024005 // RefSeq // Homo sapiens DEAD/H (Asp-Glu-Ala-Asp/His) box polypeptide 11 like 2 (DDX11L2), transcript variant 2, non-coding RNA. // chr1 // 100 // 80 // 16 // 16 // 0 /// NR_034090 // RefSeq // Homo sapiens DEAD/H (Asp-Glu-Ala-Asp/His) box polypeptide 11 like 9 (DDX11L9), non-coding RNA. // chr1 // 100 // 80 // 16 // 16 // 0 /// NR_024004 // RefSeq // Homo sapiens DEAD/H (Asp-Glu-Ala-Asp/His) box polypeptide 11 like 2 (DDX11L2), transcript variant 1, non-coding RNA. // chr1 // 100 // 75 // 15 // 15 // 0 /// AK093685 // GenBank // Homo sapiens cDNA FLJ36366 fis, clone THYMU2007824. // chr1 // 94 // 80 // 15 // 16 // 0 /// ENST00000513886 // ENSEMBL // cdna:known chromosome:GRCh37:16:61555:64090:1 gene:ENSG00000233614 // chr1 // 100 // 80 // 16 // 16 // 0 /// ENST00000456328 // ENSEMBL // cdna:known chromosome:GRCh37:1:11869:14409:1 gene:ENSG00000223972 // chr1 // 100 // 80 // 16 // 16 // 0 /// ENST00000518655 // ENSEMBL // cdna:known chromosome:GRCh37:1:11869:14409:1 gene:ENSG00000253101 // chr1 // 100 // 80 // 16 // 16 // 0', 'DQ786314 // GenBank // Homo sapiens clone HLS_IMAGE_811138 mRNA sequence. // chr1 // 100 // 38 // 3 // 3 // 0', '---', '---', 'DQ786265 // GenBank // Homo sapiens clone HLS_IMAGE_298685 mRNA sequence. // chr1 // 100 // 100 // 4 // 4 // 0'], 'category': ['main', 'main', '---', '---', 'main']}\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": "c177d765",
   "metadata": {},
   "source": [
    "### Step 6: Gene Identifier Mapping"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5c1a7a91",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:35:56.606377Z",
     "iopub.status.busy": "2025-03-25T08:35:56.606248Z",
     "iopub.status.idle": "2025-03-25T08:36:09.751255Z",
     "shell.execute_reply": "2025-03-25T08:36:09.750910Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gene data index examples (first 5): ['2315554', '2315633', '2315674', '2315739', '2315894']\n",
      "Gene annotation ID examples (first 5): ['2315100', '2315106', '2315109', '2315111', '2315113']\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of common IDs between gene data and mapping: 12033\n",
      "Total number of probes in mapping: 9390555\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of probes with gene mappings: 31980\n",
      "Number of probes in filtered mapping: 9084915\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of probes with gene mappings after filtering: 11962\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Shape of gene expression data: (0, 754)\n",
      "Warning: Gene expression data is empty after mapping\n",
      "Gene expression data saved to: ../../output/preprocess/Cystic_Fibrosis/gene_data/GSE60690.csv\n"
     ]
    }
   ],
   "source": [
    "# 1. Determining the mapping between identifiers in the gene expression data and gene annotations\n",
    "# From the previous steps, we saw:\n",
    "# - Gene expression data has numeric identifiers in the 'ID' column (e.g., \"2315554\")\n",
    "# - Gene annotation data has matching IDs and gene information in the 'gene_assignment' column\n",
    "\n",
    "# First, let's check the structure of both datasets\n",
    "print(\"Gene data index examples (first 5):\", list(gene_data.index[:5]))\n",
    "print(\"Gene annotation ID examples (first 5):\", list(gene_annotation['ID'][:5]))\n",
    "\n",
    "# 2. Create mapping dataframe using the built-in function for extracting human gene symbols\n",
    "mapping_df = pd.DataFrame()\n",
    "mapping_df['ID'] = gene_annotation['ID']\n",
    "mapping_df['Gene'] = gene_annotation['gene_assignment'].apply(extract_human_gene_symbols)\n",
    "\n",
    "# Check for ID intersection between gene data and mapping\n",
    "gene_ids_in_data = set(gene_data.index)\n",
    "gene_ids_in_mapping = set(mapping_df['ID'])\n",
    "common_ids = gene_ids_in_data.intersection(gene_ids_in_mapping)\n",
    "print(f\"Number of common IDs between gene data and mapping: {len(common_ids)}\")\n",
    "\n",
    "# Print statistics to verify mapping looks reasonable\n",
    "print(f\"Total number of probes in mapping: {len(mapping_df)}\")\n",
    "print(f\"Number of probes with gene mappings: {mapping_df['Gene'].apply(len).gt(0).sum()}\")\n",
    "\n",
    "# Filter the mapping to only include IDs present in gene_data\n",
    "filtered_mapping = mapping_df[mapping_df['ID'].isin(gene_data.index)]\n",
    "print(f\"Number of probes in filtered mapping: {len(filtered_mapping)}\")\n",
    "print(f\"Number of probes with gene mappings after filtering: {filtered_mapping['Gene'].apply(len).gt(0).sum()}\")\n",
    "\n",
    "# 3. Apply gene mapping to convert probe-level measurements to gene expression using filtered mapping\n",
    "gene_data = apply_gene_mapping(gene_data, filtered_mapping)\n",
    "\n",
    "# Print the shape of the resulting gene expression data\n",
    "print(f\"Shape of gene expression data: {gene_data.shape}\")\n",
    "if not gene_data.empty:\n",
    "    print(\"First 5 gene symbols:\")\n",
    "    print(gene_data.index[:5])\n",
    "else:\n",
    "    print(\"Warning: Gene expression data is empty after mapping\")\n",
    "\n",
    "# Save the gene expression data\n",
    "gene_data.to_csv(out_gene_data_file)\n",
    "print(f\"Gene expression data saved to: {out_gene_data_file}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d326e643",
   "metadata": {},
   "source": [
    "### Step 7: Data Normalization and Linking"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5a865c8b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:36:09.752609Z",
     "iopub.status.busy": "2025-03-25T08:36:09.752490Z",
     "iopub.status.idle": "2025-03-25T08:36:09.826390Z",
     "shell.execute_reply": "2025-03-25T08:36:09.826014Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Normalized gene data shape: (0, 754)\n",
      "First few genes with their expression values after normalization:\n",
      "Empty DataFrame\n",
      "Columns: [GSM1485230, GSM1485231, GSM1485232, GSM1485233, GSM1485234, GSM1485235, GSM1485236, GSM1485237, GSM1485238, GSM1485239, GSM1485240, GSM1485241, GSM1485242, GSM1485243, GSM1485244, GSM1485245, GSM1485246, GSM1485247, GSM1485248, GSM1485249, GSM1485250, GSM1485251, GSM1485252, GSM1485253, GSM1485254, GSM1485255, GSM1485256, GSM1485257, GSM1485258, GSM1485259, GSM1485260, GSM1485261, GSM1485262, GSM1485263, GSM1485264, GSM1485265, GSM1485266, GSM1485267, GSM1485268, GSM1485269, GSM1485270, GSM1485271, GSM1485272, GSM1485273, GSM1485274, GSM1485275, GSM1485276, GSM1485277, GSM1485278, GSM1485279, GSM1485280, GSM1485281, GSM1485282, GSM1485283, GSM1485284, GSM1485285, GSM1485286, GSM1485287, GSM1485288, GSM1485289, GSM1485290, GSM1485291, GSM1485292, GSM1485293, GSM1485294, GSM1485295, GSM1485296, GSM1485297, GSM1485298, GSM1485299, GSM1485300, GSM1485301, GSM1485302, GSM1485303, GSM1485304, GSM1485305, GSM1485306, GSM1485307, GSM1485308, GSM1485309, GSM1485310, GSM1485311, GSM1485312, GSM1485313, GSM1485314, GSM1485315, GSM1485316, GSM1485317, GSM1485318, GSM1485319, GSM1485320, GSM1485321, GSM1485322, GSM1485323, GSM1485324, GSM1485325, GSM1485326, GSM1485327, GSM1485328, GSM1485329, ...]\n",
      "Index: []\n",
      "\n",
      "[0 rows x 754 columns]\n",
      "Normalized gene data saved to ../../output/preprocess/Cystic_Fibrosis/gene_data/GSE60690.csv\n",
      "Clinical data preview:\n",
      "{'0': [0.92156, 38.2, 1.0], '1': [-0.79274, 9.2, 0.0], '2': [2.33374, 22.5, nan], '3': [-1.36666, 14.4, nan], '4': [2.86073, 33.8, nan], '5': [1.08383, 18.6, nan], '6': [1.15792, 27.7, nan], '7': [1.516, 33.5, nan], '8': [-0.77528, 17.8, nan], '9': [-0.35251, 24.1, nan], '10': [0.95176, 16.4, nan], '11': [-0.78019, 8.7, nan], '12': [-0.45468, 10.4, nan], '13': [1.14497, 46.3, nan], '14': [-0.47971, 19.0, nan], '15': [0.08552, 17.1, nan], '16': [-0.74197, 10.2, nan], '17': [-1.29147, 16.7, nan], '18': [0.81747, 39.7, nan], '19': [1.52976, 39.3, nan], '20': [1.78443, 25.4, nan], '21': [0.8515, 41.2, nan], '22': [1.98295, 18.1, nan], '23': [0.86374, 21.5, nan], '24': [0.94161, 17.3, nan], '25': [1.10084, 32.4, nan], '26': [-0.5591, 19.8, nan], '27': [0.84926, 34.3, nan], '28': [0.86596, 25.3, nan], '29': [1.3764, 46.7, nan]}\n",
      "Linked data shape (before handling missing values): (784, 3)\n",
      "Data after handling missing values: (0, 2)\n",
      "Quartiles for 'Cystic_Fibrosis':\n",
      "  25%: nan\n",
      "  50% (Median): nan\n",
      "  75%: nan\n",
      "Min: nan\n",
      "Max: nan\n",
      "Quartiles for 'Age':\n",
      "  25%: nan\n",
      "  50% (Median): nan\n",
      "  75%: nan\n",
      "Min: nan\n",
      "Max: nan\n",
      "The distribution of the feature 'Age' in this dataset is fine.\n",
      "\n",
      "Abnormality detected in the cohort: GSE60690. Preprocessing failed.\n",
      "Data was determined to be unusable and was not saved\n"
     ]
    }
   ],
   "source": [
    "# 1. Normalize gene symbols in the gene expression data\n",
    "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n",
    "print(f\"Normalized gene data shape: {normalized_gene_data.shape}\")\n",
    "print(\"First few genes with their expression values after normalization:\")\n",
    "print(normalized_gene_data.head())\n",
    "\n",
    "# Save the normalized 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",
    "# 2. Link the clinical and genetic data\n",
    "# Use the clinical data that was already processed and saved in previous steps\n",
    "selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)\n",
    "print(\"Clinical data preview:\")\n",
    "print(preview_df(selected_clinical_df))\n",
    "\n",
    "# Link the clinical and genetic data\n",
    "linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)\n",
    "print(f\"Linked data shape (before handling missing values): {linked_data.shape}\")\n",
    "\n",
    "# 3. Handle missing values in the linked data\n",
    "linked_data = handle_missing_values(linked_data, trait)\n",
    "print(f\"Data after handling missing values: {linked_data.shape}\")\n",
    "\n",
    "# 4. Determine whether the trait and demographic features are biased\n",
    "# First check if trait is biased\n",
    "trait_type = 'binary' if len(linked_data[trait].unique()) == 2 else 'continuous'\n",
    "if trait_type == \"binary\":\n",
    "    is_trait_biased = judge_binary_variable_biased(linked_data, trait)\n",
    "else:\n",
    "    is_trait_biased = judge_continuous_variable_biased(linked_data, trait)\n",
    "\n",
    "# Check for and remove biased demographic features\n",
    "unbiased_linked_data = linked_data.copy()\n",
    "if \"Age\" in unbiased_linked_data.columns:\n",
    "    age_biased = judge_continuous_variable_biased(unbiased_linked_data, 'Age')\n",
    "    if age_biased:\n",
    "        print(f\"The distribution of the feature \\'Age\\' in this dataset is severely biased.\\n\")\n",
    "        unbiased_linked_data = unbiased_linked_data.drop(columns='Age')\n",
    "    else:\n",
    "        print(f\"The distribution of the feature \\'Age\\' in this dataset is fine.\\n\")\n",
    "\n",
    "if \"Gender\" in unbiased_linked_data.columns:\n",
    "    gender_biased = judge_binary_variable_biased(unbiased_linked_data, 'Gender')\n",
    "    if gender_biased:\n",
    "        print(f\"The distribution of the feature \\'Gender\\' in this dataset is severely biased.\\n\")\n",
    "        unbiased_linked_data = unbiased_linked_data.drop(columns='Gender')\n",
    "    else:\n",
    "        print(f\"The distribution of the feature \\'Gender\\' in this dataset is fine.\\n\")\n",
    "\n",
    "# 5. Conduct final quality validation and save 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=f\"Dataset contains gene expression data comparing CFBE41o-ΔF508 (CF) cells with CFBE41o−CFTR (control) cells.\"\n",
    ")\n",
    "\n",
    "# 6. If the linked data is usable, save it\n",
    "if is_usable:\n",
    "    os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n",
    "    unbiased_linked_data.to_csv(out_data_file)\n",
    "    print(f\"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
}