Liu-Hy commited on
Commit
56598a1
·
verified ·
1 Parent(s): e75345b

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +12 -0
  2. output/preprocess/Atrial_Fibrillation/code/TCGA.py +56 -0
  3. output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE111175.csv +3 -3
  4. output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE113842.csv +3 -3
  5. output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE123302.csv +3 -3
  6. output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE87847.csv +1 -1
  7. output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE89594.csv +4 -0
  8. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE111175.py +192 -0
  9. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE113842.py +362 -0
  10. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE123302.py +382 -0
  11. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE148450.py +158 -0
  12. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE285666.py +178 -0
  13. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE42133.py +201 -0
  14. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE57802.py +224 -0
  15. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE65106.py +200 -0
  16. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE87847.py +172 -0
  17. output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE89594.py +186 -0
  18. output/preprocess/Autism_spectrum_disorder_(ASD)/code/TCGA.py +63 -0
  19. output/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json +1 -102
  20. output/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE113842.csv +1 -0
  21. output/preprocess/Autoinflammatory_Disorders/clinical_data/GSE43553.csv +1 -1
  22. output/preprocess/Autoinflammatory_Disorders/clinical_data/GSE80060.csv +2 -2
  23. output/preprocess/Autoinflammatory_Disorders/code/GSE43553.py +196 -0
  24. output/preprocess/Autoinflammatory_Disorders/code/GSE80060.py +211 -0
  25. output/preprocess/Autoinflammatory_Disorders/code/TCGA.py +123 -0
  26. output/preprocess/Autoinflammatory_Disorders/cohort_info.json +1 -32
  27. output/preprocess/Bile_Duct_Cancer/clinical_data/GSE107754.csv +1 -1
  28. output/preprocess/Bile_Duct_Cancer/clinical_data/GSE131027.csv +2 -2
  29. output/preprocess/Bile_Duct_Cancer/code/GSE107754.py +190 -0
  30. output/preprocess/Bile_Duct_Cancer/code/GSE131027.py +196 -0
  31. output/preprocess/Bile_Duct_Cancer/code/TCGA.py +306 -0
  32. output/preprocess/Bile_Duct_Cancer/cohort_info.json +1 -32
  33. output/preprocess/Bipolar_disorder/GSE120340.csv +0 -0
  34. output/preprocess/Bipolar_disorder/GSE46416.csv +0 -0
  35. output/preprocess/Bipolar_disorder/clinical_data/GSE120340.csv +2 -2
  36. output/preprocess/Bipolar_disorder/clinical_data/GSE120342.csv +2 -2
  37. output/preprocess/Bipolar_disorder/clinical_data/GSE46416.csv +2 -0
  38. output/preprocess/Bipolar_disorder/clinical_data/GSE53987.csv +4 -4
  39. output/preprocess/Bipolar_disorder/clinical_data/GSE62191.csv +3 -4
  40. output/preprocess/Bipolar_disorder/clinical_data/GSE67311.csv +2 -143
  41. output/preprocess/Bipolar_disorder/clinical_data/GSE92538.csv +1 -1
  42. output/preprocess/Bipolar_disorder/code/GSE120340.py +228 -0
  43. output/preprocess/Bipolar_disorder/code/GSE120342.py +206 -0
  44. output/preprocess/Bipolar_disorder/code/GSE45484.py +192 -0
  45. output/preprocess/Bipolar_disorder/code/GSE46416.py +211 -0
  46. output/preprocess/Bipolar_disorder/code/GSE46449.py +192 -0
  47. output/preprocess/Bipolar_disorder/code/GSE53987.py +197 -0
  48. output/preprocess/Bipolar_disorder/code/GSE62191.py +213 -0
  49. output/preprocess/Bipolar_disorder/code/GSE67311.py +207 -0
  50. output/preprocess/Bipolar_disorder/code/GSE92538.py +193 -0
.gitattributes CHANGED
@@ -2178,3 +2178,15 @@ p3/preprocess/Prostate_Cancer/gene_data/GSE201805.csv filter=lfs diff=lfs merge=
2178
  p3/preprocess/lower_grade_glioma_and_glioblastoma/TCGA.csv filter=lfs diff=lfs merge=lfs -text
2179
  p3/preprocess/Prostate_Cancer/GSE209954.csv filter=lfs diff=lfs merge=lfs -text
2180
  p3/preprocess/Obesity/TCGA.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
2178
  p3/preprocess/lower_grade_glioma_and_glioblastoma/TCGA.csv filter=lfs diff=lfs merge=lfs -text
2179
  p3/preprocess/Prostate_Cancer/GSE209954.csv filter=lfs diff=lfs merge=lfs -text
2180
  p3/preprocess/Obesity/TCGA.csv filter=lfs diff=lfs merge=lfs -text
2181
+ output/preprocess/Coronary_artery_disease/gene_data/GSE120774.csv filter=lfs diff=lfs merge=lfs -text
2182
+ output/preprocess/Glucocorticoid_Sensitivity/gene_data/GSE48801.csv filter=lfs diff=lfs merge=lfs -text
2183
+ output/preprocess/Coronary_artery_disease/GSE109048.csv filter=lfs diff=lfs merge=lfs -text
2184
+ output/preprocess/Heart_rate/GSE34788.csv filter=lfs diff=lfs merge=lfs -text
2185
+ output/preprocess/Heart_rate/gene_data/GSE34788.csv filter=lfs diff=lfs merge=lfs -text
2186
+ output/preprocess/Height/GSE106800.csv filter=lfs diff=lfs merge=lfs -text
2187
+ output/preprocess/Height/gene_data/GSE106800.csv filter=lfs diff=lfs merge=lfs -text
2188
+ output/preprocess/Height/gene_data/GSE101710.csv filter=lfs diff=lfs merge=lfs -text
2189
+ output/preprocess/Hemochromatosis/gene_data/GSE50579.csv filter=lfs diff=lfs merge=lfs -text
2190
+ output/preprocess/Huntingtons_Disease/GSE26927.csv filter=lfs diff=lfs merge=lfs -text
2191
+ output/preprocess/Hypertension/GSE117261.csv filter=lfs diff=lfs merge=lfs -text
2192
+ output/preprocess/Crohns_Disease/GSE123086.csv filter=lfs diff=lfs merge=lfs -text
output/preprocess/Atrial_Fibrillation/code/TCGA.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Atrial_Fibrillation"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/z1/preprocess/Atrial_Fibrillation/TCGA.csv"
12
+ out_gene_data_file = "./output/z1/preprocess/Atrial_Fibrillation/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/z1/preprocess/Atrial_Fibrillation/clinical_data/TCGA.csv"
14
+ json_path = "./output/z1/preprocess/Atrial_Fibrillation/cohort_info.json"
15
+
16
+
17
+ # Step 1: Initial Data Loading
18
+ import os
19
+ import pandas as pd
20
+
21
+ # Discover available TCGA cohort directories
22
+ subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
23
+
24
+ # Try to find a cohort relevant to atrial fibrillation (unlikely in TCGA cancer cohorts)
25
+ keywords = ['atrial_fibrillation', 'atrial fibrillation', 'a-fib', 'afib', 'arrhythmia', 'cardiac', 'heart']
26
+ candidates = []
27
+ for d in subdirs:
28
+ name_l = d.lower()
29
+ score = sum(1 for k in keywords if k in name_l)
30
+ if score > 0:
31
+ candidates.append((score, d))
32
+
33
+ selected_dir = None
34
+ if candidates:
35
+ # Choose the highest scoring (most specific) match
36
+ candidates.sort(key=lambda x: (-x[0], len(x[1])))
37
+ selected_dir = candidates[0][1]
38
+
39
+ if selected_dir is None:
40
+ # No suitable TCGA cohort for Atrial Fibrillation; record and skip
41
+ validate_and_save_cohort_info(
42
+ is_final=False,
43
+ cohort="TCGA",
44
+ info_path=json_path,
45
+ is_gene_available=False,
46
+ is_trait_available=False
47
+ )
48
+ print("No suitable TCGA cohort found for the trait. Skipping TCGA processing for this trait.")
49
+ else:
50
+ cohort_dir = os.path.join(tcga_root_dir, selected_dir)
51
+ clinical_path, genetic_path = tcga_get_relevant_filepaths(cohort_dir)
52
+
53
+ clinical_df = pd.read_csv(clinical_path, sep='\t', index_col=0, low_memory=False)
54
+ genetic_df = pd.read_csv(genetic_path, sep='\t', index_col=0, low_memory=False)
55
+
56
+ print(clinical_df.columns.tolist())
output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE111175.csv CHANGED
@@ -1,3 +1,3 @@
1
- GSM3024679,GSM3024680,GSM3024681,GSM3024682,GSM3024683,GSM3024684,GSM3024685,GSM3024686,GSM3024687,GSM3024688,GSM3024689,GSM3024690,GSM3024691,GSM3024692,GSM3024693,GSM3024694,GSM3024695,GSM3024696,GSM3024697,GSM3024698,GSM3024699,GSM3024700,GSM3024701,GSM3024702,GSM3024703,GSM3024704,GSM3024705,GSM3024706,GSM3024707,GSM3024708,GSM3024709,GSM3024710,GSM3024711,GSM3024712,GSM3024713,GSM3024714,GSM3024715,GSM3024716,GSM3024717,GSM3024718,GSM3024719,GSM3024720,GSM3024721,GSM3024722,GSM3024723,GSM3024724,GSM3024725,GSM3024726,GSM3024727,GSM3024728,GSM3024729,GSM3024730,GSM3024731,GSM3024732,GSM3024733,GSM3024734,GSM3024735,GSM3024736,GSM3024737,GSM3024738,GSM3024739,GSM3024740,GSM3024741,GSM3024742,GSM3024743,GSM3024744,GSM3024745,GSM3024746,GSM3024747,GSM3024748,GSM3024749,GSM3024750,GSM3024751,GSM3024752,GSM3024753,GSM3024754,GSM3024755,GSM3024756,GSM3024757,GSM3024758,GSM3024759,GSM3024760,GSM3024761,GSM3024762,GSM3024763,GSM3024764,GSM3024765,GSM3024766,GSM3024767,GSM3024768,GSM3024769,GSM3024770,GSM3024771,GSM3024772,GSM3024773,GSM3024774,GSM3024775,GSM3024776,GSM3024777,GSM3024778,GSM3024779,GSM3024780,GSM3024781,GSM3024782,GSM3024783,GSM3024784,GSM3024785,GSM3024786,GSM3024787,GSM3024788,GSM3024789,GSM3024790,GSM3024791,GSM3024792,GSM3024793,GSM3024794,GSM3024795,GSM3024796,GSM3024797,GSM3024798,GSM3024799,GSM3024800,GSM3024801,GSM3024802,GSM3024803,GSM3024804,GSM3024805,GSM3024806,GSM3024807,GSM3024808,GSM3024809,GSM3024810,GSM3024811,GSM3024812,GSM3024813,GSM3024814,GSM3024815,GSM3024816,GSM3024817,GSM3024818,GSM3024819
2
- 0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
- 15.277,18.957,25.692,13.142,24.575,34.694,19.22,13.536,15.08,15.146,23.294,23.655,32.526,17.643,17.643,13.569,13.569,19.055,12.977,13.109,15.113,16.361,29.273,29.273,24.575,44.879,17.248,22.078,14.423,28.452,12.517,23.129,28.287,13.273,40.608,40.608,21.257,33.38,12.912,19.351,31.639,33.906,19.68,15.671,41.068,41.068,36.172,29.766,13.339,17.084,17.084,24.674,38.538,15.737,15.737,39.951,13.733,30.916,28.715,25.199,11.236,28.912,14.324,18.661,13.306,29.043,14.456,33.873,31.606,12.32,11.532,41.035,31.934,19.187,18.07,28.846,16.526,18.497,33.511,14.62,18.267,40.312,15.507,15.376,18.136,16.394,19.713,12.616,40.476,40.476,12.156,31.08,13.897,14.259,15.244,15.244,13.996,30.949,12.715,12.485,37.027,12.649,13.01,16.0,13.864,14.554,20.008,18.957,16.821,27.598,27.598,12.386,14.292,13.733,13.733,13.634,17.676,15.901,23.786,15.803,16.657,26.152,22.111,23.228,12.156,23.622,13.405,18.727,18.694,25.298,25.298,16.821,32.394,12.025,13.832,13.832,19.778,30.193,17.051,13.01,16.427
 
1
+ ,GSM3024679,GSM3024680,GSM3024681,GSM3024682,GSM3024683,GSM3024684,GSM3024685,GSM3024686,GSM3024687,GSM3024688,GSM3024689,GSM3024690,GSM3024691,GSM3024692,GSM3024693,GSM3024694,GSM3024695,GSM3024696,GSM3024697,GSM3024698,GSM3024699,GSM3024700,GSM3024701,GSM3024702,GSM3024703,GSM3024704,GSM3024705,GSM3024706,GSM3024707,GSM3024708,GSM3024709,GSM3024710,GSM3024711,GSM3024712,GSM3024713,GSM3024714,GSM3024715,GSM3024716,GSM3024717,GSM3024718,GSM3024719,GSM3024720,GSM3024721,GSM3024722,GSM3024723,GSM3024724,GSM3024725,GSM3024726,GSM3024727,GSM3024728,GSM3024729,GSM3024730,GSM3024731,GSM3024732,GSM3024733,GSM3024734,GSM3024735,GSM3024736,GSM3024737,GSM3024738,GSM3024739,GSM3024740,GSM3024741,GSM3024742,GSM3024743,GSM3024744,GSM3024745,GSM3024746,GSM3024747,GSM3024748,GSM3024749,GSM3024750,GSM3024751,GSM3024752,GSM3024753,GSM3024754,GSM3024755,GSM3024756,GSM3024757,GSM3024758,GSM3024759,GSM3024760,GSM3024761,GSM3024762,GSM3024763,GSM3024764,GSM3024765,GSM3024766,GSM3024767,GSM3024768,GSM3024769,GSM3024770,GSM3024771,GSM3024772,GSM3024773,GSM3024774,GSM3024775,GSM3024776,GSM3024777,GSM3024778,GSM3024779,GSM3024780,GSM3024781,GSM3024782,GSM3024783,GSM3024784,GSM3024785,GSM3024786,GSM3024787,GSM3024788,GSM3024789,GSM3024790,GSM3024791,GSM3024792,GSM3024793,GSM3024794,GSM3024795,GSM3024796,GSM3024797,GSM3024798,GSM3024799,GSM3024800,GSM3024801,GSM3024802,GSM3024803,GSM3024804,GSM3024805,GSM3024806,GSM3024807,GSM3024808,GSM3024809,GSM3024810,GSM3024811,GSM3024812,GSM3024813,GSM3024814,GSM3024815,GSM3024816,GSM3024817,GSM3024818,GSM3024819
2
+ Autism_spectrum_disorder_(ASD),0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
+ Age,15.277,18.957,25.692,13.142,24.575,34.694,19.22,13.536,15.08,15.146,23.294,23.655,32.526,17.643,17.643,13.569,13.569,19.055,12.977,13.109,15.113,16.361,29.273,29.273,24.575,44.879,17.248,22.078,14.423,28.452,12.517,23.129,28.287,13.273,40.608,40.608,21.257,33.38,12.912,19.351,31.639,33.906,19.68,15.671,41.068,41.068,36.172,29.766,13.339,17.084,17.084,24.674,38.538,15.737,15.737,39.951,13.733,30.916,28.715,25.199,11.236,28.912,14.324,18.661,13.306,29.043,14.456,33.873,31.606,12.32,11.532,41.035,31.934,19.187,18.07,28.846,16.526,18.497,33.511,14.62,18.267,40.312,15.507,15.376,18.136,16.394,19.713,12.616,40.476,40.476,12.156,31.08,13.897,14.259,15.244,15.244,13.996,30.949,12.715,12.485,37.027,12.649,13.01,16.0,13.864,14.554,20.008,18.957,16.821,27.598,27.598,12.386,14.292,13.733,13.733,13.634,17.676,15.901,23.786,15.803,16.657,26.152,22.111,23.228,12.156,23.622,13.405,18.727,18.694,25.298,25.298,16.821,32.394,12.025,13.832,13.832,19.778,30.193,17.051,13.01,16.427
output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE113842.csv CHANGED
@@ -1,3 +1,3 @@
1
- 0
2
- 0.0
3
- ""
 
1
+ ,GSM3120900,GSM3120901,GSM3120902,GSM3120903,GSM3120904,GSM3120905,GSM3120906,GSM3120907,GSM3120908,GSM3120909,GSM3120910,GSM3120911,GSM3120912,GSM3120913,GSM3120914,GSM3120915,GSM3120916,GSM3120917,GSM3120918,GSM3120919,GSM3120920,GSM3120921,GSM3120922,GSM3120923,GSM3120924,GSM3120925,GSM3120926
2
+ Autism_spectrum_disorder_(ASD),0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
+ Age,7.0,7.0,7.0,9.0,9.0,9.0,5.0,5.0,5.0,7.0,7.0,7.0,13.0,13.0,13.0,20.5,20.5,20.5,11.0,11.0,11.0,12.0,12.0,12.0,22.0,22.0,22.0
output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE123302.csv CHANGED
@@ -1,3 +1,3 @@
1
- GSM3499537,GSM3499538,GSM3499539,GSM3499540,GSM3499541,GSM3499542,GSM3499543,GSM3499544,GSM3499545,GSM3499546,GSM3499547,GSM3499548,GSM3499549,GSM3499550,GSM3499551,GSM3499552,GSM3499553,GSM3499554,GSM3499555,GSM3499556,GSM3499557,GSM3499558,GSM3499559,GSM3499560,GSM3499561,GSM3499562,GSM3499563,GSM3499564,GSM3499565,GSM3499566,GSM3499567,GSM3499568,GSM3499569,GSM3499570,GSM3499571,GSM3499572,GSM3499573,GSM3499574,GSM3499575,GSM3499576,GSM3499577,GSM3499578,GSM3499579,GSM3499580,GSM3499581,GSM3499582,GSM3499583,GSM3499584,GSM3499585,GSM3499586,GSM3499587,GSM3499588,GSM3499589,GSM3499590,GSM3499591,GSM3499592,GSM3499593,GSM3499594,GSM3499595,GSM3499596,GSM3499597,GSM3499598,GSM3499599,GSM3499600,GSM3499601,GSM3499602,GSM3499603,GSM3499604,GSM3499605,GSM3499606,GSM3499607,GSM3499608,GSM3499609,GSM3499610,GSM3499611,GSM3499612,GSM3499613,GSM3499614,GSM3499615,GSM3499616,GSM3499617,GSM3499618,GSM3499619,GSM3499620,GSM3499621,GSM3499622,GSM3499623,GSM3499624,GSM3499625,GSM3499626,GSM3499627,GSM3499628,GSM3499629,GSM3499630,GSM3499631,GSM3499632,GSM3499633,GSM3499634,GSM3499635,GSM3499636,GSM3499637,GSM3499638,GSM3499639,GSM3499640,GSM3499641,GSM3499642,GSM3499643,GSM3499644,GSM3499645,GSM3499646,GSM3499647,GSM3499648,GSM3499649,GSM3499650,GSM3499651,GSM3499652,GSM3499653,GSM3499654,GSM3499655,GSM3499656,GSM3499657,GSM3499658,GSM3499659,GSM3499660,GSM3499661,GSM3499662,GSM3499663,GSM3499664,GSM3499665,GSM3499666,GSM3499667,GSM3499668,GSM3499669,GSM3499670,GSM3499671,GSM3499672,GSM3499673,GSM3499674,GSM3499675,GSM3499676,GSM3499677,GSM3499678,GSM3499679,GSM3499680,GSM3499681,GSM3499682,GSM3499683,GSM3499684,GSM3499685,GSM3499686,GSM3499687,GSM3499688,GSM3499689,GSM3499690,GSM3499691,GSM3499692,GSM3499693,GSM3499694,GSM3499695,GSM3499696,GSM3499697,GSM3499698,GSM3499699,GSM3499700,GSM3499701,GSM3499702,GSM3499703,GSM3499704,GSM3499705,GSM3499706,GSM3499707,GSM3499708,GSM3499709,GSM3499710,GSM3499711,GSM3499712,GSM3499713,GSM3499714,GSM3499715,GSM3499716,GSM3499717,GSM3499718,GSM3499719,GSM3499720,GSM3499721,GSM3499722,GSM3499723,GSM3499724,GSM3499725,GSM3499726,GSM3499727,GSM3499728,GSM3499729,GSM3499730,GSM3499731,GSM3499732,GSM3499733,GSM3499734,GSM3499735,GSM3499736,GSM3499737,GSM3499738,GSM3499739,GSM3499740,GSM3499741,GSM3499742,GSM3499743,GSM3499744,GSM3499745,GSM3499746,GSM3499747,GSM3499748,GSM3499749,GSM3499750,GSM3499751,GSM3499752,GSM3499753,GSM3499754,GSM3499755,GSM3499756,GSM3499757,GSM3499758,GSM3499759,GSM3499760
2
- 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
- 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
 
1
+ ,GSM3499537,GSM3499538,GSM3499539,GSM3499540,GSM3499541,GSM3499542,GSM3499543,GSM3499544,GSM3499545,GSM3499546,GSM3499547,GSM3499548,GSM3499549,GSM3499550,GSM3499551,GSM3499552,GSM3499553,GSM3499554,GSM3499555,GSM3499556,GSM3499557,GSM3499558,GSM3499559,GSM3499560,GSM3499561,GSM3499562,GSM3499563,GSM3499564,GSM3499565,GSM3499566,GSM3499567,GSM3499568,GSM3499569,GSM3499570,GSM3499571,GSM3499572,GSM3499573,GSM3499574,GSM3499575,GSM3499576,GSM3499577,GSM3499578,GSM3499579,GSM3499580,GSM3499581,GSM3499582,GSM3499583,GSM3499584,GSM3499585,GSM3499586,GSM3499587,GSM3499588,GSM3499589,GSM3499590,GSM3499591,GSM3499592,GSM3499593,GSM3499594,GSM3499595,GSM3499596,GSM3499597,GSM3499598,GSM3499599,GSM3499600,GSM3499601,GSM3499602,GSM3499603,GSM3499604,GSM3499605,GSM3499606,GSM3499607,GSM3499608,GSM3499609,GSM3499610,GSM3499611,GSM3499612,GSM3499613,GSM3499614,GSM3499615,GSM3499616,GSM3499617,GSM3499618,GSM3499619,GSM3499620,GSM3499621,GSM3499622,GSM3499623,GSM3499624,GSM3499625,GSM3499626,GSM3499627,GSM3499628,GSM3499629,GSM3499630,GSM3499631,GSM3499632,GSM3499633,GSM3499634,GSM3499635,GSM3499636,GSM3499637,GSM3499638,GSM3499639,GSM3499640,GSM3499641,GSM3499642,GSM3499643,GSM3499644,GSM3499645,GSM3499646,GSM3499647,GSM3499648,GSM3499649,GSM3499650,GSM3499651,GSM3499652,GSM3499653,GSM3499654,GSM3499655,GSM3499656,GSM3499657,GSM3499658,GSM3499659,GSM3499660,GSM3499661,GSM3499662,GSM3499663,GSM3499664,GSM3499665,GSM3499666,GSM3499667,GSM3499668,GSM3499669,GSM3499670,GSM3499671,GSM3499672,GSM3499673,GSM3499674,GSM3499675,GSM3499676,GSM3499677,GSM3499678,GSM3499679,GSM3499680,GSM3499681,GSM3499682,GSM3499683,GSM3499684,GSM3499685,GSM3499686,GSM3499687,GSM3499688,GSM3499689,GSM3499690,GSM3499691,GSM3499692,GSM3499693,GSM3499694,GSM3499695,GSM3499696,GSM3499697,GSM3499698,GSM3499699,GSM3499700,GSM3499701,GSM3499702,GSM3499703,GSM3499704,GSM3499705,GSM3499706,GSM3499707,GSM3499708,GSM3499709,GSM3499710,GSM3499711,GSM3499712,GSM3499713,GSM3499714,GSM3499715,GSM3499716,GSM3499717,GSM3499718,GSM3499719,GSM3499720,GSM3499721,GSM3499722,GSM3499723,GSM3499724,GSM3499725,GSM3499726,GSM3499727,GSM3499728,GSM3499729,GSM3499730,GSM3499731,GSM3499732,GSM3499733,GSM3499734,GSM3499735,GSM3499736,GSM3499737,GSM3499738,GSM3499739,GSM3499740,GSM3499741,GSM3499742,GSM3499743,GSM3499744,GSM3499745,GSM3499746,GSM3499747,GSM3499748,GSM3499749,GSM3499750,GSM3499751,GSM3499752,GSM3499753,GSM3499754,GSM3499755,GSM3499756,GSM3499757,GSM3499758,GSM3499759,GSM3499760
2
+ Autism_spectrum_disorder_(ASD),1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
+ Gender,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE87847.csv CHANGED
@@ -1,3 +1,3 @@
1
  ,GSM2341810,GSM2341811,GSM2341812,GSM2341813,GSM2341814,GSM2341815,GSM2341816,GSM2341817,GSM2341818,GSM2341819,GSM2341820,GSM2341821,GSM2341822,GSM2341823,GSM2341824,GSM2341825,GSM2341826,GSM2341827,GSM2341828,GSM2341829,GSM2341830,GSM2341831,GSM2341832,GSM2341833,GSM2341834,GSM2341835,GSM2341836,GSM2341837,GSM2341838,GSM2341839,GSM2341840,GSM2341841,GSM2341842,GSM2341843,GSM2341844,GSM2341845,GSM2341846,GSM2341847,GSM2341848,GSM2341849,GSM2341850,GSM2341851,GSM2341852,GSM2341853,GSM2341854,GSM2341855,GSM2341856,GSM2341857,GSM2341858,GSM2341859,GSM2341860,GSM2341861,GSM2341862,GSM2341863,GSM2341864,GSM2341865,GSM2341866,GSM2341867,GSM2341868,GSM2341869,GSM2341870,GSM2341871,GSM2341872,GSM2341873,GSM2341874,GSM2341875,GSM2341876,GSM2341877,GSM2341878,GSM2341879,GSM2341880,GSM2341881,GSM2341882,GSM2341883,GSM2341884,GSM2341885,GSM2341886,GSM2341887,GSM2341888,GSM2341889,GSM2341890,GSM2341891,GSM2341892,GSM2341893,GSM2341894,GSM2341895,GSM2341896,GSM2341897,GSM2341898,GSM2341899,GSM2341900,GSM2341901,GSM2341902
2
  Autism_spectrum_disorder_(ASD),1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
- Gender,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
 
1
  ,GSM2341810,GSM2341811,GSM2341812,GSM2341813,GSM2341814,GSM2341815,GSM2341816,GSM2341817,GSM2341818,GSM2341819,GSM2341820,GSM2341821,GSM2341822,GSM2341823,GSM2341824,GSM2341825,GSM2341826,GSM2341827,GSM2341828,GSM2341829,GSM2341830,GSM2341831,GSM2341832,GSM2341833,GSM2341834,GSM2341835,GSM2341836,GSM2341837,GSM2341838,GSM2341839,GSM2341840,GSM2341841,GSM2341842,GSM2341843,GSM2341844,GSM2341845,GSM2341846,GSM2341847,GSM2341848,GSM2341849,GSM2341850,GSM2341851,GSM2341852,GSM2341853,GSM2341854,GSM2341855,GSM2341856,GSM2341857,GSM2341858,GSM2341859,GSM2341860,GSM2341861,GSM2341862,GSM2341863,GSM2341864,GSM2341865,GSM2341866,GSM2341867,GSM2341868,GSM2341869,GSM2341870,GSM2341871,GSM2341872,GSM2341873,GSM2341874,GSM2341875,GSM2341876,GSM2341877,GSM2341878,GSM2341879,GSM2341880,GSM2341881,GSM2341882,GSM2341883,GSM2341884,GSM2341885,GSM2341886,GSM2341887,GSM2341888,GSM2341889,GSM2341890,GSM2341891,GSM2341892,GSM2341893,GSM2341894,GSM2341895,GSM2341896,GSM2341897,GSM2341898,GSM2341899,GSM2341900,GSM2341901,GSM2341902
2
  Autism_spectrum_disorder_(ASD),1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
