File size: 80,171 Bytes
82732bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "178f1766",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T05:09:55.667808Z",
     "iopub.status.busy": "2025-03-25T05:09:55.667684Z",
     "iopub.status.idle": "2025-03-25T05:09:55.866783Z",
     "shell.execute_reply": "2025-03-25T05:09:55.866410Z"
    }
   },
   "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 = \"Epilepsy\"\n",
    "cohort = \"GSE65106\"\n",
    "\n",
    "# Input paths\n",
    "in_trait_dir = \"../../input/GEO/Epilepsy\"\n",
    "in_cohort_dir = \"../../input/GEO/Epilepsy/GSE65106\"\n",
    "\n",
    "# Output paths\n",
    "out_data_file = \"../../output/preprocess/Epilepsy/GSE65106.csv\"\n",
    "out_gene_data_file = \"../../output/preprocess/Epilepsy/gene_data/GSE65106.csv\"\n",
    "out_clinical_data_file = \"../../output/preprocess/Epilepsy/clinical_data/GSE65106.csv\"\n",
    "json_path = \"../../output/preprocess/Epilepsy/cohort_info.json\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb719f9a",
   "metadata": {},
   "source": [
    "### Step 1: Initial Data Loading"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4abb058e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T05:09:55.868266Z",
     "iopub.status.busy": "2025-03-25T05:09:55.868115Z",
     "iopub.status.idle": "2025-03-25T05:09:55.985206Z",
     "shell.execute_reply": "2025-03-25T05:09:55.984833Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Background Information:\n",
      "!Series_title\t\"Expression profiling of skin fibroblast, iPSC, iPSC-derived neural progenitors, and iPSC-derived neurons from Autism Spectrum Disorder male patients and their unaffected normal male siblings\"\n",
      "!Series_summary\t\"Autism spectrum disorder (ASD) is an early onset neurodevelopmental disorder, which is characterized by disturbances of brain function and behavioral deficits in core areas of impaired reciprocal socialization, impairment in communication skills, and repetitive or restrictive interests and behaviors. ASD is known to have a significant genetic risk, but the underlying genetic variation can be attributed to hundreds of genes. The molecular and pathophysiologic basis of ASD remains elusive because of its genetic heterogeneity and complexity, its high comorbidity with other diseases, and the paucity of brain tissue for study. The invasive nature of collecting primary neuronal tissue from patients might be circumvented through reprogramming peripheral cells to induced pluripotent stem cells (iPSCs), which are able to generate live neurons carrying the genetic variants of disease. This breakthrough allows us to access the cellular and molecular phenotypes of patients with ‘intrinsic autism’, that is patients without known genetic disorders or identifiable syndromes or malformations. To do this, we studied a relatively homogeneous patient population of boys with intrinsic autism by excluding patients with known genetic disease or recognizable phenotypes or syndromes, as well as those with profound mental retardation or primary seizure disorders. We generated iPSCs from patients with intrinsic autism, their unaffected male siblings and age-, and sex-matched unaffected controls. And these stem cells were subsequently differentiated into electrophysiologically active neurons. The expression profile for autistic and their unaffected siblings' iPSC-derived neurons were compared. A distinct expression profile was found between autism and sib control. The significantly differentially expressed genes (> 2-fold, FDR < 0.05) in autistic iPSC-derived neurons were significantly enriched for processes related to synaptic transmission, such as neuroactive ligand-receptor signaling and extracellular matrix interactions (FDR < 0.05), and were significantly enriched for genes previously associated with ASD (p < 0.05). Our findings suggest approaches such as iPSC-derived neurons will be an important method to obtain tissue for study that appropriately recapitulates the complex dynamics of an autistic neural cell.\"\n",
      "!Series_overall_design\t\"We generated induced pluripotent stem cells (iPSCs) from male patients with intrinsic autism, their unaffected male siblings, and age-, and sex-matched unaffected controls. And these stem cells were subsequently differentiated into electrophysiologically active neurons following 80 days of post-mitotic neural differentiation. These samples, including fibroblast, iPSC, iPSC-derived neural progenitors (NPC) and iPSC-derived neurons, were analyzed for the change of gene expression profile by whole genome microarray.\"\n",
      "Sample Characteristics Dictionary:\n",
      "{0: ['cell type: Fibroblast', 'cell type: hESC', 'cell type: iPSC', 'cell type: iPSC-derived NPC', 'cell type: iPSC-derived neuron'], 1: ['disease type: ASD', 'disease type: Normal', 'disease type: WT'], 2: ['donor id: AA1', 'donor id: AA2', 'donor id: AA3', 'donor id: AA4', 'donor id: AN1', 'donor id: AN2', 'donor id: AN3', 'donor id: AN4', 'donor id: NN1', 'donor id: NN2', 'donor id: NN3', 'donor id: CT2', 'donor id: ESI-053'], 3: ['donor age: 8', 'donor age: 7', 'donor age: 9', 'donor age: 10', 'donor age: 16', 'donor age: embryonic'], 4: ['donor sex: Male', 'donor sex: Female'], 5: ['batch: 1a', 'batch: 2a', 'batch: 3a', 'batch: 3b', 'batch: 4a', 'cell line: CT2', 'cell line: ESI-053', 'batch: 9a', 'batch: 10a', 'batch: 12a', 'batch: 11a', 'batch: 21a', 'batch: 18a', 'batch: 19a', 'batch: 15a', 'batch: 16b', 'batch: 16a', 'batch: 19b', 'batch: 18b', 'batch: 17a', 'batch: 14d', 'batch: 14a', 'batch: 14c', 'batch: 13b', 'batch: 13a', 'batch: 14b'], 6: [nan, 'batch: 7a', 'batch: 6a']}\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": "bb8ffe12",
   "metadata": {},
   "source": [
    "### Step 2: Dataset Analysis and Clinical Feature Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8e744408",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T05:09:55.986407Z",
     "iopub.status.busy": "2025-03-25T05:09:55.986296Z",
     "iopub.status.idle": "2025-03-25T05:09:55.998632Z",
     "shell.execute_reply": "2025-03-25T05:09:55.998342Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preview of extracted clinical features:\n",
      "{0: [1.0, 8.0, 1.0], 1: [0.0, 7.0, 0.0], 2: [0.0, 9.0, nan], 3: [nan, 10.0, nan], 4: [nan, 16.0, nan], 5: [nan, nan, nan], 6: [nan, nan, nan], 7: [nan, nan, nan], 8: [nan, nan, nan], 9: [nan, nan, nan], 10: [nan, nan, nan], 11: [nan, nan, nan], 12: [nan, nan, nan], 13: [nan, nan, nan], 14: [nan, nan, nan], 15: [nan, nan, nan], 16: [nan, nan, nan], 17: [nan, nan, nan], 18: [nan, nan, nan], 19: [nan, nan, nan], 20: [nan, nan, nan], 21: [nan, nan, nan], 22: [nan, nan, nan], 23: [nan, nan, nan], 24: [nan, nan, nan], 25: [nan, nan, nan]}\n",
      "Clinical data saved to ../../output/preprocess/Epilepsy/clinical_data/GSE65106.csv\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "import json\n",
    "from typing import Dict, Any, Optional, Callable, List, Tuple\n",
    "\n",
    "# Analysis of dataset\n",
    "# 1. Gene Expression Data Availability\n",
    "# Based on the series title and summary, this dataset contains gene expression data from microarray analysis\n",
    "is_gene_available = True\n",
    "\n",
    "# 2. Variable Availability and Data Type Conversion\n",
    "# 2.1 Data Availability\n",
    "# From the sample characteristics, we can identify:\n",
    "# - Trait (Epilepsy): row 1 contains 'disease type'\n",
    "# - Age: row 3 contains 'donor age'\n",
    "# - Gender: row 4 contains 'donor sex'\n",
    "\n",
    "trait_row = 1  # 'disease type: ASD' or 'disease type: Normal'\n",
    "age_row = 3    # 'donor age: X'\n",
    "gender_row = 4  # 'donor sex: Male' or 'donor sex: Female'\n",
    "\n",
    "# 2.2 Data Type Conversion Functions\n",
    "def convert_trait(val: str) -> int:\n",
    "    \"\"\"Convert trait value to binary (0: control, 1: case)\"\"\"\n",
    "    if pd.isna(val):\n",
    "        return None\n",
    "    \n",
    "    # Extract value after colon and strip whitespace\n",
    "    if ':' in val:\n",
    "        val = val.split(':', 1)[1].strip()\n",
    "    \n",
    "    # Convert ASD to 1 (case), Normal/WT to 0 (control)\n",
    "    if val.lower() == 'asd':\n",
    "        return 1\n",
    "    elif val.lower() in ['normal', 'wt']:\n",
    "        return 0\n",
    "    return None\n",
    "\n",
    "def convert_age(val: str) -> float:\n",
    "    \"\"\"Convert age value to continuous numeric value\"\"\"\n",
    "    if pd.isna(val):\n",
    "        return None\n",
    "    \n",
    "    # Extract value after colon and strip whitespace\n",
    "    if ':' in val:\n",
    "        val = val.split(':', 1)[1].strip()\n",
    "    \n",
    "    # Try to convert to float\n",
    "    try:\n",
    "        # If it's 'embryonic', we can't assign a specific age\n",
    "        if val.lower() == 'embryonic':\n",
    "            return None\n",
    "        return float(val)\n",
    "    except (ValueError, TypeError):\n",
    "        return None\n",
    "\n",
    "def convert_gender(val: str) -> int:\n",
    "    \"\"\"Convert gender value to binary (0: female, 1: male)\"\"\"\n",
    "    if pd.isna(val):\n",
    "        return None\n",
    "    \n",
    "    # Extract value after colon and strip whitespace\n",
    "    if ':' in val:\n",
    "        val = val.split(':', 1)[1].strip()\n",
    "    \n",
    "    # Convert Male to 1, Female to 0\n",
    "    if val.lower() == 'male':\n",
    "        return 1\n",
    "    elif val.lower() == 'female':\n",
    "        return 0\n",
    "    return None\n",
    "\n",
    "# 3. Save Metadata\n",
    "# Trait data is available (trait_row is not None)\n",
    "is_trait_available = trait_row is not None\n",
    "validate_and_save_cohort_info(\n",
    "    is_final=False,\n",
    "    cohort=cohort,\n",
    "    info_path=json_path,\n",
    "    is_gene_available=is_gene_available,\n",
    "    is_trait_available=is_trait_available\n",
    ")\n",
    "\n",
    "# 4. Clinical Feature Extraction\n",
    "# Since trait_row is not None, we proceed with clinical feature extraction\n",
    "if trait_row is not None:\n",
    "    # Create a DataFrame from the sample characteristics dictionary\n",
    "    # First, convert the dictionary to a proper format\n",
    "    sample_char_dict = {0: ['cell type: Fibroblast', 'cell type: hESC', 'cell type: iPSC', 'cell type: iPSC-derived NPC', 'cell type: iPSC-derived neuron'], \n",
    "                        1: ['disease type: ASD', 'disease type: Normal', 'disease type: WT'], \n",
    "                        2: ['donor id: AA1', 'donor id: AA2', 'donor id: AA3', 'donor id: AA4', 'donor id: AN1', 'donor id: AN2', 'donor id: AN3', 'donor id: AN4', 'donor id: NN1', 'donor id: NN2', 'donor id: NN3', 'donor id: CT2', 'donor id: ESI-053'], \n",
    "                        3: ['donor age: 8', 'donor age: 7', 'donor age: 9', 'donor age: 10', 'donor age: 16', 'donor age: embryonic'], \n",
    "                        4: ['donor sex: Male', 'donor sex: Female'], \n",
    "                        5: ['batch: 1a', 'batch: 2a', 'batch: 3a', 'batch: 3b', 'batch: 4a', 'cell line: CT2', 'cell line: ESI-053', 'batch: 9a', 'batch: 10a', 'batch: 12a', 'batch: 11a', 'batch: 21a', 'batch: 18a', 'batch: 19a', 'batch: 15a', 'batch: 16b', 'batch: 16a', 'batch: 19b', 'batch: 18b', 'batch: 17a', 'batch: 14d', 'batch: 14a', 'batch: 14c', 'batch: 13b', 'batch: 13a', 'batch: 14b'], \n",
    "                        6: [np.nan, 'batch: 7a', 'batch: 6a']}\n",
    "    \n",
    "    # Create DataFrame with sample characteristics\n",
    "    clinical_data = pd.DataFrame.from_dict(sample_char_dict, orient='index')\n",
    "    \n",
    "    # Use the library function to 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 extracted clinical features\n",
    "    print(\"Preview of extracted clinical features:\")\n",
    "    print(preview_df(selected_clinical_df))\n",
    "    \n",
    "    # Save clinical data to CSV\n",
    "    os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\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": "aa3d2340",
   "metadata": {},
   "source": [
    "### Step 3: Gene Data Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0eac9db3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T05:09:55.999781Z",
     "iopub.status.busy": "2025-03-25T05:09:55.999673Z",
     "iopub.status.idle": "2025-03-25T05:09:56.174293Z",
     "shell.execute_reply": "2025-03-25T05:09:56.173839Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SOFT file: ../../input/GEO/Epilepsy/GSE65106/GSE65106_family.soft.gz\n",
      "Matrix file: ../../input/GEO/Epilepsy/GSE65106/GSE65106_series_matrix.txt.gz\n",
      "Found the matrix table marker in the file.\n",
      "Gene data shape: (33297, 59)\n",
      "First 20 gene/probe identifiers:\n",
      "['7892501', '7892502', '7892503', '7892504', '7892505', '7892506', '7892507', '7892508', '7892509', '7892510', '7892511', '7892512', '7892513', '7892514', '7892515', '7892516', '7892517', '7892518', '7892519', '7892520']\n"
     ]
    }
   ],
   "source": [
    "# 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",
    "print(f\"SOFT file: {soft_file}\")\n",
    "print(f\"Matrix file: {matrix_file}\")\n",
    "\n",
    "# Set gene availability flag\n",
    "is_gene_available = True  # Initially assume gene data is available\n",
    "\n",
    "# First check if the matrix file contains the expected marker\n",
    "found_marker = False\n",
    "try:\n",
    "    with gzip.open(matrix_file, 'rt') as file:\n",
    "        for line in file:\n",
    "            if \"!series_matrix_table_begin\" in line:\n",
    "                found_marker = True\n",
    "                break\n",
    "    \n",
    "    if found_marker:\n",
    "        print(\"Found the matrix table marker in the file.\")\n",
    "    else:\n",
    "        print(\"Warning: Could not find '!series_matrix_table_begin' marker in the file.\")\n",
    "        \n",
    "    # Try to extract gene data from the matrix file\n",
    "    gene_data = get_genetic_data(matrix_file)\n",
    "    \n",
    "    if gene_data.shape[0] == 0:\n",
    "        print(\"Warning: Extracted gene data has 0 rows.\")\n",
    "        is_gene_available = False\n",
    "    else:\n",
    "        print(f\"Gene data shape: {gene_data.shape}\")\n",
    "        # Print the first 20 gene/probe identifiers\n",
    "        print(\"First 20 gene/probe identifiers:\")\n",
    "        print(gene_data.index[:20].tolist())\n",
    "        \n",
    "except Exception as e:\n",
    "    print(f\"Error extracting gene data: {e}\")\n",
    "    is_gene_available = False\n",
    "    \n",
    "    # Try to diagnose the file format\n",
    "    print(\"Examining file content to diagnose the issue:\")\n",
    "    try:\n",
    "        with gzip.open(matrix_file, 'rt') as file:\n",
    "            for i, line in enumerate(file):\n",
    "                if i < 10:  # Print first 10 lines to diagnose\n",
    "                    print(f\"Line {i}: {line.strip()[:100]}...\")  # Print first 100 chars of each line\n",
    "                else:\n",
    "                    break\n",
    "    except Exception as e2:\n",
    "        print(f\"Error examining file: {e2}\")\n",
    "\n",
    "if not is_gene_available:\n",
    "    print(\"Gene expression data could not be successfully extracted from this dataset.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e19f3ca9",
   "metadata": {},
   "source": [
    "### Step 4: Gene Identifier Review"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b40e324a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T05:09:56.175715Z",
     "iopub.status.busy": "2025-03-25T05:09:56.175603Z",
     "iopub.status.idle": "2025-03-25T05:09:56.177432Z",
     "shell.execute_reply": "2025-03-25T05:09:56.177151Z"
    }
   },
   "outputs": [],
   "source": [
    "# These appear to be probe identifiers from an Illumina HumanHT-12 array, not standard human gene symbols.\n",
    "# They need to be mapped to official gene symbols for proper analysis.\n",
    "\n",
    "requires_gene_mapping = True\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f0b25b0",
   "metadata": {},
   "source": [
    "### Step 5: Gene Annotation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "42d457ee",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T05:09:56.178558Z",
     "iopub.status.busy": "2025-03-25T05:09:56.178457Z",
     "iopub.status.idle": "2025-03-25T05:10:01.153857Z",
     "shell.execute_reply": "2025-03-25T05:10:01.153258Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Gene annotation preview:\n",
      "Columns in gene annotation: ['ID', 'GB_LIST', 'SPOT_ID', 'seqname', 'RANGE_GB', 'RANGE_STRAND', 'RANGE_START', 'RANGE_STOP', 'total_probes', 'gene_assignment', 'mrna_assignment', 'category']\n",
      "{'ID': ['7896736', '7896738', '7896740', '7896742', '7896744'], 'GB_LIST': [nan, nan, 'NM_001004195,NM_001005240,NM_001005484,BC136848,BC136867,BC136907,BC136908', 'NR_024437,XM_006711854,XM_006726377,XR_430662,AK298283,AL137655,BC032332,BC118988,BC122537,BC131690,NM_207366,AK301928,BC071667', 'NM_001005221,NM_001005224,NM_001005277,NM_001005504,BC137547,BC137568'], 'SPOT_ID': ['chr1:53049-54936', 'chr1:63015-63887', 'chr1:69091-70008', 'chr1:334129-334296', 'chr1:367659-368597'], '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': ['53049', '63015', '69091', '334129', '367659'], 'RANGE_STOP': ['54936', '63887', '70008', '334296', '368597'], 'total_probes': [7.0, 31.0, 24.0, 6.0, 36.0], 'gene_assignment': ['---', 'ENST00000328113 // OR4G2P // olfactory receptor, family 4, subfamily G, member 2 pseudogene // --- // --- /// ENST00000492842 // OR4G11P // olfactory receptor, family 4, subfamily G, member 11 pseudogene // --- // --- /// ENST00000588632 // OR4G1P // olfactory receptor, family 4, subfamily G, member 1 pseudogene // --- // ---', 'NM_001004195 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682 /// NM_001005240 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// NM_001005484 // OR4F5 // olfactory receptor, family 4, subfamily F, member 5 // 1p36.33 // 79501 /// ENST00000318050 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// ENST00000326183 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682 /// ENST00000335137 // OR4F5 // olfactory receptor, family 4, subfamily F, member 5 // 1p36.33 // 79501 /// ENST00000585993 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// BC136848 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// BC136867 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// BC136907 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682 /// BC136908 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682', 'NR_024437 // LOC728323 // uncharacterized LOC728323 // 2q37.3 // 728323 /// XM_006711854 // LOC101060626 // F-box only protein 25-like // --- // 101060626 /// XM_006726377 // LOC101060626 // F-box only protein 25-like // --- // 101060626 /// XR_430662 // LOC101927097 // uncharacterized LOC101927097 // --- // 101927097 /// ENST00000279067 // LINC00266-1 // long intergenic non-protein coding RNA 266-1 // 20q13.33 // 140849 /// ENST00000431812 // LOC101928706 // uncharacterized LOC101928706 // --- // 101928706 /// ENST00000431812 // LOC101929823 // uncharacterized LOC101929823 // --- // 101929823 /// ENST00000433444 // LOC728323 // uncharacterized LOC728323 // 2q37.3 // 728323 /// ENST00000436899 // LINC00266-3 // long intergenic non-protein coding RNA 266-3 // --- // --- /// ENST00000445252 // LINC00266-1 // long intergenic non-protein coding RNA 266-1 // 20q13.33 // 140849 /// ENST00000455207 // LOC101928706 // uncharacterized LOC101928706 // --- // 101928706 /// ENST00000455207 // LOC101929823 // uncharacterized LOC101929823 // --- // 101929823 /// ENST00000455464 // LOC101928706 // uncharacterized LOC101928706 // --- // 101928706 /// ENST00000455464 // LOC101929823 // uncharacterized LOC101929823 // --- // 101929823 /// ENST00000456398 // LOC728323 // uncharacterized LOC728323 // 2q37.3 // 728323 /// ENST00000601814 // LOC101928706 // uncharacterized LOC101928706 // --- // 101928706 /// ENST00000601814 // LOC101929823 // uncharacterized LOC101929823 // --- // 101929823 /// AK298283 // LOC728323 // uncharacterized LOC728323 // 2q37.3 // 728323 /// AL137655 // LOC100134822 // uncharacterized LOC100134822 // --- // 100134822 /// BC032332 // PCMTD2 // protein-L-isoaspartate (D-aspartate) O-methyltransferase domain containing 2 // 20q13.33 // 55251 /// BC118988 // LINC00266-1 // long intergenic non-protein coding RNA 266-1 // 20q13.33 // 140849 /// BC122537 // LINC00266-1 // long intergenic non-protein coding RNA 266-1 // 20q13.33 // 140849 /// BC131690 // LOC728323 // uncharacterized LOC728323 // 2q37.3 // 728323 /// NM_207366 // SEPT14 // septin 14 // 7p11.2 // 346288 /// ENST00000388975 // SEPT14 // septin 14 // 7p11.2 // 346288 /// ENST00000427373 // LINC00266-4P // long intergenic non-protein coding RNA 266-4, pseudogene // --- // --- /// ENST00000431796 // LOC728323 // uncharacterized LOC728323 // 2q37.3 // 728323 /// ENST00000509776 // LINC00266-2P // long intergenic non-protein coding RNA 266-2, pseudogene // --- // --- /// ENST00000570230 // LOC101929008 // uncharacterized LOC101929008 // --- // 101929008 /// ENST00000570230 // LOC101929038 // uncharacterized LOC101929038 // --- // 101929038 /// ENST00000570230 // LOC101930130 // uncharacterized LOC101930130 // --- // 101930130 /// ENST00000570230 // LOC101930567 // uncharacterized LOC101930567 // --- // 101930567 /// AK301928 // SEPT14 // septin 14 // 7p11.2 // 346288', 'NM_001005221 // OR4F29 // olfactory receptor, family 4, subfamily F, member 29 // 1p36.33 // 729759 /// NM_001005224 // OR4F3 // olfactory receptor, family 4, subfamily F, member 3 // 5q35.3 // 26683 /// NM_001005277 // OR4F16 // olfactory receptor, family 4, subfamily F, member 16 // 1p36.33 // 81399 /// NM_001005504 // OR4F21 // olfactory receptor, family 4, subfamily F, member 21 // 8p23.3 // 441308 /// ENST00000320901 // OR4F21 // olfactory receptor, family 4, subfamily F, member 21 // 8p23.3 // 441308 /// ENST00000332831 // OR4F3 // olfactory receptor, family 4, subfamily F, member 3 // 5q35.3 // 26683 /// ENST00000332831 // OR4F16 // olfactory receptor, family 4, subfamily F, member 16 // 1p36.33 // 81399 /// ENST00000332831 // OR4F29 // olfactory receptor, family 4, subfamily F, member 29 // 1p36.33 // 729759 /// ENST00000402444 // OR4F7P // olfactory receptor, family 4, subfamily F, member 7 pseudogene // --- // --- /// ENST00000405102 // OR4F1P // olfactory receptor, family 4, subfamily F, member 1 pseudogene // --- // --- /// ENST00000424047 // OR4F2P // olfactory receptor, family 4, subfamily F, member 2 pseudogene // --- // --- /// ENST00000426406 // OR4F3 // olfactory receptor, family 4, subfamily F, member 3 // 5q35.3 // 26683 /// ENST00000426406 // OR4F16 // olfactory receptor, family 4, subfamily F, member 16 // 1p36.33 // 81399 /// ENST00000426406 // OR4F29 // olfactory receptor, family 4, subfamily F, member 29 // 1p36.33 // 729759 /// ENST00000456475 // OR4F3 // olfactory receptor, family 4, subfamily F, member 3 // 5q35.3 // 26683 /// ENST00000456475 // OR4F16 // olfactory receptor, family 4, subfamily F, member 16 // 1p36.33 // 81399 /// ENST00000456475 // OR4F29 // olfactory receptor, family 4, subfamily F, member 29 // 1p36.33 // 729759 /// ENST00000559128 // OR4F28P // olfactory receptor, family 4, subfamily F, member 28 pseudogene // --- // --- /// BC137547 // OR4F3 // olfactory receptor, family 4, subfamily F, member 3 // 5q35.3 // 26683 /// BC137547 // OR4F16 // olfactory receptor, family 4, subfamily F, member 16 // 1p36.33 // 81399 /// BC137547 // OR4F29 // olfactory receptor, family 4, subfamily F, member 29 // 1p36.33 // 729759 /// BC137568 // OR4F3 // olfactory receptor, family 4, subfamily F, member 3 // 5q35.3 // 26683 /// BC137568 // OR4F16 // olfactory receptor, family 4, subfamily F, member 16 // 1p36.33 // 81399 /// BC137568 // OR4F29 // olfactory receptor, family 4, subfamily F, member 29 // 1p36.33 // 729759 /// ENST00000589943 // OR4F8P // olfactory receptor, family 4, subfamily F, member 8 pseudogene // --- // ---'], 'mrna_assignment': ['NONHSAT060105 // NONCODE // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 7 // 7 // 0', 'ENST00000328113 // ENSEMBL // havana:known chromosome:GRCh38:15:101926805:101927707:-1 gene:ENSG00000183909 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 100 // 100 // 31 // 31 // 0 /// ENST00000492842 // ENSEMBL // havana:known chromosome:GRCh38:1:62948:63887:1 gene:ENSG00000240361 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 100 // 100 // 31 // 31 // 0 /// ENST00000588632 // ENSEMBL // havana:known chromosome:GRCh38:19:104535:105471:1 gene:ENSG00000267310 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 100 // 100 // 31 // 31 // 0 /// NONHSAT000016 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 31 // 31 // 0 /// NONHSAT051704 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 31 // 31 // 0 /// NONHSAT060106 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 31 // 31 // 0', 'NM_001004195 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 4 (OR4F4), mRNA. // chr1 // 100 // 100 // 24 // 24 // 0 /// NM_001005240 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 17 (OR4F17), mRNA. // chr1 // 100 // 100 // 24 // 24 // 0 /// NM_001005484 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000318050 // ENSEMBL // ensembl:known chromosome:GRCh38:19:110643:111696:1 gene:ENSG00000176695 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000326183 // ENSEMBL // ensembl_havana_transcript:known chromosome:GRCh38:15:101922042:101923095:-1 gene:ENSG00000177693 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000335137 // ENSEMBL // ensembl_havana_transcript:known chromosome:GRCh38:1:69091:70008:1 gene:ENSG00000186092 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000585993 // ENSEMBL // havana:known chromosome:GRCh38:19:107461:111696:1 gene:ENSG00000176695 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 100 // 100 // 24 // 24 // 0 /// BC136848 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 17, mRNA (cDNA clone MGC:168462 IMAGE:9020839), complete cds. // chr1 // 100 // 100 // 24 // 24 // 0 /// BC136867 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 17, mRNA (cDNA clone MGC:168481 IMAGE:9020858), complete cds. // chr1 // 100 // 100 // 24 // 24 // 0 /// BC136907 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 4, mRNA (cDNA clone MGC:168521 IMAGE:9020898), complete cds. // chr1 // 100 // 100 // 24 // 24 // 0 /// BC136908 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 4, mRNA (cDNA clone MGC:168522 IMAGE:9020899), complete cds. // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000618231 // ENSEMBL // havana:known chromosome:GRCh38:19:110613:111417:1 gene:ENSG00000176695 gene_biotype:protein_coding transcript_biotype:retained_intron // chr1 // 100 // 88 // 21 // 21 // 0', 'NR_024437 // RefSeq // Homo sapiens uncharacterized LOC728323 (LOC728323), long non-coding RNA. // chr1 // 100 // 100 // 6 // 6 // 0 /// XM_006711854 // RefSeq // PREDICTED: Homo sapiens F-box only protein 25-like (LOC101060626), partial mRNA. // chr1 // 100 // 100 // 6 // 6 // 0 /// XM_006726377 // RefSeq // PREDICTED: Homo sapiens F-box only protein 25-like (LOC101060626), partial mRNA. // chr1 // 100 // 100 // 6 // 6 // 0 /// XR_430662 // RefSeq // PREDICTED: Homo sapiens uncharacterized LOC101927097 (LOC101927097), misc_RNA. // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000279067 // ENSEMBL // ensembl_havana_transcript:known chromosome:GRCh38:20:64290385:64303559:1 gene:ENSG00000149656 gene_biotype:processed_transcript transcript_biotype:processed_transcript // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000431812 // ENSEMBL // havana:known chromosome:GRCh38:1:485066:489553:-1 gene:ENSG00000237094 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000433444 // ENSEMBL // havana:putative chromosome:GRCh38:2:242122293:242138888:1 gene:ENSG00000220804 gene_biotype:transcribed_unprocessed_pseudogene transcript_biotype:processed_transcript // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000436899 // ENSEMBL // havana:known chromosome:GRCh38:6:131910:144885:-1 gene:ENSG00000170590 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000445252 // ENSEMBL // havana:known chromosome:GRCh38:20:64294897:64311371:1 gene:ENSG00000149656 gene_biotype:processed_transcript transcript_biotype:processed_transcript // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000455207 // ENSEMBL // havana:known chromosome:GRCh38:1:373182:485208:-1 gene:ENSG00000237094 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000455464 // ENSEMBL // havana:known chromosome:GRCh38:1:476531:497259:-1 gene:ENSG00000237094 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000456398 // ENSEMBL // havana:known chromosome:GRCh38:2:242088633:242140638:1 gene:ENSG00000220804 gene_biotype:transcribed_unprocessed_pseudogene transcript_biotype:processed_transcript // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000601814 // ENSEMBL // havana:known chromosome:GRCh38:1:484832:495476:-1 gene:ENSG00000237094 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// AK298283 // GenBank // Homo sapiens cDNA FLJ60027 complete cds, moderately similar to F-box only protein 25. // chr1 // 100 // 100 // 6 // 6 // 0 /// AL137655 // GenBank // Homo sapiens mRNA; cDNA DKFZp434B2016 (from clone DKFZp434B2016). // chr1 // 100 // 100 // 6 // 6 // 0 /// BC032332 // GenBank // Homo sapiens protein-L-isoaspartate (D-aspartate) O-methyltransferase domain containing 2, mRNA (cDNA clone MGC:40288 IMAGE:5169056), complete cds. // chr1 // 100 // 100 // 6 // 6 // 0 /// BC118988 // GenBank // Homo sapiens chromosome 20 open reading frame 69, mRNA (cDNA clone MGC:141807 IMAGE:40035995), complete cds. // chr1 // 100 // 100 // 6 // 6 // 0 /// BC122537 // GenBank // Homo sapiens chromosome 20 open reading frame 69, mRNA (cDNA clone MGC:141808 IMAGE:40035996), complete cds. // chr1 // 100 // 100 // 6 // 6 // 0 /// BC131690 // GenBank // Homo sapiens similar to bA476I15.3 (novel protein similar to septin), mRNA (cDNA clone IMAGE:40119684), partial cds. // chr1 // 100 // 100 // 6 // 6 // 0 /// NM_207366 // RefSeq // Homo sapiens septin 14 (SEPT14), mRNA. // chr1 // 50 // 100 // 3 // 6 // 0 /// ENST00000388975 // ENSEMBL // ensembl_havana_transcript:known chromosome:GRCh38:7:55793544:55862789:-1 gene:ENSG00000154997 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 50 // 100 // 3 // 6 // 0 /// ENST00000427373 // ENSEMBL // havana:known chromosome:GRCh38:Y:25378300:25394719:-1 gene:ENSG00000228786 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 67 // 100 // 4 // 6 // 0 /// ENST00000431796 // ENSEMBL // havana:known chromosome:GRCh38:2:242088693:242122405:1 gene:ENSG00000220804 gene_biotype:transcribed_unprocessed_pseudogene transcript_biotype:processed_transcript // chr1 // 60 // 83 // 3 // 5 // 0 /// ENST00000509776 // ENSEMBL // havana:known chromosome:GRCh38:Y:24278681:24291346:1 gene:ENSG00000248792 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 67 // 100 // 4 // 6 // 0 /// ENST00000570230 // ENSEMBL // havana:known chromosome:GRCh38:16:90157932:90178344:1 gene:ENSG00000260528 gene_biotype:processed_transcript transcript_biotype:processed_transcript // chr1 // 67 // 100 // 4 // 6 // 0 /// AK301928 // GenBank // Homo sapiens cDNA FLJ59065 complete cds, moderately similar to Septin-10. // chr1 // 50 // 100 // 3 // 6 // 0 /// ENST00000413839 // ENSEMBL // havana:known chromosome:GRCh38:7:45816557:45821064:1 gene:ENSG00000226838 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000414688 // ENSEMBL // havana:known chromosome:GRCh38:1:711342:720200:-1 gene:ENSG00000230021 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000419394 // ENSEMBL // havana:known chromosome:GRCh38:1:703685:720194:-1 gene:ENSG00000230021 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000420830 // ENSEMBL // havana:known chromosome:GRCh38:1:243031272:243047869:-1 gene:ENSG00000231512 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000428915 // ENSEMBL // havana:known chromosome:GRCh38:10:38453181:38466176:1 gene:ENSG00000203496 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000439401 // ENSEMBL // havana:known chromosome:GRCh38:3:198228194:198228376:1 gene:ENSG00000226008 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000440200 // ENSEMBL // havana:known chromosome:GRCh38:1:601436:720200:-1 gene:ENSG00000230021 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000441245 // ENSEMBL // havana:known chromosome:GRCh38:1:701936:720150:-1 gene:ENSG00000230021 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 67 // 4 // 4 // 0 /// ENST00000445840 // ENSEMBL // havana:known chromosome:GRCh38:1:485032:485211:-1 gene:ENSG00000224813 gene_biotype:transcribed_unprocessed_pseudogene transcript_biotype:transcribed_unprocessed_pseudogene // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000447954 // ENSEMBL // havana:known chromosome:GRCh38:1:720058:724550:-1 gene:ENSG00000230021 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000450226 // ENSEMBL // havana:known chromosome:GRCh38:1:243038914:243047875:-1 gene:ENSG00000231512 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000453405 // ENSEMBL // havana:known chromosome:GRCh38:2:242122287:242122469:1 gene:ENSG00000244528 gene_biotype:processed_pseudogene transcript_biotype:processed_pseudogene // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000477740 // ENSEMBL // havana:known chromosome:GRCh38:1:92230:129217:-1 gene:ENSG00000238009 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000508026 // ENSEMBL // havana:known chromosome:GRCh38:8:200385:200562:-1 gene:ENSG00000255464 gene_biotype:processed_pseudogene transcript_biotype:processed_pseudogene // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000509192 // ENSEMBL // havana:known chromosome:GRCh38:5:181329241:181342213:1 gene:ENSG00000250765 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000513445 // ENSEMBL // havana:known chromosome:GRCh38:4:118640673:118640858:1 gene:ENSG00000251155 gene_biotype:processed_pseudogene transcript_biotype:processed_pseudogene // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000523795 // ENSEMBL // havana:known chromosome:GRCh38:8:192091:200563:-1 gene:ENSG00000250210 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000529266 // ENSEMBL // havana:known chromosome:GRCh38:11:121279:125784:-1 gene:ENSG00000254468 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000587432 // ENSEMBL // havana:known chromosome:GRCh38:19:191212:195696:-1 gene:ENSG00000267237 gene_biotype:transcribed_unprocessed_pseudogene transcript_biotype:processed_transcript // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000610542 // ENSEMBL // ensembl:known chromosome:GRCh38:1:120725:133723:-1 gene:ENSG00000238009 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 83 // 100 // 5 // 6 // 0 /// ENST00000612088 // ENSEMBL // ensembl:known chromosome:GRCh38:10:38453181:38466176:1 gene:ENSG00000203496 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000612214 // ENSEMBL // havana:known chromosome:GRCh38:19:186371:191429:-1 gene:ENSG00000267237 gene_biotype:transcribed_unprocessed_pseudogene transcript_biotype:processed_transcript // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000613471 // ENSEMBL // ensembl:known chromosome:GRCh38:1:476738:489710:-1 gene:ENSG00000237094 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000615295 // ENSEMBL // ensembl:known chromosome:GRCh38:5:181329241:181342213:1 gene:ENSG00000250765 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000616585 // ENSEMBL // ensembl:known chromosome:GRCh38:1:711715:724707:-1 gene:ENSG00000230021 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000618096 // ENSEMBL // havana:known chromosome:GRCh38:19:191178:191354:-1 gene:ENSG00000267237 gene_biotype:transcribed_unprocessed_pseudogene transcript_biotype:transcribed_unprocessed_pseudogene // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000618222 // ENSEMBL // ensembl:known chromosome:GRCh38:6:131910:144885:-1 gene:ENSG00000170590 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000622435 // ENSEMBL // havana:known chromosome:GRCh38:2:242088684:242159382:1 gene:ENSG00000220804 gene_biotype:transcribed_unprocessed_pseudogene transcript_biotype:processed_transcript // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000622626 // ENSEMBL // ensembl:known chromosome:GRCh38:11:112967:125927:-1 gene:ENSG00000254468 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 6 // 6 // 0 /// GENSCAN00000007486 // ENSEMBL // cdna:genscan chromosome:GRCh38:2:242089132:242175655:1 transcript_biotype:protein_coding // chr1 // 100 // 100 // 6 // 6 // 0 /// GENSCAN00000023775 // ENSEMBL // cdna:genscan chromosome:GRCh38:7:45812479:45856081:1 transcript_biotype:protein_coding // chr1 // 100 // 100 // 6 // 6 // 0 /// GENSCAN00000045845 // ENSEMBL // cdna:genscan chromosome:GRCh38:8:166086:213433:-1 transcript_biotype:protein_coding // chr1 // 100 // 100 // 6 // 6 // 0 /// BC071667 // GenBank HTC // Homo sapiens cDNA clone IMAGE:4384656, **** WARNING: chimeric clone ****. // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT000053 // NONCODE // Non-coding transcript identified by NONCODE: Sense No Exonic // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT000055 // NONCODE // Non-coding transcript identified by NONCODE: Sense No Exonic // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT000063 // NONCODE // Non-coding transcript identified by NONCODE: Sense No Exonic // chr1 // 83 // 100 // 5 // 6 // 0 /// NONHSAT000064 // NONCODE // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT000065 // NONCODE // Non-coding transcript identified by NONCODE: Sense No Exonic // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT000086 // NONCODE // Non-coding transcript identified by NONCODE: Sense No Exonic // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT000097 // NONCODE // Non-coding transcript identified by NONCODE: Sense No Exonic // chr1 // 100 // 67 // 4 // 4 // 0 /// NONHSAT000098 // NONCODE // Non-coding transcript identified by NONCODE: Sense No Exonic // chr1 // 83 // 100 // 5 // 6 // 0 /// NONHSAT010578 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 83 // 100 // 5 // 6 // 0 /// NONHSAT012829 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT017180 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT060112 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT078034 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT078035 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT078039 // NONCODE // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT078040 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT078041 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT081035 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT081036 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT094494 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT094497 // NONCODE // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT098010 // NONCODE // Non-coding transcript identified by NONCODE // chr1 // 83 // 100 // 5 // 6 // 0 /// NONHSAT105956 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT105968 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 100 // 100 // 6 // 6 // 0 /// NONHSAT120472 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 83 // 100 // 5 // 6 // 0 /// NONHSAT124571 // NONCODE // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00001800-XLOC_l2_001331 // Broad TUCP // linc-TP53BP2-4 chr1:-:224133091-224222680 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00001926-XLOC_l2_000004 // Broad TUCP // linc-OR4F16-1 chr1:+:329783-334271 // chr1 // 83 // 100 // 5 // 6 // 0 /// TCONS_l2_00001927-XLOC_l2_000004 // Broad TUCP // linc-OR4F16-1 chr1:+:334139-342806 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00002370-XLOC_l2_000720 // Broad TUCP // linc-ZNF692-5 chr1:-:92229-129217 // chr1 // 83 // 100 // 5 // 6 // 0 /// TCONS_l2_00002386-XLOC_l2_000726 // Broad TUCP // linc-OR4F29-1 chr1:-:637315-655530 // chr1 // 100 // 67 // 4 // 4 // 0 /// TCONS_l2_00002387-XLOC_l2_000726 // Broad TUCP // linc-OR4F29-1 chr1:-:639064-655574 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00002388-XLOC_l2_000726 // Broad TUCP // linc-OR4F29-1 chr1:-:646721-655580 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00002389-XLOC_l2_000726 // Broad TUCP // linc-OR4F29-1 chr1:-:655437-659930 // chr1 // 83 // 100 // 5 // 6 // 0 /// TCONS_l2_00002812-XLOC_l2_001398 // Broad TUCP // linc-PLD5-4 chr1:-:243194573-243211171 // chr1 // 83 // 100 // 5 // 6 // 0 /// TCONS_l2_00003949-XLOC_l2_001561 // Broad TUCP // linc-BMS1-9 chr10:+:38742108-38755311 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00003950-XLOC_l2_001561 // Broad TUCP // linc-BMS1-9 chr10:+:38742265-38764837 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00014349-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030831-243101574 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00014350-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030855-243102147 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00014351-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030868-243101569 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00014352-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030886-243064759 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00014354-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030931-243067562 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00014355-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030941-243102157 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00014357-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243037045-243101538 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00014358-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243058329-243064628 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00015637-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030783-243082789 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00015638-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030843-243065243 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00015639-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030843-243102469 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00015640-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030843-243102469 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00015641-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243030843-243102469 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00015643-XLOC_l2_007835 // Broad TUCP // linc-ORC6-14 chr2:+:243064443-243081039 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00016828-XLOC_l2_008724 // Broad TUCP // linc-HNF1B-4 chr20:+:62921737-62934707 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00020055-XLOC_l2_010084 // Broad TUCP // linc-MCMBP-2 chr3:+:197937115-197955676 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00025304-XLOC_l2_012836 // Broad TUCP // linc-PDCD2-1 chr6:-:131909-144885 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00025849-XLOC_l2_013383 // Broad TUCP // linc-IGFBP1-1 chr7:+:45831387-45863181 // chr1 // 100 // 100 // 6 // 6 // 0 /// TCONS_l2_00025850-XLOC_l2_013383 // Broad TUCP // linc-IGFBP1-1 chr7:+:45836951-45863174 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000437691 // ENSEMBL // havana:known chromosome:GRCh38:1:243047737:243052252:-1 gene:ENSG00000231512 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 67 // 100 // 4 // 6 // 0 /// ENST00000447236 // ENSEMBL // havana:known chromosome:GRCh38:7:56360362:56360541:-1 gene:ENSG00000231299 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 50 // 100 // 3 // 6 // 0 /// ENST00000453576 // ENSEMBL // havana:known chromosome:GRCh38:1:129081:133566:-1 gene:ENSG00000238009 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 67 // 100 // 4 // 6 // 0 /// ENST00000611754 // ENSEMBL // ensembl:known chromosome:GRCh38:Y:25378671:25391610:-1 gene:ENSG00000228786 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 67 // 100 // 4 // 6 // 0 /// ENST00000617978 // ENSEMBL // havana:known chromosome:GRCh38:1:227980051:227980227:1 gene:ENSG00000274886 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 67 // 100 // 4 // 6 // 0 /// ENST00000621799 // ENSEMBL // ensembl:known chromosome:GRCh38:16:90173217:90186204:1 gene:ENSG00000260528 gene_biotype:processed_transcript transcript_biotype:processed_transcript // chr1 // 67 // 100 // 4 // 6 // 0 /// NONHSAT000022 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 67 // 100 // 4 // 6 // 0 /// NONHSAT010579 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 67 // 100 // 4 // 6 // 0 /// NONHSAT010580 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 67 // 100 // 4 // 6 // 0 /// NONHSAT120743 // NONCODE // Non-coding transcript identified by NONCODE // chr1 // 50 // 100 // 3 // 6 // 0 /// NONHSAT139746 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 67 // 100 // 4 // 6 // 0 /// NONHSAT144650 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 67 // 100 // 4 // 6 // 0 /// NONHSAT144655 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 67 // 100 // 4 // 6 // 0 /// TCONS_l2_00002372-XLOC_l2_000720 // Broad TUCP // linc-ZNF692-5 chr1:-:129080-133566 // chr1 // 67 // 100 // 4 // 6 // 0 /// TCONS_l2_00002813-XLOC_l2_001398 // Broad TUCP // linc-PLD5-4 chr1:-:243202215-243211826 // chr1 // 67 // 100 // 4 // 6 // 0 /// TCONS_l2_00002814-XLOC_l2_001398 // Broad TUCP // linc-PLD5-4 chr1:-:243211038-243215554 // chr1 // 67 // 100 // 4 // 6 // 0 /// TCONS_l2_00010440-XLOC_l2_005352 // Broad TUCP // linc-RBM11-5 chr16:+:90244124-90289080 // chr1 // 67 // 100 // 4 // 6 // 0 /// TCONS_l2_00031062-XLOC_l2_015962 // Broad TUCP // linc-BPY2B-4 chrY:-:27524446-27540866 // chr1 // 67 // 100 // 4 // 6 // 0', 'NM_001005221 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 29 (OR4F29), mRNA. // chr1 // 100 // 100 // 36 // 36 // 0 /// NM_001005224 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 3 (OR4F3), mRNA. // chr1 // 100 // 100 // 36 // 36 // 0 /// NM_001005277 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 16 (OR4F16), mRNA. // chr1 // 100 // 100 // 36 // 36 // 0 /// NM_001005504 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 21 (OR4F21), mRNA. // chr1 // 89 // 100 // 32 // 36 // 0 /// ENST00000320901 // ENSEMBL // ensembl_havana_transcript:known chromosome:GRCh38:8:166049:167043:-1 gene:ENSG00000176269 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 89 // 100 // 32 // 36 // 0 /// ENST00000332831 // ENSEMBL // ensembl_havana_transcript:known chromosome:GRCh38:1:685716:686654:-1 gene:ENSG00000273547 gene_biotype:protein_coding transcript_biotype:protein_coding gene:ENSG00000185097 // chr1 // 100 // 100 // 36 // 36 // 0 /// ENST00000402444 // ENSEMBL // havana:known chromosome:GRCh38:6:170639606:170640536:1 gene:ENSG00000217874 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 78 // 100 // 28 // 36 // 0 /// ENST00000405102 // ENSEMBL // havana:known chromosome:GRCh38:6:105919:106856:-1 gene:ENSG00000220212 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 81 // 100 // 29 // 36 // 0 /// ENST00000424047 // ENSEMBL // havana:known chromosome:GRCh38:11:86649:87586:-1 gene:ENSG00000224777 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 78 // 100 // 28 // 36 // 0 /// ENST00000426406 // ENSEMBL // ensembl_havana_transcript:known chromosome:GRCh38:1:450740:451678:-1 gene:ENSG00000278566 gene_biotype:protein_coding transcript_biotype:protein_coding gene:ENSG00000235249 // chr1 // 100 // 100 // 36 // 36 // 0 /// ENST00000456475 // ENSEMBL // ensembl_havana_transcript:known chromosome:GRCh38:5:181367268:181368262:1 gene:ENSG00000230178 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 100 // 100 // 36 // 36 // 0 /// ENST00000559128 // ENSEMBL // havana:known chromosome:GRCh38:15:101875964:101876901:1 gene:ENSG00000257109 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 83 // 100 // 30 // 36 // 0 /// BC137547 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 3, mRNA (cDNA clone MGC:169170 IMAGE:9021547), complete cds. // chr1 // 100 // 100 // 36 // 36 // 0 /// BC137568 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 3, mRNA (cDNA clone MGC:169191 IMAGE:9021568), complete cds. // chr1 // 100 // 100 // 36 // 36 // 0 /// ENST00000589943 // ENSEMBL // havana:known chromosome:GRCh38:19:156279:157215:-1 gene:ENSG00000266971 gene_biotype:unprocessed_pseudogene transcript_biotype:unprocessed_pseudogene // chr1 // 72 // 100 // 26 // 36 // 0 /// GENSCAN00000011446 // ENSEMBL // cdna:genscan chromosome:GRCh38:5:181367527:181368225:1 transcript_biotype:protein_coding // chr1 // 100 // 64 // 23 // 23 // 0 /// GENSCAN00000017675 // ENSEMBL // cdna:genscan chromosome:GRCh38:1:685716:686414:-1 transcript_biotype:protein_coding // chr1 // 100 // 64 // 23 // 23 // 0 /// GENSCAN00000017679 // ENSEMBL // cdna:genscan chromosome:GRCh38:1:450740:451438:-1 transcript_biotype:protein_coding // chr1 // 100 // 64 // 23 // 23 // 0 /// GENSCAN00000045845 // ENSEMBL // cdna:genscan chromosome:GRCh38:8:166086:213433:-1 transcript_biotype:protein_coding // chr1 // 87 // 83 // 26 // 30 // 0 /// NONHSAT051700 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 83 // 100 // 30 // 36 // 0 /// NONHSAT051701 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 83 // 100 // 30 // 36 // 0 /// NONHSAT105966 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 81 // 100 // 29 // 36 // 0 /// NONHSAT060109 // NONCODE // Non-coding transcript identified by NONCODE: Linc // chr1 // 72 // 100 // 26 // 36 // 0'], 'category': ['main', 'main', 'main', 'main', 'main']}\n",
      "\n",
      "Sample of gene_assignment column (first 3 rows):\n",
      "Row 0: ---...\n",
      "Row 1: ENST00000328113 // OR4G2P // olfactory receptor, family 4, subfamily G, member 2 pseudogene // --- // --- /// ENST00000492842 // OR4G11P // olfactory receptor, family 4, subfamily G, member 11 pseudog...\n",
      "Row 2: NM_001004195 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682 /// NM_001005240 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 ...\n",
      "\n",
      "Attempting to extract gene symbols from gene_assignment column...\n",
      "Extracted gene symbols from first 10 rows:\n",
      "Row 0: None\n",
      "Row 1: ['OR4G2P', 'OR4G11P', 'OR4G1P']\n",
      "Row 2: ['OR4F4', 'OR4F17', 'OR4F5', 'OR4F17', 'OR4F4', 'OR4F5', 'OR4F17', 'OR4F17', 'OR4F17', 'OR4F4', 'OR4F4']\n",
      "Row 3: ['LOC728323', 'LOC101060626', 'LOC101060626', 'LOC101927097', 'LINC00266-1', 'LOC101928706', 'LOC101929823', 'LOC728323', 'LINC00266-3', 'LINC00266-1', 'LOC101928706', 'LOC101929823', 'LOC101928706', 'LOC101929823', 'LOC728323', 'LOC101928706', 'LOC101929823', 'LOC728323', 'LOC100134822', 'PCMTD2', 'LINC00266-1', 'LINC00266-1', 'LOC728323', 'SEPT14', 'SEPT14', 'LINC00266-4P', 'LOC728323', 'LINC00266-2P', 'LOC101929008', 'LOC101929038', 'LOC101930130', 'LOC101930567', 'SEPT14']\n",
      "Row 4: ['OR4F29', 'OR4F3', 'OR4F16', 'OR4F21', 'OR4F21', 'OR4F3', 'OR4F16', 'OR4F29', 'OR4F7P', 'OR4F1P', 'OR4F2P', 'OR4F3', 'OR4F16', 'OR4F29', 'OR4F3', 'OR4F16', 'OR4F29', 'OR4F28P', 'OR4F3', 'OR4F16', 'OR4F29', 'OR4F3', 'OR4F16', 'OR4F29', 'OR4F8P']\n",
      "Row 5: ['MT-TM']\n",
      "Row 6: ['MT-TW']\n",
      "Row 7: ['MT-TD']\n",
      "Row 8: ['MT-TK']\n",
      "Row 9: ['LOC100287497', 'LOC100287934', 'LOC101930657', 'LOC100287497', 'LOC100287934']\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Sample of probe ID to gene symbol mappings:\n",
      "         ID     Gene\n",
      "1   7896738   OR4G2P\n",
      "2   7896738  OR4G11P\n",
      "3   7896738   OR4G1P\n",
      "4   7896740    OR4F4\n",
      "5   7896740   OR4F17\n",
      "6   7896740    OR4F5\n",
      "7   7896740   OR4F17\n",
      "8   7896740    OR4F4\n",
      "9   7896740    OR4F5\n",
      "10  7896740   OR4F17\n",
      "\n",
      "Total number of probe-to-gene mappings: 323773\n",
      "Number of unique gene symbols: 25760\n"
     ]
    }
   ],
   "source": [
    "# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.\n",
    "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
    "gene_annotation = get_gene_annotation(soft_file)\n",
    "\n",
    "# 2. Analyze the gene annotation dataframe to identify which columns contain the gene identifiers and gene symbols\n",
    "print(\"\\nGene annotation preview:\")\n",
    "print(f\"Columns in gene annotation: {gene_annotation.columns.tolist()}\")\n",
    "print(preview_df(gene_annotation, n=5))\n",
    "\n",
    "# Display a sample of the gene_assignment column which likely contains gene information\n",
    "print(\"\\nSample of gene_assignment column (first 3 rows):\")\n",
    "if 'gene_assignment' in gene_annotation.columns:\n",
    "    for i in range(min(3, len(gene_annotation))):\n",
    "        print(f\"Row {i}: {gene_annotation['gene_assignment'].iloc[i][:200]}...\")  # Show first 200 chars\n",
    "    \n",
    "    # Extract a sample of gene symbols from gene_assignment column\n",
    "    print(\"\\nAttempting to extract gene symbols from gene_assignment column...\")\n",
    "    \n",
    "    # Function to extract gene symbols from gene_assignment string\n",
    "    def extract_gene_symbol(gene_assign_str):\n",
    "        if pd.isna(gene_assign_str) or gene_assign_str == '---':\n",
    "            return None\n",
    "        \n",
    "        # Example pattern: \"NM_001004195 // OR4F4 // olfactory receptor...\"\n",
    "        # We want to extract \"OR4F4\"\n",
    "        symbols = []\n",
    "        \n",
    "        # Split by multiple gene entries (if any)\n",
    "        gene_entries = gene_assign_str.split('///')\n",
    "        \n",
    "        for entry in gene_entries:\n",
    "            parts = entry.split('//')\n",
    "            if len(parts) >= 2:\n",
    "                # The gene symbol is usually in the second part\n",
    "                symbol_part = parts[1].strip()\n",
    "                # Extract just the symbol (not the description)\n",
    "                if symbol_part:\n",
    "                    symbol = symbol_part.split()[0]\n",
    "                    symbols.append(symbol)\n",
    "        \n",
    "        return symbols if symbols else None\n",
    "    \n",
    "    # Apply extraction to a sample\n",
    "    sample_size = min(10, len(gene_annotation))\n",
    "    sample_results = [extract_gene_symbol(gene_annotation['gene_assignment'].iloc[i]) \n",
    "                     for i in range(sample_size)]\n",
    "    \n",
    "    print(f\"Extracted gene symbols from first {sample_size} rows:\")\n",
    "    for i, symbols in enumerate(sample_results):\n",
    "        print(f\"Row {i}: {symbols}\")\n",
    "    \n",
    "    # Create mapping dataframe\n",
    "    gene_annotation['Gene'] = gene_annotation['gene_assignment'].apply(extract_gene_symbol)\n",
    "    \n",
    "    # Create the proper mapping format (ID to Gene)\n",
    "    mapping_data = pd.DataFrame({\n",
    "        'ID': np.repeat(gene_annotation['ID'].values, \n",
    "                        gene_annotation['Gene'].apply(lambda x: len(x) if isinstance(x, list) and x else 1)),\n",
    "        'Gene': [symbol for symbols in gene_annotation['Gene'] \n",
    "                       for symbol in (symbols if isinstance(symbols, list) and symbols else [None])]\n",
    "    })\n",
    "    \n",
    "    # Remove rows with None gene symbols\n",
    "    mapping_data = mapping_data.dropna(subset=['Gene'])\n",
    "    \n",
    "    # Print sample of mapping data\n",
    "    print(\"\\nSample of probe ID to gene symbol mappings:\")\n",
    "    print(mapping_data.head(10))\n",
    "    \n",
    "    # Check the size of the mapping data\n",
    "    print(f\"\\nTotal number of probe-to-gene mappings: {len(mapping_data)}\")\n",
    "    \n",
    "    # Check how many unique gene symbols we have\n",
    "    unique_genes = mapping_data['Gene'].nunique()\n",
    "    print(f\"Number of unique gene symbols: {unique_genes}\")\n",
    "else:\n",
    "    print(\"\\nError: Could not find 'gene_assignment' column in the annotation data\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1aeb5b3",
   "metadata": {},
   "source": [
    "### Step 6: Gene Identifier Mapping"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "88f388b3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T05:10:01.155819Z",
     "iopub.status.busy": "2025-03-25T05:10:01.155699Z",
     "iopub.status.idle": "2025-03-25T05:10:04.759628Z",
     "shell.execute_reply": "2025-03-25T05:10:04.759230Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original gene expression data shape: (33297, 59)\n",
      "Gene mapping shape: (155269, 2)\n",
      "Mapped gene expression data shape: (24235, 59)\n",
      "First 10 gene symbols:\n",
      "['A1BG', 'A1CF', 'A2M', 'A2ML1', 'A3GALT2', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS', 'AACS']\n",
      "\n",
      "Preview of gene expression data (first 5 rows, first 5 columns):\n",
      "         GSM1587362  GSM1587363  GSM1587364  GSM1587365  GSM1587366\n",
      "Gene                                                               \n",
      "A1BG        6.93874     7.06714     6.79534     7.04644     6.73879\n",
      "A1CF        4.64016     4.68643     4.61005     4.73412     4.41252\n",
      "A2M         5.73310     5.21556     5.66245     5.75909     5.29572\n",
      "A2ML1       4.99052     5.23956     4.79872     5.19624     5.10726\n",
      "A3GALT2     5.64074     5.31316     5.53539     5.72826     5.32214\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gene expression data saved to ../../output/preprocess/Epilepsy/gene_data/GSE65106.csv\n",
      "Gene data available: True\n"
     ]
    }
   ],
   "source": [
    "# 1. Identify which columns in gene_annotation contain the gene identifiers and gene symbols\n",
    "# From the previous output, we can see:\n",
    "# - The 'ID' column contains probe identifiers matching the gene expression data index\n",
    "# - The 'gene_assignment' column contains gene symbol information\n",
    "\n",
    "# 2. Create the gene mapping using our helper function\n",
    "# First extract probe IDs and gene symbols from gene_annotation\n",
    "prob_col = 'ID'\n",
    "gene_col = 'gene_assignment'\n",
    "\n",
    "# Create a mapping between probe IDs and gene symbols\n",
    "mapping_df = gene_annotation[[prob_col, gene_col]].copy()\n",
    "mapping_df = mapping_df.rename(columns={prob_col: 'ID'})\n",
    "\n",
    "# Extract gene symbols from the gene_assignment column string\n",
    "def extract_gene_symbols(gene_assign_str):\n",
    "    \"\"\"Extract gene symbols from gene_assignment string.\"\"\"\n",
    "    if pd.isna(gene_assign_str) or gene_assign_str == '---':\n",
    "        return []\n",
    "    \n",
    "    # Use the extract_human_gene_symbols function from the library\n",
    "    return extract_human_gene_symbols(gene_assign_str)\n",
    "\n",
    "# Apply extraction to get gene symbols\n",
    "mapping_df['Gene'] = mapping_df[gene_col].apply(extract_gene_symbols)\n",
    "mapping_df = mapping_df[['ID', 'Gene']]  # Keep only ID and Gene columns\n",
    "\n",
    "# Expand the mapping dataframe (one row per gene symbol)\n",
    "mapping_df = mapping_df.explode('Gene')\n",
    "mapping_df = mapping_df.dropna(subset=['Gene'])  # Remove rows with no gene symbol\n",
    "\n",
    "# 3. Load gene expression data and apply the mapping\n",
    "# First, load the genetic data\n",
    "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
    "gene_expr_data = get_genetic_data(matrix_file)\n",
    "\n",
    "# Apply the gene mapping to convert probe-level measurements to gene expression\n",
    "gene_data = apply_gene_mapping(gene_expr_data, mapping_df)\n",
    "\n",
    "# Normalize gene symbols to handle synonyms\n",
    "gene_data = normalize_gene_symbols_in_index(gene_data)\n",
    "\n",
    "# Preview the gene expression data\n",
    "print(f\"Original gene expression data shape: {gene_expr_data.shape}\")\n",
    "print(f\"Gene mapping shape: {mapping_df.shape}\")\n",
    "print(f\"Mapped gene expression data shape: {gene_data.shape}\")\n",
    "print(\"First 10 gene symbols:\")\n",
    "print(gene_data.index[:10].tolist())\n",
    "print(\"\\nPreview of gene expression data (first 5 rows, first 5 columns):\")\n",
    "if gene_data.shape[1] >= 5:\n",
    "    print(gene_data.iloc[:5, :5])\n",
    "else:\n",
    "    print(gene_data.iloc[:5, :])\n",
    "\n",
    "# Save the gene data to CSV\n",
    "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n",
    "gene_data.to_csv(out_gene_data_file)\n",
    "print(f\"Gene expression data saved to {out_gene_data_file}\")\n",
    "\n",
    "# Update the gene availability flag based on the results\n",
    "is_gene_available = gene_data.shape[0] > 0 and gene_data.shape[1] > 0\n",
    "print(f\"Gene data available: {is_gene_available}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a11e466",
   "metadata": {},
   "source": [
    "### Step 7: Data Normalization and Linking"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1287f7f1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T05:10:04.760986Z",
     "iopub.status.busy": "2025-03-25T05:10:04.760859Z",
     "iopub.status.idle": "2025-03-25T05:10:20.524772Z",
     "shell.execute_reply": "2025-03-25T05:10:20.524352Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gene data shape before normalization: (24235, 59)\n",
      "Gene data shape after normalization: (24235, 59)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Normalized gene data saved to ../../output/preprocess/Epilepsy/gene_data/GSE65106.csv\n",
      "Extracted clinical data shape: (3, 59)\n",
      "Preview of clinical data (first 5 samples):\n",
      "          GSM1587362  GSM1587363  GSM1587364  GSM1587365  GSM1587366\n",
      "Epilepsy         1.0         1.0         1.0         1.0         1.0\n",
      "Age              8.0         8.0         7.0         7.0         9.0\n",
      "Gender           1.0         1.0         1.0         1.0         1.0\n",
      "Clinical data saved to ../../output/preprocess/Epilepsy/clinical_data/GSE65106.csv\n",
      "Gene data columns (first 5): ['GSM1587362', 'GSM1587363', 'GSM1587364', 'GSM1587365', 'GSM1587366']\n",
      "Clinical data columns (first 5): ['GSM1587362', 'GSM1587363', 'GSM1587364', 'GSM1587365', 'GSM1587366']\n",
      "Found 59 common samples between gene and clinical data\n",
      "Initial linked data shape: (59, 24238)\n",
      "Preview of linked data (first 5 rows, first 5 columns):\n",
      "            Epilepsy  Age  Gender     A1BG     A1CF\n",
      "GSM1587362       1.0  8.0     1.0  6.93874  4.64016\n",
      "GSM1587363       1.0  8.0     1.0  7.06714  4.68643\n",
      "GSM1587364       1.0  7.0     1.0  6.79534  4.61005\n",
      "GSM1587365       1.0  7.0     1.0  7.04644  4.73412\n",
      "GSM1587366       1.0  9.0     1.0  6.73879  4.41252\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Linked data shape after handling missing values: (59, 24238)\n",
      "For the feature 'Epilepsy', the least common label is '1.0' with 21 occurrences. This represents 35.59% of the dataset.\n",
      "The distribution of the feature 'Epilepsy' in this dataset is fine.\n",
      "\n",
      "Quartiles for 'Age':\n",
      "  25%: 7.0\n",
      "  50% (Median): 9.0\n",
      "  75%: 10.0\n",
      "Min: 7.0\n",
      "Max: 16.0\n",
      "The distribution of the feature 'Age' in this dataset is fine.\n",
      "\n",
      "For the feature 'Gender', the least common label is '0.0' with 4 occurrences. This represents 6.78% of the dataset.\n",
      "The distribution of the feature 'Gender' in this dataset is severely biased.\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Linked data saved to ../../output/preprocess/Epilepsy/GSE65106.csv\n"
     ]
    }
   ],
   "source": [
    "# 1. Normalize gene symbols in the gene expression data\n",
    "try:\n",
    "    # Make sure the directory exists\n",
    "    os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n",
    "    \n",
    "    # Use the gene_data variable from the previous step (don't try to load it from file)\n",
    "    print(f\"Gene data shape before normalization: {gene_data.shape}\")\n",
    "    \n",
    "    # Apply normalization to gene symbols\n",
    "    normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n",
    "    print(f\"Gene data shape after normalization: {normalized_gene_data.shape}\")\n",
    "    \n",
    "    # Save the normalized gene data\n",
    "    normalized_gene_data.to_csv(out_gene_data_file)\n",
    "    print(f\"Normalized gene data saved to {out_gene_data_file}\")\n",
    "    \n",
    "    # Use the normalized data for further processing\n",
    "    gene_data = normalized_gene_data\n",
    "    is_gene_available = True\n",
    "except Exception as e:\n",
    "    print(f\"Error normalizing gene data: {e}\")\n",
    "    is_gene_available = False\n",
    "\n",
    "# 2. Load clinical data - respecting the analysis from Step 2\n",
    "# From Step 2, we determined:\n",
    "# trait_row = None  # No Epilepsy data available\n",
    "# age_row = None\n",
    "# gender_row = None\n",
    "is_trait_available = trait_row is not None\n",
    "\n",
    "# Skip clinical feature extraction when trait_row is None\n",
    "if is_trait_available:\n",
    "    try:\n",
    "        # Load the clinical data from file\n",
    "        soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
    "        background_info, clinical_data = get_background_and_clinical_data(matrix_file)\n",
    "        \n",
    "        # Extract clinical features\n",
    "        clinical_features = geo_select_clinical_features(\n",
    "            clinical_df=clinical_data,\n",
    "            trait=trait,\n",
    "            trait_row=trait_row,\n",
    "            convert_trait=convert_trait,\n",
    "            gender_row=gender_row,\n",
    "            convert_gender=convert_gender,\n",
    "            age_row=age_row,\n",
    "            convert_age=convert_age\n",
    "        )\n",
    "        \n",
    "        print(f\"Extracted clinical data shape: {clinical_features.shape}\")\n",
    "        print(\"Preview of clinical data (first 5 samples):\")\n",
    "        print(clinical_features.iloc[:, :5])\n",
    "        \n",
    "        # Save the properly extracted clinical data\n",
    "        os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n",
    "        clinical_features.to_csv(out_clinical_data_file)\n",
    "        print(f\"Clinical data saved to {out_clinical_data_file}\")\n",
    "    except Exception as e:\n",
    "        print(f\"Error extracting clinical data: {e}\")\n",
    "        is_trait_available = False\n",
    "else:\n",
    "    print(\"No trait data (Epilepsy) available in this dataset based on previous analysis.\")\n",
    "\n",
    "# 3. Link clinical and genetic data if both are available\n",
    "if is_trait_available and is_gene_available:\n",
    "    try:\n",
    "        # Debug the column names to ensure they match\n",
    "        print(f\"Gene data columns (first 5): {gene_data.columns[:5].tolist()}\")\n",
    "        print(f\"Clinical data columns (first 5): {clinical_features.columns[:5].tolist()}\")\n",
    "        \n",
    "        # Check for common sample IDs\n",
    "        common_samples = set(gene_data.columns).intersection(clinical_features.columns)\n",
    "        print(f\"Found {len(common_samples)} common samples between gene and clinical data\")\n",
    "        \n",
    "        if len(common_samples) > 0:\n",
    "            # Link the clinical and genetic data\n",
    "            linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)\n",
    "            print(f\"Initial linked data shape: {linked_data.shape}\")\n",
    "            \n",
    "            # Debug the trait values before handling missing values\n",
    "            print(\"Preview of linked data (first 5 rows, first 5 columns):\")\n",
    "            print(linked_data.iloc[:5, :5])\n",
    "            \n",
    "            # Handle missing values\n",
    "            linked_data = handle_missing_values(linked_data, trait)\n",
    "            print(f\"Linked data shape after handling missing values: {linked_data.shape}\")\n",
    "            \n",
    "            if linked_data.shape[0] > 0:\n",
    "                # Check for bias in trait and demographic features\n",
    "                is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)\n",
    "                \n",
    "                # Validate the data quality and save cohort info\n",
    "                note = \"Dataset contains gene expression data from GBM cell cultures, but no epilepsy phenotype 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=is_gene_available,\n",
    "                    is_trait_available=is_trait_available,\n",
    "                    is_biased=is_biased,\n",
    "                    df=linked_data,\n",
    "                    note=note\n",
    "                )\n",
    "                \n",
    "                # Save the linked data if it's usable\n",
    "                if is_usable:\n",
    "                    os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n",
    "                    linked_data.to_csv(out_data_file)\n",
    "                    print(f\"Linked data saved to {out_data_file}\")\n",
    "                else:\n",
    "                    print(\"Data not usable for the trait study - not saving final linked data.\")\n",
    "            else:\n",
    "                print(\"After handling missing values, no samples remain.\")\n",
    "                validate_and_save_cohort_info(\n",
    "                    is_final=True,\n",
    "                    cohort=cohort,\n",
    "                    info_path=json_path,\n",
    "                    is_gene_available=is_gene_available,\n",
    "                    is_trait_available=is_trait_available,\n",
    "                    is_biased=True,\n",
    "                    df=pd.DataFrame(),\n",
    "                    note=\"No valid samples after handling missing values.\"\n",
    "                )\n",
    "        else:\n",
    "            print(\"No common samples found between gene expression and clinical data.\")\n",
    "            validate_and_save_cohort_info(\n",
    "                is_final=True,\n",
    "                cohort=cohort,\n",
    "                info_path=json_path,\n",
    "                is_gene_available=is_gene_available,\n",
    "                is_trait_available=is_trait_available,\n",
    "                is_biased=True,\n",
    "                df=pd.DataFrame(),\n",
    "                note=\"No common samples between gene expression and clinical data.\"\n",
    "            )\n",
    "    except Exception as e:\n",
    "        print(f\"Error linking or processing data: {e}\")\n",
    "        validate_and_save_cohort_info(\n",
    "            is_final=True,\n",
    "            cohort=cohort,\n",
    "            info_path=json_path,\n",
    "            is_gene_available=is_gene_available,\n",
    "            is_trait_available=is_trait_available,\n",
    "            is_biased=True,  # Assume biased if there's an error\n",
    "            df=pd.DataFrame(),  # Empty dataframe for metadata\n",
    "            note=f\"Error in data processing: {str(e)}\"\n",
    "        )\n",
    "else:\n",
    "    # Create an empty DataFrame for metadata purposes\n",
    "    empty_df = pd.DataFrame()\n",
    "    \n",
    "    # We can't proceed with linking if either trait or gene data is missing\n",
    "    print(\"Cannot proceed with data linking due to missing trait or gene data.\")\n",
    "    validate_and_save_cohort_info(\n",
    "        is_final=True,\n",
    "        cohort=cohort,\n",
    "        info_path=json_path,\n",
    "        is_gene_available=is_gene_available,\n",
    "        is_trait_available=is_trait_available,\n",
    "        is_biased=True,  # Data is unusable if we're missing components\n",
    "        df=empty_df,  # Empty dataframe for metadata\n",
    "        note=\"Missing essential data components for linking: dataset contains gene expression data from GBM cell cultures, but no epilepsy phenotype information.\"\n",
    "    )"
   ]
  }
 ],
 "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
}