Liu-Hy commited on
Commit
9ffee36
·
verified ·
1 Parent(s): 4170dd3

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 +19 -0
  2. p1/preprocess/Sjögrens_Syndrome/gene_data/GSE140161.csv +3 -0
  3. p1/preprocess/Testicular_Cancer/gene_data/TCGA.csv +3 -0
  4. p1/preprocess/Thymoma/gene_data/TCGA.csv +3 -0
  5. p1/preprocess/Thyroid_Cancer/gene_data/GSE107754.csv +3 -0
  6. p1/preprocess/Thyroid_Cancer/gene_data/GSE151179.csv +3 -0
  7. p1/preprocess/Thyroid_Cancer/gene_data/GSE80022.csv +3 -0
  8. p1/preprocess/Thyroid_Cancer/gene_data/GSE82208.csv +3 -0
  9. p1/preprocess/Type_1_Diabetes/GSE156035.csv +3 -0
  10. p1/preprocess/Type_1_Diabetes/GSE193273.csv +3 -0
  11. p1/preprocess/Type_1_Diabetes/GSE232310.csv +3 -0
  12. p1/preprocess/Type_1_Diabetes/code/TCGA.py +73 -0
  13. p1/preprocess/Type_1_Diabetes/gene_data/GSE156035.csv +3 -0
  14. p1/preprocess/Type_1_Diabetes/gene_data/GSE193273.csv +3 -0
  15. p1/preprocess/Type_1_Diabetes/gene_data/GSE232310.csv +3 -0
  16. p1/preprocess/Type_2_Diabetes/GSE182120.csv +3 -0
  17. p1/preprocess/Type_2_Diabetes/GSE281144.csv +3 -0
  18. p1/preprocess/Type_2_Diabetes/clinical_data/GSE180393.csv +2 -0
  19. p1/preprocess/Type_2_Diabetes/clinical_data/GSE180394.csv +2 -0
  20. p1/preprocess/Type_2_Diabetes/clinical_data/GSE180395.csv +2 -0
  21. p1/preprocess/Type_2_Diabetes/clinical_data/GSE182120.csv +3 -0
  22. p1/preprocess/Type_2_Diabetes/clinical_data/GSE182121.csv +3 -0
  23. p1/preprocess/Type_2_Diabetes/clinical_data/GSE250283.csv +3 -0
  24. p1/preprocess/Type_2_Diabetes/clinical_data/GSE281144.csv +3 -0
  25. p1/preprocess/Type_2_Diabetes/code/GSE180393.py +173 -0
  26. p1/preprocess/Type_2_Diabetes/code/GSE180394.py +157 -0
  27. p1/preprocess/Type_2_Diabetes/code/GSE180395.py +185 -0
  28. p1/preprocess/Type_2_Diabetes/code/GSE182120.py +174 -0
  29. p1/preprocess/Type_2_Diabetes/code/GSE182121.py +211 -0
  30. p1/preprocess/Type_2_Diabetes/code/GSE227080.py +128 -0
  31. p1/preprocess/Type_2_Diabetes/code/GSE250283.py +187 -0
  32. p1/preprocess/Type_2_Diabetes/code/GSE271700.py +173 -0
  33. p1/preprocess/Type_2_Diabetes/code/GSE281144.py +172 -0
  34. p1/preprocess/Type_2_Diabetes/code/GSE98887.py +82 -0
  35. p1/preprocess/Type_2_Diabetes/code/TCGA.py +58 -0
  36. p1/preprocess/Type_2_Diabetes/cohort_info.json +1 -0
  37. p1/preprocess/Type_2_Diabetes/gene_data/GSE180393.csv +1 -0
  38. p1/preprocess/Type_2_Diabetes/gene_data/GSE180394.csv +1 -0
  39. p1/preprocess/Type_2_Diabetes/gene_data/GSE180395.csv +1 -0
  40. p1/preprocess/Type_2_Diabetes/gene_data/GSE182120.csv +3 -0
  41. p1/preprocess/Type_2_Diabetes/gene_data/GSE182121.csv +1 -0
  42. p1/preprocess/Type_2_Diabetes/gene_data/GSE227080.csv +0 -0
  43. p1/preprocess/Type_2_Diabetes/gene_data/GSE250283.csv +3 -0
  44. p1/preprocess/Type_2_Diabetes/gene_data/GSE271700.csv +1 -0
  45. p1/preprocess/Type_2_Diabetes/gene_data/GSE281144.csv +3 -0
  46. p1/preprocess/Underweight/GSE57802.csv +3 -0
  47. p1/preprocess/Underweight/clinical_data/GSE130563.csv +4 -0
  48. p1/preprocess/Underweight/clinical_data/GSE57802.csv +4 -0
  49. p1/preprocess/Underweight/code/GSE130563.py +163 -0
  50. p1/preprocess/Underweight/code/GSE131835.py +173 -0
.gitattributes CHANGED
@@ -879,3 +879,22 @@ p1/preprocess/Thymoma/gene_data/GSE131027.csv filter=lfs diff=lfs merge=lfs -tex
879
  p1/preprocess/Prostate_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
880
  p1/preprocess/Thyroid_Cancer/GSE80022.csv filter=lfs diff=lfs merge=lfs -text
881
  p1/preprocess/Thyroid_Cancer/gene_data/GSE138198.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
879
  p1/preprocess/Prostate_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
880
  p1/preprocess/Thyroid_Cancer/GSE80022.csv filter=lfs diff=lfs merge=lfs -text
881
  p1/preprocess/Thyroid_Cancer/gene_data/GSE138198.csv filter=lfs diff=lfs merge=lfs -text