+ Gender,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
output/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE89594.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM2384988,GSM2384989,GSM2384990,GSM2384991,GSM2384992,GSM2384993,GSM2384994,GSM2384995,GSM2384996,GSM2384997,GSM2384998,GSM2384999,GSM2385000,GSM2385001,GSM2385002,GSM2385003,GSM2385004,GSM2385005,GSM2385006,GSM2385007,GSM2385008,GSM2385009,GSM2385010,GSM2385011,GSM2385012,GSM2385013,GSM2385014,GSM2385015,GSM2385016,GSM2385017,GSM2385018,GSM2385019,GSM2385020,GSM2385021,GSM2385022,GSM2385023,GSM2385024,GSM2385025,GSM2385026,GSM2385027,GSM2385028,GSM2385029,GSM2385030,GSM2385031,GSM2385032,GSM2385033,GSM2385034,GSM2385035,GSM2385036,GSM2385037,GSM2385038,GSM2385039,GSM2385040,GSM2385041,GSM2385042,GSM2385043,GSM2385044,GSM2385045,GSM2385046,GSM2385047,GSM2385048,GSM2385049,GSM2385050,GSM2385051,GSM2385052,GSM2385053,GSM2385054,GSM2385055,GSM2385056,GSM2385057,GSM2385058,GSM2385059,GSM2385060,GSM2385061,GSM2385062,GSM2385063,GSM2385064,GSM2385065,GSM2385066,GSM2385067,GSM2385068,GSM2385069,GSM2385070,GSM2385071,GSM2385072,GSM2385073,GSM2385074,GSM2385075,GSM2385076,GSM2385077,GSM2385078,GSM2385079,GSM2385080,GSM2385081
2
+ Autism_spectrum_disorder_(ASD),0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
+ Age,22.0,23.0,24.0,24.0,33.0,22.0,24.0,21.0,24.0,20.0,28.0,21.0,21.0,22.0,25.0,23.0,20.0,21.0,20.0,32.0,36.0,24.0,21.0,30.0,28.0,22.0,24.0,21.0,22.0,20.0,27.0,22.0,23.0,20.0,31.0,27.0,32.0,20.0,36.0,22.0,28.0,25.0,35.0,22.0,22.0,10.0,16.0,10.0,33.0,21.0,11.0,10.0,35.0,12.0,38.0,24.0,34.0,32.0,21.0,29.0,20.0,19.0,24.0,13.0,23.0,15.0,43.0,10.0,13.0,16.0,27.0,24.0,11.0,24.0,32.0,24.0,27.0,16.0,14.0,11.0,24.0,28.0,17.0,15.0,34.0,39.0,12.0,15.0,21.0,29.0,23.0,26.0,19.0,21.0
4
+ Gender,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE111175.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE111175"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE111175"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE111175.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE111175.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE111175.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import pandas as pd
41
+
42
+ # 1. Gene expression data availability
43
+ is_gene_available = True # Leukocyte gene expression/transcriptomics per series description
44
+
45
+ # 2. Variable availability and converters
46
+ trait_row = 3 # 'diagnosis'
47
+ age_row = 2 # 'age (months)'
48
+ gender_row = None # 'gender' is constant (all 'M'), so not useful
49
+
50
+ def convert_trait(x):
51
+ if x is None:
52
+ return None
53
+ v = str(x)
54
+ if ':' in v:
55
+ v = v.split(':', 1)[1]
56
+ v = v.strip().lower()
57
+ # Map to ASD binary: ASD and PDDNOS considered ASD (1); others mapped to non-ASD (0)
58
+ if v in {'asd', 'pddnos'}:
59
+ return 1
60
+ if v in {'td', 'ld', 'preemienodelay', 'autfeat', 'control', 'typical', 'typical development', 'typical_development'}:
61
+ return 0
62
+ return None
63
+
64
+ def convert_age(x):
65
+ if x is None:
66
+ return None
67
+ v = str(x)
68
+ if ':' in v:
69
+ v = v.split(':', 1)[1]
70
+ v = v.strip()
71
+ try:
72
+ return float(v) # months as continuous numeric
73
+ except Exception:
74
+ return None
75
+
76
+ def convert_gender(x):
77
+ if x is None:
78
+ return None
79
+ v = str(x)
80
+ if ':' in v:
81
+ v = v.split(':', 1)[1]
82
+ v = v.strip().lower()
83
+ if v in {'male', 'm'}:
84
+ return 1
85
+ if v in {'female', 'f'}:
86
+ return 0
87
+ return None
88
+
89
+ # 3. Save metadata (initial filtering)
90
+ is_trait_available = trait_row is not None
91
+ _ = validate_and_save_cohort_info(
92
+ is_final=False,
93
+ cohort=cohort,
94
+ info_path=json_path,
95
+ is_gene_available=is_gene_available,
96
+ is_trait_available=is_trait_available
97
+ )
98
+
99
+ # 4. Clinical feature extraction (only if clinical data is available)
100
+ if trait_row is not None:
101
+ selected_clinical_df = geo_select_clinical_features(
102
+ clinical_df=clinical_data,
103
+ trait=trait,
104
+ trait_row=trait_row,
105
+ convert_trait=convert_trait,
106
+ age_row=age_row,
107
+ convert_age=convert_age,
108
+ gender_row=gender_row,
109
+ convert_gender=None
110
+ )
111
+ preview = preview_df(selected_clinical_df)
112
+ print(preview)
113
+
114
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
115
+ selected_clinical_df.to_csv(out_clinical_data_file, index=True)
116
+
117
+ # Step 3: Gene Data Extraction
118
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
119
+ gene_data = get_genetic_data(matrix_file)
120
+
121
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
122
+ print(gene_data.index[:20])
123
+
124
+ # Step 4: Gene Identifier Review
125
+ requires_gene_mapping = True
126
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
127
+
128
+ # Step 5: Gene Annotation
129
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
130
+ gene_annotation = get_gene_annotation(soft_file)
131
+
132
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
133
+ print("Gene annotation preview:")
134
+ print(preview_df(gene_annotation))
135
+
136
+ # Step 6: Gene Identifier Mapping
137
+ # Identify the appropriate columns for probe IDs and gene symbols based on the preview:
138
+ # Probe ID column: 'ID' (matches ILMN_* identifiers in gene_data)
139
+ # Gene symbol column: 'Symbol'
140
+
141
+ # 1-2. Build mapping dataframe from annotation
142
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol')
143
+
144
+ # 3. Apply mapping to convert probe-level data to gene-level data
145
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
146
+
147
+ # Step 7: Data Normalization and Linking
148
+ import os
149
+ import pandas as pd
150
+
151
+ # 1. Normalize gene symbols and save gene-level data
152
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
153
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
154
+ normalized_gene_data.to_csv(out_gene_data_file)
155
+
156
+ # 2. Ensure clinical data is available in memory; otherwise reload from disk
157
+ if 'selected_clinical_df' not in globals():
158
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
159
+
160
+ # Link clinical and genetic data
161
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
162
+
163
+ # 3. Handle missing values
164
+ processed_linked_data = handle_missing_values(linked_data, trait)
165
+
166
+ # 4. Bias check and remove biased demographic features
167
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(processed_linked_data, trait)
168
+
169
+ # 5. Final validation and save cohort info
170
+ is_gene_available = (normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0)
171
+ is_trait_available = (trait in linked_data.columns)
172
+
173
+ note = (
174
+ "INFO: Gender unavailable/constant (all male) per series; "
175
+ "Age recorded in months; Probe IDs mapped to gene symbols and normalized via NCBI synonyms."
176
+ )
177
+
178
+ is_usable = validate_and_save_cohort_info(
179
+ is_final=True,
180
+ cohort=cohort,
181
+ info_path=json_path,
182
+ is_gene_available=is_gene_available,
183
+ is_trait_available=is_trait_available,
184
+ is_biased=is_trait_biased,
185
+ df=unbiased_linked_data,
186
+ note=note
187
+ )
188
+
189
+ # 6. Save linked data if usable
190
+ if is_usable:
191
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
192
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE113842.py ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE113842"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE113842"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE113842.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE113842.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE113842.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+
41
+ # 1) Determine data availability
42
+ is_gene_available = True # RNA fractions and hybridization batch strongly suggest gene expression microarray data
43
+
44
+ # 2) Variable availability
45
+ trait_row = 0 # 'group: ASD' vs 'group: CTRL'
46
+ age_row = 2 # 'age: ...'
47
+ gender_row = None # No gender info present
48
+
49
+ # 2.2) Conversion functions
50
+ def _after_colon(x):
51
+ if x is None:
52
+ return None
53
+ if isinstance(x, (int, float)):
54
+ return str(x)
55
+ s = str(x)
56
+ if ':' in s:
57
+ s = s.split(':', 1)[1]
58
+ return s.strip()
59
+
60
+ def convert_trait(x):
61
+ val = _after_colon(x)
62
+ if val is None:
63
+ return None
64
+ v = val.strip().lower()
65
+ if 'asd' in v or 'autism' in v:
66
+ return 1
67
+ if 'ctrl' in v or 'control' in v or 'neurotypical' in v or 'healthy' in v:
68
+ return 0
69
+ return None
70
+
71
+ def convert_age(x):
72
+ val = _after_colon(x)
73
+ if val is None:
74
+ return None
75
+ v = str(val).strip().lower()
76
+ for sep in ['/', '-', ',']:
77
+ v = v.replace(sep, ' ')
78
+ parts = [p for p in v.split() if p.replace('.', '', 1).isdigit()]
79
+ if not parts:
80
+ return None
81
+ nums = [float(p) for p in parts]
82
+ return sum(nums) / len(nums)
83
+
84
+ def convert_gender(x):
85
+ val = _after_colon(x)
86
+ if val is None:
87
+ return None
88
+ v = str(val).strip().lower()
89
+ if v in {'male', 'm', 'man', 'boy'}:
90
+ return 1
91
+ if v in {'female', 'f', 'woman', 'girl'}:
92
+ return 0
93
+ return None
94
+
95
+ # 3) Save initial metadata
96
+ is_trait_available = trait_row is not None
97
+ _ = validate_and_save_cohort_info(
98
+ is_final=False,
99
+ cohort=cohort,
100
+ info_path=json_path,
101
+ is_gene_available=is_gene_available,
102
+ is_trait_available=is_trait_available
103
+ )
104
+
105
+ # 4) Clinical feature extraction (only if trait data is available)
106
+ if trait_row is not None:
107
+ selected_clinical_df = geo_select_clinical_features(
108
+ clinical_df=clinical_data,
109
+ trait=trait,
110
+ trait_row=trait_row,
111
+ convert_trait=convert_trait,
112
+ age_row=age_row,
113
+ convert_age=convert_age,
114
+ gender_row=gender_row,
115
+ convert_gender=convert_gender
116
+ )
117
+ clinical_preview = preview_df(selected_clinical_df)
118
+ print("Clinical preview:", clinical_preview) # quick inspection aid
119
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
120
+ selected_clinical_df.to_csv(out_clinical_data_file)
121
+
122
+ # Step 3: Gene Data Extraction
123
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
124
+ gene_data = get_genetic_data(matrix_file)
125
+
126
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
127
+ print(gene_data.index[:20])
128
+
129
+ # Step 4: Gene Identifier Review
130
+ # Affymetrix probe set IDs detected (e.g., 11715100_at, _s_at, _x_at), not human gene symbols.
131
+ requires_gene_mapping = True
132
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
133
+
134
+ # Step 5: Gene Annotation
135
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
136
+ gene_annotation = get_gene_annotation(soft_file)
137
+
138
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
139
+ print("Gene annotation preview:")
140
+ print(preview_df(gene_annotation))
141
+
142
+ # Step 6: Gene Identifier Mapping
143
+ # Decide columns for probe ID and gene symbol based on annotation preview:
144
+ # - Probe identifiers: 'ID' (e.g., '1415670_PM_at')
145
+ # - Gene symbols: 'Gene Symbol' (e.g., 'Copg', 'Atp6v0d1', ...)
146
+ # Extract mapping and apply to convert probe-level data to gene-level expression
147
+
148
+ # 1-2) Build mapping dataframe
149
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
150
+
151
+ # Make symbols uppercase to improve extraction of gene tokens in downstream helper
152
+ mapping_df['Gene'] = mapping_df['Gene'].astype(str).str.upper()
153
+
154
+ # 3) Apply mapping to aggregate probes into genes
155
+ probe_data = gene_data # keep original probe-level data
156
+ gene_data = apply_gene_mapping(probe_data, mapping_df)
157
+
158
+ # Step 7: Data Normalization and Linking
159
+ import os
160
+ import pandas as pd
161
+
162
+ # 1. Normalize gene symbols and save
163
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
164
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
165
+ normalized_gene_data.to_csv(out_gene_data_file)
166
+
167
+ # Load clinical data from previous step (ensure availability in current execution context)
168
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
169
+
170
+ # 2. Link clinical and genetic data
171
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
172
+
173
+ # 3. Handle missing values
174
+ linked_data = handle_missing_values(linked_data, trait)
175
+
176
+ # 4. Assess bias and remove biased demographic features
177
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
178
+
179
+ # 5. Final validation and save cohort info
180
+ is_gene_available_flag = normalized_gene_data.shape[0] > 0
181
+ is_trait_available_flag = trait in selected_clinical_df.index
182
+
183
+ note_parts = []
184
+ if not is_gene_available_flag:
185
+ note_parts.append("WARNING: Normalized gene data is empty after human gene symbol mapping; "
186
+ "platform annotation suggests Mus musculus, causing symbol mismatch.")
187
+ if 'Gender' not in selected_clinical_df.index:
188
+ note_parts.append("INFO: Gender not available in clinical annotations.")
189
+ note = " ".join(note_parts) if note_parts else ""
190
+
191
+ is_usable = validate_and_save_cohort_info(
192
+ is_final=True,
193
+ cohort=cohort,
194
+ info_path=json_path,
195
+ is_gene_available=is_gene_available_flag,
196
+ is_trait_available=is_trait_available_flag,
197
+ is_biased=is_trait_biased,
198
+ df=unbiased_linked_data,
199
+ note=note
200
+ )
201
+
202
+ # 6. Save linked data if usable
203
+ if is_usable:
204
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
205
+ unbiased_linked_data.to_csv(out_data_file)
206
+
207
+ # Step 8: Gene Annotation
208
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
209
+ gene_annotation = get_gene_annotation(soft_file)
210
+
211
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
212
+ print("Gene annotation preview:")
213
+ print(preview_df(gene_annotation))
214
+
215
+ # Step 9: Gene Identifier Mapping
216
+ import os
217
+ import pandas as pd
218
+
219
+ # Reload probe-level data to ensure correct overlap assessment
220
+ probe_data = get_genetic_data(matrix_file)
221
+
222
+ # Identify all SOFT files and select the annotation with maximal probe-ID overlap (prefer Homo sapiens when possible)
223
+ soft_files = [f for f in os.listdir(in_cohort_dir) if 'soft' in f.lower()]
224
+ best_soft_path = None
225
+ best_overlap = -1
226
+ best_annotation = None
227
+
228
+ for sf in soft_files:
229
+ sf_path = os.path.join(in_cohort_dir, sf)
230
+ try:
231
+ ann = get_gene_annotation(sf_path)
232
+ if 'ID' not in ann.columns:
233
+ continue
234
+
235
+ # Prefer Homo sapiens annotation if available
236
+ candidates = []
237
+ if 'Species Scientific Name' in ann.columns:
238
+ ann_hs = ann[ann['Species Scientific Name'].astype(str).str.contains('Homo sapiens', case=False, na=False)]
239
+ if not ann_hs.empty:
240
+ candidates.append(ann_hs)
241
+ candidates.append(ann)
242
+
243
+ for cand in candidates:
244
+ overlap = pd.Index(cand['ID'].astype(str)).intersection(probe_data.index).size
245
+ if overlap > best_overlap:
246
+ best_overlap = overlap
247
+ best_soft_path = sf_path
248
+ best_annotation = cand
249
+ except Exception:
250
+ continue
251
+
252
+ # Fallback to previously loaded annotation if needed
253
+ if best_annotation is None:
254
+ best_annotation = gene_annotation
255
+
256
+ # Determine the gene symbol column
257
+ symbol_col = None
258
+ for col in best_annotation.columns:
259
+ if col.strip().lower() == 'gene symbol':
260
+ symbol_col = col
261
+ break
262
+ if symbol_col is None:
263
+ # Heuristic fallbacks
264
+ if 'Target Description' in best_annotation.columns:
265
+ symbol_col = 'Target Description'
266
+ else:
267
+ candidates = [c for c in best_annotation.columns if 'symbol' in c.lower()]
268
+ symbol_col = candidates[0] if candidates else best_annotation.columns[0]
269
+
270
+ # Build mapping dataframe from the chosen annotation
271
+ mapping_df = get_gene_mapping(best_annotation, prob_col='ID', gene_col=symbol_col)
272
+ # Normalize gene tokens for robust extraction
273
+ mapping_df['Gene'] = mapping_df['Gene'].astype(str).str.replace('///', ' ', regex=False).str.upper()
274
+
275
+ # Apply mapping to aggregate probe-level measurements into gene-level expression
276
+ gene_data = apply_gene_mapping(probe_data, mapping_df)
277
+
278
+ # Step 10: Data Normalization and Linking
279
+ import os
280
+ import pandas as pd
281
+
282
+ # 1) Normalize gene symbols and save normalized gene expression
283
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
284
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
285
+ normalized_gene_data.to_csv(out_gene_data_file)
286
+
287
+ # Load clinical data from previous step to ensure availability in current context
288
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
289
+
290
+ # 2) Link clinical and genetic data (conditionally, depending on whether gene data is available)
291
+ is_gene_available_flag = normalized_gene_data.shape[0] > 0
292
+ is_trait_available_flag = trait in selected_clinical_df.index
293
+
294
+ def handle_missing_values_clinical_only(df: pd.DataFrame, trait_col: str) -> pd.DataFrame:
295
+ # Drop samples with missing trait
296
+ df = df.dropna(subset=[trait_col])
297
+ # Impute Age
298
+ if 'Age' in df.columns:
299
+ if df['Age'].notna().sum() > 0:
300
+ df['Age'] = df['Age'].fillna(df['Age'].mean())
301
+ # Impute Gender
302
+ if 'Gender' in df.columns:
303
+ mode_result = df['Gender'].mode()
304
+ if len(mode_result) > 0:
305
+ df['Gender'] = df['Gender'].fillna(mode_result[0])
306
+ else:
307
+ df = df.drop(columns='Gender')
308
+ return df
309
+
310
+ if is_trait_available_flag and is_gene_available_flag:
311
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
312
+ # 3) Handle missing values on linked data with genes
313
+ linked_data = handle_missing_values(linked_data, trait)
314
+ # 4) Assess bias and remove biased demographic features
315
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
316
+ elif is_trait_available_flag:
317
+ # Clinical-only fallback: transpose to samples-as-rows
318
+ clinical_only = selected_clinical_df.T
319
+ clinical_only = handle_missing_values_clinical_only(clinical_only, trait)
320
+ # Assess bias on clinical-only data
321
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(clinical_only, trait)
322
+ else:
323
+ # No trait available; create empty placeholders
324
+ linked_data = pd.DataFrame()
325
+ is_trait_biased, unbiased_linked_data = (False, linked_data)
326
+
327
+ # 5) Final validation and cohort info with diagnostics
328
+ note_parts = []
329
+ if not is_gene_available_flag:
330
+ note_parts.append("WARNING: Normalized gene data is empty after mapping; possible species/platform mismatch (e.g., Mus musculus annotation).")
331
+ if 'Gender' not in selected_clinical_df.index:
332
+ note_parts.append("INFO: Gender not available in clinical annotations.")
333
+
334
+ # Add diagnostic about probe-annotation overlap and resulting gene_data size
335
+ try:
336
+ probe_data_diag = get_genetic_data(matrix_file)
337
+ ann_diag = get_gene_annotation(soft_file)
338
+ if 'ID' in ann_diag.columns:
339
+ overlap = pd.Index(ann_diag['ID'].astype(str)).intersection(probe_data_diag.index).size
340
+ note_parts.append(f"DEBUG: Probe-annotation overlap={overlap}/{len(probe_data_diag)}; normalized gene rows={normalized_gene_data.shape[0]}.")
341
+ else:
342
+ note_parts.append(f"DEBUG: Annotation lacks 'ID' column; normalized gene rows={normalized_gene_data.shape[0]}.")
343
+ except Exception as _e:
344
+ note_parts.append(f"DEBUG: Diagnostics failed; normalized gene rows={normalized_gene_data.shape[0]}.")
345
+
346
+ note = " ".join(note_parts) if note_parts else ""
347
+
348
+ is_usable = validate_and_save_cohort_info(
349
+ is_final=True,
350
+ cohort=cohort,
351
+ info_path=json_path,
352
+ is_gene_available=is_gene_available_flag,
353
+ is_trait_available=is_trait_available_flag,
354
+ is_biased=is_trait_biased,
355
+ df=unbiased_linked_data,
356
+ note=note
357
+ )
358
+
359
+ # 6) Save usable linked data
360
+ if is_usable:
361
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
362
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE123302.py ADDED
@@ -0,0 +1,382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE123302"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE123302"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE123302.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE123302.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE123302.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+ import pandas as pd
42
+
43
+ # 1) Gene expression availability (Affymetrix Human Gene 2.0 array => gene expression microarray)
44
+ is_gene_available = True
45
+
46
+ # 2) Variable availability and conversion
47
+ # From the Sample Characteristics Dictionary:
48
+ # 0: diagnosis (TD, Non-TD, ASD) -> trait
49
+ # 1: Sex (male, female) -> gender
50
+ # No age available
51
+ trait_row = 0
52
+ age_row = None
53
+ gender_row = 1
54
+
55
+ def _after_colon(x):
56
+ if pd.isna(x):
57
+ return None
58
+ s = str(x)
59
+ return s.split(":", 1)[1].strip() if ":" in s else s.strip()
60
+
61
+ def convert_trait(x):
62
+ v = _after_colon(x)
63
+ if v is None:
64
+ return None
65
+ low = v.lower().strip()
66
+ # Map ASD to 1; Non-TD and TD to 0
67
+ if low == "asd":
68
+ return 1
69
+ if low in {"td", "non-td", "non td"}:
70
+ return 0
71
+ # Heuristics
72
+ if "asd" in low and not any(tok in low for tok in ["non", "not"]):
73
+ return 1
74
+ if "td" in low or "non" in low:
75
+ return 0
76
+ return None
77
+
78
+ def convert_age(x):
79
+ v = _after_colon(x)
80
+ if v is None:
81
+ return None
82
+ # Extract first number (years assumed if not specified)
83
+ m = re.search(r"[-+]?\d*\.?\d+", v)
84
+ if not m:
85
+ return None
86
+ try:
87
+ return float(m.group())
88
+ except Exception:
89
+ return None
90
+
91
+ def convert_gender(x):
92
+ v = _after_colon(x)
93
+ if v is None:
94
+ return None
95
+ low = v.lower().strip()
96
+ if low in {"male", "m"}:
97
+ return 1
98
+ if low in {"female", "f"}:
99
+ return 0
100
+ return None
101
+
102
+ # 3) Save metadata (initial filtering)
103
+ is_trait_available = trait_row is not None
104
+ _ = validate_and_save_cohort_info(
105
+ is_final=False,
106
+ cohort=cohort,
107
+ info_path=json_path,
108
+ is_gene_available=is_gene_available,
109
+ is_trait_available=is_trait_available
110
+ )
111
+
112
+ # 4) Clinical Feature Extraction (only if clinical data available)
113
+ if trait_row is not None:
114
+ selected_clinical_df = geo_select_clinical_features(
115
+ clinical_df=clinical_data,
116
+ trait=trait,
117
+ trait_row=trait_row,
118
+ convert_trait=convert_trait,
119
+ age_row=age_row,
120
+ convert_age=convert_age,
121
+ gender_row=gender_row,
122
+ convert_gender=convert_gender
123
+ )
124
+ preview = preview_df(selected_clinical_df, n=5)
125
+ print("Clinical features preview:", preview)
126
+
127
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
128
+ selected_clinical_df.to_csv(out_clinical_data_file)
129
+
130
+ # Step 3: Gene Data Extraction
131
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
132
+ gene_data = get_genetic_data(matrix_file)
133
+
134
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
135
+ print(gene_data.index[:20])
136
+
137
+ # Step 4: Gene Identifier Review
138
+ requires_gene_mapping = True
139
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
140
+
141
+ # Step 5: Gene Annotation
142
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
143
+ gene_annotation = get_gene_annotation(soft_file)
144
+
145
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
146
+ print("Gene annotation preview:")
147
+ print(preview_df(gene_annotation))
148
+
149
+ # Step 6: Gene Identifier Mapping
150
+ import os
151
+ import io
152
+ import re
153
+ import gzip
154
+ import pandas as pd
155
+
156
+ # Helper: pick gene symbol-like column
157
+ def pick_gene_symbol_column(df: pd.DataFrame) -> str | None:
158
+ preferred_exact = [
159
+ 'Gene Symbol', 'GENE_SYMBOL', 'gene_symbol', 'SYMBOL', 'ENTREZ_GENE_SYMBOL',
160
+ 'Gene Symbol(s)', 'Gene symbol', 'GENE_SYMBOLS', 'entrez_gene_symbol',
161
+ 'GENE_SYMBOLS_CHIP', 'Gene.Symbol'
162
+ ]
163
+ for c in preferred_exact:
164
+ if c in df.columns:
165
+ return c
166
+
167
+ # Common columns that embed symbols in descriptive text
168
+ alternatives = [
169
+ 'gene_assignment', 'GENE_ASSIGNMENT', 'mrna_assignment',
170
+ 'Gene Title', 'gene_title', 'Gene Name', 'Associated Gene Name',
171
+ 'Associated Genes', 'Associated Gene', 'DESCRIPTION', 'desc'
172
+ ]
173
+ for c in alternatives:
174
+ if c in df.columns:
175
+ return c
176
+
177
+ # Pattern-based search
178
+ for c in df.columns:
179
+ if re.search(r'gene.*symbol|^symbol$|symbols?$', c, flags=re.I):
180
+ return c
181
+ return None
182
+
183
+ # Helper: read GPL platform table between !platform_table_begin and !platform_table_end
184
+ def read_gpl_platform_table(soft_path: str) -> pd.DataFrame | None:
185
+ opener = gzip.open if soft_path.lower().endswith('.gz') else open
186
+ with opener(soft_path, 'rt', errors='ignore') as f:
187
+ capturing = False
188
+ buf_lines = []
189
+ for line in f:
190
+ line = line.rstrip('\n')
191
+ if line.startswith('!platform_table_begin'):
192
+ capturing = True
193
+ buf_lines.clear()
194
+ continue
195
+ if line.startswith('!platform_table_end'):
196
+ capturing = False
197
+ break
198
+ if capturing:
199
+ buf_lines.append(line)
200
+ if not buf_lines:
201
+ return None
202
+ text = '\n'.join(buf_lines)
203
+ try:
204
+ df = pd.read_csv(io.StringIO(text), sep='\t', dtype=str, low_memory=False, on_bad_lines='skip')
205
+ return df
206
+ except Exception:
207
+ return None
208
+
209
+ # Helper: find GPL soft files recursively
210
+ def find_gpl_soft_files(root_dir: str) -> list[str]:
211
+ paths = []
212
+ for dirpath, _, filenames in os.walk(root_dir):
213
+ for fn in filenames:
214
+ low = fn.lower()
215
+ if ('gpl' in low) and ('soft' in low):
216
+ paths.append(os.path.join(dirpath, fn))
217
+ return paths
218
+
219
+ # 1) Decide identifier and symbol columns from current annotation first (may not have symbols)
220
+ id_col = 'ID' # probe/feature IDs seen in gene_data index
221
+
222
+ # Try to use the existing gene_annotation first
223
+ gene_col = pick_gene_symbol_column(gene_annotation)
224
+
225
+ platform_df = None
226
+ platform_used_path = None
227
+
228
+ # If not found, search GPL files across the entire trait directory
229
+ if gene_col is None:
230
+ gpl_files = find_gpl_soft_files(in_trait_dir)
231
+ # Prioritize files that look like platform annotation
232
+ for gpl in gpl_files:
233
+ df_plat = read_gpl_platform_table(gpl)
234
+ if df_plat is None or df_plat.shape[1] < 2:
235
+ continue
236
+
237
+ # Choose ID column by maximizing overlap with our probe IDs
238
+ candidates_id = [c for c in df_plat.columns if c.upper() in {'ID', 'ID_REF', 'PROBESET_ID', 'TRANSCRIPT_CLUSTER_ID'}]
239
+ if not candidates_id:
240
+ # fallback: consider any column named like id
241
+ candidates_id = [c for c in df_plat.columns if re.fullmatch(r'id(_ref)?', c, flags=re.I)]
242
+ if not candidates_id:
243
+ # try all columns and pick the one with max overlap
244
+ candidates_id = list(df_plat.columns)
245
+
246
+ best_id = None
247
+ best_overlap = -1
248
+ probe_index_set = set(map(str, gene_data.index))
249
+ for c in candidates_id:
250
+ # compute overlap count
251
+ col_vals = set(map(str, df_plat[c].dropna().unique())) if c in df_plat.columns else set()
252
+ overlap = len(probe_index_set & col_vals)
253
+ if overlap > best_overlap:
254
+ best_overlap = overlap
255
+ best_id = c
256
+
257
+ # require at least some overlap
258
+ if best_id is None or best_overlap <= 0:
259
+ continue
260
+
261
+ # pick symbol column
262
+ gc = pick_gene_symbol_column(df_plat)
263
+ if gc is None:
264
+ # If still no symbol-like column, skip this platform
265
+ continue
266
+
267
+ platform_df = df_plat
268
+ id_col = best_id
269
+ gene_col = gc
270
+ platform_used_path = gpl
271
+ break
272
+
273
+ # If still no gene_col, attempt to parse platform table from the series soft itself
274
+ if gene_col is None:
275
+ df_plat_series = read_gpl_platform_table(soft_file)
276
+ if df_plat_series is not None and df_plat_series.shape[1] >= 2:
277
+ # choose id column by overlap
278
+ candidates_id = [c for c in df_plat_series.columns if c.upper() in {'ID', 'ID_REF', 'PROBESET_ID', 'TRANSCRIPT_CLUSTER_ID'}]
279
+ if not candidates_id:
280
+ candidates_id = list(df_plat_series.columns)
281
+ best_id = None
282
+ best_overlap = -1
283
+ probe_index_set = set(map(str, gene_data.index))
284
+ for c in candidates_id:
285
+ col_vals = set(map(str, df_plat_series[c].dropna().unique()))
286
+ overlap = len(probe_index_set & col_vals)
287
+ if overlap > best_overlap:
288
+ best_overlap = overlap
289
+ best_id = c
290
+ gc = pick_gene_symbol_column(df_plat_series)
291
+ if (best_id is not None) and (best_overlap > 0) and (gc is not None):
292
+ platform_df = df_plat_series
293
+ id_col = best_id
294
+ gene_col = gc
295
+
296
+ # Build mapping dataframe if a gene column is available
297
+ mapping_df = None
298
+ if gene_col is not None:
299
+ anno_df = platform_df if platform_df is not None else gene_annotation
300
+ try:
301
+ mapping_df = get_gene_mapping(anno_df, prob_col=id_col, gene_col=gene_col)
302
+ # If no rows after basic processing, invalidate
303
+ if mapping_df is not None and mapping_df.shape[0] == 0:
304
+ mapping_df = None
305
+ except Exception:
306
+ mapping_df = None
307
+
308
+ # Apply mapping; if unavailable, fall back to probe-level
309
+ expr_df = gene_data
310
+ if mapping_df is not None:
311
+ try:
312
+ mapped_gene_data = apply_gene_mapping(expression_df=expr_df, mapping_df=mapping_df)
313
+ if mapped_gene_data.shape[0] > 0:
314
+ gene_data = mapped_gene_data
315
+ else:
316
+ # Fallback to probe-level if mapping yielded empty
317
+ print("WARNING: Gene symbol mapping produced an empty matrix; proceeding with probe-level data.")
318
+ except Exception as e:
319
+ print(f"WARNING: Gene symbol mapping failed with error: {e}. Proceeding with probe-level data.")
320
+ else:
321
+ print("WARNING: No suitable gene symbol annotation found. Proceeding with probe-level data.")
322
+
323
+ # Step 7: Data Normalization and Linking
324
+ import os
325
+ import pandas as pd
326
+
327
+ # 1. Normalize gene symbols; if normalization yields empty (likely due to probe IDs), fall back to probe-level data.
328
+ note_msgs = []
329
+ try:
330
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data.copy())
331
+ except Exception as e:
332
+ normalized_gene_data = pd.DataFrame()
333
+ note_msgs.append(f"ERROR: normalization_failed: {e}")
334
+
335
+ if normalized_gene_data is not None and normalized_gene_data.shape[0] > 0:
336
+ final_gene_data = normalized_gene_data
337
+ note_msgs.append("INFO: Gene symbols normalized using NCBI synonyms.")
338
+ else:
339
+ final_gene_data = gene_data.copy()
340
+ note_msgs.append("WARNING: Gene symbol mapping unavailable; using probe-level identifiers without normalization.")
341
+
342
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
343
+ final_gene_data.to_csv(out_gene_data_file)
344
+
345
+ # 2. Link the clinical and genetic data
346
+ try:
347
+ selected_clinical_df # noqa: F401
348
+ except NameError:
349
+ # Reload clinical features if not in memory
350
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
351
+
352
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, final_gene_data)
353
+
354
+ # 3. Handle missing values in the linked data
355
+ linked_data = handle_missing_values(linked_data, trait)
356
+
357
+ # 4. Determine whether the trait and demographics are biased; drop biased demographics
358
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
359
+
360
+ # 5. Final validation and save cohort info with native Python booleans for JSON
361
+ covariate_cols = [trait, 'Age', 'Gender']
362
+ gene_cols_final = [c for c in unbiased_linked_data.columns if c not in covariate_cols]
363
+ is_gene_available_final = bool(len(gene_cols_final) > 0)
364
+ is_trait_available_final = bool((trait in unbiased_linked_data.columns) and bool(unbiased_linked_data[trait].notna().any()))
365
+
366
+ note = "; ".join(note_msgs) if note_msgs else "INFO: No special notes."
367
+
368
+ is_usable = validate_and_save_cohort_info(
369
+ is_final=True,
370
+ cohort=cohort,
371
+ info_path=json_path,
372
+ is_gene_available=is_gene_available_final,
373
+ is_trait_available=is_trait_available_final,
374
+ is_biased=is_trait_biased,
375
+ df=unbiased_linked_data,
376
+ note=note
377
+ )
378
+
379
+ # 6. Save the linked dataset if usable
380
+ if is_usable:
381
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
382
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE148450.py ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE148450"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE148450"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE148450.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE148450.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE148450.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ # Determine gene expression availability
40
+ is_gene_available = True # Microarray-based genome-wide transcriptome profiling indicates gene expression data.
41
+
42
+ # Identify variable availability based on the provided Sample Characteristics Dictionary
43
+ trait_row = 0 # 'diagnosis: TD/ASD/NonTD'
44
+ age_row = None # Not available in the characteristics
45
+ gender_row = 1 # 'Sex: M/F'
46
+
47
+ # Define converters
48
+ def _extract_value(x):
49
+ if x is None:
50
+ return None
51
+ try:
52
+ parts = str(x).split(':', 1)
53
+ val = parts[1] if len(parts) > 1 else parts[0]
54
+ return val.strip()
55
+ except Exception:
56
+ return None
57
+
58
+ def convert_trait(x):
59
+ v = _extract_value(x)
60
+ if v is None:
61
+ return None
62
+ v_low = v.strip().lower().replace('-', '').replace(' ', '')
63
+ if v_low == 'asd':
64
+ return 1
65
+ if v_low == 'td':
66
+ return 0
67
+ if v_low in {'nontd', 'nonstd', 'nonstddevelopment'}:
68
+ # Non-typical development is not ASD; exclude from binary ASD vs TD analysis
69
+ return None
70
+ return None
71
+
72
+ def convert_gender(x):
73
+ v = _extract_value(x)
74
+ if v is None:
75
+ return None
76
+ v_low = v.strip().lower()
77
+ if v_low in {'f', 'female'}:
78
+ return 0
79
+ if v_low in {'m', 'male'}:
80
+ return 1
81
+ return None
82
+
83
+ convert_age = None # No age available
84
+
85
+ # Trait availability for initial filtering
86
+ is_trait_available = trait_row is not None
87
+
88
+ # Save metadata via initial filtering
89
+ _ = validate_and_save_cohort_info(
90
+ is_final=False,
91
+ cohort=cohort,
92
+ info_path=json_path,
93
+ is_gene_available=is_gene_available,
94
+ is_trait_available=is_trait_available
95
+ )
96
+
97
+ # Clinical feature extraction (only if clinical data available)
98
+ if trait_row is not None:
99
+ selected_clinical_df = geo_select_clinical_features(
100
+ clinical_df=clinical_data,
101
+ trait=trait,
102
+ trait_row=trait_row,
103
+ convert_trait=convert_trait,
104
+ age_row=age_row,
105
+ convert_age=convert_age,
106
+ gender_row=gender_row,
107
+ convert_gender=convert_gender
108
+ )
109
+ preview = preview_df(selected_clinical_df, n=5)
110
+ print(preview)
111
+
112
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
113
+ selected_clinical_df.to_csv(out_clinical_data_file)
114
+
115
+ # Step 3: Gene Data Extraction
116
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
117
+ gene_data = get_genetic_data(matrix_file)
118
+
119
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
120
+ print(gene_data.index[:20])
121
+
122
+ # Step 4: Gene Identifier Review
123
+ print("requires_gene_mapping = False")
124
+
125
+ # Step 5: Data Normalization and Linking
126
+ import os
127
+
128
+ # 1. Normalize gene symbols and save
129
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
130
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
131
+ normalized_gene_data.to_csv(out_gene_data_file)
132
+
133
+ # 2. Link clinical and genetic data
134
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
135
+
136
+ # 3. Handle missing values
137
+ linked_data = handle_missing_values(linked_data, trait)
138
+
139
+ # 4. Assess bias and remove biased demographic features
140
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
141
+
142
+ # 5. Final validation and save cohort info
143
+ note = "INFO: Trait conversion retained ASD vs TD; Non-TD samples were set to missing and dropped during QC."
144
+ is_usable = validate_and_save_cohort_info(
145
+ is_final=True,
146
+ cohort=cohort,
147
+ info_path=json_path,
148
+ is_gene_available=True,
149
+ is_trait_available=True,
150
+ is_biased=is_trait_biased,
151
+ df=unbiased_linked_data,
152
+ note=note
153
+ )
154
+
155
+ # 6. Save linked data if usable
156
+ if is_usable:
157
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
158
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE285666.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE285666"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE285666"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE285666.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE285666.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE285666.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import re
40
+
41
+ # 1) Gene expression availability
42
+ is_gene_available = True # Affymetrix Human Exon 1.0 ST arrays indicate gene expression data (not miRNA/methylation)
43
+
44
+ # 2) Variable availability
45
+ # Trait is ASD, but dataset compares Williams syndrome patients vs unaffected parental controls.
46
+ trait_row = None
47
+ age_row = None
48
+ gender_row = None
49
+
50
+ # 2) Conversion functions
51
+ def _after_colon(x):
52
+ if x is None:
53
+ return None
54
+ if not isinstance(x, str):
55
+ return None
56
+ parts = x.split(":", 1)
57
+ val = parts[-1].strip() if len(parts) > 1 else x.strip()
58
+ return val if val != "" else None
59
+
60
+ def convert_trait(x):
61
+ # ASD-specific mapping; not applicable here (no ASD info), return None.
62
+ v = _after_colon(x)
63
+ if v is None:
64
+ return None
65
+ vl = v.lower()
66
+ # If any ASD keywords appear, map to case=1; explicit non-ASD control words map to 0
67
+ if any(k in vl for k in ["autism spectrum disorder", "asd", "autism"]):
68
+ return 1
69
+ if any(k in vl for k in ["control", "unaffected", "healthy", "neurotypical"]):
70
+ return 0
71
+ return None
72
+
73
+ def convert_age(x):
74
+ v = _after_colon(x)
75
+ if v is None:
76
+ return None
77
+ # Extract first float/int in the string
78
+ m = re.search(r"[-+]?\d*\.?\d+", v)
79
+ return float(m.group()) if m else None
80
+
81
+ def convert_gender(x):
82
+ v = _after_colon(x)
83
+ if v is None:
84
+ return None
85
+ vl = v.strip().lower()
86
+ if vl in ["male", "m"]:
87
+ return 1
88
+ if vl in ["female", "f"]:
89
+ return 0
90
+ return None
91
+
92
+ # 3) Save metadata (initial filtering)
93
+ is_trait_available = trait_row is not None
94
+ _ = validate_and_save_cohort_info(
95
+ is_final=False,
96
+ cohort=cohort,
97
+ info_path=json_path,
98
+ is_gene_available=is_gene_available,
99
+ is_trait_available=is_trait_available
100
+ )
101
+
102
+ # 4) Clinical feature extraction: skipped because trait_row is None (no clinical trait data available for ASD)
103
+
104
+ # Step 3: Gene Data Extraction
105
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
106
+ gene_data = get_genetic_data(matrix_file)
107
+
108
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
109
+ print(gene_data.index[:20])
110
+
111
+ # Step 4: Gene Identifier Review
112
+ print("requires_gene_mapping = True")
113
+
114
+ # Step 5: Gene Annotation
115
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
116
+ gene_annotation = get_gene_annotation(soft_file)
117
+
118
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
119
+ print("Gene annotation preview:")
120
+ print(preview_df(gene_annotation))
121
+
122
+ # Step 6: Gene Identifier Mapping
123
+ # Identify the appropriate columns in the annotation for mapping
124
+ probe_col = 'ID'
125
+ gene_symbol_col = 'gene_assignment' if 'gene_assignment' in gene_annotation.columns else 'mrna_assignment'
126
+
127
+ # Build mapping dataframe: probe ID -> gene symbol text
128
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
129
+
130
+ # Apply mapping to convert probe-level expression to gene-level expression
131
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
132
+
133
+ # Step 7: Data Normalization and Linking
134
+ # 1. Normalize the obtained gene data and save gene-only output
135
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
136
+ normalized_gene_data.to_csv(out_gene_data_file)
137
+
138
+ # Determine trait availability based on presence of extracted clinical features from prior steps
139
+ trait_available = ('selected_clinical_data' in globals()) and (selected_clinical_data is not None) and (trait in getattr(selected_clinical_data, 'index', []))
140
+
141
+ if trait_available:
142
+ # 2. Link clinical and genetic data
143
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
144
+
145
+ # 3. Handle missing values
146
+ linked_data = handle_missing_values(linked_data, trait)
147
+
148
+ # 4. Bias check and removal of biased covariates
149
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
150
+
151
+ # 5. Final validation and cohort info
152
+ is_usable = validate_and_save_cohort_info(
153
+ is_final=True,
154
+ cohort=cohort,
155
+ info_path=json_path,
156
+ is_gene_available=True,
157
+ is_trait_available=True,
158
+ is_biased=is_trait_biased,
159
+ df=unbiased_linked_data,
160
+ note="INFO: Clinical features were available; linked data processed with missing value handling and bias checks."
161
+ )
162
+
163
+ # 6. Save linked data only if usable
164
+ if is_usable:
165
+ unbiased_linked_data.to_csv(out_data_file)
166
+ else:
167
+ # No trait for ASD in this cohort; skip linking and downstream steps
168
+ _ = validate_and_save_cohort_info(
169
+ is_final=True,
170
+ cohort=cohort,
171
+ info_path=json_path,
172
+ is_gene_available=True,
173
+ is_trait_available=False,
174
+ is_biased=False,
175
+ df=normalized_gene_data.T, # provide a non-empty df to pass structural checks
176
+ note="INFO: ASD trait not available in this series (dataset contrasts Williams syndrome vs parental controls). "
177
+ "Only gene expression data were normalized and saved."
178
+ )
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE42133.py ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE42133"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE42133"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE42133.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE42133.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE42133.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+ import pandas as pd
42
+
43
+ # 1) Gene expression data availability
44
+ is_gene_available = True # Leukocyte gene expression levels (not miRNA/methylation)
45
+
46
+ # 2) Variable availability (from the provided Sample Characteristics Dictionary)
47
+ trait_row = 0 # 'dx (diagnosis): ASD' vs 'Control'
48
+ age_row = None # No age information available in the provided dictionary
49
+ gender_row = None # Only 'gender: male' listed -> constant, thus not useful
50
+
51
+ # 2.2) Data type conversion functions
52
+ def _after_colon(x):
53
+ if x is None:
54
+ return None
55
+ s = str(x)
56
+ if ':' in s:
57
+ s = s.split(':', 1)[1]
58
+ return s.strip()
59
+
60
+ def convert_trait(x):
61
+ v = _after_colon(x)
62
+ if v is None:
63
+ return None
64
+ v_low = v.lower().strip()
65
+ # Map ASD vs control/TD
66
+ asd_tokens = {'asd', 'autism', 'autistic'}
67
+ control_tokens = {'control', 'td', 'typically developing', 'typically-developed', 'typically_developing', 'neurotypical', 'sibling', 'unaffected'}
68
+ # Exact matches or contains tokens
69
+ if any(tok in v_low for tok in asd_tokens):
70
+ return 1
71
+ if any(tok in v_low for tok in control_tokens):
72
+ return 0
73
+ # Fallback for common labels
74
+ if v_low in {'case', 'patient'}:
75
+ return 1
76
+ if v_low in {'healthy', 'normal'}:
77
+ return 0
78
+ return None
79
+
80
+ def convert_age(x):
81
+ v = _after_colon(x)
82
+ if v is None:
83
+ return None
84
+ s = v.lower()
85
+ # Extract first float/int
86
+ m = re.search(r'(-?\d+(\.\d+)?)', s)
87
+ if not m:
88
+ return None
89
+ val = float(m.group(1))
90
+ # Convert to years if unit indicates months or weeks
91
+ if 'month' in s:
92
+ return val / 12.0
93
+ if 'week' in s or 'wk' in s:
94
+ return val / 52.0
95
+ # Assume years otherwise
96
+ return val
97
+
98
+ def convert_gender(x):
99
+ v = _after_colon(x)
100
+ if v is None:
101
+ return None
102
+ s = v.lower().strip()
103
+ # Female -> 0, Male -> 1
104
+ if s in {'female', 'f', 'girl', 'woman'}:
105
+ return 0
106
+ if s in {'male', 'm', 'boy', 'man'}:
107
+ return 1
108
+ return None
109
+
110
+ # 3) Save metadata (initial filtering)
111
+ is_trait_available = trait_row is not None
112
+ _ = validate_and_save_cohort_info(
113
+ is_final=False,
114
+ cohort=cohort,
115
+ info_path=json_path,
116
+ is_gene_available=is_gene_available,
117
+ is_trait_available=is_trait_available
118
+ )
119
+
120
+ # 4) Clinical feature extraction (only if trait is available)
121
+ if trait_row is not None:
122
+ selected_clinical_df = geo_select_clinical_features(
123
+ clinical_df=clinical_data,
124
+ trait=trait,
125
+ trait_row=trait_row,
126
+ convert_trait=convert_trait,
127
+ age_row=age_row,
128
+ convert_age=convert_age,
129
+ gender_row=gender_row,
130
+ convert_gender=convert_gender
131
+ )
132
+ clinical_preview = preview_df(selected_clinical_df, n=5)
133
+ print("Clinical preview:", clinical_preview)
134
+
135
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
136
+ selected_clinical_df.to_csv(out_clinical_data_file)
137
+
138
+ # Step 3: Gene Data Extraction
139
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
140
+ gene_data = get_genetic_data(matrix_file)
141
+
142
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
143
+ print(gene_data.index[:20])
144
+
145
+ # Step 4: Gene Identifier Review
146
+ requires_gene_mapping = True
147
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
148
+
149
+ # Step 5: Gene Annotation
150
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
151
+ gene_annotation = get_gene_annotation(soft_file)
152
+
153
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
154
+ print("Gene annotation preview:")
155
+ print(preview_df(gene_annotation))
156
+
157
+ # Step 6: Gene Identifier Mapping
158
+ # Identify the appropriate columns for probe IDs and gene symbols
159
+ probe_col = 'ID'
160
+ gene_symbol_col = 'Symbol'
161
+
162
+ # Build the mapping dataframe from the annotation
163
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
164
+
165
+ # Apply mapping to convert probe-level data to gene-level expression
166
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
167
+
168
+ # Step 7: Data Normalization and Linking
169
+ import os
170
+
171
+ # 1. Normalize the obtained gene data and save
172
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
173
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
174
+ normalized_gene_data.to_csv(out_gene_data_file)
175
+
176
+ # Ensure clinical features are available in current context
177
+ if 'selected_clinical_df' not in globals():
178
+ if os.path.exists(out_clinical_data_file):
179
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
180
+ else:
181
+ raise NameError("selected_clinical_df is not defined and clinical data file not found.")
182
+
183
+ # 2. Link the clinical and genetic data
184
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
185
+
186
+ # 3. Handle missing values in the linked data
187
+ linked_data = handle_missing_values(linked_data, trait)
188
+
189
+ # 4. Determine whether the trait and some demographic features are severely biased, and remove biased features.
190
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
191
+
192
+ # 5. Conduct quality check and save the cohort information.
193
+ note = "INFO: Age and Gender not available/usable in clinical data."
194
+ is_usable = validate_and_save_cohort_info(
195
+ True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data, note=note
196
+ )
197
+
198
+ # 6. If the linked data is usable, save it as a CSV file to 'out_data_file'.
199
+ if is_usable:
200
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
201
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE57802.py ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE57802"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE57802"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE57802.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE57802.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE57802.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import re
40
+
41
+ # 1. Gene Expression Data Availability
42
+ is_gene_available = True # Transcriptome profiling indicates gene expression data (not miRNA/methylation)
43
+
44
+ # 2. Variable Availability and Data Type Conversion
45
+
46
+ # 2.1 Data Availability
47
+ trait_row = None # No explicit ASD diagnosis/status available; CNV status cannot be used as ASD label
48
+ age_row = 2 # 'age: ...'
49
+ gender_row = 1 # 'gender: M/F'
50
+
51
+ # 2.2 Data Type Conversion
52
+ def _after_colon(value):
53
+ if value is None:
54
+ return None
55
+ parts = str(value).split(":", 1)
56
+ val = parts[1] if len(parts) > 1 else parts[0]
57
+ return val.strip()
58
+
59
+ def convert_trait(x):
60
+ # Generic ASD converter (not used here since trait_row is None)
61
+ v = _after_colon(x)
62
+ if v is None or v == "":
63
+ return None
64
+ vl = v.lower()
65
+ # Positive ASD indicators
66
+ pos = {'asd', 'autism', 'autism spectrum disorder', 'case', 'patient', 'affected', 'asdp', 'autistic'}
67
+ # Negative ASD indicators
68
+ neg = {'control', 'td', 'typical', 'healthy', 'unaffected', 'neurotypical'}
69
+ if vl in pos:
70
+ return 1
71
+ if vl in neg:
72
+ return 0
73
+ if vl in {'yes', 'y', 'true', '1'}:
74
+ return 1
75
+ if vl in {'no', 'n', 'false', '0'}:
76
+ return 0
77
+ return None
78
+
79
+ def convert_age(x):
80
+ v = _after_colon(x)
81
+ if v is None:
82
+ return None
83
+ vl = v.strip().lower()
84
+ if vl in {"na", "n/a", "", "none"}:
85
+ return None
86
+ # Extract first numeric token (handles integers/floats, possibly with units)
87
+ m = re.search(r'[-+]?\d*\.?\d+', vl)
88
+ if m:
89
+ try:
90
+ return float(m.group())
91
+ except Exception:
92
+ return None
93
+ return None
94
+
95
+ def convert_gender(x):
96
+ v = _after_colon(x)
97
+ if v is None:
98
+ return None
99
+ vl = v.strip().lower()
100
+ if vl in {"male", "m", "man", "boy"}:
101
+ return 1
102
+ if vl in {"female", "f", "woman", "girl"}:
103
+ return 0
104
+ return None
105
+
106
+ # 3. Save Metadata (initial filtering)
107
+ is_trait_available = trait_row is not None
108
+ _ = validate_and_save_cohort_info(
109
+ is_final=False,
110
+ cohort=cohort,
111
+ info_path=json_path,
112
+ is_gene_available=is_gene_available,
113
+ is_trait_available=is_trait_available
114
+ )
115
+
116
+ # 4. Clinical Feature Extraction (skip because trait_row is None)
117
+ # If trait_row were available:
118
+ # selected_clinical_df = geo_select_clinical_features(
119
+ # clinical_df=clinical_data,
120
+ # trait=trait,
121
+ # trait_row=trait_row,
122
+ # convert_trait=convert_trait,
123
+ # age_row=age_row,
124
+ # convert_age=convert_age,
125
+ # gender_row=gender_row,
126
+ # convert_gender=convert_gender
127
+ # )
128
+ # preview = preview_df(selected_clinical_df)
129
+ # os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
130
+ # selected_clinical_df.to_csv(out_clinical_data_file, index=True)
131
+
132
+ # Step 3: Gene Data Extraction
133
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
134
+ gene_data = get_genetic_data(matrix_file)
135
+
136
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
137
+ print(gene_data.index[:20])
138
+
139
+ # Step 4: Gene Identifier Review
140
+ requires_gene_mapping = True
141
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
142
+
143
+ # Step 5: Gene Annotation
144
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
145
+ gene_annotation = get_gene_annotation(soft_file)
146
+
147
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
148
+ print("Gene annotation preview:")
149
+ print(preview_df(gene_annotation))
150
+
151
+ # Step 6: Gene Identifier Mapping
152
+ # 1-2. Determine identifier and gene symbol columns and construct mapping dataframe
153
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
154
+
155
+ # 3. Apply mapping to convert probe-level data to gene-level expression
156
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
157
+
158
+ # Step 7: Data Normalization and Linking
159
+ import os
160
+
161
+ # 1. Normalize gene symbols and save gene expression data
162
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
163
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
164
+ normalized_gene_data.to_csv(out_gene_data_file)
165
+
166
+ # Determine if trait data is available from previous steps
167
+ try:
168
+ trait_available = (trait_row is not None)
169
+ except NameError:
170
+ trait_available = False
171
+
172
+ if trait_available:
173
+ # 2. Link clinical and genetic data
174
+ selected_clinical_data = geo_select_clinical_features(
175
+ clinical_df=clinical_data,
176
+ trait=trait,
177
+ trait_row=trait_row,
178
+ convert_trait=convert_trait,
179
+ age_row=age_row,
180
+ convert_age=convert_age,
181
+ gender_row=gender_row,
182
+ convert_gender=convert_gender
183
+ )
184
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
185
+
186
+ # 3. Handle missing values
187
+ linked_data = handle_missing_values(linked_data, trait)
188
+
189
+ # 4. Check bias and remove biased demographic features
190
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
191
+
192
+ # 5. Final validation and save metadata
193
+ is_usable = validate_and_save_cohort_info(
194
+ is_final=True,
195
+ cohort=cohort,
196
+ info_path=json_path,
197
+ is_gene_available=True,
198
+ is_trait_available=True,
199
+ is_biased=is_trait_biased,
200
+ df=unbiased_linked_data,
201
+ note="INFO: Linked clinical and gene data with age and gender where available."
202
+ )
203
+
204
+ # 6. Save linked data only if usable
205
+ if is_usable:
206
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
207
+ unbiased_linked_data.to_csv(out_data_file)
208
+
209
+ else:
210
+ # Trait not available: skip linking and still record final metadata
211
+ note = ("INFO: Trait variable is not available in sample characteristics; "
212
+ "linking clinical and gene data was skipped. Only gene expression matrix was processed and saved.")
213
+ dummy_df = normalized_gene_data.T # Use a non-empty df to avoid abnormality override
214
+ _ = validate_and_save_cohort_info(
215
+ is_final=True,
216
+ cohort=cohort,
217
+ info_path=json_path,
218
+ is_gene_available=True,
219
+ is_trait_available=False,
220
+ is_biased=False,
221
+ df=dummy_df,
222
+ note=note
223
+ )
224
+ # Do not save out_data_file since dataset is unusable without trait
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE65106.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE65106"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE65106"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE65106.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE65106.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE65106.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+ import pandas as pd
42
+ import numpy as np
43
+
44
+ # 1. Gene Expression Data Availability
45
+ is_gene_available = True # Whole-genome microarray expression data
46
+
47
+ # 2. Variable Availability
48
+ trait_row = 1 # 'disease type: Normal/ASD/WT'
49
+ age_row = 3 # 'donor age: ...'
50
+ gender_row = 4 # 'donor sex: Male/Female'
51
+
52
+ # 2.2 Conversion functions
53
+ def _extract_value(x):
54
+ if x is None or (isinstance(x, float) and np.isnan(x)):
55
+ return None
56
+ s = str(x)
57
+ if ':' in s:
58
+ s = s.split(':', 1)[1]
59
+ return s.strip()
60
+
61
+ def convert_trait(x):
62
+ v = _extract_value(x)
63
+ if v is None:
64
+ return None
65
+ s = v.strip().lower()
66
+ # Normalize common labels
67
+ if s in {'asd', 'autism', 'autism spectrum disorder', 'autistic'}:
68
+ return 1
69
+ if s in {'normal', 'control', 'wt', 'wild-type', 'wild type', 'unaffected', 'healthy', 'sib control', 'sibling control', 'non-asd'}:
70
+ return 0
71
+ return None
72
+
73
+ def convert_age(x):
74
+ v = _extract_value(x)
75
+ if v is None:
76
+ return None
77
+ s = v.strip().lower()
78
+ if any(tok in s for tok in ['embryo', 'embryonic', 'unknown', 'na', 'n/a']):
79
+ return None
80
+ m = re.search(r'[-+]?\d*\.?\d+', s)
81
+ if m:
82
+ try:
83
+ return float(m.group())
84
+ except:
85
+ return None
86
+ return None
87
+
88
+ def convert_gender(x):
89
+ v = _extract_value(x)
90
+ if v is None:
91
+ return None
92
+ s = v.strip().lower()
93
+ if s in {'male', 'm'}:
94
+ return 1
95
+ if s in {'female', 'f'}:
96
+ return 0
97
+ return None
98
+
99
+ # 3. Save Metadata (initial filtering)
100
+ is_trait_available = trait_row is not None
101
+ _ = validate_and_save_cohort_info(
102
+ is_final=False,
103
+ cohort=cohort,
104
+ info_path=json_path,
105
+ is_gene_available=is_gene_available,
106
+ is_trait_available=is_trait_available
107
+ )
108
+
109
+ # 4. Clinical Feature Extraction (only if trait is available)
110
+ if is_trait_available:
111
+ selected_clinical_df = geo_select_clinical_features(
112
+ clinical_df=clinical_data,
113
+ trait=trait,
114
+ trait_row=trait_row,
115
+ convert_trait=convert_trait,
116
+ age_row=age_row,
117
+ convert_age=convert_age,
118
+ gender_row=gender_row,
119
+ convert_gender=convert_gender
120
+ )
121
+ clinical_preview = preview_df(selected_clinical_df)
122
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
123
+ selected_clinical_df.to_csv(out_clinical_data_file)
124
+
125
+ # Step 3: Gene Data Extraction
126
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
127
+ gene_data = get_genetic_data(matrix_file)
128
+
129
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
130
+ print(gene_data.index[:20])
131
+
132
+ # Step 4: Gene Identifier Review
133
+ # The provided identifiers are numeric probe IDs (e.g., '7892501'), not human gene symbols.
134
+ requires_gene_mapping = True
135
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
136
+
137
+ # Step 5: Gene Annotation
138
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
139
+ gene_annotation = get_gene_annotation(soft_file)
140
+
141
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
142
+ print("Gene annotation preview:")
143
+ print(preview_df(gene_annotation))
144
+
145
+ # Step 6: Gene Identifier Mapping
146
+ # Identify appropriate columns for probe IDs and gene symbols from the annotation preview:
147
+ # - Probe IDs: 'ID'
148
+ # - Gene symbols information: 'gene_assignment' (contains gene symbol strings)
149
+
150
+ # 1-2. Build mapping dataframe from annotation
151
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='gene_assignment')
152
+
153
+ # 3. Apply mapping to convert probe-level data to gene-level data
154
+ # Preserve probe-level data then overwrite gene_data with gene-level
155
+ probe_data = gene_data
156
+ gene_data = apply_gene_mapping(expression_df=probe_data, mapping_df=mapping_df)
157
+
158
+ # Step 7: Data Normalization and Linking
159
+ import os
160
+ import pandas as pd
161
+
162
+ # 1. Normalize gene symbols and save gene-level data
163
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
164
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
165
+ normalized_gene_data.to_csv(out_gene_data_file)
166
+
167
+ # 2. Link clinical and genetic data
168
+ # Ensure the clinical dataframe is available in scope; if not, load from the saved file.
169
+ try:
170
+ selected_clinical_df
171
+ except NameError:
172
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
173
+
174
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
175
+
176
+ # 3. Handle missing values
177
+ linked_data = handle_missing_values(linked_data, trait)
178
+
179
+ # 4. Bias assessment and removal of biased demographic features
180
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
181
+
182
+ # 5. Final validation and save cohort info
183
+ is_gene_available_final = (normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0)
184
+ is_trait_available_final = (trait in linked_data.columns)
185
+
186
+ is_usable = validate_and_save_cohort_info(
187
+ is_final=True,
188
+ cohort=cohort,
189
+ info_path=json_path,
190
+ is_gene_available=is_gene_available_final,
191
+ is_trait_available=is_trait_available_final,
192
+ is_biased=is_trait_biased,
193
+ df=unbiased_linked_data,
194
+ note=""
195
+ )
196
+
197
+ # 6. Save linked data if usable
198
+ if is_usable:
199
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
200
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE87847.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE87847"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE87847"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE87847.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE87847.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE87847.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+
42
+ # 1) Gene expression data availability (based on series summary: mRNA expression in tissue/blood)
43
+ is_gene_available = True
44
+
45
+ # 2) Variable availability based on Sample Characteristics Dictionary provided
46
+ # Trait (ASD vs typically developing) is available at key 0
47
+ trait_row = 0
48
+
49
+ # Age is not present in the dictionary
50
+ age_row = None
51
+
52
+ # Gender is present at key 2
53
+ gender_row = 2
54
+
55
+ # 2.2) Converters
56
+ def _after_colon(x: str) -> str:
57
+ if x is None:
58
+ return ""
59
+ parts = str(x).split(":", 1)
60
+ return parts[1].strip() if len(parts) > 1 else str(x).strip()
61
+
62
+ def convert_trait(x):
63
+ v = _after_colon(x).lower()
64
+ if v in ("", "na", "n/a", "unknown", "null"):
65
+ return None
66
+ # Normalize common phrases
67
+ v_norm = v.replace("-", " ").replace("_", " ").strip()
68
+ if "autism spectrum disorder" in v_norm or v_norm == "asd":
69
+ return 1
70
+ if "typically developing" in v_norm or "control" in v_norm:
71
+ return 0
72
+ return None
73
+
74
+ def convert_age(x):
75
+ v = _after_colon(x).lower()
76
+ if not v or v in ("na", "n/a", "unknown", "null"):
77
+ return None
78
+ m = re.search(r"[-+]?\d*\.?\d+", v)
79
+ if not m:
80
+ return None
81
+ try:
82
+ return float(m.group())
83
+ except Exception:
84
+ return None
85
+
86
+ def convert_gender(x):
87
+ v = _after_colon(x).lower()
88
+ if v in ("", "na", "n/a", "unknown", "null"):
89
+ return None
90
+ if v in ("male", "m"):
91
+ return 1
92
+ if v in ("female", "f"):
93
+ return 0
94
+ return None
95
+
96
+ # 3) Save metadata (initial filtering)
97
+ is_trait_available = trait_row is not None
98
+ _ = validate_and_save_cohort_info(
99
+ is_final=False,
100
+ cohort=cohort,
101
+ info_path=json_path,
102
+ is_gene_available=is_gene_available,
103
+ is_trait_available=is_trait_available
104
+ )
105
+
106
+ # 4) Clinical Feature Extraction (only if trait_row is available)
107
+ if trait_row is not None:
108
+ selected_clinical_df = geo_select_clinical_features(
109
+ clinical_df=clinical_data,
110
+ trait=trait,
111
+ trait_row=trait_row,
112
+ convert_trait=convert_trait,
113
+ age_row=age_row,
114
+ convert_age=convert_age if age_row is not None else None,
115
+ gender_row=gender_row,
116
+ convert_gender=convert_gender
117
+ )
118
+ preview = preview_df(selected_clinical_df, n=5)
119
+ print("Preview of selected clinical features:", preview)
120
+
121
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
122
+ selected_clinical_df.to_csv(out_clinical_data_file)
123
+
124
+ # Step 3: Gene Data Extraction
125
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
126
+ gene_data = get_genetic_data(matrix_file)
127
+
128
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
129
+ print(gene_data.index[:20])
130
+
131
+ # Step 4: Gene Identifier Review
132
+ print("requires_gene_mapping = False")
133
+
134
+ # Step 5: Data Normalization and Linking
135
+ import os
136
+ import pandas as pd
137
+
138
+ # 1. Normalize gene symbols and save
139
+ if 'gene_data' not in globals():
140
+ gene_data = get_genetic_data(matrix_file)
141
+
142
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
143
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
144
+ normalized_gene_data.to_csv(out_gene_data_file)
145
+
146
+ # 2. Link clinical and genetic data
147
+ clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
148
+ linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
149
+
150
+ # 3. Handle missing values
151
+ linked_data = handle_missing_values(linked_data, trait)
152
+
153
+ # 4. Bias assessment and removal of biased demographic features
154
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
155
+
156
+ # 5. Final validation and save cohort info
157
+ note = "INFO: Age not provided; Gender available; gene symbols normalized via NCBI synonyms."
158
+ is_usable = validate_and_save_cohort_info(
159
+ is_final=True,
160
+ cohort=cohort,
161
+ info_path=json_path,
162
+ is_gene_available=True,
163
+ is_trait_available=True,
164
+ is_biased=is_trait_biased,
165
+ df=unbiased_linked_data,
166
+ note=note
167
+ )
168
+
169
+ # 6. Save linked data if usable
170
+ if is_usable:
171
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
172
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE89594.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+ cohort = "GSE89594"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
10
+ in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE89594"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/GSE89594.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE89594.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/GSE89594.csv"
16
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import re
40
+ import os
41
+
42
+ # 1) Gene expression data availability
43
+ is_gene_available = True # Gene expression profiled from blood per series design (not pure miRNA/methylation)
44
+
45
+ # 2) Variable availability
46
+ trait_row = 0 # diagnosis
47
+ age_row = 2 # age
48
+ gender_row = 3 # gender
49
+
50
+ # 2.2) Converters
51
+ def _after_colon(x):
52
+ if x is None:
53
+ return None
54
+ parts = str(x).split(':', 1)
55
+ return parts[1].strip() if len(parts) > 1 else str(x).strip()
56
+
57
+ def convert_trait(x):
58
+ v = _after_colon(x)
59
+ if v is None:
60
+ return None
61
+ lv = v.lower()
62
+ if 'autism spectrum disorder' in lv or re.search(r'\basd\b', lv):
63
+ return 1
64
+ if 'control' in lv or 'williams' in lv or re.search(r'\bws\b', lv):
65
+ return 0
66
+ return None
67
+
68
+ def convert_age(x):
69
+ v = _after_colon(x)
70
+ if v is None:
71
+ return None
72
+ m = re.search(r'(\d+(?:\.\d+)?)', v)
73
+ if not m:
74
+ return None
75
+ try:
76
+ val = float(m.group(1))
77
+ return int(val) if val.is_integer() else val
78
+ except:
79
+ return None
80
+
81
+ def convert_gender(x):
82
+ v = _after_colon(x)
83
+ if v is None:
84
+ return None
85
+ lv = v.lower()
86
+ if 'female' in lv or re.fullmatch(r'\bf\b', lv):
87
+ return 0
88
+ if 'male' in lv or re.fullmatch(r'\bm\b', lv):
89
+ return 1
90
+ return None
91
+
92
+ # 3) Save metadata (initial filtering)
93
+ is_trait_available = trait_row is not None
94
+ _ = validate_and_save_cohort_info(
95
+ is_final=False,
96
+ cohort=cohort,
97
+ info_path=json_path,
98
+ is_gene_available=is_gene_available,
99
+ is_trait_available=is_trait_available
100
+ )
101
+
102
+ # 4) Clinical feature extraction
103
+ if trait_row is not None:
104
+ selected_clinical_df = geo_select_clinical_features(
105
+ clinical_df=clinical_data,
106
+ trait=trait,
107
+ trait_row=trait_row,
108
+ convert_trait=convert_trait,
109
+ age_row=age_row,
110
+ convert_age=convert_age,
111
+ gender_row=gender_row,
112
+ convert_gender=convert_gender
113
+ )
114
+ preview = preview_df(selected_clinical_df)
115
+ print(preview)
116
+
117
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
118
+ selected_clinical_df.to_csv(out_clinical_data_file)
119
+
120
+ # Step 3: Gene Data Extraction
121
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
122
+ gene_data = get_genetic_data(matrix_file)
123
+
124
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
125
+ print(gene_data.index[:20])
126
+
127
+ # Step 4: Gene Identifier Review
128
+ print("requires_gene_mapping = True")
129
+
130
+ # Step 5: Gene Annotation
131
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
132
+ gene_annotation = get_gene_annotation(soft_file)
133
+
134
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
135
+ print("Gene annotation preview:")
136
+ print(preview_df(gene_annotation))
137
+
138
+ # Step 6: Gene Identifier Mapping
139
+ # 1) Decide columns for mapping: probe ID ('ID') and gene symbol ('GENE_SYMBOL') based on previews
140
+ probe_col = 'ID'
141
+ gene_symbol_col = 'GENE_SYMBOL'
142
+
143
+ # 2) Build mapping dataframe
144
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
145
+
146
+ # 3) Apply mapping to convert probe-level data to gene-level expression
147
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
148
+
149
+ # Step 7: Data Normalization and Linking
150
+ import os
151
+
152
+ # 1. Normalize gene symbols and save
153
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
154
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
155
+ normalized_gene_data.to_csv(out_gene_data_file)
156
+
157
+ # 2. Link clinical and genetic data
158
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
159
+
160
+ # 3. Handle missing values
161
+ linked_data = handle_missing_values(linked_data, trait)
162
+
163
+ # 4. Bias assessment and removal of biased demographics
164
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
165
+
166
+ # 5. Final validation and save cohort info (ensure pure Python bools are passed)
167
+ is_gene_available_final = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
168
+ is_trait_available_final = bool((trait in selected_clinical_df.index) and selected_clinical_df.loc[trait].notna().any())
169
+ is_trait_biased_py = bool(is_trait_biased)
170
+ note = "INFO: Probes mapped to GENE_SYMBOL; WS and controls coded as 0, ASD as 1; whole blood samples."
171
+
172
+ is_usable = validate_and_save_cohort_info(
173
+ is_final=True,
174
+ cohort=cohort,
175
+ info_path=json_path,
176
+ is_gene_available=is_gene_available_final,
177
+ is_trait_available=is_trait_available_final,
178
+ is_biased=is_trait_biased_py,
179
+ df=unbiased_linked_data,
180
+ note=note
181
+ )
182
+
183
+ # 6. Save linked data if usable
184
+ if bool(is_usable):
185
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
186
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Autism_spectrum_disorder_(ASD)/code/TCGA.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autism_spectrum_disorder_(ASD)"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/TCGA.csv"
12
+ out_gene_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/clinical_data/TCGA.csv"
14
+ json_path = "./output/z1/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json"
15
+
16
+
17
+ # Step 1: Initial Data Loading
18
+ import os
19
+ import re
20
+ import pandas as pd
21
+
22
+ # Step 1: Find the most appropriate TCGA cohort for Autism Spectrum Disorder (ASD)
23
+ subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
24
+ trait_synonyms = ["autism", "asd", "autistic", "neurodevelopmental", "neuro-developmental"]
25
+
26
+ def normalize_text(s: str) -> str:
27
+ return re.sub(r'[^a-z0-9]+', ' ', s.lower())
28
+
29
+ def score_dir(name: str, synonyms) -> int:
30
+ n = normalize_text(name)
31
+ return sum(1 for syn in synonyms if syn in n)
32
+
33
+ scored = [(d, score_dir(d, trait_synonyms)) for d in subdirs]
34
+ # Select directory with highest score > 0
35
+ scored.sort(key=lambda x: x[1], reverse=True)
36
+ selected_dir = scored[0][0] if scored and scored[0][1] > 0 else None
37
+
38
+ if selected_dir is None:
39
+ print("No suitable TCGA cohort found for the trait 'Autism Spectrum Disorder (ASD)'. Skipping this trait.")
40
+ # Record unusable dataset at initial filtering stage
41
+ validate_and_save_cohort_info(
42
+ is_final=False,
43
+ cohort="TCGA",
44
+ info_path=json_path,
45
+ is_gene_available=False,
46
+ is_trait_available=False
47
+ )
48
+ else:
49
+ print(f"Selected TCGA cohort directory: {selected_dir}")
50
+ cohort_dir = os.path.join(tcga_root_dir, selected_dir)
51
+
52
+ # Step 2: Identify clinical and genetic file paths
53
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
54
+ print(f"Clinical file: {clinical_file_path}")
55
+ print(f"Genetic file: {genetic_file_path}")
56
+
57
+ # Step 3: Load both files as DataFrames
58
+ clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False)
59
+ genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False)
60
+
61
+ # Step 4: Print column names of the clinical data
62
+ print("Clinical data columns:")
63
+ print(list(clinical_df.columns))
output/preprocess/Autism_spectrum_disorder_(ASD)/cohort_info.json CHANGED
@@ -1,102 +1 @@
1
- {
2
- "GSE89594": {
3
- "is_usable": true,
4
- "is_gene_available": true,
5
- "is_trait_available": true,
6
- "is_available": true,
7
- "is_biased": false,
8
- "has_age": true,
9
- "has_gender": true,
10
- "sample_size": 62
11
- },
12
- "GSE87847": {
13
- "is_usable": true,
14
- "is_gene_available": true,
15
- "is_trait_available": true,
16
- "is_available": true,
17
- "is_biased": false,
18
- "has_age": false,
19
- "has_gender": false,
20
- "sample_size": 93
21
- },
22
- "GSE65106": {
23
- "is_usable": true,
24
- "is_gene_available": true,
25
- "is_trait_available": true,
26
- "is_available": true,
27
- "is_biased": false,
28
- "has_age": true,
29
- "has_gender": false,
30
- "sample_size": 59
31
- },
32
- "GSE57802": {
33
- "is_usable": true,
34
- "is_gene_available": true,
35
- "is_trait_available": true,
36
- "is_available": true,
37
- "is_biased": false,
38
- "has_age": true,
39
- "has_gender": true,
40
- "sample_size": 99
41
- },
42
- "GSE42133": {
43
- "is_usable": true,
44
- "is_gene_available": true,
45
- "is_trait_available": true,
46
- "is_available": true,
47
- "is_biased": false,
48
- "has_age": false,
49
- "has_gender": false,
50
- "sample_size": 147
51
- },
52
- "GSE285666": {
53
- "is_usable": true,
54
- "is_gene_available": true,
55
- "is_trait_available": true,
56
- "is_available": true,
57
- "is_biased": false,
58
- "has_age": false,
59
- "has_gender": false,
60
- "sample_size": 52
61
- },
62
- "GSE148450": {
63
- "is_usable": true,
64
- "is_gene_available": true,
65
- "is_trait_available": true,
66
- "is_available": true,
67
- "is_biased": false,
68
- "has_age": false,
69
- "has_gender": true,
70
- "sample_size": 159
71
- },
72
- "GSE123302": {
73
- "is_usable": false,
74
- "is_gene_available": false,
75
- "is_trait_available": false,
76
- "is_available": false,
77
- "is_biased": null,
78
- "has_age": null,
79
- "has_gender": null,
80
- "sample_size": null
81
- },
82
- "GSE111175": {
83
- "is_usable": true,
84
- "is_gene_available": true,
85
- "is_trait_available": true,
86
- "is_available": true,
87
- "is_biased": false,
88
- "has_age": false,
89
- "has_gender": false,
90
- "sample_size": 140
91
- },
92
- "TCGA": {
93
- "is_usable": false,
94
- "is_gene_available": false,
95
- "is_trait_available": false,
96
- "is_available": false,
97
- "is_biased": null,
98
- "has_age": null,
99
- "has_gender": null,
100
- "sample_size": null
101
- }
102
- }
 
