Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- output/preprocess/Metabolic_Rate/clinical_data/GSE101492.csv +1 -2
- output/preprocess/Metabolic_Rate/clinical_data/GSE61225.csv +4 -75
- output/preprocess/Metabolic_Rate/code/GSE101492.py +210 -0
- output/preprocess/Metabolic_Rate/code/GSE106800.py +179 -0
- output/preprocess/Metabolic_Rate/code/GSE151683.py +110 -0
- output/preprocess/Metabolic_Rate/code/GSE23025.py +134 -0
- output/preprocess/Metabolic_Rate/code/GSE26440.py +103 -0
- output/preprocess/Metabolic_Rate/code/GSE40589.py +224 -0
- output/preprocess/Metabolic_Rate/code/GSE40873.py +118 -0
- output/preprocess/Metabolic_Rate/code/GSE41168.py +124 -0
- output/preprocess/Metabolic_Rate/code/GSE61225.py +201 -0
- output/preprocess/Metabolic_Rate/code/GSE89231.py +147 -0
- output/preprocess/Metabolic_Rate/code/TCGA.py +68 -0
- output/preprocess/Migraine/clinical_data/GSE67311.csv +2 -0
- output/preprocess/Migraine/code/GSE67311.py +258 -0
- output/preprocess/Migraine/code/TCGA.py +53 -0
- output/preprocess/Migraine/cohort_info.json +1 -22
- output/preprocess/Mitochondrial_Disorders/GSE42986.csv +0 -0
- output/preprocess/Mitochondrial_Disorders/clinical_data/GSE42986.csv +1 -1
- output/preprocess/Mitochondrial_Disorders/code/GSE22651.py +132 -0
- output/preprocess/Mitochondrial_Disorders/code/GSE30933.py +185 -0
- output/preprocess/Mitochondrial_Disorders/code/GSE42986.py +209 -0
- output/preprocess/Mitochondrial_Disorders/code/GSE65399.py +129 -0
- output/preprocess/Mitochondrial_Disorders/code/TCGA.py +65 -0
- output/preprocess/Mitochondrial_Disorders/cohort_info.json +1 -52
- output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/GSE19987.csv +0 -0
- output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/clinical_data/GSE19987.csv +2 -2
- output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/code/GSE19987.py +200 -0
- output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/code/TCGA.py +209 -0
- output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/cohort_info.json +1 -22
- output/preprocess/Multiple_sclerosis/clinical_data/GSE131282.csv +1 -1
- output/preprocess/Multiple_sclerosis/code/GSE131279.py +177 -0
- output/preprocess/Multiple_sclerosis/code/GSE131281.py +196 -0
- output/preprocess/Multiple_sclerosis/code/GSE131282.py +187 -0
- output/preprocess/Multiple_sclerosis/code/GSE135511.py +169 -0
- output/preprocess/Multiple_sclerosis/code/GSE141381.py +162 -0
- output/preprocess/Multiple_sclerosis/code/GSE141804.py +221 -0
- output/preprocess/Multiple_sclerosis/code/GSE146383.py +210 -0
- output/preprocess/Multiple_sclerosis/code/GSE189788.py +131 -0
- output/preprocess/Multiple_sclerosis/code/GSE193442.py +133 -0
- output/preprocess/Multiple_sclerosis/code/GSE203241.py +209 -0
- output/preprocess/Multiple_sclerosis/code/TCGA.py +64 -0
- output/preprocess/Multiple_sclerosis/cohort_info.json +1 -112
- output/preprocess/Obesity/GSE181339.csv +0 -0
- output/preprocess/Obesity/clinical_data/GSE123086.csv +4 -4
- output/preprocess/Obesity/clinical_data/GSE123088.csv +1 -1
- output/preprocess/Obesity/clinical_data/GSE158237.csv +4 -4
- output/preprocess/Obesity/clinical_data/GSE181339.csv +4 -4
- output/preprocess/Obesity/clinical_data/GSE271700.csv +3 -4
- output/preprocess/Obesity/clinical_data/GSE281144.csv +3 -0
output/preprocess/Metabolic_Rate/clinical_data/GSE101492.csv
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
,GSM2704900,GSM2704901,GSM2704902,GSM2704903,GSM2704904,GSM2704905,GSM2704906,GSM2704907,GSM2704908,GSM2704909,GSM2704910,GSM2704911,GSM2704912,GSM2704913,GSM2704914,GSM2704915,GSM2704916,GSM2704917,GSM2704918,GSM2704919,GSM2704920,GSM2704921,GSM2704922,GSM2704923,GSM2704924,GSM2704925,GSM2704926,GSM2704927,GSM2704928,GSM2704929,GSM2704930,GSM2704931,GSM2704932,GSM2704933,GSM2704934,GSM2704935,GSM2704936,GSM2704937,GSM2704938,GSM2704939,GSM2704940,GSM2704941,GSM2704942,GSM2704943,GSM2704944,GSM2704945,GSM2704946,GSM2704947,GSM2704948,GSM2704949,GSM2704950,GSM2704951,GSM2704952,GSM2704953,GSM2704954,GSM2704955,GSM2704956,GSM2704957,GSM2704958,GSM2704959,GSM2704960,GSM2704961,GSM2704962,GSM2704963,GSM2704964,GSM2704965,GSM2704966,GSM2704967,GSM2704968,GSM2704969,GSM2704970,GSM2704971,GSM2704972,GSM2704973,GSM2704974,GSM2704975,GSM2704976,GSM2704977,GSM2704978,GSM2704979
|
| 2 |
-
Metabolic_Rate,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
| 3 |
Age,39.0,28.0,42.0,30.0,42.0,37.0,36.0,33.0,27.0,43.0,37.0,42.0,43.0,39.0,42.0,44.0,25.0,36.0,25.0,25.0,44.0,43.0,44.0,35.0,40.0,25.0,29.0,41.0,34.0,43.0,31.0,41.0,37.0,39.0,29.0,28.0,35.0,37.0,36.0,40.0,30.0,33.0,34.0,40.0,40.0,30.0,38.0,40.0,28.0,39.0,42.0,44.0,40.0,34.0,33.0,41.0,41.0,42.0,36.0,40.0,33.0,39.0,44.0,29.0,28.0,36.0,41.0,43.0,43.0,26.0,33.0,32.0,38.0,31.0,30.0,28.0,27.0,45.0,40.0,25.0
|
| 4 |
-
Gender,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
|
|
|
|
| 1 |
,GSM2704900,GSM2704901,GSM2704902,GSM2704903,GSM2704904,GSM2704905,GSM2704906,GSM2704907,GSM2704908,GSM2704909,GSM2704910,GSM2704911,GSM2704912,GSM2704913,GSM2704914,GSM2704915,GSM2704916,GSM2704917,GSM2704918,GSM2704919,GSM2704920,GSM2704921,GSM2704922,GSM2704923,GSM2704924,GSM2704925,GSM2704926,GSM2704927,GSM2704928,GSM2704929,GSM2704930,GSM2704931,GSM2704932,GSM2704933,GSM2704934,GSM2704935,GSM2704936,GSM2704937,GSM2704938,GSM2704939,GSM2704940,GSM2704941,GSM2704942,GSM2704943,GSM2704944,GSM2704945,GSM2704946,GSM2704947,GSM2704948,GSM2704949,GSM2704950,GSM2704951,GSM2704952,GSM2704953,GSM2704954,GSM2704955,GSM2704956,GSM2704957,GSM2704958,GSM2704959,GSM2704960,GSM2704961,GSM2704962,GSM2704963,GSM2704964,GSM2704965,GSM2704966,GSM2704967,GSM2704968,GSM2704969,GSM2704970,GSM2704971,GSM2704972,GSM2704973,GSM2704974,GSM2704975,GSM2704976,GSM2704977,GSM2704978,GSM2704979
|
| 2 |
+
Metabolic_Rate,0.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,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0
|
| 3 |
Age,39.0,28.0,42.0,30.0,42.0,37.0,36.0,33.0,27.0,43.0,37.0,42.0,43.0,39.0,42.0,44.0,25.0,36.0,25.0,25.0,44.0,43.0,44.0,35.0,40.0,25.0,29.0,41.0,34.0,43.0,31.0,41.0,37.0,39.0,29.0,28.0,35.0,37.0,36.0,40.0,30.0,33.0,34.0,40.0,40.0,30.0,38.0,40.0,28.0,39.0,42.0,44.0,40.0,34.0,33.0,41.0,41.0,42.0,36.0,40.0,33.0,39.0,44.0,29.0,28.0,36.0,41.0,43.0,43.0,26.0,33.0,32.0,38.0,31.0,30.0,28.0,27.0,45.0,40.0,25.0
|
|
|
output/preprocess/Metabolic_Rate/clinical_data/GSE61225.csv
CHANGED
|
@@ -1,75 +1,4 @@
|
|
| 1 |
-
,
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
GSM1499832,0.8313807,24.39425,0.0
|
| 6 |
-
GSM1499833,0.786010716020953,51.2115,1.0
|
| 7 |
-
GSM1499834,0.9825132,51.2115,1.0
|
| 8 |
-
GSM1499835,0.744848045678339,30.16838,1.0
|
| 9 |
-
GSM1499836,0.9310601,30.16838,1.0
|
| 10 |
-
GSM1499837,0.814710221540659,26.02053,0.0
|
| 11 |
-
GSM1499838,1.018388,26.02053,0.0
|
| 12 |
-
GSM1499839,0.709058218744461,29.64819,1.0
|
| 13 |
-
GSM1499840,0.8863227,29.64819,1.0
|
| 14 |
-
GSM1499841,0.733268847575824,33.63176,1.0
|
| 15 |
-
GSM1499842,0.9165859,33.63176,1.0
|
| 16 |
-
GSM1499843,0.728783827412329,28.3258,1.0
|
| 17 |
-
GSM1499844,0.9109797,28.3258,1.0
|
| 18 |
-
GSM1499845,0.759969166965226,27.32101,0.0
|
| 19 |
-
GSM1499846,2.277797,27.32101,0.0
|
| 20 |
-
GSM1499847,0.863847192835992,26.20945,0.0
|
| 21 |
-
GSM1499848,2.987472,26.20945,0.0
|
| 22 |
-
GSM1499849,0.732301833893021,30.19576,0.0
|
| 23 |
-
GSM1499850,4.727416,30.19576,0.0
|
| 24 |
-
GSM1499851,0.755339902416559,35.37851,0.0
|
| 25 |
-
GSM1499852,3.308808,35.37851,0.0
|
| 26 |
-
GSM1499853,0.757193473208602,23.36208,1.0
|
| 27 |
-
GSM1499854,0.9464918,23.36208,1.0
|
| 28 |
-
GSM1499855,0.709058218744461,29.64819,1.0
|
| 29 |
-
GSM1499856,1.471296,29.64819,1.0
|
| 30 |
-
GSM1499857,0.812838481910338,38.17112,0.0
|
| 31 |
-
GSM1499858,3.748088,38.17112,0.0
|
| 32 |
-
GSM1499859,0.915727555354096,41.41821,0.0
|
| 33 |
-
GSM1499860,4.644773,41.41821,0.0
|
| 34 |
-
GSM1499861,0.736619878676601,40.75838,1.0
|
| 35 |
-
GSM1499862,4.075963,40.75838,1.0
|
| 36 |
-
GSM1499863,0.73853661923046,22.71869,0.0
|
| 37 |
-
GSM1499864,3.064927,22.71869,0.0
|
| 38 |
-
GSM1499865,0.705031456992829,37.81246,1.0
|
| 39 |
-
GSM1499866,3.250978,37.81246,1.0
|
| 40 |
-
GSM1499867,0.660887301626415,30.9076,1.0
|
| 41 |
-
GSM1499868,3.047425,30.9076,1.0
|
| 42 |
-
GSM1499869,0.760896527420428,29.45654,0.0
|
| 43 |
-
GSM1499870,0.9511205,29.45654,0.0
|
| 44 |
-
GSM1499871,0.740808706999891,33.64271,0.0
|
| 45 |
-
GSM1499872,2.220368,33.64271,0.0
|
| 46 |
-
GSM1499873,0.744848045678339,30.16838,1.0
|
| 47 |
-
GSM1499874,1.889017,30.16838,1.0
|
| 48 |
-
GSM1499875,0.74715416981939,30.43669,0.0
|
| 49 |
-
GSM1499876,1.722605,30.43669,0.0
|
| 50 |
-
GSM1499877,0.813342819234442,32.33949,1.0
|
| 51 |
-
GSM1499878,2.062728,32.33949,1.0
|
| 52 |
-
GSM1499879,0.718701917558319,24.53114,0.0
|
| 53 |
-
GSM1499880,2.899763,24.53114,0.0
|
| 54 |
-
GSM1499881,0.734934524683196,30.20671,1.0
|
| 55 |
-
GSM1499882,3.727751,30.20671,1.0
|
| 56 |
-
GSM1499883,0.720948083807537,39.97262,0.0
|
| 57 |
-
GSM1499884,4.487902,39.97262,0.0
|
| 58 |
-
GSM1499885,0.881592993199644,39.2334,0.0
|
| 59 |
-
GSM1499886,2.235817,39.2334,0.0
|
| 60 |
-
GSM1499887,0.595372813525237,25.21013,1.0
|
| 61 |
-
GSM1499888,2.33353,25.21013,1.0
|
| 62 |
-
GSM1499889,0.948882866645629,25.42916,0.0
|
| 63 |
-
GSM1499890,4.375404,25.42916,0.0
|
| 64 |
-
GSM1499891,0.638827477795041,28.46544,0.0
|
| 65 |
-
GSM1499892,2.945704,28.46544,0.0
|
| 66 |
-
GSM1499893,0.711721049272041,28.7885,0.0
|
| 67 |
-
GSM1499894,2.461369,28.7885,0.0
|
| 68 |
-
GSM1499895,0.6815901810508,31.49897,0.0
|
| 69 |
-
GSM1499896,2.200022,31.49897,0.0
|
| 70 |
-
GSM1499897,0.814710221540659,26.02053,0.0
|
| 71 |
-
GSM1499898,1.40877,26.02053,0.0
|
| 72 |
-
GSM1499899,0.733268847575824,33.63176,1.0
|
| 73 |
-
GSM1499900,5.917071,33.63176,1.0
|
| 74 |
-
GSM1499901,0.74230759890745,28.59138,0.0
|
| 75 |
-
GSM1499902,3.936292,28.59138,0.0
|
|
|
|
| 1 |
+
,GSM1499829,GSM1499830,GSM1499831,GSM1499832,GSM1499833,GSM1499834,GSM1499835,GSM1499836,GSM1499837,GSM1499838,GSM1499839,GSM1499840,GSM1499841,GSM1499842,GSM1499843,GSM1499844,GSM1499845,GSM1499846,GSM1499847,GSM1499848,GSM1499849,GSM1499850,GSM1499851,GSM1499852,GSM1499853,GSM1499854,GSM1499855,GSM1499856,GSM1499857,GSM1499858,GSM1499859,GSM1499860,GSM1499861,GSM1499862,GSM1499863,GSM1499864,GSM1499865,GSM1499866,GSM1499867,GSM1499868,GSM1499869,GSM1499870,GSM1499871,GSM1499872,GSM1499873,GSM1499874,GSM1499875,GSM1499876,GSM1499877,GSM1499878,GSM1499879,GSM1499880,GSM1499881,GSM1499882,GSM1499883,GSM1499884,GSM1499885,GSM1499886,GSM1499887,GSM1499888,GSM1499889,GSM1499890,GSM1499891,GSM1499892,GSM1499893,GSM1499894,GSM1499895,GSM1499896,GSM1499897,GSM1499898,GSM1499899,GSM1499900,GSM1499901,GSM1499902
|
| 2 |
+
Metabolic_Rate,0.681873816522757,0.8523423,0.665104620956877,0.8313807,0.786010716020953,0.9825132,0.744848045678339,0.9310601,0.814710221540659,1.018388,0.709058218744461,0.8863227,0.733268847575824,0.9165859,0.728783827412329,0.9109797,0.759969166965226,2.277797,0.863847192835992,2.987472,0.732301833893021,4.727416,0.755339902416559,3.308808,0.757193473208602,0.9464918,0.709058218744461,1.471296,0.812838481910338,3.748088,0.915727555354096,4.644773,0.736619878676601,4.075963,0.73853661923046,3.064927,0.705031456992829,3.250978,0.660887301626415,3.047425,0.760896527420428,0.9511205,0.740808706999891,2.220368,0.744848045678339,1.889017,0.74715416981939,1.722605,0.813342819234442,2.062728,0.718701917558319,2.899763,0.734934524683196,3.727751,0.720948083807537,4.487902,0.881592993199644,2.235817,0.595372813525237,2.33353,0.948882866645629,4.375404,0.638827477795041,2.945704,0.711721049272041,2.461369,0.6815901810508,2.200022,0.814710221540659,1.40877,0.733268847575824,5.917071,0.74230759890745,3.936292
|
| 3 |
+
Age,31.60849,31.60849,24.39425,24.39425,51.2115,51.2115,30.16838,30.16838,26.02053,26.02053,29.64819,29.64819,33.63176,33.63176,28.3258,28.3258,27.32101,27.32101,26.20945,26.20945,30.19576,30.19576,35.37851,35.37851,23.36208,23.36208,29.64819,29.64819,38.17112,38.17112,41.41821,41.41821,40.75838,40.75838,22.71869,22.71869,37.81246,37.81246,30.9076,30.9076,29.45654,29.45654,33.64271,33.64271,30.16838,30.16838,30.43669,30.43669,32.33949,32.33949,24.53114,24.53114,30.20671,30.20671,39.97262,39.97262,39.2334,39.2334,25.21013,25.21013,25.42916,25.42916,28.46544,28.46544,28.7885,28.7885,31.49897,31.49897,26.02053,26.02053,33.63176,33.63176,28.59138,28.59138
|
| 4 |
+
Gender,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,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,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output/preprocess/Metabolic_Rate/code/GSE101492.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE101492"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE101492"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE101492.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE101492.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE101492.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
import pandas as pd
|
| 42 |
+
|
| 43 |
+
# 1) Gene expression data availability (lncRNA expression; not miRNA or methylation)
|
| 44 |
+
is_gene_available = True
|
| 45 |
+
|
| 46 |
+
# 2) Variable availability and conversion functions
|
| 47 |
+
# Trait proxy in this dataset: insulin sensitivity (insulin sensitive vs insulin resistant) -> row 3
|
| 48 |
+
# Age: row 2 (continuous)
|
| 49 |
+
# Gender: row 1 but constant "female" -> not useful for association (set to None)
|
| 50 |
+
trait_row = 3
|
| 51 |
+
age_row = 2
|
| 52 |
+
gender_row = None # constant "female" across all samples -> not useful
|
| 53 |
+
|
| 54 |
+
def _after_colon(val):
|
| 55 |
+
if val is None:
|
| 56 |
+
return None
|
| 57 |
+
s = str(val)
|
| 58 |
+
parts = s.split(":", 1)
|
| 59 |
+
return parts[1].strip() if len(parts) > 1 else s.strip()
|
| 60 |
+
|
| 61 |
+
def convert_trait(x):
|
| 62 |
+
# Map insulin sensitivity to binary: insulin sensitive -> 0, insulin resistant -> 1
|
| 63 |
+
v = _after_colon(x)
|
| 64 |
+
if v is None or v == "":
|
| 65 |
+
return None
|
| 66 |
+
v_low = v.lower()
|
| 67 |
+
if "insulin resistant" in v_low or v_low in {"ir", "resistant"}:
|
| 68 |
+
return 1
|
| 69 |
+
if "insulin sensitive" in v_low or v_low in {"is", "sensitive"}:
|
| 70 |
+
return 0
|
| 71 |
+
return None
|
| 72 |
+
|
| 73 |
+
def convert_age(x):
|
| 74 |
+
v = _after_colon(x)
|
| 75 |
+
if v is None or v == "":
|
| 76 |
+
return None
|
| 77 |
+
v = v.lower()
|
| 78 |
+
m = re.search(r"[-+]?\d*\.?\d+", v)
|
| 79 |
+
if not m:
|
| 80 |
+
return None
|
| 81 |
+
try:
|
| 82 |
+
return float(m.group(0))
|
| 83 |
+
except Exception:
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
def convert_gender(x):
|
| 87 |
+
v = _after_colon(x)
|
| 88 |
+
if v is None or v == "":
|
| 89 |
+
return None
|
| 90 |
+
v_low = v.lower()
|
| 91 |
+
if "female" in v_low or v_low in {"f", "woman", "women"}:
|
| 92 |
+
return 0
|
| 93 |
+
if "male" in v_low or v_low in {"m", "man", "men"}:
|
| 94 |
+
return 1
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
# 3) Save metadata (initial filtering)
|
| 98 |
+
is_trait_available = trait_row is not None
|
| 99 |
+
_ = validate_and_save_cohort_info(
|
| 100 |
+
is_final=False,
|
| 101 |
+
cohort=cohort,
|
| 102 |
+
info_path=json_path,
|
| 103 |
+
is_gene_available=is_gene_available,
|
| 104 |
+
is_trait_available=is_trait_available
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# 4) Clinical feature extraction (only if trait_row is available)
|
| 108 |
+
if is_trait_available:
|
| 109 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 110 |
+
clinical_df=clinical_data,
|
| 111 |
+
trait=trait,
|
| 112 |
+
trait_row=trait_row,
|
| 113 |
+
convert_trait=convert_trait,
|
| 114 |
+
age_row=age_row,
|
| 115 |
+
convert_age=convert_age,
|
| 116 |
+
gender_row=gender_row,
|
| 117 |
+
convert_gender=convert_gender
|
| 118 |
+
)
|
| 119 |
+
preview = preview_df(selected_clinical_df, n=5)
|
| 120 |
+
print("Preview of selected clinical features:", preview)
|
| 121 |
+
# Save clinical data
|
| 122 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 123 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
| 124 |
+
|
| 125 |
+
# Step 3: Gene Data Extraction
|
| 126 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 127 |
+
gene_data = get_genetic_data(matrix_file)
|
| 128 |
+
|
| 129 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 130 |
+
print(gene_data.index[:20])
|
| 131 |
+
|
| 132 |
+
# Step 4: Gene Identifier Review
|
| 133 |
+
import re
|
| 134 |
+
|
| 135 |
+
# Sample of observed gene identifiers from the previous step
|
| 136 |
+
observed_ids = [
|
| 137 |
+
'18670005', '18670007', '18670009', '18670011', '18670020', '18670022',
|
| 138 |
+
'18670023', '18670027', '18670028', '18670032', '18670033', '18670036',
|
| 139 |
+
'18670038', '18670039', '18670041', '18670049', '18670051', '18670053',
|
| 140 |
+
'18670054', '18670056'
|
| 141 |
+
]
|
| 142 |
+
|
| 143 |
+
def looks_like_hgnc(symbol: str) -> bool:
|
| 144 |
+
# HGNC symbols generally include at least one letter; purely numeric IDs are not HGNC symbols.
|
| 145 |
+
return bool(re.search(r'[A-Za-z]', symbol))
|
| 146 |
+
|
| 147 |
+
is_hgnc_list = [looks_like_hgnc(x) for x in observed_ids]
|
| 148 |
+
# If the majority are not HGNC-like, mapping is required
|
| 149 |
+
requires_mapping = not (sum(is_hgnc_list) > len(is_hgnc_list) / 2)
|
| 150 |
+
|
| 151 |
+
print(f"requires_gene_mapping = {requires_mapping}")
|
| 152 |
+
|
| 153 |
+
# Step 5: Gene Annotation
|
| 154 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 155 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 156 |
+
|
| 157 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 158 |
+
print("Gene annotation preview:")
|
| 159 |
+
print(preview_df(gene_annotation))
|
| 160 |
+
|
| 161 |
+
# Step 6: Gene Identifier Mapping
|
| 162 |
+
# Determine identifier and gene symbol columns from annotation
|
| 163 |
+
id_col = 'ID' # matches probe IDs in the expression matrix
|
| 164 |
+
gene_symbol_col = 'gene_assignment' # contains gene symbol information
|
| 165 |
+
|
| 166 |
+
# Build mapping dataframe
|
| 167 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=gene_symbol_col)
|
| 168 |
+
|
| 169 |
+
# Apply mapping to convert probe-level data to gene-level data
|
| 170 |
+
probe_df = gene_data # preserve original probe-level data from previous step
|
| 171 |
+
gene_data = apply_gene_mapping(probe_df, mapping_df)
|
| 172 |
+
|
| 173 |
+
# Step 7: Data Normalization and Linking
|
| 174 |
+
import os
|
| 175 |
+
import pandas as pd
|
| 176 |
+
|
| 177 |
+
# 1. Normalize gene symbols and save gene data
|
| 178 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 179 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 180 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 181 |
+
|
| 182 |
+
# 2. Link clinical and genetic data
|
| 183 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 184 |
+
|
| 185 |
+
# 3. Missing value handling
|
| 186 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 187 |
+
|
| 188 |
+
# 4. Bias assessment and removal of biased demographics
|
| 189 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 190 |
+
|
| 191 |
+
# 5. Final validation and save cohort info
|
| 192 |
+
is_gene_available = isinstance(normalized_gene_data, pd.DataFrame) and normalized_gene_data.shape[0] > 0 and normalized_gene_data.shape[1] > 0
|
| 193 |
+
is_trait_available = isinstance(selected_clinical_df, pd.DataFrame) and (trait in selected_clinical_df.index)
|
| 194 |
+
|
| 195 |
+
note = "INFO: Gender not included because all samples are female in this cohort; trait mapped as insulin sensitivity (0=sensitive, 1=resistant)."
|
| 196 |
+
is_usable = validate_and_save_cohort_info(
|
| 197 |
+
is_final=True,
|
| 198 |
+
cohort=cohort,
|
| 199 |
+
info_path=json_path,
|
| 200 |
+
is_gene_available=is_gene_available,
|
| 201 |
+
is_trait_available=is_trait_available,
|
| 202 |
+
is_biased=is_trait_biased,
|
| 203 |
+
df=unbiased_linked_data,
|
| 204 |
+
note=note
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
# 6. Save linked data if usable
|
| 208 |
+
if is_usable:
|
| 209 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 210 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Metabolic_Rate/code/GSE106800.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE106800"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE106800"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE106800.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE106800.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE106800.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
|
| 41 |
+
# 1) Gene expression data availability
|
| 42 |
+
is_gene_available = True # Microarray analysis on skeletal muscle biopsies (not miRNA/methylation)
|
| 43 |
+
|
| 44 |
+
# 2) Variable availability and conversion functions
|
| 45 |
+
|
| 46 |
+
# Trait: Metabolic_Rate is not explicitly available in sample characteristics; cannot be reliably inferred
|
| 47 |
+
trait_row = None
|
| 48 |
+
|
| 49 |
+
def convert_trait(x):
|
| 50 |
+
# Trait not available in this cohort
|
| 51 |
+
return None
|
| 52 |
+
|
| 53 |
+
# Age: available at key 2
|
| 54 |
+
age_row = 2
|
| 55 |
+
|
| 56 |
+
def convert_age(x):
|
| 57 |
+
if x is None:
|
| 58 |
+
return None
|
| 59 |
+
# Extract substring after colon and parse float
|
| 60 |
+
try:
|
| 61 |
+
val = x.split(":", 1)[1].strip()
|
| 62 |
+
# Remove any non-numeric characters except dot and minus
|
| 63 |
+
val = re.sub(r"[^0-9.\-eE]", " ", val).strip()
|
| 64 |
+
# Sometimes units or extra spaces exist; take first numeric token
|
| 65 |
+
token = re.findall(r"[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?", val)
|
| 66 |
+
return float(token[0]) if token else None
|
| 67 |
+
except Exception:
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
# Gender: only 'male' reported across all samples -> constant feature, consider not available
|
| 71 |
+
gender_row = None
|
| 72 |
+
|
| 73 |
+
def convert_gender(x):
|
| 74 |
+
if x is None:
|
| 75 |
+
return None
|
| 76 |
+
try:
|
| 77 |
+
val = x.split(":", 1)[1].strip().lower()
|
| 78 |
+
except Exception:
|
| 79 |
+
val = str(x).strip().lower()
|
| 80 |
+
if val in ["male", "m"]:
|
| 81 |
+
return 1
|
| 82 |
+
if val in ["female", "f"]:
|
| 83 |
+
return 0
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
# 3) Save metadata (initial filtering)
|
| 87 |
+
is_trait_available = trait_row is not None
|
| 88 |
+
_ = validate_and_save_cohort_info(
|
| 89 |
+
is_final=False,
|
| 90 |
+
cohort=cohort,
|
| 91 |
+
info_path=json_path,
|
| 92 |
+
is_gene_available=is_gene_available,
|
| 93 |
+
is_trait_available=is_trait_available
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# 4) Clinical Feature Extraction: skipped because trait_row is None (no clinical trait data available)
|
| 97 |
+
# If trait_row becomes available in future, use geo_select_clinical_features and preview_df, then save to out_clinical_data_file.
|
| 98 |
+
|
| 99 |
+
# Step 3: Gene Data Extraction
|
| 100 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 101 |
+
gene_data = get_genetic_data(matrix_file)
|
| 102 |
+
|
| 103 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 104 |
+
print(gene_data.index[:20])
|
| 105 |
+
|
| 106 |
+
# Step 4: Gene Identifier Review
|
| 107 |
+
requires_gene_mapping = True
|
| 108 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 109 |
+
|
| 110 |
+
# Step 5: Gene Annotation
|
| 111 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 112 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 113 |
+
|
| 114 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 115 |
+
print("Gene annotation preview:")
|
| 116 |
+
print(preview_df(gene_annotation))
|
| 117 |
+
|
| 118 |
+
# Step 6: Gene Identifier Mapping
|
| 119 |
+
# Decide columns for mapping based on previous previews:
|
| 120 |
+
# Probe identifier column: 'ID' (matches numeric IDs in expression data)
|
| 121 |
+
# Gene symbol information column: 'gene_assignment'
|
| 122 |
+
|
| 123 |
+
# 1-2. Build mapping dataframe
|
| 124 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='gene_assignment')
|
| 125 |
+
|
| 126 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 127 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
| 128 |
+
|
| 129 |
+
# Optionally save gene-level data for downstream steps
|
| 130 |
+
import os
|
| 131 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 132 |
+
gene_data.to_csv(out_gene_data_file)
|
| 133 |
+
|
| 134 |
+
# Step 7: Data Normalization and Linking
|
| 135 |
+
# 1. Normalize the obtained gene data and save
|
| 136 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 137 |
+
import os
|
| 138 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 139 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 140 |
+
|
| 141 |
+
# 2-6. Link clinical and genetic data only if clinical trait data exists; otherwise, finalize with trait unavailable
|
| 142 |
+
is_usable = False
|
| 143 |
+
proceed_with_linking = False
|
| 144 |
+
try:
|
| 145 |
+
# Proceed only if selected_clinical_data exists and contains the trait row
|
| 146 |
+
proceed_with_linking = (selected_clinical_data is not None) and (trait in getattr(selected_clinical_data, 'index', []))
|
| 147 |
+
except NameError:
|
| 148 |
+
proceed_with_linking = False
|
| 149 |
+
|
| 150 |
+
if proceed_with_linking:
|
| 151 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 152 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 153 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 154 |
+
is_usable = validate_and_save_cohort_info(
|
| 155 |
+
is_final=True,
|
| 156 |
+
cohort=cohort,
|
| 157 |
+
info_path=json_path,
|
| 158 |
+
is_gene_available=True,
|
| 159 |
+
is_trait_available=True,
|
| 160 |
+
is_biased=is_trait_biased,
|
| 161 |
+
df=unbiased_linked_data,
|
| 162 |
+
note="INFO: Clinical trait available and data linked."
|
| 163 |
+
)
|
| 164 |
+
if is_usable:
|
| 165 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 166 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 167 |
+
else:
|
| 168 |
+
# Trait not available; perform final validation without linking
|
| 169 |
+
placeholder_df = normalized_gene_data.T
|
| 170 |
+
_ = validate_and_save_cohort_info(
|
| 171 |
+
is_final=True,
|
| 172 |
+
cohort=cohort,
|
| 173 |
+
info_path=json_path,
|
| 174 |
+
is_gene_available=True,
|
| 175 |
+
is_trait_available=False,
|
| 176 |
+
is_biased=False,
|
| 177 |
+
df=placeholder_df,
|
| 178 |
+
note="INFO: Trait not available; saved normalized gene expression only."
|
| 179 |
+
)
|
output/preprocess/Metabolic_Rate/code/GSE151683.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE151683"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE151683"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE151683.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE151683.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE151683.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
import pandas as pd
|
| 41 |
+
|
| 42 |
+
# 1) Gene expression data availability
|
| 43 |
+
is_gene_available = True # DNA microarray analysis of whole blood
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability and conversion functions
|
| 46 |
+
# From Sample Characteristics:
|
| 47 |
+
# - Age available at row 2
|
| 48 |
+
# - Gender is constant male only -> not useful, set to None
|
| 49 |
+
# - Trait (Metabolic_Rate) not present -> None
|
| 50 |
+
trait_row = None
|
| 51 |
+
age_row = 2
|
| 52 |
+
gender_row = None
|
| 53 |
+
|
| 54 |
+
def _after_colon(s: str) -> str:
|
| 55 |
+
if s is None:
|
| 56 |
+
return ''
|
| 57 |
+
parts = str(s).split(':', 1)
|
| 58 |
+
return parts[1].strip() if len(parts) == 2 else str(s).strip()
|
| 59 |
+
|
| 60 |
+
def convert_trait(x):
|
| 61 |
+
# Metabolic_Rate not available in this dataset; return None if not numeric
|
| 62 |
+
val = _after_colon(x)
|
| 63 |
+
try:
|
| 64 |
+
return float(val)
|
| 65 |
+
except Exception:
|
| 66 |
+
# Try to extract a number anywhere in the string
|
| 67 |
+
m = re.search(r"[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?", val)
|
| 68 |
+
return float(m.group(0)) if m else None
|
| 69 |
+
|
| 70 |
+
def convert_age(x):
|
| 71 |
+
val = _after_colon(x)
|
| 72 |
+
try:
|
| 73 |
+
return float(val)
|
| 74 |
+
except Exception:
|
| 75 |
+
m = re.search(r"\d{1,3}", val)
|
| 76 |
+
return float(m.group(0)) if m else None
|
| 77 |
+
|
| 78 |
+
def convert_gender(x):
|
| 79 |
+
val = _after_colon(x).lower()
|
| 80 |
+
if val in {'male', 'm'}:
|
| 81 |
+
return 1
|
| 82 |
+
if val in {'female', 'f'}:
|
| 83 |
+
return 0
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
# 3) Save metadata (initial filtering)
|
| 87 |
+
is_trait_available = trait_row is not None
|
| 88 |
+
_ = validate_and_save_cohort_info(
|
| 89 |
+
is_final=False,
|
| 90 |
+
cohort=cohort,
|
| 91 |
+
info_path=json_path,
|
| 92 |
+
is_gene_available=is_gene_available,
|
| 93 |
+
is_trait_available=is_trait_available
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# 4) Clinical feature extraction (skip because trait_row is None)
|
| 97 |
+
if trait_row is not None:
|
| 98 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 99 |
+
clinical_df=clinical_data,
|
| 100 |
+
trait=trait,
|
| 101 |
+
trait_row=trait_row,
|
| 102 |
+
convert_trait=convert_trait,
|
| 103 |
+
age_row=age_row,
|
| 104 |
+
convert_age=convert_age,
|
| 105 |
+
gender_row=gender_row,
|
| 106 |
+
convert_gender=convert_gender
|
| 107 |
+
)
|
| 108 |
+
_ = preview_df(selected_clinical_df)
|
| 109 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 110 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
output/preprocess/Metabolic_Rate/code/GSE23025.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE23025"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE23025"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE23025.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE23025.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE23025.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
|
| 41 |
+
# 1. Gene Expression Data Availability
|
| 42 |
+
# Affymetrix HG U133 Plus 2.0 Arrays indicate mRNA gene expression data are available.
|
| 43 |
+
is_gene_available = True
|
| 44 |
+
|
| 45 |
+
# 2. Variable Availability and Data Type Conversion
|
| 46 |
+
|
| 47 |
+
# Based on the provided sample characteristics, there are no explicit fields for metabolic rate, age, or gender.
|
| 48 |
+
trait_row = None # Metabolic_Rate not present
|
| 49 |
+
age_row = None # Age not present
|
| 50 |
+
gender_row = None # Gender not present
|
| 51 |
+
|
| 52 |
+
# Helper to extract value after colon and strip
|
| 53 |
+
def _after_colon(x):
|
| 54 |
+
if x is None:
|
| 55 |
+
return None
|
| 56 |
+
s = str(x)
|
| 57 |
+
if ':' in s:
|
| 58 |
+
s = s.split(':', 1)[1]
|
| 59 |
+
return s.strip() if s is not None else None
|
| 60 |
+
|
| 61 |
+
# 2.2 Conversion functions
|
| 62 |
+
|
| 63 |
+
# Metabolic_Rate: choose continuous; robust numeric parsing if ever encountered; otherwise None.
|
| 64 |
+
def convert_trait(x):
|
| 65 |
+
val = _after_colon(x)
|
| 66 |
+
if val is None or val == '':
|
| 67 |
+
return None
|
| 68 |
+
# Extract first float-like number
|
| 69 |
+
m = re.search(r'[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?', val)
|
| 70 |
+
if m:
|
| 71 |
+
try:
|
| 72 |
+
return float(m.group(0))
|
| 73 |
+
except Exception:
|
| 74 |
+
return None
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
+
# Age: continuous
|
| 78 |
+
def convert_age(x):
|
| 79 |
+
val = _after_colon(x)
|
| 80 |
+
if val is None or val == '':
|
| 81 |
+
return None
|
| 82 |
+
m = re.search(r'[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?', val)
|
| 83 |
+
if m:
|
| 84 |
+
try:
|
| 85 |
+
return float(m.group(0))
|
| 86 |
+
except Exception:
|
| 87 |
+
return None
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
# Gender: binary female->0, male->1
|
| 91 |
+
def convert_gender(x):
|
| 92 |
+
val = _after_colon(x)
|
| 93 |
+
if val is None or val == '':
|
| 94 |
+
return None
|
| 95 |
+
v = val.strip().lower()
|
| 96 |
+
# Normalize common variants
|
| 97 |
+
if v in {'male', 'm', 'man', 'boy'}:
|
| 98 |
+
return 1
|
| 99 |
+
if v in {'female', 'f', 'woman', 'girl'}:
|
| 100 |
+
return 0
|
| 101 |
+
if v in {'unknown', 'na', 'n/a', 'not available', 'undisclosed', 'other'}:
|
| 102 |
+
return None
|
| 103 |
+
# Heuristic: if contains 'male' or 'female' substrings
|
| 104 |
+
if 'male' in v:
|
| 105 |
+
return 1
|
| 106 |
+
if 'female' in v:
|
| 107 |
+
return 0
|
| 108 |
+
return None
|
| 109 |
+
|
| 110 |
+
# 3. Save Metadata (initial filtering)
|
| 111 |
+
is_trait_available = trait_row is not None
|
| 112 |
+
_ = validate_and_save_cohort_info(
|
| 113 |
+
is_final=False,
|
| 114 |
+
cohort=cohort,
|
| 115 |
+
info_path=json_path,
|
| 116 |
+
is_gene_available=is_gene_available,
|
| 117 |
+
is_trait_available=is_trait_available
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# 4. Clinical Feature Extraction: skipped because trait_row is None (no clinical trait available)
|
| 121 |
+
# If in future trait_row becomes available, the following template can be used:
|
| 122 |
+
# selected_clinical_df = geo_select_clinical_features(
|
| 123 |
+
# clinical_df=clinical_data,
|
| 124 |
+
# trait=trait,
|
| 125 |
+
# trait_row=trait_row,
|
| 126 |
+
# convert_trait=convert_trait,
|
| 127 |
+
# age_row=age_row,
|
| 128 |
+
# convert_age=convert_age,
|
| 129 |
+
# gender_row=gender_row,
|
| 130 |
+
# convert_gender=convert_gender
|
| 131 |
+
# )
|
| 132 |
+
# preview = preview_df(selected_clinical_df)
|
| 133 |
+
# os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 134 |
+
# selected_clinical_df.to_csv(out_clinical_data_file)
|
output/preprocess/Metabolic_Rate/code/GSE26440.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE26440"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE26440"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE26440.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE26440.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE26440.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# Determine data availability
|
| 40 |
+
is_gene_available = True # Genome-wide expression profiling of whole blood RNA (gene expression microarray)
|
| 41 |
+
trait_row = None # No field corresponding to Metabolic_Rate in sample characteristics
|
| 42 |
+
age_row = 2 # 'age (years): ...'
|
| 43 |
+
gender_row = None # No gender information available
|
| 44 |
+
|
| 45 |
+
# Converters
|
| 46 |
+
def _extract_after_colon(x):
|
| 47 |
+
if x is None:
|
| 48 |
+
return None
|
| 49 |
+
try:
|
| 50 |
+
parts = str(x).split(":", 1)
|
| 51 |
+
return parts[1].strip() if len(parts) > 1 else str(x).strip()
|
| 52 |
+
except Exception:
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
def convert_trait(x):
|
| 56 |
+
# No trait available for Metabolic_Rate in this cohort
|
| 57 |
+
return None
|
| 58 |
+
|
| 59 |
+
def convert_age(x):
|
| 60 |
+
val = _extract_after_colon(x)
|
| 61 |
+
if val is None:
|
| 62 |
+
return None
|
| 63 |
+
val_lower = val.strip().lower()
|
| 64 |
+
if val_lower in {"", "na", "n/a", "null", "none", "unknown"}:
|
| 65 |
+
return None
|
| 66 |
+
# Extract numeric value
|
| 67 |
+
try:
|
| 68 |
+
# Keep only the leading numeric portion
|
| 69 |
+
import re
|
| 70 |
+
match = re.search(r"[-+]?\d*\.?\d+", val_lower)
|
| 71 |
+
return float(match.group()) if match else None
|
| 72 |
+
except Exception:
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
def convert_gender(x):
|
| 76 |
+
# Not available in this dataset
|
| 77 |
+
return None
|
| 78 |
+
|
| 79 |
+
# Initial filtering metadata
|
| 80 |
+
is_trait_available = trait_row is not None
|
| 81 |
+
validate_and_save_cohort_info(
|
| 82 |
+
is_final=False,
|
| 83 |
+
cohort=cohort,
|
| 84 |
+
info_path=json_path,
|
| 85 |
+
is_gene_available=is_gene_available,
|
| 86 |
+
is_trait_available=is_trait_available
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# Clinical feature extraction (only if trait is available)
|
| 90 |
+
if trait_row is not None:
|
| 91 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 92 |
+
clinical_df=clinical_data,
|
| 93 |
+
trait=trait,
|
| 94 |
+
trait_row=trait_row,
|
| 95 |
+
convert_trait=convert_trait,
|
| 96 |
+
age_row=age_row,
|
| 97 |
+
convert_age=convert_age,
|
| 98 |
+
gender_row=gender_row,
|
| 99 |
+
convert_gender=convert_gender
|
| 100 |
+
)
|
| 101 |
+
print(preview_df(selected_clinical_df))
|
| 102 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 103 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
output/preprocess/Metabolic_Rate/code/GSE40589.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE40589"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE40589"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE40589.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE40589.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE40589.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
import pandas as pd
|
| 41 |
+
|
| 42 |
+
# 1) Gene expression availability (from series title and context, this is a gene expression study)
|
| 43 |
+
is_gene_available = True
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability based on the provided Sample Characteristics Dictionary
|
| 46 |
+
# Only key 0 exists and it is tissue info, so trait/age/gender are not available.
|
| 47 |
+
trait_row = None
|
| 48 |
+
age_row = None
|
| 49 |
+
gender_row = None
|
| 50 |
+
|
| 51 |
+
# 2.2) Conversion functions
|
| 52 |
+
|
| 53 |
+
def _get_value_after_colon(x):
|
| 54 |
+
if x is None or (isinstance(x, float) and pd.isna(x)):
|
| 55 |
+
return None
|
| 56 |
+
s = str(x)
|
| 57 |
+
if ':' in s:
|
| 58 |
+
s = s.split(':', 1)[1]
|
| 59 |
+
return s.strip()
|
| 60 |
+
|
| 61 |
+
def _extract_first_number(s):
|
| 62 |
+
if s is None:
|
| 63 |
+
return None
|
| 64 |
+
match = re.search(r'[-+]?\d*\.?\d+', s)
|
| 65 |
+
return float(match.group()) if match else None
|
| 66 |
+
|
| 67 |
+
def convert_trait(x):
|
| 68 |
+
# Metabolic_Rate is typically continuous; attempt to extract a numeric value if present.
|
| 69 |
+
s = _get_value_after_colon(x)
|
| 70 |
+
if s is None:
|
| 71 |
+
return None
|
| 72 |
+
num = _extract_first_number(s)
|
| 73 |
+
return num
|
| 74 |
+
|
| 75 |
+
def convert_age(x):
|
| 76 |
+
# Age is continuous; extract a plausible age number (0 < age < 120)
|
| 77 |
+
s = _get_value_after_colon(x)
|
| 78 |
+
if s is None:
|
| 79 |
+
return None
|
| 80 |
+
num = _extract_first_number(s)
|
| 81 |
+
if num is None:
|
| 82 |
+
return None
|
| 83 |
+
# Basic sanity check for human age
|
| 84 |
+
if 0 < num < 120:
|
| 85 |
+
return num
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
+
def convert_gender(x):
|
| 89 |
+
# Binary: female -> 0, male -> 1
|
| 90 |
+
s = _get_value_after_colon(x)
|
| 91 |
+
if s is None:
|
| 92 |
+
return None
|
| 93 |
+
v = s.strip().lower()
|
| 94 |
+
# Check female first to avoid substring confusion with male
|
| 95 |
+
female_tokens = {'f', 'female', 'woman', 'girl', 'fem'}
|
| 96 |
+
male_tokens = {'m', 'male', 'man', 'boy', 'masc'}
|
| 97 |
+
# Normalize single-letter tokens or words
|
| 98 |
+
if v in female_tokens or any(tok in v for tok in ['female']):
|
| 99 |
+
return 0
|
| 100 |
+
if v in male_tokens or any(tok in v for tok in ['male']):
|
| 101 |
+
return 1
|
| 102 |
+
return None
|
| 103 |
+
|
| 104 |
+
# 3) Save metadata with initial filtering
|
| 105 |
+
is_trait_available = trait_row is not None
|
| 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 (skip because trait_row is None)
|
| 115 |
+
if trait_row is not None:
|
| 116 |
+
selected_clinical = geo_select_clinical_features(
|
| 117 |
+
clinical_df=clinical_data,
|
| 118 |
+
trait=trait,
|
| 119 |
+
trait_row=trait_row,
|
| 120 |
+
convert_trait=convert_trait,
|
| 121 |
+
age_row=age_row,
|
| 122 |
+
convert_age=convert_age if age_row is not None else None,
|
| 123 |
+
gender_row=gender_row,
|
| 124 |
+
convert_gender=convert_gender if gender_row is not None else None
|
| 125 |
+
)
|
| 126 |
+
# Preview and save
|
| 127 |
+
_ = preview_df(selected_clinical, n=5)
|
| 128 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 129 |
+
selected_clinical.to_csv(out_clinical_data_file)
|
| 130 |
+
|
| 131 |
+
# Step 3: Gene Data Extraction
|
| 132 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 133 |
+
gene_data = get_genetic_data(matrix_file)
|
| 134 |
+
|
| 135 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 136 |
+
print(gene_data.index[:20])
|
| 137 |
+
|
| 138 |
+
# Step 4: Gene Identifier Review
|
| 139 |
+
# The identifiers like 'A_23_P100001' are Agilent probe IDs, not human gene symbols.
|
| 140 |
+
requires_gene_mapping = True
|
| 141 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 142 |
+
|
| 143 |
+
# Step 5: Gene Annotation
|
| 144 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 145 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 146 |
+
|
| 147 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 148 |
+
print("Gene annotation preview:")
|
| 149 |
+
print(preview_df(gene_annotation))
|
| 150 |
+
|
| 151 |
+
# Step 6: Gene Identifier Mapping
|
| 152 |
+
# Select appropriate columns for probe IDs and gene symbols based on the annotation preview
|
| 153 |
+
probe_col = 'ID'
|
| 154 |
+
gene_symbol_col = 'GENE_SYMBOL'
|
| 155 |
+
|
| 156 |
+
# Build the mapping dataframe
|
| 157 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 158 |
+
|
| 159 |
+
# Apply mapping to convert probe-level data to gene-level data
|
| 160 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 161 |
+
|
| 162 |
+
# Step 7: Data Normalization and Linking
|
| 163 |
+
import os
|
| 164 |
+
|
| 165 |
+
# 1. Normalize gene symbols and save gene expression data
|
| 166 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 167 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 168 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 169 |
+
|
| 170 |
+
# Determine trait availability from earlier step
|
| 171 |
+
is_trait_available = (trait_row is not None)
|
| 172 |
+
|
| 173 |
+
if is_trait_available:
|
| 174 |
+
# Ensure clinical features are available; if not, extract them now
|
| 175 |
+
try:
|
| 176 |
+
selected_clinical
|
| 177 |
+
except NameError:
|
| 178 |
+
selected_clinical = geo_select_clinical_features(
|
| 179 |
+
clinical_df=clinical_data,
|
| 180 |
+
trait=trait,
|
| 181 |
+
trait_row=trait_row,
|
| 182 |
+
convert_trait=convert_trait,
|
| 183 |
+
age_row=age_row,
|
| 184 |
+
convert_age=convert_age if age_row is not None else None,
|
| 185 |
+
gender_row=gender_row,
|
| 186 |
+
convert_gender=convert_gender if gender_row is not None else None
|
| 187 |
+
)
|
| 188 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 189 |
+
selected_clinical.to_csv(out_clinical_data_file)
|
| 190 |
+
|
| 191 |
+
# 2. Link clinical and genetic data
|
| 192 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical, normalized_gene_data)
|
| 193 |
+
|
| 194 |
+
# 3. Handle missing values
|
| 195 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 196 |
+
|
| 197 |
+
# 4. Bias assessment and removal of biased demographics
|
| 198 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 199 |
+
|
| 200 |
+
# 5. Final validation and save cohort info
|
| 201 |
+
is_usable = validate_and_save_cohort_info(
|
| 202 |
+
is_final=True,
|
| 203 |
+
cohort=cohort,
|
| 204 |
+
info_path=json_path,
|
| 205 |
+
is_gene_available=True,
|
| 206 |
+
is_trait_available=True,
|
| 207 |
+
is_biased=is_trait_biased,
|
| 208 |
+
df=unbiased_linked_data,
|
| 209 |
+
note=''
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
# 6. Save linked data if usable
|
| 213 |
+
if is_usable:
|
| 214 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 215 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 216 |
+
else:
|
| 217 |
+
# No trait data; record metadata and skip linking/validation of linked data
|
| 218 |
+
_ = validate_and_save_cohort_info(
|
| 219 |
+
is_final=False,
|
| 220 |
+
cohort=cohort,
|
| 221 |
+
info_path=json_path,
|
| 222 |
+
is_gene_available=True,
|
| 223 |
+
is_trait_available=False
|
| 224 |
+
)
|
output/preprocess/Metabolic_Rate/code/GSE40873.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE40873"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE40873"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE40873.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE40873.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE40873.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
|
| 41 |
+
# 1) Gene expression data availability (based on background: genome-wide gene expression analysis)
|
| 42 |
+
is_gene_available = True
|
| 43 |
+
|
| 44 |
+
# 2) Variable availability and converters
|
| 45 |
+
# From the Sample Characteristics Dictionary:
|
| 46 |
+
# 0: disease state (constant), 1: tissue (constant), 2: MFS time (days), 3: event (MO occurrence), 4: patient id
|
| 47 |
+
# The project trait here is "Metabolic_Rate", which is not present or inferable in this dataset.
|
| 48 |
+
trait_row = None
|
| 49 |
+
age_row = None
|
| 50 |
+
gender_row = None
|
| 51 |
+
|
| 52 |
+
def _after_colon(value):
|
| 53 |
+
if value is None:
|
| 54 |
+
return None
|
| 55 |
+
s = str(value)
|
| 56 |
+
if ":" in s:
|
| 57 |
+
s = s.split(":", 1)[1]
|
| 58 |
+
return s.strip()
|
| 59 |
+
|
| 60 |
+
def _to_float(s):
|
| 61 |
+
if s is None:
|
| 62 |
+
return None
|
| 63 |
+
m = re.search(r'[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?', str(s))
|
| 64 |
+
if m:
|
| 65 |
+
try:
|
| 66 |
+
return float(m.group(0))
|
| 67 |
+
except Exception:
|
| 68 |
+
return None
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
# Assuming metabolic rate would be continuous if available
|
| 72 |
+
def convert_trait(value):
|
| 73 |
+
# Extract numeric value after colon if any; return float or None
|
| 74 |
+
s = _after_colon(value)
|
| 75 |
+
return _to_float(s)
|
| 76 |
+
|
| 77 |
+
def convert_age(value):
|
| 78 |
+
# Expecting age in years; extract numeric
|
| 79 |
+
s = _after_colon(value)
|
| 80 |
+
return _to_float(s)
|
| 81 |
+
|
| 82 |
+
def convert_gender(value):
|
| 83 |
+
# Map female->0, male->1; otherwise None
|
| 84 |
+
s = _after_colon(value)
|
| 85 |
+
if s is None:
|
| 86 |
+
return None
|
| 87 |
+
s_low = str(s).strip().lower()
|
| 88 |
+
if s_low in {"female", "f", "woman", "women"}:
|
| 89 |
+
return 0
|
| 90 |
+
if s_low in {"male", "m", "man", "men"}:
|
| 91 |
+
return 1
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
# 3) Save metadata (initial filtering)
|
| 95 |
+
is_trait_available = trait_row is not None
|
| 96 |
+
_ = validate_and_save_cohort_info(
|
| 97 |
+
is_final=False,
|
| 98 |
+
cohort=cohort,
|
| 99 |
+
info_path=json_path,
|
| 100 |
+
is_gene_available=is_gene_available,
|
| 101 |
+
is_trait_available=is_trait_available
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
# 4) Clinical feature extraction (skip because trait_row is None)
|
| 105 |
+
if trait_row is not None:
|
| 106 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 107 |
+
clinical_df=clinical_data,
|
| 108 |
+
trait=trait,
|
| 109 |
+
trait_row=trait_row,
|
| 110 |
+
convert_trait=convert_trait,
|
| 111 |
+
age_row=age_row,
|
| 112 |
+
convert_age=convert_age if age_row is not None else None,
|
| 113 |
+
gender_row=gender_row,
|
| 114 |
+
convert_gender=convert_gender if gender_row is not None else None
|
| 115 |
+
)
|
| 116 |
+
print(preview_df(selected_clinical_df))
|
| 117 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 118 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
output/preprocess/Metabolic_Rate/code/GSE41168.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE41168"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE41168"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE41168.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE41168.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE41168.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
|
| 41 |
+
# 1) Gene expression data availability
|
| 42 |
+
# Background and design indicate mRNA expression profiling in muscle and adipose tissues.
|
| 43 |
+
is_gene_available = True
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability based on provided Sample Characteristics:
|
| 46 |
+
# {0: ['tissue: muscle', 'tissue: adipose tissue'],
|
| 47 |
+
# 1: ['sample group: calorie restrictive', 'sample group: placebo', 'sample group: resveratrol'],
|
| 48 |
+
# 2: ['treatment: before', 'treatment: after'],
|
| 49 |
+
# 3: ['gender: Female']}
|
| 50 |
+
#
|
| 51 |
+
# - Trait (Metabolic_Rate): Not present/inferable at per-sample level -> unavailable
|
| 52 |
+
# - Age: Not present -> unavailable
|
| 53 |
+
# - Gender: Constant 'Female' across all samples -> considered unavailable
|
| 54 |
+
trait_row = None
|
| 55 |
+
age_row = None
|
| 56 |
+
gender_row = None
|
| 57 |
+
|
| 58 |
+
# 2.2) Define conversion functions
|
| 59 |
+
def _after_colon(x):
|
| 60 |
+
if x is None:
|
| 61 |
+
return None
|
| 62 |
+
s = str(x)
|
| 63 |
+
parts = s.split(":", 1)
|
| 64 |
+
return parts[1].strip() if len(parts) == 2 else s.strip()
|
| 65 |
+
|
| 66 |
+
def convert_trait(x):
|
| 67 |
+
# Continuous. Extract numeric value if present; otherwise None.
|
| 68 |
+
v = _after_colon(x)
|
| 69 |
+
if v is None or v == "" or v.lower() in {"na", "n/a", "none", "unknown"}:
|
| 70 |
+
return None
|
| 71 |
+
m = re.search(r"[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?", v)
|
| 72 |
+
try:
|
| 73 |
+
return float(m.group()) if m else None
|
| 74 |
+
except Exception:
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
+
def convert_age(x):
|
| 78 |
+
# Continuous. Extract age in years (integer/float).
|
| 79 |
+
v = _after_colon(x)
|
| 80 |
+
if v is None or v == "" or v.lower() in {"na", "n/a", "none", "unknown"}:
|
| 81 |
+
return None
|
| 82 |
+
m = re.search(r"(\d*\.?\d+)", v)
|
| 83 |
+
try:
|
| 84 |
+
return float(m.group()) if m else None
|
| 85 |
+
except Exception:
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
+
def convert_gender(x):
|
| 89 |
+
# Binary: female -> 0, male -> 1
|
| 90 |
+
v = _after_colon(x)
|
| 91 |
+
if v is None:
|
| 92 |
+
return None
|
| 93 |
+
val = v.strip().lower()
|
| 94 |
+
if val in {"f", "female", "woman", "women"}:
|
| 95 |
+
return 0
|
| 96 |
+
if val in {"m", "male", "man", "men"}:
|
| 97 |
+
return 1
|
| 98 |
+
return None
|
| 99 |
+
|
| 100 |
+
# 3) Save metadata (initial filtering)
|
| 101 |
+
is_trait_available = trait_row is not None
|
| 102 |
+
_ = validate_and_save_cohort_info(
|
| 103 |
+
is_final=False,
|
| 104 |
+
cohort=cohort,
|
| 105 |
+
info_path=json_path,
|
| 106 |
+
is_gene_available=is_gene_available,
|
| 107 |
+
is_trait_available=is_trait_available
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
# 4) Clinical feature extraction (skip because trait_row is None)
|
| 111 |
+
if trait_row is not None:
|
| 112 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 113 |
+
clinical_df=clinical_data,
|
| 114 |
+
trait=trait,
|
| 115 |
+
trait_row=trait_row,
|
| 116 |
+
convert_trait=convert_trait,
|
| 117 |
+
age_row=age_row,
|
| 118 |
+
convert_age=convert_age,
|
| 119 |
+
gender_row=gender_row,
|
| 120 |
+
convert_gender=convert_gender
|
| 121 |
+
)
|
| 122 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 123 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 124 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
output/preprocess/Metabolic_Rate/code/GSE61225.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE61225"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE61225"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE61225.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE61225.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE61225.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# 1) Determine gene expression data availability based on background info
|
| 40 |
+
is_gene_available = True # Illumina HumanHT-12v3 Expression-BeadChip => gene expression microarray
|
| 41 |
+
|
| 42 |
+
# 2) Identify variable availability (row indices from Sample Characteristics Dictionary)
|
| 43 |
+
trait_row = 4 # 'metabolic equivalents: ...'
|
| 44 |
+
age_row = 6 # 'age: ...'
|
| 45 |
+
gender_row = 5 # 'gender: female/male'
|
| 46 |
+
|
| 47 |
+
# 2.2) Define conversion functions
|
| 48 |
+
def _extract_value(cell):
|
| 49 |
+
if cell is None:
|
| 50 |
+
return None
|
| 51 |
+
try:
|
| 52 |
+
# typical format "field: value"
|
| 53 |
+
parts = str(cell).split(":", 1)
|
| 54 |
+
val = parts[1] if len(parts) > 1 else parts[0]
|
| 55 |
+
val = val.strip()
|
| 56 |
+
if val == "" or val.lower() in {"na", "n/a", "nan", "none", "unknown", "?", "missing"}:
|
| 57 |
+
return None
|
| 58 |
+
return val
|
| 59 |
+
except Exception:
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
def convert_trait(x):
|
| 63 |
+
v = _extract_value(x)
|
| 64 |
+
if v is None:
|
| 65 |
+
return None
|
| 66 |
+
try:
|
| 67 |
+
return float(v)
|
| 68 |
+
except Exception:
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
def convert_age(x):
|
| 72 |
+
v = _extract_value(x)
|
| 73 |
+
if v is None:
|
| 74 |
+
return None
|
| 75 |
+
try:
|
| 76 |
+
return float(v)
|
| 77 |
+
except Exception:
|
| 78 |
+
return None
|
| 79 |
+
|
| 80 |
+
def convert_gender(x):
|
| 81 |
+
v = _extract_value(x)
|
| 82 |
+
if v is None:
|
| 83 |
+
return None
|
| 84 |
+
s = str(v).strip().lower()
|
| 85 |
+
# map to binary: female -> 0, male -> 1
|
| 86 |
+
if s in {"female", "f", "woman", "women"}:
|
| 87 |
+
return 0
|
| 88 |
+
if s in {"male", "m", "man", "men"}:
|
| 89 |
+
return 1
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
# 3) Initial filtering metadata save
|
| 93 |
+
is_trait_available = trait_row is not None
|
| 94 |
+
_ = validate_and_save_cohort_info(
|
| 95 |
+
is_final=False,
|
| 96 |
+
cohort=cohort,
|
| 97 |
+
info_path=json_path,
|
| 98 |
+
is_gene_available=is_gene_available,
|
| 99 |
+
is_trait_available=is_trait_available
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
# 4) Clinical feature extraction (only if trait is available)
|
| 103 |
+
if is_trait_available:
|
| 104 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 105 |
+
clinical_df=clinical_data,
|
| 106 |
+
trait=trait,
|
| 107 |
+
trait_row=trait_row,
|
| 108 |
+
convert_trait=convert_trait,
|
| 109 |
+
age_row=age_row,
|
| 110 |
+
convert_age=convert_age,
|
| 111 |
+
gender_row=gender_row,
|
| 112 |
+
convert_gender=convert_gender
|
| 113 |
+
)
|
| 114 |
+
preview = preview_df(selected_clinical_df, n=5)
|
| 115 |
+
print(preview)
|
| 116 |
+
|
| 117 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 118 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 119 |
+
|
| 120 |
+
# Step 3: Gene Data Extraction
|
| 121 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 122 |
+
gene_data = get_genetic_data(matrix_file)
|
| 123 |
+
|
| 124 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 125 |
+
print(gene_data.index[:20])
|
| 126 |
+
|
| 127 |
+
# Step 4: Gene Identifier Review
|
| 128 |
+
requires_gene_mapping = True
|
| 129 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 130 |
+
|
| 131 |
+
# Step 5: Gene Annotation
|
| 132 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 133 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 134 |
+
|
| 135 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 136 |
+
print("Gene annotation preview:")
|
| 137 |
+
print(preview_df(gene_annotation))
|
| 138 |
+
|
| 139 |
+
# Step 6: Gene Identifier Mapping
|
| 140 |
+
# Decide the appropriate columns for mapping:
|
| 141 |
+
# - Probe identifiers in expression data: 'ILMN_...' => matches 'ID' in gene_annotation
|
| 142 |
+
# - Gene symbols: use 'ILMN_Gene' from gene_annotation
|
| 143 |
+
identifier_col = 'ID'
|
| 144 |
+
gene_symbol_col = 'ILMN_Gene'
|
| 145 |
+
|
| 146 |
+
# 2) Build the mapping dataframe (ID -> Gene)
|
| 147 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=identifier_col, gene_col=gene_symbol_col)
|
| 148 |
+
|
| 149 |
+
# 3) Apply mapping: convert probe-level to gene-level expression
|
| 150 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 151 |
+
|
| 152 |
+
# Step 7: Data Normalization and Linking
|
| 153 |
+
import os
|
| 154 |
+
import pandas as pd
|
| 155 |
+
|
| 156 |
+
# 1. Normalize gene symbols and save
|
| 157 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 158 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 159 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 160 |
+
|
| 161 |
+
# 2. Link clinical and genetic data
|
| 162 |
+
# Ensure clinical dataframe is available (load from file if not in memory)
|
| 163 |
+
if 'selected_clinical_df' not in globals():
|
| 164 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 165 |
+
|
| 166 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 167 |
+
|
| 168 |
+
# 3. Handle missing values
|
| 169 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 170 |
+
|
| 171 |
+
# 4. Assess bias and remove biased demographic features
|
| 172 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 173 |
+
|
| 174 |
+
# 5. Final validation and save cohort metadata
|
| 175 |
+
# Ensure pure Python bools are passed to the validator
|
| 176 |
+
is_gene_available = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
|
| 177 |
+
is_trait_available = bool((trait in linked_data.columns) and bool(linked_data[trait].notna().any()))
|
| 178 |
+
is_trait_biased = bool(is_trait_biased)
|
| 179 |
+
|
| 180 |
+
note_details = (
|
| 181 |
+
f"genes_before={int(gene_data.shape[0]) if isinstance(gene_data, pd.DataFrame) else 'NA'}, "
|
| 182 |
+
f"genes_after_norm={int(normalized_gene_data.shape[0])}, "
|
| 183 |
+
f"samples_linked={int(unbiased_linked_data.shape[0])}"
|
| 184 |
+
)
|
| 185 |
+
note = f"INFO: Gene symbols normalized with NCBI synonyms; clinical features (Age, Gender) extracted from GEO characteristics; {note_details}."
|
| 186 |
+
|
| 187 |
+
is_usable = validate_and_save_cohort_info(
|
| 188 |
+
is_final=True,
|
| 189 |
+
cohort=cohort,
|
| 190 |
+
info_path=json_path,
|
| 191 |
+
is_gene_available=is_gene_available,
|
| 192 |
+
is_trait_available=is_trait_available,
|
| 193 |
+
is_biased=is_trait_biased,
|
| 194 |
+
df=unbiased_linked_data,
|
| 195 |
+
note=note
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
# 6. Save linked data if usable
|
| 199 |
+
if is_usable:
|
| 200 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 201 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Metabolic_Rate/code/GSE89231.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
cohort = "GSE89231"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Metabolic_Rate"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Metabolic_Rate/GSE89231"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/GSE89231.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/GSE89231.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/GSE89231.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# Step 1: Determine data availability
|
| 40 |
+
is_gene_available = True # Gene expression profiling is described in the background (not miRNA/methylation)
|
| 41 |
+
trait_row = None # No human Metabolic_Rate data available in cell line study
|
| 42 |
+
age_row = None # No human age data available
|
| 43 |
+
gender_row = None # No human gender data available
|
| 44 |
+
|
| 45 |
+
# Step 2: Define conversion functions
|
| 46 |
+
def _extract_value(x):
|
| 47 |
+
if x is None:
|
| 48 |
+
return None
|
| 49 |
+
s = str(x).strip()
|
| 50 |
+
if ':' in s:
|
| 51 |
+
# take substring after the last colon to be robust against headers with colons
|
| 52 |
+
s = s.split(':', 1)[1].strip()
|
| 53 |
+
return s if s != '' else None
|
| 54 |
+
|
| 55 |
+
def convert_trait(x):
|
| 56 |
+
# Metabolic_Rate not available; implement a general numeric parser if ever used
|
| 57 |
+
s = _extract_value(x)
|
| 58 |
+
if s is None:
|
| 59 |
+
return None
|
| 60 |
+
# Try to parse as float
|
| 61 |
+
try:
|
| 62 |
+
return float(s)
|
| 63 |
+
except:
|
| 64 |
+
# Try to extract first numeric token
|
| 65 |
+
import re
|
| 66 |
+
m = re.search(r'[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?', s)
|
| 67 |
+
if m:
|
| 68 |
+
try:
|
| 69 |
+
return float(m.group(0))
|
| 70 |
+
except:
|
| 71 |
+
return None
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
+
def convert_age(x):
|
| 75 |
+
s = _extract_value(x)
|
| 76 |
+
if s is None:
|
| 77 |
+
return None
|
| 78 |
+
s_lower = s.lower()
|
| 79 |
+
# Map common unknowns
|
| 80 |
+
if s_lower in {'na', 'n/a', 'nan', 'none', 'unknown', 'not available', 'missing'}:
|
| 81 |
+
return None
|
| 82 |
+
import re
|
| 83 |
+
# Handle age ranges by taking midpoint
|
| 84 |
+
range_match = re.findall(r'(\d+(?:\.\d+)?)', s_lower)
|
| 85 |
+
if '-' in s_lower or 'to' in s_lower:
|
| 86 |
+
nums = [float(n) for n in range_match] if range_match else []
|
| 87 |
+
if len(nums) >= 2:
|
| 88 |
+
return (nums[0] + nums[1]) / 2.0
|
| 89 |
+
# Detect units
|
| 90 |
+
if 'month' in s_lower or 'mo' in s_lower:
|
| 91 |
+
# Convert months to years
|
| 92 |
+
nums = [float(n) for n in range_match] if range_match else []
|
| 93 |
+
if nums:
|
| 94 |
+
return nums[0] / 12.0
|
| 95 |
+
# Default: first number in years
|
| 96 |
+
if range_match:
|
| 97 |
+
try:
|
| 98 |
+
return float(range_match[0])
|
| 99 |
+
except:
|
| 100 |
+
return None
|
| 101 |
+
return None
|
| 102 |
+
|
| 103 |
+
def convert_gender(x):
|
| 104 |
+
s = _extract_value(x)
|
| 105 |
+
if s is None:
|
| 106 |
+
return None
|
| 107 |
+
s_lower = s.strip().lower()
|
| 108 |
+
# Standardize common representations
|
| 109 |
+
if s_lower in {'male', 'm', 'man', 'boy'}:
|
| 110 |
+
return 1
|
| 111 |
+
if s_lower in {'female', 'f', 'woman', 'girl'}:
|
| 112 |
+
return 0
|
| 113 |
+
if s_lower in {'unknown', 'na', 'n/a', 'none', 'nan', 'not available', ''}:
|
| 114 |
+
return None
|
| 115 |
+
# Heuristic: if startswith 'm' assume male; 'f' assume female
|
| 116 |
+
if s_lower.startswith('m'):
|
| 117 |
+
return 1
|
| 118 |
+
if s_lower.startswith('f'):
|
| 119 |
+
return 0
|
| 120 |
+
return None
|
| 121 |
+
|
| 122 |
+
# Step 3: Initial filtering and save metadata
|
| 123 |
+
is_trait_available = trait_row is not None
|
| 124 |
+
_ = validate_and_save_cohort_info(
|
| 125 |
+
is_final=False,
|
| 126 |
+
cohort=cohort,
|
| 127 |
+
info_path=json_path,
|
| 128 |
+
is_gene_available=is_gene_available,
|
| 129 |
+
is_trait_available=is_trait_available
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
# Step 4: Clinical feature extraction (skip because trait_row is None)
|
| 133 |
+
if trait_row is not None:
|
| 134 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 135 |
+
clinical_df=clinical_data,
|
| 136 |
+
trait=trait,
|
| 137 |
+
trait_row=trait_row,
|
| 138 |
+
convert_trait=convert_trait,
|
| 139 |
+
age_row=age_row,
|
| 140 |
+
convert_age=convert_age,
|
| 141 |
+
gender_row=gender_row,
|
| 142 |
+
convert_gender=convert_gender
|
| 143 |
+
)
|
| 144 |
+
preview = preview_df(selected_clinical_df)
|
| 145 |
+
# Save clinical data
|
| 146 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 147 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
output/preprocess/Metabolic_Rate/code/TCGA.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Metabolic_Rate"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z4/preprocess/Metabolic_Rate/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z4/preprocess/Metabolic_Rate/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z4/preprocess/Metabolic_Rate/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z4/preprocess/Metabolic_Rate/cohort_info.json"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Step 1: Initial Data Loading
|
| 18 |
+
import os
|
| 19 |
+
import pandas as pd
|
| 20 |
+
|
| 21 |
+
# Step 1: Find a suitable TCGA cohort directory for the trait "Metabolic_Rate"
|
| 22 |
+
subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 23 |
+
|
| 24 |
+
# Define trait-related keywords. For "Metabolic_Rate", TCGA cohort names are cancer-type specific and unlikely to match.
|
| 25 |
+
trait_keywords = [
|
| 26 |
+
"metabolic rate", "metabolism", "metabolic", "bmr", "basal metabolic rate",
|
| 27 |
+
"energy expenditure", "resting metabolic rate", "oxygen consumption", "vo2",
|
| 28 |
+
"glycolysis", "oxidative", "mitochondrial"
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
# Rank subdirectories by presence of keywords; pick the best match if any
|
| 32 |
+
candidates = []
|
| 33 |
+
for d in subdirs:
|
| 34 |
+
dl = d.lower()
|
| 35 |
+
score = sum(1 for kw in trait_keywords if kw in dl)
|
| 36 |
+
if score > 0:
|
| 37 |
+
candidates.append((score, d))
|
| 38 |
+
|
| 39 |
+
selected_dir = None
|
| 40 |
+
if candidates:
|
| 41 |
+
# Choose the most specific (highest score, then shortest name)
|
| 42 |
+
candidates.sort(key=lambda x: (-x[0], len(x[1])))
|
| 43 |
+
selected_dir = candidates[0][1]
|
| 44 |
+
|
| 45 |
+
# Initialize variables for later steps
|
| 46 |
+
clinical_df = None
|
| 47 |
+
genetic_df = None
|
| 48 |
+
|
| 49 |
+
if selected_dir is None:
|
| 50 |
+
# No suitable directory found; mark this trait as skipped/unavailable
|
| 51 |
+
validate_and_save_cohort_info(
|
| 52 |
+
is_final=False,
|
| 53 |
+
cohort="TCGA",
|
| 54 |
+
info_path=json_path,
|
| 55 |
+
is_gene_available=False,
|
| 56 |
+
is_trait_available=False
|
| 57 |
+
)
|
| 58 |
+
else:
|
| 59 |
+
# Step 2: Identify file paths for clinical and genetic data
|
| 60 |
+
cohort_path = os.path.join(tcga_root_dir, selected_dir)
|
| 61 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_path)
|
| 62 |
+
|
| 63 |
+
# Step 3: Load both files as DataFrames
|
| 64 |
+
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False, compression='infer')
|
| 65 |
+
genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False, compression='infer')
|
| 66 |
+
|
| 67 |
+
# Step 4: Print clinical column names
|
| 68 |
+
print(list(clinical_df.columns))
|
output/preprocess/Migraine/clinical_data/GSE67311.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
,GSM1644447,GSM1644448,GSM1644449,GSM1644450,GSM1644451,GSM1644452,GSM1644453,GSM1644454,GSM1644455,GSM1644456,GSM1644457,GSM1644458,GSM1644459,GSM1644460,GSM1644461,GSM1644462,GSM1644463,GSM1644464,GSM1644465,GSM1644466,GSM1644467,GSM1644468,GSM1644469,GSM1644470,GSM1644471,GSM1644472,GSM1644473,GSM1644474,GSM1644475,GSM1644476,GSM1644477,GSM1644478,GSM1644479,GSM1644480,GSM1644481,GSM1644482,GSM1644483,GSM1644484,GSM1644485,GSM1644486,GSM1644487,GSM1644488,GSM1644489,GSM1644490,GSM1644491,GSM1644492,GSM1644493,GSM1644494,GSM1644495,GSM1644496,GSM1644497,GSM1644498,GSM1644499,GSM1644500,GSM1644501,GSM1644502,GSM1644503,GSM1644504,GSM1644505,GSM1644506,GSM1644507,GSM1644508,GSM1644509,GSM1644510,GSM1644511,GSM1644512,GSM1644513,GSM1644514,GSM1644515,GSM1644516,GSM1644517,GSM1644518,GSM1644519,GSM1644520,GSM1644521,GSM1644522,GSM1644523,GSM1644524,GSM1644525,GSM1644526,GSM1644527,GSM1644528,GSM1644529,GSM1644530,GSM1644531,GSM1644532,GSM1644533,GSM1644534,GSM1644535,GSM1644536,GSM1644537,GSM1644538,GSM1644539,GSM1644540,GSM1644541,GSM1644542,GSM1644543,GSM1644544,GSM1644545,GSM1644546,GSM1644547,GSM1644548,GSM1644549,GSM1644550,GSM1644551,GSM1644552,GSM1644553,GSM1644554,GSM1644555,GSM1644556,GSM1644557,GSM1644558,GSM1644559,GSM1644560,GSM1644561,GSM1644562,GSM1644563,GSM1644564,GSM1644565,GSM1644566,GSM1644567,GSM1644568,GSM1644569,GSM1644570,GSM1644571,GSM1644572,GSM1644573,GSM1644574,GSM1644575,GSM1644576,GSM1644577,GSM1644578,GSM1644579,GSM1644580,GSM1644581,GSM1644582,GSM1644583,GSM1644584,GSM1644585,GSM1644586,GSM1644587,GSM1644588
|
| 2 |
+
Migraine,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,,1.0,1.0,1.0,1.0,0.0,1.0,,1.0,,1.0,1.0,0.0,0.0,,0.0,1.0,0.0,1.0,0.0,0.0,0.0,,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,,1.0,1.0,0.0
|
output/preprocess/Migraine/code/GSE67311.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Migraine"
|
| 6 |
+
cohort = "GSE67311"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Migraine"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Migraine/GSE67311"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Migraine/GSE67311.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Migraine/gene_data/GSE67311.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Migraine/clinical_data/GSE67311.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Migraine/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
|
| 42 |
+
# 1) Gene expression data availability
|
| 43 |
+
is_gene_available = True # Affymetrix Human Gene 1.1 ST arrays -> gene expression microarray
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability and converters
|
| 46 |
+
|
| 47 |
+
# Trait: Migraine
|
| 48 |
+
# From sample characteristics: key 4 has 'migraine: Yes/No/-'
|
| 49 |
+
if 4 in clinical_data.index:
|
| 50 |
+
trait_row = 4
|
| 51 |
+
elif "4" in clinical_data.index:
|
| 52 |
+
trait_row = "4"
|
| 53 |
+
else:
|
| 54 |
+
trait_row = None
|
| 55 |
+
|
| 56 |
+
# Age and Gender are not present in the characteristics dictionary
|
| 57 |
+
age_row = None
|
| 58 |
+
gender_row = None
|
| 59 |
+
|
| 60 |
+
# Conversion functions
|
| 61 |
+
def _after_colon(value):
|
| 62 |
+
if value is None:
|
| 63 |
+
return None
|
| 64 |
+
s = str(value)
|
| 65 |
+
parts = s.split(":", 1)
|
| 66 |
+
val = parts[1] if len(parts) > 1 else parts[0]
|
| 67 |
+
return val.strip()
|
| 68 |
+
|
| 69 |
+
def convert_trait(value):
|
| 70 |
+
v = _after_colon(value)
|
| 71 |
+
if v is None or v == "" or v == "-" or v.lower() in {"na", "n/a", "unknown"}:
|
| 72 |
+
return None
|
| 73 |
+
vl = v.strip().lower()
|
| 74 |
+
if vl in {"yes", "y", "1", "true"}:
|
| 75 |
+
return 1
|
| 76 |
+
if vl in {"no", "n", "0", "false"}:
|
| 77 |
+
return 0
|
| 78 |
+
# Fallback: try numeric
|
| 79 |
+
try:
|
| 80 |
+
num = float(vl)
|
| 81 |
+
if num == 1.0:
|
| 82 |
+
return 1
|
| 83 |
+
if num == 0.0:
|
| 84 |
+
return 0
|
| 85 |
+
except:
|
| 86 |
+
pass
|
| 87 |
+
return None
|
| 88 |
+
|
| 89 |
+
def convert_age(value):
|
| 90 |
+
# Not available in this dataset; function provided for interface completeness.
|
| 91 |
+
v = _after_colon(value)
|
| 92 |
+
if v is None:
|
| 93 |
+
return None
|
| 94 |
+
nums = re.findall(r"[-+]?\d*\.?\d+", v)
|
| 95 |
+
if not nums:
|
| 96 |
+
return None
|
| 97 |
+
try:
|
| 98 |
+
age = float(nums[0])
|
| 99 |
+
if age <= 0 or age > 120:
|
| 100 |
+
return None
|
| 101 |
+
return age
|
| 102 |
+
except:
|
| 103 |
+
return None
|
| 104 |
+
|
| 105 |
+
def convert_gender(value):
|
| 106 |
+
# Not available in this dataset; function provided for interface completeness.
|
| 107 |
+
v = _after_colon(value)
|
| 108 |
+
if v is None or v == "" or v == "-" or v.lower() in {"na", "n/a", "unknown"}:
|
| 109 |
+
return None
|
| 110 |
+
vl = v.strip().lower()
|
| 111 |
+
# female -> 0, male -> 1
|
| 112 |
+
if vl in {"female", "f", "woman", "women"}:
|
| 113 |
+
return 0
|
| 114 |
+
if vl in {"male", "m", "man", "men"}:
|
| 115 |
+
return 1
|
| 116 |
+
return None
|
| 117 |
+
|
| 118 |
+
# 3) Save metadata (initial filtering)
|
| 119 |
+
is_trait_available = trait_row is not None
|
| 120 |
+
_ = validate_and_save_cohort_info(
|
| 121 |
+
is_final=False,
|
| 122 |
+
cohort=cohort,
|
| 123 |
+
info_path=json_path,
|
| 124 |
+
is_gene_available=is_gene_available,
|
| 125 |
+
is_trait_available=is_trait_available
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
# 4) Clinical feature extraction, preview, and save
|
| 129 |
+
if trait_row is not None:
|
| 130 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 131 |
+
clinical_df=clinical_data,
|
| 132 |
+
trait=trait,
|
| 133 |
+
trait_row=trait_row,
|
| 134 |
+
convert_trait=convert_trait,
|
| 135 |
+
age_row=age_row,
|
| 136 |
+
convert_age=convert_age,
|
| 137 |
+
gender_row=gender_row,
|
| 138 |
+
convert_gender=convert_gender
|
| 139 |
+
)
|
| 140 |
+
preview = preview_df(selected_clinical_df, n=5)
|
| 141 |
+
print("Selected clinical preview:", preview)
|
| 142 |
+
|
| 143 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 144 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 145 |
+
|
| 146 |
+
# Step 3: Gene Data Extraction
|
| 147 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 148 |
+
gene_data = get_genetic_data(matrix_file)
|
| 149 |
+
|
| 150 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 151 |
+
print(gene_data.index[:20])
|
| 152 |
+
|
| 153 |
+
# Step 4: Gene Identifier Review
|
| 154 |
+
# The observed identifiers like '7892501' are Affymetrix/array probe set IDs, not human gene symbols.
|
| 155 |
+
requires_gene_mapping = True
|
| 156 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 157 |
+
|
| 158 |
+
# Step 5: Gene Annotation
|
| 159 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 160 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 161 |
+
|
| 162 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 163 |
+
print("Gene annotation preview:")
|
| 164 |
+
print(preview_df(gene_annotation))
|
| 165 |
+
|
| 166 |
+
# Step 6: Gene Identifier Mapping
|
| 167 |
+
# Determine mapping columns based on previous previews:
|
| 168 |
+
# - Probe IDs in expression data match 'ID' in annotation.
|
| 169 |
+
# - Gene symbols are embedded in 'gene_assignment' in annotation.
|
| 170 |
+
|
| 171 |
+
# 1-2) Build mapping dataframe from annotation
|
| 172 |
+
mapping_df = get_gene_mapping(annotation=gene_annotation, prob_col='ID', gene_col='gene_assignment')
|
| 173 |
+
|
| 174 |
+
# 3) Apply mapping to convert probe-level data to gene-level expression
|
| 175 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 176 |
+
|
| 177 |
+
# Step 7: Data Normalization and Linking
|
| 178 |
+
import os
|
| 179 |
+
import json
|
| 180 |
+
|
| 181 |
+
# 1. Normalize gene symbols and save
|
| 182 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 183 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 184 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 185 |
+
|
| 186 |
+
# 2. Link clinical and genetic data (use the correct clinical variable from Step 2)
|
| 187 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 188 |
+
|
| 189 |
+
# 3. Handle missing values
|
| 190 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 191 |
+
|
| 192 |
+
# 4. Assess bias and remove biased demographic features
|
| 193 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 194 |
+
|
| 195 |
+
# 5. Final validation and save cohort info
|
| 196 |
+
covariate_cols = [trait, 'Age', 'Gender']
|
| 197 |
+
gene_cols = [c for c in unbiased_linked_data.columns if c not in covariate_cols]
|
| 198 |
+
is_gene_available_final = bool((len(gene_cols) > 0) and (len(unbiased_linked_data) > 0))
|
| 199 |
+
is_trait_available_final = bool((trait in unbiased_linked_data.columns) and unbiased_linked_data[trait].notna().any())
|
| 200 |
+
|
| 201 |
+
note = "INFO: Age and Gender not available in this cohort. Probes mapped via 'gene_assignment'; gene symbols normalized with NCBI synonyms."
|
| 202 |
+
|
| 203 |
+
# Try library function first; if serialization fails, fallback to manual JSON update with sanitized types.
|
| 204 |
+
try:
|
| 205 |
+
is_usable = validate_and_save_cohort_info(
|
| 206 |
+
is_final=True,
|
| 207 |
+
cohort=cohort,
|
| 208 |
+
info_path=json_path,
|
| 209 |
+
is_gene_available=is_gene_available_final,
|
| 210 |
+
is_trait_available=is_trait_available_final,
|
| 211 |
+
is_biased=bool(is_trait_biased),
|
| 212 |
+
df=unbiased_linked_data,
|
| 213 |
+
note=note
|
| 214 |
+
)
|
| 215 |
+
except Exception:
|
| 216 |
+
# Fallback: replicate core logic of final validation and write JSON with sanitized (primitive) types
|
| 217 |
+
is_gene_av = bool(is_gene_available_final)
|
| 218 |
+
is_trait_av = bool(is_trait_available_final)
|
| 219 |
+
|
| 220 |
+
# Detect abnormality in data and override flags similar to library behavior
|
| 221 |
+
if len(unbiased_linked_data) <= 0 or len(unbiased_linked_data.columns) <= 4:
|
| 222 |
+
is_gene_av = False
|
| 223 |
+
if len(unbiased_linked_data) <= 0:
|
| 224 |
+
is_trait_av = False
|
| 225 |
+
is_available = bool(is_gene_av and is_trait_av)
|
| 226 |
+
is_usable = bool(is_available and (is_trait_biased is False))
|
| 227 |
+
|
| 228 |
+
# Build sanitized record (cast booleans to int for maximum compatibility)
|
| 229 |
+
new_record = {
|
| 230 |
+
"is_usable": int(is_usable),
|
| 231 |
+
"is_gene_available": int(is_gene_av),
|
| 232 |
+
"is_trait_available": int(is_trait_av),
|
| 233 |
+
"is_available": int(is_available),
|
| 234 |
+
"is_biased": (int(is_trait_biased) if is_available else None),
|
| 235 |
+
"has_age": (int('Age' in unbiased_linked_data.columns) if is_available else None),
|
| 236 |
+
"has_gender": (int('Gender' in unbiased_linked_data.columns) if is_available else None),
|
| 237 |
+
"sample_size": (int(len(unbiased_linked_data)) if is_available else None),
|
| 238 |
+
"note": note
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
os.makedirs(os.path.dirname(json_path), exist_ok=True)
|
| 242 |
+
if not os.path.exists(json_path):
|
| 243 |
+
with open(json_path, 'w') as f:
|
| 244 |
+
json.dump({}, f)
|
| 245 |
+
|
| 246 |
+
with open(json_path, 'r') as f:
|
| 247 |
+
records = json.load(f)
|
| 248 |
+
records[cohort] = new_record
|
| 249 |
+
|
| 250 |
+
temp_path = json_path + ".tmp"
|
| 251 |
+
with open(temp_path, 'w') as f:
|
| 252 |
+
json.dump(records, f)
|
| 253 |
+
os.replace(temp_path, json_path)
|
| 254 |
+
|
| 255 |
+
# 6. Save linked data if usable
|
| 256 |
+
if is_usable:
|
| 257 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 258 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Migraine/code/TCGA.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Migraine"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z4/preprocess/Migraine/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z4/preprocess/Migraine/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z4/preprocess/Migraine/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z4/preprocess/Migraine/cohort_info.json"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Step 1: Initial Data Loading
|
| 18 |
+
import os
|
| 19 |
+
import pandas as pd
|
| 20 |
+
|
| 21 |
+
# Step 1: find the most appropriate cohort directory for Migraine (likely none in TCGA cancer cohorts)
|
| 22 |
+
subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 23 |
+
migraine_synonyms = [
|
| 24 |
+
"migraine", "headache", "cephalalgia", "trigeminal autonomic", "cluster headache",
|
| 25 |
+
"hemicrania", "hemicrania continua", "sunct", "suna", "paroxysmal hemicrania"
|
| 26 |
+
]
|
| 27 |
+
selected_dir = None
|
| 28 |
+
for d in subdirs:
|
| 29 |
+
dl = d.lower()
|
| 30 |
+
if any(term in dl for term in migraine_synonyms):
|
| 31 |
+
selected_dir = d
|
| 32 |
+
break
|
| 33 |
+
|
| 34 |
+
if selected_dir is None:
|
| 35 |
+
# No suitable cohort for migraine in TCGA; mark as skipped
|
| 36 |
+
validate_and_save_cohort_info(
|
| 37 |
+
is_final=False,
|
| 38 |
+
cohort="TCGA",
|
| 39 |
+
info_path=json_path,
|
| 40 |
+
is_gene_available=False,
|
| 41 |
+
is_trait_available=False
|
| 42 |
+
)
|
| 43 |
+
else:
|
| 44 |
+
# Step 2: identify clinical and genetic file paths
|
| 45 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 46 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
| 47 |
+
|
| 48 |
+
# Step 3: load dataframes
|
| 49 |
+
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False)
|
| 50 |
+
genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False)
|
| 51 |
+
|
| 52 |
+
# Step 4: print clinical column names
|
| 53 |
+
print(clinical_df.columns.tolist())
|
output/preprocess/Migraine/cohort_info.json
CHANGED
|
@@ -1,22 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"GSE67311": {
|
| 3 |
-
"is_usable": true,
|
| 4 |
-
"is_gene_available": true,
|
| 5 |
-
"is_trait_available": true,
|
| 6 |
-
"is_available": true,
|
| 7 |
-
"is_biased": false,
|
| 8 |
-
"has_age": false,
|
| 9 |
-
"has_gender": false,
|
| 10 |
-
"sample_size": 133
|
| 11 |
-
},
|
| 12 |
-
"TCGA": {
|
| 13 |
-
"is_usable": true,
|
| 14 |
-
"is_gene_available": true,
|
| 15 |
-
"is_trait_available": true,
|
| 16 |
-
"is_available": true,
|
| 17 |
-
"is_biased": false,
|
| 18 |
-
"has_age": true,
|
| 19 |
-
"has_gender": true,
|
| 20 |
-
"sample_size": 702
|
| 21 |
-
}
|
| 22 |
-
}
|
|
|
|
| 1 |
+
{"GSE67311": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 133, "note": "INFO: Age and Gender not available in this cohort. Probes mapped via 'gene_assignment'; gene symbols normalized with NCBI synonyms."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output/preprocess/Mitochondrial_Disorders/GSE42986.csv
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
output/preprocess/Mitochondrial_Disorders/clinical_data/GSE42986.csv
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
,GSM1054461,GSM1054462,GSM1054463,GSM1054464,GSM1054465,GSM1054466,GSM1054467,GSM1054468,GSM1054469,GSM1054470,GSM1054471,GSM1054472,GSM1054473,GSM1054474,GSM1054475,GSM1054476,GSM1054477,GSM1054478,GSM1054479,GSM1054480,GSM1054481,GSM1054482,GSM1054483,GSM1054484,GSM1054485,GSM1054486,GSM1054487,GSM1054488,GSM1054489,GSM1054490,GSM1054491,GSM1054492,GSM1054493,GSM1054494,GSM1054495,GSM1054496,GSM1054497,GSM1054498,GSM1054499,GSM1054500,GSM1054501,GSM1054502,GSM1054503,GSM1054504,GSM1054505,GSM1054506,GSM1054507,GSM1054508,GSM1054509,GSM1054510,GSM1054511,GSM1054512,GSM1054513
|
| 2 |
-
Mitochondrial_Disorders,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,
|
| 3 |
Age,0.76,20.0,20.0,16.0,1.0,0.75,0.75,3.0,3.0,0.2,0.9,2.0,6.0,10.0,4.0,0.3,8.0,72.0,54.0,23.0,0.75,60.0,67.0,59.0,59.0,11.0,46.0,42.0,2.0,,,,4.0,0.76,20.0,5.0,16.0,5.0,1.0,0.75,3.0,30.0,2.0,36.0,39.0,6.0,10.0,4.0,0.3,0.1,8.0,11.0,0.7
|
| 4 |
Gender,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0
|
|
|
|
| 1 |
,GSM1054461,GSM1054462,GSM1054463,GSM1054464,GSM1054465,GSM1054466,GSM1054467,GSM1054468,GSM1054469,GSM1054470,GSM1054471,GSM1054472,GSM1054473,GSM1054474,GSM1054475,GSM1054476,GSM1054477,GSM1054478,GSM1054479,GSM1054480,GSM1054481,GSM1054482,GSM1054483,GSM1054484,GSM1054485,GSM1054486,GSM1054487,GSM1054488,GSM1054489,GSM1054490,GSM1054491,GSM1054492,GSM1054493,GSM1054494,GSM1054495,GSM1054496,GSM1054497,GSM1054498,GSM1054499,GSM1054500,GSM1054501,GSM1054502,GSM1054503,GSM1054504,GSM1054505,GSM1054506,GSM1054507,GSM1054508,GSM1054509,GSM1054510,GSM1054511,GSM1054512,GSM1054513
|
| 2 |
+
Mitochondrial_Disorders,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,,1.0,1.0,,,0.0,0.0,0.0,,1.0,,,0.0,0.0,0.0,1.0,0.0,,1.0,1.0,1.0,1.0,0.0,,1.0,0.0,,0.0,1.0,0.0,1.0,1.0,,1.0,1.0,1.0
|
| 3 |
Age,0.76,20.0,20.0,16.0,1.0,0.75,0.75,3.0,3.0,0.2,0.9,2.0,6.0,10.0,4.0,0.3,8.0,72.0,54.0,23.0,0.75,60.0,67.0,59.0,59.0,11.0,46.0,42.0,2.0,,,,4.0,0.76,20.0,5.0,16.0,5.0,1.0,0.75,3.0,30.0,2.0,36.0,39.0,6.0,10.0,4.0,0.3,0.1,8.0,11.0,0.7
|
| 4 |
Gender,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0
|
output/preprocess/Mitochondrial_Disorders/code/GSE22651.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Mitochondrial_Disorders"
|
| 6 |
+
cohort = "GSE22651"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Mitochondrial_Disorders"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Mitochondrial_Disorders/GSE22651"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/GSE22651.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/gene_data/GSE22651.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/clinical_data/GSE22651.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Mitochondrial_Disorders/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
|
| 41 |
+
# 1) Gene expression data availability
|
| 42 |
+
is_gene_available = True # Illumina HT12 v3 mRNA expression platform suggests gene expression is available.
|
| 43 |
+
|
| 44 |
+
# 2) Variable availability and conversion functions
|
| 45 |
+
|
| 46 |
+
# Based on the provided sample characteristics dictionary, trait status (FRDA vs control) is not explicitly or reliably available.
|
| 47 |
+
trait_row = None
|
| 48 |
+
|
| 49 |
+
# Age appears inconsistently and mostly absent/constant (e.g., only "age: 47 years" once), so treat as unavailable.
|
| 50 |
+
age_row = None
|
| 51 |
+
|
| 52 |
+
# Gender information is split across different rows (e.g., 'gender: male' under key 0 and 'gender: female' under key 1),
|
| 53 |
+
# making it not available as a single consistent feature.
|
| 54 |
+
gender_row = None
|
| 55 |
+
|
| 56 |
+
def _after_colon(x):
|
| 57 |
+
if x is None:
|
| 58 |
+
return None
|
| 59 |
+
if isinstance(x, str):
|
| 60 |
+
parts = x.split(":", 1)
|
| 61 |
+
val = parts[1] if len(parts) > 1 else parts[0]
|
| 62 |
+
val = val.strip()
|
| 63 |
+
return val if val else None
|
| 64 |
+
return None
|
| 65 |
+
|
| 66 |
+
def convert_trait(x):
|
| 67 |
+
# Heuristic mapping for FRDA vs control if ever needed:
|
| 68 |
+
# Return 1 for FRDA, 0 for control, None if unknown.
|
| 69 |
+
v = _after_colon(x)
|
| 70 |
+
if v is None:
|
| 71 |
+
return None
|
| 72 |
+
vl = v.lower()
|
| 73 |
+
# Clear FRDA indicators
|
| 74 |
+
if "friedreich" in vl or "frda" in vl or "patient" in vl:
|
| 75 |
+
return 1
|
| 76 |
+
# Likely controls (common control lines/tissues)
|
| 77 |
+
ctrl_markers = ["embryonic stem cell", "hes-", "hsf", "h9", "keratinocyte", "huvec", "mesenchymal_stem_cells", "hs27", "hdf"]
|
| 78 |
+
if any(m in vl for m in ctrl_markers):
|
| 79 |
+
return 0
|
| 80 |
+
return None
|
| 81 |
+
|
| 82 |
+
def convert_age(x):
|
| 83 |
+
v = _after_colon(x)
|
| 84 |
+
if v is None:
|
| 85 |
+
return None
|
| 86 |
+
vl = v.lower()
|
| 87 |
+
if vl in {"na", "unknown", ""}:
|
| 88 |
+
return None
|
| 89 |
+
m = re.search(r'(\d{1,3})', vl)
|
| 90 |
+
if not m:
|
| 91 |
+
return None
|
| 92 |
+
age = int(m.group(1))
|
| 93 |
+
if 0 <= age <= 120:
|
| 94 |
+
return age
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
def convert_gender(x):
|
| 98 |
+
v = _after_colon(x)
|
| 99 |
+
if v is None:
|
| 100 |
+
return None
|
| 101 |
+
vl = v.strip().lower()
|
| 102 |
+
if vl in {"male", "m"}:
|
| 103 |
+
return 1
|
| 104 |
+
if vl in {"female", "f"}:
|
| 105 |
+
return 0
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
# 3) Save metadata via initial filtering
|
| 109 |
+
is_trait_available = trait_row is not None
|
| 110 |
+
_ = validate_and_save_cohort_info(
|
| 111 |
+
is_final=False,
|
| 112 |
+
cohort=cohort,
|
| 113 |
+
info_path=json_path,
|
| 114 |
+
is_gene_available=is_gene_available,
|
| 115 |
+
is_trait_available=is_trait_available
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
# 4) Clinical feature extraction (skip because trait_row is None)
|
| 119 |
+
if trait_row is not None:
|
| 120 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 121 |
+
clinical_df=clinical_data,
|
| 122 |
+
trait=trait,
|
| 123 |
+
trait_row=trait_row,
|
| 124 |
+
convert_trait=convert_trait,
|
| 125 |
+
age_row=age_row,
|
| 126 |
+
convert_age=convert_age,
|
| 127 |
+
gender_row=gender_row,
|
| 128 |
+
convert_gender=convert_gender
|
| 129 |
+
)
|
| 130 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 131 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 132 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
output/preprocess/Mitochondrial_Disorders/code/GSE30933.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Mitochondrial_Disorders"
|
| 6 |
+
cohort = "GSE30933"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Mitochondrial_Disorders"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Mitochondrial_Disorders/GSE30933"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/GSE30933.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/gene_data/GSE30933.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/clinical_data/GSE30933.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Mitochondrial_Disorders/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import pandas as pd
|
| 41 |
+
|
| 42 |
+
# 1) Gene expression data availability
|
| 43 |
+
is_gene_available = True # Microarray gene expression in PBMCs
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability and conversion functions
|
| 46 |
+
|
| 47 |
+
# Keys from Sample Characteristics Dictionary
|
| 48 |
+
trait_row = 0 # 'disease status: Normal/Carrier/FRDA'
|
| 49 |
+
age_row = None # Not available
|
| 50 |
+
gender_row = None # Not available
|
| 51 |
+
|
| 52 |
+
def _extract_value(x):
|
| 53 |
+
if x is None or (isinstance(x, float) and pd.isna(x)):
|
| 54 |
+
return None
|
| 55 |
+
s = str(x)
|
| 56 |
+
if ':' in s:
|
| 57 |
+
s = s.split(':', 1)[1]
|
| 58 |
+
s = s.strip()
|
| 59 |
+
return s if s != '' else None
|
| 60 |
+
|
| 61 |
+
def convert_trait(x):
|
| 62 |
+
v = _extract_value(x)
|
| 63 |
+
if v is None:
|
| 64 |
+
return None
|
| 65 |
+
v_low = v.lower()
|
| 66 |
+
# Map FRDA patients to 1; carriers and normals to 0
|
| 67 |
+
if any(k in v_low for k in ['frda', 'friedreich']):
|
| 68 |
+
return 1
|
| 69 |
+
if any(k in v_low for k in ['normal', 'control', 'healthy', 'carrier']):
|
| 70 |
+
return 0
|
| 71 |
+
return None
|
| 72 |
+
|
| 73 |
+
def convert_age(x):
|
| 74 |
+
v = _extract_value(x)
|
| 75 |
+
if v is None:
|
| 76 |
+
return None
|
| 77 |
+
# extract first numeric token as age in years
|
| 78 |
+
try:
|
| 79 |
+
# keep digits and dot
|
| 80 |
+
import re
|
| 81 |
+
m = re.search(r'[-+]?\d*\.?\d+', v)
|
| 82 |
+
return float(m.group()) if m else None
|
| 83 |
+
except Exception:
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
def convert_gender(x):
|
| 87 |
+
v = _extract_value(x)
|
| 88 |
+
if v is None:
|
| 89 |
+
return None
|
| 90 |
+
v_low = v.lower()
|
| 91 |
+
if v_low in ['male', 'm']:
|
| 92 |
+
return 1
|
| 93 |
+
if v_low in ['female', 'f']:
|
| 94 |
+
return 0
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
# 3) Save metadata with initial filtering
|
| 98 |
+
is_trait_available = trait_row is not None
|
| 99 |
+
_ = validate_and_save_cohort_info(
|
| 100 |
+
is_final=False,
|
| 101 |
+
cohort=cohort,
|
| 102 |
+
info_path=json_path,
|
| 103 |
+
is_gene_available=is_gene_available,
|
| 104 |
+
is_trait_available=is_trait_available
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# 4) Clinical Feature Extraction (only if trait is available)
|
| 108 |
+
if trait_row is not None:
|
| 109 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 110 |
+
clinical_df=clinical_data,
|
| 111 |
+
trait=trait,
|
| 112 |
+
trait_row=trait_row,
|
| 113 |
+
convert_trait=convert_trait,
|
| 114 |
+
age_row=age_row,
|
| 115 |
+
convert_age=convert_age,
|
| 116 |
+
gender_row=gender_row,
|
| 117 |
+
convert_gender=convert_gender
|
| 118 |
+
)
|
| 119 |
+
# Preview
|
| 120 |
+
preview = preview_df(selected_clinical_df, n=5)
|
| 121 |
+
print("Clinical features preview:", preview)
|
| 122 |
+
|
| 123 |
+
# Save
|
| 124 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 125 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 126 |
+
|
| 127 |
+
# Step 3: Gene Data Extraction
|
| 128 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 129 |
+
gene_data = get_genetic_data(matrix_file)
|
| 130 |
+
|
| 131 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 132 |
+
print(gene_data.index[:20])
|
| 133 |
+
|
| 134 |
+
# Step 4: Gene Identifier Review
|
| 135 |
+
print("requires_gene_mapping = True")
|
| 136 |
+
|
| 137 |
+
# Step 5: Gene Annotation
|
| 138 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 139 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 140 |
+
|
| 141 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 142 |
+
print("Gene annotation preview:")
|
| 143 |
+
print(preview_df(gene_annotation))
|
| 144 |
+
|
| 145 |
+
# Step 6: Gene Identifier Mapping
|
| 146 |
+
# Map probe IDs to gene symbols using annotation columns: 'ID' (probe) and 'SYMBOL' (gene symbol)
|
| 147 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='SYMBOL')
|
| 148 |
+
|
| 149 |
+
# Apply mapping to convert probe-level data to gene-level expression
|
| 150 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
| 151 |
+
|
| 152 |
+
# Step 7: Data Normalization and Linking
|
| 153 |
+
import os
|
| 154 |
+
|
| 155 |
+
# 1. Normalize the obtained gene data and save
|
| 156 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 157 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 158 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 159 |
+
|
| 160 |
+
# 2. Link the clinical and genetic data
|
| 161 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 162 |
+
|
| 163 |
+
# 3. Handle missing values
|
| 164 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 165 |
+
|
| 166 |
+
# 4. Determine whether the trait and demographic features are severely biased, and remove biased features.
|
| 167 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 168 |
+
|
| 169 |
+
# 5. Final validation and save cohort info
|
| 170 |
+
note = "INFO: Age and Gender not available in clinical data. Trait derived from 'disease status'."
|
| 171 |
+
is_usable = validate_and_save_cohort_info(
|
| 172 |
+
is_final=True,
|
| 173 |
+
cohort=cohort,
|
| 174 |
+
info_path=json_path,
|
| 175 |
+
is_gene_available=True,
|
| 176 |
+
is_trait_available=True,
|
| 177 |
+
is_biased=is_trait_biased,
|
| 178 |
+
df=unbiased_linked_data,
|
| 179 |
+
note=note
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
# 6. Save linked data if usable
|
| 183 |
+
if is_usable:
|
| 184 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 185 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Mitochondrial_Disorders/code/GSE42986.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Mitochondrial_Disorders"
|
| 6 |
+
cohort = "GSE42986"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Mitochondrial_Disorders"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Mitochondrial_Disorders/GSE42986"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/GSE42986.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/gene_data/GSE42986.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/clinical_data/GSE42986.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Mitochondrial_Disorders/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
import pandas as pd
|
| 42 |
+
|
| 43 |
+
# 1) Gene expression availability
|
| 44 |
+
is_gene_available = True # Affymetrix Human Exon 1.0 ST indicates mRNA expression profiling
|
| 45 |
+
|
| 46 |
+
# 2) Variable availability (rows inferred from the provided Sample Characteristics Dictionary)
|
| 47 |
+
trait_row = 4 # 'informatic analysis group: Mito Disease Group' vs 'Control Group' (exclude poor quality/outlier)
|
| 48 |
+
age_row = 3 # 'age (years): ...'
|
| 49 |
+
gender_row = 2 # 'gender: F/M'
|
| 50 |
+
|
| 51 |
+
# 2.2) Conversion helpers
|
| 52 |
+
def _after_colon(x):
|
| 53 |
+
if x is None:
|
| 54 |
+
return None
|
| 55 |
+
s = str(x)
|
| 56 |
+
if ':' in s:
|
| 57 |
+
s = s.split(':', 1)[1]
|
| 58 |
+
return s.strip() if s is not None else None
|
| 59 |
+
|
| 60 |
+
def convert_trait(x):
|
| 61 |
+
v = _after_colon(x)
|
| 62 |
+
if v is None:
|
| 63 |
+
return None
|
| 64 |
+
vl = v.strip().lower()
|
| 65 |
+
|
| 66 |
+
# Primary mapping for row 4
|
| 67 |
+
if vl in {"mito disease group", "mito disease", "disease", "patient", "rc disease group"}:
|
| 68 |
+
return 1
|
| 69 |
+
if vl in {"control group", "control", "healthy", "normal"}:
|
| 70 |
+
return 0
|
| 71 |
+
if "exclude" in vl or "outlier" in vl or "poor quality" in vl:
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
+
# Heuristic fallback if a different row is encountered inadvertently
|
| 75 |
+
if "no respiratory chain complex deficiency" in vl:
|
| 76 |
+
return 0
|
| 77 |
+
if "complex" in vl or "mtdna depletion" in vl:
|
| 78 |
+
return 1
|
| 79 |
+
if "not determined" in vl or "not measured" in vl:
|
| 80 |
+
return None
|
| 81 |
+
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
def convert_age(x):
|
| 85 |
+
v = _after_colon(x)
|
| 86 |
+
if v is None:
|
| 87 |
+
return None
|
| 88 |
+
vl = v.strip().lower()
|
| 89 |
+
if vl in {"not obtained", "na", "n/a", "unknown", ""}:
|
| 90 |
+
return None
|
| 91 |
+
try:
|
| 92 |
+
return float(vl)
|
| 93 |
+
except Exception:
|
| 94 |
+
m = re.search(r"[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?", vl)
|
| 95 |
+
if m:
|
| 96 |
+
try:
|
| 97 |
+
return float(m.group(0))
|
| 98 |
+
except Exception:
|
| 99 |
+
return None
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
def convert_gender(x):
|
| 103 |
+
v = _after_colon(x)
|
| 104 |
+
if v is None:
|
| 105 |
+
return None
|
| 106 |
+
vl = v.strip().lower()
|
| 107 |
+
if vl in {"f", "female"}:
|
| 108 |
+
return 0
|
| 109 |
+
if vl in {"m", "male"}:
|
| 110 |
+
return 1
|
| 111 |
+
return None
|
| 112 |
+
|
| 113 |
+
# 3) Initial filtering and save metadata
|
| 114 |
+
is_trait_available = trait_row is not None
|
| 115 |
+
_ = validate_and_save_cohort_info(
|
| 116 |
+
is_final=False,
|
| 117 |
+
cohort=cohort,
|
| 118 |
+
info_path=json_path,
|
| 119 |
+
is_gene_available=is_gene_available,
|
| 120 |
+
is_trait_available=is_trait_available
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
# 4) Clinical feature extraction (only if clinical data is available)
|
| 124 |
+
if is_trait_available:
|
| 125 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 126 |
+
clinical_df=clinical_data,
|
| 127 |
+
trait=trait,
|
| 128 |
+
trait_row=trait_row,
|
| 129 |
+
convert_trait=convert_trait,
|
| 130 |
+
age_row=age_row,
|
| 131 |
+
convert_age=convert_age,
|
| 132 |
+
gender_row=gender_row,
|
| 133 |
+
convert_gender=convert_gender
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
preview = preview_df(selected_clinical_df, n=5)
|
| 137 |
+
print("Selected clinical features preview:", preview)
|
| 138 |
+
|
| 139 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 140 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 141 |
+
|
| 142 |
+
# Step 3: Gene Data Extraction
|
| 143 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 144 |
+
gene_data = get_genetic_data(matrix_file)
|
| 145 |
+
|
| 146 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 147 |
+
print(gene_data.index[:20])
|
| 148 |
+
|
| 149 |
+
# Step 4: Gene Identifier Review
|
| 150 |
+
# Affymetrix probe set IDs (e.g., '10000_at') are not human gene symbols and require mapping.
|
| 151 |
+
requires_gene_mapping = True
|
| 152 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 153 |
+
|
| 154 |
+
# Step 5: Gene Annotation
|
| 155 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 156 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 157 |
+
|
| 158 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 159 |
+
print("Gene annotation preview:")
|
| 160 |
+
print(preview_df(gene_annotation))
|
| 161 |
+
|
| 162 |
+
# Step 6: Gene Identifier Mapping
|
| 163 |
+
# 1-2. Build mapping from probe IDs to gene symbols using the appropriate columns
|
| 164 |
+
# Probe identifiers: 'ID' (e.g., '10000_at'); Gene symbols: 'Symbol' (e.g., 'A1BG')
|
| 165 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol')
|
| 166 |
+
|
| 167 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 168 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
| 169 |
+
|
| 170 |
+
# Step 7: Data Normalization and Linking
|
| 171 |
+
import os
|
| 172 |
+
|
| 173 |
+
# 1. Normalize gene symbols and save
|
| 174 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 175 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 176 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 177 |
+
|
| 178 |
+
# 2. Link the clinical and genetic data
|
| 179 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 180 |
+
|
| 181 |
+
# 3. Handle missing values
|
| 182 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 183 |
+
|
| 184 |
+
# 4. Bias assessment and removal of biased covariates
|
| 185 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 186 |
+
|
| 187 |
+
# Prepare availability flags for final validation (ensure pure Python bools)
|
| 188 |
+
is_gene_available_final = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
|
| 189 |
+
is_trait_available_final = bool((trait in linked_data.columns) and linked_data[trait].notna().any())
|
| 190 |
+
is_trait_biased = bool(is_trait_biased)
|
| 191 |
+
|
| 192 |
+
note = "INFO: Samples labeled 'Excluded' or 'outlier' in the informatic analysis group were set to missing trait and removed during missing-value handling."
|
| 193 |
+
|
| 194 |
+
# 5. Final validation and save cohort info
|
| 195 |
+
is_usable = validate_and_save_cohort_info(
|
| 196 |
+
is_final=True,
|
| 197 |
+
cohort=str(cohort),
|
| 198 |
+
info_path=str(json_path),
|
| 199 |
+
is_gene_available=bool(is_gene_available_final),
|
| 200 |
+
is_trait_available=bool(is_trait_available_final),
|
| 201 |
+
is_biased=bool(is_trait_biased),
|
| 202 |
+
df=unbiased_linked_data,
|
| 203 |
+
note=str(note)
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
# 6. Save linked data if usable
|
| 207 |
+
if is_usable:
|
| 208 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 209 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Mitochondrial_Disorders/code/GSE65399.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Mitochondrial_Disorders"
|
| 6 |
+
cohort = "GSE65399"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Mitochondrial_Disorders"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Mitochondrial_Disorders/GSE65399"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/GSE65399.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/gene_data/GSE65399.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/clinical_data/GSE65399.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Mitochondrial_Disorders/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# Step 1: Assess gene expression data availability based on background information
|
| 40 |
+
is_gene_available = True # Illumina HT12v4 Gene Expression BeadArray indicates mRNA expression data
|
| 41 |
+
|
| 42 |
+
# Step 2: Determine availability of trait, age, and gender from the sample characteristics dictionary
|
| 43 |
+
# Trait and gender are not available; "time point" can be used as developmental age.
|
| 44 |
+
trait_row = None
|
| 45 |
+
age_row = 1 # "time point" (e.g., 8wk, 20wk, d24)
|
| 46 |
+
gender_row = None
|
| 47 |
+
|
| 48 |
+
# Step 2.2: Define conversion functions
|
| 49 |
+
import re
|
| 50 |
+
import pandas as pd
|
| 51 |
+
|
| 52 |
+
def _parse_value(x):
|
| 53 |
+
if x is None or (isinstance(x, float) and pd.isna(x)):
|
| 54 |
+
return None
|
| 55 |
+
if isinstance(x, str):
|
| 56 |
+
parts = x.split(":", 1)
|
| 57 |
+
v = parts[1].strip() if len(parts) > 1 else x.strip()
|
| 58 |
+
if v == "" or v.lower() in {"na", "n/a", "unknown", "missing", "not available", "nd"}:
|
| 59 |
+
return None
|
| 60 |
+
return v
|
| 61 |
+
return x
|
| 62 |
+
|
| 63 |
+
def convert_trait(x):
|
| 64 |
+
_ = _parse_value(x)
|
| 65 |
+
return None
|
| 66 |
+
|
| 67 |
+
def convert_age(x):
|
| 68 |
+
# Parse developmental time to weeks as float.
|
| 69 |
+
v = _parse_value(x)
|
| 70 |
+
if v is None:
|
| 71 |
+
return None
|
| 72 |
+
s = str(v).strip().lower()
|
| 73 |
+
# Examples: "20wk", "20 wk", "18w", "d24", "24d"
|
| 74 |
+
m = re.search(r'(\d+(?:\.\d+)?)\s*wk?', s)
|
| 75 |
+
if m:
|
| 76 |
+
try:
|
| 77 |
+
return float(m.group(1))
|
| 78 |
+
except ValueError:
|
| 79 |
+
return None
|
| 80 |
+
m = re.search(r'^d(\d+(?:\.\d+)?)$', s)
|
| 81 |
+
if m:
|
| 82 |
+
try:
|
| 83 |
+
return float(m.group(1)) / 7.0
|
| 84 |
+
except ValueError:
|
| 85 |
+
return None
|
| 86 |
+
m = re.search(r'(\d+(?:\.\d+)?)\s*d', s)
|
| 87 |
+
if m:
|
| 88 |
+
try:
|
| 89 |
+
return float(m.group(1)) / 7.0
|
| 90 |
+
except ValueError:
|
| 91 |
+
return None
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
def convert_gender(x):
|
| 95 |
+
v = _parse_value(x)
|
| 96 |
+
if v is None:
|
| 97 |
+
return None
|
| 98 |
+
v_low = str(v).strip().lower()
|
| 99 |
+
if v_low in {"female", "f", "woman", "girl"}:
|
| 100 |
+
return 0
|
| 101 |
+
if v_low in {"male", "m", "man", "boy"}:
|
| 102 |
+
return 1
|
| 103 |
+
return None
|
| 104 |
+
|
| 105 |
+
# Step 3: Initial filtering and save metadata
|
| 106 |
+
is_trait_available = trait_row is not None
|
| 107 |
+
_ = validate_and_save_cohort_info(
|
| 108 |
+
is_final=False,
|
| 109 |
+
cohort=cohort,
|
| 110 |
+
info_path=json_path,
|
| 111 |
+
is_gene_available=is_gene_available,
|
| 112 |
+
is_trait_available=is_trait_available
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# Step 4: Clinical feature extraction (skip since trait_row is None)
|
| 116 |
+
if trait_row is not None:
|
| 117 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 118 |
+
clinical_df=clinical_data,
|
| 119 |
+
trait=trait,
|
| 120 |
+
trait_row=trait_row,
|
| 121 |
+
convert_trait=convert_trait,
|
| 122 |
+
age_row=age_row,
|
| 123 |
+
convert_age=convert_age,
|
| 124 |
+
gender_row=gender_row,
|
| 125 |
+
convert_gender=convert_gender
|
| 126 |
+
)
|
| 127 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 128 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 129 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
output/preprocess/Mitochondrial_Disorders/code/TCGA.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Mitochondrial_Disorders"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z4/preprocess/Mitochondrial_Disorders/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z4/preprocess/Mitochondrial_Disorders/cohort_info.json"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Step 1: Initial Data Loading
|
| 18 |
+
import os
|
| 19 |
+
import pandas as pd
|
| 20 |
+
|
| 21 |
+
# Step 1: Find the most relevant TCGA cohort directory for the trait
|
| 22 |
+
all_entries = os.listdir(tcga_root_dir)
|
| 23 |
+
subdirs = [d for d in all_entries if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 24 |
+
|
| 25 |
+
# Keywords related to mitochondrial disorders; keep them specific to avoid false positives
|
| 26 |
+
keywords = [
|
| 27 |
+
"mitochond", "mitochondrial", "mtdna", "mt-dna", "respiratory_chain", "oxphos", "oxidative_phosphorylation",
|
| 28 |
+
"mitophagy", "electron_transport_chain"
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
matches = []
|
| 32 |
+
for d in subdirs:
|
| 33 |
+
name_lower = d.lower()
|
| 34 |
+
if any(k in name_lower for k in keywords):
|
| 35 |
+
matches.append(d)
|
| 36 |
+
|
| 37 |
+
selected_dir = None
|
| 38 |
+
if matches:
|
| 39 |
+
# If multiple, choose the most specific match by the longest match length
|
| 40 |
+
def best_score(dirname: str) -> int:
|
| 41 |
+
name_lower = dirname.lower()
|
| 42 |
+
return max((len(k) for k in keywords if k in name_lower), default=0)
|
| 43 |
+
selected_dir = max(matches, key=best_score)
|
| 44 |
+
|
| 45 |
+
if not selected_dir:
|
| 46 |
+
# No suitable TCGA cohort for mitochondrial disorders; record and skip
|
| 47 |
+
_ = validate_and_save_cohort_info(
|
| 48 |
+
is_final=False,
|
| 49 |
+
cohort="TCGA",
|
| 50 |
+
info_path=json_path,
|
| 51 |
+
is_gene_available=False,
|
| 52 |
+
is_trait_available=False
|
| 53 |
+
)
|
| 54 |
+
print("No suitable TCGA cohort directory found for the trait. Skipping this trait.")
|
| 55 |
+
else:
|
| 56 |
+
# Step 2: Identify clinical and genetic files in the selected directory
|
| 57 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 58 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
| 59 |
+
|
| 60 |
+
# Step 3: Load both files as DataFrames
|
| 61 |
+
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False)
|
| 62 |
+
genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False)
|
| 63 |
+
|
| 64 |
+
# Step 4: Print clinical data column names for inspection
|
| 65 |
+
print(list(clinical_df.columns))
|
output/preprocess/Mitochondrial_Disorders/cohort_info.json
CHANGED
|
@@ -1,52 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"GSE65399": {
|
| 3 |
-
"is_usable": false,
|
| 4 |
-
"is_gene_available": false,
|
| 5 |
-
"is_trait_available": false,
|
| 6 |
-
"is_available": false,
|
| 7 |
-
"is_biased": null,
|
| 8 |
-
"has_age": null,
|
| 9 |
-
"has_gender": null,
|
| 10 |
-
"sample_size": null
|
| 11 |
-
},
|
| 12 |
-
"GSE42986": {
|
| 13 |
-
"is_usable": true,
|
| 14 |
-
"is_gene_available": true,
|
| 15 |
-
"is_trait_available": true,
|
| 16 |
-
"is_available": true,
|
| 17 |
-
"is_biased": false,
|
| 18 |
-
"has_age": true,
|
| 19 |
-
"has_gender": true,
|
| 20 |
-
"sample_size": 46
|
| 21 |
-
},
|
| 22 |
-
"GSE30933": {
|
| 23 |
-
"is_usable": true,
|
| 24 |
-
"is_gene_available": true,
|
| 25 |
-
"is_trait_available": true,
|
| 26 |
-
"is_available": true,
|
| 27 |
-
"is_biased": false,
|
| 28 |
-
"has_age": false,
|
| 29 |
-
"has_gender": false,
|
| 30 |
-
"sample_size": 108
|
| 31 |
-
},
|
| 32 |
-
"GSE22651": {
|
| 33 |
-
"is_usable": false,
|
| 34 |
-
"is_gene_available": false,
|
| 35 |
-
"is_trait_available": false,
|
| 36 |
-
"is_available": false,
|
| 37 |
-
"is_biased": null,
|
| 38 |
-
"has_age": null,
|
| 39 |
-
"has_gender": null,
|
| 40 |
-
"sample_size": null
|
| 41 |
-
},
|
| 42 |
-
"TCGA": {
|
| 43 |
-
"is_usable": false,
|
| 44 |
-
"is_gene_available": false,
|
| 45 |
-
"is_trait_available": false,
|
| 46 |
-
"is_available": false,
|
| 47 |
-
"is_biased": null,
|
| 48 |
-
"has_age": null,
|
| 49 |
-
"has_gender": null,
|
| 50 |
-
"sample_size": null
|
| 51 |
-
}
|
| 52 |
-
}
|
|
|
|
| 1 |
+
{"GSE65399": {"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}, "GSE42986": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 43, "note": "INFO: Samples labeled 'Excluded' or 'outlier' in the informatic analysis group were set to missing trait and removed during missing-value handling."}, "GSE30933": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 108, "note": "INFO: Age and Gender not available in clinical data. Trait derived from 'disease status'."}, "GSE22651": {"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}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/GSE19987.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/clinical_data/GSE19987.csv
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
|
| 2 |
-
0.0,0.0,0.0,0.0,1.0,1.0,0.0
|
|
|
|
| 1 |
+
,GSM62248,GSM62249,GSM62250,GSM62251,GSM62252,GSM62253,GSM62254,GSM62255,GSM62256,GSM62257,GSM62258,GSM62259,GSM62260,GSM62261,GSM62262,GSM62263,GSM62264,GSM62265,GSM62266,GSM62267,GSM62268,GSM62269,GSM62270,GSM62271,GSM62272,GSM62273,GSM62274,GSM62275,GSM62276,GSM62277,GSM62278,GSM62279,GSM62280,GSM62281,GSM62282,GSM62283,GSM62284,GSM62285,GSM62286,GSM62287,GSM62288,GSM62289,GSM62290,GSM62291,GSM62292,GSM62293,GSM62294,GSM62295,GSM62296,GSM62297,GSM62298,GSM62299,GSM62300,GSM62301,GSM62302,GSM62303,GSM62304,GSM62305,GSM62306,GSM62307,GSM62308,GSM62309,GSM62310,GSM62311,GSM62312,GSM62313,GSM62314,GSM62315,GSM62316,GSM62317,GSM62318,GSM62319,GSM62320,GSM62321,GSM62322
|
| 2 |
+
Multiple_Endocrine_Neoplasia_Type_2,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,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,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,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0
|
output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/code/GSE19987.py
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_Endocrine_Neoplasia_Type_2"
|
| 6 |
+
cohort = "GSE19987"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_Endocrine_Neoplasia_Type_2"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_Endocrine_Neoplasia_Type_2/GSE19987"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z4/preprocess/Multiple_Endocrine_Neoplasia_Type_2/GSE19987.csv"
|
| 14 |
+
out_gene_data_file = "./output/z4/preprocess/Multiple_Endocrine_Neoplasia_Type_2/gene_data/GSE19987.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z4/preprocess/Multiple_Endocrine_Neoplasia_Type_2/clinical_data/GSE19987.csv"
|
| 16 |
+
json_path = "./output/z4/preprocess/Multiple_Endocrine_Neoplasia_Type_2/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
|
| 42 |
+
# 1) Gene expression data availability
|
| 43 |
+
is_gene_available = True # Expression profiling study of tumors; likely mRNA expression data
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability
|
| 46 |
+
# From the sample characteristics:
|
| 47 |
+
# 0: tumor type (constant: pheochromocytoma)
|
| 48 |
+
# 1: genetic class (includes 'MEN2A' among others) -> can infer MEN2 status
|
| 49 |
+
# 2: tumor location (not trait, not age, not gender)
|
| 50 |
+
trait_row = 1
|
| 51 |
+
age_row = None
|
| 52 |
+
gender_row = None
|
| 53 |
+
|
| 54 |
+
# 2.2) Data type conversion functions
|
| 55 |
+
def _after_colon(x):
|
| 56 |
+
if x is None:
|
| 57 |
+
return None
|
| 58 |
+
s = str(x)
|
| 59 |
+
parts = s.split(':', 1)
|
| 60 |
+
val = parts[-1].strip() if len(parts) > 1 else s.strip()
|
| 61 |
+
return val if val != '' else None
|
| 62 |
+
|
| 63 |
+
def convert_trait(x):
|
| 64 |
+
val = _after_colon(x)
|
| 65 |
+
if val is None:
|
| 66 |
+
return None
|
| 67 |
+
v = val.strip().lower()
|
| 68 |
+
# Map MEN2 syndromes to 1; others to 0
|
| 69 |
+
if 'men2' in v:
|
| 70 |
+
return 1
|
| 71 |
+
return 0
|
| 72 |
+
|
| 73 |
+
def convert_age(x):
|
| 74 |
+
val = _after_colon(x)
|
| 75 |
+
if val is None:
|
| 76 |
+
return None
|
| 77 |
+
v = val.lower()
|
| 78 |
+
# Extract first numeric token as age
|
| 79 |
+
m = re.search(r'(\d+(\.\d+)?)', v)
|
| 80 |
+
if m:
|
| 81 |
+
try:
|
| 82 |
+
return float(m.group(1))
|
| 83 |
+
except:
|
| 84 |
+
return None
|
| 85 |
+
return None
|
| 86 |
+
|
| 87 |
+
def convert_gender(x):
|
| 88 |
+
val = _after_colon(x)
|
| 89 |
+
if val is None:
|
| 90 |
+
return None
|
| 91 |
+
v = val.strip().lower()
|
| 92 |
+
if v in {'male', 'm'}:
|
| 93 |
+
return 1
|
| 94 |
+
if v in {'female', 'f'}:
|
| 95 |
+
return 0
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
# 3) Initial filtering and save metadata
|
| 99 |
+
is_trait_available = trait_row is not None
|
| 100 |
+
_ = validate_and_save_cohort_info(
|
| 101 |
+
is_final=False,
|
| 102 |
+
cohort=cohort,
|
| 103 |
+
info_path=json_path,
|
| 104 |
+
is_gene_available=is_gene_available,
|
| 105 |
+
is_trait_available=is_trait_available
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# 4) Clinical Feature Extraction (only if clinical data is available)
|
| 109 |
+
if trait_row is not None:
|
| 110 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 111 |
+
clinical_df=clinical_data,
|
| 112 |
+
trait=trait,
|
| 113 |
+
trait_row=trait_row,
|
| 114 |
+
convert_trait=convert_trait,
|
| 115 |
+
age_row=age_row,
|
| 116 |
+
convert_age=convert_age,
|
| 117 |
+
gender_row=gender_row,
|
| 118 |
+
convert_gender=convert_gender
|
| 119 |
+
)
|
| 120 |
+
preview = preview_df(selected_clinical_df)
|
| 121 |
+
print("Selected clinical features preview:", preview)
|
| 122 |
+
|
| 123 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 124 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 125 |
+
|
| 126 |
+
# Step 3: Gene Data Extraction
|
| 127 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 128 |
+
gene_data = get_genetic_data(matrix_file)
|
| 129 |
+
|
| 130 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 131 |
+
print(gene_data.index[:20])
|
| 132 |
+
|
| 133 |
+
# Step 4: Gene Identifier Review
|
| 134 |
+
requires_gene_mapping = True
|
| 135 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 136 |
+
|
| 137 |
+
# Step 5: Gene Annotation
|
| 138 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 139 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 140 |
+
|
| 141 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 142 |
+
print("Gene annotation preview:")
|
| 143 |
+
print(preview_df(gene_annotation))
|
| 144 |
+
|
| 145 |
+
# Step 6: Gene Identifier Mapping
|
| 146 |
+
# Decide the appropriate columns for probe IDs and gene symbols based on the annotation preview
|
| 147 |
+
probe_col = 'ID'
|
| 148 |
+
gene_symbol_col = 'Gene Symbol'
|
| 149 |
+
|
| 150 |
+
# Build mapping dataframe
|
| 151 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 152 |
+
|
| 153 |
+
# Apply mapping to convert probe-level expression to gene-level expression
|
| 154 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
| 155 |
+
|
| 156 |
+
# Step 7: Data Normalization and Linking
|
| 157 |
+
import os
|
| 158 |
+
import pandas as pd
|
| 159 |
+
|
| 160 |
+
# 1. Normalize the obtained gene data and save
|
| 161 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 162 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 163 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 164 |
+
|
| 165 |
+
# 2. Link the clinical and genetic data
|
| 166 |
+
# Use the correct clinical variable; fallback to load if not in memory
|
| 167 |
+
try:
|
| 168 |
+
selected_clinical_df
|
| 169 |
+
except NameError:
|
| 170 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 171 |
+
|
| 172 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 173 |
+
|
| 174 |
+
# Compute availability flags based on data
|
| 175 |
+
is_gene_available = (normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0)
|
| 176 |
+
is_trait_available = trait in linked_data.columns
|
| 177 |
+
|
| 178 |
+
# 3. Handle missing values
|
| 179 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 180 |
+
|
| 181 |
+
# 4. Determine whether the trait and some demographic features are severely biased, and remove biased features.
|
| 182 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 183 |
+
|
| 184 |
+
# 5. Conduct final quality validation and save the cohort information.
|
| 185 |
+
note = "INFO: Trait inferred from 'genetic class' (MEN2 vs others); Age/Gender not provided in series matrix."
|
| 186 |
+
is_usable = validate_and_save_cohort_info(
|
| 187 |
+
is_final=True,
|
| 188 |
+
cohort=cohort,
|
| 189 |
+
info_path=json_path,
|
| 190 |
+
is_gene_available=is_gene_available,
|
| 191 |
+
is_trait_available=is_trait_available,
|
| 192 |
+
is_biased=is_trait_biased,
|
| 193 |
+
df=unbiased_linked_data,
|
| 194 |
+
note=note
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
# 6. If the linked data is usable, save it to 'out_data_file'.
|
| 198 |
+
if is_usable:
|
| 199 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 200 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/code/TCGA.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_Endocrine_Neoplasia_Type_2"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z4/preprocess/Multiple_Endocrine_Neoplasia_Type_2/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z4/preprocess/Multiple_Endocrine_Neoplasia_Type_2/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z4/preprocess/Multiple_Endocrine_Neoplasia_Type_2/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z4/preprocess/Multiple_Endocrine_Neoplasia_Type_2/cohort_info.json"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Step 1: Initial Data Loading
|
| 18 |
+
import os
|
| 19 |
+
import pandas as pd
|
| 20 |
+
|
| 21 |
+
# Step 1: Select the most relevant TCGA cohort directory for Multiple Endocrine Neoplasia Type 2 (MEN2)
|
| 22 |
+
# MEN2 commonly presents with pheochromocytoma/paraganglioma; thus PCPG is the most specific match.
|
| 23 |
+
subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 24 |
+
selected_dir = None
|
| 25 |
+
priority_keywords = [
|
| 26 |
+
"pheochromocytoma_paraganglioma", # PCPG
|
| 27 |
+
"pcpg",
|
| 28 |
+
"thyroid_cancer", # secondary relevance (MTC is rare in TCGA THCA)
|
| 29 |
+
"(thca)",
|
| 30 |
+
"thyroid"
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
lower_subdirs = {d.lower(): d for d in subdirs}
|
| 34 |
+
for kw in priority_keywords:
|
| 35 |
+
for d_lower, d_orig in lower_subdirs.items():
|
| 36 |
+
if kw in d_lower:
|
| 37 |
+
selected_dir = d_orig
|
| 38 |
+
break
|
| 39 |
+
if selected_dir:
|
| 40 |
+
break
|
| 41 |
+
|
| 42 |
+
if selected_dir is None:
|
| 43 |
+
# No suitable directory found; record and stop
|
| 44 |
+
_ = validate_and_save_cohort_info(
|
| 45 |
+
is_final=False,
|
| 46 |
+
cohort="TCGA",
|
| 47 |
+
info_path=json_path,
|
| 48 |
+
is_gene_available=False,
|
| 49 |
+
is_trait_available=False
|
| 50 |
+
)
|
| 51 |
+
else:
|
| 52 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 53 |
+
|
| 54 |
+
# Step 2: Identify clinical and genetic data file paths
|
| 55 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
| 56 |
+
|
| 57 |
+
# Step 3: Load both files
|
| 58 |
+
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False)
|
| 59 |
+
genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False)
|
| 60 |
+
|
| 61 |
+
# Step 4: Print clinical column names
|
| 62 |
+
print(list(clinical_df.columns))
|
| 63 |
+
|
| 64 |
+
# Step 2: Find Candidate Demographic Features
|
| 65 |
+
import os
|
| 66 |
+
import pandas as pd
|
| 67 |
+
|
| 68 |
+
# Provided column names from previous step
|
| 69 |
+
column_names = ['_INTEGRATION', '_PATIENT', '_cohort', '_primary_disease', '_primary_site', 'age_at_initial_pathologic_diagnosis', 'bcr_followup_barcode', 'bcr_patient_barcode', 'bcr_sample_barcode', 'ct_scan', 'days_to_birth', 'days_to_collection', 'days_to_death', 'days_to_initial_pathologic_diagnosis', 'days_to_last_followup', 'days_to_new_tumor_event_after_initial_treatment', 'disease_detected_on_screening', 'eastern_cancer_oncology_group', 'form_completion_date', 'gender', 'histological_type', 'history_of_neoadjuvant_treatment', 'history_pheo_or_para_anatomic_site', 'history_pheo_or_para_include_benign', 'icd_10', 'icd_o_3_histology', 'icd_o_3_site', 'informed_consent_verified', 'initial_weight', 'is_ffpe', 'karnofsky_performance_score', 'laterality', 'lost_follow_up', 'lymph_node_examined_count', 'new_neoplasm_confirmed_diagnosis_method_name', 'new_neoplasm_event_occurrence_anatomic_site', 'new_neoplasm_event_type', 'new_neoplasm_occurrence_anatomic_site_text', 'new_tumor_event_after_initial_treatment', 'number_of_lymphnodes_positive_by_he', 'oct_embedded', 'other_dx', 'outside_adrenal', 'pathology_report_file_name', 'patient_id', 'performance_status_scale_timing', 'person_neoplasm_cancer_status', 'postoperative_rx_tx', 'primary_lymph_node_presentation_assessment', 'primary_therapy_outcome_success', 'radiation_therapy', 'sample_type', 'sample_type_id', 'tissue_prospective_collection_indicator', 'tissue_retrospective_collection_indicator', 'tissue_source_site', 'tumor_tissue_site', 'tumor_tissue_site_other', 'vial_number', 'vital_status', 'year_of_initial_pathologic_diagnosis', '_GENOMIC_ID_TCGA_PCPG_exp_HiSeqV2_PANCAN', '_GENOMIC_ID_TCGA_PCPG_mutation_bcm_gene', '_GENOMIC_ID_TCGA_PCPG_mutation_broad_gene', '_GENOMIC_ID_TCGA_PCPG_hMethyl450', '_GENOMIC_ID_TCGA_PCPG_gistic2thd', '_GENOMIC_ID_TCGA_PCPG_exp_HiSeqV2', '_GENOMIC_ID_TCGA_PCPG_exp_HiSeqV2_exon', '_GENOMIC_ID_TCGA_PCPG_PDMRNAseqCNV', '_GENOMIC_ID_TCGA_PCPG_miRNA_HiSeq', '_GENOMIC_ID_data/public/TCGA/PCPG/miRNA_HiSeq_gene', '_GENOMIC_ID_TCGA_PCPG_mutation_bcgsc_gene', '_GENOMIC_ID_TCGA_PCPG_RPPA', '_GENOMIC_ID_TCGA_PCPG_mutation_ucsc_maf_gene', '_GENOMIC_ID_TCGA_PCPG_gistic2', '_GENOMIC_ID_TCGA_PCPG_PDMRNAseq', '_GENOMIC_ID_TCGA_PCPG_exp_HiSeqV2_percentile']
|
| 70 |
+
|
| 71 |
+
# Identify candidate columns
|
| 72 |
+
lower_cols = [c.lower() for c in column_names]
|
| 73 |
+
candidate_age_cols = [c for c in column_names if 'age' in c.lower() or 'birth' in c.lower()]
|
| 74 |
+
candidate_gender_cols = [c for c in column_names if 'gender' in c.lower() or 'sex' in c.lower()]
|
| 75 |
+
|
| 76 |
+
# Strictly required formatted output
|
| 77 |
+
print(f"candidate_age_cols = {candidate_age_cols}")
|
| 78 |
+
print(f"candidate_gender_cols = {candidate_gender_cols}")
|
| 79 |
+
|
| 80 |
+
# Try to obtain clinical_df; if not present, load from TCGA PCPG cohort
|
| 81 |
+
clinical_df = globals().get('clinical_df', None)
|
| 82 |
+
if clinical_df is None:
|
| 83 |
+
try:
|
| 84 |
+
# Prefer PCPG if available
|
| 85 |
+
cohorts = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 86 |
+
if 'PCPG' in cohorts:
|
| 87 |
+
cohort_dir = os.path.join(tcga_root_dir, 'PCPG')
|
| 88 |
+
else:
|
| 89 |
+
# Fallback to any cohort directory
|
| 90 |
+
cohort_dir = os.path.join(tcga_root_dir, cohorts[0]) if cohorts else None
|
| 91 |
+
|
| 92 |
+
if cohort_dir:
|
| 93 |
+
clinical_file_path, _ = tcga_get_relevant_filepaths(cohort_dir)
|
| 94 |
+
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, dtype=str)
|
| 95 |
+
except Exception:
|
| 96 |
+
clinical_df = None
|
| 97 |
+
|
| 98 |
+
# Preview extracted candidate columns if clinical_df is available
|
| 99 |
+
if clinical_df is not None:
|
| 100 |
+
age_cols_existing = [c for c in candidate_age_cols if c in clinical_df.columns]
|
| 101 |
+
gender_cols_existing = [c for c in candidate_gender_cols if c in clinical_df.columns]
|
| 102 |
+
|
| 103 |
+
if age_cols_existing:
|
| 104 |
+
age_preview = preview_df(clinical_df[age_cols_existing], n=5)
|
| 105 |
+
print(age_preview)
|
| 106 |
+
else:
|
| 107 |
+
print({})
|
| 108 |
+
|
| 109 |
+
if gender_cols_existing:
|
| 110 |
+
gender_preview = preview_df(clinical_df[gender_cols_existing], n=5)
|
| 111 |
+
print(gender_preview)
|
| 112 |
+
else:
|
| 113 |
+
print({})
|
| 114 |
+
else:
|
| 115 |
+
# If clinical data cannot be loaded, print empty previews to keep output predictable
|
| 116 |
+
print({})
|
| 117 |
+
print({})
|
| 118 |
+
|
| 119 |
+
# Step 3: Select Demographic Features
|
| 120 |
+
# Deterministic selection of demographic columns based on candidate lists
|
| 121 |
+
|
| 122 |
+
# Safely access candidate lists
|
| 123 |
+
try:
|
| 124 |
+
_candidate_age_cols = candidate_age_cols if isinstance(candidate_age_cols, list) else []
|
| 125 |
+
except NameError:
|
| 126 |
+
_candidate_age_cols = []
|
| 127 |
+
try:
|
| 128 |
+
_candidate_gender_cols = candidate_gender_cols if isinstance(candidate_gender_cols, list) else []
|
| 129 |
+
except NameError:
|
| 130 |
+
_candidate_gender_cols = []
|
| 131 |
+
|
| 132 |
+
age_col = None
|
| 133 |
+
gender_col = None
|
| 134 |
+
|
| 135 |
+
# Prefer direct age field; fall back to days_to_birth if needed
|
| 136 |
+
preferred_age_order = [
|
| 137 |
+
"age_at_initial_pathologic_diagnosis",
|
| 138 |
+
"age",
|
| 139 |
+
"age_at_diagnosis",
|
| 140 |
+
"years_to_birth",
|
| 141 |
+
"days_to_birth",
|
| 142 |
+
]
|
| 143 |
+
for c in preferred_age_order:
|
| 144 |
+
if c in _candidate_age_cols:
|
| 145 |
+
age_col = c
|
| 146 |
+
break
|
| 147 |
+
|
| 148 |
+
# Prefer 'gender', then 'sex'
|
| 149 |
+
preferred_gender_order = ["gender", "sex"]
|
| 150 |
+
for c in preferred_gender_order:
|
| 151 |
+
if c in _candidate_gender_cols:
|
| 152 |
+
gender_col = c
|
| 153 |
+
break
|
| 154 |
+
|
| 155 |
+
print(f"Selected age_col: {age_col}")
|
| 156 |
+
print(f"Selected gender_col: {gender_col}")
|
| 157 |
+
|
| 158 |
+
# Step 4: Feature Engineering and Validation
|
| 159 |
+
import os
|
| 160 |
+
|
| 161 |
+
# 1) Extract and standardize clinical features (trait, optional age, gender)
|
| 162 |
+
selected_clinical_df = tcga_select_clinical_features(
|
| 163 |
+
clinical_df=clinical_df,
|
| 164 |
+
trait=trait,
|
| 165 |
+
age_col=age_col,
|
| 166 |
+
gender_col=gender_col
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
# 2) Normalize gene symbols and save normalized gene expression data
|
| 170 |
+
gene_df_norm = normalize_gene_symbols_in_index(genetic_df.copy())
|
| 171 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 172 |
+
gene_df_norm.to_csv(out_gene_data_file)
|
| 173 |
+
|
| 174 |
+
# 3) Link clinical and genetic data on sample IDs
|
| 175 |
+
common_samples = selected_clinical_df.index.intersection(gene_df_norm.columns)
|
| 176 |
+
linked_data = pd.concat(
|
| 177 |
+
[
|
| 178 |
+
selected_clinical_df.loc[common_samples],
|
| 179 |
+
gene_df_norm.loc[:, common_samples].T
|
| 180 |
+
],
|
| 181 |
+
axis=1
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
# 4) Handle missing values in the linked data
|
| 185 |
+
processed_df = handle_missing_values(linked_data, trait_col=trait)
|
| 186 |
+
|
| 187 |
+
# 5) Determine whether trait/demographics are severely biased; drop biased demographics
|
| 188 |
+
is_biased, processed_df = judge_and_remove_biased_features(processed_df, trait=trait)
|
| 189 |
+
|
| 190 |
+
# 6) Final validation and save cohort info
|
| 191 |
+
is_gene_available = gene_df_norm.shape[0] > 0
|
| 192 |
+
is_trait_available = not selected_clinical_df[trait].isna().all()
|
| 193 |
+
note = "INFO: TCGA-PCPG cohort selected for MEN2-related phenotype due to strong association with pheochromocytoma/paraganglioma."
|
| 194 |
+
|
| 195 |
+
is_usable = validate_and_save_cohort_info(
|
| 196 |
+
is_final=True,
|
| 197 |
+
cohort="TCGA",
|
| 198 |
+
info_path=json_path,
|
| 199 |
+
is_gene_available=is_gene_available,
|
| 200 |
+
is_trait_available=is_trait_available,
|
| 201 |
+
is_biased=is_biased,
|
| 202 |
+
df=processed_df,
|
| 203 |
+
note=note
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
# 7) Save linked data only if usable
|
| 207 |
+
if is_usable:
|
| 208 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 209 |
+
processed_df.to_csv(out_data_file)
|
output/preprocess/Multiple_Endocrine_Neoplasia_Type_2/cohort_info.json
CHANGED
|
@@ -1,22 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"GSE19987": {
|
| 3 |
-
"is_usable": false,
|
| 4 |
-
"is_gene_available": false,
|
| 5 |
-
"is_trait_available": false,
|
| 6 |
-
"is_available": false,
|
| 7 |
-
"is_biased": null,
|
| 8 |
-
"has_age": null,
|
| 9 |
-
"has_gender": null,
|
| 10 |
-
"sample_size": null
|
| 11 |
-
},
|
| 12 |
-
"TCGA": {
|
| 13 |
-
"is_usable": false,
|
| 14 |
-
"is_gene_available": false,
|
| 15 |
-
"is_trait_available": false,
|
| 16 |
-
"is_available": false,
|
| 17 |
-
"is_biased": null,
|
| 18 |
-
"has_age": null,
|
| 19 |
-
"has_gender": null,
|
| 20 |
-
"sample_size": null
|
| 21 |
-
}
|
| 22 |
-
}
|
|
|
|
| 1 |
+
{"GSE19987": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 75, "note": "INFO: Trait inferred from 'genetic class' (MEN2 vs others); Age/Gender not provided in series matrix."}, "TCGA": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": true, "has_gender": true, "sample_size": 187, "note": "INFO: TCGA-PCPG cohort selected for MEN2-related phenotype due to strong association with pheochromocytoma/paraganglioma."}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output/preprocess/Multiple_sclerosis/clinical_data/GSE131282.csv
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
,GSM3768507,GSM3768508,GSM3768509,GSM3768510,GSM3768511,GSM3768512,GSM3768513,GSM3768514,GSM3768515,GSM3768516,GSM3768517,GSM3768518,GSM3768519,GSM3768520,GSM3768521,GSM3768522,GSM3768523,GSM3768524,GSM3768525,GSM3768526,GSM3768527,GSM3768528,GSM3768529,GSM3768530,GSM3768531,GSM3768532,GSM3768533,GSM3768534,GSM3768535,GSM3768536,GSM3768537,GSM3768538,GSM3768539,GSM3768540,GSM3768541,GSM3768542,GSM3768543,GSM3768544,GSM3768545,GSM3768546,GSM3768547,GSM3768548,GSM3768549,GSM3768550,GSM3768551,GSM3768552,GSM3768553,GSM3768554,GSM3768555,GSM3768556,GSM3768557,GSM3768558,GSM3768559,GSM3768560,GSM3768561,GSM3768562,GSM3768563,GSM3768564,GSM3768565,GSM3768566,GSM3768567,GSM3768568,GSM3768569,GSM3768570,GSM3768571,GSM3768572,GSM3768573,GSM3768574,GSM3768575,GSM3768576,GSM3768577,GSM3768578,GSM3768579,GSM3768580,GSM3768581,GSM3768582,GSM3768583,GSM3768584,GSM3768613,GSM3768614,GSM3768616,GSM3768617,GSM3768619,GSM3768620,GSM3768621,GSM3768623,GSM3768624,GSM3768625,GSM3768626,GSM3768627,GSM3768628,GSM3768629,GSM3768630,GSM3768631,GSM3768632,GSM3768633,GSM3768634,GSM3768635,GSM3768636,GSM3768637,GSM3768638,GSM3768639,GSM3768640,GSM3768641,GSM3768642,GSM3768643,GSM3768644,GSM3768645,GSM3768646,GSM3768647,GSM3768648,GSM3768649,GSM3768650,GSM3768651,GSM3768652,GSM3768653,GSM3768654,GSM3768655,GSM3768656,GSM3768657,GSM3768658,GSM3768659,GSM3768660,GSM3768661,GSM3768662,GSM3768663,GSM3768664,GSM3768665,GSM3768666,GSM3768667,GSM3768668,GSM3768669,GSM3768670,GSM3768671,GSM3768672,GSM3768673,GSM3768674,GSM3768675,GSM3768676,GSM3768677,GSM3768678,GSM3768679,GSM3768680,GSM3768681,GSM3768682,GSM3768683,GSM3768684,GSM3768685,GSM3768686,GSM3768687,GSM3768688,GSM3768689,GSM3768690,GSM3768691,GSM3768692,GSM3768693,GSM3768694,GSM3768695,GSM3768696,GSM3768697,GSM3768698,GSM3768699,GSM3768700,GSM3768701,GSM3768702,GSM3768703,GSM3768704,GSM3768705,GSM3768706,GSM3768707,GSM3768708,GSM3768709,GSM3768710,GSM3768711,GSM3768712,GSM3768713,GSM3768714,GSM3768715,GSM3768716,GSM3768717,GSM3768718,GSM3768719,GSM3768720,GSM3768721
|
| 2 |
-
Multiple_sclerosis,1.0,
|
| 3 |
Age,58.0,59.0,80.0,63.0,47.0,78.0,59.0,88.0,45.0,45.0,61.0,50.0,54.0,78.0,80.0,61.0,45.0,69.0,39.0,58.0,78.0,56.0,44.0,58.0,78.0,58.0,58.0,80.0,58.0,56.0,78.0,42.0,58.0,58.0,50.0,78.0,92.0,54.0,71.0,58.0,39.0,78.0,78.0,56.0,58.0,54.0,45.0,59.0,45.0,77.0,78.0,56.0,44.0,58.0,78.0,34.0,58.0,63.0,78.0,78.0,58.0,92.0,58.0,69.0,58.0,49.0,47.0,78.0,45.0,58.0,70.0,56.0,58.0,71.0,45.0,78.0,78.0,49.0,58.0,92.0,56.0,35.0,80.0,56.0,84.0,75.0,38.0,59.0,77.0,58.0,78.0,64.0,56.0,95.0,60.0,78.0,75.0,58.0,78.0,75.0,51.0,56.0,64.0,77.0,58.0,78.0,60.0,39.0,47.0,87.0,75.0,88.0,64.0,75.0,35.0,58.0,39.0,56.0,61.0,78.0,84.0,73.0,59.0,75.0,47.0,78.0,77.0,39.0,60.0,77.0,49.0,89.0,75.0,58.0,58.0,84.0,70.0,47.0,77.0,58.0,56.0,60.0,75.0,58.0,88.0,92.0,45.0,59.0,84.0,78.0,84.0,60.0,75.0,58.0,58.0,49.0,51.0,58.0,78.0,77.0,35.0,84.0,49.0,75.0,75.0,61.0,75.0,78.0,47.0,58.0,39.0,78.0,77.0,87.0,35.0,45.0,84.0,70.0,58.0,73.0,45.0,78.0,64.0,58.0
|
| 4 |
Gender,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.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,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0
|
|
|
|
| 1 |
,GSM3768507,GSM3768508,GSM3768509,GSM3768510,GSM3768511,GSM3768512,GSM3768513,GSM3768514,GSM3768515,GSM3768516,GSM3768517,GSM3768518,GSM3768519,GSM3768520,GSM3768521,GSM3768522,GSM3768523,GSM3768524,GSM3768525,GSM3768526,GSM3768527,GSM3768528,GSM3768529,GSM3768530,GSM3768531,GSM3768532,GSM3768533,GSM3768534,GSM3768535,GSM3768536,GSM3768537,GSM3768538,GSM3768539,GSM3768540,GSM3768541,GSM3768542,GSM3768543,GSM3768544,GSM3768545,GSM3768546,GSM3768547,GSM3768548,GSM3768549,GSM3768550,GSM3768551,GSM3768552,GSM3768553,GSM3768554,GSM3768555,GSM3768556,GSM3768557,GSM3768558,GSM3768559,GSM3768560,GSM3768561,GSM3768562,GSM3768563,GSM3768564,GSM3768565,GSM3768566,GSM3768567,GSM3768568,GSM3768569,GSM3768570,GSM3768571,GSM3768572,GSM3768573,GSM3768574,GSM3768575,GSM3768576,GSM3768577,GSM3768578,GSM3768579,GSM3768580,GSM3768581,GSM3768582,GSM3768583,GSM3768584,GSM3768613,GSM3768614,GSM3768616,GSM3768617,GSM3768619,GSM3768620,GSM3768621,GSM3768623,GSM3768624,GSM3768625,GSM3768626,GSM3768627,GSM3768628,GSM3768629,GSM3768630,GSM3768631,GSM3768632,GSM3768633,GSM3768634,GSM3768635,GSM3768636,GSM3768637,GSM3768638,GSM3768639,GSM3768640,GSM3768641,GSM3768642,GSM3768643,GSM3768644,GSM3768645,GSM3768646,GSM3768647,GSM3768648,GSM3768649,GSM3768650,GSM3768651,GSM3768652,GSM3768653,GSM3768654,GSM3768655,GSM3768656,GSM3768657,GSM3768658,GSM3768659,GSM3768660,GSM3768661,GSM3768662,GSM3768663,GSM3768664,GSM3768665,GSM3768666,GSM3768667,GSM3768668,GSM3768669,GSM3768670,GSM3768671,GSM3768672,GSM3768673,GSM3768674,GSM3768675,GSM3768676,GSM3768677,GSM3768678,GSM3768679,GSM3768680,GSM3768681,GSM3768682,GSM3768683,GSM3768684,GSM3768685,GSM3768686,GSM3768687,GSM3768688,GSM3768689,GSM3768690,GSM3768691,GSM3768692,GSM3768693,GSM3768694,GSM3768695,GSM3768696,GSM3768697,GSM3768698,GSM3768699,GSM3768700,GSM3768701,GSM3768702,GSM3768703,GSM3768704,GSM3768705,GSM3768706,GSM3768707,GSM3768708,GSM3768709,GSM3768710,GSM3768711,GSM3768712,GSM3768713,GSM3768714,GSM3768715,GSM3768716,GSM3768717,GSM3768718,GSM3768719,GSM3768720,GSM3768721
|
| 2 |
+
Multiple_sclerosis,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,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,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0
|
| 3 |
Age,58.0,59.0,80.0,63.0,47.0,78.0,59.0,88.0,45.0,45.0,61.0,50.0,54.0,78.0,80.0,61.0,45.0,69.0,39.0,58.0,78.0,56.0,44.0,58.0,78.0,58.0,58.0,80.0,58.0,56.0,78.0,42.0,58.0,58.0,50.0,78.0,92.0,54.0,71.0,58.0,39.0,78.0,78.0,56.0,58.0,54.0,45.0,59.0,45.0,77.0,78.0,56.0,44.0,58.0,78.0,34.0,58.0,63.0,78.0,78.0,58.0,92.0,58.0,69.0,58.0,49.0,47.0,78.0,45.0,58.0,70.0,56.0,58.0,71.0,45.0,78.0,78.0,49.0,58.0,92.0,56.0,35.0,80.0,56.0,84.0,75.0,38.0,59.0,77.0,58.0,78.0,64.0,56.0,95.0,60.0,78.0,75.0,58.0,78.0,75.0,51.0,56.0,64.0,77.0,58.0,78.0,60.0,39.0,47.0,87.0,75.0,88.0,64.0,75.0,35.0,58.0,39.0,56.0,61.0,78.0,84.0,73.0,59.0,75.0,47.0,78.0,77.0,39.0,60.0,77.0,49.0,89.0,75.0,58.0,58.0,84.0,70.0,47.0,77.0,58.0,56.0,60.0,75.0,58.0,88.0,92.0,45.0,59.0,84.0,78.0,84.0,60.0,75.0,58.0,58.0,49.0,51.0,58.0,78.0,77.0,35.0,84.0,49.0,75.0,75.0,61.0,75.0,78.0,47.0,58.0,39.0,78.0,77.0,87.0,35.0,45.0,84.0,70.0,58.0,73.0,45.0,78.0,64.0,58.0
|
| 4 |
Gender,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.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,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0
|
output/preprocess/Multiple_sclerosis/code/GSE131279.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE131279"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE131279"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE131279.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE131279.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE131279.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# Step 1: Determine gene expression data availability
|
| 40 |
+
is_gene_available = True # Based on series summary indicating differential gene expression analysis (not miRNA/methylation)
|
| 41 |
+
|
| 42 |
+
# Step 2: Variable availability and conversion functions
|
| 43 |
+
|
| 44 |
+
# Trait (Multiple_sclerosis): All samples are MS cases (no controls), thus not available for association
|
| 45 |
+
trait_row = None
|
| 46 |
+
|
| 47 |
+
# Age: Available at key 2 ("age at death")
|
| 48 |
+
age_row = 2
|
| 49 |
+
|
| 50 |
+
# Gender: Available at key 1 ("Sex")
|
| 51 |
+
gender_row = 1
|
| 52 |
+
|
| 53 |
+
# Conversion functions
|
| 54 |
+
def convert_trait(x: str):
|
| 55 |
+
# Not used because trait_row is None
|
| 56 |
+
return None
|
| 57 |
+
|
| 58 |
+
def convert_age(x: str):
|
| 59 |
+
# Expect formats like "age at death: 58"
|
| 60 |
+
if x is None:
|
| 61 |
+
return None
|
| 62 |
+
try:
|
| 63 |
+
val = x.split(":", 1)[1].strip()
|
| 64 |
+
except Exception:
|
| 65 |
+
val = str(x).strip()
|
| 66 |
+
if val in {"?", "", "NA", "N/A", "nan", "None"}:
|
| 67 |
+
return None
|
| 68 |
+
# Remove possible units or stray characters and convert to float
|
| 69 |
+
try:
|
| 70 |
+
return float(''.join(ch for ch in val if (ch.isdigit() or ch == ".")))
|
| 71 |
+
except Exception:
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
+
def convert_gender(x: str):
|
| 75 |
+
# Expect formats like "Sex: F" or "Sex: M"
|
| 76 |
+
if x is None:
|
| 77 |
+
return None
|
| 78 |
+
try:
|
| 79 |
+
val = x.split(":", 1)[1].strip().lower()
|
| 80 |
+
except Exception:
|
| 81 |
+
val = str(x).strip().lower()
|
| 82 |
+
if val in {"f", "female"}:
|
| 83 |
+
return 0
|
| 84 |
+
if val in {"m", "male"}:
|
| 85 |
+
return 1
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
+
# Step 3: Save initial metadata
|
| 89 |
+
is_trait_available = trait_row is not None
|
| 90 |
+
_ = validate_and_save_cohort_info(
|
| 91 |
+
is_final=False,
|
| 92 |
+
cohort=cohort,
|
| 93 |
+
info_path=json_path,
|
| 94 |
+
is_gene_available=is_gene_available,
|
| 95 |
+
is_trait_available=is_trait_available
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
# Step 4: Clinical feature extraction (skip because trait_row is None)
|
| 99 |
+
if trait_row is not None:
|
| 100 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 101 |
+
clinical_df=clinical_data,
|
| 102 |
+
trait=trait,
|
| 103 |
+
trait_row=trait_row,
|
| 104 |
+
convert_trait=convert_trait,
|
| 105 |
+
age_row=age_row,
|
| 106 |
+
convert_age=convert_age,
|
| 107 |
+
gender_row=gender_row,
|
| 108 |
+
convert_gender=convert_gender
|
| 109 |
+
)
|
| 110 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 111 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 112 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
| 113 |
+
|
| 114 |
+
# Step 3: Gene Data Extraction
|
| 115 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 116 |
+
gene_data = get_genetic_data(matrix_file)
|
| 117 |
+
|
| 118 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 119 |
+
print(gene_data.index[:20])
|
| 120 |
+
|
| 121 |
+
# Step 4: Gene Identifier Review
|
| 122 |
+
print("requires_gene_mapping = True")
|
| 123 |
+
|
| 124 |
+
# Step 5: Gene Annotation
|
| 125 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 126 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 127 |
+
|
| 128 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 129 |
+
print("Gene annotation preview:")
|
| 130 |
+
print(preview_df(gene_annotation))
|
| 131 |
+
|
| 132 |
+
# Step 6: Gene Identifier Mapping
|
| 133 |
+
# Determine appropriate columns for probe ID and gene symbol based on annotation preview:
|
| 134 |
+
# Probe identifiers: 'ID' (e.g., ILMN_1343048)
|
| 135 |
+
# Gene symbols: 'Symbol'
|
| 136 |
+
|
| 137 |
+
# 1-2. Build mapping dataframe from annotation
|
| 138 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol')
|
| 139 |
+
|
| 140 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 141 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
| 142 |
+
|
| 143 |
+
# Step 7: Data Normalization and Linking
|
| 144 |
+
import os
|
| 145 |
+
|
| 146 |
+
# 1. Normalize gene symbols and save gene expression data
|
| 147 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 148 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 149 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 150 |
+
|
| 151 |
+
# 2-6. Handle linking and validation depending on trait availability
|
| 152 |
+
if ('trait_row' in globals()) and (trait_row is not None) and ('selected_clinical_data' in globals()):
|
| 153 |
+
# Link clinical and genetic data
|
| 154 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 155 |
+
|
| 156 |
+
# Handle missing values
|
| 157 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 158 |
+
|
| 159 |
+
# Bias evaluation and potential covariate removal
|
| 160 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 161 |
+
|
| 162 |
+
# Final validation and metadata saving
|
| 163 |
+
is_usable = validate_and_save_cohort_info(
|
| 164 |
+
True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
# Save linked data only if usable
|
| 168 |
+
if is_usable:
|
| 169 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 170 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 171 |
+
else:
|
| 172 |
+
# Trait not available; skip linking and mark as not available in final validation
|
| 173 |
+
note = "WARNING: Trait not available (all samples are MS cases); no linked data saved."
|
| 174 |
+
df_placeholder = normalized_gene_data.T
|
| 175 |
+
_ = validate_and_save_cohort_info(
|
| 176 |
+
True, cohort, json_path, True, False, False, df_placeholder, note
|
| 177 |
+
)
|
output/preprocess/Multiple_sclerosis/code/GSE131281.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE131281"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE131281"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE131281.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE131281.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE131281.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
import pandas as pd
|
| 42 |
+
|
| 43 |
+
# 1) Gene expression availability
|
| 44 |
+
is_gene_available = True # Series describes differential gene expression analysis (not miRNA-only or methylation-only)
|
| 45 |
+
|
| 46 |
+
# 2) Identify rows for variables based on the provided dictionary
|
| 47 |
+
trait_row = 5 # 'ms type' -> can infer MS case/control
|
| 48 |
+
age_row = 2 # 'age at death'
|
| 49 |
+
gender_row = 1 # 'Sex'
|
| 50 |
+
|
| 51 |
+
# 2.2) Converters
|
| 52 |
+
def _extract_after_colon(x: str) -> str:
|
| 53 |
+
if x is None or (isinstance(x, float) and pd.isna(x)):
|
| 54 |
+
return ''
|
| 55 |
+
s = str(x).strip()
|
| 56 |
+
if ':' in s:
|
| 57 |
+
return s.split(':', 1)[1].strip()
|
| 58 |
+
return s.strip()
|
| 59 |
+
|
| 60 |
+
def convert_trait(x):
|
| 61 |
+
val = _extract_after_colon(x).strip()
|
| 62 |
+
if not val:
|
| 63 |
+
return None
|
| 64 |
+
v_up = val.upper()
|
| 65 |
+
# MS case types
|
| 66 |
+
ms_types = {'MS', 'SPMS', 'PPMS', 'PRMS', 'RRMS'}
|
| 67 |
+
if v_up in ms_types:
|
| 68 |
+
return 1
|
| 69 |
+
# Controls likely annotated as '?' for ms type
|
| 70 |
+
if v_up in {'?', 'CONTROL', 'CTL', 'NA', 'N/A', 'NONE'}:
|
| 71 |
+
return 0
|
| 72 |
+
# Fallback: if string contains 'MS' but not a known control marker, treat as case
|
| 73 |
+
if 'MS' in v_up:
|
| 74 |
+
return 1
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
+
def convert_age(x):
|
| 78 |
+
val = _extract_after_colon(x)
|
| 79 |
+
# extract the first number
|
| 80 |
+
m = re.search(r'[-+]?\d*\.?\d+', val)
|
| 81 |
+
if not m:
|
| 82 |
+
return None
|
| 83 |
+
try:
|
| 84 |
+
num = float(m.group())
|
| 85 |
+
return num
|
| 86 |
+
except Exception:
|
| 87 |
+
return None
|
| 88 |
+
|
| 89 |
+
def convert_gender(x):
|
| 90 |
+
val = _extract_after_colon(x).strip().lower()
|
| 91 |
+
if val in {'f', 'female'}:
|
| 92 |
+
return 0
|
| 93 |
+
if val in {'m', 'male'}:
|
| 94 |
+
return 1
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
# 3) Save initial metadata
|
| 98 |
+
is_trait_available = trait_row is not None
|
| 99 |
+
_ = validate_and_save_cohort_info(
|
| 100 |
+
is_final=False,
|
| 101 |
+
cohort=cohort,
|
| 102 |
+
info_path=json_path,
|
| 103 |
+
is_gene_available=is_gene_available,
|
| 104 |
+
is_trait_available=is_trait_available
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# 4) Clinical feature extraction
|
| 108 |
+
if trait_row is not None:
|
| 109 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 110 |
+
clinical_df=clinical_data,
|
| 111 |
+
trait=trait,
|
| 112 |
+
trait_row=trait_row,
|
| 113 |
+
convert_trait=convert_trait,
|
| 114 |
+
age_row=age_row,
|
| 115 |
+
convert_age=convert_age,
|
| 116 |
+
gender_row=gender_row,
|
| 117 |
+
convert_gender=convert_gender
|
| 118 |
+
)
|
| 119 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 120 |
+
|
| 121 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 122 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 123 |
+
|
| 124 |
+
# Step 3: Gene Data Extraction
|
| 125 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 126 |
+
gene_data = get_genetic_data(matrix_file)
|
| 127 |
+
|
| 128 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 129 |
+
print(gene_data.index[:20])
|
| 130 |
+
|
| 131 |
+
# Step 4: Gene Identifier Review
|
| 132 |
+
print("requires_gene_mapping = True")
|
| 133 |
+
|
| 134 |
+
# Step 5: Gene Annotation
|
| 135 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 136 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 137 |
+
|
| 138 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 139 |
+
print("Gene annotation preview:")
|
| 140 |
+
print(preview_df(gene_annotation))
|
| 141 |
+
|
| 142 |
+
# Step 6: Gene Identifier Mapping
|
| 143 |
+
# 1. Decide the appropriate columns for mapping based on annotation preview:
|
| 144 |
+
# - Probe/ID column: 'ID' (matches ILMN_* probe IDs)
|
| 145 |
+
# - Gene symbol column: 'Symbol'
|
| 146 |
+
probe_col = 'ID'
|
| 147 |
+
symbol_col = 'Symbol'
|
| 148 |
+
|
| 149 |
+
# 2. Build the mapping dataframe from annotation
|
| 150 |
+
gene_mapping = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=symbol_col)
|
| 151 |
+
|
| 152 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 153 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=gene_mapping)
|
| 154 |
+
|
| 155 |
+
# Step 7: Data Normalization and Linking
|
| 156 |
+
import os
|
| 157 |
+
import pandas as pd
|
| 158 |
+
|
| 159 |
+
# Ensure clinical features are available as a DataFrame
|
| 160 |
+
try:
|
| 161 |
+
selected_clinical_df
|
| 162 |
+
except NameError:
|
| 163 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 164 |
+
|
| 165 |
+
# 1) Normalize gene symbols and save
|
| 166 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 167 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 168 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 169 |
+
|
| 170 |
+
# 2) Link clinical and genetic data
|
| 171 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 172 |
+
|
| 173 |
+
# 3) Handle missing values
|
| 174 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 175 |
+
|
| 176 |
+
# 4) Bias assessment and removal of biased demographic features
|
| 177 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 178 |
+
|
| 179 |
+
# 5) Final validation and save cohort info
|
| 180 |
+
note = ("INFO: Probe-to-gene mapping via SOFT 'Symbol' with equal split for multi-gene probes; "
|
| 181 |
+
"gene symbols normalized using NCBI synonym table; trait from 'ms type', age from 'age at death', gender from 'Sex'.")
|
| 182 |
+
is_usable = validate_and_save_cohort_info(
|
| 183 |
+
is_final=True,
|
| 184 |
+
cohort=cohort,
|
| 185 |
+
info_path=json_path,
|
| 186 |
+
is_gene_available=True,
|
| 187 |
+
is_trait_available=True,
|
| 188 |
+
is_biased=is_trait_biased,
|
| 189 |
+
df=unbiased_linked_data,
|
| 190 |
+
note=note
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
# 6) Save linked data if usable
|
| 194 |
+
if is_usable:
|
| 195 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 196 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Multiple_sclerosis/code/GSE131282.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE131282"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE131282"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE131282.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE131282.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE131282.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
|
| 41 |
+
# 1. Gene Expression Data Availability
|
| 42 |
+
# Presence of RIN and cortical tissue suggests mRNA expression profiling is available.
|
| 43 |
+
is_gene_available = True
|
| 44 |
+
|
| 45 |
+
# 2. Variable Availability and Data Type Conversion
|
| 46 |
+
|
| 47 |
+
# Identify rows for variables based on the sample characteristics dictionary provided:
|
| 48 |
+
trait_row = 0 # patient id encodes MS (M..) vs Control (C..)
|
| 49 |
+
age_row = 2 # 'age at death'
|
| 50 |
+
gender_row = 1 # 'Sex'
|
| 51 |
+
|
| 52 |
+
def _after_colon(value):
|
| 53 |
+
if value is None:
|
| 54 |
+
return None
|
| 55 |
+
s = str(value)
|
| 56 |
+
if ':' in s:
|
| 57 |
+
s = s.split(':', 1)[1]
|
| 58 |
+
return s.strip() if s.strip() != '' else None
|
| 59 |
+
|
| 60 |
+
def convert_trait(value):
|
| 61 |
+
v = _after_colon(value)
|
| 62 |
+
if v is None:
|
| 63 |
+
return None
|
| 64 |
+
first = v.strip()[0].upper()
|
| 65 |
+
# Heuristic: IDs starting with 'M' = MS case, 'C' = control
|
| 66 |
+
if first == 'M':
|
| 67 |
+
return 1
|
| 68 |
+
if first == 'C':
|
| 69 |
+
return 0
|
| 70 |
+
return None
|
| 71 |
+
|
| 72 |
+
def convert_age(value):
|
| 73 |
+
v = _after_colon(value)
|
| 74 |
+
if v is None:
|
| 75 |
+
return None
|
| 76 |
+
m = re.search(r'[-+]?\d*\.?\d+', v)
|
| 77 |
+
if not m:
|
| 78 |
+
return None
|
| 79 |
+
try:
|
| 80 |
+
num = float(m.group())
|
| 81 |
+
return num
|
| 82 |
+
except Exception:
|
| 83 |
+
return None
|
| 84 |
+
|
| 85 |
+
def convert_gender(value):
|
| 86 |
+
v = _after_colon(value)
|
| 87 |
+
if v is None:
|
| 88 |
+
return None
|
| 89 |
+
vl = v.strip().lower()
|
| 90 |
+
if vl in {'f', 'female'}:
|
| 91 |
+
return 0
|
| 92 |
+
if vl in {'m', 'male'}:
|
| 93 |
+
return 1
|
| 94 |
+
return None
|
| 95 |
+
|
| 96 |
+
# 3. Save Metadata (initial filtering)
|
| 97 |
+
is_trait_available = trait_row is not None
|
| 98 |
+
_ = validate_and_save_cohort_info(
|
| 99 |
+
is_final=False,
|
| 100 |
+
cohort=cohort,
|
| 101 |
+
info_path=json_path,
|
| 102 |
+
is_gene_available=is_gene_available,
|
| 103 |
+
is_trait_available=is_trait_available
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# 4. Clinical Feature Extraction (only if clinical data available)
|
| 107 |
+
if trait_row is not None:
|
| 108 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 109 |
+
clinical_df=clinical_data,
|
| 110 |
+
trait=trait,
|
| 111 |
+
trait_row=trait_row,
|
| 112 |
+
convert_trait=convert_trait,
|
| 113 |
+
age_row=age_row,
|
| 114 |
+
convert_age=convert_age,
|
| 115 |
+
gender_row=gender_row,
|
| 116 |
+
convert_gender=convert_gender
|
| 117 |
+
)
|
| 118 |
+
_preview = preview_df(selected_clinical_df)
|
| 119 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 120 |
+
|
| 121 |
+
# Step 3: Gene Data Extraction
|
| 122 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 123 |
+
gene_data = get_genetic_data(matrix_file)
|
| 124 |
+
|
| 125 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 126 |
+
print(gene_data.index[:20])
|
| 127 |
+
|
| 128 |
+
# Step 4: Gene Identifier Review
|
| 129 |
+
print("requires_gene_mapping = True")
|
| 130 |
+
|
| 131 |
+
# Step 5: Gene Annotation
|
| 132 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 133 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 134 |
+
|
| 135 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 136 |
+
print("Gene annotation preview:")
|
| 137 |
+
print(preview_df(gene_annotation))
|
| 138 |
+
|
| 139 |
+
# Step 6: Gene Identifier Mapping
|
| 140 |
+
# Determine the appropriate columns for probe IDs and gene symbols based on the annotation preview
|
| 141 |
+
prob_col = 'ID' # Matches probe identifiers like 'ILMN_1343048'
|
| 142 |
+
gene_col = 'Symbol' # Contains gene symbols
|
| 143 |
+
|
| 144 |
+
# 2. Create the mapping dataframe
|
| 145 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=prob_col, gene_col=gene_col)
|
| 146 |
+
|
| 147 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 148 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 149 |
+
|
| 150 |
+
# Step 7: Data Normalization and Linking
|
| 151 |
+
# 1. Normalize the obtained gene data and save
|
| 152 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 153 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 154 |
+
|
| 155 |
+
# 2. Link the clinical and genetic data
|
| 156 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 157 |
+
|
| 158 |
+
# Derive availability flags based on linked data before filtering/imputation (cast to Python bool)
|
| 159 |
+
covariate_cols = [trait, 'Age', 'Gender']
|
| 160 |
+
gene_cols_in_linked = [c for c in linked_data.columns if c not in covariate_cols]
|
| 161 |
+
is_gene_available_final = bool(len(gene_cols_in_linked) > 0)
|
| 162 |
+
is_trait_available_final = bool((trait in linked_data.columns) and bool(linked_data[trait].notna().any()))
|
| 163 |
+
|
| 164 |
+
# 3. Handle missing values
|
| 165 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 166 |
+
|
| 167 |
+
# 4. Determine bias and remove biased demographic features
|
| 168 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 169 |
+
|
| 170 |
+
# 5. Final validation and save cohort info
|
| 171 |
+
note = ("INFO: Trait inferred from patient ID prefix (M=MS case, C=control). "
|
| 172 |
+
"Platform identifiers are Illumina probes; mapped via SOFT 'Symbol' column; "
|
| 173 |
+
"gene symbols normalized using NCBI synonyms.")
|
| 174 |
+
is_usable = validate_and_save_cohort_info(
|
| 175 |
+
is_final=True,
|
| 176 |
+
cohort=cohort,
|
| 177 |
+
info_path=json_path,
|
| 178 |
+
is_gene_available=is_gene_available_final,
|
| 179 |
+
is_trait_available=is_trait_available_final,
|
| 180 |
+
is_biased=bool(is_trait_biased),
|
| 181 |
+
df=unbiased_linked_data,
|
| 182 |
+
note=note
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
# 6. Save linked data if usable
|
| 186 |
+
if is_usable:
|
| 187 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Multiple_sclerosis/code/GSE135511.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE135511"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE135511"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE135511.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE135511.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE135511.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# 1) Gene expression data availability
|
| 40 |
+
is_gene_available = True # Based on series summary: mRNA gene expression profiling
|
| 41 |
+
|
| 42 |
+
# 2) Variable availability and conversion functions
|
| 43 |
+
# From the sample characteristics dictionary:
|
| 44 |
+
# 0: disease state: Multiple Sclerosis vs Healthy Control --> trait available
|
| 45 |
+
# No explicit age or gender fields --> not available
|
| 46 |
+
trait_row = 0
|
| 47 |
+
age_row = None
|
| 48 |
+
gender_row = None
|
| 49 |
+
|
| 50 |
+
def convert_trait(x):
|
| 51 |
+
if x is None:
|
| 52 |
+
return None
|
| 53 |
+
s = str(x)
|
| 54 |
+
# Extract value after colon, if present
|
| 55 |
+
if ':' in s:
|
| 56 |
+
s = s.split(':', 1)[1]
|
| 57 |
+
s = s.strip().lower()
|
| 58 |
+
if s in {'', 'n.a.', 'na', 'n/a', 'not available', 'unknown'}:
|
| 59 |
+
return None
|
| 60 |
+
# Map to binary: MS=1, Control=0
|
| 61 |
+
if 'multiple sclerosis' in s or s == 'ms':
|
| 62 |
+
return 1
|
| 63 |
+
if 'healthy' in s or 'control' in s:
|
| 64 |
+
return 0
|
| 65 |
+
return None
|
| 66 |
+
|
| 67 |
+
# Age and gender not available; define stubs for completeness
|
| 68 |
+
def convert_age(x):
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
def convert_gender(x):
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
+
# 3) Save metadata with initial filtering
|
| 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) Clinical feature extraction (only if trait is available)
|
| 85 |
+
if trait_row is not None:
|
| 86 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 87 |
+
clinical_df=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 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 97 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 98 |
+
|
| 99 |
+
# Step 3: Gene Data Extraction
|
| 100 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 101 |
+
gene_data = get_genetic_data(matrix_file)
|
| 102 |
+
|
| 103 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 104 |
+
print(gene_data.index[:20])
|
| 105 |
+
|
| 106 |
+
# Step 4: Gene Identifier Review
|
| 107 |
+
print("requires_gene_mapping = True")
|
| 108 |
+
|
| 109 |
+
# Step 5: Gene Annotation
|
| 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 |
+
|
| 117 |
+
# Step 6: Gene Identifier Mapping
|
| 118 |
+
# Map probe IDs to gene symbols and aggregate to gene-level expression
|
| 119 |
+
|
| 120 |
+
# Backup probe-level data
|
| 121 |
+
probe_data = gene_data
|
| 122 |
+
|
| 123 |
+
# Choose columns based on annotation preview:
|
| 124 |
+
# - Probe identifier: 'ID' (e.g., ILMN_1343291)
|
| 125 |
+
# - Gene symbol: 'Symbol' (e.g., JMJD1A, NCOA3)
|
| 126 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol')
|
| 127 |
+
|
| 128 |
+
# Apply mapping to convert probe-level to gene-level expression
|
| 129 |
+
gene_data = apply_gene_mapping(expression_df=probe_data, mapping_df=mapping_df)
|
| 130 |
+
|
| 131 |
+
# Optionally save the gene-level data
|
| 132 |
+
gene_data.to_csv(out_gene_data_file)
|
| 133 |
+
|
| 134 |
+
# Step 7: Data Normalization and Linking
|
| 135 |
+
# 1. Normalize the obtained gene data and save
|
| 136 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 137 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 138 |
+
|
| 139 |
+
# 2. Link the clinical and genetic data
|
| 140 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 141 |
+
|
| 142 |
+
# 3. Handle missing values in the linked data
|
| 143 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 144 |
+
|
| 145 |
+
# 4. Determine whether the trait and some demographic features are severely biased, and remove biased features.
|
| 146 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 147 |
+
|
| 148 |
+
# 5. Final validation and save cohort info
|
| 149 |
+
covariate_cols = [trait, 'Age', 'Gender']
|
| 150 |
+
gene_cols_after = [c for c in unbiased_linked_data.columns if c not in covariate_cols]
|
| 151 |
+
is_gene_available_final = len(gene_cols_after) > 0
|
| 152 |
+
is_trait_available_final = (trait in unbiased_linked_data.columns) and (len(unbiased_linked_data) > 0)
|
| 153 |
+
|
| 154 |
+
note = "INFO: Age and Gender not provided in series characteristics; post-mortem motor cortex MS vs control study."
|
| 155 |
+
|
| 156 |
+
is_usable = validate_and_save_cohort_info(
|
| 157 |
+
is_final=True,
|
| 158 |
+
cohort=cohort,
|
| 159 |
+
info_path=json_path,
|
| 160 |
+
is_gene_available=is_gene_available_final,
|
| 161 |
+
is_trait_available=is_trait_available_final,
|
| 162 |
+
is_biased=is_trait_biased,
|
| 163 |
+
df=unbiased_linked_data,
|
| 164 |
+
note=note
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
# 6. Save the linked data only if usable
|
| 168 |
+
if is_usable:
|
| 169 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Multiple_sclerosis/code/GSE141381.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE141381"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE141381"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE141381.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE141381.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE141381.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
import os
|
| 41 |
+
import pandas as pd
|
| 42 |
+
|
| 43 |
+
# 1) Assess gene expression availability
|
| 44 |
+
is_gene_available = True # Based on series context, this is a gene expression dataset (not miRNA/methylation only)
|
| 45 |
+
|
| 46 |
+
# 2) Determine availability rows from the Sample Characteristics Dictionary provided
|
| 47 |
+
trait_row = None # All subjects are SPMS; no case-control variability for Multiple_sclerosis
|
| 48 |
+
age_row = 1 # 'age: <number>' appears primarily under key 1
|
| 49 |
+
gender_row = 0 # 'gender: male/female' appears under key 0
|
| 50 |
+
|
| 51 |
+
# 2.2) Conversion functions
|
| 52 |
+
def _extract_value(x):
|
| 53 |
+
if x is None:
|
| 54 |
+
return None
|
| 55 |
+
s = str(x)
|
| 56 |
+
if ':' in s:
|
| 57 |
+
s = s.split(':', 1)[1]
|
| 58 |
+
return s.strip()
|
| 59 |
+
|
| 60 |
+
def convert_trait(x):
|
| 61 |
+
v = _extract_value(x)
|
| 62 |
+
if v is None:
|
| 63 |
+
return None
|
| 64 |
+
vl = v.lower()
|
| 65 |
+
# Explicit MS/controls mapping
|
| 66 |
+
positive_terms = ['multiple sclerosis', 'ms', 'spms', 'rrms', 'ppms', 'patient', 'case']
|
| 67 |
+
negative_terms = ['control', 'healthy', 'normal', 'non-ms', 'no ms', 'hc']
|
| 68 |
+
if any(t in vl for t in positive_terms):
|
| 69 |
+
return 1
|
| 70 |
+
if any(t in vl for t in negative_terms):
|
| 71 |
+
return 0
|
| 72 |
+
# Ignore treatment/placebo/baseline fields for trait mapping
|
| 73 |
+
if any(t in vl for t in ['treated', 'placebo', 'baseline']):
|
| 74 |
+
return None
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
+
def convert_age(x):
|
| 78 |
+
v = _extract_value(x)
|
| 79 |
+
if v is None:
|
| 80 |
+
return None
|
| 81 |
+
v = v.lower()
|
| 82 |
+
if v in ['na', 'n/a', 'unknown', 'missing', 'nan', 'none', '']:
|
| 83 |
+
return None
|
| 84 |
+
# Extract the first integer/float from the string
|
| 85 |
+
m = re.search(r'(\d+(\.\d+)?)', v)
|
| 86 |
+
if not m:
|
| 87 |
+
return None
|
| 88 |
+
try:
|
| 89 |
+
age_val = float(m.group(1))
|
| 90 |
+
if 0 < age_val < 120:
|
| 91 |
+
return age_val
|
| 92 |
+
return None
|
| 93 |
+
except Exception:
|
| 94 |
+
return None
|
| 95 |
+
|
| 96 |
+
def convert_gender(x):
|
| 97 |
+
v = _extract_value(x)
|
| 98 |
+
if v is None:
|
| 99 |
+
return None
|
| 100 |
+
vl = v.strip().lower()
|
| 101 |
+
if vl in ['female', 'f', 'woman', 'women']:
|
| 102 |
+
return 0
|
| 103 |
+
if vl in ['male', 'm', 'man', 'men']:
|
| 104 |
+
return 1
|
| 105 |
+
return None
|
| 106 |
+
|
| 107 |
+
# 3) Initial filtering and save metadata
|
| 108 |
+
is_trait_available = trait_row is not None
|
| 109 |
+
_ = validate_and_save_cohort_info(
|
| 110 |
+
is_final=False,
|
| 111 |
+
cohort=cohort,
|
| 112 |
+
info_path=json_path,
|
| 113 |
+
is_gene_available=is_gene_available,
|
| 114 |
+
is_trait_available=is_trait_available
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# 4) Clinical feature extraction (skip if trait not available)
|
| 118 |
+
if trait_row is not None:
|
| 119 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 120 |
+
clinical_df=clinical_data,
|
| 121 |
+
trait=trait,
|
| 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 |
+
print(preview_df(selected_clinical_df, n=5))
|
| 130 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 131 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 132 |
+
|
| 133 |
+
# Step 3: Gene Data Extraction
|
| 134 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 135 |
+
gene_data = get_genetic_data(matrix_file)
|
| 136 |
+
|
| 137 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 138 |
+
print(gene_data.index[:20])
|
| 139 |
+
|
| 140 |
+
# Step 4: Gene Identifier Review
|
| 141 |
+
# The observed identifiers are numeric probe IDs, not human gene symbols.
|
| 142 |
+
requires_gene_mapping = True
|
| 143 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 144 |
+
|
| 145 |
+
# Step 5: Gene Annotation
|
| 146 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 147 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 148 |
+
|
| 149 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 150 |
+
print("Gene annotation preview:")
|
| 151 |
+
print(preview_df(gene_annotation))
|
| 152 |
+
|
| 153 |
+
# Step 6: Gene Identifier Mapping
|
| 154 |
+
# Determine appropriate columns for probe IDs and gene symbols from annotation preview
|
| 155 |
+
probe_col = 'probeset_id' if 'probeset_id' in gene_annotation.columns else 'ID'
|
| 156 |
+
gene_col = 'gene_assignment' if 'gene_assignment' in gene_annotation.columns else 'mrna_assignment'
|
| 157 |
+
|
| 158 |
+
# Build mapping dataframe: columns -> ID (probe), Gene (annotation text containing symbols)
|
| 159 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_col)
|
| 160 |
+
|
| 161 |
+
# Apply mapping to convert probe-level measurements to gene-level expression
|
| 162 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
output/preprocess/Multiple_sclerosis/code/GSE141804.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE141804"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE141804"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE141804.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE141804.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE141804.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
import pandas as pd
|
| 41 |
+
|
| 42 |
+
# 1. Gene Expression Data Availability
|
| 43 |
+
# Based on "blood mononuclear cell transcriptome", treat as gene expression (mRNA) data.
|
| 44 |
+
is_gene_available = True
|
| 45 |
+
|
| 46 |
+
# 2. Variable Availability and Data Type Conversion
|
| 47 |
+
|
| 48 |
+
# Identify rows from the Sample Characteristics Dictionary provided:
|
| 49 |
+
# 0 -> gender, 1 -> age (years)
|
| 50 |
+
trait_row = None # No disease status/group key provided in the sample characteristics dictionary
|
| 51 |
+
age_row = 1
|
| 52 |
+
gender_row = 0
|
| 53 |
+
|
| 54 |
+
# Conversion functions
|
| 55 |
+
def _after_colon(value: any) -> str:
|
| 56 |
+
if pd.isna(value):
|
| 57 |
+
return ""
|
| 58 |
+
s = str(value)
|
| 59 |
+
return s.split(":", 1)[1].strip() if ":" in s else s.strip()
|
| 60 |
+
|
| 61 |
+
def convert_trait(value: any) -> int or None:
|
| 62 |
+
"""
|
| 63 |
+
Convert to binary Multiple_sclerosis status: 1 = MS present, 0 = MS absent.
|
| 64 |
+
This function is defined for completeness; not used since trait_row is None.
|
| 65 |
+
"""
|
| 66 |
+
v = _after_colon(value).lower()
|
| 67 |
+
if not v:
|
| 68 |
+
return None
|
| 69 |
+
# Positive MS indicators
|
| 70 |
+
ms_positive = {"ms", "mso", "multiple sclerosis", "p/ms", "pms", "comorbid ms", "ms patient", "ms-only", "p/ms patient"}
|
| 71 |
+
# Negative MS indicators
|
| 72 |
+
ms_negative = {"pso", "psoriasis", "psoriasis only", "healthy", "hc", "control", "healthy control"}
|
| 73 |
+
|
| 74 |
+
# Direct exact match checks
|
| 75 |
+
if v in ms_positive:
|
| 76 |
+
return 1
|
| 77 |
+
if v in ms_negative:
|
| 78 |
+
return 0
|
| 79 |
+
|
| 80 |
+
# Heuristics
|
| 81 |
+
if "multiple sclerosis" in v or re.search(r"\bms\b", v):
|
| 82 |
+
return 1
|
| 83 |
+
if "psoriasis" in v or "healthy" in v or "control" in v:
|
| 84 |
+
return 0
|
| 85 |
+
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
+
def convert_age(value: any) -> float or None:
|
| 89 |
+
v = _after_colon(value)
|
| 90 |
+
if not v:
|
| 91 |
+
return None
|
| 92 |
+
# Extract first numeric token
|
| 93 |
+
m = re.search(r"[-+]?\d*\.?\d+", v)
|
| 94 |
+
if m:
|
| 95 |
+
try:
|
| 96 |
+
return float(m.group(0))
|
| 97 |
+
except Exception:
|
| 98 |
+
return None
|
| 99 |
+
return None
|
| 100 |
+
|
| 101 |
+
def convert_gender(value: any) -> int or None:
|
| 102 |
+
v = _after_colon(value).lower()
|
| 103 |
+
if not v:
|
| 104 |
+
return None
|
| 105 |
+
if v.startswith("female") or v == "f":
|
| 106 |
+
return 0
|
| 107 |
+
if v.startswith("male") or v == "m":
|
| 108 |
+
return 1
|
| 109 |
+
return None
|
| 110 |
+
|
| 111 |
+
# 3. Save Metadata (initial filtering)
|
| 112 |
+
is_trait_available = trait_row is not None
|
| 113 |
+
_ = validate_and_save_cohort_info(
|
| 114 |
+
is_final=False,
|
| 115 |
+
cohort=cohort,
|
| 116 |
+
info_path=json_path,
|
| 117 |
+
is_gene_available=is_gene_available,
|
| 118 |
+
is_trait_available=is_trait_available
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
# 4. Clinical Feature Extraction (skip because trait_row is None)
|
| 122 |
+
if trait_row is not None:
|
| 123 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 124 |
+
clinical_df=clinical_data,
|
| 125 |
+
trait=trait,
|
| 126 |
+
trait_row=trait_row,
|
| 127 |
+
convert_trait=convert_trait,
|
| 128 |
+
age_row=age_row,
|
| 129 |
+
convert_age=convert_age,
|
| 130 |
+
gender_row=gender_row,
|
| 131 |
+
convert_gender=convert_gender
|
| 132 |
+
)
|
| 133 |
+
_ = preview_df(selected_clinical_df)
|
| 134 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
| 135 |
+
|
| 136 |
+
# Step 3: Gene Data Extraction
|
| 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 |
+
|
| 143 |
+
# Step 4: Gene Identifier Review
|
| 144 |
+
requires_gene_mapping = True
|
| 145 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 146 |
+
|
| 147 |
+
# Step 5: Gene Annotation
|
| 148 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 149 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 150 |
+
|
| 151 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 152 |
+
print("Gene annotation preview:")
|
| 153 |
+
print(preview_df(gene_annotation))
|
| 154 |
+
|
| 155 |
+
# Step 6: Gene Identifier Mapping
|
| 156 |
+
# Decide mapping columns based on previous previews: 'ID' holds probe IDs, 'Gene Symbol' holds gene symbols
|
| 157 |
+
prob_col = 'ID'
|
| 158 |
+
gene_col = 'Gene Symbol'
|
| 159 |
+
|
| 160 |
+
# 2. Build the probe-to-gene mapping dataframe
|
| 161 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=prob_col, gene_col=gene_col)
|
| 162 |
+
|
| 163 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 164 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 165 |
+
|
| 166 |
+
# Step 7: Data Normalization and Linking
|
| 167 |
+
import os
|
| 168 |
+
import pandas as pd
|
| 169 |
+
|
| 170 |
+
# 1) Normalize gene symbols and save gene-level data
|
| 171 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 172 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 173 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 174 |
+
|
| 175 |
+
# 2) Decide if trait/clinical data are available (simplified logic)
|
| 176 |
+
has_trait = True
|
| 177 |
+
if 'trait_row' in globals() and trait_row is None:
|
| 178 |
+
has_trait = False
|
| 179 |
+
else:
|
| 180 |
+
has_trait = 'selected_clinical_data' in globals() and isinstance(selected_clinical_data, pd.DataFrame)
|
| 181 |
+
|
| 182 |
+
if has_trait:
|
| 183 |
+
# 3) Link clinical and genetic data
|
| 184 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 185 |
+
|
| 186 |
+
# 4) Handle missing values
|
| 187 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 188 |
+
|
| 189 |
+
# 5) Assess bias and remove biased demographic features
|
| 190 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 191 |
+
|
| 192 |
+
# 6) Final validation and save cohort info
|
| 193 |
+
is_usable = validate_and_save_cohort_info(
|
| 194 |
+
is_final=True,
|
| 195 |
+
cohort=cohort,
|
| 196 |
+
info_path=json_path,
|
| 197 |
+
is_gene_available=True,
|
| 198 |
+
is_trait_available=True,
|
| 199 |
+
is_biased=is_trait_biased,
|
| 200 |
+
df=unbiased_linked_data,
|
| 201 |
+
note="INFO: Clinical and genetic data linked; missing values handled and demographics evaluated."
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
# 7) Save linked data only if usable
|
| 205 |
+
if is_usable:
|
| 206 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 207 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 208 |
+
|
| 209 |
+
else:
|
| 210 |
+
# Trait not available: record metadata and skip linking
|
| 211 |
+
dummy_df = normalized_gene_data.T.head(1) # ensure >4 columns to avoid abnormality override
|
| 212 |
+
_ = validate_and_save_cohort_info(
|
| 213 |
+
is_final=True,
|
| 214 |
+
cohort=cohort,
|
| 215 |
+
info_path=json_path,
|
| 216 |
+
is_gene_available=True,
|
| 217 |
+
is_trait_available=False,
|
| 218 |
+
is_biased=False,
|
| 219 |
+
df=dummy_df,
|
| 220 |
+
note="WARNING: Trait data unavailable (trait_row is None); linking skipped. Saved only normalized gene data."
|
| 221 |
+
)
|
output/preprocess/Multiple_sclerosis/code/GSE146383.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE146383"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE146383"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE146383.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE146383.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE146383.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
|
| 41 |
+
# 1. Gene Expression Data Availability
|
| 42 |
+
is_gene_available = True # Transcriptome profiling indicates gene expression data is available.
|
| 43 |
+
|
| 44 |
+
# 2. Variable Availability and Data Type Conversion
|
| 45 |
+
|
| 46 |
+
# Determine rows from Sample Characteristics Dictionary
|
| 47 |
+
trait_row = None # Disease status/group not present in the provided characteristics dictionary.
|
| 48 |
+
age_row = 1
|
| 49 |
+
gender_row = 0
|
| 50 |
+
|
| 51 |
+
# Conversion functions
|
| 52 |
+
def _extract_value(x):
|
| 53 |
+
if x is None:
|
| 54 |
+
return None
|
| 55 |
+
s = str(x)
|
| 56 |
+
parts = s.split(":", 1)
|
| 57 |
+
val = parts[1] if len(parts) > 1 else parts[0]
|
| 58 |
+
return val.strip()
|
| 59 |
+
|
| 60 |
+
def convert_trait(x):
|
| 61 |
+
# Binary: MS = 1, Control = 0
|
| 62 |
+
v = _extract_value(x)
|
| 63 |
+
if v is None:
|
| 64 |
+
return None
|
| 65 |
+
vl = v.lower()
|
| 66 |
+
# Map known group labels and descriptors
|
| 67 |
+
ms_tokens = {
|
| 68 |
+
"ms", "multiple sclerosis",
|
| 69 |
+
"pdms-rec", "pdms-norec", "adms-rec", "adms-norec",
|
| 70 |
+
"patient with ms", "ms patient"
|
| 71 |
+
}
|
| 72 |
+
control_tokens = {"control", "healthy", "pdc", "adc"}
|
| 73 |
+
if any(tok == vl for tok in ms_tokens) or any(tok in vl for tok in ["pdms", "adms"]):
|
| 74 |
+
return 1
|
| 75 |
+
if vl in control_tokens:
|
| 76 |
+
return 0
|
| 77 |
+
# Additional heuristics
|
| 78 |
+
if "control" in vl or "healthy" in vl:
|
| 79 |
+
return 0
|
| 80 |
+
if "multiple sclerosis" in vl or vl == "ms":
|
| 81 |
+
return 1
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
def convert_age(x):
|
| 85 |
+
v = _extract_value(x)
|
| 86 |
+
if v is None:
|
| 87 |
+
return None
|
| 88 |
+
m = re.search(r"-?\d+\.?\d*", v)
|
| 89 |
+
try:
|
| 90 |
+
return float(m.group()) if m else None
|
| 91 |
+
except Exception:
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
def convert_gender(x):
|
| 95 |
+
v = _extract_value(x)
|
| 96 |
+
if v is None:
|
| 97 |
+
return None
|
| 98 |
+
vl = v.strip().lower()
|
| 99 |
+
if vl in {"male", "m"}:
|
| 100 |
+
return 1
|
| 101 |
+
if vl in {"female", "f"}:
|
| 102 |
+
return 0
|
| 103 |
+
return None
|
| 104 |
+
|
| 105 |
+
# 3. Save Metadata (initial filtering)
|
| 106 |
+
is_trait_available = trait_row is not None
|
| 107 |
+
_ = validate_and_save_cohort_info(
|
| 108 |
+
is_final=False,
|
| 109 |
+
cohort=cohort,
|
| 110 |
+
info_path=json_path,
|
| 111 |
+
is_gene_available=is_gene_available,
|
| 112 |
+
is_trait_available=is_trait_available
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# 4. Clinical Feature Extraction (skip if trait_row is None)
|
| 116 |
+
if trait_row is not None:
|
| 117 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 118 |
+
clinical_df=clinical_data,
|
| 119 |
+
trait=trait,
|
| 120 |
+
trait_row=trait_row,
|
| 121 |
+
convert_trait=convert_trait,
|
| 122 |
+
age_row=age_row,
|
| 123 |
+
convert_age=convert_age,
|
| 124 |
+
gender_row=gender_row,
|
| 125 |
+
convert_gender=convert_gender
|
| 126 |
+
)
|
| 127 |
+
_ = preview_df(selected_clinical_df)
|
| 128 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 129 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
| 130 |
+
|
| 131 |
+
# Step 3: Gene Data Extraction
|
| 132 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 133 |
+
gene_data = get_genetic_data(matrix_file)
|
| 134 |
+
|
| 135 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 136 |
+
print(gene_data.index[:20])
|
| 137 |
+
|
| 138 |
+
# Step 4: Gene Identifier Review
|
| 139 |
+
print("requires_gene_mapping = True")
|
| 140 |
+
|
| 141 |
+
# Step 5: Gene Annotation
|
| 142 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 143 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 144 |
+
|
| 145 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 146 |
+
print("Gene annotation preview:")
|
| 147 |
+
print(preview_df(gene_annotation))
|
| 148 |
+
|
| 149 |
+
# Step 6: Gene Identifier Mapping
|
| 150 |
+
# Decide mapping columns based on annotation preview
|
| 151 |
+
probe_id_col = 'ID'
|
| 152 |
+
gene_symbol_col = 'Gene Symbol'
|
| 153 |
+
|
| 154 |
+
# Build mapping dataframe
|
| 155 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_id_col, gene_col=gene_symbol_col)
|
| 156 |
+
|
| 157 |
+
# Apply mapping to convert probe-level data to gene-level data
|
| 158 |
+
probe_level_df = gene_data
|
| 159 |
+
gene_data = apply_gene_mapping(expression_df=probe_level_df, mapping_df=mapping_df)
|
| 160 |
+
|
| 161 |
+
# Step 7: Data Normalization and Linking
|
| 162 |
+
import os
|
| 163 |
+
|
| 164 |
+
# 1. Normalize gene symbols and save gene data
|
| 165 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 166 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 167 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 168 |
+
|
| 169 |
+
# Determine if clinical features (including trait) were extracted earlier
|
| 170 |
+
clinical_selected = None
|
| 171 |
+
if 'selected_clinical_data' in globals():
|
| 172 |
+
clinical_selected = selected_clinical_data
|
| 173 |
+
elif 'selected_clinical_df' in globals():
|
| 174 |
+
clinical_selected = selected_clinical_df
|
| 175 |
+
|
| 176 |
+
has_trait = clinical_selected is not None
|
| 177 |
+
|
| 178 |
+
if has_trait:
|
| 179 |
+
# 2. Link clinical and genetic data
|
| 180 |
+
linked_data = geo_link_clinical_genetic_data(clinical_selected, normalized_gene_data)
|
| 181 |
+
|
| 182 |
+
# 3. Handle missing values
|
| 183 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 184 |
+
|
| 185 |
+
# 4. Bias assessment and remove biased demographic features
|
| 186 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 187 |
+
|
| 188 |
+
# 5. Final validation and save cohort info
|
| 189 |
+
is_usable = validate_and_save_cohort_info(
|
| 190 |
+
True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
# 6. Save linked data if usable
|
| 194 |
+
if is_usable:
|
| 195 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 196 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 197 |
+
else:
|
| 198 |
+
# Clinical trait unavailable: finalize metadata without linked data
|
| 199 |
+
note = "INFO: Trait/clinical labels unavailable in matrix; only gene data processed and saved."
|
| 200 |
+
_ = validate_and_save_cohort_info(
|
| 201 |
+
True,
|
| 202 |
+
cohort,
|
| 203 |
+
json_path,
|
| 204 |
+
is_gene_available=True,
|
| 205 |
+
is_trait_available=False,
|
| 206 |
+
is_biased=False,
|
| 207 |
+
df=normalized_gene_data.T, # Use transposed gene data to resemble samples x features
|
| 208 |
+
note=note
|
| 209 |
+
)
|
| 210 |
+
# Do not save out_data_file when trait is unavailable
|
output/preprocess/Multiple_sclerosis/code/GSE189788.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE189788"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE189788"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE189788.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE189788.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE189788.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
import pandas as pd
|
| 42 |
+
|
| 43 |
+
# 1) Gene expression data availability
|
| 44 |
+
# Affymetrix HU-133A-2 microarrays indicate mRNA expression profiling.
|
| 45 |
+
is_gene_available = True
|
| 46 |
+
|
| 47 |
+
# 2) Variable availability and converters
|
| 48 |
+
# Sample Characteristics Dictionary review:
|
| 49 |
+
# 0: ['patient diagnosis: multiple sclerosis'] -> constant; not useful for association (no controls)
|
| 50 |
+
# 2: ages available and variable
|
| 51 |
+
# 3: gender available and variable
|
| 52 |
+
trait_row = None
|
| 53 |
+
age_row = 2
|
| 54 |
+
gender_row = 3
|
| 55 |
+
|
| 56 |
+
def _after_colon(value: str) -> str:
|
| 57 |
+
if value is None:
|
| 58 |
+
return ""
|
| 59 |
+
s = str(value)
|
| 60 |
+
parts = s.split(":", 1)
|
| 61 |
+
return parts[1].strip() if len(parts) > 1 else s.strip()
|
| 62 |
+
|
| 63 |
+
def convert_trait(x):
|
| 64 |
+
# Binary: 1 = Multiple sclerosis, 0 = control/healthy. Unknown -> None
|
| 65 |
+
v = _after_colon(x).lower()
|
| 66 |
+
if not v:
|
| 67 |
+
return None
|
| 68 |
+
# Positive MS indicators
|
| 69 |
+
ms_keys = ["multiple sclerosis", " rrms", " spms", " ppms", "ms patient", "ms case", "ms "]
|
| 70 |
+
if any(k in v for k in ms_keys) or v == "ms":
|
| 71 |
+
return 1
|
| 72 |
+
# Controls/healthy indicators
|
| 73 |
+
ctrl_keys = ["control", "healthy", "normal", "no disease", "non-disease", "donor"]
|
| 74 |
+
if any(k in v for k in ctrl_keys):
|
| 75 |
+
return 0
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
def convert_age(x):
|
| 79 |
+
# Continuous
|
| 80 |
+
v = _after_colon(x)
|
| 81 |
+
if not v:
|
| 82 |
+
return None
|
| 83 |
+
m = re.search(r'(-?\d+(\.\d+)?)', v)
|
| 84 |
+
if not m:
|
| 85 |
+
return None
|
| 86 |
+
try:
|
| 87 |
+
age = float(m.group(1))
|
| 88 |
+
if age < 0 or age > 120:
|
| 89 |
+
return None
|
| 90 |
+
return age
|
| 91 |
+
except Exception:
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
def convert_gender(x):
|
| 95 |
+
# Binary: female -> 0, male -> 1
|
| 96 |
+
v = _after_colon(x).lower()
|
| 97 |
+
if not v:
|
| 98 |
+
return None
|
| 99 |
+
# Handle common terms and letters
|
| 100 |
+
if v in {"female", "f", "woman", "women", "girl"} or "female" in v:
|
| 101 |
+
return 0
|
| 102 |
+
if v in {"male", "m", "man", "men", "boy"} or "male" in v:
|
| 103 |
+
return 1
|
| 104 |
+
return None
|
| 105 |
+
|
| 106 |
+
# 3) Save metadata (initial filtering)
|
| 107 |
+
is_trait_available = trait_row is not None
|
| 108 |
+
_ = validate_and_save_cohort_info(
|
| 109 |
+
is_final=False,
|
| 110 |
+
cohort=cohort,
|
| 111 |
+
info_path=json_path,
|
| 112 |
+
is_gene_available=is_gene_available,
|
| 113 |
+
is_trait_available=is_trait_available
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
# 4) Clinical feature extraction (only if trait is available)
|
| 117 |
+
if trait_row is not None:
|
| 118 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 119 |
+
clinical_df=clinical_data,
|
| 120 |
+
trait=trait,
|
| 121 |
+
trait_row=trait_row,
|
| 122 |
+
convert_trait=convert_trait,
|
| 123 |
+
age_row=age_row,
|
| 124 |
+
convert_age=convert_age,
|
| 125 |
+
gender_row=gender_row,
|
| 126 |
+
convert_gender=convert_gender
|
| 127 |
+
)
|
| 128 |
+
print(preview_df(selected_clinical_df, n=5))
|
| 129 |
+
|
| 130 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 131 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
output/preprocess/Multiple_sclerosis/code/GSE193442.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE193442"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE193442"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE193442.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE193442.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE193442.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# Step 1: Determine data availability
|
| 40 |
+
is_gene_available = True # "Transcriptional profiling" of human KIR+ CD8 T cells suggests mRNA expression data
|
| 41 |
+
trait_row = None # No disease/trait info found in sample characteristics
|
| 42 |
+
age_row = None # No age info found
|
| 43 |
+
gender_row = None # No gender info found
|
| 44 |
+
|
| 45 |
+
# Step 2: Define conversion functions
|
| 46 |
+
def _extract_value(x):
|
| 47 |
+
if x is None:
|
| 48 |
+
return None
|
| 49 |
+
if not isinstance(x, str):
|
| 50 |
+
x = str(x)
|
| 51 |
+
parts = x.split(":", 1)
|
| 52 |
+
val = parts[1] if len(parts) > 1 else parts[0]
|
| 53 |
+
return val.strip()
|
| 54 |
+
|
| 55 |
+
def convert_trait(x):
|
| 56 |
+
val = _extract_value(x)
|
| 57 |
+
if not val:
|
| 58 |
+
return None
|
| 59 |
+
v = val.lower()
|
| 60 |
+
# Positive MS indicators
|
| 61 |
+
ms_tokens = ["multiple sclerosis", "ms", "rrms", "ppms", "spms", "cis", "clinically isolated syndrome"]
|
| 62 |
+
# Negative/control indicators
|
| 63 |
+
ctrl_tokens = ["control", "healthy", "normal", "no ms", "non-ms", "without ms"]
|
| 64 |
+
if any(tok in v for tok in ms_tokens):
|
| 65 |
+
return 1
|
| 66 |
+
if any(tok in v for tok in ctrl_tokens):
|
| 67 |
+
return 0
|
| 68 |
+
# Generic yes/no
|
| 69 |
+
if v in {"case", "patient", "disease", "yes"}:
|
| 70 |
+
return 1
|
| 71 |
+
if v in {"control", "healthy control", "no", "none"}:
|
| 72 |
+
return 0
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
def convert_age(x):
|
| 76 |
+
val = _extract_value(x)
|
| 77 |
+
if not val:
|
| 78 |
+
return None
|
| 79 |
+
v = val.lower().replace("years", "").replace("year", "").replace("yrs", "").replace("yr", "").strip()
|
| 80 |
+
# Keep digits and dot
|
| 81 |
+
import re
|
| 82 |
+
m = re.search(r"(\d+(\.\d+)?)", v)
|
| 83 |
+
if m:
|
| 84 |
+
try:
|
| 85 |
+
return float(m.group(1))
|
| 86 |
+
except Exception:
|
| 87 |
+
return None
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
def convert_gender(x):
|
| 91 |
+
val = _extract_value(x)
|
| 92 |
+
if not val:
|
| 93 |
+
return None
|
| 94 |
+
v = val.lower().strip()
|
| 95 |
+
if v in {"male", "m", "man"}:
|
| 96 |
+
return 1
|
| 97 |
+
if v in {"female", "f", "woman"}:
|
| 98 |
+
return 0
|
| 99 |
+
return None
|
| 100 |
+
|
| 101 |
+
# Step 3: Save initial metadata
|
| 102 |
+
is_trait_available = trait_row is not None
|
| 103 |
+
_ = validate_and_save_cohort_info(
|
| 104 |
+
is_final=False,
|
| 105 |
+
cohort=cohort,
|
| 106 |
+
info_path=json_path,
|
| 107 |
+
is_gene_available=is_gene_available,
|
| 108 |
+
is_trait_available=is_trait_available
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
# Step 4: Clinical feature extraction (skip because trait_row is None)
|
| 112 |
+
# If trait_row becomes available in future, uncomment and use:
|
| 113 |
+
# if trait_row is not None:
|
| 114 |
+
# selected = geo_select_clinical_features(
|
| 115 |
+
# clinical_df=clinical_data,
|
| 116 |
+
# trait=trait,
|
| 117 |
+
# trait_row=trait_row,
|
| 118 |
+
# convert_trait=convert_trait,
|
| 119 |
+
# age_row=age_row,
|
| 120 |
+
# convert_age=convert_age,
|
| 121 |
+
# gender_row=gender_row,
|
| 122 |
+
# convert_gender=convert_gender
|
| 123 |
+
# )
|
| 124 |
+
# preview = preview_df(selected)
|
| 125 |
+
# os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 126 |
+
# selected.to_csv(out_clinical_data_file, index=True)
|
| 127 |
+
|
| 128 |
+
# Step 3: Gene Data Extraction
|
| 129 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 130 |
+
gene_data = get_genetic_data(matrix_file)
|
| 131 |
+
|
| 132 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 133 |
+
print(gene_data.index[:20])
|
output/preprocess/Multiple_sclerosis/code/GSE203241.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
cohort = "GSE203241"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Multiple_sclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Multiple_sclerosis/GSE203241"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/GSE203241.csv"
|
| 14 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/GSE203241.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/GSE203241.csv"
|
| 16 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import pandas as pd
|
| 40 |
+
|
| 41 |
+
# 1. Gene Expression Data Availability
|
| 42 |
+
is_gene_available = True # Transcriptome profiling of blood mononuclear cells indicates gene expression data.
|
| 43 |
+
|
| 44 |
+
# 2. Variable Availability and Data Type Conversion
|
| 45 |
+
|
| 46 |
+
# 2.1 Identify keys in the sample characteristics dictionary
|
| 47 |
+
trait_row = None # No explicit diagnosis/status key provided in the sample characteristics.
|
| 48 |
+
age_row = 1
|
| 49 |
+
gender_row = 0
|
| 50 |
+
|
| 51 |
+
# 2.2 Conversion functions
|
| 52 |
+
def _after_colon(value):
|
| 53 |
+
if value is None:
|
| 54 |
+
return None
|
| 55 |
+
parts = str(value).split(":", 1)
|
| 56 |
+
return parts[1].strip() if len(parts) > 1 else str(value).strip()
|
| 57 |
+
|
| 58 |
+
def convert_trait(value):
|
| 59 |
+
v = _after_colon(value)
|
| 60 |
+
if v is None:
|
| 61 |
+
return None
|
| 62 |
+
vl = v.strip().lower().replace("_", " ")
|
| 63 |
+
vl_nospace = vl.replace(" ", "")
|
| 64 |
+
# Map MS patients to 1
|
| 65 |
+
ms_pos = {
|
| 66 |
+
"ms", "multiple sclerosis", "multiplesclerosis",
|
| 67 |
+
"poms", "aoms",
|
| 68 |
+
"rrms", "relapsing remitting multiple sclerosis", "relapsingremittingmultiplesclerosis"
|
| 69 |
+
}
|
| 70 |
+
# Map controls to 0
|
| 71 |
+
ms_neg = {"control", "healthy", "hc", "phc", "ahc", "normal"}
|
| 72 |
+
if vl in ms_neg or vl_nospace in ms_neg:
|
| 73 |
+
return 0
|
| 74 |
+
if vl in ms_pos or vl_nospace in ms_pos:
|
| 75 |
+
return 1
|
| 76 |
+
# Heuristics: keywords
|
| 77 |
+
if "control" in vl or "healthy" in vl:
|
| 78 |
+
return 0
|
| 79 |
+
if "sclerosis" in vl or vl == "ms":
|
| 80 |
+
return 1
|
| 81 |
+
return None
|
| 82 |
+
|
| 83 |
+
def convert_age(value):
|
| 84 |
+
v = _after_colon(value)
|
| 85 |
+
if v is None or v == "":
|
| 86 |
+
return None
|
| 87 |
+
# keep only numbers, dot, minus
|
| 88 |
+
try:
|
| 89 |
+
# Remove any non-numeric trailing text (e.g., 'years')
|
| 90 |
+
num = ''.join(ch for ch in v if (ch.isdigit() or ch in ['.', '-']))
|
| 91 |
+
if num == '' or num == '-' or num == '.':
|
| 92 |
+
return None
|
| 93 |
+
return float(num)
|
| 94 |
+
except Exception:
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
def convert_gender(value):
|
| 98 |
+
v = _after_colon(value)
|
| 99 |
+
if v is None:
|
| 100 |
+
return None
|
| 101 |
+
vl = v.strip().lower()
|
| 102 |
+
if vl in {"female", "f", "woman", "women", "girl"}:
|
| 103 |
+
return 0
|
| 104 |
+
if vl in {"male", "m", "man", "men", "boy"}:
|
| 105 |
+
return 1
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
# 3. Save Metadata (initial filtering)
|
| 109 |
+
is_trait_available = trait_row is not None
|
| 110 |
+
_ = validate_and_save_cohort_info(
|
| 111 |
+
is_final=False,
|
| 112 |
+
cohort=cohort,
|
| 113 |
+
info_path=json_path,
|
| 114 |
+
is_gene_available=is_gene_available,
|
| 115 |
+
is_trait_available=is_trait_available
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
# 4. Clinical Feature Extraction (skip if trait_row is None)
|
| 119 |
+
if trait_row is not None:
|
| 120 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 121 |
+
clinical_df=clinical_data,
|
| 122 |
+
trait=trait,
|
| 123 |
+
trait_row=trait_row,
|
| 124 |
+
convert_trait=convert_trait,
|
| 125 |
+
age_row=age_row,
|
| 126 |
+
convert_age=convert_age,
|
| 127 |
+
gender_row=gender_row,
|
| 128 |
+
convert_gender=convert_gender
|
| 129 |
+
)
|
| 130 |
+
# Preview and save
|
| 131 |
+
_ = preview_df(selected_clinical_df, n=5)
|
| 132 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
| 133 |
+
|
| 134 |
+
# Step 3: Gene Data Extraction
|
| 135 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 136 |
+
gene_data = get_genetic_data(matrix_file)
|
| 137 |
+
|
| 138 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 139 |
+
print(gene_data.index[:20])
|
| 140 |
+
|
| 141 |
+
# Step 4: Gene Identifier Review
|
| 142 |
+
print("requires_gene_mapping = True")
|
| 143 |
+
|
| 144 |
+
# Step 5: Gene Annotation
|
| 145 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 146 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 147 |
+
|
| 148 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 149 |
+
print("Gene annotation preview:")
|
| 150 |
+
print(preview_df(gene_annotation))
|
| 151 |
+
|
| 152 |
+
# Step 6: Gene Identifier Mapping
|
| 153 |
+
# Identify the appropriate columns for mapping based on the preview:
|
| 154 |
+
# Probe ID column in annotation matches the probe IDs in gene expression data
|
| 155 |
+
id_col = 'ID'
|
| 156 |
+
# Gene symbol column in annotation
|
| 157 |
+
gene_col = 'Gene Symbol'
|
| 158 |
+
|
| 159 |
+
# Build mapping dataframe
|
| 160 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=gene_col)
|
| 161 |
+
|
| 162 |
+
# Apply mapping to convert probe-level data to gene-level data
|
| 163 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 164 |
+
|
| 165 |
+
# Step 7: Data Normalization and Linking
|
| 166 |
+
# 1. Normalize the obtained gene data and save
|
| 167 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 168 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 169 |
+
|
| 170 |
+
# Determine availability of clinical trait data from earlier steps
|
| 171 |
+
has_selected_clinical = 'selected_clinical_data' in globals()
|
| 172 |
+
|
| 173 |
+
if has_selected_clinical:
|
| 174 |
+
# 2. Link the clinical and genetic data
|
| 175 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 176 |
+
|
| 177 |
+
# 3. Handle missing values in the linked data
|
| 178 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 179 |
+
|
| 180 |
+
# 4. Determine whether the trait and some demographic features are severely biased, and remove biased features.
|
| 181 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 182 |
+
|
| 183 |
+
# 5. Conduct quality check and save the cohort information.
|
| 184 |
+
is_usable = validate_and_save_cohort_info(
|
| 185 |
+
is_final=True,
|
| 186 |
+
cohort=cohort,
|
| 187 |
+
info_path=json_path,
|
| 188 |
+
is_gene_available=True,
|
| 189 |
+
is_trait_available=True,
|
| 190 |
+
is_biased=is_trait_biased,
|
| 191 |
+
df=unbiased_linked_data,
|
| 192 |
+
note="INFO: Clinical-genetic linking performed with available trait data."
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
# 6. If the linked data is usable, save it as a CSV file to 'out_data_file'.
|
| 196 |
+
if is_usable:
|
| 197 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 198 |
+
else:
|
| 199 |
+
# Trait not available: perform final validation reflecting this and do not attempt linking
|
| 200 |
+
_ = validate_and_save_cohort_info(
|
| 201 |
+
is_final=True,
|
| 202 |
+
cohort=cohort,
|
| 203 |
+
info_path=json_path,
|
| 204 |
+
is_gene_available=True,
|
| 205 |
+
is_trait_available=False,
|
| 206 |
+
is_biased=False, # placeholder; ignored since is_available will be False
|
| 207 |
+
df=normalized_gene_data.T, # use gene data (samples x genes) for shape reference
|
| 208 |
+
note=f"WARNING: Trait ({trait}) not available; clinical-genetic linking skipped."
|
| 209 |
+
)
|
output/preprocess/Multiple_sclerosis/code/TCGA.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Multiple_sclerosis"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z5/preprocess/Multiple_sclerosis/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z5/preprocess/Multiple_sclerosis/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z5/preprocess/Multiple_sclerosis/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z5/preprocess/Multiple_sclerosis/cohort_info.json"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Step 1: Initial Data Loading
|
| 18 |
+
import os
|
| 19 |
+
import pandas as pd
|
| 20 |
+
|
| 21 |
+
# Step 1: Identify the most relevant TCGA cohort directory for Multiple Sclerosis (likely none in TCGA cancer cohorts)
|
| 22 |
+
subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 23 |
+
|
| 24 |
+
# Define search terms for Multiple Sclerosis
|
| 25 |
+
search_terms = {"multiple sclerosis", "multiple_sclerosis", "ms"}
|
| 26 |
+
|
| 27 |
+
def name_tokens(name: str):
|
| 28 |
+
# Normalize and split directory name into tokens
|
| 29 |
+
base = name.lower().replace('-', ' ').replace('_', ' ').replace('(', ' ').replace(')', ' ')
|
| 30 |
+
return set(base.split())
|
| 31 |
+
|
| 32 |
+
selected_dir = None
|
| 33 |
+
for d in subdirs:
|
| 34 |
+
tokens = name_tokens(d)
|
| 35 |
+
# Exact phrase search in the raw lowercased name as a fallback
|
| 36 |
+
raw_name = d.lower()
|
| 37 |
+
if ("multiple sclerosis" in raw_name) or ("multiple_sclerosis" in raw_name) or (tokens & search_terms):
|
| 38 |
+
selected_dir = d
|
| 39 |
+
break
|
| 40 |
+
|
| 41 |
+
clinical_df = None
|
| 42 |
+
genetic_df = None
|
| 43 |
+
|
| 44 |
+
if selected_dir is None:
|
| 45 |
+
print("No suitable TCGA cohort found for Multiple Sclerosis. Skipping this trait.")
|
| 46 |
+
# Record unusable cohort for TCGA in metadata and mark task as completed for this trait
|
| 47 |
+
validate_and_save_cohort_info(
|
| 48 |
+
is_final=False,
|
| 49 |
+
cohort="TCGA",
|
| 50 |
+
info_path=json_path,
|
| 51 |
+
is_gene_available=False,
|
| 52 |
+
is_trait_available=False
|
| 53 |
+
)
|
| 54 |
+
else:
|
| 55 |
+
# Step 2: Identify clinical and genetic file paths
|
| 56 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 57 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
| 58 |
+
|
| 59 |
+
# Step 3: Load both files as DataFrames
|
| 60 |
+
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False)
|
| 61 |
+
genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False)
|
| 62 |
+
|
| 63 |
+
# Step 4: Print column names of the clinical data
|
| 64 |
+
print(list(clinical_df.columns))
|
output/preprocess/Multiple_sclerosis/cohort_info.json
CHANGED
|
@@ -1,112 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"GSE203241": {
|
| 3 |
-
"is_usable": false,
|
| 4 |
-
"is_gene_available": true,
|
| 5 |
-
"is_trait_available": false,
|
| 6 |
-
"is_available": false,
|
| 7 |
-
"is_biased": null,
|
| 8 |
-
"has_age": null,
|
| 9 |
-
"has_gender": null,
|
| 10 |
-
"sample_size": null
|
| 11 |
-
},
|
| 12 |
-
"GSE193442": {
|
| 13 |
-
"is_usable": false,
|
| 14 |
-
"is_gene_available": false,
|
| 15 |
-
"is_trait_available": false,
|
| 16 |
-
"is_available": false,
|
| 17 |
-
"is_biased": null,
|
| 18 |
-
"has_age": null,
|
| 19 |
-
"has_gender": null,
|
| 20 |
-
"sample_size": null
|
| 21 |
-
},
|
| 22 |
-
"GSE189788": {
|
| 23 |
-
"is_usable": false,
|
| 24 |
-
"is_gene_available": true,
|
| 25 |
-
"is_trait_available": true,
|
| 26 |
-
"is_available": true,
|
| 27 |
-
"is_biased": true,
|
| 28 |
-
"has_age": true,
|
| 29 |
-
"has_gender": true,
|
| 30 |
-
"sample_size": 216
|
| 31 |
-
},
|
| 32 |
-
"GSE146383": {
|
| 33 |
-
"is_usable": false,
|
| 34 |
-
"is_gene_available": true,
|
| 35 |
-
"is_trait_available": false,
|
| 36 |
-
"is_available": false,
|
| 37 |
-
"is_biased": null,
|
| 38 |
-
"has_age": null,
|
| 39 |
-
"has_gender": null,
|
| 40 |
-
"sample_size": null
|
| 41 |
-
},
|
| 42 |
-
"GSE141804": {
|
| 43 |
-
"is_usable": false,
|
| 44 |
-
"is_gene_available": true,
|
| 45 |
-
"is_trait_available": false,
|
| 46 |
-
"is_available": false,
|
| 47 |
-
"is_biased": null,
|
| 48 |
-
"has_age": null,
|
| 49 |
-
"has_gender": null,
|
| 50 |
-
"sample_size": null
|
| 51 |
-
},
|
| 52 |
-
"GSE141381": {
|
| 53 |
-
"is_usable": true,
|
| 54 |
-
"is_gene_available": true,
|
| 55 |
-
"is_trait_available": true,
|
| 56 |
-
"is_available": true,
|
| 57 |
-
"is_biased": false,
|
| 58 |
-
"has_age": true,
|
| 59 |
-
"has_gender": true,
|
| 60 |
-
"sample_size": 25
|
| 61 |
-
},
|
| 62 |
-
"GSE135511": {
|
| 63 |
-
"is_usable": true,
|
| 64 |
-
"is_gene_available": true,
|
| 65 |
-
"is_trait_available": true,
|
| 66 |
-
"is_available": true,
|
| 67 |
-
"is_biased": false,
|
| 68 |
-
"has_age": false,
|
| 69 |
-
"has_gender": false,
|
| 70 |
-
"sample_size": 50
|
| 71 |
-
},
|
| 72 |
-
"GSE131282": {
|
| 73 |
-
"is_usable": true,
|
| 74 |
-
"is_gene_available": true,
|
| 75 |
-
"is_trait_available": true,
|
| 76 |
-
"is_available": true,
|
| 77 |
-
"is_biased": false,
|
| 78 |
-
"has_age": true,
|
| 79 |
-
"has_gender": true,
|
| 80 |
-
"sample_size": 78
|
| 81 |
-
},
|
| 82 |
-
"GSE131281": {
|
| 83 |
-
"is_usable": true,
|
| 84 |
-
"is_gene_available": true,
|
| 85 |
-
"is_trait_available": true,
|
| 86 |
-
"is_available": true,
|
| 87 |
-
"is_biased": false,
|
| 88 |
-
"has_age": true,
|
| 89 |
-
"has_gender": true,
|
| 90 |
-
"sample_size": 106
|
| 91 |
-
},
|
| 92 |
-
"GSE131279": {
|
| 93 |
-
"is_usable": true,
|
| 94 |
-
"is_gene_available": true,
|
| 95 |
-
"is_trait_available": true,
|
| 96 |
-
"is_available": true,
|
| 97 |
-
"is_biased": false,
|
| 98 |
-
"has_age": true,
|
| 99 |
-
"has_gender": true,
|
| 100 |
-
"sample_size": 78
|
| 101 |
-
},
|
| 102 |
-
"TCGA": {
|
| 103 |
-
"is_usable": false,
|
| 104 |
-
"is_gene_available": false,
|
| 105 |
-
"is_trait_available": false,
|
| 106 |
-
"is_available": false,
|
| 107 |
-
"is_biased": null,
|
| 108 |
-
"has_age": null,
|
| 109 |
-
"has_gender": null,
|
| 110 |
-
"sample_size": null
|
| 111 |
-
}
|
| 112 |
-
}
|
|
|
|
| 1 |
+
{"GSE203241": {"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": "WARNING: Trait (Multiple_sclerosis) not available; clinical-genetic linking skipped."}, "GSE193442": {"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}, "GSE189788": {"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}, "GSE146383": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "INFO: Trait/clinical labels unavailable in matrix; only gene data processed and saved."}, "GSE141804": {"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": "WARNING: Trait data unavailable (trait_row is None); linking skipped. Saved only normalized gene data."}, "GSE141381": {"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}, "GSE135511": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 50, "note": "INFO: Age and Gender not provided in series characteristics; post-mortem motor cortex MS vs control study."}, "GSE131282": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 184, "note": "INFO: Trait inferred from patient ID prefix (M=MS case, C=control). Platform identifiers are Illumina probes; mapped via SOFT 'Symbol' column; gene symbols normalized using NCBI synonyms."}, "GSE131281": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 106, "note": "INFO: Probe-to-gene mapping via SOFT 'Symbol' with equal split for multi-gene probes; gene symbols normalized using NCBI synonym table; trait from 'ms type', age from 'age at death', gender from 'Sex'."}, "GSE131279": {"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": "WARNING: Trait not available (all samples are MS cases); no linked data saved."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output/preprocess/Obesity/GSE181339.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
output/preprocess/Obesity/clinical_data/GSE123086.csv
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
,
|
| 2 |
-
Obesity,,,,,
|
| 3 |
-
Age,,,,51.0,49.0
|
| 4 |
-
Gender,,,0.0,,
|
|
|
|
| 1 |
+
,GSM3494884,GSM3494885,GSM3494886,GSM3494887,GSM3494888,GSM3494889,GSM3494890,GSM3494891,GSM3494892,GSM3494893,GSM3494894,GSM3494895,GSM3494896,GSM3494897,GSM3494898,GSM3494899,GSM3494900,GSM3494901,GSM3494902,GSM3494903,GSM3494904,GSM3494905,GSM3494906,GSM3494907,GSM3494908,GSM3494909,GSM3494910,GSM3494911,GSM3494912,GSM3494913,GSM3494914,GSM3494915,GSM3494916,GSM3494917,GSM3494918,GSM3494919,GSM3494920,GSM3494921,GSM3494922,GSM3494923,GSM3494924,GSM3494925,GSM3494926,GSM3494927,GSM3494928,GSM3494929,GSM3494930,GSM3494931,GSM3494932,GSM3494933,GSM3494934,GSM3494935,GSM3494936,GSM3494937,GSM3494938,GSM3494939,GSM3494940,GSM3494941,GSM3494942,GSM3494943,GSM3494944,GSM3494945,GSM3494946,GSM3494947,GSM3494948,GSM3494949,GSM3494950,GSM3494951,GSM3494952,GSM3494953,GSM3494954,GSM3494955,GSM3494956,GSM3494957,GSM3494958,GSM3494959,GSM3494960,GSM3494961,GSM3494962,GSM3494963,GSM3494964,GSM3494965,GSM3494966,GSM3494967,GSM3494968,GSM3494969,GSM3494970,GSM3494971,GSM3494972,GSM3494973,GSM3494974,GSM3494975,GSM3494976,GSM3494977,GSM3494978,GSM3494979,GSM3494980,GSM3494981,GSM3494982,GSM3494983,GSM3494984,GSM3494985,GSM3494986,GSM3494987,GSM3494988,GSM3494989,GSM3494990,GSM3494991,GSM3494992,GSM3494993,GSM3494994,GSM3494995,GSM3494996,GSM3494997,GSM3494998,GSM3494999,GSM3495000,GSM3495001,GSM3495002,GSM3495003,GSM3495004,GSM3495005,GSM3495006,GSM3495007,GSM3495008,GSM3495009,GSM3495010,GSM3495011,GSM3495012,GSM3495013,GSM3495014,GSM3495015,GSM3495016,GSM3495017,GSM3495018,GSM3495019,GSM3495020,GSM3495021,GSM3495022,GSM3495023,GSM3495024,GSM3495025,GSM3495026,GSM3495027,GSM3495028,GSM3495029,GSM3495030,GSM3495031,GSM3495032,GSM3495033,GSM3495034,GSM3495035,GSM3495036,GSM3495037,GSM3495038,GSM3495039,GSM3495040,GSM3495041,GSM3495042,GSM3495043,GSM3495044,GSM3495045,GSM3495046,GSM3495047,GSM3495048,GSM3495049
|
| 2 |
+
Obesity,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
|
| 3 |
+
Age,56.0,,20.0,51.0,37.0,61.0,,31.0,56.0,41.0,61.0,,80.0,53.0,61.0,73.0,60.0,76.0,77.0,74.0,69.0,77.0,81.0,70.0,82.0,69.0,82.0,67.0,67.0,78.0,67.0,74.0,,51.0,72.0,66.0,80.0,36.0,67.0,31.0,31.0,45.0,56.0,65.0,53.0,48.0,50.0,76.0,,24.0,42.0,76.0,22.0,,23.0,34.0,43.0,47.0,24.0,55.0,48.0,58.0,30.0,28.0,41.0,63.0,55.0,55.0,67.0,47.0,46.0,49.0,23.0,68.0,39.0,24.0,36.0,58.0,38.0,27.0,67.0,61.0,69.0,63.0,60.0,17.0,10.0,9.0,13.0,10.0,13.0,15.0,12.0,13.0,81.0,94.0,51.0,40.0,,97.0,23.0,93.0,58.0,28.0,54.0,15.0,8.0,11.0,12.0,8.0,14.0,8.0,10.0,14.0,13.0,40.0,52.0,42.0,29.0,43.0,41.0,54.0,42.0,49.0,45.0,56.0,64.0,71.0,48.0,20.0,53.0,32.0,26.0,28.0,47.0,24.0,48.0,,19.0,41.0,38.0,,15.0,12.0,13.0,,11.0,,16.0,11.0,,35.0,26.0,39.0,46.0,42.0,20.0,69.0,69.0,47.0,47.0,56.0,54.0,53.0,50.0,22.0
|
| 4 |
+
Gender,1.0,,0.0,0.0,1.0,1.0,,1.0,0.0,0.0,0.0,,1.0,1.0,1.0,1.0,1.0,1.0,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,1.0,,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,,0.0,0.0,1.0,1.0,,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,0.0,0.0,,0.0,1.0,0.0,,1.0,,1.0,1.0,,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0
|
output/preprocess/Obesity/clinical_data/GSE123088.csv
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
,GSM3494884,GSM3494885,GSM3494886,GSM3494887,GSM3494888,GSM3494889,GSM3494890,GSM3494891,GSM3494892,GSM3494893,GSM3494894,GSM3494895,GSM3494896,GSM3494897,GSM3494898,GSM3494899,GSM3494900,GSM3494901,GSM3494902,GSM3494903,GSM3494904,GSM3494905,GSM3494906,GSM3494907,GSM3494908,GSM3494909,GSM3494910,GSM3494911,GSM3494912,GSM3494913,GSM3494914,GSM3494915,GSM3494916,GSM3494917,GSM3494918,GSM3494919,GSM3494920,GSM3494921,GSM3494922,GSM3494923,GSM3494924,GSM3494925,GSM3494926,GSM3494927,GSM3494928,GSM3494929,GSM3494930,GSM3494931,GSM3494932,GSM3494933,GSM3494934,GSM3494935,GSM3494936,GSM3494937,GSM3494938,GSM3494939,GSM3494940,GSM3494941,GSM3494942,GSM3494943,GSM3494944,GSM3494945,GSM3494946,GSM3494947,GSM3494948,GSM3494949,GSM3494950,GSM3494951,GSM3494952,GSM3494953,GSM3494954,GSM3494955,GSM3494956,GSM3494957,GSM3494958,GSM3494959,GSM3494960,GSM3494961,GSM3494962,GSM3494963,GSM3494964,GSM3494965,GSM3494966,GSM3494967,GSM3494968,GSM3494969,GSM3494970,GSM3494971,GSM3494972,GSM3494973,GSM3494974,GSM3494975,GSM3494976,GSM3494977,GSM3494978,GSM3494979,GSM3494980,GSM3494981,GSM3494982,GSM3494983,GSM3494984,GSM3494985,GSM3494986,GSM3494987,GSM3494988,GSM3494989,GSM3494990,GSM3494991,GSM3494992,GSM3494993,GSM3494994,GSM3494995,GSM3494996,GSM3494997,GSM3494998,GSM3494999,GSM3495000,GSM3495001,GSM3495002,GSM3495003,GSM3495004,GSM3495005,GSM3495006,GSM3495007,GSM3495008,GSM3495009,GSM3495010,GSM3495011,GSM3495012,GSM3495013,GSM3495014,GSM3495015,GSM3495016,GSM3495017,GSM3495018,GSM3495019,GSM3495020,GSM3495021,GSM3495022,GSM3495023,GSM3495024,GSM3495025,GSM3495026,GSM3495027,GSM3495028,GSM3495029,GSM3495030,GSM3495031,GSM3495032,GSM3495033,GSM3495034,GSM3495035,GSM3495036,GSM3495037,GSM3495038,GSM3495039,GSM3495040,GSM3495041,GSM3495042,GSM3495043,GSM3495044,GSM3495045,GSM3495046,GSM3495047,GSM3495048,GSM3495049,GSM3495050,GSM3495051,GSM3495052,GSM3495053,GSM3495054,GSM3495055,GSM3495056,GSM3495057,GSM3495058,GSM3495059,GSM3495060,GSM3495061,GSM3495062,GSM3495063,GSM3495064,GSM3495065,GSM3495066,GSM3495067,GSM3495068,GSM3495069,GSM3495070,GSM3495071,GSM3495072,GSM3495073,GSM3495074,GSM3495075,GSM3495076,GSM3495077,GSM3495078,GSM3495079,GSM3495080,GSM3495081,GSM3495082,GSM3495083,GSM3495084,GSM3495085,GSM3495086,GSM3495087
|
| 2 |
-
Obesity,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0.0,0.0,,,0.0,,0.0,,,0.0,,0.0,0.0,,,0.0,,,,,,0.0,0.0,0.0,,,,,,0.0,,,,,0.0,0.0
|
| 3 |
Age,56.0,,20.0,51.0,37.0,61.0,,31.0,56.0,41.0,61.0,,80.0,53.0,61.0,73.0,60.0,76.0,77.0,74.0,69.0,77.0,81.0,70.0,82.0,69.0,82.0,67.0,67.0,78.0,67.0,74.0,,51.0,72.0,66.0,80.0,36.0,67.0,31.0,31.0,45.0,56.0,65.0,53.0,48.0,50.0,76.0,,24.0,42.0,76.0,22.0,,23.0,34.0,43.0,47.0,24.0,55.0,48.0,58.0,30.0,28.0,41.0,63.0,55.0,55.0,67.0,47.0,46.0,49.0,23.0,68.0,39.0,24.0,36.0,58.0,38.0,27.0,67.0,61.0,69.0,63.0,60.0,17.0,10.0,9.0,13.0,10.0,13.0,15.0,12.0,13.0,81.0,94.0,51.0,40.0,,97.0,23.0,93.0,58.0,28.0,54.0,15.0,8.0,11.0,12.0,8.0,14.0,8.0,10.0,14.0,13.0,40.0,52.0,42.0,29.0,43.0,41.0,54.0,42.0,49.0,45.0,56.0,64.0,71.0,48.0,20.0,53.0,32.0,26.0,28.0,47.0,24.0,48.0,,19.0,41.0,38.0,,15.0,12.0,13.0,,11.0,,16.0,11.0,,35.0,26.0,39.0,46.0,42.0,20.0,69.0,69.0,47.0,47.0,56.0,54.0,53.0,50.0,22.0,62.0,74.0,57.0,47.0,70.0,50.0,52.0,43.0,57.0,53.0,70.0,41.0,61.0,39.0,58.0,55.0,63.0,60.0,43.0,68.0,67.0,50.0,67.0,51.0,59.0,44.0,35.0,83.0,78.0,88.0,41.0,60.0,72.0,53.0,73.0,56.0,38.0,53.0
|
| 4 |
Gender,1.0,,0.0,0.0,1.0,1.0,,1.0,0.0,0.0,0.0,,1.0,1.0,1.0,1.0,1.0,1.0,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,1.0,,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,,0.0,0.0,1.0,1.0,,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,0.0,0.0,,0.0,1.0,0.0,,1.0,,1.0,1.0,,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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 |
,GSM3494884,GSM3494885,GSM3494886,GSM3494887,GSM3494888,GSM3494889,GSM3494890,GSM3494891,GSM3494892,GSM3494893,GSM3494894,GSM3494895,GSM3494896,GSM3494897,GSM3494898,GSM3494899,GSM3494900,GSM3494901,GSM3494902,GSM3494903,GSM3494904,GSM3494905,GSM3494906,GSM3494907,GSM3494908,GSM3494909,GSM3494910,GSM3494911,GSM3494912,GSM3494913,GSM3494914,GSM3494915,GSM3494916,GSM3494917,GSM3494918,GSM3494919,GSM3494920,GSM3494921,GSM3494922,GSM3494923,GSM3494924,GSM3494925,GSM3494926,GSM3494927,GSM3494928,GSM3494929,GSM3494930,GSM3494931,GSM3494932,GSM3494933,GSM3494934,GSM3494935,GSM3494936,GSM3494937,GSM3494938,GSM3494939,GSM3494940,GSM3494941,GSM3494942,GSM3494943,GSM3494944,GSM3494945,GSM3494946,GSM3494947,GSM3494948,GSM3494949,GSM3494950,GSM3494951,GSM3494952,GSM3494953,GSM3494954,GSM3494955,GSM3494956,GSM3494957,GSM3494958,GSM3494959,GSM3494960,GSM3494961,GSM3494962,GSM3494963,GSM3494964,GSM3494965,GSM3494966,GSM3494967,GSM3494968,GSM3494969,GSM3494970,GSM3494971,GSM3494972,GSM3494973,GSM3494974,GSM3494975,GSM3494976,GSM3494977,GSM3494978,GSM3494979,GSM3494980,GSM3494981,GSM3494982,GSM3494983,GSM3494984,GSM3494985,GSM3494986,GSM3494987,GSM3494988,GSM3494989,GSM3494990,GSM3494991,GSM3494992,GSM3494993,GSM3494994,GSM3494995,GSM3494996,GSM3494997,GSM3494998,GSM3494999,GSM3495000,GSM3495001,GSM3495002,GSM3495003,GSM3495004,GSM3495005,GSM3495006,GSM3495007,GSM3495008,GSM3495009,GSM3495010,GSM3495011,GSM3495012,GSM3495013,GSM3495014,GSM3495015,GSM3495016,GSM3495017,GSM3495018,GSM3495019,GSM3495020,GSM3495021,GSM3495022,GSM3495023,GSM3495024,GSM3495025,GSM3495026,GSM3495027,GSM3495028,GSM3495029,GSM3495030,GSM3495031,GSM3495032,GSM3495033,GSM3495034,GSM3495035,GSM3495036,GSM3495037,GSM3495038,GSM3495039,GSM3495040,GSM3495041,GSM3495042,GSM3495043,GSM3495044,GSM3495045,GSM3495046,GSM3495047,GSM3495048,GSM3495049,GSM3495050,GSM3495051,GSM3495052,GSM3495053,GSM3495054,GSM3495055,GSM3495056,GSM3495057,GSM3495058,GSM3495059,GSM3495060,GSM3495061,GSM3495062,GSM3495063,GSM3495064,GSM3495065,GSM3495066,GSM3495067,GSM3495068,GSM3495069,GSM3495070,GSM3495071,GSM3495072,GSM3495073,GSM3495074,GSM3495075,GSM3495076,GSM3495077,GSM3495078,GSM3495079,GSM3495080,GSM3495081,GSM3495082,GSM3495083,GSM3495084,GSM3495085,GSM3495086,GSM3495087
|
| 2 |
+
Obesity,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
|
| 3 |
Age,56.0,,20.0,51.0,37.0,61.0,,31.0,56.0,41.0,61.0,,80.0,53.0,61.0,73.0,60.0,76.0,77.0,74.0,69.0,77.0,81.0,70.0,82.0,69.0,82.0,67.0,67.0,78.0,67.0,74.0,,51.0,72.0,66.0,80.0,36.0,67.0,31.0,31.0,45.0,56.0,65.0,53.0,48.0,50.0,76.0,,24.0,42.0,76.0,22.0,,23.0,34.0,43.0,47.0,24.0,55.0,48.0,58.0,30.0,28.0,41.0,63.0,55.0,55.0,67.0,47.0,46.0,49.0,23.0,68.0,39.0,24.0,36.0,58.0,38.0,27.0,67.0,61.0,69.0,63.0,60.0,17.0,10.0,9.0,13.0,10.0,13.0,15.0,12.0,13.0,81.0,94.0,51.0,40.0,,97.0,23.0,93.0,58.0,28.0,54.0,15.0,8.0,11.0,12.0,8.0,14.0,8.0,10.0,14.0,13.0,40.0,52.0,42.0,29.0,43.0,41.0,54.0,42.0,49.0,45.0,56.0,64.0,71.0,48.0,20.0,53.0,32.0,26.0,28.0,47.0,24.0,48.0,,19.0,41.0,38.0,,15.0,12.0,13.0,,11.0,,16.0,11.0,,35.0,26.0,39.0,46.0,42.0,20.0,69.0,69.0,47.0,47.0,56.0,54.0,53.0,50.0,22.0,62.0,74.0,57.0,47.0,70.0,50.0,52.0,43.0,57.0,53.0,70.0,41.0,61.0,39.0,58.0,55.0,63.0,60.0,43.0,68.0,67.0,50.0,67.0,51.0,59.0,44.0,35.0,83.0,78.0,88.0,41.0,60.0,72.0,53.0,73.0,56.0,38.0,53.0
|
| 4 |
Gender,1.0,,0.0,0.0,1.0,1.0,,1.0,0.0,0.0,0.0,,1.0,1.0,1.0,1.0,1.0,1.0,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,1.0,,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,,0.0,0.0,1.0,1.0,,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,0.0,0.0,,0.0,1.0,0.0,,1.0,,1.0,1.0,,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
|
output/preprocess/Obesity/clinical_data/GSE158237.csv
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 1 |
+
,GSM4795701,GSM4795702,GSM4795703,GSM4795704,GSM4795705,GSM4795706,GSM4795707,GSM4795708,GSM4795709,GSM4795710,GSM4795711,GSM4795712,GSM4795713,GSM4795714,GSM4795715,GSM4795716,GSM4795717,GSM4795718,GSM4795719,GSM4795720,GSM4795721,GSM4795722,GSM4795723,GSM4795724,GSM4795725,GSM4795726,GSM4795727,GSM4795728,GSM4795729,GSM4795730,GSM4795731,GSM4795732,GSM4795733,GSM4795734,GSM4795735,GSM4795736,GSM4795737
|
| 2 |
+
Obesity,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,1.0,,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
|
| 3 |
+
Age,52.0,71.0,66.0,71.0,53.0,57.0,70.0,62.0,58.0,60.0,68.0,69.0,44.0,73.0,55.0,55.0,48.0,56.0,52.0,66.0,65.0,65.0,58.0,70.0,55.0,64.0,69.0,67.0,59.0,44.0,50.0,39.0,65.0,51.0,56.0,58.0,46.0
|
| 4 |
+
Gender,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0
|
output/preprocess/Obesity/clinical_data/GSE181339.csv
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
0.0,1.0,0.0,,,,,,,,,,,,,,,,,
|
| 3 |
-
21.0,23.0,
|
| 4 |
-
1.0,0.0,,,,,,,,,,,,,,,,,,
|
|
|
|
| 1 |
+
,GSM5494930,GSM5494931,GSM5494932,GSM5494933,GSM5494934,GSM5494935,GSM5494936,GSM5494937,GSM5494938,GSM5494939,GSM5494940,GSM5494941,GSM5494942,GSM5494943,GSM5494944,GSM5494945,GSM5494946,GSM5494947,GSM5494948,GSM5494949,GSM5494950,GSM5494951,GSM5494952,GSM5494953,GSM5494954,GSM5494955,GSM5494956,GSM5494957,GSM5494958,GSM5494959,GSM5494960,GSM5494961,GSM5494962,GSM5494963,GSM5494964,GSM5494965,GSM5494966,GSM5494967,GSM5494968,GSM5494969,GSM5494970,GSM5494971,GSM5494972,GSM5494973,GSM5494974,GSM5494975,GSM5494976,GSM5494977,GSM5494978,GSM5494979,GSM5494980,GSM5494981,GSM5494982,GSM5494983,GSM5494984,GSM5494985,GSM5494986,GSM5494987,GSM5494988,GSM5494989,GSM5494990,GSM5494991,GSM5494992,GSM5494993,GSM5494994,GSM5494995,GSM5494996,GSM5494997,GSM5494998,GSM5494999,GSM5495000,GSM5495001,GSM5495002,GSM5495003,GSM5495004,GSM5495005,GSM5495006,GSM5495007
|
| 2 |
+
Obesity,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0
|
| 3 |
+
Age,21.0,23.0,,17.0,,,18.0,,12.0,23.0,23.0,,,17.0,,,14.0,12.0,21.0,,26.0,,21.0,26.0,14.0,,,,,,,,26.0,,,,,,23.0,13.0,17.0,,,15.0,,,18.0,,21.0,17.0,21.0,,,18.0,13.0,,,,18.0,26.0,15.0,30.0,,17.0,21.0,,,,,,30.0,17.0,30.0,19.0,30.0,,,19.0
|
| 4 |
+
Gender,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.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,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0
|
output/preprocess/Obesity/clinical_data/GSE271700.csv
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
,
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
Gender,0.0,1.0,,,,,,,,,,,,,,,,
|
|
|
|
| 1 |
+
,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
|
| 2 |
+
Age,51.0,51.0,43.0,43.0,43.0,46.0,46.0,46.0,41.0,41.0,41.0,29.0,29.0,29.0,33.0,33.0,33.0,36.0,36.0,36.0,44.0,44.0,48.0,48.0,36.0,36.0,36.0,41.0,41.0,40.0,40.0,40.0,46.0,46.0,46.0,51.0,51.0,51.0,49.0,49.0,49.0,50.0,50.0,50.0,33.0,33.0,33.0,33.0,33.0,35.0,35.0,35.0,41.0,41.0,41.0,47.0,47.0,47.0,31.0,31.0,31.0,28.0,28.0,28.0,36.0,36.0,36.0,37.0,37.0,37.0,39.0,39.0,39.0
|
| 3 |
+
Gender,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,1.0,1.0,1.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,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,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0
|
|
|
output/preprocess/Obesity/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 |
+
Obesity,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,,,,,0.0,0.0,0.0,,,,,,,0.0,0.0,0.0,,,,,,
|
| 3 |
+
Gender,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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
|