882
+ p1/preprocess/Thymoma/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
883
+ p1/preprocess/Thyroid_Cancer/gene_data/GSE82208.csv filter=lfs diff=lfs merge=lfs -text
884
+ p1/preprocess/Thyroid_Cancer/gene_data/GSE80022.csv filter=lfs diff=lfs merge=lfs -text
885
+ p1/preprocess/Testicular_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
886
+ p1/preprocess/Type_1_Diabetes/GSE156035.csv filter=lfs diff=lfs merge=lfs -text
887
+ p1/preprocess/Thyroid_Cancer/gene_data/GSE151179.csv filter=lfs diff=lfs merge=lfs -text
888
+ p1/preprocess/Type_1_Diabetes/GSE193273.csv filter=lfs diff=lfs merge=lfs -text
889
+ p1/preprocess/Thyroid_Cancer/gene_data/GSE107754.csv filter=lfs diff=lfs merge=lfs -text
890
+ p1/preprocess/Type_1_Diabetes/GSE232310.csv filter=lfs diff=lfs merge=lfs -text
891
+ p1/preprocess/Type_1_Diabetes/gene_data/GSE156035.csv filter=lfs diff=lfs merge=lfs -text
892
+ p1/preprocess/Type_2_Diabetes/GSE281144.csv filter=lfs diff=lfs merge=lfs -text
893
+ p1/preprocess/Type_1_Diabetes/gene_data/GSE232310.csv filter=lfs diff=lfs merge=lfs -text
894
+ p1/preprocess/Type_1_Diabetes/gene_data/GSE193273.csv filter=lfs diff=lfs merge=lfs -text
895
+ p1/preprocess/Type_2_Diabetes/GSE182120.csv filter=lfs diff=lfs merge=lfs -text
896
+ p1/preprocess/Sjögrens_Syndrome/gene_data/GSE140161.csv filter=lfs diff=lfs merge=lfs -text
897
+ p1/preprocess/Type_2_Diabetes/gene_data/GSE250283.csv filter=lfs diff=lfs merge=lfs -text
898
+ p1/preprocess/Type_2_Diabetes/gene_data/GSE182120.csv filter=lfs diff=lfs merge=lfs -text
899
+ p1/preprocess/Type_2_Diabetes/gene_data/GSE281144.csv filter=lfs diff=lfs merge=lfs -text
900
+ p1/preprocess/Underweight/GSE57802.csv filter=lfs diff=lfs merge=lfs -text
p1/preprocess/Sjögrens_Syndrome/gene_data/GSE140161.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ddce9b69fbde8d55fec4fd32c5c8f8f60e09bfb1310be19a0f9f9d1e71619e65
3
+ size 109093516
p1/preprocess/Testicular_Cancer/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a92e03834ea667aef1ad85b109c67d56f2a8432b82e3bf638b2e77eba7a5673
3
+ size 46431842
p1/preprocess/Thymoma/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b7b28d036ad87ff3f89a1cf30425e17d10a0dda3092fa87bd017b8d48ce65a7
3
+ size 36560043
p1/preprocess/Thyroid_Cancer/gene_data/GSE107754.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a82da64a5edcbde2a3ccf1c07d005767e02ceeaad822b4ed6217419063405079
3
+ size 19822703
p1/preprocess/Thyroid_Cancer/gene_data/GSE151179.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6d36147e9cf82fbfc4c8f1cfb327f32ff546234be24d8fb2798f3868b44d5ad
3
+ size 18389009
p1/preprocess/Thyroid_Cancer/gene_data/GSE80022.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:397ef7f74e1da8939e698959607d2d7392f7769219e33c46668e58af08250078
3
+ size 14561873
p1/preprocess/Thyroid_Cancer/gene_data/GSE82208.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6ca9a45dd52f9050e53aacd31fb1ff99a2481e77e58f1f73887828fea0214e8
3
+ size 13702283
p1/preprocess/Type_1_Diabetes/GSE156035.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54c9ee71ae0a40d804692a3063732add048ce2b4853759709fc30b883cd0cd76
3
+ size 14452290
p1/preprocess/Type_1_Diabetes/GSE193273.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a0e8bacd07cde79b24f2b9fada2ca6d7727ea80091cd769461e592c7827bcd1
3
+ size 14452123
p1/preprocess/Type_1_Diabetes/GSE232310.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f3aa4179415a1ce76ced98e40ddfb9e6623699090361e9ce053ee01863ee1cc1
3
+ size 12205435
p1/preprocess/Type_1_Diabetes/code/TCGA.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_1_Diabetes"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/1/Type_1_Diabetes/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/1/Type_1_Diabetes/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/1/Type_1_Diabetes/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/1/Type_1_Diabetes/cohort_info.json"
15
+
16
+ # Step 1: Initial Data Loading
17
+
18
+ import os
19
+ import pandas as pd
20
+
21
+ # List subdirectories (as already given in the environment)
22
+ subdirectories = [
23
+ 'TCGA-LGG', 'CrawlData.ipynb', '.DS_Store',
24
+ 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
25
+ 'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)',
26
+ 'TCGA_Thymoma_(THYM)', 'TCGA_Testicular_Cancer_(TGCT)',
27
+ 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
28
+ 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)',
29
+ 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)', 'TCGA_Pancreatic_Cancer_(PAAD)',
30
+ 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
31
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)',
32
+ 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)', 'TCGA_Lung_Cancer_(LUNG)',
33
+ 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
34
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)',
35
+ 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)', 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)',
36
+ 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
37
+ 'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)',
38
+ 'TCGA_Endometrioid_Cancer_(UCEC)', 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)',
39
+ 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
40
+ 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)',
41
+ 'TCGA_Bile_Duct_Cancer_(CHOL)', 'TCGA_Adrenocortical_Cancer_(ACC)',
42
+ 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
43
+ ]
44
+
45
+ # Trait synonyms for "Type_1_Diabetes"
46
+ trait_synonyms = ["diabetes", "t1d", "type_1_diabetes", "type 1 diabetes"]
47
+
48
+ relevant_folder = None
49
+ for folder in subdirectories:
50
+ folder_lower = folder.lower()
51
+ if any(syn in folder_lower for syn in trait_synonyms):
52
+ relevant_folder = folder
53
+ break
54
+
55
+ if not relevant_folder:
56
+ # No suitable directory found, mark as skipped
57
+ _ = validate_and_save_cohort_info(
58
+ is_final=False,
59
+ cohort="TCGA",
60
+ info_path=json_path,
61
+ is_gene_available=False,
62
+ is_trait_available=False
63
+ )
64
+ print(f"No suitable directory found for trait {trait}. Skipping this trait.")
65
+ else:
66
+ # If a relevant directory is found, load the files
67
+ folder_path = os.path.join(tcga_root_dir, relevant_folder)
68
+ clinical_file, genetic_file = tcga_get_relevant_filepaths(folder_path)
69
+
70
+ clinical_data = pd.read_csv(clinical_file, index_col=0, sep='\t')
71
+ genetic_data = pd.read_csv(genetic_file, index_col=0, sep='\t')
72
+
73
+ print("Clinical data columns:", clinical_data.columns.tolist())
p1/preprocess/Type_1_Diabetes/gene_data/GSE156035.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:76a012bf5acadf39619ceabad8eebbc5005a1f709df4b76e886c194d5b8d6215
3
+ size 14451951
p1/preprocess/Type_1_Diabetes/gene_data/GSE193273.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b7a642cbe712235eae3e7b7bbd6b8863dc3eb6a6f0474b9e543d0297b760e38
3
+ size 14451951
p1/preprocess/Type_1_Diabetes/gene_data/GSE232310.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:30d7004d913b204faf89bed1cd3fd4a2d6d7d1e9d2194a0c776a78e588947440
3
+ size 12205175
p1/preprocess/Type_2_Diabetes/GSE182120.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c761df520ec3afdd3fe6d083afa8b523142fe1c6ca85182ef7c0071177537217
3
+ size 17706986
p1/preprocess/Type_2_Diabetes/GSE281144.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac135519678eeec353596d0ad4599ebcd6346428f10334b423f1a25d3618d957
3
+ size 10704143
p1/preprocess/Type_2_Diabetes/clinical_data/GSE180393.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GSM5607752,GSM5607753,GSM5607754,GSM5607755,GSM5607756,GSM5607757,GSM5607758,GSM5607759,GSM5607760,GSM5607761,GSM5607762,GSM5607763,GSM5607764,GSM5607765,GSM5607766,GSM5607767,GSM5607768,GSM5607769,GSM5607770,GSM5607771,GSM5607772,GSM5607773,GSM5607774,GSM5607775,GSM5607776,GSM5607777,GSM5607778,GSM5607779,GSM5607780,GSM5607781,GSM5607782,GSM5607783,GSM5607784,GSM5607785,GSM5607786,GSM5607787,GSM5607788,GSM5607789,GSM5607790,GSM5607791,GSM5607792,GSM5607793,GSM5607794,GSM5607795,GSM5607796,GSM5607797,GSM5607798,GSM5607799,GSM5607800,GSM5607801,GSM5607802,GSM5607803,GSM5607804,GSM5607805,GSM5607806,GSM5607807,GSM5607808,GSM5607809,GSM5607810,GSM5607811,GSM5607812,GSM5607813
2
+ 0.0,0.0,0.0,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,0.0,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,0.0,0.0,0.0,0.0
p1/preprocess/Type_2_Diabetes/clinical_data/GSE180394.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GSM5607814,GSM5607815,GSM5607816,GSM5607817,GSM5607818,GSM5607819,GSM5607820,GSM5607821,GSM5607822,GSM5607823,GSM5607824,GSM5607825,GSM5607826,GSM5607827,GSM5607828,GSM5607829,GSM5607830,GSM5607831,GSM5607832,GSM5607833,GSM5607834,GSM5607835,GSM5607836,GSM5607837,GSM5607838,GSM5607839,GSM5607840,GSM5607841,GSM5607842,GSM5607843,GSM5607844,GSM5607845,GSM5607846,GSM5607847,GSM5607848,GSM5607849,GSM5607850,GSM5607851,GSM5607852,GSM5607853,GSM5607854,GSM5607855,GSM5607856,GSM5607857,GSM5607858,GSM5607859,GSM5607860,GSM5607861,GSM5607862,GSM5607863,GSM5607864,GSM5607865,GSM5607866,GSM5607867,GSM5607868,GSM5607869,GSM5607870,GSM5607871,GSM5607872
2
+ 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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
p1/preprocess/Type_2_Diabetes/clinical_data/GSE180395.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,0,1,2,3
2
+ Type_2_Diabetes,0.0,0.0,0.0,1.0
p1/preprocess/Type_2_Diabetes/clinical_data/GSE182120.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ GSM5518937,GSM5518938,GSM5518939,GSM5518940,GSM5518941,GSM5518942,GSM5518943,GSM5518944,GSM5518945,GSM5518946,GSM5518947,GSM5518948,GSM5518949,GSM5518950,GSM5518951,GSM5518952,GSM5518953,GSM5518954,GSM5518955,GSM5518956,GSM5518957,GSM5518958,GSM5518959,GSM5518960,GSM5518961,GSM5518962,GSM5518963,GSM5518964,GSM5518965,GSM5518966,GSM5518967,GSM5518968,GSM5518969,GSM5518970,GSM5518971,GSM5518972,GSM5518973,GSM5518974,GSM5518975,GSM5518976,GSM5518977,GSM5518978,GSM5518979,GSM5518980,GSM5518981,GSM5518982,GSM5518983,GSM5518984,GSM5518985
2
+ 0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.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,0.0,1.0,1.0,0.0,1.0
3
+ 41.0,69.0,68.0,57.0,69.0,69.0,67.0,60.0,66.0,44.0,50.0,60.0,52.0,52.0,48.0,65.0,66.0,62.0,57.0,50.0,68.0,63.0,68.0,63.0,67.0,68.0,65.0,69.0,69.0,66.0,41.0,69.0,69.0,41.0,58.0,65.0,62.0,53.0,62.0,63.0,68.0,63.0,69.0,58.0,42.0,46.0,67.0,43.0,41.0
p1/preprocess/Type_2_Diabetes/clinical_data/GSE182121.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ GSM5518937,GSM5518938,GSM5518939,GSM5518940,GSM5518941,GSM5518942,GSM5518943,GSM5518944,GSM5518945,GSM5518946,GSM5518947,GSM5518948,GSM5518949,GSM5518950,GSM5518951,GSM5518952,GSM5518953,GSM5518954,GSM5518955,GSM5518956,GSM5518957,GSM5518958,GSM5518959,GSM5518960,GSM5518961,GSM5518962,GSM5518963,GSM5518964,GSM5518965,GSM5518966,GSM5518967,GSM5518968,GSM5518969,GSM5518970,GSM5518971,GSM5518972,GSM5518973,GSM5518974,GSM5518975,GSM5518976,GSM5518977,GSM5518978,GSM5518979,GSM5518980,GSM5518981,GSM5518982,GSM5518983,GSM5518984,GSM5518985
2
+ 0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.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,0.0,1.0,1.0,0.0,1.0
3
+ 41.0,69.0,68.0,57.0,69.0,69.0,67.0,60.0,66.0,44.0,50.0,60.0,52.0,52.0,48.0,65.0,66.0,62.0,57.0,50.0,68.0,63.0,68.0,63.0,67.0,68.0,65.0,69.0,69.0,66.0,41.0,69.0,69.0,41.0,58.0,65.0,62.0,53.0,62.0,63.0,68.0,63.0,69.0,58.0,42.0,46.0,67.0,43.0,41.0
p1/preprocess/Type_2_Diabetes/clinical_data/GSE250283.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ 0,1,2,3,4,5
2
+ 1.0,1.0,0.0,1.0,0.0,0.0
3
+ 0.0,1.0,1.0,0.0,0.0,1.0
p1/preprocess/Type_2_Diabetes/clinical_data/GSE281144.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ GSM8611649,GSM8611650,GSM8611651,GSM8611652,GSM8611653,GSM8611654,GSM8611655,GSM8611656,GSM8611657,GSM8611658,GSM8611659,GSM8611660,GSM8611661,GSM8611662,GSM8611663,GSM8611664,GSM8611665,GSM8611666,GSM8611667,GSM8611668,GSM8611669,GSM8611670,GSM8611671,GSM8611672,GSM8611673,GSM8611674,GSM8611675,GSM8611676,GSM8611677,GSM8611678,GSM8611679,GSM8611680,GSM8611681,GSM8611682
2
+ 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,0.0,0.0,0.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
3
+ 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,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
p1/preprocess/Type_2_Diabetes/code/GSE180393.py ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE180393"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE180393"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE180393.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE180393.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE180393.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ # 1. Determine whether gene expression data is available
42
+ # According to the series summary, this dataset uses microarrays to analyze gene expression,
43
+ # so we set is_gene_available to True.
44
+ is_gene_available = True
45
+
46
+ # 2. Identify data availability and define type conversion functions.
47
+
48
+ # From the sample characteristics dictionary:
49
+ # Key 0 contains multiple disease subgroups, including "DN" (diabetic nephropathy),
50
+ # which we interpret as Type_2_Diabetes (binary: has T2D vs. does not have T2D).
51
+ # Thus, we set trait_row = 0. There are no keys for age or gender, so set them as None.
52
+ trait_row = 0
53
+ age_row = None
54
+ gender_row = None
55
+
56
+ # The following conversion function will extract the substring after ":", strip spaces,
57
+ # and map "DN" to 1 (T2D present), and everything else to 0.
58
+ def convert_trait(value: str):
59
+ if not value or ":" not in value:
60
+ return None
61
+ val = value.split(":", 1)[1].strip().lower()
62
+ if val == "dn":
63
+ return 1
64
+ else:
65
+ return 0
66
+
67
+ # Since age and gender are not available, these can simply return None.
68
+ def convert_age(value: str):
69
+ return None
70
+
71
+ def convert_gender(value: str):
72
+ return None
73
+
74
+ # 3. Save dataset metadata. We perform the initial stage of validation (is_final=False).
75
+ is_trait_available = (trait_row is not None)
76
+ validate_and_save_cohort_info(
77
+ is_final=False,
78
+ cohort=cohort,
79
+ info_path=json_path,
80
+ is_gene_available=is_gene_available,
81
+ is_trait_available=is_trait_available
82
+ )
83
+
84
+ # 4. If trait_row is not None, extract clinical features and preview/save them.
85
+ if trait_row is not None:
86
+ selected_clinical_features_df = geo_select_clinical_features(
87
+ clinical_data,
88
+ trait=trait,
89
+ trait_row=trait_row,
90
+ convert_trait=convert_trait,
91
+ age_row=age_row,
92
+ convert_age=convert_age,
93
+ gender_row=gender_row,
94
+ convert_gender=convert_gender
95
+ )
96
+ preview = preview_df(selected_clinical_features_df)
97
+ print("Clinical Features Preview:", preview)
98
+
99
+ selected_clinical_features_df.to_csv(out_clinical_data_file, index=False)
100
+ # STEP3
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
+ # Observing the gene identifiers, they are Affymetrix probe IDs rather than standard gene symbols.
107
+ # Thus, we need to map them to gene symbols.
108
+ print("requires_gene_mapping = True")
109
+ # STEP5
110
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
111
+ gene_annotation = get_gene_annotation(soft_file)
112
+
113
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
114
+ print("Gene annotation preview:")
115
+ print(preview_df(gene_annotation))
116
+ # STEP: Gene Identifier Mapping
117
+ # The annotation preview shows numeric Entrez IDs. The library's "extract_human_gene_symbols" function
118
+ # discards numeric strings because they do not match the typical gene symbol pattern.
119
+ # To preserve these numeric IDs, we can prepend a letter (e.g., 'E') so they pass the pattern check.
120
+
121
+ # 1. Retrieve the mapping table from "ID" (probe ID) to "ENTREZ_GENE_ID" (numeric ID).
122
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='ENTREZ_GENE_ID')
123
+
124
+ # 2. Convert each numeric ID into a simple "gene symbol"-like string by prepending 'E', so that
125
+ # "extract_human_gene_symbols" won't discard it.
126
+ def prefix_numeric_entrez(entrez_id):
127
+ if isinstance(entrez_id, str) and entrez_id.isdigit():
128
+ return [f"E{entrez_id}"]
129
+ return []
130
+
131
+ mapping_df['Gene'] = mapping_df['Gene'].apply(prefix_numeric_entrez)
132
+
133
+ # 3. Apply the mapping to convert probe-level expression to "gene-level" expression.
134
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
135
+
136
+ # 4. Preview the results
137
+ print("Mapped gene_data shape:", gene_data.shape)
138
+ print("First 20 gene symbols after mapping:", gene_data.index[:20].tolist())
139
+ import pandas as pd
140
+
141
+ # Make sure we have a reference to the clinical data from the previous step
142
+ selected_clinical_df = selected_clinical_features_df
143
+
144
+ # STEP 7: Data Normalization and Linking
145
+
146
+ # 1. Normalize gene symbols and save the normalized gene data
147
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
148
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
149
+
150
+ # 2. Link the clinical and genetic data
151
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
152
+
153
+ # 3. Handle missing values in the linked data
154
+ processed_data = handle_missing_values(linked_data, trait_col=trait)
155
+
156
+ # 4. Determine whether the trait or demographics are severely biased
157
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait=trait)
158
+
159
+ # 5. Conduct final validation and save metadata
160
+ is_usable = validate_and_save_cohort_info(
161
+ is_final=True,
162
+ cohort=cohort,
163
+ info_path=json_path,
164
+ is_gene_available=True,
165
+ is_trait_available=True,
166
+ is_biased=trait_biased,
167
+ df=processed_data,
168
+ note="Proceeding with final linked dataset."
169
+ )
170
+
171
+ # 6. If usable, save the fully processed data
172
+ if is_usable:
173
+ processed_data.to_csv(out_data_file, index=True)
p1/preprocess/Type_2_Diabetes/code/GSE180394.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE180394"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE180394"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE180394.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE180394.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE180394.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ # Step 1: Determine if gene expression data is available
42
+ is_gene_available = True # Based on microarray gene expression platform in background info
43
+
44
+ # Step 2: Determine the availability of trait, age, and gender, and define conversion functions
45
+
46
+ # From the sample characteristics dictionary, key=0 contains "DN" among various values,
47
+ # which we interpret as "Diabetic Nephropathy" indicating T2D presence.
48
+ # Hence, we set trait_row=0. No mention of age or gender, so age_row=gender_row=None.
49
+
50
+ trait_row = 0
51
+ age_row = None
52
+ gender_row = None
53
+
54
+ # Decide data type: we use binary for T2D presence. Everything not DN -> 0, DN -> 1
55
+ def convert_trait(value: str):
56
+ parts = value.split(":")
57
+ val_str = parts[1].strip().lower() if len(parts) > 1 else parts[0].strip().lower()
58
+ if val_str == "dn":
59
+ return 1
60
+ else:
61
+ return 0
62
+
63
+ # Since age and gender are not available, we define empty converters.
64
+ def convert_age(value: str):
65
+ return None
66
+
67
+ def convert_gender(value: str):
68
+ return None
69
+
70
+ # Step 3: Save metadata using initial filtering
71
+ is_trait_available = (trait_row is not None)
72
+ validate_and_save_cohort_info(
73
+ is_final=False,
74
+ cohort=cohort,
75
+ info_path=json_path,
76
+ is_gene_available=is_gene_available,
77
+ is_trait_available=is_trait_available
78
+ )
79
+
80
+ # Step 4: If trait_row is not None, extract clinical features and save
81
+ if trait_row is not None:
82
+ clinical_features = geo_select_clinical_features(
83
+ clinical_df=clinical_data,
84
+ trait=trait,
85
+ trait_row=trait_row,
86
+ convert_trait=convert_trait,
87
+ age_row=age_row,
88
+ convert_age=convert_age,
89
+ gender_row=gender_row,
90
+ convert_gender=convert_gender
91
+ )
92
+ preview = preview_df(clinical_features)
93
+ print("Preview of Clinical Features:", preview)
94
+ clinical_features.to_csv(out_clinical_data_file, index=False)
95
+ # STEP3
96
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
97
+ gene_data = get_genetic_data(matrix_file)
98
+
99
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
100
+ print(gene_data.index[:20])
101
+ # Observing the provided gene identifiers, they appear to be Affymetrix probe IDs, not human gene symbols.
102
+ # Therefore, they require mapping to gene symbols.
103
+ requires_gene_mapping = True
104
+ # STEP5
105
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
106
+ gene_annotation = get_gene_annotation(soft_file)
107
+
108
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
109
+ print("Gene annotation preview:")
110
+ print(preview_df(gene_annotation))
111
+ # STEP: Gene Identifier Mapping
112
+
113
+ # 1. Identify the columns in 'gene_annotation' that match the probe IDs from our gene expression data
114
+ # and the columns that provide the gene identifiers (e.g., Entrez IDs).
115
+ prob_col = "ID" # Matches the probe IDs in our gene_data index
116
+ gene_col = "ENTREZ_GENE_ID" # Serves as the gene symbol/identifier for mapping
117
+
118
+ # 2. Extract the mapping dataframe using the specified columns
119
+ mapping_df = get_gene_mapping(annotation=gene_annotation, prob_col=prob_col, gene_col=gene_col)
120
+
121
+ # 3. Convert probe-level expression measurements to gene-level expression data
122
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
123
+ import pandas as pd
124
+
125
+ # Make sure we have a reference to the clinical data from the previous step
126
+ selected_clinical_df = clinical_features
127
+
128
+ # STEP 7: Data Normalization and Linking
129
+
130
+ # 1. Normalize gene symbols and save the normalized gene data
131
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
132
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
133
+
134
+ # 2. Link the clinical and genetic data
135
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
136
+
137
+ # 3. Handle missing values in the linked data
138
+ processed_data = handle_missing_values(linked_data, trait_col=trait)
139
+
140
+ # 4. Determine whether the trait or demographics are severely biased
141
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait=trait)
142
+
143
+ # 5. Conduct final validation and save metadata
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=trait_biased,
151
+ df=processed_data,
152
+ note="Proceeding with final linked dataset."
153
+ )
154
+
155
+ # 6. If usable, save the fully processed data
156
+ if is_usable:
157
+ processed_data.to_csv(out_data_file, index=True)
p1/preprocess/Type_2_Diabetes/code/GSE180395.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE180395"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE180395"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE180395.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE180395.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE180395.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ import pandas as pd
42
+
43
+ # 1. Gene Expression Data Availability
44
+ # Based on "Transcriptome" mention, we assume gene expression data is available.
45
+ is_gene_available = True
46
+
47
+ # 2. Variable Availability and Data Type Conversion
48
+ # From the sample characteristics dictionary, we see that row 0 ("sample group: ...")
49
+ # contains an entry "DN" (commonly referring to Diabetic Nephropathy).
50
+ # We'll treat that as indicative of Type_2_Diabetes and map it as a binary variable.
51
+
52
+ trait_row = 0 # "sample group"
53
+ age_row = None
54
+ gender_row = None
55
+
56
+ def convert_trait(value: str):
57
+ """
58
+ Convert the string to a binary (0/1) indicating absence/presence of Type_2_Diabetes.
59
+ We'll parse the portion after the first colon if available.
60
+ If it contains 'DN' (case-insensitive), convert to 1; otherwise 0.
61
+ """
62
+ if ":" in value:
63
+ value = value.split(":", 1)[1].strip().lower()
64
+ else:
65
+ value = value.strip().lower()
66
+
67
+ if "dn" in value:
68
+ return 1
69
+ return 0
70
+
71
+ def convert_age(value: str):
72
+ """
73
+ Age not available in this dataset; return None.
74
+ """
75
+ return None
76
+
77
+ def convert_gender(value: str):
78
+ """
79
+ Gender not available in this dataset; return None.
80
+ """
81
+ return None
82
+
83
+ # 3. Save Metadata (initial filtering)
84
+ is_trait_available = (trait_row is not None)
85
+ is_usable = validate_and_save_cohort_info(
86
+ is_final=False,
87
+ cohort=cohort,
88
+ info_path=json_path,
89
+ is_gene_available=is_gene_available,
90
+ is_trait_available=is_trait_available
91
+ )
92
+
93
+ # 4. Clinical Feature Extraction (only if trait is available)
94
+ if trait_row is not None:
95
+ # Suppose we have a DataFrame named 'clinical_data' prepared from the sample characteristics
96
+ clinical_data = pd.DataFrame.from_dict(
97
+ {
98
+ 0: [
99
+ 'sample group: Living donor',
100
+ 'sample group: infection-associated GN',
101
+ 'sample group: FSGS',
102
+ 'sample group: DN'
103
+ ],
104
+ 1: [
105
+ 'tissue: Glomeruli from kidney biopsy',
106
+ 'tissue: Tubuli from kidney biopsy',
107
+ 'tissue: Glomeruli from kidney biopsy',
108
+ 'tissue: Tubuli from kidney biopsy'
109
+ ],
110
+ },
111
+ orient='index'
112
+ )
113
+
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
+
125
+ preview = preview_df(selected_clinical_df)
126
+ print("Preview of selected clinical features:\n", preview)
127
+
128
+ selected_clinical_df.to_csv(out_clinical_data_file)
129
+ # STEP3
130
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
131
+ gene_data = get_genetic_data(matrix_file)
132
+
133
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
134
+ print(gene_data.index[:20])
135
+ # These identifiers appear to be Affymetrix microarray probe IDs rather than standard human gene symbols.
136
+ # Therefore, mapping to gene symbols is needed.
137
+ print("requires_gene_mapping = True")
138
+ # STEP5
139
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
140
+ gene_annotation = get_gene_annotation(soft_file)
141
+
142
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
143
+ print("Gene annotation preview:")
144
+ print(preview_df(gene_annotation))
145
+ # STEP6: Gene Identifier Mapping
146
+
147
+ # 1) From the preview, we see that the gene expression data uses the "ID" column for probes
148
+ # (e.g., "10000_at"), and the "ENTREZ_GENE_ID" column contains corresponding gene information.
149
+ # 2) Get a gene mapping dataframe with these two columns.
150
+ mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="ENTREZ_GENE_ID")
151
+
152
+ # 3) Convert the probe-level measurements to gene-level data using this mapping.
153
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
154
+ import pandas as pd
155
+
156
+ # STEP 7: Data Normalization and Linking
157
+
158
+ # 1. Normalize gene symbols and save the normalized gene data
159
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
160
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
161
+
162
+ # 2. Link the clinical and genetic data (replace the undefined variable with the one from previous steps)
163
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
164
+
165
+ # 3. Handle missing values in the linked data
166
+ processed_data = handle_missing_values(linked_data, trait_col=trait)
167
+
168
+ # 4. Determine whether the trait or demographics are severely biased
169
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait=trait)
170
+
171
+ # 5. Conduct final validation and save metadata
172
+ is_usable = validate_and_save_cohort_info(
173
+ is_final=True,
174
+ cohort=cohort,
175
+ info_path=json_path,
176
+ is_gene_available=True,
177
+ is_trait_available=True,
178
+ is_biased=trait_biased,
179
+ df=processed_data,
180
+ note="Proceeding with final linked dataset."
181
+ )
182
+
183
+ # 6. If usable, save the fully processed data
184
+ if is_usable:
185
+ processed_data.to_csv(out_data_file, index=True)
p1/preprocess/Type_2_Diabetes/code/GSE182120.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE182120"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE182120"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE182120.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE182120.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE182120.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ # 1. Gene Expression Data Availability
42
+ # Based on the background description ("the transcriptome was analyzed by RNA-sequencing"),
43
+ # we conclude that gene expression data is available.
44
+ is_gene_available = True
45
+
46
+ # 2. Variable Availability and Data Type Conversion
47
+ # From the sample characteristics dictionary:
48
+ # - trait (T2D/NGT) is at key 0 => trait_row = 0
49
+ # - age is at key 1 => age_row = 1
50
+ # - gender data is not present => gender_row = None
51
+
52
+ trait_row = 0
53
+ age_row = 1
54
+ gender_row = None
55
+
56
+ # Conversion functions
57
+ def convert_trait(value: str):
58
+ """Convert 'disease: T2D'/'disease: NGT' to 1/0, respectively."""
59
+ val = value.split(":")[-1].strip().upper()
60
+ if val == "T2D":
61
+ return 1
62
+ elif val == "NGT":
63
+ return 0
64
+ return None
65
+
66
+ def convert_age(value: str):
67
+ """Parse 'age: 57' -> float(57). Unknown/invalid values -> None."""
68
+ val = value.split(":")[-1].strip()
69
+ try:
70
+ return float(val)
71
+ except ValueError:
72
+ return None
73
+
74
+ def convert_gender(value: str):
75
+ """
76
+ A placeholder function since 'gender' data is not found (gender_row=None).
77
+ If needed, convert female->0, male->1. Otherwise return None.
78
+ """
79
+ val = value.split(":")[-1].strip().upper()
80
+ if val in ["F", "FEMALE"]:
81
+ return 0
82
+ elif val in ["M", "MALE"]:
83
+ return 1
84
+ return None
85
+
86
+ # 3. Save Metadata with initial filtering
87
+ is_trait_available = (trait_row is not None)
88
+ is_usable = 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 is available)
97
+ if trait_row is not None:
98
+ clinical_features = 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
+
109
+ # Preview the extracted clinical features
110
+ preview_result = preview_df(clinical_features)
111
+ print("Preview of clinical features:", preview_result)
112
+
113
+ # Save the clinical features to CSV
114
+ clinical_features.to_csv(out_clinical_data_file, index=False)
115
+ # STEP3
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
+ print("requires_gene_mapping = True")
122
+ # STEP5
123
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
124
+ gene_annotation = get_gene_annotation(soft_file)
125
+
126
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
127
+ print("Gene annotation preview:")
128
+ print(preview_df(gene_annotation))
129
+ # STEP 6: Gene Identifier Mapping
130
+
131
+ # 1. Decide which columns store the same kind of identifiers and which store the gene symbols.
132
+ # From the preview, "probeset_id" appears to correspond to the probe-level IDs (e.g. "TC01000001.hg.1"),
133
+ # and "gene_assignment" contains gene symbol information.
134
+
135
+ # Instead of calling get_gene_mapping directly (which expects a column named 'ID'),
136
+ # we'll manually create the mapping dataframe so that the 'probeset_id' column is renamed to 'ID'.
137
+
138
+ mapping_df = gene_annotation.loc[:, ["probeset_id", "gene_assignment"]].dropna()
139
+ mapping_df = mapping_df.rename(columns={"probeset_id": "ID", "gene_assignment": "Gene"}).astype({"ID": "str"})
140
+
141
+ # 2. Convert the probe-level expression data to gene-level expression by applying the mapping.
142
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
143
+ import pandas as pd
144
+
145
+ # STEP 7: Data Normalization and Linking
146
+
147
+ # 1. Normalize gene symbols and save the normalized gene data
148
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
149
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
150
+
151
+ # 2. Link the clinical and genetic data
152
+ linked_data = geo_link_clinical_genetic_data(clinical_features, normalized_gene_data)
153
+
154
+ # 3. Handle missing values in the linked data
155
+ processed_data = handle_missing_values(linked_data, trait_col=trait)
156
+
157
+ # 4. Determine whether the trait or demographics are severely biased
158
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait=trait)
159
+
160
+ # 5. Conduct final validation and save metadata
161
+ is_usable = validate_and_save_cohort_info(
162
+ is_final=True,
163
+ cohort=cohort,
164
+ info_path=json_path,
165
+ is_gene_available=True,
166
+ is_trait_available=True,
167
+ is_biased=trait_biased,
168
+ df=processed_data,
169
+ note="Proceeding with final linked dataset."
170
+ )
171
+
172
+ # 6. If usable, save the fully processed data
173
+ if is_usable:
174
+ processed_data.to_csv(out_data_file, index=True)
p1/preprocess/Type_2_Diabetes/code/GSE182121.py ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE182121"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE182121"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE182121.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE182121.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE182121.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ # 1. Decide if gene expression data is available
42
+ is_gene_available = True # Based on dataset details, it likely contains gene expression data (not exclusively miRNA/methylation).
43
+
44
+ # 2. Identify row indices for the trait, age, and gender, and define type conversion functions
45
+ trait_row = 0 # Row 0 contains 'disease: NGT'/'disease: T2D'
46
+ age_row = 1 # Row 1 contains varying ages
47
+ gender_row = None # No gender information provided
48
+
49
+ def convert_trait(value: str) -> Optional[int]:
50
+ """
51
+ Convert the 'disease' values to binary:
52
+ - T2D => 1
53
+ - NGT => 0
54
+ """
55
+ # Each cell might look like "disease: T2D" or "disease: NGT". Extract the value after the colon.
56
+ parts = value.split(':')
57
+ if len(parts) < 2:
58
+ return None
59
+ val_str = parts[1].strip().upper()
60
+ if val_str == "T2D":
61
+ return 1
62
+ elif val_str == "NGT":
63
+ return 0
64
+ return None
65
+
66
+ def convert_age(value: str) -> Optional[float]:
67
+ """
68
+ Convert the 'age' values to continuous floats.
69
+ """
70
+ parts = value.split(':')
71
+ if len(parts) < 2:
72
+ return None
73
+ val_str = parts[1].strip()
74
+ try:
75
+ return float(val_str)
76
+ except ValueError:
77
+ return None
78
+
79
+ def convert_gender(value: str) -> Optional[int]:
80
+ """
81
+ Placeholder function: no 'gender' field in the dataset, so won't be used.
82
+ If needed, we would convert 'female' -> 0, 'male' -> 1.
83
+ """
84
+ return None
85
+
86
+ # 3. Conduct initial filtering on dataset usability and save metadata
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. If trait data is available, extract clinical features
97
+ if trait_row is not None:
98
+ selected_clinical_df = geo_select_clinical_features(
99
+ clinical_data, # This DataFrame is assumed to be available from a previous step
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 the first few rows
109
+ preview = preview_df(selected_clinical_df, n=5)
110
+ print("Preview of selected clinical features:\n", preview)
111
+
112
+ # Save clinical features to CSV
113
+ selected_clinical_df.to_csv(out_clinical_data_file, index=False)
114
+ # STEP3
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
+ # Based on the provided identifiers (e.g., "2824546_st"), they appear to be microarray probe IDs
121
+ # (such as Affymetrix probe sets), not standard human gene symbols. Thus, they require mapping to gene symbols.
122
+ print("requires_gene_mapping = True")
123
+ # STEP5
124
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
125
+ gene_annotation = get_gene_annotation(soft_file)
126
+
127
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
128
+ print("Gene annotation preview:")
129
+ print(preview_df(gene_annotation))
130
+ # STEP 6: Gene Identifier Mapping
131
+
132
+ # The library function get_gene_mapping expects a column named "ID" for the probe identifiers
133
+ # and will rename the gene column to "Gene." Our annotation has "probeset_id" for probes
134
+ # and "mrna_assignment" for gene-related data. We will rename those columns in a copy of
135
+ # the annotation to align with what the library function expects.
136
+
137
+ # Make a renamed copy so that "probeset_id" => "ID" and "mrna_assignment" => "Gene"
138
+ annotation_for_mapping = gene_annotation.rename(columns={"probeset_id": "ID", "mrna_assignment": "Gene"})
139
+
140
+ # Now use "ID" and "Gene" as the arguments for prob_col and gene_col,
141
+ # since the library code specifically looks for them.
142
+ mapping_df = get_gene_mapping(
143
+ annotation=annotation_for_mapping,
144
+ prob_col="ID",
145
+ gene_col="Gene"
146
+ )
147
+
148
+ # Convert probe-level measurements to gene-level expression data
149
+ gene_data = apply_gene_mapping(
150
+ expression_df=gene_data,
151
+ mapping_df=mapping_df
152
+ )
153
+
154
+ # Check the shape and the first few gene IDs of the newly mapped gene_data
155
+ print("Mapped gene_data shape:", gene_data.shape)
156
+ print("First 5 gene IDs in the mapped data:\n", gene_data.index[:5])
157
+ # STEP: Gene Identifier Mapping
158
+
159
+ # 1. Identify columns in the gene annotation that match our probe IDs
160
+ # ("probeset_id") and that contain gene symbols or transcripts ("mrna_assignment").
161
+ # We will rename them to "ID" and "Gene" to fit the library's function signatures.
162
+
163
+ annotation_for_mapping = gene_annotation[["probeset_id", "mrna_assignment"]].copy()
164
+ annotation_for_mapping.columns = ["ID", "Gene"]
165
+
166
+ # 2. Get a gene mapping dataframe by extracting the probe IDs and gene symbols
167
+ mapping_df = get_gene_mapping(
168
+ annotation=annotation_for_mapping,
169
+ prob_col="ID",
170
+ gene_col="Gene"
171
+ )
172
+
173
+ # 3. Convert probe-level measurements to gene-level expression data
174
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
175
+
176
+ # Check the shape and first few gene IDs
177
+ print("Mapped gene_data shape:", gene_data.shape)
178
+ print("First 5 gene IDs in the mapped data:\n", gene_data.index[:5])
179
+ import pandas as pd
180
+
181
+ # STEP 8: Data Normalization and Linking
182
+
183
+ # 1. Normalize gene symbols and save the normalized gene data
184
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
185
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
186
+
187
+ # 2. Link the clinical and genetic data
188
+ # (Assuming 'selected_clinical_df' is still in memory from the earlier step where we extracted clinical data)
189
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
190
+
191
+ # 3. Handle missing values in the linked data
192
+ processed_data = handle_missing_values(linked_data, trait_col=trait)
193
+
194
+ # 4. Determine whether the trait or demographics are severely biased
195
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait=trait)
196
+
197
+ # 5. Conduct final validation and save metadata
198
+ is_usable = validate_and_save_cohort_info(
199
+ is_final=True,
200
+ cohort=cohort,
201
+ info_path=json_path,
202
+ is_gene_available=True,
203
+ is_trait_available=True,
204
+ is_biased=trait_biased,
205
+ df=processed_data,
206
+ note="Proceeding with final linked dataset."
207
+ )
208
+
209
+ # 6. If usable, save the fully processed data
210
+ if is_usable:
211
+ processed_data.to_csv(out_data_file, index=True)
p1/preprocess/Type_2_Diabetes/code/GSE227080.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE227080"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE227080"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE227080.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE227080.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE227080.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ # 1) Gene expression data availability
42
+ is_gene_available = True
43
+
44
+ # 2) Variable availability
45
+ trait_row = None # No Type_2_Diabetes info
46
+ age_row = 1 # Multiple unique values found for age
47
+ gender_row = 0 # Multiple unique values found for gender
48
+
49
+ # 2.2) Data type conversion
50
+ def convert_trait(value: str):
51
+ # No trait data found, so return None
52
+ return None
53
+
54
+ def convert_age(value: str):
55
+ # Extract value after "age:"
56
+ parts = value.split(':', 1)
57
+ if len(parts) < 2:
58
+ return None
59
+ val_str = parts[1].strip()
60
+ try:
61
+ return float(val_str)
62
+ except ValueError:
63
+ return None
64
+
65
+ def convert_gender(value: str):
66
+ # Extract value after "gender:"
67
+ parts = value.split(':', 1)
68
+ if len(parts) < 2:
69
+ return None
70
+ val_str = parts[1].strip().upper()
71
+ if val_str == 'F':
72
+ return 0
73
+ elif val_str == 'M':
74
+ return 1
75
+ else:
76
+ return None
77
+
78
+ # 3) Save metadata (initial filtering)
79
+ is_trait_available = (trait_row is not None)
80
+ _ = validate_and_save_cohort_info(
81
+ is_final=False,
82
+ cohort=cohort,
83
+ info_path=json_path,
84
+ is_gene_available=is_gene_available,
85
+ is_trait_available=is_trait_available
86
+ )
87
+
88
+ # 4) The substep for clinical feature extraction is skipped because trait_row is None
89
+ # STEP3
90
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
91
+ gene_data = get_genetic_data(matrix_file)
92
+
93
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
94
+ print(gene_data.index[:20])
95
+ # The gene identifiers in the expression data (ABCB1, ABL1, ADA, AHR, etc.)
96
+ # appear to be recognized human gene symbols. No mapping is required.
97
+
98
+ requires_gene_mapping = False
99
+ # STEP 7
100
+
101
+ import pandas as pd
102
+
103
+ # 1) Normalize the gene expression data
104
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
105
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
106
+
107
+ # Since trait_row was determined to be None, we have is_trait_available=False.
108
+ # We skip clinical-data linking and trait-based steps because the trait is not available.
109
+
110
+ # 2) Final validation: Mark the dataset as not usable for trait-based analysis.
111
+ dummy_df = pd.DataFrame() # A placeholder DataFrame
112
+ is_biased = False # Arbitrary placeholder; the trait is not available, so bias check is moot
113
+
114
+ is_usable = validate_and_save_cohort_info(
115
+ is_final=True,
116
+ cohort=cohort,
117
+ info_path=json_path,
118
+ is_gene_available=True,
119
+ is_trait_available=False,
120
+ is_biased=is_biased,
121
+ df=dummy_df, # Pass empty DataFrame to satisfy function signature
122
+ note="No trait data. Dataset is not usable for trait-based analyses."
123
+ )
124
+
125
+ # 3) Since the dataset is not usable (no trait), do not proceed with final linking or data saving.
126
+ if is_usable:
127
+ # Normally would save final linked data, but it's not usable here.
128
+ pass
p1/preprocess/Type_2_Diabetes/code/GSE250283.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE250283"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE250283"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE250283.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE250283.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE250283.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ import pandas as pd
42
+ from typing import Optional, Any
43
+
44
+ # 1. Gene Expression Data Availability
45
+ # Based on the background info ("...whole transcriptomic profiling..." using Illumina expression beadchip),
46
+ # we conclude this dataset likely contains gene expression data.
47
+ is_gene_available = True
48
+
49
+ # 2. Variable Availability and Data Type Conversion
50
+
51
+ # 2.1 Identify keys for each variable in the sample characteristics dictionary
52
+ trait_row = 2 # "sample group (dm or no dm): DM" or "Healthy"
53
+ age_row = None # No indication of age in the dictionary
54
+ gender_row = 1 # "gender: Female" or "gender: Male"
55
+
56
+ # 2.2 Data Type Conversion Functions
57
+ def convert_trait(x: str) -> Optional[int]:
58
+ # Example: "sample group (dm or no dm): DM"
59
+ parts = x.split(":", 1)
60
+ if len(parts) < 2:
61
+ return None
62
+ val = parts[1].strip().lower()
63
+ if val in ["dm", "t2dm", "diabetic", "diabetes"]:
64
+ return 1
65
+ elif val in ["healthy", "control"]:
66
+ return 0
67
+ return None
68
+
69
+ def convert_age(x: str) -> Optional[float]:
70
+ # No age data available, but implement a generic converter for completeness
71
+ # Return None because age data is not present
72
+ return None
73
+
74
+ def convert_gender(x: str) -> Optional[int]:
75
+ # Example: "gender: Female"
76
+ parts = x.split(":", 1)
77
+ if len(parts) < 2:
78
+ return None
79
+ val = parts[1].strip().lower()
80
+ if val == "female":
81
+ return 0
82
+ elif val == "male":
83
+ return 1
84
+ return None
85
+
86
+ # 3. Save Metadata (initial filtering)
87
+ # Trait data is considered available if trait_row is not None
88
+ is_trait_available = (trait_row is not None)
89
+
90
+ # Validate and save initial info
91
+ is_usable = 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 trait_row is not None
100
+ if trait_row is not None:
101
+ # Suppose we have loaded the clinical data into a variable named 'clinical_data'
102
+ # For demonstration, we'll create a mock DataFrame here, but in practice,
103
+ # you should use the actual clinical data DataFrame from prior steps.
104
+ clinical_data = pd.DataFrame({
105
+ 0: ["tissue: blood"]*6,
106
+ 1: ["gender: Female", "gender: Male", "gender: Male", "gender: Female", "gender: Female", "gender: Male"],
107
+ 2: ["sample group (dm or no dm): DM", "sample group (dm or no dm): DM",
108
+ "sample group (dm or no dm): Healthy", "sample group (dm or no dm): DM",
109
+ "sample group (dm or no dm): Healthy", "sample group (dm or no dm): Healthy"],
110
+ 3: ["comorbidity: with Retinopathy", "comorbidity: Healthy",
111
+ "comorbidity: with no Retinopathy", "comorbidity: with Retinopathy",
112
+ "comorbidity: Healthy", "comorbidity: with no Retinopathy"]
113
+ }).T
114
+
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=convert_age,
122
+ gender_row=gender_row,
123
+ convert_gender=convert_gender
124
+ )
125
+
126
+ # Preview return DataFrame
127
+ preview = preview_df(selected_clinical_df)
128
+
129
+ # Save the clinical data as CSV
130
+ selected_clinical_df.to_csv(out_clinical_data_file, index=False)
131
+ # STEP3
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
+ print("requires_gene_mapping = True")
138
+ # STEP5
139
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
140
+ gene_annotation = get_gene_annotation(soft_file)
141
+
142
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
143
+ print("Gene annotation preview:")
144
+ print(preview_df(gene_annotation))
145
+ # STEP6: Gene Identifier Mapping
146
+
147
+ # 1 & 2. Identify the columns for probe IDs (matching gene_data.index) and for gene symbols, then construct the mapping dataframe.
148
+ mapping_df = get_gene_mapping(
149
+ annotation=gene_annotation,
150
+ prob_col='ID', # Column storing probe IDs (e.g., ILMN_1343295)
151
+ gene_col='SYMBOL' # Column storing gene symbols (e.g., GAPDH, EEF1A1)
152
+ )
153
+
154
+ # 3. Convert probe-level data to gene-level expression data by applying the mapping.
155
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
156
+
157
+
158
+ # STEP 7
159
+
160
+ import pandas as pd
161
+
162
+ # 1) Normalize the gene expression data
163
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
164
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
165
+
166
+ # Since trait_row was determined to be None, we have is_trait_available=False.
167
+ # We skip clinical-data linking and trait-based steps because the trait is not available.
168
+
169
+ # 2) Final validation: Mark the dataset as not usable for trait-based analysis.
170
+ dummy_df = pd.DataFrame() # A placeholder DataFrame
171
+ is_biased = False # Arbitrary placeholder; the trait is not available, so bias check is moot
172
+
173
+ is_usable = validate_and_save_cohort_info(
174
+ is_final=True,
175
+ cohort=cohort,
176
+ info_path=json_path,
177
+ is_gene_available=True,
178
+ is_trait_available=False,
179
+ is_biased=is_biased,
180
+ df=dummy_df, # Pass empty DataFrame to satisfy function signature
181
+ note="No trait data. Dataset is not usable for trait-based analyses."
182
+ )
183
+
184
+ # 3) Since the dataset is not usable (no trait), do not proceed with final linking or data saving.
185
+ if is_usable:
186
+ # Normally would save final linked data, but it's not usable here.
187
+ pass
p1/preprocess/Type_2_Diabetes/code/GSE271700.py ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE271700"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE271700"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE271700.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE271700.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE271700.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ # 1. Gene Expression Data Availability
42
+ # Based on the background ("whole-genome microarray"), we conclude:
43
+ is_gene_available = True
44
+
45
+ # 2. Variable Availability and Data Type Conversion
46
+
47
+ # The trait "Type_2_Diabetes" is constant for all subjects (everyone has T2D),
48
+ # so it is effectively not available for association analysis.
49
+ trait_row = None # Not found as a variable row, or it's constant => treat as unavailable
50
+
51
+ # We observe that age data exists at key=1 with multiple distinct values.
52
+ age_row = 1
53
+
54
+ # We observe that gender data exists at key=0 with "Female" and "Male".
55
+ gender_row = 0
56
+
57
+ # Data type conversion functions:
58
+ def convert_trait(value: str):
59
+ """
60
+ Since the trait is not available (constant in this study),
61
+ we return None for every input.
62
+ """
63
+ return None
64
+
65
+ def convert_age(value: str):
66
+ """
67
+ Convert age from string after the colon to a float.
68
+ If parsing fails, return None.
69
+ Example: "age: 51" -> 51.0
70
+ """
71
+ parts = value.split(':')
72
+ if len(parts) < 2:
73
+ return None
74
+ try:
75
+ return float(parts[1].strip())
76
+ except ValueError:
77
+ return None
78
+
79
+ def convert_gender(value: str):
80
+ """
81
+ Convert gender to binary:
82
+ Female -> 0
83
+ Male -> 1
84
+ If parsing fails or unknown, return None.
85
+ Example: "gender: Female" -> 0
86
+ """
87
+ parts = value.split(':')
88
+ if len(parts) < 2:
89
+ return None
90
+ val = parts[1].strip().lower()
91
+ if val == 'female':
92
+ return 0
93
+ elif val == 'male':
94
+ return 1
95
+ return None
96
+
97
+ # 3. Save Metadata (initial filtering)
98
+ is_trait_available = (trait_row is not None) # False in this case
99
+ is_usable = 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
108
+ # Only do this if trait_row is not None. Here, trait_row is None => skip.
109
+ # STEP3
110
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
111
+ gene_data = get_genetic_data(matrix_file)
112
+
113
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
114
+ print(gene_data.index[:20])
115
+ # Based on the provided index values (e.g., "10000_at", "10001_at"), these are Affymetrix probe identifiers.
116
+ # They do not appear to be standard human gene symbols and typically require mapping to gene symbols
117
+ # using a corresponding annotation file or relevant mapping strategy.
118
+
119
+ print("These gene identifiers are Affymetrix probe IDs and require mapping.")
120
+ requires_gene_mapping = True
121
+ # STEP5
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
+ # STEP: Gene Identifier Mapping
129
+
130
+ # 1. Based on the preview, the column 'ID' in the gene_annotation DataFrame corresponds
131
+ # to the probe IDs (like "1_at", "2_at", etc.), which matches the format in the gene
132
+ # expression data index. The column 'SPOT_ID' does not look like a typical gene symbol,
133
+ # but appears to be the only other column available for mapping. We'll treat 'SPOT_ID'
134
+ # as the gene symbol column in this dataset.
135
+
136
+ # 2. Create a mapping DataFrame with 'ID' as the probe identifier column and 'SPOT_ID'
137
+ # as the gene symbol column.
138
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='SPOT_ID')
139
+
140
+ # 3. Convert the probe-level measurements to gene-level expression data by applying this mapping.
141
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
142
+
143
+ # Now 'gene_data' holds expression values aggregated by gene symbols.
144
+ # STEP 7
145
+
146
+ import pandas as pd
147
+
148
+ # 1) Normalize the gene expression data
149
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
150
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
151
+
152
+ # Since trait_row was determined to be None, we have is_trait_available=False.
153
+ # We skip clinical-data linking and trait-based steps because the trait is not available.
154
+
155
+ # 2) Final validation: Mark the dataset as not usable for trait-based analysis.
156
+ dummy_df = pd.DataFrame() # A placeholder DataFrame
157
+ is_biased = False # Arbitrary placeholder; the trait is not available, so bias check is moot
158
+
159
+ is_usable = validate_and_save_cohort_info(
160
+ is_final=True,
161
+ cohort=cohort,
162
+ info_path=json_path,
163
+ is_gene_available=True,
164
+ is_trait_available=False,
165
+ is_biased=is_biased,
166
+ df=dummy_df, # Pass empty DataFrame to satisfy function signature
167
+ note="No trait data. Dataset is not usable for trait-based analyses."
168
+ )
169
+
170
+ # 3) Since the dataset is not usable (no trait), do not proceed with final linking or data saving.
171
+ if is_usable:
172
+ # Normally would save final linked data, but it's not usable here.
173
+ pass
p1/preprocess/Type_2_Diabetes/code/GSE281144.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE281144"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE281144"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE281144.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE281144.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE281144.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ # Step 1: Determine if gene expression data is available
42
+ # From the series and background information, this dataset uses microarray for gene expression.
43
+ is_gene_available = True
44
+
45
+ # Step 2: Check availability of trait, age, and gender data from the sample characteristics dictionary
46
+ # Sample Characteristics Dictionary:
47
+ # {0: ['Sex: Female', 'Sex: Male'],
48
+ # 1: ['diabetes status: Control', 'diabetes status: Diabetic'],
49
+ # 2: ['treatment: Roux-en-Y gastric bypass surgery (RYGB)']}
50
+
51
+ # 2.1 Identify keys for each variable
52
+ # The trait "Type_2_Diabetes" matches "diabetes status" in row 1
53
+ trait_row = 1
54
+
55
+ # No information about Age is found, so None
56
+ age_row = None
57
+
58
+ # Gender data is available at row 0 ("Sex: Female", "Sex: Male")
59
+ gender_row = 0
60
+
61
+ # 2.2 Define data type conversions
62
+ def convert_trait(value: str):
63
+ # Extract substring after colon, convert to lowercase
64
+ val = value.split(":", 1)[-1].strip().lower()
65
+ if "control" in val:
66
+ return 0
67
+ elif "diabetic" in val:
68
+ return 1
69
+ return None
70
+
71
+ def convert_age(value: str):
72
+ # Not applicable here (age_row is None), so just return None if called
73
+ return None
74
+
75
+ def convert_gender(value: str):
76
+ # Extract substring after colon, convert to lowercase
77
+ val = value.split(":", 1)[-1].strip().lower()
78
+ if "female" in val:
79
+ return 0
80
+ elif "male" in val:
81
+ return 1
82
+ return None
83
+
84
+ # Step 3: Save metadata (initial filtering)
85
+ is_trait_available = (trait_row is not None)
86
+ is_usable = validate_and_save_cohort_info(
87
+ is_final=False,
88
+ cohort=cohort,
89
+ info_path=json_path,
90
+ is_gene_available=is_gene_available,
91
+ is_trait_available=is_trait_available
92
+ )
93
+
94
+ # Step 4: If trait data is available, extract clinical features
95
+ if trait_row is not None:
96
+ clinical_data_extracted = geo_select_clinical_features(
97
+ clinical_data,
98
+ trait=trait,
99
+ trait_row=trait_row,
100
+ convert_trait=convert_trait,
101
+ age_row=age_row,
102
+ convert_age=convert_age,
103
+ gender_row=gender_row,
104
+ convert_gender=convert_gender
105
+ )
106
+
107
+ preview = preview_df(clinical_data_extracted)
108
+ print("Preview of selected clinical features:", preview)
109
+
110
+ clinical_data_extracted.to_csv(out_clinical_data_file, index=False)
111
+ # STEP3
112
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
113
+ gene_data = get_genetic_data(matrix_file)
114
+
115
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
116
+ print(gene_data.index[:20])
117
+ requires_gene_mapping = True
118
+ # STEP5
119
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
120
+ gene_annotation = get_gene_annotation(soft_file)
121
+
122
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
123
+ print("Gene annotation preview:")
124
+ print(preview_df(gene_annotation))
125
+ # STEP: Gene Identifier Mapping
126
+
127
+ # 1. Decide which columns correspond to probe identifiers and gene symbols.
128
+ # From the preview, the 'ID' column in gene_annotation matches the probe identifier format,
129
+ # and the 'gene_assignment' column contains gene symbols (possibly multiple).
130
+ prob_col = "ID"
131
+ gene_col = "gene_assignment"
132
+
133
+ # 2. Get the gene mapping dataframe using the selected columns.
134
+ mapping_df = get_gene_mapping(gene_annotation, prob_col, gene_col)
135
+
136
+ # 3. Convert probe-level measurements to gene-level data.
137
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
138
+
139
+ # Print a small preview of the resulting gene expression data
140
+ print("Gene data shape after mapping:", gene_data.shape)
141
+ print("Some gene symbols in the mapped data index:", gene_data.index[:10].tolist())
142
+ # STEP 7
143
+
144
+ # 1) Normalize the gene expression data
145
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
146
+ normalized_gene_data.to_csv(out_gene_data_file, index=True)
147
+
148
+ # 2) Link the clinical features with gene expression data
149
+ # (We have trait_row=1 from previous steps, so clinical_data_extracted is available)
150
+ linked_data = geo_link_clinical_genetic_data(clinical_data_extracted, normalized_gene_data)
151
+
152
+ # 3) Handle missing values (including trait, which is "Type_2_Diabetes")
153
+ linked_data = handle_missing_values(linked_data, trait)
154
+
155
+ # 4) Judge and remove biased features
156
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
157
+
158
+ # 5) Final validation and metadata saving
159
+ is_usable = validate_and_save_cohort_info(
160
+ is_final=True,
161
+ cohort=cohort,
162
+ info_path=json_path,
163
+ is_gene_available=True,
164
+ is_trait_available=True,
165
+ is_biased=is_biased,
166
+ df=linked_data,
167
+ note="All preprocessing steps completed; linking and bias checks done."
168
+ )
169
+
170
+ # 6) If the dataset is deemed usable, save the final linked data
171
+ if is_usable:
172
+ linked_data.to_csv(out_data_file, index=True)
p1/preprocess/Type_2_Diabetes/code/GSE98887.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+ cohort = "GSE98887"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Type_2_Diabetes"
10
+ in_cohort_dir = "../DATA/GEO/Type_2_Diabetes/GSE98887"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/GSE98887.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/GSE98887.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/GSE98887.csv"
16
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+
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(
28
+ matrix_file,
29
+ background_prefixes,
30
+ clinical_prefixes
31
+ )
32
+
33
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
34
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
35
+
36
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
37
+ print("Background Information:")
38
+ print(background_info)
39
+ print("Sample Characteristics Dictionary:")
40
+ print(sample_characteristics_dict)
41
+ # 1. Gene Expression Data Availability
42
+ is_gene_available = True # Based on the background info (scRNA-Seq profiles), we assume gene expression data is available.
43
+
44
+ # 2. Variable Availability
45
+ # The sample characteristics only show {0: ['tissue: inlet cells']}, which is constant and does not reflect our trait, age, or gender.
46
+ # Hence, we treat them as not available.
47
+ trait_row = None
48
+ age_row = None
49
+ gender_row = None
50
+
51
+ # 2.2 Data Type Conversion functions (even though they're not used due to data unavailability):
52
+ def convert_trait(value: str) -> int:
53
+ # No actual data, return None directly
54
+ return None
55
+
56
+ def convert_age(value: str) -> float:
57
+ # No actual data, return None directly
58
+ return None
59
+
60
+ def convert_gender(value: str) -> int:
61
+ # No actual data, return None directly
62
+ return None
63
+
64
+ # 3. Save Metadata - initial filtering
65
+ is_trait_available = (trait_row is not None)
66
+
67
+ is_usable = validate_and_save_cohort_info(
68
+ is_final=False,
69
+ cohort=cohort,
70
+ info_path=json_path,
71
+ is_gene_available=is_gene_available,
72
+ is_trait_available=is_trait_available
73
+ )
74
+
75
+ # 4. Clinical Feature Extraction
76
+ # Since trait_row is None, we skip clinical feature extraction.
77
+ # STEP3
78
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
79
+ gene_data = get_genetic_data(matrix_file)
80
+
81
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
82
+ print(gene_data.index[:20])
p1/preprocess/Type_2_Diabetes/code/TCGA.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Type_2_Diabetes"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/1/Type_2_Diabetes/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/1/Type_2_Diabetes/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/1/Type_2_Diabetes/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/1/Type_2_Diabetes/cohort_info.json"
15
+
16
+ import os
17
+ import pandas as pd
18
+
19
+ # 1. Identify the relevant subdirectory for "Type_2_Diabetes"
20
+ subdirectories = [
21
+ 'CrawlData.ipynb', '.DS_Store', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
22
+ 'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)',
23
+ 'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
24
+ 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
25
+ 'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
26
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
27
+ 'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
28
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)',
29
+ 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
30
+ 'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)',
31
+ 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
32
+ 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)',
33
+ 'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
34
+ ]
35
+
36
+ trait_keyword = "Type_2_Diabetes"
37
+
38
+ target_subdir = None
39
+ for sd in subdirectories:
40
+ # Check if our trait keyword or synonyms appear in the directory name
41
+ if trait_keyword.lower() in sd.lower():
42
+ target_subdir = sd
43
+ break
44
+
45
+ if target_subdir is None:
46
+ # No suitable data found for this trait; mark as completed
47
+ print("No TCGA subdirectory found for the trait. Skipping.")
48
+ else:
49
+ cohort_dir = os.path.join(tcga_root_dir, target_subdir)
50
+ # 2. Locate clinical and genetic data files
51
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
52
+
53
+ # 3. Load the data
54
+ clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
55
+ genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
56
+
57
+ # 4. Print column names of clinical data
58
+ print(clinical_df.columns)
p1/preprocess/Type_2_Diabetes/cohort_info.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"GSE98887": {"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": null}, "GSE281144": {"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": 34, "note": "All preprocessing steps completed; linking and bias checks done."}, "GSE271700": {"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": "No trait data. Dataset is not usable for trait-based analyses."}, "GSE250283": {"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": "No trait data. Dataset is not usable for trait-based analyses."}, "GSE227080": {"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": "No trait data. Dataset is not usable for trait-based analyses."}, "GSE182121": {"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": "Proceeding with final linked dataset."}, "GSE182120": {"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": 49, "note": "Proceeding with final linked dataset."}, "GSE180395": {"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": "Proceeding with final linked dataset."}, "GSE180394": {"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": "Proceeding with final linked dataset."}, "GSE180393": {"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": "Proceeding with final linked dataset."}}
p1/preprocess/Type_2_Diabetes/gene_data/GSE180393.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ Gene,GSM5607752,GSM5607753,GSM5607754,GSM5607755,GSM5607756,GSM5607757,GSM5607758,GSM5607759,GSM5607760,GSM5607761,GSM5607762,GSM5607763,GSM5607764,GSM5607765,GSM5607766,GSM5607767,GSM5607768,GSM5607769,GSM5607770,GSM5607771,GSM5607772,GSM5607773,GSM5607774,GSM5607775,GSM5607776,GSM5607777,GSM5607778,GSM5607779,GSM5607780,GSM5607781,GSM5607782,GSM5607783,GSM5607784,GSM5607785,GSM5607786,GSM5607787,GSM5607788,GSM5607789,GSM5607790,GSM5607791,GSM5607792,GSM5607793,GSM5607794,GSM5607795,GSM5607796,GSM5607797,GSM5607798,GSM5607799,GSM5607800,GSM5607801,GSM5607802,GSM5607803,GSM5607804,GSM5607805,GSM5607806,GSM5607807,GSM5607808,GSM5607809,GSM5607810,GSM5607811,GSM5607812,GSM5607813
p1/preprocess/Type_2_Diabetes/gene_data/GSE180394.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ Gene,GSM5607814,GSM5607815,GSM5607816,GSM5607817,GSM5607818,GSM5607819,GSM5607820,GSM5607821,GSM5607822,GSM5607823,GSM5607824,GSM5607825,GSM5607826,GSM5607827,GSM5607828,GSM5607829,GSM5607830,GSM5607831,GSM5607832,GSM5607833,GSM5607834,GSM5607835,GSM5607836,GSM5607837,GSM5607838,GSM5607839,GSM5607840,GSM5607841,GSM5607842,GSM5607843,GSM5607844,GSM5607845,GSM5607846,GSM5607847,GSM5607848,GSM5607849,GSM5607850,GSM5607851,GSM5607852,GSM5607853,GSM5607854,GSM5607855,GSM5607856,GSM5607857,GSM5607858,GSM5607859,GSM5607860,GSM5607861,GSM5607862,GSM5607863,GSM5607864,GSM5607865,GSM5607866,GSM5607867,GSM5607868,GSM5607869,GSM5607870,GSM5607871,GSM5607872
p1/preprocess/Type_2_Diabetes/gene_data/GSE180395.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ Gene,GSM5607752,GSM5607753,GSM5607754,GSM5607755,GSM5607756,GSM5607757,GSM5607758,GSM5607759,GSM5607760,GSM5607761,GSM5607762,GSM5607763,GSM5607764,GSM5607765,GSM5607766,GSM5607767,GSM5607768,GSM5607769,GSM5607770,GSM5607771,GSM5607772,GSM5607773,GSM5607774,GSM5607775,GSM5607776,GSM5607777,GSM5607778,GSM5607779,GSM5607780,GSM5607781,GSM5607782,GSM5607783,GSM5607784,GSM5607785,GSM5607786,GSM5607787,GSM5607788,GSM5607789,GSM5607790,GSM5607791,GSM5607792,GSM5607793,GSM5607794,GSM5607795,GSM5607796,GSM5607797,GSM5607798,GSM5607799,GSM5607800,GSM5607801,GSM5607802,GSM5607803,GSM5607804,GSM5607805,GSM5607806,GSM5607807,GSM5607808,GSM5607809,GSM5607810,GSM5607811,GSM5607812,GSM5607813,GSM5607814,GSM5607815,GSM5607816,GSM5607817,GSM5607818,GSM5607819,GSM5607820,GSM5607821,GSM5607822,GSM5607823,GSM5607824,GSM5607825,GSM5607826,GSM5607827,GSM5607828,GSM5607829,GSM5607830,GSM5607831,GSM5607832,GSM5607833,GSM5607834,GSM5607835,GSM5607836,GSM5607837,GSM5607838,GSM5607839,GSM5607840,GSM5607841,GSM5607842,GSM5607843,GSM5607844,GSM5607845,GSM5607846,GSM5607847,GSM5607848,GSM5607849,GSM5607850,GSM5607851,GSM5607852,GSM5607853,GSM5607854,GSM5607855,GSM5607856,GSM5607857,GSM5607858,GSM5607859,GSM5607860,GSM5607861,GSM5607862,GSM5607863,GSM5607864,GSM5607865,GSM5607866,GSM5607867,GSM5607868,GSM5607869,GSM5607870,GSM5607871,GSM5607872
p1/preprocess/Type_2_Diabetes/gene_data/GSE182120.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f57f3160d99f6760730d3716e814953d36fa7f73b1dd5f098c8a488fa4e19c20
3
+ size 17706529
p1/preprocess/Type_2_Diabetes/gene_data/GSE182121.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ ID,GSM5518937,GSM5518938,GSM5518939,GSM5518940,GSM5518941,GSM5518942,GSM5518943,GSM5518944,GSM5518945,GSM5518946,GSM5518947,GSM5518948,GSM5518949,GSM5518950,GSM5518951,GSM5518952,GSM5518953,GSM5518954,GSM5518955,GSM5518956,GSM5518957,GSM5518958,GSM5518959,GSM5518960,GSM5518961,GSM5518962,GSM5518963,GSM5518964,GSM5518965,GSM5518966,GSM5518967,GSM5518968,GSM5518969,GSM5518970,GSM5518971,GSM5518972,GSM5518973,GSM5518974,GSM5518975,GSM5518976,GSM5518977,GSM5518978,GSM5518979,GSM5518980,GSM5518981,GSM5518982,GSM5518983,GSM5518984,GSM5518985
p1/preprocess/Type_2_Diabetes/gene_data/GSE227080.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Type_2_Diabetes/gene_data/GSE250283.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7cb78956d52d9800fde6cd29df8e74629bcc74d66008fcf97d339c023dda7da
3
+ size 12423542
p1/preprocess/Type_2_Diabetes/gene_data/GSE271700.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ Gene,GSM8382768,GSM8382769,GSM8382770,GSM8382771,GSM8382772,GSM8382773,GSM8382774,GSM8382775,GSM8382776,GSM8382777,GSM8382778,GSM8382779,GSM8382780,GSM8382781,GSM8382782,GSM8382783,GSM8382784,GSM8382785,GSM8382786,GSM8382787,GSM8382788,GSM8382789,GSM8382790,GSM8382791,GSM8382792,GSM8382793,GSM8382794,GSM8382795,GSM8382796,GSM8382797,GSM8382798,GSM8382799,GSM8382800,GSM8382801,GSM8382802,GSM8382803,GSM8382804,GSM8382805,GSM8382806,GSM8382807,GSM8382808,GSM8382809,GSM8382810,GSM8382811,GSM8382812,GSM8382813,GSM8382814,GSM8382815,GSM8382816,GSM8382817,GSM8382818,GSM8382819,GSM8382820,GSM8382821,GSM8382822,GSM8382823,GSM8382824,GSM8382825,GSM8382826,GSM8382827,GSM8382828,GSM8382829,GSM8382830,GSM8382831,GSM8382832,GSM8382833,GSM8382834,GSM8382835,GSM8382836,GSM8382837,GSM8382838,GSM8382839,GSM8382840
p1/preprocess/Type_2_Diabetes/gene_data/GSE281144.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8483fe08215b894dbff26b549aa32a1e016306417e26e1280d877ce2c7934964
3
+ size 10703852
p1/preprocess/Underweight/GSE57802.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6f8f17730827fcc66ba1f050455650af4ec4b87b8c106b364e207e406ebf98e7
3
+ size 16353386
p1/preprocess/Underweight/clinical_data/GSE130563.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ GSM3743555,GSM3743556,GSM3743557,GSM3743558,GSM3743559,GSM3743560,GSM3743561,GSM3743562,GSM3743563,GSM3743564,GSM3743565,GSM3743566,GSM3743567,GSM3743568,GSM3743569,GSM3743570,GSM3743571,GSM3743572,GSM3743573,GSM3743574,GSM3743575,GSM3743576,GSM3743577,GSM3743578,GSM3743579,GSM3743580,GSM3743581,GSM3743582,GSM3743583,GSM3743584,GSM3743585,GSM3743586,GSM3743587,GSM3743588,GSM3743589,GSM3743590,GSM3743591,GSM3743592,GSM3743593,GSM3743594,GSM3743595,GSM3743596,GSM3743597,GSM3743598,GSM3743599,GSM3743600
2
+ 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,1.0,1.0,1.0,1.0,1.0,1.0,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,,,,,,,,
3
+ 33.0,68.0,73.0,49.0,78.0,57.0,55.0,50.0,47.0,63.0,51.0,50.0,69.0,50.0,60.0,68.0,66.0,54.0,64.0,76.0,68.0,73.0,56.0,80.0,68.0,79.0,72.0,52.0,74.0,74.0,55.0,56.0,77.0,70.0,70.0,63.0,59.0,74.0,30.0,51.0,55.0,55.0,45.0,58.0,50.0,54.0
4
+ 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,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0
p1/preprocess/Underweight/clinical_data/GSE57802.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ GSM1389621,GSM1389622,GSM1389623,GSM1389624,GSM1389625,GSM1389626,GSM1389627,GSM1389628,GSM1389629,GSM1389630,GSM1389631,GSM1389632,GSM1389633,GSM1389634,GSM1389635,GSM1389636,GSM1389637,GSM1389638,GSM1389639,GSM1389640,GSM1389641,GSM1389642,GSM1389643,GSM1389644,GSM1389645,GSM1389646,GSM1389647,GSM1389648,GSM1389649,GSM1389650,GSM1389651,GSM1389652,GSM1389653,GSM1389654,GSM1389655,GSM1389656,GSM1389657,GSM1389658,GSM1389659,GSM1389660,GSM1389661,GSM1389662,GSM1389663,GSM1389664,GSM1389665,GSM1389666,GSM1389667,GSM1389668,GSM1389669,GSM1389670,GSM1389671,GSM1389672,GSM1389673,GSM1389674,GSM1389675,GSM1389676,GSM1389677,GSM1389678,GSM1389679,GSM1389680,GSM1389681,GSM1389682,GSM1389683,GSM1389684,GSM1389685,GSM1389686,GSM1389687,GSM1389688,GSM1389689,GSM1389690,GSM1389691,GSM1389692,GSM1389693,GSM1389694,GSM1389695,GSM1389696,GSM1389697,GSM1389698,GSM1389699,GSM1389700,GSM1389701,GSM1389702,GSM1389703,GSM1389704,GSM1389705,GSM1389706,GSM1389707,GSM1389708,GSM1389709,GSM1389710,GSM1389711,GSM1389712,GSM1389713,GSM1389714,GSM1389715,GSM1389716,GSM1389717,GSM1389718,GSM1389719
2
+ 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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
3
+ 46.0,33.0,,,22.0,52.0,25.0,31.0,60.0,,40.0,50.0,51.0,39.0,6.0,51.0,56.0,16.0,41.0,31.0,35.0,4.0,10.0,12.0,7.0,6.0,1.4,10.0,6.0,38.0,14.7,11.0,7.0,12.8,11.9,7.7,3.3,1.5,16.0,40.0,39.0,12.0,5.9,4.1,5.2,9.0,37.0,14.8,15.0,5.7,23.0,6.8,53.0,8.8,6.8,26.0,21.0,13.0,12.0,21.0,10.0,15.0,11.0,5.5,3.7,4.0,7.0,5.0,5.0,42.0,42.0,5.0,8.0,15.0,3.4,44.0,16.0,52.0,28.0,0.6,14.0,1.8,40.0,9.0,5.2,5.5,28.0,42.0,12.8,36.0,3.0,41.0,6.0,76.0,47.0,44.0,3.0,34.0,11.0
4
+ 1.0,0.0,1.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,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,0.0,0.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,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.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,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,1.0,0.0,0.0,0.0,1.0
p1/preprocess/Underweight/code/GSE130563.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Underweight"
6
+ cohort = "GSE130563"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Underweight"
10
+ in_cohort_dir = "../DATA/GEO/Underweight/GSE130563"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Underweight/GSE130563.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Underweight/gene_data/GSE130563.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Underweight/clinical_data/GSE130563.csv"
16
+ json_path = "./output/preprocess/1/Underweight/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1) Gene Expression Data Availability
37
+ # Based on the background info, this dataset involves microarray analysis for gene expression.
38
+ is_gene_available = True
39
+
40
+ # 2) Variable Availability and Data Type Conversion
41
+ # We identify the keys in the sample characteristics that hold relevant info
42
+ # for trait (interpreted as whether one is "underweight" by applying a cachexia-based threshold),
43
+ # age, and gender.
44
+ trait_row = 3 # "bw loss in 6 months prior to surgery"
45
+ age_row = 4 # "age"
46
+ gender_row = 1 # "Sex"
47
+
48
+ # Define the conversion functions
49
+ def convert_trait(val: str) -> int:
50
+ """
51
+ Convert "bw loss in 6 months prior to surgery" to a binary:
52
+ 1 if weight loss > 5%, else 0. If 'n.d.' return None.
53
+ """
54
+ # Example val: "bw loss in 6 months prior to surgery: 10"
55
+ parts = val.split(':')
56
+ if len(parts) < 2:
57
+ return None
58
+ raw_value = parts[1].strip()
59
+ if 'n.d.' in raw_value.lower():
60
+ return None
61
+ try:
62
+ loss = float(raw_value)
63
+ return 1 if loss > 5 else 0
64
+ except ValueError:
65
+ return None
66
+
67
+ def convert_age(val: str) -> float:
68
+ """
69
+ Convert "age" to a continuous float.
70
+ If 'n.d.' or not parseable, return None.
71
+ """
72
+ # Example val: "age: 65"
73
+ parts = val.split(':')
74
+ if len(parts) < 2:
75
+ return None
76
+ raw_value = parts[1].strip()
77
+ if 'n.d.' in raw_value.lower():
78
+ return None
79
+ try:
80
+ return float(raw_value)
81
+ except ValueError:
82
+ return None
83
+
84
+ def convert_gender(val: str) -> int:
85
+ """
86
+ Convert "Sex: F/M" to binary (F=0, M=1).
87
+ If unknown, return None.
88
+ """
89
+ # Example val: "Sex: F"
90
+ parts = val.split(':')
91
+ if len(parts) < 2:
92
+ return None
93
+ raw_value = parts[1].strip().upper()
94
+ if raw_value.startswith('F'):
95
+ return 0
96
+ elif raw_value.startswith('M'):
97
+ return 1
98
+ return None
99
+
100
+ # Determine if trait data is available
101
+ is_trait_available = (trait_row is not None)
102
+
103
+ # 3) Save Metadata (initial filtering)
104
+ # Since we haven't fully validated or integrated the data, use is_final=False.
105
+ # is_biased can be omitted at this stage.
106
+ validate_and_save_cohort_info(
107
+ is_final=False,
108
+ cohort=cohort,
109
+ info_path=json_path,
110
+ is_gene_available=is_gene_available,
111
+ is_trait_available=is_trait_available
112
+ )
113
+
114
+ # 4) Clinical Feature Extraction (only if trait_row is not None)
115
+ if trait_row is not None:
116
+ # Suppose we already have the clinical data DataFrame loaded as 'clinical_data'.
117
+ # In practice, it should be provided from a previous context or file read.
118
+ # For demonstration, assume 'clinical_data' is available here.
119
+ selected_clinical_df = geo_select_clinical_features(
120
+ clinical_df=clinical_data,
121
+ trait=trait, # "Underweight"
122
+ trait_row=trait_row,
123
+ convert_trait=convert_trait,
124
+ age_row=age_row,
125
+ convert_age=convert_age,
126
+ gender_row=gender_row,
127
+ convert_gender=convert_gender
128
+ )
129
+
130
+ # Preview the extracted data
131
+ preview = preview_df(selected_clinical_df)
132
+ print("Preview of clinical features:", preview)
133
+
134
+ # Save the clinical features to a CSV file
135
+ selected_clinical_df.to_csv(out_clinical_data_file, index=False)
136
+ # STEP3
137
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
138
+ gene_data = get_genetic_data(matrix_file)
139
+
140
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
141
+ print(gene_data.index[:20])
142
+ print("requires_gene_mapping = True")
143
+ # STEP5
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
+ # STEP 6: Gene Identifier Mapping
151
+ # Revert to using the "ORF" column as the gene symbol column since "Gene Symbol" does not exist.
152
+
153
+ probe_col = "ID"
154
+ gene_symbol_col = "ORF"
155
+
156
+ # 1) Create the mapping DataFrame
157
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
158
+
159
+ # 2) Apply gene mapping to convert probe-level data to gene-level data
160
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
161
+
162
+ # Print out shape or other info to confirm a successful mapping
163
+ print(f"Gene data after mapping: {gene_data.shape}")
p1/preprocess/Underweight/code/GSE131835.py ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Underweight"
6
+ cohort = "GSE131835"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Underweight"
10
+ in_cohort_dir = "../DATA/GEO/Underweight/GSE131835"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Underweight/GSE131835.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Underweight/gene_data/GSE131835.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Underweight/clinical_data/GSE131835.csv"
16
+ json_path = "./output/preprocess/1/Underweight/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ # Based on the background, this dataset used an Affymetrix Clariom S Microarray platform,
38
+ # which indicates it's likely to contain gene expression data.
39
+ is_gene_available = True
40
+
41
+ # 2. Variable Availability and Data Type Conversion
42
+ # For the 'trait' (Underweight), we find no row in the sample dictionary that directly or
43
+ # reliably indicates "Underweight" status. Hence trait data is unavailable.
44
+ trait_row = None
45
+
46
+ # Row 3 has multiple distinct "age" values, so age data is available.
47
+ age_row = 3
48
+
49
+ # Row 2 has multiple distinct "Sex" values, so gender data is available.
50
+ gender_row = 2
51
+
52
+ # Conversion functions
53
+ def convert_trait(x: str):
54
+ # No direct or inferable mapping for 'Underweight' in this dataset
55
+ return None
56
+
57
+ def convert_age(x: str):
58
+ try:
59
+ val_str = x.split(':')[1].strip()
60
+ return float(val_str)
61
+ except:
62
+ return None
63
+
64
+ def convert_gender(x: str):
65
+ val_str = x.split(':')[1].strip().lower()
66
+ if val_str == "female":
67
+ return 0
68
+ elif val_str == "male":
69
+ return 1
70
+ else:
71
+ return None
72
+
73
+ # 3. Save Metadata (Initial Filtering)
74
+ is_trait_available = (trait_row is not None)
75
+ is_usable = 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
+ # 4. Clinical Feature Extraction (Only if trait_row is not None)
84
+ # Since trait_row is None, we skip this step.
85
+ # STEP3
86
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
87
+ gene_data = get_genetic_data(matrix_file)
88
+
89
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
90
+ print(gene_data.index[:20])
91
+ # Based on the observed identifiers (e.g., ENSG00000000003_at), these appear to be Ensembl gene IDs
92
+ # appended with '_at', which are not standard HGNC gene symbols. Therefore, gene symbol mapping is required.
93
+ print("They are Ensembl gene IDs, not human gene symbols.")
94
+
95
+ # Conclusion:
96
+ print("requires_gene_mapping = True")
97
+ # STEP5
98
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
99
+ gene_annotation = get_gene_annotation(soft_file)
100
+
101
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
102
+ print("Gene annotation preview:")
103
+ print(preview_df(gene_annotation))
104
+ # STEP: Gene Identifier Mapping
105
+
106
+ # 1 & 2. Identify the columns in gene_annotation that match the gene expression "ID" and the actual gene symbol.
107
+ # From the previous preview, "ID" in gene_annotation matches expression row IDs, and "ORF" holds the gene symbol.
108
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='ORF')
109
+
110
+ # 3. Convert probe-level measurements to gene-level data by applying the mapping.
111
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
112
+
113
+ # For confirmation, let's print out the dimensions of the resulting gene_data
114
+ # and preview the first 10 gene symbols in the index.
115
+ print("Gene data shape:", gene_data.shape)
116
+ print("First 10 gene symbols:", gene_data.index[:10].tolist())
117
+ # STEP7
118
+
119
+ import pandas as pd
120
+
121
+ # Check if clinical data (and thus the trait) was actually extracted in a previous step
122
+ # by testing whether "selected_clinical_df" exists.
123
+ try:
124
+ selected_clinical_df
125
+ trait_data_available = True
126
+ except NameError:
127
+ trait_data_available = False
128
+
129
+ if not trait_data_available:
130
+ # Since there's no clinical DataFrame, we finalize the dataset as unusable for trait analysis
131
+ # (missing trait), and skip further processing.
132
+ empty_df = pd.DataFrame()
133
+ # Mark trait as biased (or simply unusable) to ensure the final validation flags it as not usable
134
+ is_trait_biased = True
135
+ validate_and_save_cohort_info(
136
+ is_final=True,
137
+ cohort=cohort,
138
+ info_path=json_path,
139
+ is_gene_available=True, # We do have gene data, but no trait data
140
+ is_trait_available=False,
141
+ is_biased=is_trait_biased,
142
+ df=empty_df,
143
+ note="No trait data found; dataset is not usable for trait-based analysis."
144
+ )
145
+ else:
146
+ # 1. Normalize the obtained gene data and save
147
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
148
+ normalized_gene_data.to_csv(out_gene_data_file)
149
+
150
+ # 2. Link clinical and gene expression data on sample IDs
151
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
152
+
153
+ # 3. Handle missing values systematically using the trait column name in the 'trait' variable
154
+ linked_data = handle_missing_values(linked_data, trait)
155
+
156
+ # 4. Check for biased features (trait, age, gender) using the same trait column name
157
+ is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
158
+
159
+ # 5. Final quality validation and record metadata
160
+ is_usable = validate_and_save_cohort_info(
161
+ is_final=True,
162
+ cohort=cohort,
163
+ info_path=json_path,
164
+ is_gene_available=True,
165
+ is_trait_available=True,
166
+ is_biased=is_trait_biased,
167
+ df=linked_data,
168
+ note=f"Preprocessed with trait column named '{trait}'."
169
+ )
170
+
171
+ # 6. If usable, save linked data
172
+ if is_usable and (len(linked_data) > 0):
173
+ linked_data.to_csv(out_data_file, index=True)