1
+ {"GSE89594": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 94, "note": "INFO: Probes mapped to GENE_SYMBOL; WS and controls coded as 0, ASD as 1; whole blood samples."}, "GSE87847": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": true, "sample_size": 93, "note": "INFO: Age not provided; Gender available; gene symbols normalized via NCBI synonyms."}, "GSE65106": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": false, "sample_size": 59, "note": ""}, "GSE57802": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "INFO: Trait variable is not available in sample characteristics; linking clinical and gene data was skipped. Only gene expression matrix was processed and saved."}, "GSE42133": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 147, "note": "INFO: Age and Gender not available/usable in clinical data."}, "GSE285666": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "INFO: ASD trait not available in this series (dataset contrasts Williams syndrome vs parental controls). Only gene expression data were normalized and saved."}, "GSE148450": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": true, "sample_size": 159, "note": "INFO: Trait conversion retained ASD vs TD; Non-TD samples were set to missing and dropped during QC."}, "GSE123302": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": true, "sample_size": 224, "note": "WARNING: Gene symbol mapping unavailable; using probe-level identifiers without normalization."}, "GSE113842": {"is_usable": false, "is_gene_available": false, "is_trait_available": true, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "WARNING: Normalized gene data is empty after mapping; possible species/platform mismatch (e.g., Mus musculus annotation). INFO: Gender not available in clinical annotations. DEBUG: Probe-annotation overlap=49372/49372; normalized gene rows=0."}, "GSE111175": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": false, "sample_size": 141, "note": "INFO: Gender unavailable/constant (all male) per series; Age recorded in months; Probe IDs mapped to gene symbols and normalized via NCBI synonyms."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
output/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE113842.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ Gene,GSM3120900,GSM3120901,GSM3120902,GSM3120903,GSM3120904,GSM3120905,GSM3120906,GSM3120907,GSM3120908,GSM3120909,GSM3120910,GSM3120911,GSM3120912,GSM3120913,GSM3120914,GSM3120915,GSM3120916,GSM3120917,GSM3120918,GSM3120919,GSM3120920,GSM3120921,GSM3120922,GSM3120923,GSM3120924,GSM3120925,GSM3120926
output/preprocess/Autoinflammatory_Disorders/clinical_data/GSE43553.csv CHANGED
@@ -1,2 +1,2 @@
1
  ,GSM1065191,GSM1065192,GSM1065193,GSM1065194,GSM1065195,GSM1065196,GSM1065197,GSM1065198,GSM1065199,GSM1065200,GSM1065201,GSM1065202,GSM1065203,GSM1065204,GSM1065205,GSM1065206,GSM1065207,GSM1065208,GSM1065209,GSM1065210,GSM1065211,GSM1065212,GSM1065213,GSM1065214,GSM1065215,GSM1065216,GSM1065217,GSM1065218,GSM1065219,GSM1065220,GSM1065221,GSM1065222,GSM1065223,GSM1065224,GSM1065225,GSM1065226,GSM1065227,GSM1065228,GSM1065229,GSM1065230,GSM1065231,GSM1065232,GSM1065233,GSM1065234,GSM1065235,GSM1065236,GSM1065237,GSM1065238,GSM1065239,GSM1065240,GSM1065241,GSM1065242,GSM1065243,GSM1065244,GSM1065245,GSM1065246,GSM1065247,GSM1065248,GSM1065249,GSM1065250,GSM1065251,GSM1065252,GSM1065253,GSM1065254,GSM1065255,GSM1065256,GSM1065257,GSM1065258,GSM1065259,GSM1065260,GSM1065261,GSM1065262,GSM1065263,GSM1065264,GSM1065265,GSM1065266,GSM1065267,GSM1065268,GSM1065269,GSM1065270,GSM1065271,GSM1065272,GSM1065273,GSM1065274,GSM1065275,GSM1065276,GSM1065277,GSM1065278,GSM1065279,GSM1065280,GSM1065281,GSM1065282,GSM1065283,GSM1065284,GSM1065285,GSM1065286,GSM1065287,GSM1065288,GSM1065289,GSM1065290
2
- Autoinflammatory_Disorders,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,,,,,,,,,,,,,,,,,,,,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,,,,,,,,,,,,,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
 
1
  ,GSM1065191,GSM1065192,GSM1065193,GSM1065194,GSM1065195,GSM1065196,GSM1065197,GSM1065198,GSM1065199,GSM1065200,GSM1065201,GSM1065202,GSM1065203,GSM1065204,GSM1065205,GSM1065206,GSM1065207,GSM1065208,GSM1065209,GSM1065210,GSM1065211,GSM1065212,GSM1065213,GSM1065214,GSM1065215,GSM1065216,GSM1065217,GSM1065218,GSM1065219,GSM1065220,GSM1065221,GSM1065222,GSM1065223,GSM1065224,GSM1065225,GSM1065226,GSM1065227,GSM1065228,GSM1065229,GSM1065230,GSM1065231,GSM1065232,GSM1065233,GSM1065234,GSM1065235,GSM1065236,GSM1065237,GSM1065238,GSM1065239,GSM1065240,GSM1065241,GSM1065242,GSM1065243,GSM1065244,GSM1065245,GSM1065246,GSM1065247,GSM1065248,GSM1065249,GSM1065250,GSM1065251,GSM1065252,GSM1065253,GSM1065254,GSM1065255,GSM1065256,GSM1065257,GSM1065258,GSM1065259,GSM1065260,GSM1065261,GSM1065262,GSM1065263,GSM1065264,GSM1065265,GSM1065266,GSM1065267,GSM1065268,GSM1065269,GSM1065270,GSM1065271,GSM1065272,GSM1065273,GSM1065274,GSM1065275,GSM1065276,GSM1065277,GSM1065278,GSM1065279,GSM1065280,GSM1065281,GSM1065282,GSM1065283,GSM1065284,GSM1065285,GSM1065286,GSM1065287,GSM1065288,GSM1065289,GSM1065290
2
+ Autoinflammatory_Disorders,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
output/preprocess/Autoinflammatory_Disorders/clinical_data/GSE80060.csv CHANGED
@@ -1,2 +1,2 @@
1
- feature_0,feature_1,feature_2,feature_3,feature_4,feature_5
2
- ,0.0,1.0,,,
 
1
+ ,GSM2111993,GSM2111994,GSM2111995,GSM2111996,GSM2111997,GSM2111998,GSM2111999,GSM2112000,GSM2112001,GSM2112002,GSM2112003,GSM2112004,GSM2112005,GSM2112006,GSM2112007,GSM2112008,GSM2112009,GSM2112010,GSM2112011,GSM2112012,GSM2112013,GSM2112014,GSM2112015,GSM2112016,GSM2112017,GSM2112018,GSM2112019,GSM2112020,GSM2112021,GSM2112022,GSM2112023,GSM2112024,GSM2112025,GSM2112026,GSM2112027,GSM2112028,GSM2112029,GSM2112030,GSM2112031,GSM2112032,GSM2112033,GSM2112034,GSM2112035,GSM2112036,GSM2112037,GSM2112038,GSM2112039,GSM2112040,GSM2112041,GSM2112042,GSM2112043,GSM2112044,GSM2112045,GSM2112046,GSM2112047,GSM2112048,GSM2112049,GSM2112050,GSM2112051,GSM2112052,GSM2112053,GSM2112054,GSM2112055,GSM2112056,GSM2112057,GSM2112058,GSM2112059,GSM2112060,GSM2112061,GSM2112062,GSM2112063,GSM2112064,GSM2112065,GSM2112066,GSM2112067,GSM2112068,GSM2112069,GSM2112070,GSM2112071,GSM2112072,GSM2112073,GSM2112074,GSM2112075,GSM2112076,GSM2112077,GSM2112078,GSM2112079,GSM2112080,GSM2112081,GSM2112082,GSM2112083,GSM2112084,GSM2112085,GSM2112086,GSM2112087,GSM2112088,GSM2112089,GSM2112090,GSM2112091,GSM2112092,GSM2112093,GSM2112094,GSM2112095,GSM2112096,GSM2112097,GSM2112098,GSM2112099,GSM2112100,GSM2112101,GSM2112102,GSM2112103,GSM2112104,GSM2112105,GSM2112106,GSM2112107,GSM2112108,GSM2112109,GSM2112110,GSM2112111,GSM2112112,GSM2112113,GSM2112114,GSM2112115,GSM2112116,GSM2112117,GSM2112118,GSM2112119,GSM2112120,GSM2112121,GSM2112122,GSM2112123,GSM2112124,GSM2112125,GSM2112126,GSM2112127,GSM2112128,GSM2112129,GSM2112130,GSM2112131,GSM2112132,GSM2112133,GSM2112134,GSM2112135,GSM2112136,GSM2112137,GSM2112138,GSM2112139,GSM2112140,GSM2112141,GSM2112142,GSM2112143,GSM2112144,GSM2112145,GSM2112146,GSM2112147,GSM2112148,GSM2112149,GSM2112150,GSM2112151,GSM2112152,GSM2112153,GSM2112154,GSM2112155,GSM2112156,GSM2112157,GSM2112158,GSM2112159,GSM2112160,GSM2112161,GSM2112162,GSM2112163,GSM2112164,GSM2112165,GSM2112166,GSM2112167,GSM2112168,GSM2112169,GSM2112170,GSM2112171,GSM2112172,GSM2112173,GSM2112174,GSM2112175,GSM2112176,GSM2112177,GSM2112178,GSM2112179,GSM2112180,GSM2112181,GSM2112182,GSM2112183,GSM2112184,GSM2112185,GSM2112186,GSM2112187,GSM2112188,GSM2112189,GSM2112190,GSM2112191,GSM2112192,GSM2112193,GSM2112194,GSM2112195,GSM2112196,GSM2112197,GSM2112198
2
+ Autoinflammatory_Disorders,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0
output/preprocess/Autoinflammatory_Disorders/code/GSE43553.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autoinflammatory_Disorders"
6
+ cohort = "GSE43553"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autoinflammatory_Disorders"
10
+ in_cohort_dir = "../DATA/GEO/Autoinflammatory_Disorders/GSE43553"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/GSE43553.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/gene_data/GSE43553.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/clinical_data/GSE43553.csv"
16
+ json_path = "./output/z1/preprocess/Autoinflammatory_Disorders/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import pandas as pd
41
+
42
+ # 1) Gene expression availability
43
+ is_gene_available = True # Microarray-based gene expression profiling stated in background
44
+
45
+ # 2) Variable availability and converters
46
+ # Based on Sample Characteristics Dictionary:
47
+ # - Use key 1 ('genotype: ...') to infer Autoinflammatory_Disorders vs healthy controls
48
+ trait_row = 1
49
+ age_row = None
50
+ gender_row = None
51
+
52
+ def _after_colon(value):
53
+ if pd.isna(value):
54
+ return None
55
+ s = str(value)
56
+ parts = s.split(":", 1)
57
+ v = parts[1] if len(parts) > 1 else parts[0]
58
+ v = v.strip()
59
+ return v if v else None
60
+
61
+ def convert_trait(value):
62
+ v = _after_colon(value)
63
+ if v is None:
64
+ return None
65
+ vl = v.lower()
66
+ # Controls
67
+ if "healthy" in vl or "control" in vl:
68
+ return 0
69
+ # Known autoinflammatory-related genotype descriptors
70
+ keywords = ["mutation", "carrier", "mvk", "nlrp3", "pstpip1", "tnfrsf1a"]
71
+ if any(k in vl for k in keywords):
72
+ return 1
73
+ # Default to case if genotype is not explicitly healthy/control
74
+ return 1
75
+
76
+ def convert_age(value):
77
+ return None
78
+
79
+ def convert_gender(value):
80
+ return None
81
+
82
+ # 3) Initial filtering metadata save
83
+ is_trait_available = trait_row is not None
84
+ _ = validate_and_save_cohort_info(
85
+ is_final=False,
86
+ cohort=cohort,
87
+ info_path=json_path,
88
+ is_gene_available=is_gene_available,
89
+ is_trait_available=is_trait_available
90
+ )
91
+
92
+ # 4) Clinical feature extraction (only if trait is available)
93
+ if trait_row is not None:
94
+ selected_clinical_df = geo_select_clinical_features(
95
+ clinical_df=clinical_data,
96
+ trait=trait,
97
+ trait_row=trait_row,
98
+ convert_trait=convert_trait,
99
+ age_row=age_row,
100
+ convert_age=convert_age,
101
+ gender_row=gender_row,
102
+ convert_gender=convert_gender
103
+ )
104
+ preview = preview_df(selected_clinical_df)
105
+ print(preview)
106
+
107
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
108
+ selected_clinical_df.to_csv(out_clinical_data_file)
109
+
110
+ # Step 3: Gene Data Extraction
111
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
112
+ gene_data = get_genetic_data(matrix_file)
113
+
114
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
115
+ print(gene_data.index[:20])
116
+
117
+ # Step 4: Gene Identifier Review
118
+ requires_gene_mapping = True
119
+ print("requires_gene_mapping = True")
120
+
121
+ # Step 5: Gene Annotation
122
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
123
+ gene_annotation = get_gene_annotation(soft_file)
124
+
125
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
126
+ print("Gene annotation preview:")
127
+ print(preview_df(gene_annotation))
128
+
129
+ # Step 6: Gene Identifier Mapping
130
+ # 1-2. Identify the appropriate columns for probe IDs and gene symbols, then create the mapping dataframe
131
+ # From the annotation preview, probe IDs are in 'ID' and gene symbols are in 'Gene Symbol'
132
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
133
+
134
+ # 3. Apply the mapping to convert probe-level data to gene-level expression
135
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
136
+
137
+ # Step 7: Data Normalization and Linking
138
+ import os
139
+ import pandas as pd
140
+
141
+ # 1) Normalize gene symbols and save
142
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
143
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
144
+ normalized_gene_data.to_csv(out_gene_data_file)
145
+
146
+ # Ensure clinical data is available (reuse in-memory or reload from disk)
147
+ try:
148
+ selected_clinical_df
149
+ except NameError:
150
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
151
+
152
+ # 2) Link clinical and genetic data
153
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
154
+
155
+ # 3) Handle missing values
156
+ linked_data = handle_missing_values(linked_data, trait)
157
+
158
+ # 4) Bias assessment and removal of biased demographic features
159
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
160
+
161
+ # Availability flags
162
+ is_gene_available = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
163
+ is_trait_available = bool((trait in linked_data.columns) and (linked_data[trait].notna().sum() > 0))
164
+
165
+ # Prepare a brief note
166
+ try:
167
+ trait_counts = linked_data[trait].value_counts(dropna=True).to_dict()
168
+ except Exception:
169
+ trait_counts = {}
170
+ note = (
171
+ f"INFO: Post-QC samples={len(unbiased_linked_data)}; "
172
+ f"trait_counts={trait_counts}; "
173
+ f"has_age={'Age' in linked_data.columns}; "
174
+ f"has_gender={'Gender' in linked_data.columns}."
175
+ )
176
+
177
+ # 5) Final validation and save cohort info
178
+ # Ensure df has plain string column names to avoid any non-serializable types downstream
179
+ df_for_validation = unbiased_linked_data.copy()
180
+ df_for_validation.columns = [str(c) for c in list(df_for_validation.columns)]
181
+
182
+ is_usable = validate_and_save_cohort_info(
183
+ is_final=True,
184
+ cohort=cohort,
185
+ info_path=json_path,
186
+ is_gene_available=bool(is_gene_available),
187
+ is_trait_available=bool(is_trait_available),
188
+ is_biased=bool(is_trait_biased),
189
+ df=df_for_validation,
190
+ note=note
191
+ )
192
+
193
+ # 6) Save linked data if usable
194
+ if is_usable:
195
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
196
+ df_for_validation.to_csv(out_data_file)
output/preprocess/Autoinflammatory_Disorders/code/GSE80060.py ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autoinflammatory_Disorders"
6
+ cohort = "GSE80060"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Autoinflammatory_Disorders"
10
+ in_cohort_dir = "../DATA/GEO/Autoinflammatory_Disorders/GSE80060"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/GSE80060.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/gene_data/GSE80060.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/clinical_data/GSE80060.csv"
16
+ json_path = "./output/z1/preprocess/Autoinflammatory_Disorders/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+ import pandas as pd
42
+
43
+ # 1) Gene expression data availability
44
+ is_gene_available = True # Title indicates "Gene expression data"; not miRNA/methylation
45
+
46
+ # 2) Variable availability
47
+ # From Sample Characteristics Dictionary:
48
+ # 1: ['disease status: SJIA', 'disease status: Healthy'] -> maps to our trait (Autoinflammatory_Disorders)
49
+ trait_row = 1
50
+ age_row = None # No age field found
51
+ gender_row = None # No gender field found
52
+
53
+ # 2.2) Converters
54
+ def _after_colon(value: str) -> str:
55
+ s = str(value)
56
+ if ':' in s:
57
+ s = s.split(':', 1)[1]
58
+ return s.strip()
59
+
60
+ def convert_trait(value):
61
+ if pd.isna(value):
62
+ return None
63
+ v = _after_colon(value).lower()
64
+ # Heuristics: SJIA is an autoinflammatory disease -> 1; Healthy/Control -> 0
65
+ if 'sjia' in v or ('patient' in v and 'healthy' not in v):
66
+ return 1
67
+ if 'healthy' in v or 'control' in v or v == 'normal':
68
+ return 0
69
+ return None
70
+
71
+ def convert_age(value):
72
+ if pd.isna(value):
73
+ return None
74
+ v = _after_colon(value).strip()
75
+ if v == '' or v.lower() in {'na', 'n/a', 'nan', 'none', 'unknown'}:
76
+ return None
77
+ # Try direct float
78
+ try:
79
+ return float(v)
80
+ except Exception:
81
+ pass
82
+ low = v.lower()
83
+ m = re.search(r'(\d+(\.\d+)?)', low)
84
+ if not m:
85
+ return None
86
+ num = float(m.group(1))
87
+ # Convert to years if units provided
88
+ if 'month' in low or re.search(r'\bmo\b', low):
89
+ return round(num / 12.0, 3)
90
+ if 'week' in low or re.search(r'\bwk\b', low):
91
+ return round(num / 52.0, 3)
92
+ if 'day' in low or re.search(r'\bd\b', low):
93
+ return round(num / 365.0, 3)
94
+ return num # assume years
95
+
96
+ def convert_gender(value):
97
+ if pd.isna(value):
98
+ return None
99
+ v = _after_colon(value).strip().lower()
100
+ if v in {'m', 'male'} or 'male' in v or 'man' in v or 'boy' in v:
101
+ return 1
102
+ if v in {'f', 'female'} or 'female' in v or 'woman' in v or 'girl' in v:
103
+ return 0
104
+ return None
105
+
106
+ # 3) Save metadata (initial filtering)
107
+ is_trait_available = trait_row is not None
108
+ _ = validate_and_save_cohort_info(
109
+ is_final=False,
110
+ cohort=cohort,
111
+ info_path=json_path,
112
+ is_gene_available=is_gene_available,
113
+ is_trait_available=is_trait_available
114
+ )
115
+
116
+ # 4) Clinical Feature Extraction (only if trait_row is available)
117
+ if trait_row is not None:
118
+ selected_clinical_df = geo_select_clinical_features(
119
+ clinical_df=clinical_data,
120
+ trait=trait,
121
+ trait_row=trait_row,
122
+ convert_trait=convert_trait,
123
+ age_row=age_row,
124
+ convert_age=convert_age,
125
+ gender_row=gender_row,
126
+ convert_gender=convert_gender
127
+ )
128
+ preview = preview_df(selected_clinical_df)
129
+ print("Preview of selected clinical features:", preview)
130
+
131
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
132
+ selected_clinical_df.to_csv(out_clinical_data_file)
133
+
134
+ # Step 3: Gene Data Extraction
135
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
136
+ gene_data = get_genetic_data(matrix_file)
137
+
138
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
139
+ print(gene_data.index[:20])
140
+
141
+ # Step 4: Gene Identifier Review
142
+ print("requires_gene_mapping = True")
143
+
144
+ # Step 5: Gene Annotation
145
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
146
+ gene_annotation = get_gene_annotation(soft_file)
147
+
148
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
149
+ print("Gene annotation preview:")
150
+ print(preview_df(gene_annotation))
151
+
152
+ # Step 6: Gene Identifier Mapping
153
+ # Identify the columns for probe IDs and gene symbols based on the annotation preview
154
+ probe_col = 'ID' # matches probe identifiers like '1007_s_at'
155
+ gene_symbol_col = 'Gene Symbol' # contains gene symbols (may include multiple per probe)
156
+
157
+ # Build mapping dataframe
158
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
159
+
160
+ # Apply mapping to convert probe-level data to gene-level expression
161
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
162
+
163
+ # Step 7: Data Normalization and Linking
164
+ import os
165
+
166
+ # 1. Normalize gene symbols and save gene expression data
167
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
168
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
169
+ normalized_gene_data.to_csv(out_gene_data_file)
170
+
171
+ # 2. Link clinical and genetic data (use the correct variable from Step 2)
172
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
173
+
174
+ # Derive availability flags based on current data state and cast to built-in bool
175
+ is_gene_available = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
176
+ is_trait_available = bool((trait in linked_data.columns) and (linked_data[trait].notna().sum() > 0))
177
+
178
+ # 3. Handle missing values
179
+ linked_data = handle_missing_values(linked_data, trait)
180
+
181
+ # 4. Determine biases and remove biased demographic features
182
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
183
+ is_trait_biased = bool(is_trait_biased)
184
+
185
+ # 5. Final quality validation and save cohort info
186
+ covariate_cols = [trait, 'Age', 'Gender']
187
+ gene_cols_in_final = [c for c in unbiased_linked_data.columns if c not in covariate_cols]
188
+ sample_count = int(len(unbiased_linked_data))
189
+ gene_count = int(len(gene_cols_in_final))
190
+ note = (
191
+ f"INFO: Normalized Affymetrix probe data to gene symbols using NCBI synonyms. "
192
+ f"Clinical features available: trait only; Age/Gender not provided. "
193
+ f"Post-QC samples: {sample_count}; genes: {gene_count}."
194
+ )
195
+ is_usable = validate_and_save_cohort_info(
196
+ is_final=True,
197
+ cohort=cohort,
198
+ info_path=json_path,
199
+ is_gene_available=bool(is_gene_available),
200
+ is_trait_available=bool(is_trait_available),
201
+ is_biased=bool(is_trait_biased),
202
+ df=unbiased_linked_data,
203
+ note=note
204
+ )
205
+
206
+ # 6. Save linked data if usable
207
+ if is_usable:
208
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
209
+ unbiased_linked_data.to_csv(out_data_file)
210
+ print(f"Saved processed cohort to {out_data_file}")
211
+ print(f"Saved gene data to {out_gene_data_file}")
output/preprocess/Autoinflammatory_Disorders/code/TCGA.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Autoinflammatory_Disorders"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/TCGA.csv"
12
+ out_gene_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/clinical_data/TCGA.csv"
14
+ json_path = "./output/z1/preprocess/Autoinflammatory_Disorders/cohort_info.json"
15
+
16
+
17
+ # Step 1: Initial Data Loading
18
+ import os
19
+ import pandas as pd
20
+
21
+ # Discover available TCGA cohort directories
22
+ available_dirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
23
+
24
+ # Try to find a TCGA cohort relevant to Autoinflammatory Disorders (unlikely among cancer cohorts)
25
+ keywords = [
26
+ "autoinflammatory", "auto-inflammatory", "autoinflammation", "autoinflamm",
27
+ "periodic_fever", "periodic-fever", "fmf", "traps", "hids", "caps", "nlrp", "inflam"
28
+ ]
29
+ matches = []
30
+ for d in available_dirs:
31
+ name_l = d.lower()
32
+ score = sum(1 for k in keywords if k in name_l)
33
+ if score > 0:
34
+ # Prefer more keyword hits and shorter names (more specific)
35
+ matches.append((score, -len(d), d))
36
+
37
+ if not matches:
38
+ # No suitable TCGA cohort for autoinflammatory disorders; record and skip
39
+ validate_and_save_cohort_info(
40
+ is_final=False,
41
+ cohort="TCGA",
42
+ info_path=json_path,
43
+ is_gene_available=False,
44
+ is_trait_available=False
45
+ )
46
+ selected_dir = None
47
+ clinical_df = pd.DataFrame()
48
+ genetic_df = pd.DataFrame()
49
+ else:
50
+ # Select the best match
51
+ matches.sort(reverse=True)
52
+ selected_dir = matches[0][2]
53
+
54
+ if selected_dir:
55
+ cohort_dir = os.path.join(tcga_root_dir, selected_dir)
56
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
57
+
58
+ clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, compression='infer', low_memory=False)
59
+ genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, compression='infer', low_memory=False)
60
+
61
+ print(list(clinical_df.columns))
62
+
63
+ # Step 2: Initial Data Loading
64
+ import os
65
+ import pandas as pd
66
+
67
+ # Use the provided list of subdirectories but ensure they exist on disk
68
+ provided_subdirs = [
69
+ 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)', 'TCGA_Uterine_Carcinosarcoma_(UCS)',
70
+ 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)', 'TCGA_Testicular_Cancer_(TGCT)',
71
+ 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)', 'TCGA_Rectal_Cancer_(READ)',
72
+ 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
73
+ 'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
74
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
75
+ 'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
76
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)',
77
+ 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)', 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)',
78
+ 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)', 'TCGA_Glioblastoma_(GBM)',
79
+ 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)', 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)',
80
+ 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)', 'TCGA_Breast_Cancer_(BRCA)',
81
+ 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)', 'TCGA_Adrenocortical_Cancer_(ACC)',
82
+ 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
83
+ ]
84
+ available_dirs = [d for d in provided_subdirs if os.path.isdir(os.path.join(tcga_root_dir, d))]
85
+
86
+ # Search for directories matching autoinflammatory disorders (unlikely in TCGA cancer cohorts)
87
+ keywords = [
88
+ "autoinflammatory", "auto-inflammatory", "autoinflammation", "autoinflamm",
89
+ "periodic_fever", "periodic-fever", "fmf", "traps", "hids", "caps", "nlrp", "inflam"
90
+ ]
91
+ matches = []
92
+ for d in available_dirs:
93
+ name_l = d.lower()
94
+ score = sum(1 for k in keywords if k in name_l)
95
+ if score > 0:
96
+ matches.append((score, -len(d), d))
97
+
98
+ if not matches:
99
+ # No suitable TCGA cohort for Autoinflammatory Disorders; record and skip
100
+ validate_and_save_cohort_info(
101
+ is_final=False,
102
+ cohort="TCGA",
103
+ info_path=json_path,
104
+ is_gene_available=False,
105
+ is_trait_available=False
106
+ )
107
+ selected_dir = None
108
+ clinical_df = pd.DataFrame()
109
+ genetic_df = pd.DataFrame()
110
+ else:
111
+ # Select the most specific match (more keywords, shorter name)
112
+ matches.sort(reverse=True)
113
+ selected_dir = matches[0][2]
114
+
115
+ # If a directory was selected, locate files and load data
116
+ if selected_dir:
117
+ cohort_dir = os.path.join(tcga_root_dir, selected_dir)
118
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
119
+
120
+ clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, compression='infer', low_memory=False)
121
+ genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, compression='infer', low_memory=False)
122
+
123
+ print(list(clinical_df.columns))
output/preprocess/Autoinflammatory_Disorders/cohort_info.json CHANGED
@@ -1,32 +1 @@
1
- {
2
- "GSE80060": {
3
- "is_usable": false,
4
- "is_gene_available": false,
5
- "is_trait_available": false,
6
- "is_available": false,
7
- "is_biased": null,
8
- "has_age": null,
9
- "has_gender": null,
10
- "sample_size": null
11
- },
12
- "GSE43553": {
13
- "is_usable": true,
14
- "is_gene_available": true,
15
- "is_trait_available": true,
16
- "is_available": true,
17
- "is_biased": false,
18
- "has_age": false,
19
- "has_gender": false,
20
- "sample_size": 66
21
- },
22
- "TCGA": {
23
- "is_usable": false,
24
- "is_gene_available": true,
25
- "is_trait_available": true,
26
- "is_available": true,
27
- "is_biased": true,
28
- "has_age": true,
29
- "has_gender": true,
30
- "sample_size": 48
31
- }
32
- }
 
1
+ {"GSE80060": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 206, "note": "INFO: Normalized Affymetrix probe data to gene symbols using NCBI synonyms. Clinical features available: trait only; Age/Gender not provided. Post-QC samples: 206; genes: 19845."}, "GSE43553": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 100, "note": "INFO: Post-QC samples=100; trait_counts={1.0: 66, 0.0: 34}; has_age=False; has_gender=False."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
output/preprocess/Bile_Duct_Cancer/clinical_data/GSE107754.csv CHANGED
@@ -1,3 +1,3 @@
1
  ,GSM2878070,GSM2878071,GSM2878072,GSM2878073,GSM2878074,GSM2878075,GSM2878076,GSM2878077,GSM2878078,GSM2878079,GSM2878080,GSM2878081,GSM2878082,GSM2891194,GSM2891195,GSM2891196,GSM2891197,GSM2891198,GSM2891199,GSM2891200,GSM2891201,GSM2891202,GSM2891203,GSM2891204,GSM2891205,GSM2891206,GSM2891207,GSM2891208,GSM2891209,GSM2891210,GSM2891211,GSM2891212,GSM2891213,GSM2891214,GSM2891215,GSM2891216,GSM2891217,GSM2891218,GSM2891219,GSM2891220,GSM2891221,GSM2891222,GSM2891223,GSM2891224,GSM2891225,GSM2891226,GSM2891227,GSM2891228,GSM2891229,GSM2891230,GSM2891231,GSM2891232,GSM2891233,GSM2891234,GSM2891235,GSM2891236,GSM2891237,GSM2891238,GSM2891239,GSM2891240,GSM2891241,GSM2891242,GSM2891243,GSM2891244,GSM2891245,GSM2891246,GSM2891247,GSM2891248,GSM2891249,GSM2891250,GSM2891251,GSM2891252,GSM2891253,GSM2891254,GSM2891255,GSM2891256,GSM2891257,GSM2891258,GSM2891259,GSM2891260,GSM2891261,GSM2891262,GSM2891263,GSM2891264
2
- Bile_Duct_Cancer,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0
3
  Gender,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0
 
1
  ,GSM2878070,GSM2878071,GSM2878072,GSM2878073,GSM2878074,GSM2878075,GSM2878076,GSM2878077,GSM2878078,GSM2878079,GSM2878080,GSM2878081,GSM2878082,GSM2891194,GSM2891195,GSM2891196,GSM2891197,GSM2891198,GSM2891199,GSM2891200,GSM2891201,GSM2891202,GSM2891203,GSM2891204,GSM2891205,GSM2891206,GSM2891207,GSM2891208,GSM2891209,GSM2891210,GSM2891211,GSM2891212,GSM2891213,GSM2891214,GSM2891215,GSM2891216,GSM2891217,GSM2891218,GSM2891219,GSM2891220,GSM2891221,GSM2891222,GSM2891223,GSM2891224,GSM2891225,GSM2891226,GSM2891227,GSM2891228,GSM2891229,GSM2891230,GSM2891231,GSM2891232,GSM2891233,GSM2891234,GSM2891235,GSM2891236,GSM2891237,GSM2891238,GSM2891239,GSM2891240,GSM2891241,GSM2891242,GSM2891243,GSM2891244,GSM2891245,GSM2891246,GSM2891247,GSM2891248,GSM2891249,GSM2891250,GSM2891251,GSM2891252,GSM2891253,GSM2891254,GSM2891255,GSM2891256,GSM2891257,GSM2891258,GSM2891259,GSM2891260,GSM2891261,GSM2891262,GSM2891263,GSM2891264
2
+ Bile_Duct_Cancer,,,,,,,,,,,,,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0
3
  Gender,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0
output/preprocess/Bile_Duct_Cancer/clinical_data/GSE131027.csv CHANGED
@@ -1,2 +1,2 @@
1
- 0,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
2
- 0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,,,,,,
 
1
+ ,GSM3759992,GSM3759993,GSM3759994,GSM3759995,GSM3759996,GSM3759997,GSM3759998,GSM3759999,GSM3760000,GSM3760001,GSM3760002,GSM3760003,GSM3760004,GSM3760005,GSM3760006,GSM3760007,GSM3760008,GSM3760009,GSM3760010,GSM3760011,GSM3760012,GSM3760013,GSM3760014,GSM3760015,GSM3760016,GSM3760017,GSM3760018,GSM3760019,GSM3760020,GSM3760021,GSM3760022,GSM3760023,GSM3760024,GSM3760025,GSM3760026,GSM3760027,GSM3760028,GSM3760029,GSM3760030,GSM3760031,GSM3760032,GSM3760033,GSM3760034,GSM3760035,GSM3760036,GSM3760037,GSM3760038,GSM3760039,GSM3760040,GSM3760041,GSM3760042,GSM3760043,GSM3760044,GSM3760045,GSM3760046,GSM3760047,GSM3760048,GSM3760049,GSM3760050,GSM3760051,GSM3760052,GSM3760053,GSM3760054,GSM3760055,GSM3760056,GSM3760057,GSM3760058,GSM3760059,GSM3760060,GSM3760061,GSM3760062,GSM3760063,GSM3760064,GSM3760065,GSM3760066,GSM3760067,GSM3760068,GSM3760069,GSM3760070,GSM3760071,GSM3760072,GSM3760073,GSM3760074,GSM3760075,GSM3760076,GSM3760077,GSM3760078,GSM3760079,GSM3760080,GSM3760081,GSM3760082,GSM3760083
2
+ Bile_Duct_Cancer,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0
output/preprocess/Bile_Duct_Cancer/code/GSE107754.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bile_Duct_Cancer"
6
+ cohort = "GSE107754"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bile_Duct_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Bile_Duct_Cancer/GSE107754"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/GSE107754.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/gene_data/GSE107754.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/clinical_data/GSE107754.csv"
16
+ json_path = "./output/z1/preprocess/Bile_Duct_Cancer/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ # Step 1: Determine gene expression data availability based on background information
40
+ is_gene_available = True # Whole human genome gene expression microarrays are reported
41
+
42
+ # Step 2: Identify rows for trait, age, and gender from the Sample Characteristics Dictionary
43
+ trait_row = 2 # 'tissue: Bile duct cancer' appears here among other tissue types
44
+ age_row = None # No age information found
45
+ gender_row = 0 # 'gender: Female' and 'gender: Male' are present
46
+
47
+ # Step 2.2: Define conversion functions
48
+ def _after_colon(value):
49
+ if value is None:
50
+ return None
51
+ s = str(value)
52
+ if ':' in s:
53
+ key, val = s.split(':', 1)
54
+ return key.strip().lower(), val.strip()
55
+ return '', s.strip()
56
+
57
+ def convert_trait(value):
58
+ # Map to 1 if tissue is bile duct cancer, 0 if tissue is another cancer.
59
+ # If the field is not tissue (e.g., biopsy location), return None.
60
+ key, val = _after_colon(value)
61
+ val_l = val.lower()
62
+ if 'bile' in val_l and 'duct' in val_l:
63
+ return 1
64
+ if 'tissue' in key:
65
+ # Not bile duct tissue -> control (0)
66
+ return 0
67
+ # Unknown/irrelevant field for trait
68
+ return None
69
+
70
+ def convert_gender(value):
71
+ key, val = _after_colon(value)
72
+ v = val.lower()
73
+ if v in ['female', 'f']:
74
+ return 0
75
+ if v in ['male', 'm']:
76
+ return 1
77
+ return None
78
+
79
+ def convert_age(value):
80
+ # Not used as age_row is None; keep for completeness if needed later
81
+ key, val = _after_colon(value)
82
+ v = val.lower()
83
+ # Remove common non-numeric tokens
84
+ for token in ['years', 'year', 'yrs', 'yr', 'y', 'age', ' ']:
85
+ v = v.replace(token, '')
86
+ v = v.replace('+', '').replace('~', '').replace('about', '').strip()
87
+ try:
88
+ return float(v)
89
+ except Exception:
90
+ return None
91
+
92
+ # Step 3: Initial filtering and save metadata
93
+ is_trait_available = trait_row is not None
94
+ _ = validate_and_save_cohort_info(
95
+ is_final=False,
96
+ cohort=cohort,
97
+ info_path=json_path,
98
+ is_gene_available=is_gene_available,
99
+ is_trait_available=is_trait_available
100
+ )
101
+
102
+ # Step 4: Clinical Feature Extraction (only if trait is available)
103
+ if trait_row is not None:
104
+ import os
105
+
106
+ kwargs = {
107
+ "clinical_df": clinical_data,
108
+ "trait": trait,
109
+ "trait_row": trait_row,
110
+ "convert_trait": convert_trait
111
+ }
112
+ # Age not available; include gender
113
+ kwargs.update({
114
+ "gender_row": gender_row,
115
+ "convert_gender": convert_gender
116
+ })
117
+
118
+ selected_clinical_df = geo_select_clinical_features(**kwargs)
119
+
120
+ # Preview and save
121
+ preview = preview_df(selected_clinical_df)
122
+ print(preview)
123
+
124
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
125
+ selected_clinical_df.to_csv(out_clinical_data_file)
126
+
127
+ # Step 3: Gene Data Extraction
128
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
129
+ gene_data = get_genetic_data(matrix_file)
130
+
131
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
132
+ print(gene_data.index[:20])
133
+
134
+ # Step 4: Gene Identifier Review
135
+ print("requires_gene_mapping = True")
136
+
137
+ # Step 5: Gene Annotation
138
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
139
+ gene_annotation = get_gene_annotation(soft_file)
140
+
141
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
142
+ print("Gene annotation preview:")
143
+ print(preview_df(gene_annotation))
144
+
145
+ # Step 6: Gene Identifier Mapping
146
+ # Identify the columns for probe IDs and gene symbols based on the annotation preview
147
+ probe_col = 'ID'
148
+ gene_symbol_col = 'GENE_SYMBOL'
149
+
150
+ # Build mapping dataframe from annotation
151
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
152
+
153
+ # Apply mapping to convert probe-level data to gene-level expression
154
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
155
+
156
+ # Step 7: Data Normalization and Linking
157
+ import os
158
+
159
+ # 1. Normalize gene symbols and save
160
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
161
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
162
+ normalized_gene_data.to_csv(out_gene_data_file)
163
+
164
+ # 2. Link clinical and genetic data
165
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
166
+
167
+ # 3. Handle missing values
168
+ linked_data = handle_missing_values(linked_data, trait)
169
+
170
+ # 4. Assess bias and drop biased covariates
171
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
172
+
173
+ # 5. Final validation and save cohort info
174
+ note = ("INFO: Age unavailable; trait derived from 'tissue' field in sample characteristics; "
175
+ "samples without explicit tissue label were dropped during missing-value handling.")
176
+ is_usable = validate_and_save_cohort_info(
177
+ is_final=True,
178
+ cohort=cohort,
179
+ info_path=json_path,
180
+ is_gene_available=True,
181
+ is_trait_available=True,
182
+ is_biased=is_trait_biased,
183
+ df=unbiased_linked_data,
184
+ note=note
185
+ )
186
+
187
+ # 6. Save linked data only if usable
188
+ if is_usable:
189
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
190
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Bile_Duct_Cancer/code/GSE131027.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bile_Duct_Cancer"
6
+ cohort = "GSE131027"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bile_Duct_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Bile_Duct_Cancer/GSE131027"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/GSE131027.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/gene_data/GSE131027.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/clinical_data/GSE131027.csv"
16
+ json_path = "./output/z1/preprocess/Bile_Duct_Cancer/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+
42
+ # 1) Gene expression data availability
43
+ is_gene_available = True # Based on series design indicating expression features
44
+
45
+ # 2) Variable availability and converters
46
+ # From Sample Characteristics Dictionary:
47
+ # 0: tissue
48
+ # 1: cancer (contains 'Bile duct cancer')
49
+ # 2: mutated gene
50
+ # 3: predicted HRDEXP
51
+ # 4: parp predicted
52
+ trait_row = 1
53
+ age_row = None
54
+ gender_row = None
55
+
56
+ def _after_last_colon(x: str) -> str:
57
+ if x is None:
58
+ return ""
59
+ parts = str(x).split(":")
60
+ return parts[-1].strip().lower()
61
+
62
+ def convert_trait(x):
63
+ v = _after_last_colon(x)
64
+ if not v or v in {"na", "n/a", "unknown", "none"}:
65
+ return None
66
+ # Map bile duct cancer / cholangiocarcinoma to 1, others to 0
67
+ if "bile" in v and "duct" in v:
68
+ return 1
69
+ if "cholangiocarcinoma" in v:
70
+ return 1
71
+ # If it's any other cancer label, map to 0
72
+ return 0
73
+
74
+ def convert_age(x):
75
+ v = _after_last_colon(x)
76
+ if not v or v in {"na", "n/a", "unknown", "none"}:
77
+ return None
78
+ m = re.search(r"[-+]?\d*\.?\d+", v)
79
+ if m:
80
+ try:
81
+ return float(m.group())
82
+ except Exception:
83
+ return None
84
+ return None
85
+
86
+ def convert_gender(x):
87
+ v = _after_last_colon(x)
88
+ if not v:
89
+ return None
90
+ if v in {"female", "f", "woman", "women"}:
91
+ return 0
92
+ if v in {"male", "m", "man", "men"}:
93
+ return 1
94
+ return None
95
+
96
+ # 3) Save metadata (initial filtering)
97
+ is_trait_available = trait_row is not None
98
+ _ = validate_and_save_cohort_info(
99
+ is_final=False,
100
+ cohort=cohort,
101
+ info_path=json_path,
102
+ is_gene_available=is_gene_available,
103
+ is_trait_available=is_trait_available
104
+ )
105
+
106
+ # 4) Clinical feature extraction (only if trait is available)
107
+ if trait_row is not None:
108
+ selected_clinical_df = geo_select_clinical_features(
109
+ clinical_df=clinical_data,
110
+ trait=trait,
111
+ trait_row=trait_row,
112
+ convert_trait=convert_trait,
113
+ age_row=age_row,
114
+ convert_age=convert_age,
115
+ gender_row=gender_row,
116
+ convert_gender=convert_gender
117
+ )
118
+ clinical_preview = preview_df(selected_clinical_df)
119
+ # Save
120
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
121
+ selected_clinical_df.to_csv(out_clinical_data_file)
122
+
123
+ # Step 3: Gene Data Extraction
124
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
125
+ gene_data = get_genetic_data(matrix_file)
126
+
127
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
128
+ print(gene_data.index[:20])
129
+
130
+ # Step 4: Gene Identifier Review
131
+ requires_gene_mapping = True
132
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
133
+
134
+ # Step 5: Gene Annotation
135
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
136
+ gene_annotation = get_gene_annotation(soft_file)
137
+
138
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
139
+ print("Gene annotation preview:")
140
+ print(preview_df(gene_annotation))
141
+
142
+ # Step 6: Gene Identifier Mapping
143
+ # Identify columns for probe IDs and gene symbols in the annotation dataframe
144
+ probe_id_col = 'ID'
145
+ gene_symbol_col = 'Gene Symbol'
146
+
147
+ # Build mapping dataframe from annotation
148
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_id_col, gene_col=gene_symbol_col)
149
+
150
+ # Apply mapping to convert probe-level data to gene-level expression
151
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
152
+
153
+ # Step 7: Data Normalization and Linking
154
+ import os
155
+
156
+ # 1. Normalize gene symbols and save
157
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
158
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
159
+ normalized_gene_data.to_csv(out_gene_data_file)
160
+
161
+ # 2. Link clinical and genetic data
162
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
163
+
164
+ # 3. Handle missing values
165
+ linked_data = handle_missing_values(linked_data, trait)
166
+
167
+ # 4. Bias assessment
168
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
169
+
170
+ # 5. Final validation and save cohort info
171
+ # Ensure pure Python bools for JSON serialization
172
+ is_gene_available = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
173
+ is_trait_available = bool((trait in linked_data.columns) and (linked_data[trait].notna().sum() > 0))
174
+ is_trait_biased = bool(is_trait_biased)
175
+
176
+ # Defensive copy for any downstream processing; ensure string column names
177
+ df_to_save = unbiased_linked_data.copy()
178
+ df_to_save.columns = [str(c) for c in df_to_save.columns]
179
+
180
+ note = "INFO: Trait derived from cancer type; no age/gender available in series; probes mapped via 'Gene Symbol' and gene symbols normalized by NCBI synonym dictionary."
181
+
182
+ is_usable = validate_and_save_cohort_info(
183
+ is_final=True,
184
+ cohort=cohort,
185
+ info_path=json_path,
186
+ is_gene_available=is_gene_available,
187
+ is_trait_available=is_trait_available,
188
+ is_biased=is_trait_biased,
189
+ df=df_to_save,
190
+ note=note
191
+ )
192
+
193
+ # 6. Save linked data if usable
194
+ if is_usable:
195
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
196
+ df_to_save.to_csv(out_data_file)
output/preprocess/Bile_Duct_Cancer/code/TCGA.py ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bile_Duct_Cancer"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/TCGA.csv"
12
+ out_gene_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/z1/preprocess/Bile_Duct_Cancer/clinical_data/TCGA.csv"
14
+ json_path = "./output/z1/preprocess/Bile_Duct_Cancer/cohort_info.json"
15
+
16
+
17
+ # Step 1: Initial Data Loading
18
+ import os
19
+ import pandas as pd
20
+
21
+ # Find the most appropriate TCGA cohort directory for the trait
22
+ subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
23
+ lower_map = {d: d.lower() for d in subdirs}
24
+
25
+ # Prioritize exact trait phrase, then synonyms
26
+ selected_dir = None
27
+ exact_key = 'bile_duct_cancer'
28
+ synonym_keys = ['(chol', 'cholangio'] # CHOL code and cholangiocarcinoma keyword
29
+
30
+ # Exact match
31
+ candidates_exact = [d for d, dl in lower_map.items() if exact_key in dl]
32
+ if candidates_exact:
33
+ # Choose the most specific (shortest name) if multiple
34
+ selected_dir = sorted(candidates_exact, key=len)[0]
35
+ else:
36
+ # Synonym-based match
37
+ candidates_syn = [d for d, dl in lower_map.items() if any(k in dl for k in synonym_keys)]
38
+ if candidates_syn:
39
+ selected_dir = sorted(candidates_syn, key=len)[0]
40
+
41
+ if selected_dir is None:
42
+ # No suitable cohort found; mark and stop further processing in this step
43
+ validate_and_save_cohort_info(
44
+ is_final=False,
45
+ cohort="TCGA",
46
+ info_path=json_path,
47
+ is_gene_available=False,
48
+ is_trait_available=False
49
+ )
50
+ print("No suitable TCGA cohort found for the trait. Skipping.")
51
+ else:
52
+ tcga_cohort_dir = os.path.join(tcga_root_dir, selected_dir)
53
+ # Identify clinical and genetic file paths
54
+ tcga_clinical_file, tcga_genetic_file = tcga_get_relevant_filepaths(tcga_cohort_dir)
55
+
56
+ # Load dataframes
57
+ tcga_clinical_df = pd.read_csv(tcga_clinical_file, sep='\t', index_col=0, low_memory=False, compression='infer')
58
+ tcga_genetic_df = pd.read_csv(tcga_genetic_file, sep='\t', index_col=0, low_memory=False, compression='infer')
59
+
60
+ # Print clinical column names for further analysis
61
+ print(list(tcga_clinical_df.columns))
62
+
63
+ # Step 2: Find Candidate Demographic Features
64
+ import os
65
+ import pandas as pd
66
+
67
+ # Column names from the previous step
68
+ column_names = ['_INTEGRATION', '_PATIENT', '_cohort', '_primary_disease', '_primary_site', 'additional_pharmaceutical_therapy', 'additional_radiation_therapy', 'age_at_initial_pathologic_diagnosis', 'albumin_result_lower_limit', 'albumin_result_specified_value', 'albumin_result_upper_limit', 'bcr_followup_barcode', 'bcr_patient_barcode', 'bcr_sample_barcode', 'bilirubin_lower_limit', 'bilirubin_upper_limit', 'ca_19_9_level', 'ca_19_9_level_lower', 'ca_19_9_level_upper', 'cancer_first_degree_relative', 'child_pugh_classification_grade', 'cholangitis_tissue_evidence', 'creatinine_lower_level', 'creatinine_upper_limit', 'creatinine_value_in_mg_dl', 'days_to_birth', 'days_to_collection', 'days_to_death', 'days_to_initial_pathologic_diagnosis', 'days_to_last_followup', 'days_to_new_tumor_event_after_initial_treatment', 'eastern_cancer_oncology_group', 'family_cancer_type_txt', 'family_member_relationship_type', 'fetoprotein_outcome_lower_limit', 'fetoprotein_outcome_upper_limit', 'fetoprotein_outcome_value', 'fibrosis_ishak_score', 'form_completion_date', 'gender', 'height', 'hist_hepato_carc_fact', 'hist_hepato_carcinoma_risk', 'histological_type', 'history_of_neoadjuvant_treatment', 'icd_10', 'icd_o_3_histology', 'icd_o_3_site', 'informed_consent_verified', 'initial_weight', 'inter_norm_ratio_lower_limit', 'intern_norm_ratio_upper_limit', 'is_ffpe', 'lost_follow_up', 'neoplasm_histologic_grade', 'new_neoplasm_event_occurrence_anatomic_site', 'new_neoplasm_event_type', 'new_tumor_event_ablation_embo_tx', 'new_tumor_event_additional_surgery_procedure', 'new_tumor_event_after_initial_treatment', 'new_tumor_event_liver_transplant', 'oct_embedded', 'other_dx', 'pathologic_M', 'pathologic_N', 'pathologic_T', 'pathologic_stage', 'pathology_report_file_name', 'patient_id', 'perineural_invasion_present', 'person_neoplasm_cancer_status', 'platelet_result_count', 'platelet_result_lower_limit', 'platelet_result_upper_limit', 'post_op_ablation_embolization_tx', 'postoperative_rx_tx', 'prothrombin_time_result_value', 'radiation_therapy', 'relative_family_cancer_history', 'residual_tumor', 'sample_type', 'sample_type_id', 'specimen_collection_method_name', 'system_version', 'tissue_prospective_collection_indicator', 'tissue_retrospective_collection_indicator', 'tissue_source_site', 'total_bilirubin_upper_limit', 'tumor_tissue_site', 'vascular_tumor_cell_type', 'vial_number', 'vital_status', 'weight', 'year_of_initial_pathologic_diagnosis', '_GENOMIC_ID_TCGA_CHOL_mutation_broad_gene', '_GENOMIC_ID_TCGA_CHOL_mutation_bcgsc_gene', '_GENOMIC_ID_TCGA_CHOL_hMethyl450', '_GENOMIC_ID_TCGA_CHOL_exp_HiSeqV2', '_GENOMIC_ID_TCGA_CHOL_exp_HiSeqV2_PANCAN', '_GENOMIC_ID_TCGA_CHOL_mutation_bcm_gene', '_GENOMIC_ID_TCGA_CHOL_miRNA_HiSeq', '_GENOMIC_ID_TCGA_CHOL_gistic2thd', '_GENOMIC_ID_TCGA_CHOL_gistic2', '_GENOMIC_ID_TCGA_CHOL_PDMRNAseqCNV', '_GENOMIC_ID_TCGA_CHOL_exp_HiSeqV2_exon', '_GENOMIC_ID_data/public/TCGA/CHOL/miRNA_HiSeq_gene', '_GENOMIC_ID_TCGA_CHOL_mutation_ucsc_maf_gene', '_GENOMIC_ID_TCGA_CHOL_PDMRNAseq', '_GENOMIC_ID_TCGA_CHOL_exp_HiSeqV2_percentile', '_GENOMIC_ID_TCGA_CHOL_RPPA']
69
+
70
+ # Step 1: Identify candidate demographic columns
71
+ candidate_age_cols = [col for col in column_names if col in ['age_at_initial_pathologic_diagnosis', 'days_to_birth']]
72
+ candidate_gender_cols = [col for col in column_names if col.lower() == 'gender']
73
+
74
+ print(f"candidate_age_cols = {candidate_age_cols}")
75
+ print(f"candidate_gender_cols = {candidate_gender_cols}")
76
+
77
+ # Step 2: Extract candidate columns from clinical data and preview
78
+ clinical_df = None
79
+ clinical_file_path = None
80
+
81
+ # Try to locate the CHOL clinical file under tcga_root_dir
82
+ try:
83
+ # Prefer directories that contain CHOL
84
+ found = False
85
+ for root, dirs, files in os.walk(tcga_root_dir):
86
+ try:
87
+ cpath, _ = tcga_get_relevant_filepaths(root)
88
+ if os.path.exists(cpath) and ('chol' in cpath.lower() or 'chol' in root.lower()):
89
+ clinical_file_path = cpath
90
+ found = True
91
+ break
92
+ except Exception:
93
+ pass
94
+ # Fallback: directly search for clinical files mentioning CHOL
95
+ if not found:
96
+ for root, dirs, files in os.walk(tcga_root_dir):
97
+ for f in files:
98
+ fl = f.lower()
99
+ if 'clinical' in fl and 'matrix' in fl and 'chol' in fl:
100
+ clinical_file_path = os.path.join(root, f)
101
+ found = True
102
+ break
103
+ if found:
104
+ break
105
+
106
+ if clinical_file_path and os.path.exists(clinical_file_path):
107
+ # Xena clinicalMatrix is tab-separated; sample IDs as index
108
+ clinical_df = pd.read_csv(clinical_file_path, sep='\t', header=0, index_col=0, dtype=str)
109
+ except Exception:
110
+ clinical_df = None
111
+
112
+ age_preview = {}
113
+ gender_preview = {}
114
+
115
+ if clinical_df is not None:
116
+ age_cols_present = [c for c in candidate_age_cols if c in clinical_df.columns]
117
+ gender_cols_present = [c for c in candidate_gender_cols if c in clinical_df.columns]
118
+
119
+ if age_cols_present:
120
+ age_preview = preview_df(clinical_df[age_cols_present], n=5)
121
+ if gender_cols_present:
122
+ gender_preview = preview_df(clinical_df[gender_cols_present], n=5)
123
+
124
+ print(age_preview)
125
+ print(gender_preview)
126
+
127
+ # Step 3: Select Demographic Features
128
+ # Robust selection of demographic columns using provided candidate lists and preview dictionaries.
129
+ # Incorporates value plausibility checks and handles empty inputs.
130
+
131
+ # Helper to safely get global variables by name
132
+ def _get_global(name, default=None):
133
+ return globals()[name] if name in globals() else default
134
+
135
+ # Try to find the preview dictionary by known names or by heuristic overlap with candidate columns
136
+ def _find_preview_dict(candidates, preferred_names):
137
+ for n in preferred_names:
138
+ d = _get_global(n, None)
139
+ if isinstance(d, dict):
140
+ return d
141
+ # Heuristic scan: choose dict with the largest overlap with candidates
142
+ best = None
143
+ best_overlap = 0
144
+ for k, v in globals().items():
145
+ if isinstance(v, dict) and v:
146
+ try:
147
+ overlap = len(set(v.keys()) & set(candidates))
148
+ except Exception:
149
+ overlap = 0
150
+ if overlap > best_overlap:
151
+ best = v
152
+ best_overlap = overlap
153
+ return best if best_overlap > 0 else {}
154
+
155
+ # Parsing helpers
156
+ def _parse_int_with_sign(x):
157
+ if x is None:
158
+ return None
159
+ s = str(x).strip()
160
+ m = re.search(r'-?\d+', s)
161
+ return int(m.group()) if m else None
162
+
163
+ def _is_valid_age_column(col, values):
164
+ if not isinstance(values, list) or len(values) == 0:
165
+ return False
166
+ n = len(values)
167
+ min_valid = max(1, int((0.6 * n) + 0.9999)) # ceil(0.6*n)
168
+ lc = col.lower()
169
+
170
+ if 'days' in lc and 'birth' in lc:
171
+ parsed = [_parse_int_with_sign(v) for v in values]
172
+ valid = [p for p in parsed if isinstance(p, int)]
173
+ if len(valid) < min_valid:
174
+ return False
175
+ plausible = [abs(v) / 365.25 for v in valid]
176
+ plausible_cnt = sum(0 <= yr <= 120 for yr in plausible)
177
+ return plausible_cnt >= min_valid
178
+ else:
179
+ # Treat as age in years
180
+ parsed = [tcga_convert_age(v) for v in values]
181
+ valid = [p for p in parsed if isinstance(p, int)]
182
+ if len(valid) < min_valid:
183
+ return False
184
+ plausible_cnt = sum(0 <= p <= 120 for p in valid)
185
+ return plausible_cnt >= min_valid
186
+
187
+ def _is_valid_gender_values(values):
188
+ if not isinstance(values, list) or len(values) == 0:
189
+ return False
190
+ n = len(values)
191
+ min_valid = max(1, int((0.6 * n) + 0.9999)) # ceil(0.6*n)
192
+ mapped = [tcga_convert_gender(v) for v in values]
193
+ valid = [m for m in mapped if m in (0, 1)]
194
+ return len(valid) >= min_valid
195
+
196
+ def select_age_col(candidates, age_preview_dict):
197
+ if not candidates or not isinstance(age_preview_dict, dict) or not age_preview_dict:
198
+ return None
199
+ # Priority: explicit age in years over derived days
200
+ priority_order = [
201
+ "age_at_initial_pathologic_diagnosis",
202
+ "age_at_diagnosis",
203
+ "age_at_index",
204
+ "age"
205
+ ]
206
+ ordered = [p for p in priority_order if p in candidates]
207
+ ordered += [c for c in candidates if c not in ordered]
208
+
209
+ for c in ordered:
210
+ if c in age_preview_dict and _is_valid_age_column(c, age_preview_dict[c]):
211
+ return c
212
+ # As a last resort, if days_to_birth is available and valid, use it
213
+ for c in candidates:
214
+ if c.lower() == 'days_to_birth' and c in age_preview_dict and _is_valid_age_column(c, age_preview_dict[c]):
215
+ return c
216
+ return None
217
+
218
+ def select_gender_col(candidates, gender_preview_dict):
219
+ if not candidates or not isinstance(gender_preview_dict, dict) or not gender_preview_dict:
220
+ return None
221
+ priority_order = ["gender", "sex"]
222
+ ordered = [p for p in priority_order if p in candidates]
223
+ ordered += [c for c in candidates if c not in ordered]
224
+
225
+ for c in ordered:
226
+ if c in gender_preview_dict and _is_valid_gender_values(gender_preview_dict[c]):
227
+ return c
228
+ return None
229
+
230
+ # Retrieve candidate lists
231
+ candidate_age_cols = _get_global('candidate_age_cols', [])
232
+ candidate_gender_cols = _get_global('candidate_gender_cols', [])
233
+
234
+ # Retrieve preview dicts (try known names, then heuristic)
235
+ age_preview_dict = _find_preview_dict(candidate_age_cols, ['age_preview_dict', 'age_preview'])
236
+ gender_preview_dict = _find_preview_dict(candidate_gender_cols, ['gender_preview_dict', 'gender_preview'])
237
+
238
+ # Select columns using both candidates and previews
239
+ age_col = select_age_col(candidate_age_cols, age_preview_dict)
240
+ gender_col = select_gender_col(candidate_gender_cols, gender_preview_dict)
241
+
242
+ # Explicitly print chosen columns and their preview values (first 5)
243
+ print(f"Chosen age_col: {age_col}")
244
+ if age_col is not None and isinstance(age_preview_dict, dict) and age_col in age_preview_dict:
245
+ print(f"age_col preview values: {age_preview_dict[age_col]}")
246
+ else:
247
+ print("age_col preview values: None or not available")
248
+
249
+ print(f"Chosen gender_col: {gender_col}")
250
+ if gender_col is not None and isinstance(gender_preview_dict, dict) and gender_col in gender_preview_dict:
251
+ print(f"gender_col preview values: {gender_preview_dict[gender_col]}")
252
+ else:
253
+ print("gender_col preview values: None or not available")
254
+
255
+ # Step 4: Feature Engineering and Validation
256
+ import os
257
+
258
+ # 1) Extract and standardize clinical features
259
+ selected_clinical_df = tcga_select_clinical_features(
260
+ clinical_df=tcga_clinical_df,
261
+ trait=trait,
262
+ age_col=age_col,
263
+ gender_col=gender_col
264
+ )
265
+
266
+ # 2) Normalize gene symbols and save
267
+ normalized_gene_df = normalize_gene_symbols_in_index(tcga_genetic_df.copy())
268
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
269
+ normalized_gene_df.to_csv(out_gene_data_file)
270
+
271
+ # 3) Link clinical and genetic data
272
+ gene_t = normalized_gene_df.T # samples as index
273
+ linked_data = selected_clinical_df.join(gene_t, how='inner')
274
+
275
+ # 4) Handle missing values
276
+ processed_df = handle_missing_values(linked_data.copy(), trait_col=trait)
277
+
278
+ # 5) Determine bias and remove biased demographic features if needed
279
+ is_biased, processed_df = judge_and_remove_biased_features(processed_df, trait=trait)
280
+
281
+ # 6) Final validation and save cohort info
282
+ # Cast to Python bool to avoid numpy.bool_ JSON serialization issues
283
+ is_gene_available = bool((normalized_gene_df.shape[0] > 0) and (normalized_gene_df.shape[1] > 0))
284
+ is_trait_available = bool((trait in selected_clinical_df.columns) and bool(selected_clinical_df[trait].notna().any()))
285
+ is_biased_bool = bool(is_biased)
286
+
287
+ note = (
288
+ f"INFO: Age column used: {age_col}; Gender column used: {gender_col}. "
289
+ f"Linked samples (pre-QC): {linked_data.shape[0]}, genes: {linked_data.shape[1] - selected_clinical_df.shape[1]}."
290
+ )
291
+
292
+ is_usable = validate_and_save_cohort_info(
293
+ is_final=True,
294
+ cohort="TCGA",
295
+ info_path=json_path,
296
+ is_gene_available=is_gene_available,
297
+ is_trait_available=is_trait_available,
298
+ is_biased=is_biased_bool,
299
+ df=processed_df,
300
+ note=note
301
+ )
302
+
303
+ # 7) Save linked data if usable
304
+ if is_usable:
305
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
306
+ processed_df.to_csv(out_data_file)
output/preprocess/Bile_Duct_Cancer/cohort_info.json CHANGED
@@ -1,32 +1 @@
1
- {
2
- "GSE131027": {
3
- "is_usable": false,
4
- "is_gene_available": false,
5
- "is_trait_available": false,
6
- "is_available": false,
7
- "is_biased": null,
8
- "has_age": null,
9
- "has_gender": null,
10
- "sample_size": null
11
- },
12
- "GSE107754": {
13
- "is_usable": false,
14
- "is_gene_available": true,
15
- "is_trait_available": true,
16
- "is_available": true,
17
- "is_biased": true,
18
- "has_age": false,
19
- "has_gender": true,
20
- "sample_size": 84
21
- },
22
- "TCGA": {
23
- "is_usable": true,
24
- "is_gene_available": true,
25
- "is_trait_available": true,
26
- "is_available": true,
27
- "is_biased": false,
28
- "has_age": true,
29
- "has_gender": true,
30
- "sample_size": 45
31
- }
32
- }
 
1
+ {"GSE131027": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 92, "note": "INFO: Trait derived from cancer type; no age/gender available in series; probes mapped via 'Gene Symbol' and gene symbols normalized by NCBI synonym dictionary."}, "GSE107754": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": false, "has_gender": true, "sample_size": 71, "note": "INFO: Age unavailable; trait derived from 'tissue' field in sample characteristics; samples without explicit tissue label were dropped during missing-value handling."}, "TCGA": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 45, "note": "INFO: Age column used: age_at_initial_pathologic_diagnosis; Gender column used: gender. Linked samples (pre-QC): 45, genes: 19848."}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
output/preprocess/Bipolar_disorder/GSE120340.csv ADDED
The diff for this file is too large to render. See raw diff
 
output/preprocess/Bipolar_disorder/GSE46416.csv ADDED
The diff for this file is too large to render. See raw diff
 
output/preprocess/Bipolar_disorder/clinical_data/GSE120340.csv CHANGED
@@ -1,2 +1,2 @@
1
- 0,1,2,3
2
- 0.0,0.0,1.0,1.0
 
1
+ ,GSM3398477,GSM3398478,GSM3398479,GSM3398480,GSM3398481,GSM3398482,GSM3398483,GSM3398484,GSM3398485,GSM3398486,GSM3398487,GSM3398488,GSM3398489,GSM3398490,GSM3398491,GSM3398492,GSM3398493,GSM3398494,GSM3398495,GSM3398496,GSM3398497,GSM3398498,GSM3398499,GSM3398500,GSM3398501,GSM3398502,GSM3398503,GSM3398504,GSM3398505,GSM3398506
2
+ Bipolar_disorder,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,,,,,,,,,,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
output/preprocess/Bipolar_disorder/clinical_data/GSE120342.csv CHANGED
@@ -1,2 +1,2 @@
1
- ,0,1
2
- Bipolar_disorder,0.0,
 
1
+ ,GSM3398507,GSM3398508,GSM3398509,GSM3398510,GSM3398511,GSM3398512,GSM3398513,GSM3398514,GSM3398515,GSM3398516,GSM3398517
2
+ Bipolar_disorder,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0
output/preprocess/Bipolar_disorder/clinical_data/GSE46416.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM1129903,GSM1129904,GSM1129905,GSM1129906,GSM1129907,GSM1129908,GSM1129909,GSM1129910,GSM1129911,GSM1129912,GSM1129913,GSM1129914,GSM1129915,GSM1129916,GSM1129917,GSM1129918,GSM1129919,GSM1129920,GSM1129921,GSM1129922,GSM1129923,GSM1129924,GSM1129925,GSM1129926,GSM1129927,GSM1129928,GSM1129929,GSM1129930,GSM1129931,GSM1129932,GSM1129933,GSM1129934
2
+ Bipolar_disorder,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
output/preprocess/Bipolar_disorder/clinical_data/GSE53987.csv CHANGED
@@ -1,4 +1,4 @@
1
- ,Feature,Sample_1,Sample_2,Sample_3,Sample_4,Sample_5,Sample_6,Sample_7,Sample_8,Sample_9,Sample_10,Sample_11,Sample_12,Sample_13,Sample_14,Sample_15,Sample_16,Sample_17,Sample_18,Sample_19,Sample_20,Sample_21,Sample_22,Sample_23,Sample_24,Sample_25,Sample_26,Sample_27,Sample_28,Sample_29,Sample_30,Sample_31,Sample_32,Sample_33,Sample_34,Sample_35,Sample_36,Sample_37,Sample_38,Sample_39,Sample_40,Sample_41,Sample_42,Sample_43,Sample_44,Sample_45,Sample_46,Sample_47,Sample_48,Sample_49,Sample_50,Sample_51,Sample_52,Sample_53,Sample_54,Sample_55,Sample_56,Sample_57,Sample_58,Sample_59,Sample_60,Sample_61,Sample_62,Sample_63,Sample_64,Sample_65,Sample_66,Sample_67,Sample_68,Sample_69,Sample_70,Sample_71,Sample_72,Sample_73,Sample_74,Sample_75,Sample_76,Sample_77,Sample_78,Sample_79,Sample_80,Sample_81,Sample_82,Sample_83,Sample_84,Sample_85,Sample_86,Sample_87,Sample_88,Sample_89,Sample_90,Sample_91,Sample_92,Sample_93,Sample_94,Sample_95,Sample_96,Sample_97,Sample_98,Sample_99,Sample_100,Sample_101,Sample_102,Sample_103,Sample_104,Sample_105,Sample_106,Sample_107,Sample_108,Sample_109,Sample_110,Sample_111,Sample_112,Sample_113,Sample_114,Sample_115,Sample_116,Sample_117,Sample_118,Sample_119,Sample_120,Sample_121,Sample_122,Sample_123,Sample_124,Sample_125,Sample_126,Sample_127,Sample_128,Sample_129,Sample_130,Sample_131,Sample_132,Sample_133,Sample_134,Sample_135,Sample_136,Sample_137,Sample_138,Sample_139,Sample_140,Sample_141,Sample_142,Sample_143,Sample_144,Sample_145,Sample_146,Sample_147,Sample_148,Sample_149,Sample_150,Sample_151,Sample_152,Sample_153,Sample_154,Sample_155,Sample_156,Sample_157,Sample_158,Sample_159,Sample_160,Sample_161,Sample_162,Sample_163,Sample_164,Sample_165,Sample_166,Sample_167,Sample_168,Sample_169,Sample_170,Sample_171,Sample_172,Sample_173,Sample_174,Sample_175,Sample_176,Sample_177,Sample_178,Sample_179,Sample_180,Sample_181,Sample_182,Sample_183,Sample_184,Sample_185,Sample_186,Sample_187,Sample_188,Sample_189,Sample_190,Sample_191,Sample_192,Sample_193,Sample_194,Sample_195,Sample_196,Sample_197,Sample_198,Sample_199,Sample_200,Sample_201,Sample_202,Sample_203,Sample_204,Sample_205
2
- Bipolar_disorder,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
- Age,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
4
- Gender,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
 
1
+ ,GSM1304852,GSM1304853,GSM1304854,GSM1304855,GSM1304856,GSM1304857,GSM1304858,GSM1304859,GSM1304860,GSM1304861,GSM1304862,GSM1304863,GSM1304864,GSM1304865,GSM1304866,GSM1304867,GSM1304868,GSM1304869,GSM1304870,GSM1304871,GSM1304872,GSM1304873,GSM1304874,GSM1304875,GSM1304876,GSM1304877,GSM1304878,GSM1304879,GSM1304880,GSM1304881,GSM1304882,GSM1304883,GSM1304884,GSM1304885,GSM1304886,GSM1304887,GSM1304888,GSM1304889,GSM1304890,GSM1304891,GSM1304892,GSM1304893,GSM1304894,GSM1304895,GSM1304896,GSM1304897,GSM1304898,GSM1304899,GSM1304900,GSM1304901,GSM1304902,GSM1304903,GSM1304904,GSM1304905,GSM1304906,GSM1304907,GSM1304908,GSM1304909,GSM1304910,GSM1304911,GSM1304912,GSM1304913,GSM1304914,GSM1304915,GSM1304916,GSM1304917,GSM1304918,GSM1304919,GSM1304920,GSM1304921,GSM1304922,GSM1304923,GSM1304924,GSM1304925,GSM1304926,GSM1304927,GSM1304928,GSM1304929,GSM1304930,GSM1304931,GSM1304932,GSM1304933,GSM1304934,GSM1304935,GSM1304936,GSM1304937,GSM1304938,GSM1304939,GSM1304940,GSM1304941,GSM1304942,GSM1304943,GSM1304944,GSM1304945,GSM1304946,GSM1304947,GSM1304948,GSM1304949,GSM1304950,GSM1304951,GSM1304952,GSM1304953,GSM1304954,GSM1304955,GSM1304956,GSM1304957,GSM1304958,GSM1304959,GSM1304960,GSM1304961,GSM1304962,GSM1304963,GSM1304964,GSM1304965,GSM1304966,GSM1304967,GSM1304968,GSM1304969,GSM1304970,GSM1304971,GSM1304972,GSM1304973,GSM1304974,GSM1304975,GSM1304976,GSM1304977,GSM1304978,GSM1304979,GSM1304980,GSM1304981,GSM1304982,GSM1304983,GSM1304984,GSM1304985,GSM1304986,GSM1304987,GSM1304988,GSM1304989,GSM1304990,GSM1304991,GSM1304992,GSM1304993,GSM1304994,GSM1304995,GSM1304996,GSM1304997,GSM1304998,GSM1304999,GSM1305000,GSM1305001,GSM1305002,GSM1305003,GSM1305004,GSM1305005,GSM1305006,GSM1305007,GSM1305008,GSM1305009,GSM1305010,GSM1305011,GSM1305012,GSM1305013,GSM1305014,GSM1305015,GSM1305016,GSM1305017,GSM1305018,GSM1305019,GSM1305020,GSM1305021,GSM1305022,GSM1305023,GSM1305024,GSM1305025,GSM1305026,GSM1305027,GSM1305028,GSM1305029,GSM1305030,GSM1305031,GSM1305032,GSM1305033,GSM1305034,GSM1305035,GSM1305036,GSM1305037,GSM1305038,GSM1305039,GSM1305040,GSM1305041,GSM1305042,GSM1305043,GSM1305044,GSM1305045,GSM1305046,GSM1305047,GSM1305048,GSM1305049,GSM1305050,GSM1305051,GSM1305052,GSM1305053,GSM1305054,GSM1305055,GSM1305056
2
+ Bipolar_disorder,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
3
+ Age,52.0,50.0,28.0,55.0,58.0,28.0,49.0,42.0,43.0,50.0,40.0,39.0,45.0,42.0,65.0,51.0,39.0,48.0,51.0,51.0,36.0,65.0,55.0,22.0,52.0,58.0,40.0,41.0,49.0,48.0,39.0,48.0,43.0,68.0,58.0,43.0,51.0,53.0,26.0,52.0,62.0,29.0,49.0,54.0,28.0,42.0,44.0,40.0,47.0,59.0,47.0,34.0,51.0,49.0,47.0,25.0,62.0,44.0,46.0,50.0,46.0,41.0,47.0,37.0,58.0,44.0,38.0,52.0,52.0,50.0,28.0,55.0,58.0,28.0,49.0,56.0,50.0,40.0,39.0,45.0,42.0,65.0,51.0,39.0,48.0,51.0,51.0,36.0,65.0,55.0,22.0,52.0,58.0,40.0,41.0,49.0,48.0,39.0,48.0,43.0,68.0,58.0,43.0,46.0,51.0,53.0,26.0,52.0,62.0,29.0,49.0,54.0,28.0,42.0,40.0,47.0,44.0,59.0,47.0,34.0,51.0,49.0,47.0,25.0,41.0,62.0,47.0,44.0,46.0,50.0,41.0,47.0,37.0,58.0,44.0,52.0,50.0,40.0,39.0,45.0,42.0,65.0,51.0,39.0,48.0,52.0,50.0,28.0,55.0,58.0,49.0,56.0,42.0,49.0,48.0,39.0,48.0,43.0,68.0,58.0,43.0,46.0,51.0,51.0,36.0,65.0,55.0,22.0,52.0,58.0,40.0,42.0,44.0,47.0,44.0,59.0,47.0,34.0,51.0,51.0,53.0,26.0,52.0,62.0,29.0,49.0,54.0,50.0,46.0,41.0,47.0,37.0,58.0,44.0,38.0,52.0,49.0,47.0,25.0,41.0,62.0,32.0,47.0,50.0,44.0
4
+ Gender,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0
output/preprocess/Bipolar_disorder/clinical_data/GSE62191.csv CHANGED
@@ -1,4 +1,3 @@
1
- 0,1,2,3,4,5,6
2
- ,,,,,,
3
- ,,34.0,,,20.0,
4
- ,,,,,,1.0
 
1
+ ,GSM1521625,GSM1521626,GSM1521627,GSM1521628,GSM1521629,GSM1521630,GSM1521631,GSM1521632,GSM1521633,GSM1521634,GSM1521635,GSM1521636,GSM1521637,GSM1521638,GSM1521639,GSM1521640,GSM1521641,GSM1521642,GSM1521643,GSM1521644,GSM1521645,GSM1521646,GSM1521647,GSM1521648,GSM1521649,GSM1521650,GSM1521651,GSM1521652,GSM1521653,GSM1521654,GSM1521655,GSM1521656,GSM1521657,GSM1521658,GSM1521659,GSM1521660,GSM1521661,GSM1521662,GSM1521663,GSM1521664,GSM1521665,GSM1521666,GSM1521667,GSM1521668,GSM1521669,GSM1521670,GSM1521671,GSM1521672,GSM1521673,GSM1521674,GSM1521675,GSM1521676,GSM1521677,GSM1521678,GSM1521679,GSM1521680,GSM1521681,GSM1521682,GSM1521683,GSM1521684,GSM1521685,GSM1521686,GSM1521687,GSM1521688,GSM1521689,GSM1521690,GSM1521691,GSM1521692,GSM1521693,GSM1521694,GSM1521695,GSM1521696,GSM1521697,GSM1521698,GSM1521699,GSM1521700,GSM1521701,GSM1521702,GSM1521703,GSM1521704,GSM1521705,GSM1521706,GSM1521707,GSM1521708,GSM1521709,GSM1521710,GSM1521711,GSM1521712
2
+ Bipolar_disorder,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
+ Age,29.0,58.0,54.0,42.0,63.0,64.0,59.0,51.0,49.0,41.0,48.0,47.0,45.0,41.0,29.0,44.0,48.0,42.0,35.0,35.0,38.0,44.0,43.0,50.0,56.0,29.0,59.0,35.0,33.0,34.0,44.0,46.0,51.0,33.0,48.0,40.0,31.0,39.0,59.0,53.0,53.0,38.0,60.0,45.0,45.0,35.0,47.0,34.0,42.0,19.0,41.0,44.0,49.0,49.0,35.0,47.0,51.0,48.0,49.0,55.0,40.0,44.0,31.0,38.0,47.0,24.0,32.0,44.0,39.0,33.0,43.0,35.0,47.0,36.0,53.0,45.0,51.0,19.0,45.0,43.0,46.0,52.0,44.0,50.0,41.0,42.0,53.0,52.0
 
output/preprocess/Bipolar_disorder/clinical_data/GSE67311.csv CHANGED
@@ -1,143 +1,2 @@
1
- ,Bipolar_disorder
2
- GSM1644447,
3
- GSM1644448,
4
- GSM1644449,
5
- GSM1644450,
6
- GSM1644451,
7
- GSM1644452,
8
- GSM1644453,
9
- GSM1644454,
10
- GSM1644455,
11
- GSM1644456,
12
- GSM1644457,
13
- GSM1644458,
14
- GSM1644459,
15
- GSM1644460,
16
- GSM1644461,
17
- GSM1644462,
18
- GSM1644463,
19
- GSM1644464,
20
- GSM1644465,
21
- GSM1644466,
22
- GSM1644467,
23
- GSM1644468,
24
- GSM1644469,
25
- GSM1644470,
26
- GSM1644471,
27
- GSM1644472,
28
- GSM1644473,
29
- GSM1644474,
30
- GSM1644475,
31
- GSM1644476,
32
- GSM1644477,
33
- GSM1644478,
34
- GSM1644479,
35
- GSM1644480,
36
- GSM1644481,
37
- GSM1644482,
38
- GSM1644483,
39
- GSM1644484,
40
- GSM1644485,
41
- GSM1644486,
42
- GSM1644487,
43
- GSM1644488,
44
- GSM1644489,
45
- GSM1644490,
46
- GSM1644491,
47
- GSM1644492,
48
- GSM1644493,
49
- GSM1644494,
50
- GSM1644495,
51
- GSM1644496,
52
- GSM1644497,
53
- GSM1644498,
54
- GSM1644499,
55
- GSM1644500,
56
- GSM1644501,
57
- GSM1644502,
58
- GSM1644503,
59
- GSM1644504,
60
- GSM1644505,
61
- GSM1644506,
62
- GSM1644507,
63
- GSM1644508,
64
- GSM1644509,
65
- GSM1644510,
66
- GSM1644511,
67
- GSM1644512,
68
- GSM1644513,
69
- GSM1644514,
70
- GSM1644515,
71
- GSM1644516,
72
- GSM1644517,
73
- GSM1644518,
74
- GSM1644519,
75
- GSM1644520,
76
- GSM1644521,
77
- GSM1644522,
78
- GSM1644523,
79
- GSM1644524,
80
- GSM1644525,
81
- GSM1644526,
82
- GSM1644527,
83
- GSM1644528,
84
- GSM1644529,
85
- GSM1644530,
86
- GSM1644531,
87
- GSM1644532,
88
- GSM1644533,
89
- GSM1644534,
90
- GSM1644535,
91
- GSM1644536,
92
- GSM1644537,
93
- GSM1644538,
94
- GSM1644539,
95
- GSM1644540,
96
- GSM1644541,
97
- GSM1644542,
98
- GSM1644543,
99
- GSM1644544,
100
- GSM1644545,
101
- GSM1644546,
102
- GSM1644547,
103
- GSM1644548,
104
- GSM1644549,
105
- GSM1644550,
106
- GSM1644551,
107
- GSM1644552,
108
- GSM1644553,
109
- GSM1644554,
110
- GSM1644555,
111
- GSM1644556,
112
- GSM1644557,
113
- GSM1644558,
114
- GSM1644559,
115
- GSM1644560,
116
- GSM1644561,
117
- GSM1644562,
118
- GSM1644563,
119
- GSM1644564,
120
- GSM1644565,
121
- GSM1644566,
122
- GSM1644567,
123
- GSM1644568,
124
- GSM1644569,
125
- GSM1644570,
126
- GSM1644571,
127
- GSM1644572,
128
- GSM1644573,
129
- GSM1644574,
130
- GSM1644575,
131
- GSM1644576,
132
- GSM1644577,
133
- GSM1644578,
134
- GSM1644579,
135
- GSM1644580,
136
- GSM1644581,
137
- GSM1644582,
138
- GSM1644583,
139
- GSM1644584,
140
- GSM1644585,
141
- GSM1644586,
142
- GSM1644587,
143
- GSM1644588,
 
1
+ ,GSM1644447,GSM1644448,GSM1644449,GSM1644450,GSM1644451,GSM1644452,GSM1644453,GSM1644454,GSM1644455,GSM1644456,GSM1644457,GSM1644458,GSM1644459,GSM1644460,GSM1644461,GSM1644462,GSM1644463,GSM1644464,GSM1644465,GSM1644466,GSM1644467,GSM1644468,GSM1644469,GSM1644470,GSM1644471,GSM1644472,GSM1644473,GSM1644474,GSM1644475,GSM1644476,GSM1644477,GSM1644478,GSM1644479,GSM1644480,GSM1644481,GSM1644482,GSM1644483,GSM1644484,GSM1644485,GSM1644486,GSM1644487,GSM1644488,GSM1644489,GSM1644490,GSM1644491,GSM1644492,GSM1644493,GSM1644494,GSM1644495,GSM1644496,GSM1644497,GSM1644498,GSM1644499,GSM1644500,GSM1644501,GSM1644502,GSM1644503,GSM1644504,GSM1644505,GSM1644506,GSM1644507,GSM1644508,GSM1644509,GSM1644510,GSM1644511,GSM1644512,GSM1644513,GSM1644514,GSM1644515,GSM1644516,GSM1644517,GSM1644518,GSM1644519,GSM1644520,GSM1644521,GSM1644522,GSM1644523,GSM1644524,GSM1644525,GSM1644526,GSM1644527,GSM1644528,GSM1644529,GSM1644530,GSM1644531,GSM1644532,GSM1644533,GSM1644534,GSM1644535,GSM1644536,GSM1644537,GSM1644538,GSM1644539,GSM1644540,GSM1644541,GSM1644542,GSM1644543,GSM1644544,GSM1644545,GSM1644546,GSM1644547,GSM1644548,GSM1644549,GSM1644550,GSM1644551,GSM1644552,GSM1644553,GSM1644554,GSM1644555,GSM1644556,GSM1644557,GSM1644558,GSM1644559,GSM1644560,GSM1644561,GSM1644562,GSM1644563,GSM1644564,GSM1644565,GSM1644566,GSM1644567,GSM1644568,GSM1644569,GSM1644570,GSM1644571,GSM1644572,GSM1644573,GSM1644574,GSM1644575,GSM1644576,GSM1644577,GSM1644578,GSM1644579,GSM1644580,GSM1644581,GSM1644582,GSM1644583,GSM1644584,GSM1644585,GSM1644586,GSM1644587,GSM1644588
2
+ Bipolar_disorder,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,,0.0,0.0,0.0,0.0,,0.0,0.0,0.0,0.0,0.0,0.0,1.0,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,0.0,0.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
output/preprocess/Bipolar_disorder/clinical_data/GSE92538.csv CHANGED
@@ -1,4 +1,4 @@
1
  ,GSM2431718,GSM2431721,GSM2431722,GSM2431723,GSM2431726,GSM2431727,GSM2431728,GSM2431730,GSM2431731,GSM2431733,GSM2431734,GSM2431735,GSM2431737,GSM2431738,GSM2431739,GSM2431740,GSM2431743,GSM2431745,GSM2431749,GSM2431750,GSM2431751,GSM2431752,GSM2431753,GSM2431755,GSM2431756,GSM2431758,GSM2431759,GSM2431761,GSM2431762,GSM2431763,GSM2431765,GSM2431768,GSM2431771,GSM2431772,GSM2431773,GSM2431776,GSM2431777,GSM2431780,GSM2431783,GSM2431784,GSM2431785,GSM2431786,GSM2431787,GSM2431788,GSM2431789,GSM2431790,GSM2431791,GSM2431792,GSM2431794,GSM2431795,GSM2431796,GSM2431797,GSM2431800,GSM2431801,GSM2431803,GSM2431804,GSM2431807,GSM2431810,GSM2431811,GSM2431812,GSM2431813,GSM2431814,GSM2431815,GSM2431819,GSM2431820,GSM2431821,GSM2431822,GSM2431824,GSM2431827,GSM2431828,GSM2431830,GSM2431831,GSM2431832,GSM2431833,GSM2431834,GSM2431835,GSM2431836,GSM2431838,GSM2431839,GSM2431840,GSM2431841,GSM2431842,GSM2431844,GSM2431846,GSM2431847,GSM2431850,GSM2431851,GSM2431854,GSM2431855,GSM2431856,GSM2431857,GSM2431859,GSM2431860,GSM2431861,GSM2431862,GSM2431863,GSM2431865,GSM2431869,GSM2431870,GSM2431871,GSM2431872,GSM2431875,GSM2431878,GSM2431879,GSM2431880,GSM2431881,GSM2431882,GSM2431883,GSM2431884,GSM2431885,GSM2431886,GSM2431887,GSM2431888,GSM2431889,GSM2431890,GSM2431891,GSM2431892,GSM2431893,GSM2431894,GSM2431895,GSM2431896,GSM2431897,GSM2431898,GSM2431899,GSM2431902,GSM2431906,GSM2431908,GSM2431909,GSM2431912,GSM2431913,GSM2431914,GSM2431916,GSM2431918,GSM2431919,GSM2431920,GSM2431921,GSM2431923,GSM2431924,GSM2431926,GSM2431927,GSM2431929,GSM2431934,GSM2431935,GSM2431936,GSM2431937,GSM2431938,GSM2431939,GSM2431941,GSM2431942,GSM2431946,GSM2431947,GSM2431949,GSM2431950,GSM2431951,GSM2431954,GSM2431955,GSM2431960,GSM2431961,GSM2431962,GSM2431964,GSM2431965,GSM2431966,GSM2431967,GSM2431972,GSM2431973,GSM2431974,GSM2431975,GSM2431976,GSM2431977,GSM2431978,GSM2431979,GSM2431980,GSM2431981,GSM2431982,GSM2431983,GSM2431986,GSM2431987,GSM2431988,GSM2431989,GSM2431992,GSM2431993,GSM2431994,GSM2431996,GSM2431997,GSM2432001,GSM2432003,GSM2432004,GSM2432006,GSM2432007,GSM2432008,GSM2432009,GSM2432011,GSM2432012,GSM2432013,GSM2432015,GSM2432016,GSM2432019,GSM2432020,GSM2432022,GSM2432023,GSM2432024,GSM2432025,GSM2432026,GSM2432027,GSM2432028,GSM2432030,GSM2432031,GSM2432032,GSM2432033,GSM2432034,GSM2432035,GSM2432036,GSM2432038,GSM2432043,GSM2432044,GSM2432046,GSM2432049,GSM2432050,GSM2432051,GSM2432053,GSM2432056,GSM2432057,GSM2432059,GSM2432061,GSM2432062,GSM2432067,GSM2432072,GSM2432073,GSM2432075,GSM2432080,GSM2432085,GSM2432086,GSM2432088,GSM2432090,GSM2432092
2
- Bipolar_disorder,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0
3
  Age,39.0,32.0,63.0,70.0,71.0,44.0,66.0,59.0,65.0,69.0,52.0,49.0,58.0,45.0,72.0,73.0,44.0,64.0,70.0,52.0,77.0,59.0,55.0,49.0,49.0,53.0,62.0,47.0,67.0,57.0,35.0,48.0,19.0,54.0,73.0,48.0,69.0,50.0,48.0,65.0,69.0,56.0,63.0,80.0,60.0,55.0,40.0,39.0,59.0,48.0,39.0,67.0,66.0,18.0,41.0,47.0,50.0,40.0,40.0,41.0,72.0,72.0,64.0,48.0,34.0,77.0,63.0,50.0,40.0,84.0,32.0,58.0,46.0,70.0,73.0,58.0,70.0,23.0,63.0,52.0,39.0,19.0,48.0,64.0,47.0,49.0,64.0,50.0,59.0,25.0,45.0,60.0,78.0,52.0,65.0,68.0,71.0,81.0,54.0,34.0,68.0,43.0,35.0,47.0,26.0,57.0,39.0,59.0,44.0,64.0,59.0,47.0,48.0,48.0,50.0,48.0,40.0,64.0,48.0,48.0,59.0,54.0,43.0,57.0,39.0,32.0,63.0,70.0,71.0,44.0,66.0,59.0,69.0,69.0,49.0,49.0,58.0,58.0,45.0,44.0,64.0,70.0,52.0,77.0,59.0,55.0,55.0,49.0,49.0,53.0,62.0,47.0,67.0,57.0,35.0,48.0,19.0,54.0,54.0,73.0,48.0,69.0,50.0,48.0,65.0,69.0,56.0,56.0,63.0,80.0,60.0,60.0,55.0,40.0,39.0,59.0,48.0,39.0,67.0,66.0,18.0,18.0,41.0,47.0,50.0,40.0,41.0,72.0,72.0,72.0,64.0,48.0,34.0,77.0,50.0,50.0,40.0,84.0,32.0,46.0,70.0,73.0,58.0,58.0,70.0,23.0,23.0,63.0,52.0,39.0,19.0,19.0,48.0,49.0,49.0,64.0,59.0,25.0,45.0,60.0,78.0,52.0,52.0,65.0,65.0,71.0,81.0,54.0,34.0,43.0,35.0,47.0,26.0,26.0,57.0
4
  Gender,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0
 
1
  ,GSM2431718,GSM2431721,GSM2431722,GSM2431723,GSM2431726,GSM2431727,GSM2431728,GSM2431730,GSM2431731,GSM2431733,GSM2431734,GSM2431735,GSM2431737,GSM2431738,GSM2431739,GSM2431740,GSM2431743,GSM2431745,GSM2431749,GSM2431750,GSM2431751,GSM2431752,GSM2431753,GSM2431755,GSM2431756,GSM2431758,GSM2431759,GSM2431761,GSM2431762,GSM2431763,GSM2431765,GSM2431768,GSM2431771,GSM2431772,GSM2431773,GSM2431776,GSM2431777,GSM2431780,GSM2431783,GSM2431784,GSM2431785,GSM2431786,GSM2431787,GSM2431788,GSM2431789,GSM2431790,GSM2431791,GSM2431792,GSM2431794,GSM2431795,GSM2431796,GSM2431797,GSM2431800,GSM2431801,GSM2431803,GSM2431804,GSM2431807,GSM2431810,GSM2431811,GSM2431812,GSM2431813,GSM2431814,GSM2431815,GSM2431819,GSM2431820,GSM2431821,GSM2431822,GSM2431824,GSM2431827,GSM2431828,GSM2431830,GSM2431831,GSM2431832,GSM2431833,GSM2431834,GSM2431835,GSM2431836,GSM2431838,GSM2431839,GSM2431840,GSM2431841,GSM2431842,GSM2431844,GSM2431846,GSM2431847,GSM2431850,GSM2431851,GSM2431854,GSM2431855,GSM2431856,GSM2431857,GSM2431859,GSM2431860,GSM2431861,GSM2431862,GSM2431863,GSM2431865,GSM2431869,GSM2431870,GSM2431871,GSM2431872,GSM2431875,GSM2431878,GSM2431879,GSM2431880,GSM2431881,GSM2431882,GSM2431883,GSM2431884,GSM2431885,GSM2431886,GSM2431887,GSM2431888,GSM2431889,GSM2431890,GSM2431891,GSM2431892,GSM2431893,GSM2431894,GSM2431895,GSM2431896,GSM2431897,GSM2431898,GSM2431899,GSM2431902,GSM2431906,GSM2431908,GSM2431909,GSM2431912,GSM2431913,GSM2431914,GSM2431916,GSM2431918,GSM2431919,GSM2431920,GSM2431921,GSM2431923,GSM2431924,GSM2431926,GSM2431927,GSM2431929,GSM2431934,GSM2431935,GSM2431936,GSM2431937,GSM2431938,GSM2431939,GSM2431941,GSM2431942,GSM2431946,GSM2431947,GSM2431949,GSM2431950,GSM2431951,GSM2431954,GSM2431955,GSM2431960,GSM2431961,GSM2431962,GSM2431964,GSM2431965,GSM2431966,GSM2431967,GSM2431972,GSM2431973,GSM2431974,GSM2431975,GSM2431976,GSM2431977,GSM2431978,GSM2431979,GSM2431980,GSM2431981,GSM2431982,GSM2431983,GSM2431986,GSM2431987,GSM2431988,GSM2431989,GSM2431992,GSM2431993,GSM2431994,GSM2431996,GSM2431997,GSM2432001,GSM2432003,GSM2432004,GSM2432006,GSM2432007,GSM2432008,GSM2432009,GSM2432011,GSM2432012,GSM2432013,GSM2432015,GSM2432016,GSM2432019,GSM2432020,GSM2432022,GSM2432023,GSM2432024,GSM2432025,GSM2432026,GSM2432027,GSM2432028,GSM2432030,GSM2432031,GSM2432032,GSM2432033,GSM2432034,GSM2432035,GSM2432036,GSM2432038,GSM2432043,GSM2432044,GSM2432046,GSM2432049,GSM2432050,GSM2432051,GSM2432053,GSM2432056,GSM2432057,GSM2432059,GSM2432061,GSM2432062,GSM2432067,GSM2432072,GSM2432073,GSM2432075,GSM2432080,GSM2432085,GSM2432086,GSM2432088,GSM2432090,GSM2432092
2
+ Bipolar_disorder,,0.0,0.0,0.0,0.0,0.0,,,,1.0,0.0,,0.0,0.0,0.0,0.0,,0.0,0.0,0.0,,0.0,0.0,,0.0,,0.0,,0.0,,0.0,,0.0,0.0,1.0,0.0,1.0,,,0.0,1.0,1.0,,,0.0,0.0,0.0,,1.0,,0.0,0.0,1.0,0.0,0.0,0.0,,0.0,0.0,,0.0,,,0.0,1.0,0.0,1.0,0.0,1.0,,1.0,0.0,,0.0,0.0,,0.0,1.0,1.0,,1.0,,0.0,0.0,0.0,1.0,0.0,0.0,,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,,1.0,0.0,,,1.0,0.0,,,,0.0,0.0,,,0.0,,,0.0,,0.0,0.0,,0.0,0.0,0.0,,0.0,0.0,0.0,0.0,0.0,,,1.0,1.0,,,0.0,0.0,0.0,,0.0,0.0,0.0,,0.0,0.0,0.0,,0.0,,0.0,,0.0,,0.0,,0.0,0.0,0.0,1.0,0.0,1.0,,,0.0,1.0,1.0,1.0,,,0.0,0.0,0.0,0.0,,1.0,,0.0,0.0,1.0,0.0,0.0,0.0,0.0,,0.0,,0.0,,,,0.0,1.0,0.0,0.0,0.0,1.0,,1.0,,0.0,0.0,,,0.0,1.0,1.0,1.0,,1.0,,,0.0,1.0,1.0,0.0,,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,,0.0,,,1.0,1.0,0.0
3
  Age,39.0,32.0,63.0,70.0,71.0,44.0,66.0,59.0,65.0,69.0,52.0,49.0,58.0,45.0,72.0,73.0,44.0,64.0,70.0,52.0,77.0,59.0,55.0,49.0,49.0,53.0,62.0,47.0,67.0,57.0,35.0,48.0,19.0,54.0,73.0,48.0,69.0,50.0,48.0,65.0,69.0,56.0,63.0,80.0,60.0,55.0,40.0,39.0,59.0,48.0,39.0,67.0,66.0,18.0,41.0,47.0,50.0,40.0,40.0,41.0,72.0,72.0,64.0,48.0,34.0,77.0,63.0,50.0,40.0,84.0,32.0,58.0,46.0,70.0,73.0,58.0,70.0,23.0,63.0,52.0,39.0,19.0,48.0,64.0,47.0,49.0,64.0,50.0,59.0,25.0,45.0,60.0,78.0,52.0,65.0,68.0,71.0,81.0,54.0,34.0,68.0,43.0,35.0,47.0,26.0,57.0,39.0,59.0,44.0,64.0,59.0,47.0,48.0,48.0,50.0,48.0,40.0,64.0,48.0,48.0,59.0,54.0,43.0,57.0,39.0,32.0,63.0,70.0,71.0,44.0,66.0,59.0,69.0,69.0,49.0,49.0,58.0,58.0,45.0,44.0,64.0,70.0,52.0,77.0,59.0,55.0,55.0,49.0,49.0,53.0,62.0,47.0,67.0,57.0,35.0,48.0,19.0,54.0,54.0,73.0,48.0,69.0,50.0,48.0,65.0,69.0,56.0,56.0,63.0,80.0,60.0,60.0,55.0,40.0,39.0,59.0,48.0,39.0,67.0,66.0,18.0,18.0,41.0,47.0,50.0,40.0,41.0,72.0,72.0,72.0,64.0,48.0,34.0,77.0,50.0,50.0,40.0,84.0,32.0,46.0,70.0,73.0,58.0,58.0,70.0,23.0,23.0,63.0,52.0,39.0,19.0,19.0,48.0,49.0,49.0,64.0,59.0,25.0,45.0,60.0,78.0,52.0,52.0,65.0,65.0,71.0,81.0,54.0,34.0,43.0,35.0,47.0,26.0,26.0,57.0
4
  Gender,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0
output/preprocess/Bipolar_disorder/code/GSE120340.py ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE120340"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE120340"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE120340.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE120340.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE120340.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+
42
+ # 1. Gene Expression Data Availability
43
+ is_gene_available = True # Affymetrix whole-genome expression microarrays were used.
44
+
45
+ # 2. Variable Availability and Data Type Conversion
46
+
47
+ # Based on the sample characteristics dictionary:
48
+ # {0: ['disease state: control', 'disease state: SCZ', 'disease state: BD(+)', 'disease state: BD(-)'],
49
+ # 1: ['laterality: left', 'laterality: right']}
50
+ trait_row = 0
51
+ age_row = None
52
+ gender_row = None
53
+
54
+ def _after_colon(x):
55
+ if x is None:
56
+ return None
57
+ s = str(x)
58
+ # Extract substring after the first colon if present
59
+ parts = s.split(":", 1)
60
+ return parts[1].strip() if len(parts) == 2 else s.strip()
61
+
62
+ def convert_trait(x):
63
+ v = _after_colon(x)
64
+ if v is None or v == '':
65
+ return None
66
+ val = v.lower().strip()
67
+
68
+ # Normalize some variants
69
+ val = val.replace('bipolar disorder', 'bd')
70
+ val = val.replace('psychotic bd', 'bd(+)')
71
+ val = val.replace('non-psychotic bd', 'bd(-)')
72
+
73
+ # Map to binary for Bipolar_disorder: control -> 0, BD(+)/BD(-) -> 1, SCZ -> None
74
+ if val in {'control', 'healthy control', 'normal'}:
75
+ return 0
76
+ if val in {'bd', 'bd(+)', 'bd(-)'}:
77
+ return 1
78
+ if val in {'scz', 'schizophrenia'}:
79
+ return None
80
+ # If the cell includes BD text anywhere, map conservatively to 1
81
+ if 'bd' in val or 'bipolar' in val:
82
+ return 1
83
+ # Otherwise unknown
84
+ return None
85
+
86
+ def convert_age(x):
87
+ v = _after_colon(x)
88
+ if v is None or v == '':
89
+ return None
90
+ val = v.lower()
91
+ if any(k in val for k in ['na', 'n/a', 'unknown', 'missing']):
92
+ return None
93
+ m = re.search(r'[-+]?\d*\.?\d+', val)
94
+ if m:
95
+ try:
96
+ return float(m.group())
97
+ except Exception:
98
+ return None
99
+ return None
100
+
101
+ def convert_gender(x):
102
+ v = _after_colon(x)
103
+ if v is None or v == '':
104
+ return None
105
+ val = v.lower().strip()
106
+ if val in {'female', 'f', 'woman', 'women'}:
107
+ return 0
108
+ if val in {'male', 'm', 'man', 'men'}:
109
+ return 1
110
+ return None
111
+
112
+ # 3. Save Metadata (initial filtering)
113
+ is_trait_available = trait_row is not None
114
+ _ = validate_and_save_cohort_info(
115
+ is_final=False,
116
+ cohort=cohort,
117
+ info_path=json_path,
118
+ is_gene_available=is_gene_available,
119
+ is_trait_available=is_trait_available
120
+ )
121
+
122
+ # 4. Clinical Feature Extraction (only if trait_row is available)
123
+ if trait_row is not None:
124
+ selected_clinical_df = geo_select_clinical_features(
125
+ clinical_df=clinical_data,
126
+ trait=trait,
127
+ trait_row=trait_row,
128
+ convert_trait=convert_trait,
129
+ age_row=age_row,
130
+ convert_age=convert_age if age_row is not None else None,
131
+ gender_row=gender_row,
132
+ convert_gender=convert_gender if gender_row is not None else None
133
+ )
134
+ preview = preview_df(selected_clinical_df)
135
+ print(preview)
136
+
137
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
138
+ selected_clinical_df.to_csv(out_clinical_data_file)
139
+
140
+ # Step 3: Gene Data Extraction
141
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
142
+ gene_data = get_genetic_data(matrix_file)
143
+
144
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
145
+ print(gene_data.index[:20])
146
+
147
+ # Step 4: Gene Identifier Review
148
+ requires_gene_mapping = True
149
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
150
+
151
+ # Step 5: Gene Annotation
152
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
153
+ gene_annotation = get_gene_annotation(soft_file)
154
+
155
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
156
+ print("Gene annotation preview:")
157
+ print(preview_df(gene_annotation))
158
+
159
+ # Step 6: Gene Identifier Mapping
160
+ # Decide probe ID column and gene symbol column from gene_annotation
161
+ prob_col = 'ID' if 'ID' in gene_annotation.columns else gene_annotation.columns[0]
162
+
163
+ # Try to find a gene symbol column
164
+ symbol_candidates = [c for c in gene_annotation.columns if re.search(r'symbol', c, flags=re.I)]
165
+ if len(symbol_candidates) > 0:
166
+ gene_col = symbol_candidates[0]
167
+ else:
168
+ # Fallbacks commonly seen in GEO/GPL annotations
169
+ for cand in ['Gene Symbol', 'Gene.symbol', 'GENE_SYMBOL', 'Symbol', 'SYMBOL', 'gene_symbol']:
170
+ if cand in gene_annotation.columns:
171
+ gene_col = cand
172
+ break
173
+ else:
174
+ # Last resort: use Description (extract_human_gene_symbols will try to parse symbols from text)
175
+ gene_col = 'Description' if 'Description' in gene_annotation.columns else gene_annotation.columns[-1]
176
+
177
+ # Build mapping dataframe
178
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=prob_col, gene_col=gene_col)
179
+
180
+ # Apply mapping to convert probe-level data into gene-level data
181
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
182
+
183
+ # Step 7: Data Normalization and Linking
184
+ import os
185
+
186
+ # 1. Normalize the obtained gene data and save
187
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
188
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
189
+ normalized_gene_data.to_csv(out_gene_data_file)
190
+
191
+ # 2. Link the clinical and genetic data
192
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
193
+
194
+ # 3. Handle missing values in the linked data
195
+ linked_data = handle_missing_values(linked_data, trait)
196
+
197
+ # 4. Determine whether the trait and some demographic features are severely biased, and remove biased features.
198
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
199
+
200
+ # Derive availability flags from processed data
201
+ is_gene_available_final = (normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0)
202
+ is_trait_available_final = (trait in unbiased_linked_data.columns) and (len(unbiased_linked_data) > 0)
203
+
204
+ # Optional notes
205
+ notes = []
206
+ notes.append("INFO: SCZ samples mapped to None for trait and were excluded during missing-value handling.")
207
+ if "Age" not in unbiased_linked_data.columns:
208
+ notes.append("INFO: Age not available in clinical annotations.")
209
+ if "Gender" not in unbiased_linked_data.columns:
210
+ notes.append("INFO: Gender not available in clinical annotations.")
211
+ note = " ".join(notes) if notes else "INFO: No additional notes."
212
+
213
+ # 5. Conduct quality check and save the cohort information.
214
+ is_usable = validate_and_save_cohort_info(
215
+ is_final=True,
216
+ cohort=cohort,
217
+ info_path=json_path,
218
+ is_gene_available=is_gene_available_final,
219
+ is_trait_available=is_trait_available_final,
220
+ is_biased=is_trait_biased,
221
+ df=unbiased_linked_data,
222
+ note=note
223
+ )
224
+
225
+ # 6. If the linked data is usable, save it
226
+ if is_usable:
227
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
228
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Bipolar_disorder/code/GSE120342.py ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE120342"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE120342"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE120342.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE120342.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE120342.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+ import pandas as pd
42
+
43
+ # 1) Gene expression availability (SuperSeries mentions transcriptomes -> likely contains gene expression)
44
+ is_gene_available = True
45
+
46
+ # 2) Variable availability
47
+ # From sample characteristics: {0: ['disease state: control', 'disease state: SCZ', 'disease state: BD(-)', 'disease state: BD(+)'],
48
+ # 1: ['laterality: right', 'laterality: left']}
49
+ trait_row = 0 # disease state contains BD labels
50
+ age_row = None # not available
51
+ gender_row = None # not available
52
+
53
+ # 2.2) Converters
54
+ def _after_colon(x):
55
+ if x is None or (isinstance(x, float) and pd.isna(x)):
56
+ return None
57
+ s = str(x)
58
+ if ':' in s:
59
+ s = s.split(':', 1)[1]
60
+ return s.strip()
61
+
62
+ def convert_trait(x):
63
+ v = _after_colon(x)
64
+ if v is None:
65
+ return None
66
+ vl = v.lower()
67
+ # Map presence of bipolar disorder to 1; control and SCZ to 0
68
+ if 'bd' in vl: # 'bd(+)' or 'bd(-)' or 'bipolar'
69
+ return 1
70
+ if 'control' in vl or 'scz' in vl or 'schizo' in vl:
71
+ return 0
72
+ return None
73
+
74
+ def convert_age(x):
75
+ v = _after_colon(x)
76
+ if v is None:
77
+ return None
78
+ # extract the first number (years)
79
+ m = re.search(r'[-+]?\d*\.?\d+', v)
80
+ if m:
81
+ try:
82
+ return float(m.group(0))
83
+ except Exception:
84
+ return None
85
+ return None
86
+
87
+ def convert_gender(x):
88
+ v = _after_colon(x)
89
+ if v is None:
90
+ return None
91
+ vl = v.lower()
92
+ if any(k in vl for k in ['female', 'f']):
93
+ return 0
94
+ if any(k in vl for k in ['male', 'm']):
95
+ return 1
96
+ return None
97
+
98
+ # 3) Save initial metadata
99
+ is_trait_available = trait_row is not None
100
+ _ = validate_and_save_cohort_info(
101
+ is_final=False,
102
+ cohort=cohort,
103
+ info_path=json_path,
104
+ is_gene_available=is_gene_available,
105
+ is_trait_available=is_trait_available
106
+ )
107
+
108
+ # 4) Clinical feature extraction if available
109
+ if trait_row is not None:
110
+ selected_clinical_df = geo_select_clinical_features(
111
+ clinical_df=clinical_data,
112
+ trait=trait,
113
+ trait_row=trait_row,
114
+ convert_trait=convert_trait,
115
+ age_row=age_row,
116
+ convert_age=convert_age if age_row is not None else None,
117
+ gender_row=gender_row,
118
+ convert_gender=convert_gender if gender_row is not None else None
119
+ )
120
+ preview = preview_df(selected_clinical_df)
121
+ print(preview)
122
+
123
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
124
+ selected_clinical_df.to_csv(out_clinical_data_file)
125
+
126
+ # Step 3: Gene Data Extraction
127
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
128
+ gene_data = get_genetic_data(matrix_file)
129
+
130
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
131
+ print(gene_data.index[:20])
132
+
133
+ # Step 4: Gene Identifier Review
134
+ requires_gene_mapping = True
135
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
136
+
137
+ # Step 5: Gene Annotation
138
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
139
+ gene_annotation = get_gene_annotation(soft_file)
140
+
141
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
142
+ print("Gene annotation preview:")
143
+ print(preview_df(gene_annotation))
144
+
145
+ # Step 6: Gene Identifier Mapping
146
+ # Decide the identifier and gene symbol columns based on the annotation preview:
147
+ identifier_col = 'ID' # Matches probe IDs like 'cg00000292'
148
+ gene_symbol_col = 'Symbol' # Contains human gene symbols
149
+
150
+ # Build mapping dataframe
151
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=identifier_col, gene_col=gene_symbol_col)
152
+
153
+ # Fallback: if mapping is unexpectedly empty, try 'Name' as probe identifier
154
+ if mapping_df.empty and 'Name' in gene_annotation.columns:
155
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='Name', gene_col=gene_symbol_col)
156
+
157
+ # Apply mapping to convert probe-level measurements to gene-level data
158
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
159
+
160
+ # Step 7: Data Normalization and Linking
161
+ import os
162
+
163
+ # 1. Normalize gene symbols and save
164
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
165
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
166
+ normalized_gene_data.to_csv(out_gene_data_file)
167
+
168
+ # 2. Link the clinical and genetic data
169
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
170
+
171
+ # 3. Handle missing values
172
+ linked_data = handle_missing_values(linked_data, trait)
173
+
174
+ # 4. Determine bias and remove biased demographic features
175
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
176
+
177
+ # Determine dataset suitability (detect methylation data via cg probes / CPG_ISLAND annotation)
178
+ is_methylation = False
179
+ try:
180
+ if 'CPG_ISLAND' in gene_annotation.columns:
181
+ is_methylation = True
182
+ if 'ID' in mapping_df.columns and mapping_df['ID'].astype(str).str.startswith('cg').any():
183
+ is_methylation = True
184
+ except Exception:
185
+ pass
186
+ is_gene_available_final = not is_methylation
187
+ is_trait_available_final = True # trait_row existed and clinical features were extracted
188
+
189
+ note_msg = "WARNING: Matrix appears to be DNA methylation (Illumina CpG 'cg' probes); treated as not gene expression for this pipeline."
190
+
191
+ # 5. Final validation and save cohort info
192
+ is_usable = validate_and_save_cohort_info(
193
+ is_final=True,
194
+ cohort=cohort,
195
+ info_path=json_path,
196
+ is_gene_available=is_gene_available_final,
197
+ is_trait_available=is_trait_available_final,
198
+ is_biased=is_trait_biased,
199
+ df=unbiased_linked_data,
200
+ note=note_msg
201
+ )
202
+
203
+ # 6. Save linked data only if usable
204
+ if is_usable:
205
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
206
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Bipolar_disorder/code/GSE45484.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE45484"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE45484"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE45484.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE45484.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE45484.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ # Determine data availability based on provided background and sample characteristics
40
+ is_gene_available = True # Gene expression microarray from whole blood RNA
41
+ trait_row = None # All subjects have bipolar disorder -> trait not variable here
42
+ age_row = 4 # 'age: <number>'
43
+ gender_row = 3 # 'sex: F'/'sex: M'
44
+
45
+ # Converters
46
+ def convert_trait(x):
47
+ # Trait (Bipolar_disorder) is constant in this cohort; mark as unavailable
48
+ return None
49
+
50
+ def _after_colon(val: str) -> str:
51
+ if val is None:
52
+ return ""
53
+ s = str(val)
54
+ return s.split(":", 1)[1].strip() if ":" in s else s.strip()
55
+
56
+ def convert_age(x):
57
+ v = _after_colon(x)
58
+ if v == "" or v.lower() in {"na", "n/a", "nan", "null", "unknown", "?", "none"}:
59
+ return None
60
+ try:
61
+ return float(v)
62
+ except Exception:
63
+ return None
64
+
65
+ def convert_gender(x):
66
+ v = _after_colon(x).strip().lower()
67
+ if v in {"f", "female", "woman", "women"}:
68
+ return 0
69
+ if v in {"m", "male", "man", "men"}:
70
+ return 1
71
+ return None
72
+
73
+ # Initial filtering and save metadata
74
+ is_trait_available = trait_row is not None
75
+ _ = validate_and_save_cohort_info(
76
+ is_final=False,
77
+ cohort=cohort,
78
+ info_path=json_path,
79
+ is_gene_available=is_gene_available,
80
+ is_trait_available=is_trait_available
81
+ )
82
+
83
+ # Clinical feature extraction: only proceed if trait is available (not in this dataset)
84
+ if is_trait_available:
85
+ selected_clinical_df = geo_select_clinical_features(
86
+ clinical_df=clinical_data,
87
+ trait=trait,
88
+ trait_row=trait_row,
89
+ convert_trait=convert_trait,
90
+ age_row=age_row,
91
+ convert_age=convert_age,
92
+ gender_row=gender_row,
93
+ convert_gender=convert_gender
94
+ )
95
+ clinical_preview = preview_df(selected_clinical_df)
96
+ print(clinical_preview)
97
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
98
+ selected_clinical_df.to_csv(out_clinical_data_file, index=True)
99
+
100
+ # Step 3: Gene Data Extraction
101
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
102
+ gene_data = get_genetic_data(matrix_file)
103
+
104
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
105
+ print(gene_data.index[:20])
106
+
107
+ # Step 4: Gene Identifier Review
108
+ # ILMN_* identifiers are Illumina probe IDs, not human gene symbols
109
+ requires_gene_mapping = True
110
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
111
+
112
+ # Step 5: Gene Annotation
113
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
114
+ gene_annotation = get_gene_annotation(soft_file)
115
+
116
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
117
+ print("Gene annotation preview:")
118
+ print(preview_df(gene_annotation))
119
+
120
+ # Step 6: Gene Identifier Mapping
121
+ # Decide identifier and gene symbol columns based on annotation preview
122
+ id_col = 'ID' # ILMN_* probe IDs
123
+ gene_col = 'Symbol' if 'Symbol' in gene_annotation.columns else (
124
+ 'ILMN_Gene' if 'ILMN_Gene' in gene_annotation.columns else None
125
+ )
126
+
127
+ if gene_col is None:
128
+ raise ValueError("No suitable gene symbol column found in annotation (expected 'Symbol' or 'ILMN_Gene').")
129
+
130
+ # 2. Build mapping dataframe
131
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=gene_col)
132
+
133
+ # 3. Apply mapping to convert probe-level data to gene-level expression
134
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
135
+
136
+ # Step 7: Data Normalization and Linking
137
+ import os
138
+ import pandas as pd
139
+
140
+ # 1. Normalize gene symbols and save gene expression data
141
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
142
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
143
+ normalized_gene_data.to_csv(out_gene_data_file)
144
+
145
+ # 2-6. Proceed only if clinical data with trait exists; otherwise perform final validation noting trait unavailability
146
+ has_selected_clinical = (
147
+ ('selected_clinical_data' in globals()) and
148
+ (selected_clinical_data is not None) and
149
+ (not selected_clinical_data.empty) and
150
+ (trait in selected_clinical_data.index)
151
+ )
152
+
153
+ if has_selected_clinical:
154
+ # 2. Link clinical and genetic data
155
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
156
+
157
+ # 3. Handle missing values
158
+ linked_data = handle_missing_values(linked_data, trait)
159
+
160
+ # 4. Bias check and remove biased covariates
161
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
162
+
163
+ # 5. Final quality validation and metadata saving
164
+ is_usable = validate_and_save_cohort_info(
165
+ is_final=True,
166
+ cohort=cohort,
167
+ info_path=json_path,
168
+ is_gene_available=True,
169
+ is_trait_available=True,
170
+ is_biased=is_trait_biased,
171
+ df=unbiased_linked_data,
172
+ note="INFO: Linked clinical-genetic data generated from GEO series."
173
+ )
174
+
175
+ # 6. Save linked data only if usable
176
+ if is_usable:
177
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
178
+ unbiased_linked_data.to_csv(out_data_file)
179
+ else:
180
+ # Trait is unavailable in this cohort (all subjects have Bipolar_disorder); skip linking but record correct metadata
181
+ print("Skipping linking and downstream steps: trait is not available/variable in this cohort.")
182
+ df_for_validation = normalized_gene_data.T # Non-empty placeholder to avoid abnormality override
183
+ _ = validate_and_save_cohort_info(
184
+ is_final=True,
185
+ cohort=cohort,
186
+ info_path=json_path,
187
+ is_gene_available=True,
188
+ is_trait_available=False,
189
+ is_biased=False,
190
+ df=df_for_validation,
191
+ note="INFO: Trait not variable/recorded in this cohort (all subjects have Bipolar_disorder). Only gene data saved."
192
+ )
output/preprocess/Bipolar_disorder/code/GSE46416.py ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE46416"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE46416"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE46416.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE46416.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE46416.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+
42
+ # 1) Gene expression data availability
43
+ is_gene_available = True # Series describes gene expression profiling in blood; not miRNA-only or methylation.
44
+
45
+ # 2) Variable availability and conversion functions
46
+
47
+ # From the provided Sample Characteristics Dictionary:
48
+ # 0: tissue
49
+ # 1: disease status: bipolar disorder (BD) / control
50
+ # 2: bd phase: mania / euthymia
51
+ # 3: patient identifier
52
+ trait_row = 1
53
+ age_row = None
54
+ gender_row = None
55
+
56
+ def _after_colon(x):
57
+ if x is None:
58
+ return None
59
+ s = str(x).strip().strip('"').strip()
60
+ if ':' in s:
61
+ s = s.split(':', 1)[1]
62
+ return s.strip()
63
+
64
+ def convert_trait(x):
65
+ v = _after_colon(x)
66
+ if v is None or v == '':
67
+ return None
68
+ vl = v.lower()
69
+ # Map bipolar disorder cases to 1, controls to 0
70
+ if 'control' in vl:
71
+ return 0
72
+ # capture terms indicating bipolar disorder
73
+ if 'bipolar' in vl or re.search(r'\bbd\b', vl):
74
+ return 1
75
+ return None
76
+
77
+ def convert_age(x):
78
+ # Not available for this cohort; keep here for completeness
79
+ v = _after_colon(x)
80
+ if not v:
81
+ return None
82
+ # extract first float/int number as age in years
83
+ m = re.search(r'(\d+(\.\d+)?)', v)
84
+ return float(m.group(1)) if m else None
85
+
86
+ def convert_gender(x):
87
+ # Not available for this cohort; keep here for completeness
88
+ v = _after_colon(x)
89
+ if not v:
90
+ return None
91
+ vl = v.lower()
92
+ if vl in ['male', 'm']:
93
+ return 1
94
+ if vl in ['female', 'f']:
95
+ return 0
96
+ # handle common encodings
97
+ if 'male' in vl:
98
+ return 1
99
+ if 'female' in vl:
100
+ return 0
101
+ return None
102
+
103
+ # 3) Save metadata (initial filtering)
104
+ is_trait_available = trait_row is not None
105
+ _ = validate_and_save_cohort_info(
106
+ is_final=False,
107
+ cohort=cohort,
108
+ info_path=json_path,
109
+ is_gene_available=is_gene_available,
110
+ is_trait_available=is_trait_available
111
+ )
112
+
113
+ # 4) Clinical feature extraction (only if clinical data is available)
114
+ if trait_row is not None:
115
+ selected_clinical_df = geo_select_clinical_features(
116
+ clinical_df=clinical_data,
117
+ trait=trait,
118
+ trait_row=trait_row,
119
+ convert_trait=convert_trait,
120
+ age_row=age_row,
121
+ convert_age=None,
122
+ gender_row=gender_row,
123
+ convert_gender=None
124
+ )
125
+ clinical_selected_preview = preview_df(selected_clinical_df)
126
+ print(clinical_selected_preview)
127
+
128
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
129
+ selected_clinical_df.to_csv(out_clinical_data_file)
130
+
131
+ # Step 3: Gene Data Extraction
132
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
133
+ gene_data = get_genetic_data(matrix_file)
134
+
135
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
136
+ print(gene_data.index[:20])
137
+
138
+ # Step 4: Gene Identifier Review
139
+ # Based on the provided probe-like numeric IDs (e.g., '2315252'), these are not human gene symbols.
140
+ requires_gene_mapping = True
141
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
142
+
143
+ # Step 5: Gene Annotation
144
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
145
+ gene_annotation = get_gene_annotation(soft_file)
146
+
147
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
148
+ print("Gene annotation preview:")
149
+ print(preview_df(gene_annotation))
150
+
151
+ # Step 6: Gene Identifier Mapping
152
+ # Decide columns for mapping based on annotation preview:
153
+ # Probe/ID column: 'ID' matches gene_data index (e.g., '2315252')
154
+ # Gene symbol column: 'gene_symbol'
155
+ probe_col = 'ID'
156
+ gene_col = 'gene_symbol'
157
+
158
+ # Build mapping dataframe
159
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_col)
160
+
161
+ # Apply mapping to convert probe-level data to gene-level data
162
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
163
+
164
+ # Step 7: Data Normalization and Linking
165
+ import os
166
+
167
+ # 1. Normalize gene symbols and save
168
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
169
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
170
+ normalized_gene_data.to_csv(out_gene_data_file)
171
+
172
+ # 2. Link clinical and genetic data
173
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
174
+
175
+ # 3. Handle missing values
176
+ linked_data = handle_missing_values(linked_data, trait)
177
+
178
+ # 4. Determine bias; guard against empty dataframe after missing-value handling
179
+ if linked_data.shape[0] == 0:
180
+ is_trait_biased = True
181
+ unbiased_linked_data = linked_data
182
+ else:
183
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
184
+
185
+ # 5. Final quality validation and save cohort info
186
+ # Ensure Python-native bools for JSON serialization
187
+ is_gene_available_final = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
188
+ is_trait_available_final = bool((trait in selected_clinical_df.index) and bool(selected_clinical_df.loc[trait].notna().any()))
189
+
190
+ # If the linked data is empty after processing, mark availability flags as False
191
+ if unbiased_linked_data.shape[0] == 0:
192
+ is_gene_available_final = False
193
+ # trait info might still exist in clinical, but dataset is unusable for analysis without samples
194
+ # Keep trait flag as is to record availability; validate_and_save_cohort_info will also re-check
195
+ is_trait_biased = bool(is_trait_biased)
196
+
197
+ is_usable = validate_and_save_cohort_info(
198
+ is_final=True,
199
+ cohort=cohort,
200
+ info_path=json_path,
201
+ is_gene_available=is_gene_available_final,
202
+ is_trait_available=is_trait_available_final,
203
+ is_biased=is_trait_biased,
204
+ df=unbiased_linked_data,
205
+ note="INFO: Gene-level mapping may be sparse; platform annotation had limited gene_symbol entries."
206
+ )
207
+
208
+ # 6. Save linked data if usable
209
+ if is_usable:
210
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
211
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Bipolar_disorder/code/GSE46449.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE46449"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE46449"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE46449.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE46449.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE46449.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+
42
+ # 1) Gene expression availability
43
+ is_gene_available = True # Affymetrix microarray gene expression (not miRNA/methylation)
44
+
45
+ # 2) Variable availability (rows) inferred from sample characteristics
46
+ trait_row = 1 # 'genotype: bipolar patient' / 'genotype: control subject'
47
+ age_row = 2 # 'age: <number>'
48
+ gender_row = None # Only 'gender: male' observed -> constant, not useful
49
+
50
+ # 2) Conversion functions
51
+ def _after_colon(x):
52
+ if x is None:
53
+ return None
54
+ if not isinstance(x, str):
55
+ return None
56
+ parts = x.split(":", 1)
57
+ val = parts[1] if len(parts) > 1 else parts[0]
58
+ return val.strip()
59
+
60
+ def convert_trait(x):
61
+ v = _after_colon(x)
62
+ if v is None:
63
+ return None
64
+ vl = v.lower()
65
+ if any(k in vl for k in ['control', 'healthy', 'normal']):
66
+ return 0
67
+ if ('bipolar' in vl) or ('bpd' in vl) or ('bp ' in vl) or (vl == 'bp') or ('patient' in vl) or ('case' in vl):
68
+ return 1
69
+ return None
70
+
71
+ def convert_age(x):
72
+ v = _after_colon(x)
73
+ if v is None:
74
+ return None
75
+ nums = re.findall(r'[-+]?\d*\.?\d+', v)
76
+ if not nums:
77
+ return None
78
+ try:
79
+ age_val = float(nums[0])
80
+ if 0 <= age_val <= 120:
81
+ return age_val
82
+ except Exception:
83
+ pass
84
+ return None
85
+
86
+ def convert_gender(x):
87
+ v = _after_colon(x)
88
+ if v is None:
89
+ return None
90
+ vl = v.lower()
91
+ if 'female' in vl or vl == 'f':
92
+ return 0
93
+ if 'male' in vl or vl == 'm':
94
+ return 1
95
+ return None
96
+
97
+ # 3) Save metadata (initial filtering)
98
+ is_trait_available = trait_row is not None
99
+ _ = validate_and_save_cohort_info(
100
+ is_final=False,
101
+ cohort=cohort,
102
+ info_path=json_path,
103
+ is_gene_available=is_gene_available,
104
+ is_trait_available=is_trait_available
105
+ )
106
+
107
+ # 4) Clinical feature extraction (only if trait is available)
108
+ if trait_row is not None:
109
+ clinical_selected_df = geo_select_clinical_features(
110
+ clinical_df=clinical_data,
111
+ trait=trait,
112
+ trait_row=trait_row,
113
+ convert_trait=convert_trait,
114
+ age_row=age_row,
115
+ convert_age=convert_age,
116
+ gender_row=gender_row,
117
+ convert_gender=convert_gender
118
+ )
119
+ preview = preview_df(clinical_selected_df)
120
+ print(preview)
121
+
122
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
123
+ clinical_selected_df.to_csv(out_clinical_data_file)
124
+
125
+ # Step 3: Gene Data Extraction
126
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
127
+ gene_data = get_genetic_data(matrix_file)
128
+
129
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
130
+ print(gene_data.index[:20])
131
+
132
+ # Step 4: Gene Identifier Review
133
+ print("requires_gene_mapping = True")
134
+
135
+ # Step 5: Gene Annotation
136
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
137
+ gene_annotation = get_gene_annotation(soft_file)
138
+
139
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
140
+ print("Gene annotation preview:")
141
+ print(preview_df(gene_annotation))
142
+
143
+ # Step 6: Gene Identifier Mapping
144
+ # 1-2. Identify columns for probe IDs and gene symbols, then build mapping dataframe
145
+ probe_col = 'ID' # Matches probe IDs in the expression data (e.g., '1007_s_at')
146
+ gene_symbol_col = 'Gene Symbol' # Contains gene symbols (may include multiple symbols separated by delimiters)
147
+
148
+ mapping_df = get_gene_mapping(annotation=gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
149
+
150
+ # 3. Apply mapping to convert probe-level data to gene-level expression
151
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
152
+
153
+ # Step 7: Data Normalization and Linking
154
+ import os
155
+ import pandas as pd
156
+
157
+ # 1. Normalize gene symbols and save gene expression data
158
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
159
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
160
+ normalized_gene_data.to_csv(out_gene_data_file)
161
+
162
+ # 2. Link the clinical and genetic data
163
+ try:
164
+ clinical_df_link = clinical_selected_df
165
+ except NameError:
166
+ clinical_df_link = pd.read_csv(out_clinical_data_file, index_col=0)
167
+
168
+ linked_data = geo_link_clinical_genetic_data(clinical_df_link, normalized_gene_data)
169
+
170
+ # 3. Handle missing values
171
+ linked_data = handle_missing_values(linked_data, trait)
172
+
173
+ # 4. Determine bias and remove biased demographic features
174
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
175
+
176
+ # 5. Final validation and save cohort info
177
+ note = "INFO: Gender not available (constant) in source; not included."
178
+ is_usable = validate_and_save_cohort_info(
179
+ is_final=True,
180
+ cohort=cohort,
181
+ info_path=json_path,
182
+ is_gene_available=True,
183
+ is_trait_available=True,
184
+ is_biased=is_trait_biased,
185
+ df=unbiased_linked_data,
186
+ note=note
187
+ )
188
+
189
+ # 6. Save linked data if usable
190
+ if is_usable:
191
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
192
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Bipolar_disorder/code/GSE53987.py ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE53987"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE53987"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE53987.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE53987.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE53987.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import pandas as pd
41
+
42
+ # 1) Gene expression data availability
43
+ is_gene_available = True # Affymetrix U133 Plus 2.0 microarray => mRNA gene expression
44
+
45
+ # 2) Variable availability and converters
46
+
47
+ # Data availability (row indices from Sample Characteristics Dictionary)
48
+ trait_row = 7 # 'disease state'
49
+ age_row = 0 # 'age'
50
+ gender_row = 1 # 'gender'
51
+
52
+ def _after_colon(x):
53
+ if x is None:
54
+ return None
55
+ s = str(x)
56
+ if ':' in s:
57
+ val = s.split(':', 1)[1]
58
+ else:
59
+ val = s
60
+ return val.strip()
61
+
62
+ def convert_trait(x):
63
+ val = _after_colon(x)
64
+ if val is None:
65
+ return None
66
+ v = val.strip().lower()
67
+ # map to binary: Bipolar_disorder case=1, control=0, other diagnoses excluded
68
+ if 'bipolar' in v or v in {'bpd', 'bp', 'bd'}:
69
+ return 1
70
+ if v in {'control', 'healthy', 'normal'}:
71
+ return 0
72
+ # exclude other psychiatric diagnoses (e.g., schizophrenia, MDD)
73
+ return None
74
+
75
+ def convert_age(x):
76
+ val = _after_colon(x)
77
+ if val is None:
78
+ return None
79
+ v = val.strip().lower()
80
+ if v in {'na', 'n/a', 'unknown', ''}:
81
+ return None
82
+ try:
83
+ # prefer integer if clean, else float
84
+ f = float(v)
85
+ return int(f) if f.is_integer() else f
86
+ except Exception:
87
+ return None
88
+
89
+ def convert_gender(x):
90
+ val = _after_colon(x)
91
+ if val is None:
92
+ return None
93
+ v = val.strip().lower()
94
+ if v in {'female', 'f'}:
95
+ return 0
96
+ if v in {'male', 'm'}:
97
+ return 1
98
+ return None
99
+
100
+ # 3) Save metadata (initial filtering)
101
+ is_trait_available = trait_row is not None
102
+ _ = validate_and_save_cohort_info(
103
+ is_final=False,
104
+ cohort=cohort,
105
+ info_path=json_path,
106
+ is_gene_available=is_gene_available,
107
+ is_trait_available=is_trait_available
108
+ )
109
+
110
+ # 4) Clinical feature extraction (only if clinical data available)
111
+ if trait_row is not None:
112
+ selected_clinical_df = geo_select_clinical_features(
113
+ clinical_df=clinical_data,
114
+ trait=trait,
115
+ trait_row=trait_row,
116
+ convert_trait=convert_trait,
117
+ age_row=age_row,
118
+ convert_age=convert_age,
119
+ gender_row=gender_row,
120
+ convert_gender=convert_gender
121
+ )
122
+ preview = preview_df(selected_clinical_df, n=5)
123
+ print(preview)
124
+
125
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
126
+ selected_clinical_df.to_csv(out_clinical_data_file)
127
+
128
+ # Step 3: Gene Data Extraction
129
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
130
+ gene_data = get_genetic_data(matrix_file)
131
+
132
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
133
+ print(gene_data.index[:20])
134
+
135
+ # Step 4: Gene Identifier Review
136
+ # The gene identifiers like "1007_s_at", "1552258_at" are Affymetrix probe set IDs, not HGNC gene symbols.
137
+ requires_gene_mapping = True
138
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
139
+
140
+ # Step 5: Gene Annotation
141
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
142
+ gene_annotation = get_gene_annotation(soft_file)
143
+
144
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
145
+ print("Gene annotation preview:")
146
+ print(preview_df(gene_annotation))
147
+
148
+ # Step 6: Gene Identifier Mapping
149
+ # 1-2) Identify mapping columns and build probe-to-gene mapping dataframe
150
+ probe_col = 'ID' # Matches probe IDs in expression data (e.g., '1007_s_at')
151
+ gene_symbol_col = 'Gene Symbol' # Column with gene symbols in annotation
152
+
153
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
154
+
155
+ # 3) Apply mapping to convert probe-level data to gene-level expression
156
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
157
+
158
+ # Step 7: Data Normalization and Linking
159
+ import os
160
+
161
+ # 1. Normalize gene symbols and save
162
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
163
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
164
+ normalized_gene_data.to_csv(out_gene_data_file)
165
+
166
+ # 2. Link clinical and genetic data
167
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
168
+
169
+ # 3. Handle missing values
170
+ linked_data = handle_missing_values(linked_data, trait)
171
+
172
+ # 4. Bias assessment and removal of biased demographics
173
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
174
+
175
+ # 5. Final validation and save cohort info using actual availability indicators
176
+ is_gene_available_final = (normalized_gene_data is not None) and (normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0)
177
+ is_trait_available_final = (('trait_row' in globals()) and (trait_row is not None)) and (('selected_clinical_df' in globals()) and (trait in selected_clinical_df.index))
178
+
179
+ note = ("INFO: Trait constructed as bipolar disorder (case=1) vs control (0); "
180
+ "samples with other diagnoses (schizophrenia/MDD) were set to missing and removed during preprocessing. "
181
+ "Multiple brain regions are present; no tissue harmonization performed here.")
182
+
183
+ is_usable = validate_and_save_cohort_info(
184
+ is_final=True,
185
+ cohort=cohort,
186
+ info_path=json_path,
187
+ is_gene_available=is_gene_available_final,
188
+ is_trait_available=is_trait_available_final,
189
+ is_biased=is_trait_biased,
190
+ df=unbiased_linked_data,
191
+ note=note
192
+ )
193
+
194
+ # 6. Save linked data if usable
195
+ if is_usable:
196
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
197
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Bipolar_disorder/code/GSE62191.py ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE62191"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE62191"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE62191.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE62191.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE62191.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+ import pandas as pd
42
+
43
+ # 1) Gene expression availability
44
+ is_gene_available = True # Based on series title/summary indicating mRNA gene expression profiling
45
+
46
+ # 2) Variable availability and converters
47
+ # From Sample Characteristics:
48
+ # - trait_row: 1 ('disease state: healthy control' | 'bipolar disorder' | 'schizophrenia')
49
+ # - age_row: 2 ('age: XX yr')
50
+ # - gender_row: None (only 'gender: male' observed; constant feature -> not useful)
51
+ trait_row = 1
52
+ age_row = 2
53
+ gender_row = None
54
+
55
+ def convert_trait(x):
56
+ # Map bipolar disorder to 1; treat schizophrenia and healthy controls as non-BD (0)
57
+ if x is None or (isinstance(x, float) and pd.isna(x)):
58
+ return None
59
+ val = str(x)
60
+ if ':' in val:
61
+ val = val.split(':', 1)[1]
62
+ v = val.strip().lower()
63
+ if 'bipolar' in v:
64
+ return 1
65
+ if ('healthy' in v) or ('control' in v):
66
+ return 0
67
+ if 'schizo' in v:
68
+ return 0
69
+ return None
70
+
71
+ def convert_age(x):
72
+ if x is None or (isinstance(x, float) and pd.isna(x)):
73
+ return None
74
+ val = str(x)
75
+ if ':' in val:
76
+ val = val.split(':', 1)[1]
77
+ m = re.search(r'(\d+(\.\d+)?)', val)
78
+ if m:
79
+ try:
80
+ num = float(m.group(1))
81
+ return num
82
+ except Exception:
83
+ return None
84
+ return None
85
+
86
+ def convert_gender(x):
87
+ if x is None or (isinstance(x, float) and pd.isna(x)):
88
+ return None
89
+ val = str(x)
90
+ if ':' in val:
91
+ val = val.split(':', 1)[1]
92
+ v = val.strip().lower()
93
+ if 'female' in v:
94
+ return 0
95
+ if 'male' in v:
96
+ return 1
97
+ return None
98
+
99
+ # 3) Save metadata (initial filtering)
100
+ is_trait_available = trait_row is not None
101
+ _ = validate_and_save_cohort_info(
102
+ is_final=False,
103
+ cohort=cohort,
104
+ info_path=json_path,
105
+ is_gene_available=is_gene_available,
106
+ is_trait_available=is_trait_available
107
+ )
108
+
109
+ # 4) Clinical feature extraction (only if trait is available)
110
+ if trait_row is not None:
111
+ selected_clinical_df = geo_select_clinical_features(
112
+ clinical_df=clinical_data,
113
+ trait=trait,
114
+ trait_row=trait_row,
115
+ convert_trait=convert_trait,
116
+ age_row=age_row,
117
+ convert_age=convert_age,
118
+ gender_row=gender_row,
119
+ convert_gender=convert_gender
120
+ )
121
+ clinical_preview = preview_df(selected_clinical_df)
122
+ print(clinical_preview)
123
+ print(f"Selected clinical features shape: {selected_clinical_df.shape}")
124
+
125
+ # Save clinical data
126
+ out_dir = os.path.dirname(out_clinical_data_file)
127
+ os.makedirs(out_dir, exist_ok=True)
128
+ selected_clinical_df.to_csv(out_clinical_data_file)
129
+
130
+ # Step 3: Gene Data Extraction
131
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
132
+ gene_data = get_genetic_data(matrix_file)
133
+
134
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
135
+ print(gene_data.index[:20])
136
+
137
+ # Step 4: Gene Identifier Review
138
+ print("requires_gene_mapping = True")
139
+
140
+ # Step 5: Gene Annotation
141
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
142
+ gene_annotation = get_gene_annotation(soft_file)
143
+
144
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
145
+ print("Gene annotation preview:")
146
+ print(preview_df(gene_annotation))
147
+
148
+ # Step 6: Gene Identifier Mapping
149
+ # 1-2) Decide columns and create mapping dataframe
150
+ prob_col = 'ID' # Matches probe IDs in gene_data (numeric strings like '12', '13', ...)
151
+ gene_col = 'GENE_SYMBOL' # Stores human gene symbols
152
+
153
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=prob_col, gene_col=gene_col)
154
+
155
+ # 3) Apply mapping to convert probe-level data to gene-level expression
156
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
157
+
158
+ # Step 7: Data Normalization and Linking
159
+ import os
160
+ import pandas as pd
161
+ from json import JSONDecodeError
162
+
163
+ # 1. Normalize gene symbols and save gene data
164
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
165
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
166
+ normalized_gene_data.to_csv(out_gene_data_file)
167
+
168
+ # 2. Ensure clinical data is available in this step: reload if needed
169
+ try:
170
+ selected_clinical_df
171
+ except NameError:
172
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
173
+
174
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
175
+
176
+ # 3. Handle missing values
177
+ linked_data = handle_missing_values(linked_data, trait)
178
+
179
+ # 4. Bias assessment and removal of biased demographics
180
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
181
+
182
+ # 5. Final quality validation and save cohort info
183
+ is_gene_available_final = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
184
+ is_trait_available_final = bool((trait in linked_data.columns) and (linked_data[trait].notna().any()))
185
+ is_trait_biased_bool = bool(is_trait_biased)
186
+
187
+ note = "INFO: Age available; Gender not available in clinical annotations for this series."
188
+
189
+ def run_validate():
190
+ return validate_and_save_cohort_info(
191
+ is_final=True,
192
+ cohort=cohort,
193
+ info_path=json_path,
194
+ is_gene_available=is_gene_available_final,
195
+ is_trait_available=is_trait_available_final,
196
+ is_biased=is_trait_biased_bool,
197
+ df=unbiased_linked_data,
198
+ note=note
199
+ )
200
+
201
+ try:
202
+ is_usable = run_validate()
203
+ except (TypeError, JSONDecodeError):
204
+ # Repair/reset JSON file and retry
205
+ os.makedirs(os.path.dirname(json_path), exist_ok=True)
206
+ with open(json_path, "w") as f:
207
+ f.write("{}")
208
+ is_usable = run_validate()
209
+
210
+ # 6. Save linked data if usable
211
+ if is_usable:
212
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
213
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Bipolar_disorder/code/GSE67311.py ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE67311"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE67311"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE67311.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE67311.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE67311.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+ import pandas as pd
42
+
43
+ # 1. Gene Expression Data Availability
44
+ is_gene_available = True # Affymetrix Human Gene 1.1 ST arrays indicate gene expression data.
45
+
46
+ # 2. Variable Availability and Data Type Conversion
47
+
48
+ # 2.1 Data Availability based on the provided Sample Characteristics Dictionary
49
+ trait_row = 7 # 'bipolar disorder: Yes/No/-'
50
+ age_row = None # Not available in the provided dictionary
51
+ gender_row = None # Not available in the provided dictionary
52
+
53
+ # 2.2 Data Type Conversion functions
54
+ def _extract_value(x):
55
+ if x is None:
56
+ return None
57
+ if isinstance(x, str):
58
+ parts = x.split(":", 1)
59
+ val = parts[1] if len(parts) > 1 else parts[0]
60
+ return val.strip()
61
+ return x
62
+
63
+ def convert_trait(x):
64
+ v = _extract_value(x)
65
+ if v is None or v == '' or v in {'-', 'na', 'n/a', 'unknown', 'NA', 'N/A', 'Unknown'}:
66
+ return None
67
+ v_low = str(v).strip().lower()
68
+ if v_low in {'yes', 'y', 'true', '1'}:
69
+ return 1
70
+ if v_low in {'no', 'n', 'false', '0'}:
71
+ return 0
72
+ return None
73
+
74
+ def convert_age(x):
75
+ # Not used (age_row is None); implemented for completeness.
76
+ v = _extract_value(x)
77
+ if v is None or v == '' or str(v).strip().lower() in {'-', 'na', 'n/a', 'unknown'}:
78
+ return None
79
+ try:
80
+ # Extract first numeric occurrence
81
+ num = re.findall(r"[-+]?\d*\.?\d+", str(v))
82
+ return float(num[0]) if num else None
83
+ except Exception:
84
+ return None
85
+
86
+ def convert_gender(x):
87
+ # Not used (gender_row is None); implemented for completeness.
88
+ v = _extract_value(x)
89
+ if v is None or v == '' or str(v).strip().lower() in {'-', 'na', 'n/a', 'unknown'}:
90
+ return None
91
+ v_low = str(v).strip().lower()
92
+ if v_low in {'female', 'f', '0'}:
93
+ return 0
94
+ if v_low in {'male', 'm', '1'}:
95
+ return 1
96
+ return None
97
+
98
+ # 3. Save Metadata (initial filtering)
99
+ is_trait_available = trait_row is not None
100
+ _ = validate_and_save_cohort_info(
101
+ is_final=False,
102
+ cohort=cohort,
103
+ info_path=json_path,
104
+ is_gene_available=is_gene_available,
105
+ is_trait_available=is_trait_available
106
+ )
107
+
108
+ # 4. Clinical Feature Extraction (only if trait_row is not None)
109
+ if trait_row is not None:
110
+ selected_clinical_df = geo_select_clinical_features(
111
+ clinical_df=clinical_data,
112
+ trait=trait,
113
+ trait_row=trait_row,
114
+ convert_trait=convert_trait,
115
+ age_row=age_row,
116
+ convert_age=convert_age,
117
+ gender_row=gender_row,
118
+ convert_gender=convert_gender
119
+ )
120
+ preview = preview_df(selected_clinical_df)
121
+ print(preview)
122
+
123
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
124
+ selected_clinical_df.to_csv(out_clinical_data_file)
125
+
126
+ # Step 3: Gene Data Extraction
127
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
128
+ gene_data = get_genetic_data(matrix_file)
129
+
130
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
131
+ print(gene_data.index[:20])
132
+
133
+ # Step 4: Gene Identifier Review
134
+ print("requires_gene_mapping = True")
135
+
136
+ # Step 5: Gene Annotation
137
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
138
+ gene_annotation = get_gene_annotation(soft_file)
139
+
140
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
141
+ print("Gene annotation preview:")
142
+ print(preview_df(gene_annotation))
143
+
144
+ # Step 6: Gene Identifier Mapping
145
+ # Decide columns: probe IDs are in 'ID'; gene info (symbols embedded) is in 'gene_assignment'
146
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='gene_assignment')
147
+
148
+ # Apply mapping to convert probe-level data to gene-level expression
149
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
150
+
151
+ # Step 7: Data Normalization and Linking
152
+ import os
153
+
154
+ # 1. Normalize gene symbols and save gene data
155
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
156
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
157
+ normalized_gene_data.to_csv(out_gene_data_file)
158
+
159
+ # 2. Link the clinical and genetic data
160
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
161
+
162
+ # 3. Handle missing values in the linked data
163
+ linked_data = handle_missing_values(linked_data, trait)
164
+
165
+ # 4. Determine whether the trait and demographic features are biased; remove biased demographics
166
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
167
+
168
+ # 5. Final quality validation and save metadata
169
+ covariate_cols_present = [c for c in [trait, 'Age', 'Gender'] if c in unbiased_linked_data.columns]
170
+ gene_cols_present = [c for c in unbiased_linked_data.columns if c not in covariate_cols_present]
171
+ is_trait_available = bool((trait in unbiased_linked_data.columns) and unbiased_linked_data[trait].notna().any())
172
+ is_gene_available = bool(len(gene_cols_present) > 0)
173
+ is_trait_biased = bool(is_trait_biased)
174
+
175
+ note = "INFO: Mapped Affymetrix Human Gene 1.1 ST probe IDs to gene symbols; no age/gender available in sample characteristics."
176
+
177
+ # Retry logic to avoid JSON serialization issues due to a corrupted/legacy file
178
+ try:
179
+ is_usable = validate_and_save_cohort_info(
180
+ is_final=True,
181
+ cohort=cohort,
182
+ info_path=json_path,
183
+ is_gene_available=is_gene_available,
184
+ is_trait_available=is_trait_available,
185
+ is_biased=is_trait_biased,
186
+ df=unbiased_linked_data,
187
+ note=note
188
+ )
189
+ except Exception:
190
+ # Remove possibly corrupted JSON and retry once
191
+ if os.path.exists(json_path):
192
+ os.remove(json_path)
193
+ is_usable = validate_and_save_cohort_info(
194
+ is_final=True,
195
+ cohort=cohort,
196
+ info_path=json_path,
197
+ is_gene_available=is_gene_available,
198
+ is_trait_available=is_trait_available,
199
+ is_biased=is_trait_biased,
200
+ df=unbiased_linked_data,
201
+ note=note
202
+ )
203
+
204
+ # 6. Save linked data if usable
205
+ if is_usable:
206
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
207
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Bipolar_disorder/code/GSE92538.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Bipolar_disorder"
6
+ cohort = "GSE92538"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Bipolar_disorder"
10
+ in_cohort_dir = "../DATA/GEO/Bipolar_disorder/GSE92538"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z1/preprocess/Bipolar_disorder/GSE92538.csv"
14
+ out_gene_data_file = "./output/z1/preprocess/Bipolar_disorder/gene_data/GSE92538.csv"
15
+ out_clinical_data_file = "./output/z1/preprocess/Bipolar_disorder/clinical_data/GSE92538.csv"
16
+ json_path = "./output/z1/preprocess/Bipolar_disorder/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import pandas as pd
41
+
42
+ # 1) Gene expression data availability
43
+ is_gene_available = True # Affymetrix U133 microarray gene expression per background info
44
+
45
+ # 2) Variable availability and conversion functions
46
+ trait_row = 2 # 'diagnosis' with categories including 'Bipolar Disorder'
47
+ age_row = 8 # 'age'
48
+ gender_row = 6 # 'gender'
49
+
50
+ def _after_colon(x: str) -> str:
51
+ if x is None:
52
+ return ""
53
+ parts = str(x).split(":", 1)
54
+ return parts[1].strip() if len(parts) > 1 else str(x).strip()
55
+
56
+ def convert_trait(x):
57
+ val = _after_colon(x).lower()
58
+ if val in {"bipolar disorder", "bipolar"}:
59
+ return 1
60
+ if val in {"control", "healthy control"}:
61
+ return 0
62
+ # Other diagnoses are not part of the binary trait for Bipolar Disorder
63
+ return None
64
+
65
+ def convert_age(x):
66
+ val = _after_colon(x)
67
+ if val in {"", "na", "NA", None}:
68
+ return None
69
+ try:
70
+ age = float(val)
71
+ # human plausible range
72
+ if 0 <= age <= 120:
73
+ return age
74
+ except Exception:
75
+ pass
76
+ return None
77
+
78
+ def convert_gender(x):
79
+ val = _after_colon(x).lower()
80
+ if val in {"f", "female"}:
81
+ return 0
82
+ if val in {"m", "male"}:
83
+ return 1
84
+ return None
85
+
86
+ # 3) Save metadata (initial filtering)
87
+ is_trait_available = trait_row is not None
88
+ _ = validate_and_save_cohort_info(
89
+ is_final=False,
90
+ cohort=cohort,
91
+ info_path=json_path,
92
+ is_gene_available=is_gene_available,
93
+ is_trait_available=is_trait_available
94
+ )
95
+
96
+ # 4) Clinical feature extraction (only if trait data available)
97
+ if trait_row is not None:
98
+ selected_clinical_df = geo_select_clinical_features(
99
+ clinical_df=clinical_data,
100
+ trait=trait,
101
+ trait_row=trait_row,
102
+ convert_trait=convert_trait,
103
+ age_row=age_row,
104
+ convert_age=convert_age,
105
+ gender_row=gender_row,
106
+ convert_gender=convert_gender
107
+ )
108
+ preview = preview_df(selected_clinical_df, n=5)
109
+ print(preview)
110
+
111
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
112
+ selected_clinical_df.to_csv(out_clinical_data_file)
113
+
114
+ # Step 3: Gene Data Extraction
115
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
116
+ gene_data = get_genetic_data(matrix_file)
117
+
118
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
119
+ print(gene_data.index[:20])
120
+
121
+ # Step 4: Gene Identifier Review
122
+ requires_gene_mapping = True
123
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
124
+
125
+ # Step 5: Gene Annotation
126
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
127
+ gene_annotation = get_gene_annotation(soft_file)
128
+
129
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
130
+ print("Gene annotation preview:")
131
+ print(preview_df(gene_annotation))
132
+
133
+ # Step 6: Gene Identifier Mapping
134
+ # Decide annotation columns: probe IDs are in 'ID'; gene symbols are in 'SYMBOL'
135
+ id_col = 'ID'
136
+ gene_symbol_col = 'SYMBOL'
137
+
138
+ # 2) Build mapping dataframe (columns: 'ID' and 'Gene')
139
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=gene_symbol_col)
140
+
141
+ # 3) Apply mapping to convert probe-level to gene-level expression
142
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
143
+
144
+ # Step 7: Data Normalization and Linking
145
+ import os
146
+
147
+ # 1. Normalize gene symbols and save gene data
148
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
149
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
150
+ normalized_gene_data.to_csv(out_gene_data_file)
151
+
152
+ # 2. Link clinical and genetic data
153
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
154
+
155
+ # 3. Handle missing values
156
+ linked_data = handle_missing_values(linked_data, trait)
157
+
158
+ # 4. Bias evaluation and removal of biased demographic features
159
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
160
+
161
+ # Determine availability flags robustly
162
+ gene_available_flag = (normalized_gene_data.shape[0] > 0 and normalized_gene_data.shape[1] > 0)
163
+ trait_available_flag = (trait in linked_data.columns)
164
+
165
+ try:
166
+ iga = is_gene_available
167
+ except NameError:
168
+ iga = gene_available_flag
169
+
170
+ try:
171
+ ita = is_trait_available
172
+ except NameError:
173
+ ita = trait_available_flag
174
+
175
+ # 5. Final validation and save cohort info
176
+ note_text = ("INFO: Diagnosis converted to binary trait (Bipolar Disorder=1, Control=0); "
177
+ "other diagnoses set to None prior to missing-value handling. "
178
+ "Gene symbols normalized using NCBI synonym mapping.")
179
+ is_usable = validate_and_save_cohort_info(
180
+ is_final=True,
181
+ cohort=cohort,
182
+ info_path=json_path,
183
+ is_gene_available=iga,
184
+ is_trait_available=ita,
185
+ is_biased=is_trait_biased,
186
+ df=unbiased_linked_data,
187
+ note=note_text
188
+ )
189
+
190
+ # 6. Save linked data if usable
191
+ if is_usable:
192
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
193
+ unbiased_linked_data.to_csv(out_data_file)