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/Atherosclerosis/clinical_data/GSE123086.csv +4 -4
- output/preprocess/Atherosclerosis/clinical_data/GSE123088.csv +4 -4
- output/preprocess/Atherosclerosis/clinical_data/GSE57691.csv +1 -1
- output/preprocess/Atherosclerosis/code/GSE109048.py +306 -0
- output/preprocess/Atherosclerosis/code/GSE123086.py +551 -0
- output/preprocess/Atherosclerosis/code/GSE123088.py +268 -0
- output/preprocess/Atherosclerosis/code/GSE125771.py +223 -0
- output/preprocess/Atherosclerosis/code/GSE133601.py +259 -0
- output/preprocess/Atherosclerosis/code/GSE154851.py +258 -0
- output/preprocess/Atherosclerosis/code/GSE57691.py +216 -0
- output/preprocess/Atherosclerosis/code/GSE83500.py +129 -0
- output/preprocess/Atherosclerosis/code/GSE87005.py +222 -0
- output/preprocess/Atherosclerosis/code/GSE90074.py +238 -0
- output/preprocess/Atherosclerosis/code/TCGA.py +60 -0
- output/preprocess/Atherosclerosis/cohort_info.json +1 -82
- output/preprocess/Atherosclerosis/gene_data/GSE133601.csv +0 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE208662.csv +0 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE162635.csv +2 -2
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE208662.csv +2 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE212331.csv +4 -4
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE21359.csv +4 -4
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE32030.csv +2 -2
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE162635.py +165 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE175616.py +220 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE208662.py +198 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE210272.py +211 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE212331.py +203 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE21359.py +197 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE32030.py +119 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE64593.py +104 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE64599.py +203 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE84046.py +120 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/TCGA.py +73 -0
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/cohort_info.json +1 -112
- output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE210272.csv +1 -1
- output/preprocess/Fibromyalgia/code/GSE67311.py +193 -0
- output/preprocess/Fibromyalgia/code/TCGA.py +64 -0
- output/preprocess/Fibromyalgia/cohort_info.json +1 -22
- output/preprocess/Hypertension/code/GSE149256.py +126 -0
- output/preprocess/Hypertension/code/GSE151158.py +187 -0
- output/preprocess/Hypertension/code/GSE161533.py +199 -0
- output/preprocess/Hypertension/code/GSE181339.py +141 -0
- output/preprocess/Hypertension/code/GSE256539.py +125 -0
- output/preprocess/Hypertension/code/GSE71994.py +192 -0
- output/preprocess/Hypertension/code/GSE74144.py +169 -0
- output/preprocess/Hypertension/code/GSE77627.py +202 -0
- output/preprocess/Hypertension/code/TCGA.py +65 -0
- output/preprocess/Hypertrophic_Cardiomyopathy/code/GSE36961.py +196 -0
- output/preprocess/Hypertrophic_Cardiomyopathy/code/TCGA.py +60 -0
- output/preprocess/Hypertrophic_Cardiomyopathy/cohort_info.json +1 -22
output/preprocess/Atherosclerosis/clinical_data/GSE123086.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
|
| 2 |
-
|
| 3 |
-
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 |
-
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
|
|
|
|
| 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 |
+
Atherosclerosis,,,,,,,,,,,,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
| 3 |
+
Age,56.0,63.0,20.0,51.0,37.0,61.0,74.0,31.0,56.0,41.0,61.0,49.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,60.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,49.0,24.0,42.0,76.0,22.0,49.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,68.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,38.0,19.0,41.0,38.0,49.0,15.0,12.0,13.0,16.0,11.0,12.0,16.0,11.0,27.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/Atherosclerosis/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 |
-
|
| 3 |
-
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 |
-
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 |
+
Atherosclerosis,,,,,,,,,,,,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
|
| 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/Atherosclerosis/clinical_data/GSE57691.csv
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
,GSM1386783,GSM1386784,GSM1386785,GSM1386786,GSM1386787,GSM1386788,GSM1386789,GSM1386790,GSM1386791,GSM1386792,GSM1386793,GSM1386794,GSM1386795,GSM1386796,GSM1386797,GSM1386798,GSM1386799,GSM1386800,GSM1386801,GSM1386802,GSM1386803,GSM1386804,GSM1386805,GSM1386806,GSM1386807,GSM1386808,GSM1386809,GSM1386810,GSM1386811,GSM1386812,GSM1386813,GSM1386814,GSM1386815,GSM1386816,GSM1386817,GSM1386818,GSM1386819,GSM1386820,GSM1386821,GSM1386822,GSM1386823,GSM1386824,GSM1386825,GSM1386826,GSM1386827,GSM1386828,GSM1386829,GSM1386830,GSM1386831,GSM1386832,GSM1386833,GSM1386834,GSM1386835,GSM1386836,GSM1386837,GSM1386838,GSM1386839,GSM1386840,GSM1386841,GSM1386842,GSM1386843,GSM1386844,GSM1386845,GSM1386846,GSM1386847,GSM1386848,GSM1386849,GSM1386850
|
| 2 |
-
Atherosclerosis,
|
|
|
|
| 1 |
,GSM1386783,GSM1386784,GSM1386785,GSM1386786,GSM1386787,GSM1386788,GSM1386789,GSM1386790,GSM1386791,GSM1386792,GSM1386793,GSM1386794,GSM1386795,GSM1386796,GSM1386797,GSM1386798,GSM1386799,GSM1386800,GSM1386801,GSM1386802,GSM1386803,GSM1386804,GSM1386805,GSM1386806,GSM1386807,GSM1386808,GSM1386809,GSM1386810,GSM1386811,GSM1386812,GSM1386813,GSM1386814,GSM1386815,GSM1386816,GSM1386817,GSM1386818,GSM1386819,GSM1386820,GSM1386821,GSM1386822,GSM1386823,GSM1386824,GSM1386825,GSM1386826,GSM1386827,GSM1386828,GSM1386829,GSM1386830,GSM1386831,GSM1386832,GSM1386833,GSM1386834,GSM1386835,GSM1386836,GSM1386837,GSM1386838,GSM1386839,GSM1386840,GSM1386841,GSM1386842,GSM1386843,GSM1386844,GSM1386845,GSM1386846,GSM1386847,GSM1386848,GSM1386849,GSM1386850
|
| 2 |
+
Atherosclerosis,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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
|
output/preprocess/Atherosclerosis/code/GSE109048.py
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE109048"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE109048"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE109048.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE109048.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE109048.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
|
| 41 |
+
# 1) Gene expression availability
|
| 42 |
+
is_gene_available = True # Platelet gene expression profiling indicates mRNA GE data.
|
| 43 |
+
|
| 44 |
+
# 2) Variable availability and conversion
|
| 45 |
+
# Available keys from Sample Characteristics:
|
| 46 |
+
# {0: ['tissue: Platelets'], 1: ['diagnosis: sCAD', 'diagnosis: healthy', 'diagnosis: STEMI']}
|
| 47 |
+
trait_row = 1 # Use diagnosis to infer atherosclerosis presence
|
| 48 |
+
age_row = None
|
| 49 |
+
gender_row = None
|
| 50 |
+
|
| 51 |
+
def _after_colon(val):
|
| 52 |
+
if val is None:
|
| 53 |
+
return None
|
| 54 |
+
if isinstance(val, str):
|
| 55 |
+
parts = val.split(":", 1)
|
| 56 |
+
v = parts[1] if len(parts) > 1 else parts[0]
|
| 57 |
+
return v.strip()
|
| 58 |
+
return val
|
| 59 |
+
|
| 60 |
+
def convert_trait(x):
|
| 61 |
+
# Map any CAD/MI diagnosis to atherosclerosis present (1); healthy to 0; unknown -> None
|
| 62 |
+
v = _after_colon(x)
|
| 63 |
+
if v is None:
|
| 64 |
+
return None
|
| 65 |
+
vl = str(v).strip().lower()
|
| 66 |
+
# Positive mappings
|
| 67 |
+
pos_terms = {
|
| 68 |
+
"scad", "s-cad", "stable cad", "cad", "coronary artery disease",
|
| 69 |
+
"stemi", "ami", "acute myocardial infarction", "myocardial infarction", "mi"
|
| 70 |
+
}
|
| 71 |
+
if vl in pos_terms:
|
| 72 |
+
return 1
|
| 73 |
+
# Negative mappings
|
| 74 |
+
neg_terms = {"healthy", "control", "healthy donor", "hd"}
|
| 75 |
+
if vl in neg_terms:
|
| 76 |
+
return 0
|
| 77 |
+
# Heuristics
|
| 78 |
+
if "cad" in vl or "coronary" in vl:
|
| 79 |
+
return 1
|
| 80 |
+
if "infarction" in vl or "stemi" in vl or "ami" in vl or vl == "mi":
|
| 81 |
+
return 1
|
| 82 |
+
if "healthy" in vl or "control" in vl or vl == "hd":
|
| 83 |
+
return 0
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
def convert_age(x):
|
| 87 |
+
# Not available in this dataset
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
def convert_gender(x):
|
| 91 |
+
# Not available in this dataset
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
# 3) Save metadata with 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 (only if trait data is available)
|
| 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,
|
| 113 |
+
gender_row=gender_row,
|
| 114 |
+
convert_gender=convert_gender
|
| 115 |
+
)
|
| 116 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 117 |
+
|
| 118 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 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 |
+
# Affymetrix probe set IDs (e.g., '2824546_st') are not human gene symbols and require mapping.
|
| 130 |
+
requires_gene_mapping = True
|
| 131 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 132 |
+
|
| 133 |
+
# Step 5: Gene Annotation
|
| 134 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 135 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 136 |
+
|
| 137 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 138 |
+
print("Gene annotation preview:")
|
| 139 |
+
print(preview_df(gene_annotation))
|
| 140 |
+
|
| 141 |
+
# Step 6: Gene Identifier Mapping
|
| 142 |
+
import os
|
| 143 |
+
import re
|
| 144 |
+
import pandas as pd
|
| 145 |
+
|
| 146 |
+
# Preserve original probe-level data
|
| 147 |
+
expr_df = gene_data.copy()
|
| 148 |
+
expr_ids = set(expr_df.index.astype(str))
|
| 149 |
+
n_expr = len(expr_ids)
|
| 150 |
+
|
| 151 |
+
# Enumerate all SOFT files and pick the one with the highest overlap to expression IDs
|
| 152 |
+
soft_files = [os.path.join(in_cohort_dir, f) for f in os.listdir(in_cohort_dir) if 'soft' in f.lower()]
|
| 153 |
+
if not soft_files:
|
| 154 |
+
raise FileNotFoundError("No SOFT files found in cohort directory for annotation mapping.")
|
| 155 |
+
|
| 156 |
+
best = {
|
| 157 |
+
"file": None,
|
| 158 |
+
"annotation": None,
|
| 159 |
+
"probe_col": None,
|
| 160 |
+
"gene_col": None,
|
| 161 |
+
"mode": None, # 'direct' or 'add_st'
|
| 162 |
+
"overlap": 0
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
def compute_overlap(series: pd.Series, expr_ids: set) -> tuple:
|
| 166 |
+
# Returns (overlap_direct_count, overlap_add_st_count)
|
| 167 |
+
vals = series.astype(str).str.strip()
|
| 168 |
+
unique_vals = pd.unique(vals)
|
| 169 |
+
direct = set(unique_vals) & expr_ids
|
| 170 |
+
|
| 171 |
+
# Add "_st" to numeric-like tokens (support integers or floats ending with .0)
|
| 172 |
+
def to_num_str(x):
|
| 173 |
+
m = re.fullmatch(r'(\d+)(?:\.0)?', x)
|
| 174 |
+
return m.group(1) if m else None
|
| 175 |
+
|
| 176 |
+
numeric_vals = [to_num_str(v) for v in unique_vals]
|
| 177 |
+
numeric_vals = [v for v in numeric_vals if v is not None]
|
| 178 |
+
add_st = set(v + "_st" for v in numeric_vals) & expr_ids
|
| 179 |
+
|
| 180 |
+
return len(direct), len(add_st)
|
| 181 |
+
|
| 182 |
+
# Scan all SOFT files
|
| 183 |
+
for sfile in soft_files:
|
| 184 |
+
try:
|
| 185 |
+
ann = get_gene_annotation(sfile)
|
| 186 |
+
except Exception as e:
|
| 187 |
+
print(f"WARNING: Failed to parse SOFT file {sfile}: {e}")
|
| 188 |
+
continue
|
| 189 |
+
if ann is None or len(ann.columns) == 0:
|
| 190 |
+
continue
|
| 191 |
+
|
| 192 |
+
# Candidate gene symbol column
|
| 193 |
+
if 'gene_assignment' in ann.columns:
|
| 194 |
+
gene_col = 'gene_assignment'
|
| 195 |
+
elif 'mrna_assignment' in ann.columns:
|
| 196 |
+
gene_col = 'mrna_assignment'
|
| 197 |
+
else:
|
| 198 |
+
# fallback to any object/text column
|
| 199 |
+
obj_cols = [c for c in ann.columns if ann[c].dtype == 'object']
|
| 200 |
+
gene_col = obj_cols[0] if obj_cols else ann.columns[0]
|
| 201 |
+
|
| 202 |
+
# Evaluate all columns for overlap with expression IDs
|
| 203 |
+
for col in ann.columns:
|
| 204 |
+
# Skip the gene_col itself for probe matching if it's the same
|
| 205 |
+
try:
|
| 206 |
+
direct_cnt, addst_cnt = compute_overlap(ann[col], expr_ids)
|
| 207 |
+
except Exception:
|
| 208 |
+
continue
|
| 209 |
+
|
| 210 |
+
# Prefer direct match over add_st when counts tie (more reliable)
|
| 211 |
+
if direct_cnt > best["overlap"]:
|
| 212 |
+
best.update({"file": sfile, "annotation": ann, "probe_col": col, "gene_col": gene_col,
|
| 213 |
+
"mode": "direct", "overlap": direct_cnt})
|
| 214 |
+
elif addst_cnt > best["overlap"]:
|
| 215 |
+
best.update({"file": sfile, "annotation": ann, "probe_col": col, "gene_col": gene_col,
|
| 216 |
+
"mode": "add_st", "overlap": addst_cnt})
|
| 217 |
+
|
| 218 |
+
# Validate best match
|
| 219 |
+
if best["annotation"] is None or best["probe_col"] is None:
|
| 220 |
+
raise RuntimeError("Failed to identify any valid probe ID column from available SOFT files for mapping.")
|
| 221 |
+
|
| 222 |
+
coverage = best["overlap"] / max(1, n_expr)
|
| 223 |
+
print(f"Best SOFT: {os.path.basename(best['file'])}, probe_col: {best['probe_col']}, gene_col: {best['gene_col']}, "
|
| 224 |
+
f"mode: {best['mode']}, overlap: {best['overlap']} of {n_expr} ({coverage:.1%})")
|
| 225 |
+
|
| 226 |
+
# Fail fast on low coverage
|
| 227 |
+
if coverage < 0.20:
|
| 228 |
+
raise RuntimeError(f"Low probe-to-annotation ID overlap ({coverage:.1%}). "
|
| 229 |
+
f"Likely wrong platform annotation for IDs like '_st'. Aborting mapping.")
|
| 230 |
+
|
| 231 |
+
# Build mapping dataframe using the selected SOFT and columns
|
| 232 |
+
ann = best["annotation"]
|
| 233 |
+
probe_col = best["probe_col"]
|
| 234 |
+
gene_col = best["gene_col"]
|
| 235 |
+
mode = best["mode"]
|
| 236 |
+
|
| 237 |
+
mapping_df = ann[[probe_col, gene_col]].copy()
|
| 238 |
+
mapping_df.columns = ['ID_raw', 'Gene']
|
| 239 |
+
|
| 240 |
+
if mode == "direct":
|
| 241 |
+
mapping_df['ID'] = mapping_df['ID_raw'].astype(str).str.strip()
|
| 242 |
+
else:
|
| 243 |
+
# add "_st" to integer-like IDs; drop others
|
| 244 |
+
raw = mapping_df['ID_raw'].astype(str).str.strip()
|
| 245 |
+
extracted = raw.str.extract(r'^(\d+)(?:\.0)?$')[0]
|
| 246 |
+
mapping_df['ID'] = extracted.where(extracted.notna(), None)
|
| 247 |
+
mapping_df['ID'] = mapping_df['ID'].astype(object)
|
| 248 |
+
mapping_df['ID'] = mapping_df['ID'].map(lambda x: f"{x}_st" if pd.notnull(x) else None)
|
| 249 |
+
|
| 250 |
+
# Keep only valid rows and those present in expression data
|
| 251 |
+
mapping_df = mapping_df.dropna(subset=['ID', 'Gene'])
|
| 252 |
+
mapping_df = mapping_df[mapping_df['ID'].isin(expr_ids)]
|
| 253 |
+
|
| 254 |
+
# Apply mapping using helper (extracts human symbols, splits multi-gene probes, sums to gene level)
|
| 255 |
+
gene_data = apply_gene_mapping(expression_df=expr_df, mapping_df=mapping_df)
|
| 256 |
+
|
| 257 |
+
print(f"Mapped probes: {len(mapping_df)}; Resulting genes: {gene_data.shape[0]}")
|
| 258 |
+
|
| 259 |
+
# Step 7: Gene Identifier Mapping
|
| 260 |
+
import pandas as pd
|
| 261 |
+
|
| 262 |
+
# Start from the probe-level matrix loaded earlier
|
| 263 |
+
expr_df = gene_data.copy()
|
| 264 |
+
# Ensure numeric expression values to avoid arithmetic errors during mapping
|
| 265 |
+
expr_df = expr_df.apply(pd.to_numeric, errors='coerce')
|
| 266 |
+
|
| 267 |
+
# Load SOFT annotation
|
| 268 |
+
ann = get_gene_annotation(soft_file)
|
| 269 |
+
|
| 270 |
+
# Identify the best probe ID column by overlap with expression IDs
|
| 271 |
+
expr_ids = set(expr_df.index.astype(str))
|
| 272 |
+
overlaps = {}
|
| 273 |
+
for col in ann.columns:
|
| 274 |
+
try:
|
| 275 |
+
s = ann[col].astype(str).str.strip()
|
| 276 |
+
overlaps[col] = s.isin(expr_ids).sum()
|
| 277 |
+
except Exception:
|
| 278 |
+
overlaps[col] = -1
|
| 279 |
+
|
| 280 |
+
# Choose the column with maximum direct overlap
|
| 281 |
+
probe_col = max(overlaps, key=overlaps.get)
|
| 282 |
+
overlap_count = overlaps[probe_col]
|
| 283 |
+
|
| 284 |
+
# Choose gene symbol-containing column with preference order
|
| 285 |
+
if 'gene_assignment' in ann.columns:
|
| 286 |
+
gene_col = 'gene_assignment'
|
| 287 |
+
elif 'mrna_assignment' in ann.columns:
|
| 288 |
+
gene_col = 'mrna_assignment'
|
| 289 |
+
else:
|
| 290 |
+
# Fallback: pick a column name containing 'gene' (case-insensitive), else last column
|
| 291 |
+
gene_like = [c for c in ann.columns if 'gene' in c.lower()]
|
| 292 |
+
gene_col = gene_like[0] if gene_like else ann.columns[-1]
|
| 293 |
+
|
| 294 |
+
print(f"Selected mapping columns -> probe_col: {probe_col}, gene_col: {gene_col}")
|
| 295 |
+
total_probes = len(expr_ids)
|
| 296 |
+
coverage = overlap_count / max(1, total_probes)
|
| 297 |
+
print(f"Direct ID overlap: {overlap_count} of {total_probes} ({coverage:.1%})")
|
| 298 |
+
|
| 299 |
+
# Build mapping dataframe and restrict to available probes
|
| 300 |
+
mapping_df = get_gene_mapping(annotation=ann, prob_col=probe_col, gene_col=gene_col)
|
| 301 |
+
mapping_df = mapping_df[mapping_df['ID'].isin(expr_ids)]
|
| 302 |
+
|
| 303 |
+
# Apply mapping to obtain gene-level expression
|
| 304 |
+
gene_data = apply_gene_mapping(expression_df=expr_df, mapping_df=mapping_df)
|
| 305 |
+
|
| 306 |
+
print(f"Mapped probes used: {mapping_df['ID'].nunique()}; Resulting genes: {gene_data.shape[0]}")
|
output/preprocess/Atherosclerosis/code/GSE123086.py
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE123086"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE123086"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE123086.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE123086.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE123086.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
|
| 41 |
+
# 1) Determine gene expression availability
|
| 42 |
+
is_gene_available = True # Agilent one-color microarray-based gene expression per background info
|
| 43 |
+
|
| 44 |
+
# 2) Identify rows and define converters
|
| 45 |
+
trait_row = 1 # 'primary diagnosis' includes ATHEROSCLEROSIS and HEALTHY_CONTROL among others
|
| 46 |
+
age_row = 3 # contains most 'age:' entries (row 4 also has some ages but row 3 is more complete)
|
| 47 |
+
gender_row = 2 # contains 'Sex: Female' and 'Sex: Male' (though mixed with diagnosis2 entries)
|
| 48 |
+
|
| 49 |
+
def _extract_value(cell):
|
| 50 |
+
if cell is None:
|
| 51 |
+
return None
|
| 52 |
+
s = str(cell)
|
| 53 |
+
if ':' in s:
|
| 54 |
+
return s.split(':', 1)[1].strip()
|
| 55 |
+
return s.strip()
|
| 56 |
+
|
| 57 |
+
def convert_trait(cell):
|
| 58 |
+
v = _extract_value(cell)
|
| 59 |
+
if v is None or v == '':
|
| 60 |
+
return None
|
| 61 |
+
v_up = v.upper().strip()
|
| 62 |
+
# 1 = ATHEROSCLEROSIS; 0 = HEALTHY_CONTROL; Others set to None to avoid mixing with other diseases
|
| 63 |
+
if v_up == 'ATHEROSCLEROSIS':
|
| 64 |
+
return 1
|
| 65 |
+
if v_up == 'HEALTHY_CONTROL':
|
| 66 |
+
return 0
|
| 67 |
+
return None
|
| 68 |
+
|
| 69 |
+
def convert_age(cell):
|
| 70 |
+
v = _extract_value(cell)
|
| 71 |
+
if v is None or v == '':
|
| 72 |
+
return None
|
| 73 |
+
try:
|
| 74 |
+
val = float(v)
|
| 75 |
+
if 0 <= val <= 120:
|
| 76 |
+
return val
|
| 77 |
+
return None
|
| 78 |
+
except Exception:
|
| 79 |
+
return None
|
| 80 |
+
|
| 81 |
+
def convert_gender(cell):
|
| 82 |
+
v = _extract_value(cell)
|
| 83 |
+
if v is None or v == '':
|
| 84 |
+
return None
|
| 85 |
+
v_low = v.lower()
|
| 86 |
+
if v_low.startswith('male'):
|
| 87 |
+
return 1
|
| 88 |
+
if v_low.startswith('female'):
|
| 89 |
+
return 0
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
# 3) Save initial metadata
|
| 93 |
+
is_trait_available = trait_row is not None
|
| 94 |
+
_ = validate_and_save_cohort_info(
|
| 95 |
+
is_final=False,
|
| 96 |
+
cohort=cohort,
|
| 97 |
+
info_path=json_path,
|
| 98 |
+
is_gene_available=is_gene_available,
|
| 99 |
+
is_trait_available=is_trait_available
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
# 4) Clinical Feature Extraction (only if trait data 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 |
+
# Improve age completeness by filling missing Age with values from row 4
|
| 115 |
+
try:
|
| 116 |
+
age_row4_df = get_feature_data(clinical_data, 4, 'Age', convert_age)
|
| 117 |
+
if 'Age' in selected_clinical_df.index and 'Age' in age_row4_df.index:
|
| 118 |
+
selected_clinical_df.loc['Age'] = selected_clinical_df.loc['Age'].fillna(age_row4_df.loc['Age'])
|
| 119 |
+
except Exception:
|
| 120 |
+
pass # Fallback silently if the helper isn't available or row 4 doesn't exist
|
| 121 |
+
|
| 122 |
+
preview = preview_df(selected_clinical_df)
|
| 123 |
+
print(preview)
|
| 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 |
+
import os
|
| 136 |
+
import re
|
| 137 |
+
import pandas as pd
|
| 138 |
+
|
| 139 |
+
def infer_requires_mapping_from_ids(ids):
|
| 140 |
+
# Sample up to 1000 IDs for speed
|
| 141 |
+
sample = pd.Series(ids).astype(str).dropna().unique()
|
| 142 |
+
sample = sample[:1000]
|
| 143 |
+
if len(sample) == 0:
|
| 144 |
+
return True # conservative default
|
| 145 |
+
|
| 146 |
+
def is_numeric(s):
|
| 147 |
+
return s.isdigit()
|
| 148 |
+
|
| 149 |
+
def is_ensembl(s):
|
| 150 |
+
s = s.upper()
|
| 151 |
+
return s.startswith('ENSG') or s.startswith('ENST') or s.startswith('ENSP')
|
| 152 |
+
|
| 153 |
+
def is_probe_like(s):
|
| 154 |
+
su = s.upper()
|
| 155 |
+
return (
|
| 156 |
+
'_AT' in su or su.startswith('ILMN_') or su.startswith('A_') or su.startswith('AFFX') or
|
| 157 |
+
su.startswith('GPL') or su.startswith('GSM') or su.startswith('GSE') or su.startswith('XM_') or
|
| 158 |
+
su.startswith('XR_') or su.startswith('NR_') or su.startswith('NM_')
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
# Gene symbol heuristic: letters with optional digits/hyphen/dot; exclude numeric and known other IDs
|
| 162 |
+
sym_regex = re.compile(r'^[A-Za-z][A-Za-z0-9\-\.]*$')
|
| 163 |
+
|
| 164 |
+
n_numeric = sum(is_numeric(s) for s in sample)
|
| 165 |
+
n_ensembl = sum(is_ensembl(s) for s in sample)
|
| 166 |
+
n_probe = sum(is_probe_like(s) for s in sample)
|
| 167 |
+
n_symbol_like = sum(bool(sym_regex.match(s)) and not (is_numeric(s) or is_ensembl(s) or is_probe_like(s)) for s in sample)
|
| 168 |
+
|
| 169 |
+
n = len(sample)
|
| 170 |
+
# If most are numeric/ensembl/probe-like, mapping is required
|
| 171 |
+
frac_non_symbol = (n_numeric + n_ensembl + n_probe) / n if n > 0 else 1.0
|
| 172 |
+
if frac_non_symbol >= 0.6:
|
| 173 |
+
return True
|
| 174 |
+
# If symbol-like dominate, no mapping needed
|
| 175 |
+
if n_symbol_like / n >= 0.6:
|
| 176 |
+
return False
|
| 177 |
+
# Default conservative: mapping required
|
| 178 |
+
return True
|
| 179 |
+
|
| 180 |
+
requires_gene_mapping = True # default conservative
|
| 181 |
+
try:
|
| 182 |
+
if os.path.exists(out_gene_data_file):
|
| 183 |
+
df_gene = pd.read_csv(out_gene_data_file, index_col=0)
|
| 184 |
+
gene_ids = df_gene.index.tolist()
|
| 185 |
+
requires_gene_mapping = infer_requires_mapping_from_ids(gene_ids)
|
| 186 |
+
else:
|
| 187 |
+
# If file not present, rely on observed IDs in the prompt (numeric-like), so mapping needed
|
| 188 |
+
requires_gene_mapping = True
|
| 189 |
+
except Exception:
|
| 190 |
+
requires_gene_mapping = True
|
| 191 |
+
|
| 192 |
+
print(f"requires_gene_mapping = {str(requires_gene_mapping)}")
|
| 193 |
+
|
| 194 |
+
# Step 5: Gene Annotation
|
| 195 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 196 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 197 |
+
|
| 198 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 199 |
+
print("Gene annotation preview:")
|
| 200 |
+
print(preview_df(gene_annotation))
|
| 201 |
+
|
| 202 |
+
# Step 6: Gene Identifier Mapping
|
| 203 |
+
import os
|
| 204 |
+
import re
|
| 205 |
+
import pandas as pd
|
| 206 |
+
from tools.preprocess import (
|
| 207 |
+
get_gene_annotation,
|
| 208 |
+
get_gene_mapping,
|
| 209 |
+
apply_gene_mapping,
|
| 210 |
+
normalize_gene_symbols_in_index,
|
| 211 |
+
extract_human_gene_symbols
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
# Preserve the original probe-level expression matrix from Step 3
|
| 215 |
+
expr_df = gene_data.copy()
|
| 216 |
+
|
| 217 |
+
def _normalize_str_series(s: pd.Series) -> pd.Series:
|
| 218 |
+
s = s.astype(str).str.strip()
|
| 219 |
+
s = s.str.replace(r'\.0$', '', regex=True)
|
| 220 |
+
return s
|
| 221 |
+
|
| 222 |
+
# Prefer platform (GPL) SOFT file if available to obtain richer annotation (including gene symbols)
|
| 223 |
+
try:
|
| 224 |
+
files = os.listdir(in_cohort_dir)
|
| 225 |
+
gpl_softs = [f for f in files if ('soft' in f.lower()) and ('gpl' in f.lower())]
|
| 226 |
+
soft_ann = os.path.join(in_cohort_dir, gpl_softs[0]) if len(gpl_softs) > 0 else soft_file
|
| 227 |
+
except Exception:
|
| 228 |
+
soft_ann = soft_file
|
| 229 |
+
|
| 230 |
+
# Load platform annotation
|
| 231 |
+
ga = get_gene_annotation(soft_ann).copy()
|
| 232 |
+
|
| 233 |
+
# Determine identifier column by maximizing unique overlap with expression IDs
|
| 234 |
+
expr_ids = pd.Index(expr_df.index.astype(str)).str.replace(r'\.0$', '', regex=True)
|
| 235 |
+
expr_ids_set = set(expr_ids)
|
| 236 |
+
|
| 237 |
+
best_id_col = None
|
| 238 |
+
best_overlap_unique = -1
|
| 239 |
+
|
| 240 |
+
for col in ga.columns:
|
| 241 |
+
col_vals = _normalize_str_series(ga[col])
|
| 242 |
+
overlap_unique = col_vals[col_vals.isin(expr_ids)].nunique()
|
| 243 |
+
if overlap_unique > best_overlap_unique:
|
| 244 |
+
best_overlap_unique = overlap_unique
|
| 245 |
+
best_id_col = col
|
| 246 |
+
|
| 247 |
+
# Fallback if none detected
|
| 248 |
+
if best_id_col is None:
|
| 249 |
+
for c in ['ID', 'SPOT_ID', 'PROBE_ID']:
|
| 250 |
+
if c in ga.columns:
|
| 251 |
+
best_id_col = c
|
| 252 |
+
break
|
| 253 |
+
|
| 254 |
+
print(f"Selected identifier column: {best_id_col} with unique overlap {best_overlap_unique} against {len(expr_ids_set)} probes")
|
| 255 |
+
|
| 256 |
+
# Try to find a gene symbol column
|
| 257 |
+
symbol_col_candidates = [
|
| 258 |
+
'Gene Symbol', 'GENE_SYMBOL', 'GENE SYMBOL', 'Gene symbol', 'SYMBOL',
|
| 259 |
+
'GENE_SYMBOLS', 'GeneSymbol', 'Gene.symbol', 'Gene Symbol(s)', 'GeneSymbol(s)',
|
| 260 |
+
'GENE_NAME', 'GENE', 'Symbol', 'GENE NAME'
|
| 261 |
+
]
|
| 262 |
+
gene_symbol_col = None
|
| 263 |
+
for c in symbol_col_candidates:
|
| 264 |
+
if c in ga.columns:
|
| 265 |
+
gene_symbol_col = c
|
| 266 |
+
break
|
| 267 |
+
|
| 268 |
+
# If explicit symbol column not present, attempt inference from any non-ID column by extracting symbol-like tokens
|
| 269 |
+
if gene_symbol_col is None:
|
| 270 |
+
min_rows = max(20, int(0.02 * len(ga))) # at least 2% of rows or 20 rows carry symbols
|
| 271 |
+
inferred_col = None
|
| 272 |
+
inferred_support = 0
|
| 273 |
+
for col in ga.columns:
|
| 274 |
+
if col == best_id_col:
|
| 275 |
+
continue
|
| 276 |
+
series = ga[col].astype(str).map(extract_human_gene_symbols)
|
| 277 |
+
count_nonempty = series.apply(lambda x: len(x) if isinstance(x, list) else 0).gt(0).sum()
|
| 278 |
+
if count_nonempty > inferred_support:
|
| 279 |
+
inferred_support = count_nonempty
|
| 280 |
+
inferred_col = col
|
| 281 |
+
if inferred_col is not None and inferred_support >= min_rows:
|
| 282 |
+
gene_symbol_col = inferred_col
|
| 283 |
+
print(f"Inferred gene symbol source column: {gene_symbol_col} (rows with symbol-like tokens: {inferred_support})")
|
| 284 |
+
|
| 285 |
+
# Build mapping and convert to gene-level with gene symbols when possible
|
| 286 |
+
def _build_symbol_mapping_and_apply(ga: pd.DataFrame, id_col: str, sym_col: str) -> pd.DataFrame:
|
| 287 |
+
m = get_gene_mapping(annotation=ga, prob_col=id_col, gene_col=sym_col)
|
| 288 |
+
# Normalize ID strings and filter to measured probes
|
| 289 |
+
m['ID'] = _normalize_str_series(m['ID'])
|
| 290 |
+
m = m[m['ID'].isin(expr_ids_set)]
|
| 291 |
+
# Remove exact duplicate (ID, Gene) pairs to avoid expansion
|
| 292 |
+
m = m.drop_duplicates(subset=['ID', 'Gene'])
|
| 293 |
+
# Apply mapping with the library helper (extracts human symbols internally, splits multi-gene probes, sums)
|
| 294 |
+
gd = apply_gene_mapping(expression_df=expr_df, mapping_df=m)
|
| 295 |
+
# Canonicalize gene symbols using synonym table
|
| 296 |
+
try:
|
| 297 |
+
gd = normalize_gene_symbols_in_index(gd)
|
| 298 |
+
except Exception as e:
|
| 299 |
+
print(f"INFO: Gene symbol normalization skipped or partially applied: {e}")
|
| 300 |
+
return gd
|
| 301 |
+
|
| 302 |
+
# Fallback: build Entrez-indexed matrix, and optionally convert Entrez -> symbol using annotation if possible
|
| 303 |
+
def _build_entrez_mapping_and_apply(ga: pd.DataFrame, id_col: str, optional_sym_col: str = None) -> pd.DataFrame:
|
| 304 |
+
if 'ENTREZ_GENE_ID' not in ga.columns:
|
| 305 |
+
raise RuntimeError("No gene symbol and no ENTREZ_GENE_ID available in annotation; cannot proceed.")
|
| 306 |
+
|
| 307 |
+
m = get_gene_mapping(annotation=ga, prob_col=id_col, gene_col='ENTREZ_GENE_ID')
|
| 308 |
+
m['ID'] = _normalize_str_series(m['ID'])
|
| 309 |
+
m = m[m['ID'].isin(expr_ids_set)]
|
| 310 |
+
# Split mapping values; keep only numeric Entrez IDs
|
| 311 |
+
def split_keep_numeric(x: str):
|
| 312 |
+
if pd.isna(x):
|
| 313 |
+
return []
|
| 314 |
+
s = str(x)
|
| 315 |
+
nums = re.findall(r'\d+', s)
|
| 316 |
+
# cap to avoid pathological many-to-many expansion
|
| 317 |
+
if len(nums) > 5:
|
| 318 |
+
nums = nums[:5]
|
| 319 |
+
return nums
|
| 320 |
+
m['Gene'] = m['Gene'].astype(str).map(split_keep_numeric)
|
| 321 |
+
m = m.explode('Gene').dropna(subset=['Gene'])
|
| 322 |
+
m = m[m['Gene'].astype(str).str.strip() != '']
|
| 323 |
+
m = m.drop_duplicates(subset=['ID', 'Gene'])
|
| 324 |
+
|
| 325 |
+
merged = m.set_index('ID').join(expr_df, how='inner')
|
| 326 |
+
expr_cols = [c for c in merged.columns if c not in ['Gene']]
|
| 327 |
+
# If a probe maps to multiple Entrez IDs, divide equally
|
| 328 |
+
counts_per_id = m.groupby('ID')['Gene'].nunique()
|
| 329 |
+
merged = merged.join(counts_per_id.rename('num_genes'), on='ID')
|
| 330 |
+
merged['num_genes'] = merged['num_genes'].fillna(1)
|
| 331 |
+
merged[expr_cols] = merged[expr_cols].div(merged['num_genes'], axis=0)
|
| 332 |
+
gd_entrez = merged.groupby('Gene')[expr_cols].sum()
|
| 333 |
+
|
| 334 |
+
# Optional: convert Entrez -> symbols using annotation if an appropriate column exists
|
| 335 |
+
if optional_sym_col and optional_sym_col in ga.columns:
|
| 336 |
+
entrez_to_sym = ga[['ENTREZ_GENE_ID', optional_sym_col]].dropna()
|
| 337 |
+
entrez_to_sym['ENTREZ_GENE_ID'] = entrez_to_sym['ENTREZ_GENE_ID'].astype(str).str.extract(r'(\d+)')
|
| 338 |
+
entrez_to_sym = entrez_to_sym.dropna(subset=['ENTREZ_GENE_ID'])
|
| 339 |
+
# Extract a single canonical symbol from the optional_sym_col
|
| 340 |
+
entrez_to_sym['SYMBOL_EXTRACT'] = entrez_to_sym[optional_sym_col].astype(str).map(lambda t: (extract_human_gene_symbols(t) or [None])[0])
|
| 341 |
+
entrez_to_sym = entrez_to_sym.dropna(subset=['SYMBOL_EXTRACT'])
|
| 342 |
+
# Build mapping dict
|
| 343 |
+
e2s = entrez_to_sym.drop_duplicates(subset=['ENTREZ_GENE_ID']).set_index('ENTREZ_GENE_ID')['SYMBOL_EXTRACT'].to_dict()
|
| 344 |
+
# Map index and aggregate
|
| 345 |
+
idx = gd_entrez.index.astype(str)
|
| 346 |
+
sym_index = idx.map(lambda x: e2s.get(re.findall(r'\d+', x)[0], None) if re.findall(r'\d+', x) else None)
|
| 347 |
+
gd_sym = gd_entrez.copy()
|
| 348 |
+
gd_sym.index = sym_index
|
| 349 |
+
gd_sym = gd_sym[gd_sym.index.notnull()]
|
| 350 |
+
if len(gd_sym) > 0:
|
| 351 |
+
try:
|
| 352 |
+
gd_sym = normalize_gene_symbols_in_index(gd_sym)
|
| 353 |
+
except Exception as e:
|
| 354 |
+
print(f"INFO: Gene symbol normalization skipped or partially applied: {e}")
|
| 355 |
+
return gd_sym
|
| 356 |
+
|
| 357 |
+
# Return Entrez-indexed if symbol conversion not possible
|
| 358 |
+
return gd_entrez
|
| 359 |
+
|
| 360 |
+
gene_data_mapped = None
|
| 361 |
+
used_symbol_col = None
|
| 362 |
+
|
| 363 |
+
# First attempt: use a symbol-bearing column (explicit or inferred)
|
| 364 |
+
if gene_symbol_col is not None:
|
| 365 |
+
try:
|
| 366 |
+
gene_data_mapped = _build_symbol_mapping_and_apply(ga, best_id_col, gene_symbol_col)
|
| 367 |
+
used_symbol_col = gene_symbol_col
|
| 368 |
+
print(f"Gene-level matrix constructed using symbol column '{gene_symbol_col}'. Shape: {gene_data_mapped.shape}")
|
| 369 |
+
except Exception as e:
|
| 370 |
+
print(f"WARNING: Symbol-based mapping failed with error: {e}")
|
| 371 |
+
|
| 372 |
+
# Sanity checks; if failed or implausible, fallback to Entrez-based mapping
|
| 373 |
+
def _is_implausible(df: pd.DataFrame) -> bool:
|
| 374 |
+
if df is None or len(df) == 0:
|
| 375 |
+
return True
|
| 376 |
+
n_genes = df.shape[0]
|
| 377 |
+
return (n_genes < 500) or (n_genes > 100000)
|
| 378 |
+
|
| 379 |
+
if _is_implausible(gene_data_mapped):
|
| 380 |
+
print("INFO: Symbol mapping implausible or unavailable; falling back to Entrez-based mapping.")
|
| 381 |
+
gene_data_mapped = _build_entrez_mapping_and_apply(ga, best_id_col, optional_sym_col=used_symbol_col)
|
| 382 |
+
# If still too many genes, try a light filter: retain genes with finite variance and drop any empty rows (should be none)
|
| 383 |
+
if gene_data_mapped.shape[0] > 120000:
|
| 384 |
+
print(f"WARNING: Entrez-based mapping produced {gene_data_mapped.shape[0]} genes; attempting de-duplication and sanity reduction.")
|
| 385 |
+
gene_data_mapped = gene_data_mapped.groupby(gene_data_mapped.index).sum()
|
| 386 |
+
# Remove rows that are all zeros (unlikely but safe)
|
| 387 |
+
nonzero_mask = (gene_data_mapped.abs().sum(axis=1) > 0)
|
| 388 |
+
gene_data_mapped = gene_data_mapped.loc[nonzero_mask]
|
| 389 |
+
print(f"Post-filter gene count: {gene_data_mapped.shape[0]}")
|
| 390 |
+
|
| 391 |
+
# Final assignment
|
| 392 |
+
gene_data = gene_data_mapped
|
| 393 |
+
print(f"Final gene-level data shape: {gene_data.shape}")
|
| 394 |
+
|
| 395 |
+
# Persist gene-level data
|
| 396 |
+
try:
|
| 397 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 398 |
+
gene_data.to_csv(out_gene_data_file)
|
| 399 |
+
print(f"Saved gene-level data to {out_gene_data_file}")
|
| 400 |
+
except Exception as e:
|
| 401 |
+
print(f"INFO: Could not save gene-level data to file: {e}")
|
| 402 |
+
|
| 403 |
+
# Step 7: Gene Identifier Mapping
|
| 404 |
+
import os
|
| 405 |
+
import re
|
| 406 |
+
import pandas as pd
|
| 407 |
+
|
| 408 |
+
# Re-load the original probe-level expression matrix to avoid propagating any prior incorrect mappings
|
| 409 |
+
expr_df = get_genetic_data(matrix_file)
|
| 410 |
+
|
| 411 |
+
def _normalize_str_series(s: pd.Series) -> pd.Series:
|
| 412 |
+
return s.astype(str).str.strip().str.replace(r'\.0$', '', regex=True)
|
| 413 |
+
|
| 414 |
+
# Prefer a platform (GPL) SOFT if present; otherwise use the existing soft_file
|
| 415 |
+
try:
|
| 416 |
+
files = os.listdir(in_cohort_dir)
|
| 417 |
+
gpl_softs = [f for f in files if ('soft' in f.lower()) and ('gpl' in f.lower())]
|
| 418 |
+
soft_ann = os.path.join(in_cohort_dir, gpl_softs[0]) if len(gpl_softs) > 0 else soft_file
|
| 419 |
+
except Exception:
|
| 420 |
+
soft_ann = soft_file
|
| 421 |
+
|
| 422 |
+
ga = get_gene_annotation(soft_ann).copy()
|
| 423 |
+
|
| 424 |
+
# Determine which annotation column matches the expression IDs (max overlap)
|
| 425 |
+
expr_ids = pd.Index(expr_df.index.astype(str)).str.replace(r'\.0$', '', regex=True)
|
| 426 |
+
expr_ids_set = set(expr_ids)
|
| 427 |
+
best_id_col, best_overlap = None, -1
|
| 428 |
+
for col in ga.columns:
|
| 429 |
+
col_vals = _normalize_str_series(ga[col])
|
| 430 |
+
overlap = col_vals[col_vals.isin(expr_ids)].nunique()
|
| 431 |
+
if overlap > best_overlap:
|
| 432 |
+
best_overlap = overlap
|
| 433 |
+
best_id_col = col
|
| 434 |
+
|
| 435 |
+
if best_id_col is None:
|
| 436 |
+
# Fallback to common identifier columns if overlap heuristic fails
|
| 437 |
+
for c in ['ID', 'SPOT_ID', 'PROBE_ID']:
|
| 438 |
+
if c in ga.columns:
|
| 439 |
+
best_id_col = c
|
| 440 |
+
break
|
| 441 |
+
if best_id_col is None:
|
| 442 |
+
raise RuntimeError("Could not determine an annotation identifier column matching expression IDs.")
|
| 443 |
+
|
| 444 |
+
# Try to find a gene symbol column
|
| 445 |
+
symbol_col_candidates = [
|
| 446 |
+
'Gene Symbol', 'GENE_SYMBOL', 'GENE SYMBOL', 'Gene symbol', 'SYMBOL',
|
| 447 |
+
'GENE_SYMBOLS', 'GeneSymbol', 'Gene.symbol', 'Gene Symbol(s)', 'GeneSymbol(s)',
|
| 448 |
+
'GENE_NAME', 'GENE', 'Symbol', 'GENE NAME'
|
| 449 |
+
]
|
| 450 |
+
gene_symbol_col = None
|
| 451 |
+
for c in symbol_col_candidates:
|
| 452 |
+
if c in ga.columns:
|
| 453 |
+
gene_symbol_col = c
|
| 454 |
+
break
|
| 455 |
+
|
| 456 |
+
# If not found, try to infer a column that contains human gene symbols
|
| 457 |
+
if gene_symbol_col is None:
|
| 458 |
+
inferred_col = None
|
| 459 |
+
inferred_support = 0
|
| 460 |
+
for col in ga.columns:
|
| 461 |
+
if col == best_id_col:
|
| 462 |
+
continue
|
| 463 |
+
series = ga[col].astype(str).map(extract_human_gene_symbols)
|
| 464 |
+
count_nonempty = series.apply(lambda x: len(x) if isinstance(x, list) else 0).gt(0).sum()
|
| 465 |
+
if count_nonempty > inferred_support:
|
| 466 |
+
inferred_support = count_nonempty
|
| 467 |
+
inferred_col = col
|
| 468 |
+
# Require at least some reasonable support (>1% rows) to accept inference
|
| 469 |
+
if inferred_col is not None and inferred_support >= max(20, int(0.01 * len(ga))):
|
| 470 |
+
gene_symbol_col = inferred_col
|
| 471 |
+
|
| 472 |
+
# Mapping and aggregation
|
| 473 |
+
def _apply_symbol_mapping(ga: pd.DataFrame, id_col: str, sym_col: str) -> pd.DataFrame:
|
| 474 |
+
m = get_gene_mapping(annotation=ga, prob_col=id_col, gene_col=sym_col)
|
| 475 |
+
m['ID'] = _normalize_str_series(m['ID'])
|
| 476 |
+
# Keep only mappings for probes present in expression matrix
|
| 477 |
+
m = m[m['ID'].isin(expr_ids_set)].drop_duplicates(subset=['ID', 'Gene'])
|
| 478 |
+
gd = apply_gene_mapping(expression_df=expr_df, mapping_df=m)
|
| 479 |
+
# Normalize symbols if possible
|
| 480 |
+
try:
|
| 481 |
+
gd = normalize_gene_symbols_in_index(gd)
|
| 482 |
+
except Exception:
|
| 483 |
+
pass
|
| 484 |
+
return gd
|
| 485 |
+
|
| 486 |
+
def _parse_entrez_list(val: str) -> list:
|
| 487 |
+
# Conservative parser: split on common separators; keep only pure integer tokens
|
| 488 |
+
if pd.isna(val):
|
| 489 |
+
return []
|
| 490 |
+
s = str(val).strip()
|
| 491 |
+
if not s:
|
| 492 |
+
return []
|
| 493 |
+
# Replace typical multi-ID separators with semicolon
|
| 494 |
+
s = re.sub(r'\s*//+\s*', ';', s) # '//' or '///'
|
| 495 |
+
s = re.sub(r'[,\s]+', ';', s) # commas and whitespace to ';'
|
| 496 |
+
toks = [t for t in s.split(';') if t.strip().isdigit()]
|
| 497 |
+
# Deduplicate, preserve order
|
| 498 |
+
seen = set()
|
| 499 |
+
out = []
|
| 500 |
+
for t in toks:
|
| 501 |
+
if t not in seen:
|
| 502 |
+
seen.add(t)
|
| 503 |
+
out.append(t)
|
| 504 |
+
return out
|
| 505 |
+
|
| 506 |
+
def _apply_entrez_mapping(ga: pd.DataFrame, id_col: str) -> pd.DataFrame:
|
| 507 |
+
if 'ENTREZ_GENE_ID' not in ga.columns:
|
| 508 |
+
raise RuntimeError("ENTREZ_GENE_ID not found in annotation; cannot proceed without gene symbols.")
|
| 509 |
+
m = ga[[id_col, 'ENTREZ_GENE_ID']].dropna().copy()
|
| 510 |
+
m[id_col] = _normalize_str_series(m[id_col])
|
| 511 |
+
m = m[m[id_col].isin(expr_ids_set)]
|
| 512 |
+
# Strictly parse Entrez IDs to avoid extracting arbitrary numbers
|
| 513 |
+
m['Gene'] = m['ENTREZ_GENE_ID'].map(_parse_entrez_list)
|
| 514 |
+
m = m.explode('Gene').dropna(subset=['Gene'])
|
| 515 |
+
m = m[m['Gene'].astype(str).str.strip() != '']
|
| 516 |
+
m = m.drop_duplicates(subset=[id_col, 'Gene'])
|
| 517 |
+
if m.empty:
|
| 518 |
+
# As a last resort, if the ID itself is an Entrez ID (all digits), map ID->ID one-to-one
|
| 519 |
+
id_is_numeric = pd.Index(expr_df.index).str.fullmatch(r'\d+').all()
|
| 520 |
+
if id_is_numeric:
|
| 521 |
+
gd = expr_df.copy()
|
| 522 |
+
gd.index.name = 'Gene'
|
| 523 |
+
return gd
|
| 524 |
+
else:
|
| 525 |
+
raise RuntimeError("No valid Entrez mappings could be derived.")
|
| 526 |
+
# Equal-split across multiple genes per probe
|
| 527 |
+
counts_per_id = m.groupby(id_col)['Gene'].nunique().rename('num_genes')
|
| 528 |
+
merged = m.set_index(id_col).join(expr_df, how='inner')
|
| 529 |
+
expr_cols = [c for c in merged.columns if c not in ['Gene']]
|
| 530 |
+
merged = merged.join(counts_per_id, on=id_col)
|
| 531 |
+
merged['num_genes'] = merged['num_genes'].fillna(1)
|
| 532 |
+
merged[expr_cols] = merged[expr_cols].div(merged['num_genes'], axis=0)
|
| 533 |
+
gd = merged.groupby('Gene')[expr_cols].sum()
|
| 534 |
+
gd.index.name = 'Gene'
|
| 535 |
+
return gd
|
| 536 |
+
|
| 537 |
+
# Choose mapping path
|
| 538 |
+
if gene_symbol_col is not None:
|
| 539 |
+
try:
|
| 540 |
+
gene_data = _apply_symbol_mapping(ga, best_id_col, gene_symbol_col)
|
| 541 |
+
# Sanity check: expect a reasonable number of genes
|
| 542 |
+
if gene_data.shape[0] < 500 or gene_data.shape[0] > 100000:
|
| 543 |
+
raise RuntimeError("Implausible gene count after symbol mapping.")
|
| 544 |
+
except Exception:
|
| 545 |
+
gene_data = _apply_entrez_mapping(ga, best_id_col)
|
| 546 |
+
else:
|
| 547 |
+
gene_data = _apply_entrez_mapping(ga, best_id_col)
|
| 548 |
+
|
| 549 |
+
# Persist gene-level data
|
| 550 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 551 |
+
gene_data.to_csv(out_gene_data_file)
|
output/preprocess/Atherosclerosis/code/GSE123088.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE123088"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE123088"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE123088.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE123088.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE123088.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# Determine data availability based on provided sample characteristics summary
|
| 40 |
+
is_gene_available = True # Single-cell study on CD4+ T cells; likely gene expression, not miRNA/methylation.
|
| 41 |
+
|
| 42 |
+
# Identify rows for variables based on the Sample Characteristics Dictionary provided above
|
| 43 |
+
trait_row = 1 # primary diagnosis (includes ATHEROSCLEROSIS and controls)
|
| 44 |
+
age_row = 3 # majority of 'age' values appear here
|
| 45 |
+
gender_row = 2 # contains both 'Sex: Female' and 'Sex: Male' (non-constant)
|
| 46 |
+
|
| 47 |
+
# Converters
|
| 48 |
+
def _extract_value(x):
|
| 49 |
+
if x is None:
|
| 50 |
+
return None
|
| 51 |
+
if isinstance(x, (int, float)):
|
| 52 |
+
return x
|
| 53 |
+
try:
|
| 54 |
+
s = str(x).strip()
|
| 55 |
+
except Exception:
|
| 56 |
+
return None
|
| 57 |
+
if ':' in s:
|
| 58 |
+
s = s.split(':', 1)[1]
|
| 59 |
+
return s.strip()
|
| 60 |
+
|
| 61 |
+
def convert_trait(x):
|
| 62 |
+
# Map ATHEROSCLEROSIS to 1; Control/Healthy to 0; other diseases to None
|
| 63 |
+
v = _extract_value(x)
|
| 64 |
+
if v is None:
|
| 65 |
+
return None
|
| 66 |
+
norm = str(v).strip().upper().replace('-', '_').replace(' ', '_')
|
| 67 |
+
# Controls
|
| 68 |
+
if norm in {'CONTROL', 'HEALTHY', 'HEALTHY_CONTROL', 'NORMAL'}:
|
| 69 |
+
return 0
|
| 70 |
+
# Case
|
| 71 |
+
if norm == 'ATHEROSCLEROSIS':
|
| 72 |
+
return 1
|
| 73 |
+
# Other diseases -> unknown for this trait context
|
| 74 |
+
return None
|
| 75 |
+
|
| 76 |
+
def convert_age(x):
|
| 77 |
+
v = _extract_value(x)
|
| 78 |
+
if v is None:
|
| 79 |
+
return None
|
| 80 |
+
sv = str(v).strip()
|
| 81 |
+
if sv == '' or sv.upper() in {'NA', 'N/A', 'UNKNOWN', 'NULL'}:
|
| 82 |
+
return None
|
| 83 |
+
# keep only number and decimal point
|
| 84 |
+
try:
|
| 85 |
+
return float(sv)
|
| 86 |
+
except Exception:
|
| 87 |
+
# attempt to parse with non-digit characters removed
|
| 88 |
+
import re
|
| 89 |
+
nums = re.findall(r'[-+]?\d*\.?\d+', sv)
|
| 90 |
+
if nums:
|
| 91 |
+
try:
|
| 92 |
+
return float(nums[0])
|
| 93 |
+
except Exception:
|
| 94 |
+
return None
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
def convert_gender(x):
|
| 98 |
+
v = _extract_value(x)
|
| 99 |
+
if v is None:
|
| 100 |
+
return None
|
| 101 |
+
norm = str(v).strip().upper()
|
| 102 |
+
if norm in {'MALE', 'M'}:
|
| 103 |
+
return 1
|
| 104 |
+
if norm in {'FEMALE', 'F'}:
|
| 105 |
+
return 0
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
# Initial filtering metadata save
|
| 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 |
+
# Clinical feature extraction (only if trait data is available)
|
| 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
|
| 131 |
+
print(preview_df(selected_clinical_df))
|
| 132 |
+
|
| 133 |
+
# Save clinical features
|
| 134 |
+
import os
|
| 135 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 136 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 137 |
+
|
| 138 |
+
# Step 3: Gene Data Extraction
|
| 139 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 140 |
+
gene_data = get_genetic_data(matrix_file)
|
| 141 |
+
|
| 142 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 143 |
+
print(gene_data.index[:20])
|
| 144 |
+
|
| 145 |
+
# Step 4: Gene Identifier Review
|
| 146 |
+
print("requires_gene_mapping = True")
|
| 147 |
+
|
| 148 |
+
# Step 5: Gene Annotation
|
| 149 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 150 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 151 |
+
|
| 152 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 153 |
+
print("Gene annotation preview:")
|
| 154 |
+
print(preview_df(gene_annotation))
|
| 155 |
+
|
| 156 |
+
# Step 6: Gene Identifier Mapping
|
| 157 |
+
# Attempt to map probe IDs to human gene symbols if available; otherwise, fallback to using probe IDs as gene identifiers.
|
| 158 |
+
|
| 159 |
+
import pandas as pd
|
| 160 |
+
|
| 161 |
+
# Columns
|
| 162 |
+
id_col = 'ID'
|
| 163 |
+
candidate_symbol_cols = [
|
| 164 |
+
'Gene Symbol', 'GENE_SYMBOL', 'Gene symbol', 'SYMBOL', 'Symbol', 'Gene', 'GENE',
|
| 165 |
+
'gene_assignment', 'GENE_SYMBOLS', 'GENE_NAME', 'GeneName', 'Gene_Name'
|
| 166 |
+
]
|
| 167 |
+
symbol_col = next((c for c in candidate_symbol_cols if c in gene_annotation.columns), None)
|
| 168 |
+
|
| 169 |
+
print(f"Identifier column selected: {id_col}")
|
| 170 |
+
print(f"Gene symbol column selected: {symbol_col}")
|
| 171 |
+
|
| 172 |
+
if symbol_col is not None:
|
| 173 |
+
try:
|
| 174 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=symbol_col)
|
| 175 |
+
mapped_gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 176 |
+
# Use mapped data only if non-empty
|
| 177 |
+
if mapped_gene_data.shape[0] > 0:
|
| 178 |
+
gene_data = mapped_gene_data
|
| 179 |
+
gene_data.index.name = 'Gene'
|
| 180 |
+
else:
|
| 181 |
+
# Fallback: keep probe IDs
|
| 182 |
+
gene_data = gene_data.copy()
|
| 183 |
+
gene_data.index.name = 'Gene'
|
| 184 |
+
except Exception as e:
|
| 185 |
+
# Robust fallback on any failure
|
| 186 |
+
print(f"Mapping to gene symbols failed with error: {e}. Falling back to probe IDs as genes.")
|
| 187 |
+
gene_data = gene_data.copy()
|
| 188 |
+
gene_data.index.name = 'Gene'
|
| 189 |
+
else:
|
| 190 |
+
# No gene symbol column available; fallback to using probe IDs as gene identifiers
|
| 191 |
+
gene_data = gene_data.copy()
|
| 192 |
+
gene_data.index.name = 'Gene'
|
| 193 |
+
|
| 194 |
+
# Ensure expression columns are numeric
|
| 195 |
+
gene_data = gene_data.apply(pd.to_numeric, errors='coerce')
|
| 196 |
+
|
| 197 |
+
# Step 7: Data Normalization and Linking
|
| 198 |
+
import os
|
| 199 |
+
import re
|
| 200 |
+
|
| 201 |
+
# Helper to detect if index entries look like human gene symbols
|
| 202 |
+
def _looks_like_gene_symbol(idx, sample_size=500, threshold=0.5):
|
| 203 |
+
if len(idx) == 0:
|
| 204 |
+
return False
|
| 205 |
+
# Sample to speed up
|
| 206 |
+
sample = list(idx[:sample_size]) if len(idx) > sample_size else list(idx)
|
| 207 |
+
basic_pat = re.compile(r"^[A-Z][A-Z0-9-]{1,9}$")
|
| 208 |
+
orf_pat = re.compile(r"^C\d+orf\d+$")
|
| 209 |
+
exclude_prefixes = ("NR_", "XR_", "LOC", "LINC")
|
| 210 |
+
matches = 0
|
| 211 |
+
for s in sample:
|
| 212 |
+
if not isinstance(s, str):
|
| 213 |
+
s = str(s)
|
| 214 |
+
if any(s.upper().startswith(p) for p in exclude_prefixes):
|
| 215 |
+
continue
|
| 216 |
+
if basic_pat.match(s) or orf_pat.match(s):
|
| 217 |
+
matches += 1
|
| 218 |
+
return (matches / len(sample)) >= threshold
|
| 219 |
+
|
| 220 |
+
note_parts = []
|
| 221 |
+
|
| 222 |
+
# 1. Normalize gene symbols when feasible; otherwise, keep identifiers as-is
|
| 223 |
+
apply_normalization = _looks_like_gene_symbol(gene_data.index)
|
| 224 |
+
final_gene_data = gene_data
|
| 225 |
+
if apply_normalization:
|
| 226 |
+
before_rows = gene_data.shape[0]
|
| 227 |
+
try:
|
| 228 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data.copy())
|
| 229 |
+
if normalized_gene_data.shape[0] > 0:
|
| 230 |
+
final_gene_data = normalized_gene_data
|
| 231 |
+
note_parts.append(f"INFO: Gene symbols normalized using synonym table (rows {before_rows} -> {normalized_gene_data.shape[0]}).")
|
| 232 |
+
else:
|
| 233 |
+
note_parts.append("WARNING: Normalization yielded 0 rows; falling back to original identifiers (likely probes).")
|
| 234 |
+
except Exception as e:
|
| 235 |
+
note_parts.append(f"WARNING: Normalization failed with error: {e}; falling back to original identifiers.")
|
| 236 |
+
else:
|
| 237 |
+
note_parts.append("INFO: Index does not resemble human gene symbols; normalization skipped and probe-level identifiers retained.")
|
| 238 |
+
|
| 239 |
+
# Ensure output directory exists and save gene data
|
| 240 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 241 |
+
final_gene_data.to_csv(out_gene_data_file)
|
| 242 |
+
|
| 243 |
+
# 2. Link clinical and genetic data
|
| 244 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, final_gene_data)
|
| 245 |
+
|
| 246 |
+
# 3. Handle missing values
|
| 247 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 248 |
+
|
| 249 |
+
# 4. Judge bias and remove biased demographic features
|
| 250 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 251 |
+
|
| 252 |
+
# 5. Final validation and save cohort information
|
| 253 |
+
notes = " | ".join(note_parts) if note_parts else "INFO: No special notes."
|
| 254 |
+
is_usable = validate_and_save_cohort_info(
|
| 255 |
+
is_final=True,
|
| 256 |
+
cohort=cohort,
|
| 257 |
+
info_path=json_path,
|
| 258 |
+
is_gene_available=True,
|
| 259 |
+
is_trait_available=True,
|
| 260 |
+
is_biased=is_trait_biased,
|
| 261 |
+
df=unbiased_linked_data,
|
| 262 |
+
note=notes
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
# 6. Save linked data only if usable
|
| 266 |
+
if is_usable:
|
| 267 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 268 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Atherosclerosis/code/GSE125771.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE125771"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE125771"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE125771.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE125771.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE125771.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import re
|
| 40 |
+
|
| 41 |
+
# 1) Gene expression availability
|
| 42 |
+
is_gene_available = True # RNA expression microarray data (mRNA), not miRNA/methylation
|
| 43 |
+
|
| 44 |
+
# 2) Variable availability and conversion functions
|
| 45 |
+
|
| 46 |
+
# Trait (Atherosclerosis): Only carotid-atherosclerotic-plaque samples; no variation -> not available
|
| 47 |
+
trait_row = None
|
| 48 |
+
|
| 49 |
+
def convert_trait(x: str):
|
| 50 |
+
# Not used since trait_row is None
|
| 51 |
+
return None
|
| 52 |
+
|
| 53 |
+
# Age
|
| 54 |
+
age_row = 3 # 'age: <number>'
|
| 55 |
+
def convert_age(x: str):
|
| 56 |
+
if x is None:
|
| 57 |
+
return None
|
| 58 |
+
try:
|
| 59 |
+
# Extract part after colon
|
| 60 |
+
val = x.split(":", 1)[1].strip()
|
| 61 |
+
except Exception:
|
| 62 |
+
val = x.strip()
|
| 63 |
+
if val == "" or val.lower() in {"na", "n/a", "nan", "null", "unknown"}:
|
| 64 |
+
return None
|
| 65 |
+
# Extract numeric
|
| 66 |
+
m = re.search(r"-?\d+\.?\d*", val)
|
| 67 |
+
if not m:
|
| 68 |
+
return None
|
| 69 |
+
try:
|
| 70 |
+
num = float(m.group())
|
| 71 |
+
# return integer if it's whole number
|
| 72 |
+
return int(num) if num.is_integer() else num
|
| 73 |
+
except Exception:
|
| 74 |
+
return None
|
| 75 |
+
|
| 76 |
+
# Gender
|
| 77 |
+
gender_row = 2 # 'Sex: Male' / 'Sex: Female'
|
| 78 |
+
def convert_gender(x: str):
|
| 79 |
+
if x is None:
|
| 80 |
+
return None
|
| 81 |
+
try:
|
| 82 |
+
val = x.split(":", 1)[1].strip().lower()
|
| 83 |
+
except Exception:
|
| 84 |
+
val = x.strip().lower()
|
| 85 |
+
if val in {"male", "m"}:
|
| 86 |
+
return 1
|
| 87 |
+
if val in {"female", "f"}:
|
| 88 |
+
return 0
|
| 89 |
+
if val in {"unknown", "na", "n/a", "nan", ""}:
|
| 90 |
+
return None
|
| 91 |
+
# Heuristic for unexpected strings
|
| 92 |
+
if "male" in val:
|
| 93 |
+
return 1
|
| 94 |
+
if "female" in val:
|
| 95 |
+
return 0
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
# 3) Save metadata (initial filtering)
|
| 99 |
+
is_trait_available = trait_row is not None
|
| 100 |
+
_ = validate_and_save_cohort_info(
|
| 101 |
+
is_final=False,
|
| 102 |
+
cohort=cohort,
|
| 103 |
+
info_path=json_path,
|
| 104 |
+
is_gene_available=is_gene_available,
|
| 105 |
+
is_trait_available=is_trait_available
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# 4) Clinical feature extraction
|
| 109 |
+
# Skip because trait_row is None (no varying trait label available)
|
| 110 |
+
# If trait_row were available:
|
| 111 |
+
# selected_clinical = geo_select_clinical_features(
|
| 112 |
+
# clinical_df=clinical_data,
|
| 113 |
+
# trait=trait,
|
| 114 |
+
# trait_row=trait_row,
|
| 115 |
+
# convert_trait=convert_trait,
|
| 116 |
+
# age_row=age_row,
|
| 117 |
+
# convert_age=convert_age,
|
| 118 |
+
# gender_row=gender_row,
|
| 119 |
+
# convert_gender=convert_gender
|
| 120 |
+
# )
|
| 121 |
+
# preview = preview_df(selected_clinical)
|
| 122 |
+
# os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 123 |
+
# selected_clinical.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 |
+
print("requires_gene_mapping = True")
|
| 134 |
+
|
| 135 |
+
# Step 5: Gene Annotation
|
| 136 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 137 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 138 |
+
|
| 139 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 140 |
+
print("Gene annotation preview:")
|
| 141 |
+
print(preview_df(gene_annotation))
|
| 142 |
+
|
| 143 |
+
# Step 6: Gene Identifier Mapping
|
| 144 |
+
# Determine the appropriate columns for probe IDs and gene symbols from the annotation
|
| 145 |
+
id_col = 'ID' if 'ID' in gene_annotation.columns else 'probeset_id'
|
| 146 |
+
gene_symbol_col = 'gene_assignment' # contains gene symbols within descriptive strings
|
| 147 |
+
|
| 148 |
+
# 2. Get mapping dataframe between probe IDs and gene symbols
|
| 149 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=gene_symbol_col)
|
| 150 |
+
|
| 151 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 152 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 153 |
+
|
| 154 |
+
# Step 7: Data Normalization and Linking
|
| 155 |
+
import os
|
| 156 |
+
|
| 157 |
+
# 1. Normalize gene symbols and save gene-level data
|
| 158 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 159 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 160 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 161 |
+
|
| 162 |
+
# Determine trait availability from previous steps
|
| 163 |
+
is_trait_available = (trait_row is not None)
|
| 164 |
+
|
| 165 |
+
# 2-6. Handle two branches based on trait availability
|
| 166 |
+
if is_trait_available:
|
| 167 |
+
# Attempt to find a clinical dataframe variable created earlier
|
| 168 |
+
selected_clinical_var = None
|
| 169 |
+
if 'selected_clinical_data' in locals():
|
| 170 |
+
selected_clinical_var = selected_clinical_data
|
| 171 |
+
elif 'selected_clinical' in locals():
|
| 172 |
+
selected_clinical_var = selected_clinical
|
| 173 |
+
|
| 174 |
+
if selected_clinical_var is None:
|
| 175 |
+
# Fallback: record metadata as trait unavailable due to missing clinical dataframe
|
| 176 |
+
is_usable = validate_and_save_cohort_info(
|
| 177 |
+
is_final=True,
|
| 178 |
+
cohort=cohort,
|
| 179 |
+
info_path=json_path,
|
| 180 |
+
is_gene_available=True,
|
| 181 |
+
is_trait_available=False,
|
| 182 |
+
is_biased=False,
|
| 183 |
+
df=normalized_gene_data.T,
|
| 184 |
+
note="INFO: Clinical feature dataframe not found; skipping linking and marking trait as unavailable."
|
| 185 |
+
)
|
| 186 |
+
else:
|
| 187 |
+
# Link clinical and genetic data
|
| 188 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_var, normalized_gene_data)
|
| 189 |
+
|
| 190 |
+
# Handle missing values
|
| 191 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 192 |
+
|
| 193 |
+
# Assess bias and remove biased demographic features
|
| 194 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 195 |
+
|
| 196 |
+
# Final validation and metadata saving
|
| 197 |
+
is_usable = validate_and_save_cohort_info(
|
| 198 |
+
is_final=True,
|
| 199 |
+
cohort=cohort,
|
| 200 |
+
info_path=json_path,
|
| 201 |
+
is_gene_available=True,
|
| 202 |
+
is_trait_available=True,
|
| 203 |
+
is_biased=is_trait_biased,
|
| 204 |
+
df=unbiased_linked_data,
|
| 205 |
+
note="INFO: Linked clinical and gene expression data with standard preprocessing."
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
# Save linked data only if usable
|
| 209 |
+
if is_usable:
|
| 210 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 211 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 212 |
+
else:
|
| 213 |
+
# Trait not available in this cohort; skip linking and record metadata
|
| 214 |
+
is_usable = validate_and_save_cohort_info(
|
| 215 |
+
is_final=True,
|
| 216 |
+
cohort=cohort,
|
| 217 |
+
info_path=json_path,
|
| 218 |
+
is_gene_available=True,
|
| 219 |
+
is_trait_available=False,
|
| 220 |
+
is_biased=False,
|
| 221 |
+
df=normalized_gene_data.T,
|
| 222 |
+
note="INFO: Trait unavailable (all samples are carotid atherosclerotic plaques; no variation). Gene data saved; linking skipped."
|
| 223 |
+
)
|
output/preprocess/Atherosclerosis/code/GSE133601.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE133601"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE133601"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE133601.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE133601.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE133601.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/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: Dataset Analysis and Clinical Feature Extraction for cohort GSE133601
|
| 40 |
+
|
| 41 |
+
# 1) Gene Expression Data Availability
|
| 42 |
+
is_gene_available = True # PBMC transcriptome profiling (pre/post CPAP) suggests gene expression data are available.
|
| 43 |
+
|
| 44 |
+
# 2) Variable Availability and Data Type Conversion
|
| 45 |
+
|
| 46 |
+
# From the provided Sample Characteristics Dictionary:
|
| 47 |
+
# {0: ['tissue: peripheral blood mononuclear cells'],
|
| 48 |
+
# 1: ['subject: ...'],
|
| 49 |
+
# 2: ['timepoint: pre-CPAP', 'timepoint: post-CPAP']}
|
| 50 |
+
# There is no explicit or inferable Atherosclerosis status, age, or gender info.
|
| 51 |
+
|
| 52 |
+
trait_row = None # Atherosclerosis not available in this dataset
|
| 53 |
+
age_row = None # Age not available
|
| 54 |
+
gender_row = None # Gender not available
|
| 55 |
+
|
| 56 |
+
def _extract_value(x):
|
| 57 |
+
if x is None:
|
| 58 |
+
return None
|
| 59 |
+
s = str(x).strip()
|
| 60 |
+
if ':' in s:
|
| 61 |
+
s = s.split(':', 1)[1].strip()
|
| 62 |
+
if s == '' or s.lower() in {'na', 'n/a', 'null', 'none', 'missing', 'unknown', 'undef', 'undetermined'}:
|
| 63 |
+
return None
|
| 64 |
+
return s
|
| 65 |
+
|
| 66 |
+
# Define converters (even if not used) following the required interface.
|
| 67 |
+
def convert_trait(x):
|
| 68 |
+
# Binary mapping for Atherosclerosis if any value is present in other datasets:
|
| 69 |
+
v = _extract_value(x)
|
| 70 |
+
if v is None:
|
| 71 |
+
return None
|
| 72 |
+
vl = v.lower()
|
| 73 |
+
positive = {'atherosclerosis', 'yes', 'y', 'case', 'present', 'disease', 'true', '1', 'positive', 'pos'}
|
| 74 |
+
negative = {'no atherosclerosis', 'no', 'n', 'control', 'absent', 'healthy', 'false', '0', 'negative', 'neg'}
|
| 75 |
+
if vl in positive:
|
| 76 |
+
return 1
|
| 77 |
+
if vl in negative:
|
| 78 |
+
return 0
|
| 79 |
+
# Heuristics: mention of plaque, stenosis, CAD, ASCVD implies presence
|
| 80 |
+
if any(k in vl for k in ['plaque', 'stenosis', 'cad', 'ascvd', 'atheroma', 'carotid athero', 'mi history']):
|
| 81 |
+
return 1
|
| 82 |
+
if any(k in vl for k in ['no plaque', 'no cad', 'no ascvd']):
|
| 83 |
+
return 0
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
def convert_age(x):
|
| 87 |
+
v = _extract_value(x)
|
| 88 |
+
if v is None:
|
| 89 |
+
return None
|
| 90 |
+
v = v.replace('years', '').replace('year', '').replace('yrs', '').replace('yr', '').replace('y', '').strip()
|
| 91 |
+
try:
|
| 92 |
+
return float(v)
|
| 93 |
+
except Exception:
|
| 94 |
+
# Try to extract leading numeric token
|
| 95 |
+
import re
|
| 96 |
+
m = re.search(r'[-+]?\d+(\.\d+)?', v)
|
| 97 |
+
if m:
|
| 98 |
+
try:
|
| 99 |
+
return float(m.group())
|
| 100 |
+
except Exception:
|
| 101 |
+
return None
|
| 102 |
+
return None
|
| 103 |
+
|
| 104 |
+
def convert_gender(x):
|
| 105 |
+
v = _extract_value(x)
|
| 106 |
+
if v is None:
|
| 107 |
+
return None
|
| 108 |
+
vl = v.lower()
|
| 109 |
+
# Female -> 0, Male -> 1
|
| 110 |
+
if vl in {'female', 'f', 'woman', 'women', 'girl'}:
|
| 111 |
+
return 0
|
| 112 |
+
if vl in {'male', 'm', 'man', 'men', 'boy'}:
|
| 113 |
+
return 1
|
| 114 |
+
# Handle shorthand
|
| 115 |
+
if vl.startswith('fem'):
|
| 116 |
+
return 0
|
| 117 |
+
if vl.startswith('mal'):
|
| 118 |
+
return 1
|
| 119 |
+
return None
|
| 120 |
+
|
| 121 |
+
# 3) Save Metadata (initial filtering)
|
| 122 |
+
is_trait_available = trait_row is not None
|
| 123 |
+
_ = validate_and_save_cohort_info(
|
| 124 |
+
is_final=False,
|
| 125 |
+
cohort=cohort,
|
| 126 |
+
info_path=json_path,
|
| 127 |
+
is_gene_available=is_gene_available,
|
| 128 |
+
is_trait_available=is_trait_available
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
# 4) Clinical Feature Extraction (skip because trait_row is None)
|
| 132 |
+
selected_clinical_df = None
|
| 133 |
+
clinical_preview = None
|
| 134 |
+
if trait_row is not None:
|
| 135 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 136 |
+
clinical_df=clinical_data,
|
| 137 |
+
trait=trait,
|
| 138 |
+
trait_row=trait_row,
|
| 139 |
+
convert_trait=convert_trait,
|
| 140 |
+
age_row=age_row,
|
| 141 |
+
convert_age=convert_age,
|
| 142 |
+
gender_row=gender_row,
|
| 143 |
+
convert_gender=convert_gender
|
| 144 |
+
)
|
| 145 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 146 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 147 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 148 |
+
|
| 149 |
+
# Step 3: Gene Data Extraction
|
| 150 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 151 |
+
gene_data = get_genetic_data(matrix_file)
|
| 152 |
+
|
| 153 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 154 |
+
print(gene_data.index[:20])
|
| 155 |
+
|
| 156 |
+
# Step 4: Gene Identifier Review
|
| 157 |
+
# The identifiers like '10000_at' are Affymetrix probe set IDs, not HGNC gene symbols.
|
| 158 |
+
print("requires_gene_mapping = True")
|
| 159 |
+
|
| 160 |
+
# Step 5: Gene Annotation
|
| 161 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 162 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 163 |
+
|
| 164 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 165 |
+
print("Gene annotation preview:")
|
| 166 |
+
print(preview_df(gene_annotation))
|
| 167 |
+
|
| 168 |
+
# Step 6: Gene Identifier Mapping
|
| 169 |
+
# Determine the probe ID column in the annotation by maximizing overlap with expression probe IDs
|
| 170 |
+
expr_probe_ids = set(gene_data.index.astype(str))
|
| 171 |
+
|
| 172 |
+
best_id_col = None
|
| 173 |
+
best_overlap = -1
|
| 174 |
+
for col in gene_annotation.columns:
|
| 175 |
+
ann_ids = set(gene_annotation[col].astype(str).str.strip())
|
| 176 |
+
overlap = len(expr_probe_ids.intersection(ann_ids))
|
| 177 |
+
if overlap > best_overlap:
|
| 178 |
+
best_overlap = overlap
|
| 179 |
+
best_id_col = col
|
| 180 |
+
|
| 181 |
+
# Determine the gene symbol column with a priority order
|
| 182 |
+
def pick_gene_symbol_col(df: pd.DataFrame) -> str:
|
| 183 |
+
cols = list(df.columns)
|
| 184 |
+
# Priority 1: exact/close matches to gene symbol naming
|
| 185 |
+
for pat in [r'gene.?symbol', r'\bsymbol\b']:
|
| 186 |
+
for c in cols:
|
| 187 |
+
if re.search(pat, c, flags=re.IGNORECASE):
|
| 188 |
+
return c
|
| 189 |
+
# Priority 2: gene title/name/description as fallbacks
|
| 190 |
+
for pat in [r'gene.?title', r'gene.?name', r'description', r'title', r'name']:
|
| 191 |
+
for c in cols:
|
| 192 |
+
if re.search(pat, c, flags=re.IGNORECASE):
|
| 193 |
+
return c
|
| 194 |
+
# Fallback to the last column if nothing else (unlikely)
|
| 195 |
+
return cols[-1]
|
| 196 |
+
|
| 197 |
+
gene_symbol_col = pick_gene_symbol_col(gene_annotation)
|
| 198 |
+
|
| 199 |
+
# Build mapping dataframe from annotation
|
| 200 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=best_id_col, gene_col=gene_symbol_col)
|
| 201 |
+
|
| 202 |
+
# Apply mapping to convert probe-level data to gene-level expression
|
| 203 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 204 |
+
|
| 205 |
+
# Step 7: Data Normalization and Linking
|
| 206 |
+
# 1. Normalize the obtained gene data and save to file
|
| 207 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 208 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 209 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 210 |
+
|
| 211 |
+
# 2-6. Proceed only if clinical data (trait) is available; otherwise, finalize metadata without linking
|
| 212 |
+
clinical_available = (
|
| 213 |
+
('selected_clinical_df' in globals()) and
|
| 214 |
+
(selected_clinical_df is not None) and
|
| 215 |
+
isinstance(selected_clinical_df, pd.DataFrame) and
|
| 216 |
+
(trait in getattr(selected_clinical_df, 'index', []))
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
if clinical_available:
|
| 220 |
+
# 2. Link the clinical and genetic data
|
| 221 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 222 |
+
|
| 223 |
+
# 3. Handle missing values
|
| 224 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 225 |
+
|
| 226 |
+
# 4. Determine bias and remove biased demographic features
|
| 227 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 228 |
+
|
| 229 |
+
# 5. Final validation and save cohort info
|
| 230 |
+
note = "INFO: Clinical trait data available; linked data processed with QC."
|
| 231 |
+
is_usable = validate_and_save_cohort_info(
|
| 232 |
+
is_final=True,
|
| 233 |
+
cohort=cohort,
|
| 234 |
+
info_path=json_path,
|
| 235 |
+
is_gene_available=True,
|
| 236 |
+
is_trait_available=True,
|
| 237 |
+
is_biased=is_trait_biased,
|
| 238 |
+
df=unbiased_linked_data,
|
| 239 |
+
note=note
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
# 6. Save linked data only if usable
|
| 243 |
+
if is_usable:
|
| 244 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 245 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 246 |
+
else:
|
| 247 |
+
# Trait is not available in this cohort; finalize metadata accordingly and do not save linked data
|
| 248 |
+
dummy_df = pd.DataFrame({'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]}) # avoid abnormality override
|
| 249 |
+
note = "INFO: Atherosclerosis trait not available in sample characteristics; only gene expression data was saved."
|
| 250 |
+
validate_and_save_cohort_info(
|
| 251 |
+
is_final=True,
|
| 252 |
+
cohort=cohort,
|
| 253 |
+
info_path=json_path,
|
| 254 |
+
is_gene_available=True,
|
| 255 |
+
is_trait_available=False,
|
| 256 |
+
is_biased=False,
|
| 257 |
+
df=dummy_df,
|
| 258 |
+
note=note
|
| 259 |
+
)
|
output/preprocess/Atherosclerosis/code/GSE154851.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE154851"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE154851"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE154851.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE154851.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE154851.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/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 # Agilent Human Gene Expression microarray -> gene expression data present
|
| 43 |
+
|
| 44 |
+
# 2) Variable availability based on Sample Characteristics Dictionary provided
|
| 45 |
+
trait_row = None # No explicit atherosclerosis status field found; cannot infer reliably
|
| 46 |
+
age_row = 2
|
| 47 |
+
gender_row = 1
|
| 48 |
+
|
| 49 |
+
# 2.2) Conversion functions
|
| 50 |
+
def _after_colon(x):
|
| 51 |
+
if x is None:
|
| 52 |
+
return None
|
| 53 |
+
parts = str(x).split(":", 1)
|
| 54 |
+
if len(parts) == 2:
|
| 55 |
+
return parts[1].strip()
|
| 56 |
+
return str(x).strip()
|
| 57 |
+
|
| 58 |
+
def convert_trait(x):
|
| 59 |
+
# Generic binary converter for atherosclerosis if such a field exists; not used since trait_row is None
|
| 60 |
+
val = _after_colon(x)
|
| 61 |
+
if val is None:
|
| 62 |
+
return None
|
| 63 |
+
s = val.lower().strip()
|
| 64 |
+
# Positive indicators
|
| 65 |
+
pos_terms = {
|
| 66 |
+
"atherosclerosis", "has atherosclerosis", "plaque", "plaques", "cad", "coronary artery disease",
|
| 67 |
+
"case", "yes", "positive", "as", "athero", "with atherosclerosis"
|
| 68 |
+
}
|
| 69 |
+
neg_terms = {"no atherosclerosis", "no", "negative", "control", "healthy", "without atherosclerosis"}
|
| 70 |
+
if s in pos_terms:
|
| 71 |
+
return 1
|
| 72 |
+
if s in neg_terms:
|
| 73 |
+
return 0
|
| 74 |
+
# Heuristics
|
| 75 |
+
if "atherosclerosis" in s or "plaque" in s or "cad" in s:
|
| 76 |
+
return 1
|
| 77 |
+
if "no " in s and ("atherosclerosis" in s or "plaque" in s or "cad" in s):
|
| 78 |
+
return 0
|
| 79 |
+
return None
|
| 80 |
+
|
| 81 |
+
def convert_age(x):
|
| 82 |
+
val = _after_colon(x)
|
| 83 |
+
if val is None:
|
| 84 |
+
return None
|
| 85 |
+
# Extract first number (e.g., "23y", "23 years")
|
| 86 |
+
m = re.search(r"[-+]?\d*\.?\d+", val)
|
| 87 |
+
if not m:
|
| 88 |
+
return None
|
| 89 |
+
try:
|
| 90 |
+
age = float(m.group())
|
| 91 |
+
# Filter unreasonable ages
|
| 92 |
+
if 0 < age < 120:
|
| 93 |
+
return age
|
| 94 |
+
return None
|
| 95 |
+
except Exception:
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
def convert_gender(x):
|
| 99 |
+
val = _after_colon(x)
|
| 100 |
+
if val is None:
|
| 101 |
+
return None
|
| 102 |
+
s = val.lower().strip()
|
| 103 |
+
if s in {"female", "f", "woman", "women"}:
|
| 104 |
+
return 0
|
| 105 |
+
if s in {"male", "m", "man", "men"}:
|
| 106 |
+
return 1
|
| 107 |
+
return None
|
| 108 |
+
|
| 109 |
+
# 3) Save metadata using initial filtering
|
| 110 |
+
is_trait_available = trait_row is not None
|
| 111 |
+
_ = validate_and_save_cohort_info(
|
| 112 |
+
is_final=False,
|
| 113 |
+
cohort=cohort,
|
| 114 |
+
info_path=json_path,
|
| 115 |
+
is_gene_available=is_gene_available,
|
| 116 |
+
is_trait_available=is_trait_available
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# 4) Clinical feature extraction (skip because trait_row is None)
|
| 120 |
+
# If trait_row becomes available in future adjustments, uncomment and use:
|
| 121 |
+
# selected_clinical_df = geo_select_clinical_features(
|
| 122 |
+
# clinical_df=clinical_data,
|
| 123 |
+
# trait=trait,
|
| 124 |
+
# trait_row=trait_row,
|
| 125 |
+
# convert_trait=convert_trait,
|
| 126 |
+
# age_row=age_row,
|
| 127 |
+
# convert_age=convert_age,
|
| 128 |
+
# gender_row=gender_row,
|
| 129 |
+
# convert_gender=convert_gender
|
| 130 |
+
# )
|
| 131 |
+
# preview = preview_df(selected_clinical_df)
|
| 132 |
+
# os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 133 |
+
# selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
| 134 |
+
|
| 135 |
+
# Step 3: Gene Data Extraction
|
| 136 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 137 |
+
gene_data = get_genetic_data(matrix_file)
|
| 138 |
+
|
| 139 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 140 |
+
print(gene_data.index[:20])
|
| 141 |
+
|
| 142 |
+
# Step 4: Gene Identifier Review
|
| 143 |
+
import os
|
| 144 |
+
import re
|
| 145 |
+
import pandas as pd
|
| 146 |
+
|
| 147 |
+
def load_index():
|
| 148 |
+
# Prefer in-memory object if available
|
| 149 |
+
if 'gene_data_df' in globals() and isinstance(globals()['gene_data_df'], pd.DataFrame):
|
| 150 |
+
return globals()['gene_data_df'].index.astype(str)
|
| 151 |
+
|
| 152 |
+
# Try loading from saved file
|
| 153 |
+
try:
|
| 154 |
+
if os.path.exists(out_gene_data_file):
|
| 155 |
+
df = pd.read_csv(out_gene_data_file, index_col=0)
|
| 156 |
+
return df.index.astype(str)
|
| 157 |
+
except Exception:
|
| 158 |
+
pass
|
| 159 |
+
|
| 160 |
+
# Fallback to the provided preview index
|
| 161 |
+
return pd.Index([str(i) for i in range(1, 21)], name='ID')
|
| 162 |
+
|
| 163 |
+
idx = load_index()
|
| 164 |
+
|
| 165 |
+
def needs_mapping(index: pd.Index) -> bool:
|
| 166 |
+
vals = pd.Series(index.astype(str)).dropna().astype(str)
|
| 167 |
+
if len(vals) == 0:
|
| 168 |
+
return True
|
| 169 |
+
|
| 170 |
+
# Patterns for non-symbol identifiers
|
| 171 |
+
ens_pat = re.compile(r'^(ENSG|ENST|ENSMUSG|ENSMUST)\d+(\.\d+)?$')
|
| 172 |
+
refseq_pat = re.compile(r'^(NM_|NR_|XM_|XR_)\d+(\.\d+)?$')
|
| 173 |
+
affy_pat = re.compile(r'^\d+(_at|_st|_x_at|_s_at)$', re.IGNORECASE)
|
| 174 |
+
numeric_pat = re.compile(r'^\d+(\.\d+)?$')
|
| 175 |
+
|
| 176 |
+
def is_symbol(s: str) -> bool:
|
| 177 |
+
if ens_pat.match(s) or refseq_pat.match(s) or affy_pat.match(s) or numeric_pat.match(s):
|
| 178 |
+
return False
|
| 179 |
+
# Typical gene symbols are not purely numeric and contain letters; allow '-', numbers inside.
|
| 180 |
+
# Require at least one alphabetic character.
|
| 181 |
+
return any(c.isalpha() for c in s)
|
| 182 |
+
|
| 183 |
+
# If majority are not symbols => needs mapping
|
| 184 |
+
is_sym = vals.apply(is_symbol)
|
| 185 |
+
frac_symbol = is_sym.mean()
|
| 186 |
+
return frac_symbol < 0.5
|
| 187 |
+
|
| 188 |
+
requires_gene_mapping = needs_mapping(idx)
|
| 189 |
+
print(f"requires_gene_mapping = {str(requires_gene_mapping)}")
|
| 190 |
+
|
| 191 |
+
# Step 5: Gene Annotation
|
| 192 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 193 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 194 |
+
|
| 195 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 196 |
+
print("Gene annotation preview:")
|
| 197 |
+
print(preview_df(gene_annotation))
|
| 198 |
+
|
| 199 |
+
# Step 6: Gene Identifier Mapping
|
| 200 |
+
# Decide columns for mapping: expression uses numeric 'ID' matching annotation 'ID'; gene symbols are in 'GENE_SYMBOL'
|
| 201 |
+
probe_col = 'ID'
|
| 202 |
+
gene_symbol_col = 'GENE_SYMBOL'
|
| 203 |
+
|
| 204 |
+
# 2. Build mapping dataframe
|
| 205 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 206 |
+
|
| 207 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 208 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 209 |
+
|
| 210 |
+
# Step 7: Data Normalization and Linking
|
| 211 |
+
import os
|
| 212 |
+
import pandas as pd
|
| 213 |
+
|
| 214 |
+
# 1. Normalize gene symbols and save gene data
|
| 215 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 216 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 217 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 218 |
+
|
| 219 |
+
# Determine if clinical data (with trait) is available
|
| 220 |
+
has_clinical = ('selected_clinical_data' in globals() and
|
| 221 |
+
isinstance(selected_clinical_data, pd.DataFrame))
|
| 222 |
+
|
| 223 |
+
if has_clinical:
|
| 224 |
+
# 2. Link clinical and genetic data
|
| 225 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 226 |
+
|
| 227 |
+
# 3. Handle missing values
|
| 228 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 229 |
+
|
| 230 |
+
# 4. Judge bias and remove biased demographic features
|
| 231 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 232 |
+
|
| 233 |
+
# 5. Final validation and save cohort info
|
| 234 |
+
is_usable = validate_and_save_cohort_info(
|
| 235 |
+
is_final=True,
|
| 236 |
+
cohort=cohort,
|
| 237 |
+
info_path=json_path,
|
| 238 |
+
is_gene_available=True,
|
| 239 |
+
is_trait_available=True,
|
| 240 |
+
is_biased=is_trait_biased,
|
| 241 |
+
df=unbiased_linked_data,
|
| 242 |
+
note="INFO: Linked and processed when clinical data was available."
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
# 6. Save linked data only if usable
|
| 246 |
+
if is_usable:
|
| 247 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 248 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 249 |
+
|
| 250 |
+
else:
|
| 251 |
+
# Clinical trait not available -> skip linking and record metadata appropriately
|
| 252 |
+
validate_and_save_cohort_info(
|
| 253 |
+
is_final=False,
|
| 254 |
+
cohort=cohort,
|
| 255 |
+
info_path=json_path,
|
| 256 |
+
is_gene_available=True,
|
| 257 |
+
is_trait_available=False
|
| 258 |
+
)
|
output/preprocess/Atherosclerosis/code/GSE57691.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE57691"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE57691"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE57691.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE57691.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE57691.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/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 |
+
import re
|
| 41 |
+
|
| 42 |
+
# 1) Gene expression data availability
|
| 43 |
+
is_gene_available = True # Genome-wide expression analysis indicates mRNA expression data
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability
|
| 46 |
+
trait_row = 0
|
| 47 |
+
age_row = None
|
| 48 |
+
gender_row = None
|
| 49 |
+
|
| 50 |
+
# 2.2) Converters
|
| 51 |
+
def _after_colon(value):
|
| 52 |
+
if value is None:
|
| 53 |
+
return None
|
| 54 |
+
s = str(value)
|
| 55 |
+
parts = s.split(":", 1)
|
| 56 |
+
s = parts[1] if len(parts) > 1 else parts[0]
|
| 57 |
+
return s.strip().strip('"').strip("'")
|
| 58 |
+
|
| 59 |
+
def convert_trait(value):
|
| 60 |
+
v = _after_colon(value)
|
| 61 |
+
if v is None:
|
| 62 |
+
return None
|
| 63 |
+
v_low = v.lower()
|
| 64 |
+
# Positive (atherosclerosis): AOD (aortic occlusive disease)
|
| 65 |
+
if "aod" in v_low or "aortic occlusive" in v_low or "atherosclerosis" in v_low:
|
| 66 |
+
return 1
|
| 67 |
+
# Controls
|
| 68 |
+
if "control" in v_low or "donor" in v_low:
|
| 69 |
+
return 0
|
| 70 |
+
# AAA groups -> not the target trait; exclude
|
| 71 |
+
if "aaa" in v_low or "aneurysm" in v_low:
|
| 72 |
+
return None
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
def convert_age(value):
|
| 76 |
+
v = _after_colon(value)
|
| 77 |
+
if v is None:
|
| 78 |
+
return None
|
| 79 |
+
# Extract first numeric token as age in years
|
| 80 |
+
m = re.search(r"(\d+(\.\d+)?)", v)
|
| 81 |
+
if not m:
|
| 82 |
+
return None
|
| 83 |
+
try:
|
| 84 |
+
age = float(m.group(1))
|
| 85 |
+
# Basic plausibility check
|
| 86 |
+
if 0 < age < 120:
|
| 87 |
+
return age
|
| 88 |
+
except Exception:
|
| 89 |
+
return None
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
def convert_gender(value):
|
| 93 |
+
v = _after_colon(value)
|
| 94 |
+
if v is None:
|
| 95 |
+
return None
|
| 96 |
+
v_low = v.lower()
|
| 97 |
+
if "female" in v_low or v_low == "f":
|
| 98 |
+
return 0
|
| 99 |
+
if "male" in v_low or v_low == "m":
|
| 100 |
+
return 1
|
| 101 |
+
return None
|
| 102 |
+
|
| 103 |
+
# 3) Save initial metadata
|
| 104 |
+
is_trait_available = trait_row is not None
|
| 105 |
+
_ = validate_and_save_cohort_info(
|
| 106 |
+
is_final=False,
|
| 107 |
+
cohort=cohort,
|
| 108 |
+
info_path=json_path,
|
| 109 |
+
is_gene_available=is_gene_available,
|
| 110 |
+
is_trait_available=is_trait_available
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# 4) Clinical feature extraction (only if trait_row is available)
|
| 114 |
+
if trait_row is not None and 'clinical_data' in globals() and isinstance(globals()['clinical_data'], pd.DataFrame):
|
| 115 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 116 |
+
clinical_df=clinical_data,
|
| 117 |
+
trait=trait,
|
| 118 |
+
trait_row=trait_row,
|
| 119 |
+
convert_trait=convert_trait,
|
| 120 |
+
age_row=age_row,
|
| 121 |
+
convert_age=None,
|
| 122 |
+
gender_row=gender_row,
|
| 123 |
+
convert_gender=None
|
| 124 |
+
)
|
| 125 |
+
preview = preview_df(selected_clinical_df, n=5)
|
| 126 |
+
print(preview)
|
| 127 |
+
# Save
|
| 128 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 129 |
+
|
| 130 |
+
# Step 3: Gene Data Extraction
|
| 131 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 132 |
+
gene_data = get_genetic_data(matrix_file)
|
| 133 |
+
|
| 134 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 135 |
+
print(gene_data.index[:20])
|
| 136 |
+
|
| 137 |
+
# Step 4: Gene Identifier Review
|
| 138 |
+
# ILMN_* identifiers are Illumina probe IDs, not human gene symbols
|
| 139 |
+
requires_gene_mapping = True
|
| 140 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 141 |
+
|
| 142 |
+
# Step 5: Gene Annotation
|
| 143 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 144 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 145 |
+
|
| 146 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 147 |
+
print("Gene annotation preview:")
|
| 148 |
+
print(preview_df(gene_annotation))
|
| 149 |
+
|
| 150 |
+
# Step 6: Gene Identifier Mapping
|
| 151 |
+
# Determine appropriate columns for probe IDs and gene symbols from the annotation
|
| 152 |
+
id_col = 'ID' if 'ID' in gene_annotation.columns else None
|
| 153 |
+
gene_symbol_candidates = ['Symbol', 'ILMN_Gene', 'Gene Symbol', 'GeneSymbol']
|
| 154 |
+
gene_col = next((c for c in gene_symbol_candidates if c in gene_annotation.columns), None)
|
| 155 |
+
|
| 156 |
+
if id_col is None or gene_col is None:
|
| 157 |
+
raise ValueError(f"Could not find required columns in gene annotation. Found ID: {id_col}, Gene: {gene_col}")
|
| 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 expression to gene-level expression
|
| 163 |
+
probe_data = gene_data
|
| 164 |
+
gene_data = apply_gene_mapping(expression_df=probe_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 expression matrix
|
| 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) Ensure clinical data is available in memory; fallback to file if needed
|
| 176 |
+
if 'selected_clinical_df' not in globals() or not isinstance(globals().get('selected_clinical_df'), pd.DataFrame):
|
| 177 |
+
try:
|
| 178 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 179 |
+
except FileNotFoundError as e:
|
| 180 |
+
raise FileNotFoundError(
|
| 181 |
+
f"Clinical data not found in memory and file not found at {out_clinical_data_file}."
|
| 182 |
+
) from e
|
| 183 |
+
|
| 184 |
+
# Link the clinical and genetic data
|
| 185 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 186 |
+
|
| 187 |
+
# 3) Handle missing values in the linked data
|
| 188 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 189 |
+
|
| 190 |
+
# 4) Determine whether the trait and demographics are biased; drop biased covariates
|
| 191 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 192 |
+
|
| 193 |
+
# 5) Conduct final quality validation and save cohort info with native Python bools
|
| 194 |
+
is_gene_available_flag = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
|
| 195 |
+
is_trait_available_flag = bool((trait in linked_data.columns) and linked_data[trait].notna().any())
|
| 196 |
+
is_trait_biased_bool = bool(is_trait_biased)
|
| 197 |
+
|
| 198 |
+
note = ("INFO: Trait derived from 'disease state': AOD mapped to atherosclerosis=1 and controls=0; "
|
| 199 |
+
"AAA/aneurysm samples were treated as missing and removed. Age/Gender not provided in the series matrix. "
|
| 200 |
+
"Illumina probes mapped to gene symbols with split-sum handling for multi-mapping.")
|
| 201 |
+
|
| 202 |
+
is_usable = validate_and_save_cohort_info(
|
| 203 |
+
is_final=True,
|
| 204 |
+
cohort=cohort,
|
| 205 |
+
info_path=json_path,
|
| 206 |
+
is_gene_available=is_gene_available_flag,
|
| 207 |
+
is_trait_available=is_trait_available_flag,
|
| 208 |
+
is_biased=is_trait_biased_bool,
|
| 209 |
+
df=unbiased_linked_data,
|
| 210 |
+
note=note
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
# 6) Save linked data only if usable
|
| 214 |
+
if is_usable:
|
| 215 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 216 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Atherosclerosis/code/GSE83500.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE83500"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE83500"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE83500.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE83500.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE83500.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/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 # Microarray mRNA expression per background info
|
| 41 |
+
|
| 42 |
+
# 2) Variable availability and conversion functions
|
| 43 |
+
|
| 44 |
+
# From the provided sample characteristics dictionary:
|
| 45 |
+
# 0: ['individual: non-MI patient', 'individual: MI patient'] -> MI status, not our trait (Atherosclerosis)
|
| 46 |
+
# 1: ['age: ...'] -> age available
|
| 47 |
+
# 2: ['Sex: Male', 'Sex: Female'] -> gender available
|
| 48 |
+
# There is no varying label indicating presence/absence of atherosclerosis in this cohort (all have CAD/atherosclerosis).
|
| 49 |
+
trait_row = None
|
| 50 |
+
age_row = 1
|
| 51 |
+
gender_row = 2
|
| 52 |
+
|
| 53 |
+
def _after_colon(x):
|
| 54 |
+
if x is None:
|
| 55 |
+
return None
|
| 56 |
+
if isinstance(x, str):
|
| 57 |
+
parts = x.split(":", 1)
|
| 58 |
+
val = parts[1] if len(parts) > 1 else parts[0]
|
| 59 |
+
val = val.strip()
|
| 60 |
+
return val if val not in {"", "NA", "N/A", "na", "n/a", "null", "None", "unknown", "Unknown"} else None
|
| 61 |
+
return x
|
| 62 |
+
|
| 63 |
+
# Although trait is not available for this dataset (no controls without atherosclerosis),
|
| 64 |
+
# we still define a robust converter for presence of atherosclerosis when possible.
|
| 65 |
+
def convert_trait(x):
|
| 66 |
+
val = _after_colon(x)
|
| 67 |
+
if val is None:
|
| 68 |
+
return None
|
| 69 |
+
v = val.lower()
|
| 70 |
+
# Heuristic: terms strongly implying atherosclerosis/CAD presence -> 1
|
| 71 |
+
pos_markers = ["atherosclerosis", "cad", "coronary artery disease", "ihd", "ischemic heart disease",
|
| 72 |
+
"mi", "myocardial infarction", "stemi", "nstemi", "ua", "unstable angina", "stable"]
|
| 73 |
+
if any(m in v for m in pos_markers):
|
| 74 |
+
return 1
|
| 75 |
+
# Terms implying absence/healthy -> 0
|
| 76 |
+
neg_markers = ["control", "healthy", "no cad", "no atherosclerosis", "normal"]
|
| 77 |
+
if any(m in v for m in neg_markers):
|
| 78 |
+
return 0
|
| 79 |
+
return None
|
| 80 |
+
|
| 81 |
+
def convert_age(x):
|
| 82 |
+
val = _after_colon(x)
|
| 83 |
+
if val is None:
|
| 84 |
+
return None
|
| 85 |
+
# Keep as continuous numeric
|
| 86 |
+
try:
|
| 87 |
+
# Remove potential units
|
| 88 |
+
val_clean = ''.join(ch for ch in val if ch.isdigit() or ch in ".-")
|
| 89 |
+
return float(val_clean) if val_clean not in {"", ".", "-", "--"} else None
|
| 90 |
+
except Exception:
|
| 91 |
+
return None
|
| 92 |
+
|
| 93 |
+
def convert_gender(x):
|
| 94 |
+
val = _after_colon(x)
|
| 95 |
+
if val is None:
|
| 96 |
+
return None
|
| 97 |
+
v = val.strip().lower()
|
| 98 |
+
# female -> 0, male -> 1
|
| 99 |
+
if v in {"female", "f", "woman", "women"}:
|
| 100 |
+
return 0
|
| 101 |
+
if v in {"male", "m", "man", "men"}:
|
| 102 |
+
return 1
|
| 103 |
+
return None
|
| 104 |
+
|
| 105 |
+
# 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 |
+
# 4) Clinical feature extraction (skip because trait_row is None for this dataset)
|
| 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 = 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/Atherosclerosis/code/GSE87005.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE87005"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE87005"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE87005.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE87005.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE87005.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/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 # Transcriptomic profile in PBMCs indicates mRNA expression microarray data
|
| 43 |
+
|
| 44 |
+
# 2) Variable availability and data type conversion
|
| 45 |
+
# From the provided Sample Characteristics Dictionary:
|
| 46 |
+
# {0: ['cell type: PBMC', 'group: Low HOMA', 'group: High HOMA'],
|
| 47 |
+
# 1: ['cell type: PBMC', 'group: Low HOMA', 'group: High HOMA']}
|
| 48 |
+
# No explicit atherosclerosis status, age, or gender fields are available.
|
| 49 |
+
trait_row = None
|
| 50 |
+
age_row = None
|
| 51 |
+
gender_row = None
|
| 52 |
+
|
| 53 |
+
# Conversion functions
|
| 54 |
+
def _extract_value_after_colon(x: str) -> str:
|
| 55 |
+
if x is None:
|
| 56 |
+
return ""
|
| 57 |
+
parts = str(x).split(":", 1)
|
| 58 |
+
return parts[1].strip() if len(parts) == 2 else str(x).strip()
|
| 59 |
+
|
| 60 |
+
def convert_trait(x):
|
| 61 |
+
# Binary: Atherosclerosis present (1) vs absent (0)
|
| 62 |
+
v = _extract_value_after_colon(x).lower()
|
| 63 |
+
if v in ("", "na", "n/a", "nan", "none", "unknown", "not available"):
|
| 64 |
+
return None
|
| 65 |
+
# Positive indicators
|
| 66 |
+
pos_terms = {"atherosclerosis", "cad", "coronary artery disease", "plaque", "carotid atherosclerosis"}
|
| 67 |
+
# Negative/control indicators
|
| 68 |
+
neg_terms = {"control", "healthy", "normal", "no atherosclerosis", "without atherosclerosis", "absent"}
|
| 69 |
+
# Direct boolean-ish
|
| 70 |
+
if v in ("yes", "present", "positive", "pos", "case"):
|
| 71 |
+
return 1
|
| 72 |
+
if v in ("no", "absent", "negative", "neg", "ctrl", "control", "healthy"):
|
| 73 |
+
return 0
|
| 74 |
+
# Keyword inference
|
| 75 |
+
for t in pos_terms:
|
| 76 |
+
if t in v:
|
| 77 |
+
return 1
|
| 78 |
+
for t in neg_terms:
|
| 79 |
+
if t in v:
|
| 80 |
+
return 0
|
| 81 |
+
return None
|
| 82 |
+
|
| 83 |
+
def convert_age(x):
|
| 84 |
+
# Continuous: age in years
|
| 85 |
+
v = _extract_value_after_colon(x).lower()
|
| 86 |
+
if v in ("", "na", "n/a", "nan", "none", "unknown", "not available"):
|
| 87 |
+
return None
|
| 88 |
+
# Extract first numeric token (handles formats like "45", "45 years", "45.0 yrs")
|
| 89 |
+
m = re.search(r"[-+]?\d*\.?\d+", v)
|
| 90 |
+
if not m:
|
| 91 |
+
return None
|
| 92 |
+
try:
|
| 93 |
+
return float(m.group())
|
| 94 |
+
except:
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
def convert_gender(x):
|
| 98 |
+
# Binary: female -> 0, male -> 1
|
| 99 |
+
v = _extract_value_after_colon(x).lower()
|
| 100 |
+
if v in ("", "na", "n/a", "nan", "none", "unknown", "not available"):
|
| 101 |
+
return None
|
| 102 |
+
if v in ("male", "m", "man", "men", "1"):
|
| 103 |
+
return 1
|
| 104 |
+
if v in ("female", "f", "woman", "women", "0", "2"):
|
| 105 |
+
return 0
|
| 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: skipped because trait_row is None (no clinical trait data available for atherosclerosis)
|
| 119 |
+
# If in future a trait_row is identified, use the following template:
|
| 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 = preview_df(selected_clinical_df)
|
| 131 |
+
# selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
| 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 |
+
requires_gene_mapping = True
|
| 142 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 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: probe IDs ('ID') and gene symbols ('GENE_SYMBOL')
|
| 154 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')
|
| 155 |
+
|
| 156 |
+
# Preserve probe-level data, then map to gene-level and overwrite gene_data as required
|
| 157 |
+
probe_level_df = gene_data
|
| 158 |
+
gene_data = apply_gene_mapping(probe_level_df, mapping_df)
|
| 159 |
+
|
| 160 |
+
# Step 7: Data Normalization and Linking
|
| 161 |
+
import os
|
| 162 |
+
|
| 163 |
+
# 1) Normalize gene symbols and save gene-level data
|
| 164 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 165 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 166 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 167 |
+
|
| 168 |
+
# 2) Determine clinical trait availability and guard linking/validation accordingly
|
| 169 |
+
try:
|
| 170 |
+
trait_available = (trait_row is not None)
|
| 171 |
+
except NameError:
|
| 172 |
+
trait_available = False
|
| 173 |
+
|
| 174 |
+
linked_data = None # default when no clinical data is available
|
| 175 |
+
|
| 176 |
+
if trait_available:
|
| 177 |
+
# Recompute clinical features to ensure availability in this step
|
| 178 |
+
selected_clinical_data = 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,
|
| 185 |
+
gender_row=gender_row,
|
| 186 |
+
convert_gender=convert_gender
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
# 2) Link clinical and genetic data
|
| 190 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 191 |
+
|
| 192 |
+
# 3) Handle missing values
|
| 193 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 194 |
+
|
| 195 |
+
# 4) Bias check and remove biased demographic features
|
| 196 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 197 |
+
|
| 198 |
+
# 5) Final validation and cohort info
|
| 199 |
+
is_usable = validate_and_save_cohort_info(
|
| 200 |
+
is_final=True,
|
| 201 |
+
cohort=cohort,
|
| 202 |
+
info_path=json_path,
|
| 203 |
+
is_gene_available=True,
|
| 204 |
+
is_trait_available=True,
|
| 205 |
+
is_biased=is_trait_biased,
|
| 206 |
+
df=unbiased_linked_data
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
# 6) Save linked data only if usable
|
| 210 |
+
if is_usable:
|
| 211 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 212 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 213 |
+
|
| 214 |
+
else:
|
| 215 |
+
# No trait data available: skip linking and final validation; ensure metadata correctly reflects unavailability
|
| 216 |
+
_ = validate_and_save_cohort_info(
|
| 217 |
+
is_final=False,
|
| 218 |
+
cohort=cohort,
|
| 219 |
+
info_path=json_path,
|
| 220 |
+
is_gene_available=True,
|
| 221 |
+
is_trait_available=False
|
| 222 |
+
)
|
output/preprocess/Atherosclerosis/code/GSE90074.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
cohort = "GSE90074"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Atherosclerosis"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Atherosclerosis/GSE90074"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/GSE90074.csv"
|
| 14 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/GSE90074.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/GSE90074.csv"
|
| 16 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/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 |
+
# Based on the background information (Agilent Whole Human Genome arrays on PBMC RNA), gene expression data is available.
|
| 43 |
+
is_gene_available = True
|
| 44 |
+
|
| 45 |
+
# 2. Variable Availability and Data Type Conversion
|
| 46 |
+
# Sample Characteristics Dictionary shows only one constant, non-informative entry, so no usable human trait/age/gender fields are available.
|
| 47 |
+
trait_row = None
|
| 48 |
+
age_row = None
|
| 49 |
+
gender_row = None
|
| 50 |
+
|
| 51 |
+
def _extract_value(x: str) -> str:
|
| 52 |
+
if x is None:
|
| 53 |
+
return None
|
| 54 |
+
# Extract part after the first colon if present
|
| 55 |
+
parts = str(x).split(":", 1)
|
| 56 |
+
val = parts[1] if len(parts) > 1 else parts[0]
|
| 57 |
+
val = val.strip()
|
| 58 |
+
return val if val != "" else None
|
| 59 |
+
|
| 60 |
+
def convert_trait(x):
|
| 61 |
+
"""
|
| 62 |
+
Convert trait (Atherosclerosis/CAD) to a binary indicator when possible.
|
| 63 |
+
Heuristics:
|
| 64 |
+
- map case/yes/present/disease to 1; control/no/absent to 0
|
| 65 |
+
- extract numeric severity if provided; if numeric, return as 1 if >0 else 0
|
| 66 |
+
Unknown -> None
|
| 67 |
+
"""
|
| 68 |
+
val = _extract_value(x)
|
| 69 |
+
if val is None:
|
| 70 |
+
return None
|
| 71 |
+
low = val.lower()
|
| 72 |
+
# Explicit binary cues
|
| 73 |
+
if low in {"case", "cad", "atherosclerosis", "disease", "yes", "y", "present", "true", "positive", "pos"}:
|
| 74 |
+
return 1
|
| 75 |
+
if low in {"control", "no disease", "no", "n", "absent", "false", "negative", "neg", "healthy"}:
|
| 76 |
+
return 0
|
| 77 |
+
# Look for typical tokens
|
| 78 |
+
if any(tok in low for tok in ["case", "patient", "cad", "atheroscler", "stenosis", "plaque"]):
|
| 79 |
+
# If it sounds disease-like, lean towards case
|
| 80 |
+
return 1
|
| 81 |
+
if any(tok in low for tok in ["control", "healthy", "no cad", "no atheroscler"]):
|
| 82 |
+
return 0
|
| 83 |
+
# Try numeric
|
| 84 |
+
try:
|
| 85 |
+
num = float(re.findall(r"[-+]?\d*\.?\d+", low)[0])
|
| 86 |
+
# If a numeric severity/score exists, binarize >0 as diseased
|
| 87 |
+
return 1 if num > 0 else 0
|
| 88 |
+
except Exception:
|
| 89 |
+
return None
|
| 90 |
+
|
| 91 |
+
def convert_age(x):
|
| 92 |
+
"""
|
| 93 |
+
Convert age to continuous years. Extract first numeric token.
|
| 94 |
+
"""
|
| 95 |
+
val = _extract_value(x)
|
| 96 |
+
if val is None:
|
| 97 |
+
return None
|
| 98 |
+
m = re.search(r"[-+]?\d*\.?\d+", val)
|
| 99 |
+
if not m:
|
| 100 |
+
return None
|
| 101 |
+
try:
|
| 102 |
+
age_val = float(m.group(0))
|
| 103 |
+
# Filter unreasonable ages
|
| 104 |
+
if 0 <= age_val <= 120:
|
| 105 |
+
return age_val
|
| 106 |
+
return None
|
| 107 |
+
except Exception:
|
| 108 |
+
return None
|
| 109 |
+
|
| 110 |
+
def convert_gender(x):
|
| 111 |
+
"""
|
| 112 |
+
Convert gender to binary: female->0, male->1. Unknown -> None.
|
| 113 |
+
"""
|
| 114 |
+
val = _extract_value(x)
|
| 115 |
+
if val is None:
|
| 116 |
+
return None
|
| 117 |
+
low = val.lower()
|
| 118 |
+
if low in {"male", "m"}:
|
| 119 |
+
return 1
|
| 120 |
+
if low in {"female", "f"}:
|
| 121 |
+
return 0
|
| 122 |
+
# Handle common encodings
|
| 123 |
+
if "male" in low:
|
| 124 |
+
return 1
|
| 125 |
+
if "female" in low:
|
| 126 |
+
return 0
|
| 127 |
+
return None
|
| 128 |
+
|
| 129 |
+
# 3. Save Metadata (initial filtering)
|
| 130 |
+
is_trait_available = trait_row is not None
|
| 131 |
+
_ = validate_and_save_cohort_info(
|
| 132 |
+
is_final=False,
|
| 133 |
+
cohort=cohort,
|
| 134 |
+
info_path=json_path,
|
| 135 |
+
is_gene_available=is_gene_available,
|
| 136 |
+
is_trait_available=is_trait_available
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
# 4. Clinical Feature Extraction (skip because trait_row is None)
|
| 140 |
+
# If trait_row were available:
|
| 141 |
+
if (trait_row is not None) and ('clinical_data' in globals()):
|
| 142 |
+
selected = geo_select_clinical_features(
|
| 143 |
+
clinical_df=clinical_data,
|
| 144 |
+
trait=trait,
|
| 145 |
+
trait_row=trait_row,
|
| 146 |
+
convert_trait=convert_trait,
|
| 147 |
+
age_row=age_row,
|
| 148 |
+
convert_age=convert_age,
|
| 149 |
+
gender_row=gender_row,
|
| 150 |
+
convert_gender=convert_gender
|
| 151 |
+
)
|
| 152 |
+
_ = preview_df(selected)
|
| 153 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 154 |
+
selected.to_csv(out_clinical_data_file, index=True)
|
| 155 |
+
|
| 156 |
+
# Step 3: Gene Data Extraction
|
| 157 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 158 |
+
gene_data = get_genetic_data(matrix_file)
|
| 159 |
+
|
| 160 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 161 |
+
print(gene_data.index[:20])
|
| 162 |
+
|
| 163 |
+
# Step 4: Gene Identifier Review
|
| 164 |
+
requires_gene_mapping = True
|
| 165 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 166 |
+
|
| 167 |
+
# Step 5: Gene Annotation
|
| 168 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 169 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 170 |
+
|
| 171 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 172 |
+
print("Gene annotation preview:")
|
| 173 |
+
print(preview_df(gene_annotation))
|
| 174 |
+
|
| 175 |
+
# Step 6: Gene Identifier Mapping
|
| 176 |
+
# Determine the appropriate columns for mapping
|
| 177 |
+
probe_id_col = 'ID' # Matches probe identifiers in gene_data (e.g., A_23_P100001)
|
| 178 |
+
gene_symbol_col = 'GENE_SYMBOL' # Contains human gene symbols
|
| 179 |
+
|
| 180 |
+
# 2. Build mapping dataframe from annotation
|
| 181 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_id_col, gene_col=gene_symbol_col)
|
| 182 |
+
|
| 183 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 184 |
+
probe_level_data = gene_data.copy()
|
| 185 |
+
gene_data = apply_gene_mapping(expression_df=probe_level_data, mapping_df=mapping_df)
|
| 186 |
+
|
| 187 |
+
# Step 7: Data Normalization and Linking
|
| 188 |
+
import os
|
| 189 |
+
import pandas as pd
|
| 190 |
+
|
| 191 |
+
# 1. Normalize the obtained gene data and save
|
| 192 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 193 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 194 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 195 |
+
|
| 196 |
+
# Determine if clinical data is available (from in-memory 'selected' or saved CSV)
|
| 197 |
+
clinical_df = None
|
| 198 |
+
if 'selected' in globals() and isinstance(selected, pd.DataFrame):
|
| 199 |
+
clinical_df = selected
|
| 200 |
+
elif os.path.exists(out_clinical_data_file):
|
| 201 |
+
clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 202 |
+
|
| 203 |
+
# If no clinical data (trait) is available, skip linking/processing and record initial filtering result
|
| 204 |
+
if clinical_df is None:
|
| 205 |
+
linked_data = None
|
| 206 |
+
_ = validate_and_save_cohort_info(
|
| 207 |
+
is_final=False,
|
| 208 |
+
cohort=cohort,
|
| 209 |
+
info_path=json_path,
|
| 210 |
+
is_gene_available=True,
|
| 211 |
+
is_trait_available=False
|
| 212 |
+
)
|
| 213 |
+
else:
|
| 214 |
+
# 2. Link the clinical and genetic data
|
| 215 |
+
linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
|
| 216 |
+
|
| 217 |
+
# 3. Handle missing values in the linked data
|
| 218 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 219 |
+
|
| 220 |
+
# 4. Determine whether the trait and demographic features are severely biased, and remove biased features
|
| 221 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 222 |
+
|
| 223 |
+
# 5. Conduct final quality validation and save the cohort information
|
| 224 |
+
is_usable = validate_and_save_cohort_info(
|
| 225 |
+
is_final=True,
|
| 226 |
+
cohort=cohort,
|
| 227 |
+
info_path=json_path,
|
| 228 |
+
is_gene_available=True,
|
| 229 |
+
is_trait_available=True,
|
| 230 |
+
is_biased=is_trait_biased,
|
| 231 |
+
df=unbiased_linked_data,
|
| 232 |
+
note="INFO: Linked gene expression with available clinical features; applied QC and imputation."
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
# 6. If the linked data is usable, save it
|
| 236 |
+
if is_usable:
|
| 237 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 238 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Atherosclerosis/code/TCGA.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Atherosclerosis"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z1/preprocess/Atherosclerosis/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z1/preprocess/Atherosclerosis/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z1/preprocess/Atherosclerosis/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z1/preprocess/Atherosclerosis/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 Atherosclerosis (unlikely in TCGA; attempt matching)
|
| 22 |
+
subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 23 |
+
trait_synonyms = [
|
| 24 |
+
"atherosclerosis", "atheroma", "artery", "arterial", "coronary", "cad",
|
| 25 |
+
"ischemic", "ischemia", "heart", "cardiac", "cardiovascular", "vascular"
|
| 26 |
+
]
|
| 27 |
+
def relevance_score(name: str) -> int:
|
| 28 |
+
lname = name.lower()
|
| 29 |
+
return sum(1 for s in trait_synonyms if s in lname)
|
| 30 |
+
|
| 31 |
+
scored = [(d, relevance_score(d)) for d in subdirs]
|
| 32 |
+
scored.sort(key=lambda x: x[1], reverse=True)
|
| 33 |
+
selected_dir = scored[0][0] if scored and scored[0][1] > 0 else None
|
| 34 |
+
|
| 35 |
+
if selected_dir is None:
|
| 36 |
+
print("No suitable TCGA cohort directory found for the trait 'Atherosclerosis'. Skipping.")
|
| 37 |
+
# Record as unavailable and exit early for this trait
|
| 38 |
+
validate_and_save_cohort_info(
|
| 39 |
+
is_final=False,
|
| 40 |
+
cohort="TCGA",
|
| 41 |
+
info_path=json_path,
|
| 42 |
+
is_gene_available=False,
|
| 43 |
+
is_trait_available=False
|
| 44 |
+
)
|
| 45 |
+
clinical_df = pd.DataFrame()
|
| 46 |
+
genetic_df = pd.DataFrame()
|
| 47 |
+
else:
|
| 48 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 49 |
+
# Step 2: Identify clinical and genetic file paths
|
| 50 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
| 51 |
+
print(f"Selected cohort: {selected_dir}")
|
| 52 |
+
print(f"Clinical file: {clinical_file_path}")
|
| 53 |
+
print(f"Genetic file: {genetic_file_path}")
|
| 54 |
+
|
| 55 |
+
# Step 3: Load files
|
| 56 |
+
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False, compression='infer')
|
| 57 |
+
genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False, compression='infer')
|
| 58 |
+
|
| 59 |
+
# Step 4: Print clinical data columns
|
| 60 |
+
print(list(clinical_df.columns))
|
output/preprocess/Atherosclerosis/cohort_info.json
CHANGED
|
@@ -1,82 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"GSE90074": {
|
| 3 |
-
"is_usable": true,
|
| 4 |
-
"is_gene_available": true,
|
| 5 |
-
"is_trait_available": true,
|
| 6 |
-
"is_available": true,
|
| 7 |
-
"is_biased": false,
|
| 8 |
-
"has_age": true,
|
| 9 |
-
"has_gender": true,
|
| 10 |
-
"sample_size": 143
|
| 11 |
-
},
|
| 12 |
-
"GSE87005": {
|
| 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": 40
|
| 21 |
-
},
|
| 22 |
-
"GSE83500": {
|
| 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": 37
|
| 31 |
-
},
|
| 32 |
-
"GSE57691": {
|
| 33 |
-
"is_usable": true,
|
| 34 |
-
"is_gene_available": true,
|
| 35 |
-
"is_trait_available": true,
|
| 36 |
-
"is_available": true,
|
| 37 |
-
"is_biased": false,
|
| 38 |
-
"has_age": false,
|
| 39 |
-
"has_gender": false,
|
| 40 |
-
"sample_size": 68
|
| 41 |
-
},
|
| 42 |
-
"GSE154851": {
|
| 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 |
-
"GSE133601": {
|
| 53 |
-
"is_usable": false,
|
| 54 |
-
"is_gene_available": true,
|
| 55 |
-
"is_trait_available": false,
|
| 56 |
-
"is_available": false,
|
| 57 |
-
"is_biased": null,
|
| 58 |
-
"has_age": null,
|
| 59 |
-
"has_gender": null,
|
| 60 |
-
"sample_size": null
|
| 61 |
-
},
|
| 62 |
-
"GSE109048": {
|
| 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": 57
|
| 71 |
-
},
|
| 72 |
-
"TCGA": {
|
| 73 |
-
"is_usable": false,
|
| 74 |
-
"is_gene_available": false,
|
| 75 |
-
"is_trait_available": false,
|
| 76 |
-
"is_available": false,
|
| 77 |
-
"is_biased": null,
|
| 78 |
-
"has_age": null,
|
| 79 |
-
"has_gender": null,
|
| 80 |
-
"sample_size": null
|
| 81 |
-
}
|
| 82 |
-
}
|
|
|
|
| 1 |
+
{"GSE90074": {"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}, "GSE87005": {"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}, "GSE83500": {"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}, "GSE57691": {"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": 19, "note": "INFO: Trait derived from 'disease state': AOD mapped to atherosclerosis=1 and controls=0; AAA/aneurysm samples were treated as missing and removed. Age/Gender not provided in the series matrix. Illumina probes mapped to gene symbols with split-sum handling for multi-mapping."}, "GSE154851": {"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}, "GSE133601": {"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: Atherosclerosis trait not available in sample characteristics; only gene expression data was saved."}, "GSE125771": {"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 unavailable (all samples are carotid atherosclerotic plaques; no variation). Gene data saved; linking skipped."}, "GSE123088": {"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": 63, "note": "INFO: Index does not resemble human gene symbols; normalization skipped and probe-level identifiers retained."}, "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/Atherosclerosis/gene_data/GSE133601.csv
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE208662.csv
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE162635.csv
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
,
|
| 2 |
-
Chronic_obstructive_pulmonary_disease_(COPD),1.0,1.0,1.0,1.0,0.0,1.0,,,,,,,,,,,,,,,,,,,,,,,,
|
|
|
|
| 1 |
+
,GSM4955871,GSM4955872,GSM4955873,GSM4955874,GSM4955875,GSM4955876,GSM4955877,GSM4955878,GSM4955879,GSM4955880,GSM4955881,GSM4955882,GSM4955883,GSM4955884,GSM4955885,GSM4955886,GSM4955887,GSM4955888,GSM4955889,GSM4955890,GSM4955891,GSM4955892,GSM4955893,GSM4955894,GSM4955895,GSM4955896,GSM4955897,GSM4955898,GSM4955899,GSM4955900,GSM4955901,GSM4955902,GSM4955903,GSM4955904,GSM4955905,GSM4955906,GSM4955907,GSM4955908,GSM4955909,GSM4955910,GSM4955911,GSM4955912,GSM4955913,GSM4955914,GSM4955915,GSM4955916,GSM4955917,GSM4955918,GSM4955919,GSM4955920,GSM4955921,GSM4955922,GSM4955923,GSM4955924,GSM4955925,GSM4955926,GSM4955927,GSM4955928,GSM4955929,GSM4955930,GSM4955931,GSM4955932,GSM4955933,GSM4955934,GSM4955935,GSM4955936,GSM4955937,GSM4955938,GSM4955939,GSM4955940,GSM4955941,GSM4955942,GSM4955943,GSM4955944,GSM4955945,GSM4955946,GSM4955947,GSM4955948,GSM4955949,GSM4955950,GSM4955951,GSM4955952,GSM4955953,GSM4955954,GSM4955955,GSM4955956,GSM4955957,GSM4955958,GSM4955959,GSM4955960,GSM4955961,GSM4955962,GSM4955963,GSM4955964,GSM4955965,GSM4955966,GSM4955967,GSM4955968,GSM4955969,GSM4955970,GSM4955971,GSM4955972,GSM4955973,GSM4955974,GSM4955975,GSM4955976,GSM4955977,GSM4955978,GSM4955979,GSM4955980,GSM4955981,GSM4955982,GSM4955983,GSM4955984,GSM4955985,GSM4955986,GSM4955987,GSM4955988,GSM4955989,GSM4955990,GSM4955991,GSM4955992,GSM4955993,GSM4955994,GSM4955995,GSM4955996,GSM4955997,GSM4955998,GSM4955999,GSM4956000,GSM4956001,GSM4956002,GSM4956003,GSM4956004,GSM4956005,GSM4956006,GSM4956007,GSM4956008,GSM4956009,GSM4956010,GSM4956011,GSM4956012,GSM4956013,GSM4956014,GSM4956015,GSM4956016,GSM4956017,GSM4956018,GSM4956019,GSM4956020,GSM4956021,GSM4956022,GSM4956023,GSM4956024,GSM4956025,GSM4956026,GSM4956027,GSM4956028,GSM4956029,GSM4956030,GSM4956031,GSM4956032,GSM4956033,GSM4956034,GSM4956035,GSM4956036,GSM4956037,GSM4956038,GSM4956039,GSM4956040,GSM4956041,GSM4956042,GSM4956043,GSM4956044,GSM4956045,GSM4956046,GSM4956047,GSM4956048,GSM4956049,GSM4956050,GSM4956051,GSM4956052,GSM4956053,GSM4956054,GSM4956055,GSM4956056,GSM4956057,GSM4956058,GSM4956059,GSM4956060,GSM4956061,GSM4956062,GSM4956063,GSM4956064,GSM4956065,GSM4956066,GSM4956067,GSM4956068,GSM4956069,GSM4956070,GSM4956071,GSM4956072,GSM4956073,GSM4956074,GSM4956075
|
| 2 |
+
Chronic_obstructive_pulmonary_disease_(COPD),0.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,1.0,1.0,1.0,1.0,1.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,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,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,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,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,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,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,0.0,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE208662.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
,GSM6360778,GSM6360779,GSM6360780,GSM6360781,GSM6360782,GSM6360783,GSM6360784,GSM6360785,GSM6360786,GSM6360787,GSM6360788,GSM6360789,GSM6360790,GSM6360791,GSM6360792,GSM6360793,GSM6360794,GSM6360795,GSM6360796,GSM6360797,GSM6360798,GSM6360799,GSM6360800,GSM6360801,GSM6360802,GSM6360803,GSM6360804,GSM6360805,GSM6360806,GSM6360807,GSM6360808,GSM6360809
|
| 2 |
+
Chronic_obstructive_pulmonary_disease_(COPD),1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.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,0.0
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE212331.csv
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
1.0
|
| 3 |
-
75.0
|
| 4 |
-
0.0
|
|
|
|
| 1 |
+
,GSM6524456,GSM6524458,GSM6524459,GSM6524460,GSM6524462,GSM6524463,GSM6524465,GSM6524466,GSM6524468,GSM6524469,GSM6524470,GSM6524472,GSM6524473,GSM6524475,GSM6524476,GSM6524478,GSM6524479,GSM6524481,GSM6524482,GSM6524484,GSM6524485,GSM6524486,GSM6524488,GSM6524489,GSM6524490,GSM6524492,GSM6524493,GSM6524495,GSM6524496,GSM6524498,GSM6524499,GSM6524501,GSM6524502,GSM6524504,GSM6524505,GSM6524507,GSM6524508,GSM6524510,GSM6524511,GSM6524512,GSM6524514,GSM6524515,GSM6524517,GSM6524518,GSM6524520,GSM6524521,GSM6524523,GSM6524524,GSM6524525,GSM6524527,GSM6524528,GSM6524529,GSM6524531,GSM6524532,GSM6524534,GSM6524535,GSM6524537,GSM6524538,GSM6524540,GSM6524541,GSM6524543,GSM6524544,GSM6524545,GSM6524547,GSM6524548,GSM6524549,GSM6524551,GSM6524552,GSM6524554,GSM6524555,GSM6524557,GSM6524558,GSM6524560,GSM6524561,GSM6524563,GSM6524564,GSM6524566,GSM6524567,GSM6524568,GSM6524569,GSM6524571,GSM6524573,GSM6524574,GSM6524576,GSM6524577,GSM6524579,GSM6524580
|
| 2 |
+
Chronic_obstructive_pulmonary_disease_(COPD),1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,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
|
| 3 |
+
Age,75.0,66.0,83.0,70.0,61.0,77.0,70.0,64.0,81.0,60.0,62.0,80.0,65.0,74.0,64.0,70.0,73.0,81.0,54.0,64.0,65.0,67.0,75.0,72.0,71.0,61.0,60.0,65.0,61.0,77.0,74.0,82.0,69.0,75.0,67.0,63.0,77.0,76.0,60.0,62.0,69.0,69.0,81.0,66.0,73.0,73.0,70.0,64.0,65.0,61.0,76.0,70.0,72.0,68.0,63.0,78.0,71.0,78.0,60.0,69.0,72.0,68.0,84.0,78.0,81.0,62.0,71.0,64.0,69.0,62.0,88.0,79.0,24.0,76.0,64.0,65.0,62.0,66.0,61.0,21.0,20.0,69.0,27.0,41.0,25.0,27.0,27.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.0,1.0,1.0,1.0,1.0,1.0,1.0
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE21359.csv
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
,,,0.0
|
| 3 |
-
41.0,,,
|
| 4 |
-
,1.0,,
|
|
|
|
| 1 |
+
,GSM101095,GSM101096,GSM101097,GSM101098,GSM101100,GSM101101,GSM101102,GSM101103,GSM101104,GSM101105,GSM101106,GSM101107,GSM101111,GSM101113,GSM101114,GSM101115,GSM101116,GSM114089,GSM114090,GSM190149,GSM190150,GSM190151,GSM190152,GSM190153,GSM190154,GSM190155,GSM190156,GSM252828,GSM252829,GSM252830,GSM252831,GSM252833,GSM252835,GSM252836,GSM252837,GSM252838,GSM252839,GSM252841,GSM252871,GSM252876,GSM252879,GSM252880,GSM252881,GSM252882,GSM252884,GSM252885,GSM254149,GSM254150,GSM254151,GSM254152,GSM254157,GSM254158,GSM254159,GSM254160,GSM254161,GSM254163,GSM254169,GSM254172,GSM254173,GSM254174,GSM254175,GSM254176,GSM298219,GSM298220,GSM298221,GSM298222,GSM298223,GSM298224,GSM298225,GSM298226,GSM298227,GSM298228,GSM298229,GSM298230,GSM298231,GSM298232,GSM298233,GSM298234,GSM298235,GSM298236,GSM298237,GSM298238,GSM298239,GSM298240,GSM298241,GSM298242,GSM298243,GSM298244,GSM298245,GSM298246,GSM298247,GSM300859,GSM302396,GSM302397,GSM302399,GSM350871,GSM350873,GSM350874,GSM350955,GSM350956,GSM350957,GSM350958,GSM364037,GSM364038,GSM364041,GSM364045,GSM364046,GSM364048,GSM410161,GSM410162,GSM410163,GSM410164,GSM410165,GSM434049,GSM434050,GSM434051,GSM434052,GSM434053,GSM434054,GSM434055,GSM434056,GSM434057,GSM434058,GSM434059,GSM434060,GSM434061,GSM434062,GSM434063,GSM434064,GSM458579,GSM458580,GSM458581,GSM458582,GSM469991,GSM470000
|
| 2 |
+
Chronic_obstructive_pulmonary_disease_(COPD),0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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
|
| 3 |
+
Age,41.0,35.0,61.0,37.0,47.0,38.0,49.0,45.0,36.0,38.0,35.0,46.0,37.0,45.0,48.0,50.0,46.0,56.0,59.0,49.0,34.0,44.0,45.0,45.0,29.0,42.0,56.0,47.0,47.0,50.0,55.0,59.0,51.0,46.0,56.0,60.0,46.0,52.0,40.0,45.0,41.0,47.0,41.0,48.0,43.0,41.0,41.0,35.0,37.0,31.0,45.0,50.0,46.0,49.0,40.0,51.0,48.0,53.0,42.0,36.0,44.0,62.0,44.0,60.0,49.0,36.0,38.0,73.0,49.0,22.0,29.0,39.0,48.0,39.0,54.0,43.0,36.0,41.0,46.0,47.0,41.0,42.0,46.0,41.0,32.0,27.0,35.0,40.0,48.0,47.0,41.0,62.0,47.0,39.0,27.0,24.0,31.0,43.0,26.0,33.0,45.0,48.0,57.0,66.0,45.0,45.0,48.0,47.0,21.0,45.0,55.0,47.0,39.0,68.0,26.0,45.0,40.0,40.0,46.0,47.0,29.0,30.0,47.0,43.0,48.0,24.0,27.0,54.0,73.0,27.0,34.0,27.0,47.0,37.0,48.0
|
| 4 |
+
Gender,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.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,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE32030.csv
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
|
| 2 |
-
1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
|
|
| 1 |
+
,GSM549645,GSM549646,GSM549647,GSM549648,GSM549649,GSM549650,GSM549651,GSM549652,GSM549653,GSM549654,GSM549655,GSM549656,GSM549657,GSM549658,GSM549659,GSM549660,GSM549661,GSM549662,GSM549663,GSM549664,GSM549665,GSM549666,GSM549667,GSM549668,GSM549669,GSM549670,GSM549671,GSM549672,GSM549673,GSM549674,GSM549675,GSM549676,GSM549677,GSM549678,GSM549679,GSM549680,GSM549681,GSM549682,GSM549683,GSM549684,GSM549685,GSM549686,GSM549687,GSM549688,GSM549689,GSM549690,GSM549691,GSM549692,GSM549693,GSM549694,GSM549695,GSM549696,GSM549697,GSM549698,GSM549699,GSM549700,GSM549701,GSM549702,GSM549703,GSM549704,GSM549705,GSM549706,GSM549707,GSM549708,GSM549709,GSM549710,GSM549711,GSM549712,GSM549713,GSM549714,GSM549715,GSM549716,GSM549717,GSM549718,GSM549719,GSM549720,GSM549721,GSM549722,GSM549723,GSM549724,GSM549725,GSM549726,GSM549727,GSM549728,GSM549729,GSM549730,GSM549731,GSM549732,GSM549733,GSM549734,GSM549735,GSM549736,GSM549737,GSM549738,GSM549739,GSM549740,GSM549742,GSM549743,GSM549744,GSM549745,GSM549746,GSM549747,GSM549748,GSM549749,GSM549751,GSM549752,GSM549753,GSM549754,GSM549755,GSM549756,GSM549757,GSM549758,GSM549759,GSM549760,GSM549761,GSM549762,GSM549763,GSM549764,GSM549765,GSM549766,GSM549767,GSM549768,GSM549769,GSM549770,GSM549771,GSM549772,GSM549773,GSM549774,GSM549775,GSM549776,GSM549777,GSM549778,GSM549779,GSM549780,GSM549781,GSM549783,GSM549784,GSM549785,GSM549786,GSM549787,GSM549788,GSM549789,GSM549790,GSM549791,GSM549792,GSM549793,GSM549794,GSM549795,GSM549796,GSM549797,GSM549798,GSM549799,GSM549800,GSM549801,GSM549802,GSM549803,GSM549804,GSM549805,GSM549806,GSM549807,GSM549808,GSM549809,GSM549810,GSM549811,GSM549812,GSM549813,GSM549814,GSM549815,GSM549816,GSM549817,GSM549818,GSM549819,GSM549820,GSM549821,GSM569911,GSM569912,GSM569913,GSM569914,GSM569915,GSM569916,GSM569917,GSM569918,GSM569919,GSM569920,GSM569921,GSM569922,GSM569923,GSM569924,GSM569925,GSM569926,GSM599910,GSM599911,GSM599912,GSM599913,GSM599914,GSM599915,GSM599916,GSM599917,GSM599918,GSM599919,GSM599920,GSM599921,GSM631346,GSM631347,GSM631349,GSM631351,GSM631353,GSM631354,GSM631356,GSM631357,GSM631359,GSM631361,GSM631362,GSM631363,GSM631364,GSM631365,GSM631366,GSM631367,GSM631368,GSM631369,GSM631370,GSM631371,GSM631372,GSM631373,GSM631374,GSM631375,GSM631376,GSM631377,GSM631378,GSM631379,GSM631380,GSM631381,GSM631382,GSM631383,GSM631384,GSM631385,GSM631386,GSM631387,GSM631388,GSM631389,GSM631390,GSM631391,GSM794191,GSM794192,GSM794193,GSM794194,GSM794195,GSM794196,GSM794197,GSM794198,GSM794199,GSM794200,GSM794201,GSM794202,GSM794203,GSM794204,GSM794205,GSM794206,GSM794207,GSM794208,GSM794209,GSM794210,GSM794211,GSM794212,GSM794214,GSM794215,GSM794216,GSM794217,GSM794218,GSM794219
|
| 2 |
+
Chronic_obstructive_pulmonary_disease_(COPD),1.0,,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE162635.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE162635"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE162635"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE162635.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE162635.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE162635.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/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 (expression profiling in lung tissue)
|
| 43 |
+
is_gene_available = True
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability and converters
|
| 46 |
+
# From the sample characteristics, GOLD stages are present under key 2 (gold.1)
|
| 47 |
+
trait_row = 2 # 'gold.1' with values including healthy, O(0), I, II, III, IV
|
| 48 |
+
age_row = None
|
| 49 |
+
gender_row = None
|
| 50 |
+
|
| 51 |
+
def convert_trait(x):
|
| 52 |
+
if x is None or (isinstance(x, float) and pd.isna(x)):
|
| 53 |
+
return None
|
| 54 |
+
s = str(x)
|
| 55 |
+
# Extract the portion after colon if present
|
| 56 |
+
val = s.split(':', 1)[1] if ':' in s else s
|
| 57 |
+
v = val.strip().lower()
|
| 58 |
+
# Normalize some possible variants
|
| 59 |
+
v = v.replace('stage', '').strip()
|
| 60 |
+
# Map GOLD stages: I-IV => COPD (1); healthy/0/O => non-COPD (0)
|
| 61 |
+
if v in {'i', 'ii', 'iii', 'iv'}:
|
| 62 |
+
return 1
|
| 63 |
+
if v in {'healthy', '0', 'o', 'none', 'no', 'control'}:
|
| 64 |
+
return 0
|
| 65 |
+
# Any other ambiguous/unknown goes to None
|
| 66 |
+
return None
|
| 67 |
+
|
| 68 |
+
def convert_age(x):
|
| 69 |
+
# Not available in this dataset
|
| 70 |
+
return None
|
| 71 |
+
|
| 72 |
+
def convert_gender(x):
|
| 73 |
+
# Not available in this dataset
|
| 74 |
+
return None
|
| 75 |
+
|
| 76 |
+
# 3) Initial filtering and save metadata
|
| 77 |
+
is_trait_available = trait_row is not None
|
| 78 |
+
_ = validate_and_save_cohort_info(
|
| 79 |
+
is_final=False,
|
| 80 |
+
cohort=cohort,
|
| 81 |
+
info_path=json_path,
|
| 82 |
+
is_gene_available=is_gene_available,
|
| 83 |
+
is_trait_available=is_trait_available
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
# 4) Clinical Feature Extraction (only if trait data is available)
|
| 87 |
+
if trait_row is not None:
|
| 88 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 89 |
+
clinical_df=clinical_data,
|
| 90 |
+
trait=trait,
|
| 91 |
+
trait_row=trait_row,
|
| 92 |
+
convert_trait=convert_trait
|
| 93 |
+
)
|
| 94 |
+
preview = preview_df(selected_clinical_df)
|
| 95 |
+
print(preview)
|
| 96 |
+
|
| 97 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 98 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 99 |
+
|
| 100 |
+
# Step 3: Gene Data Extraction
|
| 101 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 102 |
+
gene_data = get_genetic_data(matrix_file)
|
| 103 |
+
|
| 104 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 105 |
+
print(gene_data.index[:20])
|
| 106 |
+
|
| 107 |
+
# Step 4: Gene Identifier Review
|
| 108 |
+
requires_gene_mapping = True
|
| 109 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 110 |
+
|
| 111 |
+
# Step 5: Gene Annotation
|
| 112 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 113 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 114 |
+
|
| 115 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 116 |
+
print("Gene annotation preview:")
|
| 117 |
+
print(preview_df(gene_annotation))
|
| 118 |
+
|
| 119 |
+
# Step 6: Gene Identifier Mapping
|
| 120 |
+
# Determine the appropriate columns for probe IDs and gene symbols based on the annotation preview
|
| 121 |
+
probe_col = 'ID'
|
| 122 |
+
gene_col = 'Gene Symbol'
|
| 123 |
+
|
| 124 |
+
# 1-2. Build the mapping dataframe from annotation
|
| 125 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_col)
|
| 126 |
+
|
| 127 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 128 |
+
probe_level_df = gene_data
|
| 129 |
+
gene_data = apply_gene_mapping(expression_df=probe_level_df, mapping_df=mapping_df)
|
| 130 |
+
|
| 131 |
+
# Step 7: Data Normalization and Linking
|
| 132 |
+
import os
|
| 133 |
+
|
| 134 |
+
# 1. Normalize gene symbols and save gene data
|
| 135 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 136 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 137 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 138 |
+
|
| 139 |
+
# 2. Link clinical and genetic data
|
| 140 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 141 |
+
|
| 142 |
+
# 3. Handle missing values
|
| 143 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 144 |
+
|
| 145 |
+
# 4. Bias check and remove biased demographic features if any
|
| 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 |
+
note = ("INFO: Trait derived from GOLD stages (gold.1): healthy/0/O mapped to 0; "
|
| 150 |
+
"stages I–IV mapped to 1. No age or gender available.")
|
| 151 |
+
is_usable = validate_and_save_cohort_info(
|
| 152 |
+
is_final=True,
|
| 153 |
+
cohort=cohort,
|
| 154 |
+
info_path=json_path,
|
| 155 |
+
is_gene_available=True,
|
| 156 |
+
is_trait_available=True,
|
| 157 |
+
is_biased=is_trait_biased,
|
| 158 |
+
df=unbiased_linked_data,
|
| 159 |
+
note=note
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
# 6. Save linked data if usable
|
| 163 |
+
if is_usable:
|
| 164 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 165 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE175616.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE175616"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE175616"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE175616.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE175616.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE175616.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/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 # RNA expression profiling of nasal epithelium; not miRNA-only or methylation-only.
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability (from provided Sample Characteristics Dictionary)
|
| 46 |
+
trait_row = None # COPD status not provided; not inferable from available fields.
|
| 47 |
+
age_row = 6 # 'age: <number>'
|
| 48 |
+
gender_row = 5 # 'Sex: male'/'Sex: female'
|
| 49 |
+
|
| 50 |
+
# 2.2) Conversion functions
|
| 51 |
+
def _after_colon(value: any) -> str:
|
| 52 |
+
if value is None or (isinstance(value, float) and pd.isna(value)):
|
| 53 |
+
return ""
|
| 54 |
+
s = str(value)
|
| 55 |
+
parts = s.split(":", 1)
|
| 56 |
+
return parts[1].strip() if len(parts) == 2 else s.strip()
|
| 57 |
+
|
| 58 |
+
def convert_trait(value: any):
|
| 59 |
+
# Binary: COPD (1) vs non-COPD (0). Not available here; robust parser for potential future use.
|
| 60 |
+
v = _after_colon(value).lower()
|
| 61 |
+
if v in {"copd", "yes", "case", "patient", "present", "true"}:
|
| 62 |
+
return 1
|
| 63 |
+
if v in {"no copd", "no", "control", "healthy", "normal", "absent", "false"}:
|
| 64 |
+
return 0
|
| 65 |
+
if "copd" in v:
|
| 66 |
+
return 1
|
| 67 |
+
return None
|
| 68 |
+
|
| 69 |
+
def convert_age(value: any):
|
| 70 |
+
# Continuous age in years
|
| 71 |
+
v = _after_colon(value)
|
| 72 |
+
m = re.search(r"[-+]?\d*\.?\d+", v)
|
| 73 |
+
if m:
|
| 74 |
+
try:
|
| 75 |
+
return float(m.group())
|
| 76 |
+
except Exception:
|
| 77 |
+
return None
|
| 78 |
+
return None
|
| 79 |
+
|
| 80 |
+
def convert_gender(value: any):
|
| 81 |
+
# Binary: female=0, male=1
|
| 82 |
+
v = _after_colon(value).lower()
|
| 83 |
+
if v in {"male", "m", "man"}:
|
| 84 |
+
return 1
|
| 85 |
+
if v in {"female", "f", "woman"}:
|
| 86 |
+
return 0
|
| 87 |
+
return None
|
| 88 |
+
|
| 89 |
+
# 3) Save metadata (initial filtering)
|
| 90 |
+
is_trait_available = trait_row is not None
|
| 91 |
+
_ = validate_and_save_cohort_info(
|
| 92 |
+
is_final=False,
|
| 93 |
+
cohort=cohort,
|
| 94 |
+
info_path=json_path,
|
| 95 |
+
is_gene_available=is_gene_available,
|
| 96 |
+
is_trait_available=is_trait_available
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
# 4) Clinical feature extraction (skip because trait_row is None)
|
| 100 |
+
if trait_row is not None:
|
| 101 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 102 |
+
clinical_df=clinical_data,
|
| 103 |
+
trait=trait,
|
| 104 |
+
trait_row=trait_row,
|
| 105 |
+
convert_trait=convert_trait,
|
| 106 |
+
age_row=age_row,
|
| 107 |
+
convert_age=convert_age,
|
| 108 |
+
gender_row=gender_row,
|
| 109 |
+
convert_gender=convert_gender
|
| 110 |
+
)
|
| 111 |
+
_ = preview_df(selected_clinical_df)
|
| 112 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 113 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
| 114 |
+
|
| 115 |
+
# Step 3: Gene Data Extraction
|
| 116 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 117 |
+
gene_data = get_genetic_data(matrix_file)
|
| 118 |
+
|
| 119 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 120 |
+
print(gene_data.index[:20])
|
| 121 |
+
|
| 122 |
+
# Step 4: Gene Identifier Review
|
| 123 |
+
print("requires_gene_mapping = True")
|
| 124 |
+
|
| 125 |
+
# Step 5: Gene Annotation
|
| 126 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 127 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 128 |
+
|
| 129 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 130 |
+
print("Gene annotation preview:")
|
| 131 |
+
print(preview_df(gene_annotation))
|
| 132 |
+
|
| 133 |
+
# Step 6: Gene Identifier Mapping
|
| 134 |
+
# 1-2) Build mapping from probe IDs to gene symbols using columns in annotation
|
| 135 |
+
probe_col = 'ID' # Matches probe IDs in gene_data (e.g., '10000_at')
|
| 136 |
+
gene_symbol_col = 'DESCRIPTION' # Contains gene description; symbols will be extracted from this text
|
| 137 |
+
|
| 138 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 139 |
+
|
| 140 |
+
# 3) Apply mapping to convert probe-level data to gene-level expression
|
| 141 |
+
# Keep original probe-level data; then overwrite gene_data with gene-level
|
| 142 |
+
probe_level_df = gene_data
|
| 143 |
+
gene_data = apply_gene_mapping(probe_level_df, mapping_df)
|
| 144 |
+
|
| 145 |
+
# Step 7: Gene Identifier Mapping
|
| 146 |
+
# 1-2) Decide mapping columns and build mapping dataframe
|
| 147 |
+
probe_col = 'ID' # Probe identifiers match the gene_data row IDs (e.g., '10000_at')
|
| 148 |
+
gene_symbol_col = 'DESCRIPTION' # Gene symbol/description text; symbols will be extracted from this text
|
| 149 |
+
|
| 150 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 151 |
+
|
| 152 |
+
# 3) Convert probe-level measurements to gene-level expression
|
| 153 |
+
# Reload probe-level data to ensure correct mapping input
|
| 154 |
+
probe_level_df = get_genetic_data(matrix_file)
|
| 155 |
+
gene_data = apply_gene_mapping(probe_level_df, mapping_df)
|
| 156 |
+
|
| 157 |
+
# Step 8: Data Normalization and Linking
|
| 158 |
+
import os
|
| 159 |
+
import pandas as pd
|
| 160 |
+
|
| 161 |
+
# 1) Normalize gene symbols and save gene expression data
|
| 162 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 163 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 164 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 165 |
+
|
| 166 |
+
# Determine trait availability from previous step (trait_row was None)
|
| 167 |
+
is_gene_available = True
|
| 168 |
+
is_trait_available = False # COPD status not available in this cohort per Step 2
|
| 169 |
+
|
| 170 |
+
# Prepare a placeholder for linked_data to avoid NameError downstream
|
| 171 |
+
linked_data = None
|
| 172 |
+
|
| 173 |
+
if is_trait_available:
|
| 174 |
+
# If trait were available, ensure clinical features are present
|
| 175 |
+
if 'selected_clinical_data' not in globals():
|
| 176 |
+
try:
|
| 177 |
+
selected_clinical_data = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 178 |
+
except Exception as e:
|
| 179 |
+
raise RuntimeError("Clinical features expected but not found. Aborting linking.") from e
|
| 180 |
+
|
| 181 |
+
# 2) Link clinical and genetic data
|
| 182 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 183 |
+
|
| 184 |
+
# 3) Missing value handling
|
| 185 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 186 |
+
|
| 187 |
+
# 4) Bias check and remove biased covariates
|
| 188 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 189 |
+
|
| 190 |
+
# 5) Final validation and save cohort info
|
| 191 |
+
is_usable = validate_and_save_cohort_info(
|
| 192 |
+
is_final=True,
|
| 193 |
+
cohort=cohort,
|
| 194 |
+
info_path=json_path,
|
| 195 |
+
is_gene_available=is_gene_available,
|
| 196 |
+
is_trait_available=is_trait_available,
|
| 197 |
+
is_biased=is_trait_biased,
|
| 198 |
+
df=unbiased_linked_data,
|
| 199 |
+
note="INFO: Trait available; standard preprocessing completed."
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
# 6) Save linked data if usable
|
| 203 |
+
if is_usable:
|
| 204 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 205 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 206 |
+
|
| 207 |
+
else:
|
| 208 |
+
# Trait not available: skip linking and downstream steps; still record metadata for gene data
|
| 209 |
+
# Use transposed gene data as df input for validation to pass shape checks
|
| 210 |
+
is_usable = validate_and_save_cohort_info(
|
| 211 |
+
is_final=True,
|
| 212 |
+
cohort=cohort,
|
| 213 |
+
info_path=json_path,
|
| 214 |
+
is_gene_available=is_gene_available,
|
| 215 |
+
is_trait_available=is_trait_available,
|
| 216 |
+
is_biased=False, # Not applicable; set to False for record completeness
|
| 217 |
+
df=normalized_gene_data.T,
|
| 218 |
+
note="INFO: Trait not available in sample characteristics; only gene data saved."
|
| 219 |
+
)
|
| 220 |
+
# Do not save out_data_file since dataset is not usable for association without trait
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE208662.py
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE208662"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE208662"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE208662.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE208662.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE208662.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/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 # Gene expression microarray analysis is explicitly stated
|
| 45 |
+
|
| 46 |
+
# 2) Variable availability based on the provided Sample Characteristics Dictionary
|
| 47 |
+
trait_row = 0 # 'disease state: COPD-IV' vs 'disease state: control'
|
| 48 |
+
age_row = None # Not provided
|
| 49 |
+
gender_row = None # Not provided
|
| 50 |
+
|
| 51 |
+
# 2.2) Conversion functions
|
| 52 |
+
def _after_colon(value):
|
| 53 |
+
if value is None:
|
| 54 |
+
return ""
|
| 55 |
+
s = str(value)
|
| 56 |
+
parts = s.split(":", 1)
|
| 57 |
+
return parts[1].strip() if len(parts) == 2 else s.strip()
|
| 58 |
+
|
| 59 |
+
def convert_trait(value):
|
| 60 |
+
v = _after_colon(value).lower()
|
| 61 |
+
if v == "":
|
| 62 |
+
return None
|
| 63 |
+
# Positive trait (COPD)
|
| 64 |
+
if "copd" in v:
|
| 65 |
+
return 1
|
| 66 |
+
# Controls / non-disease
|
| 67 |
+
if any(k in v for k in ["control", "healthy", "non-cld", "non cld", "noncld", "no cld", "no lung disease", "normal"]):
|
| 68 |
+
return 0
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
def convert_age(value):
|
| 72 |
+
v = _after_colon(value).lower()
|
| 73 |
+
if v in {"", "na", "n/a", "nan", "none", "unknown"}:
|
| 74 |
+
return None
|
| 75 |
+
# extract first number (integer or float)
|
| 76 |
+
m = re.search(r"(-?\d+(\.\d+)?)", v)
|
| 77 |
+
if m:
|
| 78 |
+
try:
|
| 79 |
+
return float(m.group(1))
|
| 80 |
+
except Exception:
|
| 81 |
+
return None
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
def convert_gender(value):
|
| 85 |
+
v = _after_colon(value).lower()
|
| 86 |
+
if v in {"", "na", "n/a", "nan", "none", "unknown"}:
|
| 87 |
+
return None
|
| 88 |
+
if v in {"female", "f", "woman", "women", "girl"}:
|
| 89 |
+
return 0
|
| 90 |
+
if v in {"male", "m", "man", "men", "boy"}:
|
| 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
|
| 105 |
+
if trait_row is not None:
|
| 106 |
+
# Ensure clinical_data exists
|
| 107 |
+
if 'clinical_data' not in globals():
|
| 108 |
+
raise RuntimeError("clinical_data DataFrame is not available in the environment.")
|
| 109 |
+
|
| 110 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 111 |
+
clinical_df=clinical_data,
|
| 112 |
+
trait=trait,
|
| 113 |
+
trait_row=trait_row,
|
| 114 |
+
convert_trait=convert_trait,
|
| 115 |
+
age_row=age_row,
|
| 116 |
+
convert_age=convert_age if age_row is not None else None,
|
| 117 |
+
gender_row=gender_row,
|
| 118 |
+
convert_gender=convert_gender if gender_row is not None else None
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
clinical_preview = preview_df(selected_clinical_df, n=5)
|
| 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 which columns to use for mapping
|
| 147 |
+
prob_col = 'ID' if 'ID' in gene_annotation.columns else 'probeset_id'
|
| 148 |
+
gene_col = 'SPOT_ID.1'
|
| 149 |
+
|
| 150 |
+
# 2. Get the gene mapping dataframe
|
| 151 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=prob_col, gene_col=gene_col)
|
| 152 |
+
|
| 153 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 154 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
| 155 |
+
|
| 156 |
+
# Step 7: Data Normalization and Linking
|
| 157 |
+
import os
|
| 158 |
+
import pandas as pd
|
| 159 |
+
|
| 160 |
+
# 1. Normalize gene symbols and save gene expression data
|
| 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 clinical and genetic data
|
| 166 |
+
# Ensure selected_clinical_df is available; if not, load from saved file
|
| 167 |
+
if 'selected_clinical_df' not in globals():
|
| 168 |
+
if os.path.exists(out_clinical_data_file):
|
| 169 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 170 |
+
else:
|
| 171 |
+
raise RuntimeError("Clinical features are not available in memory and the saved file is missing.")
|
| 172 |
+
|
| 173 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 174 |
+
|
| 175 |
+
# 3. Handle missing values
|
| 176 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 177 |
+
|
| 178 |
+
# 4. Judge bias and remove biased demographic features
|
| 179 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 180 |
+
|
| 181 |
+
# 5. Final validation and save cohort info
|
| 182 |
+
note = ("INFO: Dataset includes multiple treatment arms (Printex/Zn/LPS/Sham). "
|
| 183 |
+
"Only disease state (trait) is available as clinical covariate; age and gender not provided.")
|
| 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=note
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
# 6. Save linked data if usable
|
| 196 |
+
if is_usable:
|
| 197 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 198 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE210272.py
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE210272"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE210272"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE210272.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE210272.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE210272.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/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 |
+
from typing import Any, Optional
|
| 42 |
+
|
| 43 |
+
# 1) Gene expression availability (Affymetrix Human Gene 1.0 ST Arrays => mRNA expression)
|
| 44 |
+
is_gene_available = True
|
| 45 |
+
|
| 46 |
+
# 2) Variable availability (from Sample Characteristics Dictionary)
|
| 47 |
+
trait_row = None # No explicit COPD status field found; cannot robustly infer from FEV1% alone
|
| 48 |
+
age_row = 2 # 'age: ...'
|
| 49 |
+
gender_row = 1 # 'Sex: Male/Female'
|
| 50 |
+
|
| 51 |
+
# 2.2) Converters
|
| 52 |
+
def _extract_value(cell: Any) -> str:
|
| 53 |
+
if cell is None:
|
| 54 |
+
return ''
|
| 55 |
+
s = str(cell)
|
| 56 |
+
parts = s.split(':', 1)
|
| 57 |
+
return parts[1].strip() if len(parts) == 2 else s.strip()
|
| 58 |
+
|
| 59 |
+
def convert_trait(x: Any) -> Optional[int]:
|
| 60 |
+
v = _extract_value(x).lower()
|
| 61 |
+
if v in ('', 'na', 'n/a', 'none', 'unknown', 'not available'):
|
| 62 |
+
return None
|
| 63 |
+
if any(k in v for k in ['copd', 'chronic obstructive']):
|
| 64 |
+
if any(k in v for k in ['no copd', 'without copd', 'control', 'non-copd', 'healthy', 'normal']):
|
| 65 |
+
return 0
|
| 66 |
+
return 1
|
| 67 |
+
if 'case' in v and 'control' not in v:
|
| 68 |
+
return 1
|
| 69 |
+
if 'control' in v:
|
| 70 |
+
return 0
|
| 71 |
+
return None
|
| 72 |
+
|
| 73 |
+
def convert_age(x: Any) -> Optional[float]:
|
| 74 |
+
v = _extract_value(x)
|
| 75 |
+
if v.lower() in ('', 'na', 'n/a', 'none', 'unknown'):
|
| 76 |
+
return None
|
| 77 |
+
m = re.search(r'[-+]?\d*\.?\d+', v)
|
| 78 |
+
try:
|
| 79 |
+
return float(m.group()) if m else None
|
| 80 |
+
except Exception:
|
| 81 |
+
return None
|
| 82 |
+
|
| 83 |
+
def convert_gender(x: Any) -> Optional[int]:
|
| 84 |
+
v = _extract_value(x).strip().lower()
|
| 85 |
+
if v in ('', 'na', 'n/a', 'none', 'unknown'):
|
| 86 |
+
return None
|
| 87 |
+
if v in ('male', 'm'):
|
| 88 |
+
return 1
|
| 89 |
+
if v in ('female', 'f'):
|
| 90 |
+
return 0
|
| 91 |
+
return None
|
| 92 |
+
|
| 93 |
+
# 3) Save metadata with initial filtering
|
| 94 |
+
is_trait_available = trait_row is not None
|
| 95 |
+
_ = validate_and_save_cohort_info(
|
| 96 |
+
is_final=False,
|
| 97 |
+
cohort=cohort,
|
| 98 |
+
info_path=json_path,
|
| 99 |
+
is_gene_available=is_gene_available,
|
| 100 |
+
is_trait_available=is_trait_available
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
# 4) Clinical feature extraction (skip because trait_row is None)
|
| 104 |
+
if is_trait_available:
|
| 105 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 106 |
+
clinical_df=clinical_data,
|
| 107 |
+
trait=trait,
|
| 108 |
+
trait_row=trait_row,
|
| 109 |
+
convert_trait=convert_trait,
|
| 110 |
+
age_row=age_row,
|
| 111 |
+
convert_age=convert_age,
|
| 112 |
+
gender_row=gender_row,
|
| 113 |
+
convert_gender=convert_gender
|
| 114 |
+
)
|
| 115 |
+
_ = preview_df(selected_clinical_df)
|
| 116 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 117 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 118 |
+
|
| 119 |
+
# Step 3: Gene Data Extraction
|
| 120 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 121 |
+
gene_data = get_genetic_data(matrix_file)
|
| 122 |
+
|
| 123 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 124 |
+
print(gene_data.index[:20])
|
| 125 |
+
|
| 126 |
+
# Step 4: Gene Identifier Review
|
| 127 |
+
print("requires_gene_mapping = True")
|
| 128 |
+
|
| 129 |
+
# Step 5: Gene Annotation
|
| 130 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 131 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 132 |
+
|
| 133 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 134 |
+
print("Gene annotation preview:")
|
| 135 |
+
print(preview_df(gene_annotation))
|
| 136 |
+
|
| 137 |
+
# Step 6: Gene Identifier Mapping
|
| 138 |
+
import re
|
| 139 |
+
import pandas as pd
|
| 140 |
+
|
| 141 |
+
# Use explicit columns based on the annotation preview
|
| 142 |
+
id_col = 'ID'
|
| 143 |
+
gene_col = 'ORF'
|
| 144 |
+
|
| 145 |
+
# Build mapping dataframe and restrict to probes present in expression data
|
| 146 |
+
mapping_df = gene_annotation[[id_col, gene_col]].dropna().copy()
|
| 147 |
+
mapping_df[id_col] = mapping_df[id_col].astype(str).str.strip()
|
| 148 |
+
mapping_df[gene_col] = mapping_df[gene_col].astype(str).str.strip()
|
| 149 |
+
mapping_df = mapping_df[mapping_df[id_col].isin(gene_data.index)]
|
| 150 |
+
|
| 151 |
+
# Split possible multi-mapped entries; keep only valid Ensembl IDs
|
| 152 |
+
def split_genes(s: str):
|
| 153 |
+
s = s.strip().strip('"').strip("'")
|
| 154 |
+
if s == '' or s.lower() in ('na', 'n/a', 'none', 'nan'):
|
| 155 |
+
return []
|
| 156 |
+
parts = re.split(r'\s*(?:/{2,3}|;|,|\|)\s*', s)
|
| 157 |
+
return [p for p in parts if p]
|
| 158 |
+
|
| 159 |
+
mapping_df['Gene'] = mapping_df[gene_col].apply(split_genes)
|
| 160 |
+
mapping_df = mapping_df.explode('Gene').dropna(subset=['Gene'])
|
| 161 |
+
# Keep canonical Ensembl gene IDs
|
| 162 |
+
mapping_df = mapping_df[mapping_df['Gene'].str.match(r'^ENSG\d+$')]
|
| 163 |
+
|
| 164 |
+
# If nothing left after filtering, raise a clear error
|
| 165 |
+
if mapping_df.empty:
|
| 166 |
+
raise ValueError("No valid Ensembl mappings found in annotation. Check annotation columns and contents.")
|
| 167 |
+
|
| 168 |
+
# Count mappings per probe for equal split, then join to expression and aggregate
|
| 169 |
+
mapping_df['num_genes'] = mapping_df.groupby(id_col)[id_col].transform('count')
|
| 170 |
+
mapping_df = mapping_df.set_index(id_col)
|
| 171 |
+
|
| 172 |
+
# Join mapping with expression data and distribute probe signal equally among mapped genes
|
| 173 |
+
merged = mapping_df[['Gene', 'num_genes']].join(gene_data, how='inner')
|
| 174 |
+
expr_cols = gene_data.columns.tolist()
|
| 175 |
+
merged[expr_cols] = merged[expr_cols].div(merged['num_genes'].replace(0, 1), axis=0)
|
| 176 |
+
|
| 177 |
+
# Aggregate to gene-level
|
| 178 |
+
gene_level = merged.groupby('Gene')[expr_cols].sum()
|
| 179 |
+
|
| 180 |
+
# Sanity checks to avoid corrupted indices
|
| 181 |
+
if gene_level.shape[0] == 0:
|
| 182 |
+
raise ValueError("Mapped gene-level matrix is empty after aggregation.")
|
| 183 |
+
if not gene_level.index.to_series().str.startswith('ENSG').all():
|
| 184 |
+
bad_examples = gene_level.index[~gene_level.index.to_series().str.startswith('ENSG')][:5].tolist()
|
| 185 |
+
raise ValueError(f"Unexpected gene identifiers detected (examples: {bad_examples}).")
|
| 186 |
+
|
| 187 |
+
# Assign result and print basic info
|
| 188 |
+
gene_data = gene_level
|
| 189 |
+
print(f"Gene-level data shape: {gene_data.shape}")
|
| 190 |
+
print(f"First 5 gene IDs: {list(gene_data.index[:5])}")
|
| 191 |
+
|
| 192 |
+
# Step 7: Data Normalization and Linking
|
| 193 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
| 194 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 195 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 196 |
+
|
| 197 |
+
# 2. Link the clinical and genetic data with the 'geo_link_clinical_genetic_data' function from the library.
|
| 198 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 199 |
+
|
| 200 |
+
# 3. Handle missing values in the linked data
|
| 201 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 202 |
+
|
| 203 |
+
# 4. Determine whether the trait and some demographic features are severely biased, and remove biased features.
|
| 204 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 205 |
+
|
| 206 |
+
# 5. Conduct quality check and save the cohort information.
|
| 207 |
+
is_usable = validate_and_save_cohort_info(True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data)
|
| 208 |
+
|
| 209 |
+
# 6. If the linked data is usable, save it as a CSV file to 'out_data_file'.
|
| 210 |
+
if is_usable:
|
| 211 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE212331.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE212331"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE212331"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE212331.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE212331.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE212331.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
|
| 42 |
+
# 1. Gene Expression Data Availability
|
| 43 |
+
is_gene_available = True # Based on series summary: gene expression profiles from induced sputum
|
| 44 |
+
|
| 45 |
+
# 2. Variable Availability and Data Type Conversion
|
| 46 |
+
|
| 47 |
+
# Keys from Sample Characteristics Dictionary
|
| 48 |
+
trait_row = 1 # 'disease group: COPD' vs 'disease group: Healthy Control'
|
| 49 |
+
age_row = 3 # 'age: <number>'
|
| 50 |
+
gender_row = 4 # 'gender: Male'/'gender: Female'
|
| 51 |
+
|
| 52 |
+
def _after_colon(value):
|
| 53 |
+
if value is None:
|
| 54 |
+
return None
|
| 55 |
+
s = str(value)
|
| 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(value):
|
| 61 |
+
v = _after_colon(value)
|
| 62 |
+
if v is None:
|
| 63 |
+
return None
|
| 64 |
+
vl = v.lower()
|
| 65 |
+
# Map COPD cases to 1, healthy controls to 0
|
| 66 |
+
if "copd" in vl:
|
| 67 |
+
return 1
|
| 68 |
+
if ("healthy" in vl and "control" in vl) or vl in {"control", "healthy", "hc", "ctrl"}:
|
| 69 |
+
return 0
|
| 70 |
+
if vl in {"case", "patient", "disease"}:
|
| 71 |
+
return 1
|
| 72 |
+
if vl in {"normal"}:
|
| 73 |
+
return 0
|
| 74 |
+
return None
|
| 75 |
+
|
| 76 |
+
def convert_age(value):
|
| 77 |
+
v = _after_colon(value)
|
| 78 |
+
if v is None:
|
| 79 |
+
return None
|
| 80 |
+
vl = v.lower()
|
| 81 |
+
if vl in {"na", "n/a", "nan", ""}:
|
| 82 |
+
return None
|
| 83 |
+
m = re.search(r"[-+]?\d*\.?\d+", v)
|
| 84 |
+
if not m:
|
| 85 |
+
return None
|
| 86 |
+
try:
|
| 87 |
+
num = float(m.group())
|
| 88 |
+
return num
|
| 89 |
+
except Exception:
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
def convert_gender(value):
|
| 93 |
+
v = _after_colon(value)
|
| 94 |
+
if v is None:
|
| 95 |
+
return None
|
| 96 |
+
vl = v.lower()
|
| 97 |
+
if "male" in vl or vl == "m":
|
| 98 |
+
return 1
|
| 99 |
+
if "female" in vl or vl == "f":
|
| 100 |
+
return 0
|
| 101 |
+
return None
|
| 102 |
+
|
| 103 |
+
# 3. Save Metadata (initial filtering)
|
| 104 |
+
is_trait_available = trait_row is not None
|
| 105 |
+
_ = validate_and_save_cohort_info(
|
| 106 |
+
is_final=False,
|
| 107 |
+
cohort=cohort,
|
| 108 |
+
info_path=json_path,
|
| 109 |
+
is_gene_available=is_gene_available,
|
| 110 |
+
is_trait_available=is_trait_available
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# 4. Clinical Feature Extraction (only if trait is available)
|
| 114 |
+
if trait_row is not None:
|
| 115 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 116 |
+
clinical_df=clinical_data,
|
| 117 |
+
trait=trait,
|
| 118 |
+
trait_row=trait_row,
|
| 119 |
+
convert_trait=convert_trait,
|
| 120 |
+
age_row=age_row,
|
| 121 |
+
convert_age=convert_age,
|
| 122 |
+
gender_row=gender_row,
|
| 123 |
+
convert_gender=convert_gender
|
| 124 |
+
)
|
| 125 |
+
preview = preview_df(selected_clinical_df)
|
| 126 |
+
print(preview)
|
| 127 |
+
|
| 128 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 129 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 130 |
+
|
| 131 |
+
# Step 3: Gene Data Extraction
|
| 132 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 133 |
+
gene_data = get_genetic_data(matrix_file)
|
| 134 |
+
|
| 135 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 136 |
+
print(gene_data.index[:20])
|
| 137 |
+
|
| 138 |
+
# Step 4: Gene Identifier Review
|
| 139 |
+
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 |
+
# Identify the appropriate columns in the annotation for probe IDs and gene symbols
|
| 151 |
+
probe_col = 'ID'
|
| 152 |
+
gene_symbol_col = 'Symbol'
|
| 153 |
+
|
| 154 |
+
# Build the mapping dataframe (probe -> gene symbol)
|
| 155 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 156 |
+
|
| 157 |
+
# Apply the mapping to convert probe-level data to gene-level data
|
| 158 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 159 |
+
|
| 160 |
+
# Step 7: Data Normalization and Linking
|
| 161 |
+
import os
|
| 162 |
+
import pandas as pd
|
| 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 |
+
# 2. Link clinical and genetic data
|
| 170 |
+
try:
|
| 171 |
+
selected_clinical_df
|
| 172 |
+
except NameError:
|
| 173 |
+
# Load previously saved clinical data if not in memory
|
| 174 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 175 |
+
|
| 176 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 177 |
+
|
| 178 |
+
# 3. Handle missing values
|
| 179 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 180 |
+
|
| 181 |
+
# 4. Bias check and remove biased demographic features
|
| 182 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 183 |
+
|
| 184 |
+
# 5. Final validation and save cohort info
|
| 185 |
+
is_gene_available = (normalized_gene_data.shape[0] > 0 and normalized_gene_data.shape[1] > 0)
|
| 186 |
+
is_trait_available = (trait in linked_data.columns)
|
| 187 |
+
note = "INFO: Illumina probe-level data mapped to symbols; sputum samples from COPD vs healthy controls."
|
| 188 |
+
|
| 189 |
+
is_usable = validate_and_save_cohort_info(
|
| 190 |
+
is_final=True,
|
| 191 |
+
cohort=cohort,
|
| 192 |
+
info_path=json_path,
|
| 193 |
+
is_gene_available=is_gene_available,
|
| 194 |
+
is_trait_available=is_trait_available,
|
| 195 |
+
is_biased=is_trait_biased,
|
| 196 |
+
df=unbiased_linked_data,
|
| 197 |
+
note=note
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
# 6. Save linked data if usable
|
| 201 |
+
if is_usable:
|
| 202 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 203 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE21359.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE21359"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE21359"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE21359.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE21359.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE21359.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
import pandas as pd
|
| 42 |
+
import numpy as np
|
| 43 |
+
|
| 44 |
+
# 1) Gene expression data availability (Affymetrix expression arrays per background info)
|
| 45 |
+
is_gene_available = True
|
| 46 |
+
|
| 47 |
+
# 2) Variable availability and converters
|
| 48 |
+
# Rows determined from the provided Sample Characteristics Dictionary
|
| 49 |
+
trait_row = 3 # smoking status field contains COPD info
|
| 50 |
+
age_row = 0 # age
|
| 51 |
+
gender_row = 1 # sex
|
| 52 |
+
|
| 53 |
+
def _after_colon(value: str) -> str:
|
| 54 |
+
if value is None or (isinstance(value, float) and np.isnan(value)):
|
| 55 |
+
return ""
|
| 56 |
+
parts = str(value).split(":", 1)
|
| 57 |
+
val = parts[1] if len(parts) > 1 else parts[0]
|
| 58 |
+
return val.strip()
|
| 59 |
+
|
| 60 |
+
def convert_trait(value):
|
| 61 |
+
# Binary: COPD (1) vs non-COPD (0)
|
| 62 |
+
try:
|
| 63 |
+
v = _after_colon(value).lower()
|
| 64 |
+
if v == "":
|
| 65 |
+
return None
|
| 66 |
+
if "copd" in v:
|
| 67 |
+
return 1
|
| 68 |
+
# If explicitly non-smoker or smoker without COPD mentioned => non-COPD
|
| 69 |
+
if "non-smoker" in v or "nonsmoker" in v or "smoker" in v:
|
| 70 |
+
return 0
|
| 71 |
+
# Heuristic: absence of 'copd' implies non-copd for this field
|
| 72 |
+
return 0
|
| 73 |
+
except Exception:
|
| 74 |
+
return None
|
| 75 |
+
|
| 76 |
+
def convert_age(value):
|
| 77 |
+
# Continuous
|
| 78 |
+
try:
|
| 79 |
+
v = _after_colon(value)
|
| 80 |
+
if v == "":
|
| 81 |
+
return None
|
| 82 |
+
# Extract first integer number
|
| 83 |
+
m = re.search(r"[-+]?\d+\.?\d*", v)
|
| 84 |
+
if m:
|
| 85 |
+
return float(m.group())
|
| 86 |
+
return None
|
| 87 |
+
except Exception:
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
def convert_gender(value):
|
| 91 |
+
# Binary: female=0, male=1
|
| 92 |
+
try:
|
| 93 |
+
v = _after_colon(value).strip().lower()
|
| 94 |
+
if v in ("m", "male"):
|
| 95 |
+
return 1
|
| 96 |
+
if v in ("f", "female"):
|
| 97 |
+
return 0
|
| 98 |
+
return None
|
| 99 |
+
except Exception:
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
# 3) Save metadata (initial filtering)
|
| 103 |
+
is_trait_available = trait_row is not None
|
| 104 |
+
_ = validate_and_save_cohort_info(
|
| 105 |
+
is_final=False,
|
| 106 |
+
cohort=cohort,
|
| 107 |
+
info_path=json_path,
|
| 108 |
+
is_gene_available=is_gene_available,
|
| 109 |
+
is_trait_available=is_trait_available
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
# 4) Clinical feature extraction (only if clinical data is available)
|
| 113 |
+
if trait_row is not None:
|
| 114 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 115 |
+
clinical_df=clinical_data,
|
| 116 |
+
trait=trait,
|
| 117 |
+
trait_row=trait_row,
|
| 118 |
+
convert_trait=convert_trait,
|
| 119 |
+
age_row=age_row,
|
| 120 |
+
convert_age=convert_age,
|
| 121 |
+
gender_row=gender_row,
|
| 122 |
+
convert_gender=convert_gender
|
| 123 |
+
)
|
| 124 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 125 |
+
print(clinical_preview)
|
| 126 |
+
|
| 127 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 128 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
| 129 |
+
|
| 130 |
+
# Step 3: Gene Data Extraction
|
| 131 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 132 |
+
gene_data = get_genetic_data(matrix_file)
|
| 133 |
+
|
| 134 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 135 |
+
print(gene_data.index[:20])
|
| 136 |
+
|
| 137 |
+
# Step 4: Gene Identifier Review
|
| 138 |
+
requires_gene_mapping = True
|
| 139 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 140 |
+
|
| 141 |
+
# Step 5: Gene Annotation
|
| 142 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 143 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 144 |
+
|
| 145 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 146 |
+
print("Gene annotation preview:")
|
| 147 |
+
print(preview_df(gene_annotation))
|
| 148 |
+
|
| 149 |
+
# Step 6: Gene Identifier Mapping
|
| 150 |
+
# Identify the probe ID column and the gene symbol column in the annotation
|
| 151 |
+
probe_col = 'ID'
|
| 152 |
+
gene_symbol_col = 'Gene Symbol'
|
| 153 |
+
|
| 154 |
+
# Build mapping dataframe from annotation
|
| 155 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 156 |
+
|
| 157 |
+
# Map probe-level expression to gene-level expression
|
| 158 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 159 |
+
|
| 160 |
+
# Step 7: Data Normalization and Linking
|
| 161 |
+
import os
|
| 162 |
+
|
| 163 |
+
# 1. Normalize gene symbols and save gene data
|
| 164 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 165 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 166 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 167 |
+
|
| 168 |
+
# 2. Link clinical and genetic data
|
| 169 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 170 |
+
|
| 171 |
+
# 3. Handle missing values systematically
|
| 172 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 173 |
+
|
| 174 |
+
# 4. Bias assessment and removal of biased demographic features
|
| 175 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 176 |
+
|
| 177 |
+
# 5. Final validation and save cohort metadata
|
| 178 |
+
# Ensure native Python bools to avoid JSON serialization issues
|
| 179 |
+
is_gene_available = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
|
| 180 |
+
is_trait_available = bool((trait in linked_data.columns) and bool(linked_data[trait].notna().any()))
|
| 181 |
+
|
| 182 |
+
note = "INFO: Affymetrix platform; probes mapped to gene symbols via GPL; COPD inferred from smoking status (COPD vs non-COPD)."
|
| 183 |
+
is_usable = validate_and_save_cohort_info(
|
| 184 |
+
is_final=True,
|
| 185 |
+
cohort=cohort,
|
| 186 |
+
info_path=json_path,
|
| 187 |
+
is_gene_available=bool(is_gene_available),
|
| 188 |
+
is_trait_available=bool(is_trait_available),
|
| 189 |
+
is_biased=bool(is_trait_biased),
|
| 190 |
+
df=unbiased_linked_data,
|
| 191 |
+
note=note
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
# 6. Save linked data if usable
|
| 195 |
+
if bool(is_usable):
|
| 196 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 197 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE32030.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE32030"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE32030"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE32030.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE32030.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE32030.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/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 (microarray gene expression described in background)
|
| 44 |
+
is_gene_available = True
|
| 45 |
+
|
| 46 |
+
# 2) Variable availability and converters
|
| 47 |
+
|
| 48 |
+
# COPD status only appears as positive ("copd status: yes") without explicit negatives,
|
| 49 |
+
# making the trait effectively a constant/one-class under the available keys.
|
| 50 |
+
# Per instructions, treat as not available for association analysis.
|
| 51 |
+
trait_row = None
|
| 52 |
+
|
| 53 |
+
# No explicit age or gender information is present in the dictionary.
|
| 54 |
+
age_row = None
|
| 55 |
+
gender_row = None
|
| 56 |
+
|
| 57 |
+
# Converters (defined but unused since trait/age/gender rows are unavailable)
|
| 58 |
+
def _extract_after_colon(x):
|
| 59 |
+
if x is None or (isinstance(x, float) and pd.isna(x)):
|
| 60 |
+
return None
|
| 61 |
+
s = str(x).strip()
|
| 62 |
+
if ':' in s:
|
| 63 |
+
parts = s.split(':', 1)
|
| 64 |
+
key = parts[0].strip().lower()
|
| 65 |
+
val = parts[1].strip().lower()
|
| 66 |
+
return key, val
|
| 67 |
+
else:
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
def convert_trait(x):
|
| 71 |
+
kv = _extract_after_colon(x)
|
| 72 |
+
if not kv:
|
| 73 |
+
return None
|
| 74 |
+
key, val = kv
|
| 75 |
+
if 'copd' in key:
|
| 76 |
+
if val in {'yes', 'y', 'positive', 'pos'}:
|
| 77 |
+
return 1
|
| 78 |
+
if val in {'no', 'n', 'negative', 'neg'}:
|
| 79 |
+
return 0
|
| 80 |
+
if val in {'healthy', 'control'}:
|
| 81 |
+
return 0
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
def convert_age(x):
|
| 85 |
+
kv = _extract_after_colon(x)
|
| 86 |
+
if not kv:
|
| 87 |
+
return None
|
| 88 |
+
_, val = kv
|
| 89 |
+
m = re.search(r'(\d+(\.\d+)?)', val)
|
| 90 |
+
if m:
|
| 91 |
+
try:
|
| 92 |
+
return float(m.group(1))
|
| 93 |
+
except Exception:
|
| 94 |
+
return None
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
def convert_gender(x):
|
| 98 |
+
kv = _extract_after_colon(x)
|
| 99 |
+
if not kv:
|
| 100 |
+
return None
|
| 101 |
+
_, val = kv
|
| 102 |
+
v = val.strip().lower()
|
| 103 |
+
if v in {'male', 'm'}:
|
| 104 |
+
return 1
|
| 105 |
+
if v in {'female', 'f'}:
|
| 106 |
+
return 0
|
| 107 |
+
return None
|
| 108 |
+
|
| 109 |
+
# 3) Save metadata (initial filtering)
|
| 110 |
+
is_trait_available = trait_row is not None
|
| 111 |
+
_ = validate_and_save_cohort_info(
|
| 112 |
+
is_final=False,
|
| 113 |
+
cohort=cohort,
|
| 114 |
+
info_path=json_path,
|
| 115 |
+
is_gene_available=is_gene_available,
|
| 116 |
+
is_trait_available=is_trait_available
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# 4) Clinical feature extraction is skipped because trait_row is None (trait not available)
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE64593.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE64593"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE64593"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE64593.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE64593.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE64593.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# Determine gene expression availability based on series description (Affymetrix expression profiling)
|
| 40 |
+
is_gene_available = True
|
| 41 |
+
|
| 42 |
+
# Variable availability based on Sample Characteristics Dictionary
|
| 43 |
+
# {0: ['smoking status: smoker'], 1: ['disease state: HIV-', 'disease state: HIV+'], 2: ['cell type: alveolar macrophage']}
|
| 44 |
+
# No explicit or inferable COPD status; no age; no gender.
|
| 45 |
+
trait_row = None
|
| 46 |
+
age_row = None
|
| 47 |
+
gender_row = None
|
| 48 |
+
|
| 49 |
+
# Converters (defined for completeness; not used since corresponding rows are None)
|
| 50 |
+
def _extract_value(x):
|
| 51 |
+
if x is None:
|
| 52 |
+
return None
|
| 53 |
+
try:
|
| 54 |
+
s = str(x)
|
| 55 |
+
if ':' in s:
|
| 56 |
+
s = s.split(':', 1)[1]
|
| 57 |
+
return s.strip()
|
| 58 |
+
except Exception:
|
| 59 |
+
return None
|
| 60 |
+
|
| 61 |
+
def convert_trait(x):
|
| 62 |
+
# Map COPD-related labels to binary if present; otherwise None
|
| 63 |
+
v = _extract_value(x)
|
| 64 |
+
if not v:
|
| 65 |
+
return None
|
| 66 |
+
vl = v.lower()
|
| 67 |
+
case_tokens = ['copd', 'emphysema', 'low dlco', 'obstructive']
|
| 68 |
+
control_tokens = ['healthy', 'normal', 'no copd', 'non-copd']
|
| 69 |
+
if any(t in vl for t in case_tokens):
|
| 70 |
+
return 1
|
| 71 |
+
if any(t in vl for t in control_tokens):
|
| 72 |
+
return 0
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
def convert_age(x):
|
| 76 |
+
v = _extract_value(x)
|
| 77 |
+
if not v:
|
| 78 |
+
return None
|
| 79 |
+
# extract first number as age
|
| 80 |
+
import re
|
| 81 |
+
m = re.search(r'(\d+(\.\d+)?)', v)
|
| 82 |
+
if m:
|
| 83 |
+
try:
|
| 84 |
+
return float(m.group(1))
|
| 85 |
+
except Exception:
|
| 86 |
+
return None
|
| 87 |
+
return None
|
| 88 |
+
|
| 89 |
+
def convert_gender(x):
|
| 90 |
+
v = _extract_value(x)
|
| 91 |
+
if not v:
|
| 92 |
+
return None
|
| 93 |
+
vl = v.lower()
|
| 94 |
+
if vl in ['female', 'f', 'woman', 'women']:
|
| 95 |
+
return 0
|
| 96 |
+
if vl in ['male', 'm', 'man', 'men']:
|
| 97 |
+
return 1
|
| 98 |
+
return None
|
| 99 |
+
|
| 100 |
+
# Initial filtering and save metadata
|
| 101 |
+
is_trait_available = trait_row is not None
|
| 102 |
+
validate_and_save_cohort_info(False, cohort, json_path, is_gene_available, is_trait_available)
|
| 103 |
+
|
| 104 |
+
# Clinical feature extraction skipped because trait_row is None
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE64599.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE64599"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE64599"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE64599.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE64599.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE64599.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/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 availability based on provided background
|
| 40 |
+
# The series focuses on gene expression in alveolar macrophages; no indication it's miRNA-only or methylation-only.
|
| 41 |
+
is_gene_available = True
|
| 42 |
+
|
| 43 |
+
# Step 2: Variable availability and conversion functions
|
| 44 |
+
|
| 45 |
+
# From the provided Sample Characteristics Dictionary:
|
| 46 |
+
# {0: ['smoking status: smoker'],
|
| 47 |
+
# 1: ['disease state: HIV-', 'disease state: HIV+'],
|
| 48 |
+
# 2: ['cell type: alveolar macrophage']}
|
| 49 |
+
# There is no COPD status, age, or gender. Smoking status is constant and not our trait. Therefore:
|
| 50 |
+
trait_row = None
|
| 51 |
+
age_row = None
|
| 52 |
+
gender_row = None
|
| 53 |
+
|
| 54 |
+
def _extract_value(x):
|
| 55 |
+
if x is None:
|
| 56 |
+
return None
|
| 57 |
+
s = str(x)
|
| 58 |
+
parts = s.split(":", 1)
|
| 59 |
+
val = parts[-1] if len(parts) > 1 else s
|
| 60 |
+
val = val.strip()
|
| 61 |
+
return val if val != "" else None
|
| 62 |
+
|
| 63 |
+
def convert_trait(x):
|
| 64 |
+
# Binary: 1 = COPD/emphysema case, 0 = control/non-COPD
|
| 65 |
+
val = _extract_value(x)
|
| 66 |
+
if val is None:
|
| 67 |
+
return None
|
| 68 |
+
v = val.lower()
|
| 69 |
+
# Heuristics in case trait wording varies
|
| 70 |
+
# Positive indicators
|
| 71 |
+
pos_keywords = ["copd", "emphysema"]
|
| 72 |
+
neg_keywords = ["control", "healthy", "normal", "no copd", "non-copd", "without copd", "no evidence of copd"]
|
| 73 |
+
if any(k in v for k in pos_keywords):
|
| 74 |
+
if any(k in v for k in neg_keywords) or "no " in v or "non-" in v:
|
| 75 |
+
return 0
|
| 76 |
+
return 1
|
| 77 |
+
if v in {"case", "patient", "diseased"}:
|
| 78 |
+
return 1
|
| 79 |
+
if v in {"control", "healthy", "normal"}:
|
| 80 |
+
return 0
|
| 81 |
+
return None
|
| 82 |
+
|
| 83 |
+
def convert_age(x):
|
| 84 |
+
# Continuous age in years (float)
|
| 85 |
+
val = _extract_value(x)
|
| 86 |
+
if val is None:
|
| 87 |
+
return None
|
| 88 |
+
import re
|
| 89 |
+
m = re.search(r"[-+]?\d*\.?\d+", val)
|
| 90 |
+
if m:
|
| 91 |
+
try:
|
| 92 |
+
return float(m.group(0))
|
| 93 |
+
except Exception:
|
| 94 |
+
return None
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
def convert_gender(x):
|
| 98 |
+
# Binary: female=0, male=1
|
| 99 |
+
val = _extract_value(x)
|
| 100 |
+
if val is None:
|
| 101 |
+
return None
|
| 102 |
+
v = val.strip().lower()
|
| 103 |
+
if v in {"male", "m", "man", "boy"}:
|
| 104 |
+
return 1
|
| 105 |
+
if v in {"female", "f", "woman", "girl"}:
|
| 106 |
+
return 0
|
| 107 |
+
return None
|
| 108 |
+
|
| 109 |
+
# Step 3: Initial filtering and save metadata
|
| 110 |
+
is_trait_available = trait_row is not None
|
| 111 |
+
_ = validate_and_save_cohort_info(
|
| 112 |
+
is_final=False,
|
| 113 |
+
cohort=cohort,
|
| 114 |
+
info_path=json_path,
|
| 115 |
+
is_gene_available=is_gene_available,
|
| 116 |
+
is_trait_available=is_trait_available
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# Step 4: Clinical feature extraction (skip because trait_row is None)
|
| 120 |
+
# If trait_row becomes available in future updates, the below block can be enabled.
|
| 121 |
+
if trait_row is not None:
|
| 122 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 123 |
+
clinical_df=clinical_data,
|
| 124 |
+
trait=trait,
|
| 125 |
+
trait_row=trait_row,
|
| 126 |
+
convert_trait=convert_trait,
|
| 127 |
+
age_row=age_row,
|
| 128 |
+
convert_age=convert_age,
|
| 129 |
+
gender_row=gender_row,
|
| 130 |
+
convert_gender=convert_gender
|
| 131 |
+
)
|
| 132 |
+
clinical_preview = preview_df(selected_clinical_df, n=5)
|
| 133 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 134 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 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 |
+
# Affymetrix probe set IDs (e.g., '1007_s_at') are not gene symbols and require mapping.
|
| 145 |
+
requires_gene_mapping = True
|
| 146 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 147 |
+
|
| 148 |
+
# Step 5: Gene Annotation
|
| 149 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 150 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 151 |
+
|
| 152 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 153 |
+
print("Gene annotation preview:")
|
| 154 |
+
print(preview_df(gene_annotation))
|
| 155 |
+
|
| 156 |
+
# Step 6: Gene Identifier Mapping
|
| 157 |
+
# 1-2. Decide columns and get mapping dataframe
|
| 158 |
+
probe_col = 'ID' # Matches probe IDs in gene expression data (e.g., '1007_s_at')
|
| 159 |
+
gene_symbol_col = 'Gene Symbol' # Contains human gene symbols
|
| 160 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 161 |
+
|
| 162 |
+
# 3. 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 |
+
import os
|
| 167 |
+
import pandas as pd
|
| 168 |
+
|
| 169 |
+
# 1. Normalize gene symbols and save normalized gene data
|
| 170 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 171 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 172 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 173 |
+
|
| 174 |
+
# 2-6. If clinical data with trait is unavailable, skip linking and final validation; record metadata accordingly.
|
| 175 |
+
if 'selected_clinical_data' in globals() and selected_clinical_data is not None:
|
| 176 |
+
# Proceed only if trait data exists (i.e., selected_clinical_data was created in Step 2)
|
| 177 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
| 178 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 179 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 180 |
+
|
| 181 |
+
is_usable = validate_and_save_cohort_info(
|
| 182 |
+
is_final=True,
|
| 183 |
+
cohort=cohort,
|
| 184 |
+
info_path=json_path,
|
| 185 |
+
is_gene_available=True,
|
| 186 |
+
is_trait_available=True,
|
| 187 |
+
is_biased=is_trait_biased,
|
| 188 |
+
df=unbiased_linked_data,
|
| 189 |
+
note="INFO: Gene data normalized and linked with available clinical features."
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
if is_usable:
|
| 193 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 194 |
+
unbiased_linked_data.to_csv(out_data_file)
|
| 195 |
+
else:
|
| 196 |
+
# Trait unavailable in this cohort; log and do not attempt linking or saving linked data
|
| 197 |
+
_ = validate_and_save_cohort_info(
|
| 198 |
+
is_final=False,
|
| 199 |
+
cohort=cohort,
|
| 200 |
+
info_path=json_path,
|
| 201 |
+
is_gene_available=True,
|
| 202 |
+
is_trait_available=False
|
| 203 |
+
)
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/GSE84046.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
cohort = "GSE84046"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE84046"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE84046.csv"
|
| 14 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE84046.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE84046.csv"
|
| 16 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
# Determine data availability based on provided background and sample characteristics
|
| 40 |
+
is_gene_available = True # Whole-genome gene expression in adipose tissue (not miRNA/methylation)
|
| 41 |
+
trait_row = None # COPD status not provided; dataset is dietary intervention, not COPD-specific
|
| 42 |
+
age_row = None # Only date of birth provided; no sampling date to compute age reliably
|
| 43 |
+
gender_row = 4 # 'sexe: Male/Female' present
|
| 44 |
+
|
| 45 |
+
# Converters
|
| 46 |
+
def _extract_after_colon(x):
|
| 47 |
+
if x is None:
|
| 48 |
+
return None
|
| 49 |
+
if isinstance(x, str):
|
| 50 |
+
parts = x.split(":", 1)
|
| 51 |
+
return parts[1].strip() if len(parts) == 2 else x.strip()
|
| 52 |
+
return x
|
| 53 |
+
|
| 54 |
+
def convert_trait(x):
|
| 55 |
+
# Binary: 1 = COPD, 0 = control/non-COPD
|
| 56 |
+
val = _extract_after_colon(x)
|
| 57 |
+
if val is None:
|
| 58 |
+
return None
|
| 59 |
+
v = str(val).strip().lower()
|
| 60 |
+
# Heuristics for case/control labels
|
| 61 |
+
if "copd" in v:
|
| 62 |
+
# Exclude negations like "non-copd"
|
| 63 |
+
if "non-copd" in v or "no copd" in v:
|
| 64 |
+
return 0
|
| 65 |
+
return 1
|
| 66 |
+
if any(k in v for k in ["control", "healthy", "non-copd", "normal", "no copd"]):
|
| 67 |
+
return 0
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
def convert_age(x):
|
| 71 |
+
# Continuous. Try numeric; if date-of-birth or non-numeric, return None.
|
| 72 |
+
val = _extract_after_colon(x)
|
| 73 |
+
if val is None:
|
| 74 |
+
return None
|
| 75 |
+
s = str(val).strip()
|
| 76 |
+
# If looks like a date (e.g., dd-mm-yyyy), we don't have sampling date; return None.
|
| 77 |
+
if "-" in s and any(ch.isdigit() for ch in s):
|
| 78 |
+
return None
|
| 79 |
+
try:
|
| 80 |
+
return float(s)
|
| 81 |
+
except Exception:
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
def convert_gender(x):
|
| 85 |
+
# Binary: female -> 0, male -> 1
|
| 86 |
+
val = _extract_after_colon(x)
|
| 87 |
+
if val is None:
|
| 88 |
+
return None
|
| 89 |
+
v = str(val).strip().lower()
|
| 90 |
+
if v in ["female", "f", "woman", "women"]:
|
| 91 |
+
return 0
|
| 92 |
+
if v in ["male", "m", "man", "men"]:
|
| 93 |
+
return 1
|
| 94 |
+
return None
|
| 95 |
+
|
| 96 |
+
# Initial filtering and save metadata
|
| 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 |
+
# Clinical feature extraction: skip because trait is not available
|
| 107 |
+
# If trait_row becomes available in future updates, uncomment and use the following:
|
| 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 |
+
# os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 120 |
+
# selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/code/TCGA.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Chronic_obstructive_pulmonary_disease_(COPD)"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z2/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/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 appropriate TCGA cohort directory for COPD
|
| 22 |
+
all_dirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 23 |
+
dirs_lower = {d: d.lower() for d in all_dirs}
|
| 24 |
+
|
| 25 |
+
# Define strict COPD-related terms
|
| 26 |
+
copd_terms = [
|
| 27 |
+
"copd",
|
| 28 |
+
"chronic_obstructive_pulmonary_disease",
|
| 29 |
+
"chronic-obstructive-pulmonary-disease",
|
| 30 |
+
"chronic obstructive pulmonary disease"
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
# Exclude clear cancer-specific cohorts even if they mention "lung"
|
| 34 |
+
exclude_terms = [
|
| 35 |
+
"cancer", "carcinoma", "adenocarcinoma", "squamous", "glioma", "sarcoma", "melanoma",
|
| 36 |
+
"leukemia", "lymphoma", "tumor", "neoplasm", "blastoma"
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
selected_dir = None
|
| 40 |
+
for d, dl in dirs_lower.items():
|
| 41 |
+
if any(term in dl for term in copd_terms):
|
| 42 |
+
if not any(ex in dl for ex in exclude_terms):
|
| 43 |
+
selected_dir = d
|
| 44 |
+
break
|
| 45 |
+
|
| 46 |
+
# If no suitable directory found, skip this trait and mark task as completed
|
| 47 |
+
if selected_dir is None:
|
| 48 |
+
# Record metadata that TCGA is not suitable for COPD
|
| 49 |
+
validate_and_save_cohort_info(
|
| 50 |
+
is_final=False,
|
| 51 |
+
cohort="TCGA",
|
| 52 |
+
info_path=json_path,
|
| 53 |
+
is_gene_available=False,
|
| 54 |
+
is_trait_available=False
|
| 55 |
+
)
|
| 56 |
+
else:
|
| 57 |
+
# Step 2: Identify clinical and genetic file paths
|
| 58 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 59 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
| 60 |
+
|
| 61 |
+
# Step 3: Load both files as DataFrames
|
| 62 |
+
clinical_kwargs = {"sep": "\t", "index_col": 0, "low_memory": False}
|
| 63 |
+
genetic_kwargs = {"sep": "\t", "index_col": 0, "low_memory": False}
|
| 64 |
+
if clinical_file_path.endswith(".gz"):
|
| 65 |
+
clinical_kwargs["compression"] = "gzip"
|
| 66 |
+
if genetic_file_path.endswith(".gz"):
|
| 67 |
+
genetic_kwargs["compression"] = "gzip"
|
| 68 |
+
|
| 69 |
+
clinical_df = pd.read_csv(clinical_file_path, **clinical_kwargs)
|
| 70 |
+
genetic_df = pd.read_csv(genetic_file_path, **genetic_kwargs)
|
| 71 |
+
|
| 72 |
+
# Step 4: Print the column names of the clinical data
|
| 73 |
+
print(list(clinical_df.columns))
|
output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/cohort_info.json
CHANGED
|
@@ -1,112 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"GSE84046": {
|
| 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 |
-
"GSE64599": {
|
| 13 |
-
"is_usable": false,
|
| 14 |
-
"is_gene_available": true,
|
| 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 |
-
"GSE64593": {
|
| 23 |
-
"is_usable": false,
|
| 24 |
-
"is_gene_available": true,
|
| 25 |
-
"is_trait_available": false,
|
| 26 |
-
"is_available": false,
|
| 27 |
-
"is_biased": null,
|
| 28 |
-
"has_age": null,
|
| 29 |
-
"has_gender": null,
|
| 30 |
-
"sample_size": null
|
| 31 |
-
},
|
| 32 |
-
"GSE32030": {
|
| 33 |
-
"is_usable": false,
|
| 34 |
-
"is_gene_available": true,
|
| 35 |
-
"is_trait_available": true,
|
| 36 |
-
"is_available": true,
|
| 37 |
-
"is_biased": true,
|
| 38 |
-
"has_age": false,
|
| 39 |
-
"has_gender": false,
|
| 40 |
-
"sample_size": 35
|
| 41 |
-
},
|
| 42 |
-
"GSE21359": {
|
| 43 |
-
"is_usable": true,
|
| 44 |
-
"is_gene_available": true,
|
| 45 |
-
"is_trait_available": true,
|
| 46 |
-
"is_available": true,
|
| 47 |
-
"is_biased": false,
|
| 48 |
-
"has_age": false,
|
| 49 |
-
"has_gender": false,
|
| 50 |
-
"sample_size": 135
|
| 51 |
-
},
|
| 52 |
-
"GSE212331": {
|
| 53 |
-
"is_usable": true,
|
| 54 |
-
"is_gene_available": true,
|
| 55 |
-
"is_trait_available": true,
|
| 56 |
-
"is_available": true,
|
| 57 |
-
"is_biased": false,
|
| 58 |
-
"has_age": false,
|
| 59 |
-
"has_gender": false,
|
| 60 |
-
"sample_size": 87
|
| 61 |
-
},
|
| 62 |
-
"GSE210272": {
|
| 63 |
-
"is_usable": false,
|
| 64 |
-
"is_gene_available": false,
|
| 65 |
-
"is_trait_available": false,
|
| 66 |
-
"is_available": false,
|
| 67 |
-
"is_biased": null,
|
| 68 |
-
"has_age": null,
|
| 69 |
-
"has_gender": null,
|
| 70 |
-
"sample_size": null
|
| 71 |
-
},
|
| 72 |
-
"GSE208662": {
|
| 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": false,
|
| 79 |
-
"has_gender": false,
|
| 80 |
-
"sample_size": 32
|
| 81 |
-
},
|
| 82 |
-
"GSE175616": {
|
| 83 |
-
"is_usable": false,
|
| 84 |
-
"is_gene_available": true,
|
| 85 |
-
"is_trait_available": false,
|
| 86 |
-
"is_available": false,
|
| 87 |
-
"is_biased": null,
|
| 88 |
-
"has_age": null,
|
| 89 |
-
"has_gender": null,
|
| 90 |
-
"sample_size": null
|
| 91 |
-
},
|
| 92 |
-
"GSE162635": {
|
| 93 |
-
"is_usable": false,
|
| 94 |
-
"is_gene_available": false,
|
| 95 |
-
"is_trait_available": false,
|
| 96 |
-
"is_available": false,
|
| 97 |
-
"is_biased": null,
|
| 98 |
-
"has_age": null,
|
| 99 |
-
"has_gender": null,
|
| 100 |
-
"sample_size": null
|
| 101 |
-
},
|
| 102 |
-
"TCGA": {
|
| 103 |
-
"is_usable": true,
|
| 104 |
-
"is_gene_available": true,
|
| 105 |
-
"is_trait_available": true,
|
| 106 |
-
"is_available": true,
|
| 107 |
-
"is_biased": false,
|
| 108 |
-
"has_age": true,
|
| 109 |
-
"has_gender": true,
|
| 110 |
-
"sample_size": 1129
|
| 111 |
-
}
|
| 112 |
-
}
|
|
|
|
| 1 |
+
{"GSE84046": {"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}, "GSE64599": {"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}, "GSE64593": {"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}, "GSE32030": {"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}, "GSE21359": {"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": 135, "note": "INFO: Affymetrix platform; probes mapped to gene symbols via GPL; COPD inferred from smoking status (COPD vs non-COPD)."}, "GSE212331": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": false, "sample_size": 87, "note": "INFO: Illumina probe-level data mapped to symbols; sputum samples from COPD vs healthy controls."}, "GSE210272": {"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}, "GSE208662": {"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": 32, "note": "INFO: Dataset includes multiple treatment arms (Printex/Zn/LPS/Sham). Only disease state (trait) is available as clinical covariate; age and gender not provided."}, "GSE175616": {"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 not available in sample characteristics; only gene data saved."}, "GSE162635": {"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": 205, "note": "INFO: Trait derived from GOLD stages (gold.1): healthy/0/O mapped to 0; stages I\u2013IV mapped to 1. No age or gender available."}, "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/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE210272.csv
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
Gene,GSM6427241,GSM6427242,GSM6427243,GSM6427244,GSM6427245,GSM6427246,GSM6427247,GSM6427248,GSM6427249,GSM6427250,GSM6427251,GSM6427252,GSM6427253,GSM6427254,GSM6427255,GSM6427256,GSM6427257,GSM6427258,GSM6427259,GSM6427260,GSM6427261,GSM6427262,GSM6427263,GSM6427264,GSM6427265,GSM6427266,GSM6427267,GSM6427268,GSM6427269,GSM6427270,GSM6427271,GSM6427272,GSM6427273,GSM6427274,GSM6427275,GSM6427276,GSM6427277,GSM6427278,GSM6427279,GSM6427280,GSM6427281,GSM6427282,GSM6427283,GSM6427284,GSM6427285,GSM6427286,GSM6427287,GSM6427288,GSM6427289,GSM6427290,GSM6427291,GSM6427292,GSM6427293,GSM6427294,GSM6427295,GSM6427296,GSM6427297,GSM6427298,GSM6427299,GSM6427300,GSM6427301,GSM6427302,GSM6427303,GSM6427304,GSM6427305,GSM6427306,GSM6427307,GSM6427308,GSM6427309,GSM6427310,GSM6427311,GSM6427312,GSM6427313,GSM6427314,GSM6427315,GSM6427316,GSM6427317,GSM6427318,GSM6427319,GSM6427320,GSM6427321,GSM6427322,GSM6427323,GSM6427324,GSM6427325,GSM6427326,GSM6427327,GSM6427328,GSM6427329,GSM6427330,GSM6427331,GSM6427332,GSM6427333,GSM6427334,GSM6427335,GSM6427336,GSM6427337,GSM6427338,GSM6427339,GSM6427340,GSM6427341,GSM6427342,GSM6427343,GSM6427344,GSM6427345,GSM6427346,GSM6427347,GSM6427348,GSM6427349,GSM6427350,GSM6427351,GSM6427352,GSM6427353,GSM6427354,GSM6427355,GSM6427356,GSM6427357,GSM6427358,GSM6427359,GSM6427360,GSM6427361,GSM6427362,GSM6427363,GSM6427364,GSM6427365,GSM6427366,GSM6427367,GSM6427368,GSM6427369,GSM6427370,GSM6427371,GSM6427372,GSM6427373,GSM6427374,GSM6427375,GSM6427376,GSM6427377,GSM6427378,GSM6427379,GSM6427380,GSM6427381,GSM6427382,GSM6427383,GSM6427384,GSM6427385,GSM6427386,GSM6427387,GSM6427388,GSM6427389,GSM6427390,GSM6427391,GSM6427392,GSM6427393,GSM6427394,GSM6427395,GSM6427396,GSM6427397,GSM6427398,GSM6427399,GSM6427400,GSM6427401,GSM6427402,GSM6427403,GSM6427404,GSM6427405,GSM6427406,GSM6427407,GSM6427408,GSM6427409,GSM6427410,GSM6427411,GSM6427412,GSM6427413,GSM6427414,GSM6427415,GSM6427416,GSM6427417,GSM6427418,GSM6427419,GSM6427420,GSM6427421,GSM6427422,GSM6427423,GSM6427424,GSM6427425,GSM6427426,GSM6427427,GSM6427428,GSM6427429,GSM6427430,GSM6427431,GSM6427432,GSM6427433,GSM6427434,GSM6427435,GSM6427436,GSM6427437,GSM6427438,GSM6427439,GSM6427440,GSM6427441,GSM6427442,GSM6427443,GSM6427444,GSM6427445,GSM6427446,GSM6427447,GSM6427448,GSM6427449,GSM6427450,GSM6427451,GSM6427452,GSM6427453,GSM6427454,GSM6427455,GSM6427456,GSM6427457,GSM6427458,GSM6427459,GSM6427460,GSM6427461,GSM6427462,GSM6427463,GSM6427464,GSM6427465,GSM6427466,GSM6427467,GSM6427468,GSM6427469,GSM6427470,GSM6427471,GSM6427472,GSM6427473,GSM6427474,GSM6427475,GSM6427476,GSM6427477,GSM6427478
|
output/preprocess/Fibromyalgia/code/GSE67311.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Fibromyalgia"
|
| 6 |
+
cohort = "GSE67311"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Fibromyalgia"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Fibromyalgia/GSE67311"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Fibromyalgia/GSE67311.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Fibromyalgia/gene_data/GSE67311.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Fibromyalgia/clinical_data/GSE67311.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Fibromyalgia/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import pandas as pd
|
| 41 |
+
|
| 42 |
+
# 1. Gene Expression Data Availability
|
| 43 |
+
is_gene_available = True # Affymetrix Human Gene 1.1 ST arrays indicate gene expression data.
|
| 44 |
+
|
| 45 |
+
# 2. Variable Availability and Data Type Conversion
|
| 46 |
+
|
| 47 |
+
# Rows determined from the provided Sample Characteristics Dictionary
|
| 48 |
+
trait_row = 0 # 'diagnosis: healthy control' / 'diagnosis: fibromyalgia'
|
| 49 |
+
age_row = None # Not available
|
| 50 |
+
gender_row = None # Not available
|
| 51 |
+
|
| 52 |
+
# Conversion functions
|
| 53 |
+
def _extract_value(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()
|
| 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 fibromyalgia cases to 1, controls to 0
|
| 67 |
+
if v_low in {'fibromyalgia', 'fm', 'patient', 'case'} or 'fibro' in v_low:
|
| 68 |
+
return 1
|
| 69 |
+
if v_low in {'healthy control', 'control', 'hc', 'healthy', 'normal'} or 'control' in v_low:
|
| 70 |
+
return 0
|
| 71 |
+
return None
|
| 72 |
+
|
| 73 |
+
def convert_age(x):
|
| 74 |
+
v = _extract_value(x)
|
| 75 |
+
if v is None or v == '':
|
| 76 |
+
return None
|
| 77 |
+
try:
|
| 78 |
+
return float(v)
|
| 79 |
+
except Exception:
|
| 80 |
+
return None
|
| 81 |
+
|
| 82 |
+
def convert_gender(x):
|
| 83 |
+
v = _extract_value(x)
|
| 84 |
+
if v is None:
|
| 85 |
+
return None
|
| 86 |
+
v_low = v.lower()
|
| 87 |
+
if v_low in {'female', 'f', 'woman', 'women', 'girl'}:
|
| 88 |
+
return 0
|
| 89 |
+
if v_low in {'male', 'm', 'man', 'men', 'boy'}:
|
| 90 |
+
return 1
|
| 91 |
+
if v_low in {'0', '1'}:
|
| 92 |
+
try:
|
| 93 |
+
return int(v_low)
|
| 94 |
+
except Exception:
|
| 95 |
+
return None
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
# 3. Save Metadata (initial filtering)
|
| 99 |
+
is_trait_available = trait_row is not None
|
| 100 |
+
_ = validate_and_save_cohort_info(
|
| 101 |
+
is_final=False,
|
| 102 |
+
cohort=cohort,
|
| 103 |
+
info_path=json_path,
|
| 104 |
+
is_gene_available=is_gene_available,
|
| 105 |
+
is_trait_available=is_trait_available
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# 4. Clinical Feature Extraction (only if trait 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(preview)
|
| 122 |
+
|
| 123 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 124 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 125 |
+
|
| 126 |
+
# Step 3: Gene Data Extraction
|
| 127 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 128 |
+
gene_data = get_genetic_data(matrix_file)
|
| 129 |
+
|
| 130 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 131 |
+
print(gene_data.index[:20])
|
| 132 |
+
|
| 133 |
+
# Step 4: Gene Identifier Review
|
| 134 |
+
print("requires_gene_mapping = True")
|
| 135 |
+
|
| 136 |
+
# Step 5: Gene Annotation
|
| 137 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 138 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 139 |
+
|
| 140 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 141 |
+
print("Gene annotation preview:")
|
| 142 |
+
print(preview_df(gene_annotation))
|
| 143 |
+
|
| 144 |
+
# Step 6: Gene Identifier Mapping
|
| 145 |
+
# Decide the columns for probe IDs and gene symbols based on the annotation preview:
|
| 146 |
+
# - Probe IDs match the 'ID' column (e.g., 789xxxx).
|
| 147 |
+
# - Gene symbols can be parsed from the 'gene_assignment' column.
|
| 148 |
+
id_col = 'ID'
|
| 149 |
+
symbol_col = 'gene_assignment'
|
| 150 |
+
|
| 151 |
+
# Build mapping and apply it to convert probe-level data to gene-level expression
|
| 152 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=symbol_col)
|
| 153 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 154 |
+
|
| 155 |
+
# Step 7: Data Normalization and Linking
|
| 156 |
+
import os
|
| 157 |
+
import pandas as pd
|
| 158 |
+
|
| 159 |
+
# Ensure clinical data is available in memory; reload if needed
|
| 160 |
+
if 'selected_clinical_df' not in locals():
|
| 161 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 162 |
+
|
| 163 |
+
# 1. Normalize gene symbols and save
|
| 164 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 165 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 166 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 167 |
+
|
| 168 |
+
# 2. Link clinical and genetic data
|
| 169 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 170 |
+
|
| 171 |
+
# 3. Handle missing values
|
| 172 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 173 |
+
|
| 174 |
+
# 4. Check bias and remove biased demographics
|
| 175 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 176 |
+
|
| 177 |
+
# 5. Final validation and save cohort info
|
| 178 |
+
note = "INFO: Platform=Affymetrix Human Gene 1.1 ST; Age/Gender unavailable; Trait derived from 'diagnosis'."
|
| 179 |
+
is_usable = validate_and_save_cohort_info(
|
| 180 |
+
is_final=True,
|
| 181 |
+
cohort=cohort,
|
| 182 |
+
info_path=json_path,
|
| 183 |
+
is_gene_available=True,
|
| 184 |
+
is_trait_available=True,
|
| 185 |
+
is_biased=is_trait_biased,
|
| 186 |
+
df=unbiased_linked_data,
|
| 187 |
+
note=note
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
# 6. Save linked data if usable
|
| 191 |
+
if is_usable:
|
| 192 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 193 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Fibromyalgia/code/TCGA.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Fibromyalgia"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z3/preprocess/Fibromyalgia/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z3/preprocess/Fibromyalgia/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z3/preprocess/Fibromyalgia/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z3/preprocess/Fibromyalgia/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 Fibromyalgia (likely none)
|
| 22 |
+
synonym_terms = [
|
| 23 |
+
'fibromyalgia',
|
| 24 |
+
'myalgia',
|
| 25 |
+
'chronic pain',
|
| 26 |
+
'central sensitization',
|
| 27 |
+
'musculoskeletal pain'
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
# List available subdirectories
|
| 31 |
+
all_subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 32 |
+
|
| 33 |
+
# Find matches
|
| 34 |
+
matches = []
|
| 35 |
+
for d in all_subdirs:
|
| 36 |
+
name_l = d.lower()
|
| 37 |
+
score = sum(term in name_l for term in synonym_terms)
|
| 38 |
+
if score > 0:
|
| 39 |
+
matches.append((score, d))
|
| 40 |
+
|
| 41 |
+
if not matches:
|
| 42 |
+
# No suitable TCGA cohort for Fibromyalgia; record and skip
|
| 43 |
+
validate_and_save_cohort_info(
|
| 44 |
+
is_final=False,
|
| 45 |
+
cohort="TCGA",
|
| 46 |
+
info_path=json_path,
|
| 47 |
+
is_gene_available=False,
|
| 48 |
+
is_trait_available=False
|
| 49 |
+
)
|
| 50 |
+
else:
|
| 51 |
+
# Choose the most specific match (highest score, then longest matched directory name)
|
| 52 |
+
matches.sort(key=lambda x: (x[0], len(x[1])), reverse=True)
|
| 53 |
+
selected_dir = matches[0][1]
|
| 54 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 55 |
+
|
| 56 |
+
# Step 2: Identify clinical and genetic file paths
|
| 57 |
+
clinical_fp, genetic_fp = tcga_get_relevant_filepaths(cohort_dir)
|
| 58 |
+
|
| 59 |
+
# Step 3: Load both files
|
| 60 |
+
clinical_df = pd.read_csv(clinical_fp, sep='\t', index_col=0, low_memory=False)
|
| 61 |
+
genetic_df = pd.read_csv(genetic_fp, sep='\t', index_col=0, low_memory=False)
|
| 62 |
+
|
| 63 |
+
# Step 4: Print clinical column names
|
| 64 |
+
print(clinical_df.columns.tolist())
|
output/preprocess/Fibromyalgia/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": 142
|
| 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 |
+
{"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": 142, "note": "INFO: Platform=Affymetrix Human Gene 1.1 ST; Age/Gender unavailable; Trait derived from 'diagnosis'."}, "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/Hypertension/code/GSE149256.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
cohort = "GSE149256"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertension"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertension/GSE149256"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertension/GSE149256.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/GSE149256.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/GSE149256.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertension/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 # Microarray gene expression in PBMCs per background info
|
| 41 |
+
|
| 42 |
+
# Step 2: Identify variable availability from the sample characteristics dictionary
|
| 43 |
+
# Based on the provided dictionary:
|
| 44 |
+
# 0: gender, 1: ethnicity, 2: poverty status, 3: age, 4: tissue
|
| 45 |
+
trait_row = None # Hypertension is not available in this dataset
|
| 46 |
+
age_row = 3 # 'age: <value>'
|
| 47 |
+
gender_row = 0 # 'gender: Male/Female'
|
| 48 |
+
|
| 49 |
+
# Step 2.2: Define conversion functions
|
| 50 |
+
def _after_colon(value: str) -> str:
|
| 51 |
+
if value is None:
|
| 52 |
+
return None
|
| 53 |
+
s = str(value)
|
| 54 |
+
parts = s.split(":", 1)
|
| 55 |
+
v = parts[1] if len(parts) > 1 else parts[0]
|
| 56 |
+
v = v.strip()
|
| 57 |
+
return v if v != "" else None
|
| 58 |
+
|
| 59 |
+
def convert_trait(value):
|
| 60 |
+
# Robust parser for hypertension if it ever appears; returns None otherwise
|
| 61 |
+
v = _after_colon(value)
|
| 62 |
+
if v is None:
|
| 63 |
+
return None
|
| 64 |
+
vl = v.lower()
|
| 65 |
+
yes_set = {"yes", "y", "1", "true", "hypertensive", "htn", "case", "with hypertension", "hypertension"}
|
| 66 |
+
no_set = {"no", "n", "0", "false", "normotensive", "control", "without hypertension", "non-hypertension"}
|
| 67 |
+
if vl in yes_set:
|
| 68 |
+
return 1
|
| 69 |
+
if vl in no_set:
|
| 70 |
+
return 0
|
| 71 |
+
# Heuristics for common phrasing
|
| 72 |
+
if "hypertens" in vl and ("no" in vl or "without" in vl or "non" in vl):
|
| 73 |
+
return 0
|
| 74 |
+
if "hypertens" in vl:
|
| 75 |
+
return 1
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
def convert_age(value):
|
| 79 |
+
v = _after_colon(value)
|
| 80 |
+
if v is None:
|
| 81 |
+
return None
|
| 82 |
+
try:
|
| 83 |
+
# Some GEO ages can include units or extra text; extract leading numeric
|
| 84 |
+
return float(v)
|
| 85 |
+
except Exception:
|
| 86 |
+
# Try to parse numbers embedded in text
|
| 87 |
+
import re
|
| 88 |
+
m = re.search(r"[-+]?\d+(\.\d+)?", v)
|
| 89 |
+
return float(m.group()) if m else None
|
| 90 |
+
|
| 91 |
+
def convert_gender(value):
|
| 92 |
+
v = _after_colon(value)
|
| 93 |
+
if v is None:
|
| 94 |
+
return None
|
| 95 |
+
vl = v.lower()
|
| 96 |
+
if vl in {"male", "m"}:
|
| 97 |
+
return 1
|
| 98 |
+
if vl in {"female", "f"}:
|
| 99 |
+
return 0
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
# Step 3: Initial filtering and save metadata
|
| 103 |
+
is_trait_available = trait_row is not None
|
| 104 |
+
_ = validate_and_save_cohort_info(
|
| 105 |
+
is_final=False,
|
| 106 |
+
cohort=cohort,
|
| 107 |
+
info_path=json_path,
|
| 108 |
+
is_gene_available=is_gene_available,
|
| 109 |
+
is_trait_available=is_trait_available
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
# Step 4: Clinical feature extraction (skip if trait not available)
|
| 113 |
+
if trait_row is not None:
|
| 114 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 115 |
+
clinical_df=clinical_data,
|
| 116 |
+
trait=trait,
|
| 117 |
+
trait_row=trait_row,
|
| 118 |
+
convert_trait=convert_trait,
|
| 119 |
+
age_row=age_row,
|
| 120 |
+
convert_age=convert_age,
|
| 121 |
+
gender_row=gender_row,
|
| 122 |
+
convert_gender=convert_gender
|
| 123 |
+
)
|
| 124 |
+
preview = preview_df(selected_clinical_df, n=5)
|
| 125 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 126 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
output/preprocess/Hypertension/code/GSE151158.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
cohort = "GSE151158"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertension"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertension/GSE151158"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertension/GSE151158.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/GSE151158.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/GSE151158.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertension/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 |
+
# Based on series summary describing RNA from liver tissue with expression of 594 genes.
|
| 45 |
+
is_gene_available = True
|
| 46 |
+
|
| 47 |
+
# 2) Variable availability
|
| 48 |
+
trait_row = 7 # 'hypertension: N'/'Y'
|
| 49 |
+
age_row = 1 # 'age: ...'
|
| 50 |
+
gender_row = 2 # 'Sex: F'/'M'
|
| 51 |
+
|
| 52 |
+
# 2) Data type conversion functions
|
| 53 |
+
def _value_after_colon(x):
|
| 54 |
+
if x is None:
|
| 55 |
+
return None
|
| 56 |
+
s = str(x)
|
| 57 |
+
parts = s.split(":", 1)
|
| 58 |
+
v = parts[1] if len(parts) == 2 else parts[0]
|
| 59 |
+
return v.strip()
|
| 60 |
+
|
| 61 |
+
def convert_trait(x):
|
| 62 |
+
v = _value_after_colon(x)
|
| 63 |
+
if v is None or v == "":
|
| 64 |
+
return None
|
| 65 |
+
v_low = v.strip().lower()
|
| 66 |
+
# Map common binary representations
|
| 67 |
+
if v_low in {"y", "yes", "1", "true", "positive", "pos"}:
|
| 68 |
+
return 1
|
| 69 |
+
if v_low in {"n", "no", "0", "false", "negative", "neg"}:
|
| 70 |
+
return 0
|
| 71 |
+
# Heuristic: if it contains 'y' alone or startswith 't', consider as yes; 'n' or startswith 'f' as no
|
| 72 |
+
if v_low.startswith("y"):
|
| 73 |
+
return 1
|
| 74 |
+
if v_low.startswith("n"):
|
| 75 |
+
return 0
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
def convert_age(x):
|
| 79 |
+
v = _value_after_colon(x)
|
| 80 |
+
if v is None or v == "":
|
| 81 |
+
return None
|
| 82 |
+
# Extract first numeric token (integer or float)
|
| 83 |
+
m = re.search(r"[-+]?\d*\.?\d+", v)
|
| 84 |
+
if not m:
|
| 85 |
+
return None
|
| 86 |
+
try:
|
| 87 |
+
val = float(m.group(0))
|
| 88 |
+
# Age cannot be non-sensical; filter out extreme negatives
|
| 89 |
+
if val < 0:
|
| 90 |
+
return None
|
| 91 |
+
return val
|
| 92 |
+
except:
|
| 93 |
+
return None
|
| 94 |
+
|
| 95 |
+
def convert_gender(x):
|
| 96 |
+
v = _value_after_colon(x)
|
| 97 |
+
if v is None or v == "":
|
| 98 |
+
return None
|
| 99 |
+
v_low = v.strip().lower()
|
| 100 |
+
# Female -> 0, Male -> 1
|
| 101 |
+
if v_low in {"female", "f", "woman", "women", "girl"}:
|
| 102 |
+
return 0
|
| 103 |
+
if v_low in {"male", "m", "man", "men", "boy"}:
|
| 104 |
+
return 1
|
| 105 |
+
return None
|
| 106 |
+
|
| 107 |
+
# 3) Save metadata (initial filtering)
|
| 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 (only if trait data is 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 |
+
# Preview and save
|
| 130 |
+
preview = preview_df(selected_clinical_df)
|
| 131 |
+
print(preview)
|
| 132 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 133 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 134 |
+
|
| 135 |
+
# Step 3: Gene Data Extraction
|
| 136 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 137 |
+
gene_data = get_genetic_data(matrix_file)
|
| 138 |
+
|
| 139 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 140 |
+
print(gene_data.index[:20])
|
| 141 |
+
|
| 142 |
+
# Step 4: Gene Identifier Review
|
| 143 |
+
print("requires_gene_mapping = False")
|
| 144 |
+
|
| 145 |
+
# Step 5: Data Normalization and Linking
|
| 146 |
+
import os
|
| 147 |
+
|
| 148 |
+
# 1. Normalize the obtained gene data and save
|
| 149 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 150 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 151 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 152 |
+
|
| 153 |
+
# 2. Link the clinical and genetic data
|
| 154 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 155 |
+
|
| 156 |
+
# Track pre-QC stats
|
| 157 |
+
covariate_cols = [trait, 'Age', 'Gender']
|
| 158 |
+
pre_gene_cols = [c for c in linked_data.columns if c not in covariate_cols]
|
| 159 |
+
pre_samples = len(linked_data)
|
| 160 |
+
pre_genes = len(pre_gene_cols)
|
| 161 |
+
|
| 162 |
+
# 3. Handle missing values in the linked data
|
| 163 |
+
linked_data_qc = handle_missing_values(linked_data, trait)
|
| 164 |
+
|
| 165 |
+
# Post-QC stats
|
| 166 |
+
post_gene_cols = [c for c in linked_data_qc.columns if c not in covariate_cols]
|
| 167 |
+
post_samples = len(linked_data_qc)
|
| 168 |
+
post_genes = len(post_gene_cols)
|
| 169 |
+
|
| 170 |
+
# 4. Determine whether the trait and demographic features are severely biased, and remove biased features.
|
| 171 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data_qc, trait)
|
| 172 |
+
|
| 173 |
+
# 5. Conduct quality check and save the cohort information.
|
| 174 |
+
note = (
|
| 175 |
+
f"INFO: Linked {pre_samples} samples and {pre_genes} genes; "
|
| 176 |
+
f"after QC retained {post_samples} samples and {post_genes} genes. "
|
| 177 |
+
f"Age present after QC: {'Age' in linked_data_qc.columns}. "
|
| 178 |
+
f"Gender present after QC: {'Gender' in linked_data_qc.columns}."
|
| 179 |
+
)
|
| 180 |
+
is_usable = validate_and_save_cohort_info(
|
| 181 |
+
True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data, note
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
# 6. If the linked data is usable, save it
|
| 185 |
+
if is_usable:
|
| 186 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 187 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Hypertension/code/GSE161533.py
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
cohort = "GSE161533"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertension"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertension/GSE161533"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertension/GSE161533.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/GSE161533.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/GSE161533.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertension/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 Genome U133 Plus 2.0 Array indicates mRNA expression microarray
|
| 44 |
+
|
| 45 |
+
# 2. Variable Availability and Data Type Conversion
|
| 46 |
+
|
| 47 |
+
# Identified keys from Sample Characteristics Dictionary
|
| 48 |
+
trait_row = 6 # disease history, includes 'Hypertension' among other diseases
|
| 49 |
+
age_row = 2 # 'age: <number>'
|
| 50 |
+
gender_row = 3 # 'gender: Male/Female'
|
| 51 |
+
|
| 52 |
+
def _after_colon(value):
|
| 53 |
+
if value is None:
|
| 54 |
+
return None
|
| 55 |
+
if not isinstance(value, str):
|
| 56 |
+
value = str(value)
|
| 57 |
+
parts = value.split(":", 1)
|
| 58 |
+
v = parts[1] if len(parts) > 1 else parts[0]
|
| 59 |
+
return v.strip()
|
| 60 |
+
|
| 61 |
+
def convert_trait(value):
|
| 62 |
+
v = _after_colon(value)
|
| 63 |
+
if v is None or v == "":
|
| 64 |
+
return None
|
| 65 |
+
v_low = v.lower()
|
| 66 |
+
# Handle unknowns
|
| 67 |
+
if v_low in {"na", "n/a", "unknown", "undef", "missing"}:
|
| 68 |
+
return None
|
| 69 |
+
# Binary: 1 if hypertension is present, else 0
|
| 70 |
+
return 1 if "hypertension" in v_low else 0
|
| 71 |
+
|
| 72 |
+
def convert_age(value):
|
| 73 |
+
v = _after_colon(value)
|
| 74 |
+
if v is None or v == "":
|
| 75 |
+
return None
|
| 76 |
+
v = v.strip()
|
| 77 |
+
# Extract first integer or float in the string
|
| 78 |
+
m = re.search(r"[-+]?\d+\.?\d*", v)
|
| 79 |
+
if not m:
|
| 80 |
+
return None
|
| 81 |
+
try:
|
| 82 |
+
num = float(m.group())
|
| 83 |
+
# Age should be within a reasonable human range
|
| 84 |
+
if num <= 0 or num > 120:
|
| 85 |
+
return None
|
| 86 |
+
return num
|
| 87 |
+
except Exception:
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
def convert_gender(value):
|
| 91 |
+
v = _after_colon(value)
|
| 92 |
+
if v is None or v == "":
|
| 93 |
+
return None
|
| 94 |
+
v_low = v.lower()
|
| 95 |
+
if v_low.startswith("male"):
|
| 96 |
+
return 1
|
| 97 |
+
if v_low.startswith("female"):
|
| 98 |
+
return 0
|
| 99 |
+
return None
|
| 100 |
+
|
| 101 |
+
# 3. Save Metadata (initial filtering)
|
| 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 |
+
# 4. Clinical Feature Extraction (only if clinical data is available)
|
| 112 |
+
if trait_row is not None:
|
| 113 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 114 |
+
clinical_df=clinical_data,
|
| 115 |
+
trait=trait,
|
| 116 |
+
trait_row=trait_row,
|
| 117 |
+
convert_trait=convert_trait,
|
| 118 |
+
age_row=age_row,
|
| 119 |
+
convert_age=convert_age,
|
| 120 |
+
gender_row=gender_row,
|
| 121 |
+
convert_gender=convert_gender
|
| 122 |
+
)
|
| 123 |
+
_ = preview_df(selected_clinical_df, n=5)
|
| 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 |
+
# Affymetrix probe set IDs (e.g., '1007_s_at') are not human gene symbols and need mapping.
|
| 136 |
+
requires_gene_mapping = True
|
| 137 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 138 |
+
|
| 139 |
+
# Step 5: Gene Annotation
|
| 140 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 141 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 142 |
+
|
| 143 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 144 |
+
print("Gene annotation preview:")
|
| 145 |
+
print(preview_df(gene_annotation))
|
| 146 |
+
|
| 147 |
+
# Step 6: Gene Identifier Mapping
|
| 148 |
+
# Decide columns for mapping: probe IDs and gene symbols
|
| 149 |
+
probe_id_col = 'ID'
|
| 150 |
+
gene_symbol_col = 'Gene Symbol'
|
| 151 |
+
|
| 152 |
+
# 2. Build mapping dataframe from annotation
|
| 153 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_id_col, gene_col=gene_symbol_col)
|
| 154 |
+
|
| 155 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 156 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 157 |
+
|
| 158 |
+
# Step 7: Data Normalization and Linking
|
| 159 |
+
import os
|
| 160 |
+
import pandas as pd
|
| 161 |
+
|
| 162 |
+
# 1. Normalize gene symbols and save
|
| 163 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 164 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 165 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 166 |
+
|
| 167 |
+
# 2. Ensure clinical data is loaded, then link clinical and genetic data
|
| 168 |
+
if 'selected_clinical_df' not in globals():
|
| 169 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 170 |
+
|
| 171 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 172 |
+
|
| 173 |
+
# Determine availability flags from actual data
|
| 174 |
+
is_gene_available = (normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0)
|
| 175 |
+
is_trait_available = trait in linked_data.columns
|
| 176 |
+
|
| 177 |
+
# 3. Handle missing values
|
| 178 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 179 |
+
|
| 180 |
+
# 4. Bias check and removal of biased demographic features
|
| 181 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 182 |
+
|
| 183 |
+
# 5. Final validation and metadata save
|
| 184 |
+
note = "INFO: Affymetrix U133 Plus 2.0 microarray; trait derived from 'disease history' indicating Hypertension presence."
|
| 185 |
+
is_usable = validate_and_save_cohort_info(
|
| 186 |
+
is_final=True,
|
| 187 |
+
cohort=cohort,
|
| 188 |
+
info_path=json_path,
|
| 189 |
+
is_gene_available=is_gene_available,
|
| 190 |
+
is_trait_available=is_trait_available,
|
| 191 |
+
is_biased=is_trait_biased,
|
| 192 |
+
df=unbiased_linked_data,
|
| 193 |
+
note=note
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
# 6. Save final linked data only if usable
|
| 197 |
+
if is_usable:
|
| 198 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 199 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Hypertension/code/GSE181339.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
cohort = "GSE181339"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertension"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertension/GSE181339"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertension/GSE181339.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/GSE181339.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/GSE181339.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertension/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 json
|
| 41 |
+
import os
|
| 42 |
+
|
| 43 |
+
# 1. Gene Expression Data Availability
|
| 44 |
+
is_gene_available = True # PBMC microarray gene expression per background info
|
| 45 |
+
|
| 46 |
+
# 2. Variable Availability and Data Type Conversion
|
| 47 |
+
|
| 48 |
+
# Keys inferred from the sample characteristics dictionary
|
| 49 |
+
trait_row = None # Hypertension not explicitly available and cannot be reliably inferred
|
| 50 |
+
age_row = None # The 'age' field (key 2) shows implausible small integers (e.g., 1–15), conflicting with 18–45 study range
|
| 51 |
+
gender_row = 0 # 'gender: Man/Woman' present
|
| 52 |
+
|
| 53 |
+
def _after_colon(value):
|
| 54 |
+
if value is None:
|
| 55 |
+
return None
|
| 56 |
+
if isinstance(value, str):
|
| 57 |
+
parts = value.split(":", 1)
|
| 58 |
+
v = parts[1] if len(parts) > 1 else parts[0]
|
| 59 |
+
return v.strip()
|
| 60 |
+
return value
|
| 61 |
+
|
| 62 |
+
def convert_trait(x):
|
| 63 |
+
"""
|
| 64 |
+
Convert hypertension-like information to binary if explicitly available.
|
| 65 |
+
Returns:
|
| 66 |
+
1 for hypertensive/yes; 0 for normotensive/no; None if unknown/irrelevant.
|
| 67 |
+
"""
|
| 68 |
+
v = _after_colon(x)
|
| 69 |
+
if v is None:
|
| 70 |
+
return None
|
| 71 |
+
s = str(v).strip().lower()
|
| 72 |
+
pos = {"yes", "y", "true", "1", "hypertension", "htn", "hypertensive", "high blood pressure", "hypertensive patient"}
|
| 73 |
+
neg = {"no", "n", "false", "0", "normotensive", "none", "normal", "without hypertension", "no hypertension"}
|
| 74 |
+
if s in pos:
|
| 75 |
+
return 1
|
| 76 |
+
if s in neg:
|
| 77 |
+
return 0
|
| 78 |
+
if any(k in s for k in ["hypertension", "hypertens"]):
|
| 79 |
+
if any(k in s for k in ["no ", "not ", "without", "non-"]):
|
| 80 |
+
return 0
|
| 81 |
+
return 1
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
def convert_age(x):
|
| 85 |
+
"""
|
| 86 |
+
Convert age to a continuous numeric value (years). Unknown -> None.
|
| 87 |
+
"""
|
| 88 |
+
v = _after_colon(x)
|
| 89 |
+
if v is None:
|
| 90 |
+
return None
|
| 91 |
+
s = str(v).strip().lower()
|
| 92 |
+
m = re.search(r"[-+]?\d*\.?\d+", s)
|
| 93 |
+
if not m:
|
| 94 |
+
return None
|
| 95 |
+
try:
|
| 96 |
+
age = float(m.group())
|
| 97 |
+
except Exception:
|
| 98 |
+
return None
|
| 99 |
+
if 0 <= age <= 120:
|
| 100 |
+
return age
|
| 101 |
+
return None
|
| 102 |
+
|
| 103 |
+
def convert_gender(x):
|
| 104 |
+
"""
|
| 105 |
+
Convert gender to binary: female=0, male=1. Unknown -> None.
|
| 106 |
+
"""
|
| 107 |
+
v = _after_colon(x)
|
| 108 |
+
if v is None:
|
| 109 |
+
return None
|
| 110 |
+
s = str(v).strip().lower()
|
| 111 |
+
if s in {"female", "woman", "women", "girl", "f"}:
|
| 112 |
+
return 0
|
| 113 |
+
if s in {"male", "man", "men", "boy", "m"}:
|
| 114 |
+
return 1
|
| 115 |
+
return None
|
| 116 |
+
|
| 117 |
+
# 3. Save Metadata (initial filtering)
|
| 118 |
+
is_trait_available = trait_row is not None
|
| 119 |
+
_ = validate_and_save_cohort_info(
|
| 120 |
+
is_final=False,
|
| 121 |
+
cohort=cohort,
|
| 122 |
+
info_path=json_path,
|
| 123 |
+
is_gene_available=is_gene_available,
|
| 124 |
+
is_trait_available=is_trait_available
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
# 4. Clinical Feature Extraction (skip because trait_row is None)
|
| 128 |
+
if trait_row is not None:
|
| 129 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 130 |
+
clinical_df=clinical_data,
|
| 131 |
+
trait=trait,
|
| 132 |
+
trait_row=trait_row,
|
| 133 |
+
convert_trait=convert_trait,
|
| 134 |
+
age_row=age_row,
|
| 135 |
+
convert_age=convert_age,
|
| 136 |
+
gender_row=gender_row,
|
| 137 |
+
convert_gender=convert_gender
|
| 138 |
+
)
|
| 139 |
+
preview = preview_df(selected_clinical_df)
|
| 140 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 141 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
output/preprocess/Hypertension/code/GSE256539.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
cohort = "GSE256539"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertension"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertension/GSE256539"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertension/GSE256539.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/GSE256539.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/GSE256539.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertension/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 (GeoMx DSP whole transcriptome => gene expression)
|
| 43 |
+
is_gene_available = True
|
| 44 |
+
|
| 45 |
+
# 2) Variable availability based on provided Sample Characteristics Dictionary
|
| 46 |
+
# Only 'individuial' (subject ID) and 'batch' are present; no trait/age/gender fields with variable information.
|
| 47 |
+
trait_row = None
|
| 48 |
+
age_row = None
|
| 49 |
+
gender_row = None
|
| 50 |
+
|
| 51 |
+
# 2.2) Define converters (robust, though they won't be used since rows are None)
|
| 52 |
+
def _extract_value_after_colon(x):
|
| 53 |
+
if x is None:
|
| 54 |
+
return None
|
| 55 |
+
if isinstance(x, (int, float)):
|
| 56 |
+
return x
|
| 57 |
+
s = str(x)
|
| 58 |
+
parts = s.split(":", 1)
|
| 59 |
+
return parts[1].strip() if len(parts) == 2 else s.strip()
|
| 60 |
+
|
| 61 |
+
def convert_trait(x):
|
| 62 |
+
v = _extract_value_after_colon(x)
|
| 63 |
+
if v is None:
|
| 64 |
+
return None
|
| 65 |
+
s = str(v).strip().lower()
|
| 66 |
+
# Map pulmonary arterial hypertension as "Hypertension" present; controls as absent
|
| 67 |
+
positive = {"ipah", "pah", "pulmonary arterial hypertension", "hypertension", "htn"}
|
| 68 |
+
negative = {"control", "normal", "healthy", "donor", "non-hypertensive", "no"}
|
| 69 |
+
if any(p in s for p in positive):
|
| 70 |
+
return 1
|
| 71 |
+
if any(n in s for n in negative):
|
| 72 |
+
return 0
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
def convert_age(x):
|
| 76 |
+
v = _extract_value_after_colon(x)
|
| 77 |
+
if v is None:
|
| 78 |
+
return None
|
| 79 |
+
s = str(v).lower()
|
| 80 |
+
nums = re.findall(r"[\d\.]+", s)
|
| 81 |
+
if not nums:
|
| 82 |
+
return None
|
| 83 |
+
try:
|
| 84 |
+
return float(nums[0])
|
| 85 |
+
except Exception:
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
+
def convert_gender(x):
|
| 89 |
+
v = _extract_value_after_colon(x)
|
| 90 |
+
if v is None:
|
| 91 |
+
return None
|
| 92 |
+
s = str(v).strip().lower()
|
| 93 |
+
# female -> 0, male -> 1
|
| 94 |
+
if s in {"female", "f", "woman", "women"}:
|
| 95 |
+
return 0
|
| 96 |
+
if s in {"male", "m", "man", "men"}:
|
| 97 |
+
return 1
|
| 98 |
+
return None
|
| 99 |
+
|
| 100 |
+
# 3) Initial filtering and save metadata
|
| 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 |
+
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)
|
| 125 |
+
print(preview)
|
output/preprocess/Hypertension/code/GSE71994.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
cohort = "GSE71994"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertension"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertension/GSE71994"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertension/GSE71994.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/GSE71994.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/GSE71994.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertension/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 math
|
| 41 |
+
|
| 42 |
+
# 1. Gene Expression Data Availability
|
| 43 |
+
is_gene_available = True # PBMC genome-wide gene expression analysis per background info
|
| 44 |
+
|
| 45 |
+
# 2. Variable Availability and Data Type Conversion
|
| 46 |
+
|
| 47 |
+
# Keys from Sample Characteristics Dictionary:
|
| 48 |
+
# trait candidate (infer uncontrolled hypertension from systolic BP "in a sample")
|
| 49 |
+
trait_row = 6 # 'sistolic blood pressure in a sample'
|
| 50 |
+
age_row = 3 # 'age'
|
| 51 |
+
gender_row = 1 # 'gender'
|
| 52 |
+
|
| 53 |
+
# 2.2 Converters
|
| 54 |
+
def _after_colon(value: str) -> str:
|
| 55 |
+
if value is None:
|
| 56 |
+
return ""
|
| 57 |
+
if isinstance(value, str):
|
| 58 |
+
parts = value.split(":", 1)
|
| 59 |
+
return parts[1].strip() if len(parts) > 1 else value.strip()
|
| 60 |
+
return str(value).strip()
|
| 61 |
+
|
| 62 |
+
def convert_trait(value):
|
| 63 |
+
# Map systolic BP to uncontrolled hypertension (1) if systolic >= 140, else controlled (0)
|
| 64 |
+
try:
|
| 65 |
+
v = _after_colon(value)
|
| 66 |
+
if v == "" or v.lower() in {"na", "n/a", "nan", "none", "missing", "unknown"}:
|
| 67 |
+
return None
|
| 68 |
+
sbp = float(v)
|
| 69 |
+
# Basic sanity check
|
| 70 |
+
if sbp <= 0 or sbp > 300:
|
| 71 |
+
return None
|
| 72 |
+
return 1 if sbp >= 140 else 0
|
| 73 |
+
except Exception:
|
| 74 |
+
return None
|
| 75 |
+
|
| 76 |
+
def convert_age(value):
|
| 77 |
+
try:
|
| 78 |
+
v = _after_colon(value)
|
| 79 |
+
if v == "" or v.lower() in {"na", "n/a", "nan", "none", "missing", "unknown"}:
|
| 80 |
+
return None
|
| 81 |
+
age = float(v)
|
| 82 |
+
if not (0 < age < 120):
|
| 83 |
+
return None
|
| 84 |
+
return age
|
| 85 |
+
except Exception:
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
+
def convert_gender(value):
|
| 89 |
+
v = _after_colon(value).strip().lower()
|
| 90 |
+
if v in {"female", "f", "woman", "women"}:
|
| 91 |
+
return 0
|
| 92 |
+
if v in {"male", "m", "man", "men"}:
|
| 93 |
+
return 1
|
| 94 |
+
return None
|
| 95 |
+
|
| 96 |
+
# 3. Save Metadata (initial filtering)
|
| 97 |
+
is_trait_available = trait_row is not None
|
| 98 |
+
_ = validate_and_save_cohort_info(
|
| 99 |
+
is_final=False,
|
| 100 |
+
cohort=cohort,
|
| 101 |
+
info_path=json_path,
|
| 102 |
+
is_gene_available=is_gene_available,
|
| 103 |
+
is_trait_available=is_trait_available
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# 4. Clinical Feature Extraction (only if trait data available)
|
| 107 |
+
if is_trait_available:
|
| 108 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 109 |
+
clinical_df=clinical_data,
|
| 110 |
+
trait=trait,
|
| 111 |
+
trait_row=trait_row,
|
| 112 |
+
convert_trait=convert_trait,
|
| 113 |
+
age_row=age_row,
|
| 114 |
+
convert_age=convert_age,
|
| 115 |
+
gender_row=gender_row,
|
| 116 |
+
convert_gender=convert_gender
|
| 117 |
+
)
|
| 118 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 119 |
+
|
| 120 |
+
# Save clinical data
|
| 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 |
+
# Based on the provided index values (e.g., '7896746', '7896756'), these are platform probe IDs, not human gene symbols.
|
| 133 |
+
requires_gene_mapping = True
|
| 134 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 135 |
+
|
| 136 |
+
# Step 5: Gene Annotation
|
| 137 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 138 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 139 |
+
|
| 140 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 141 |
+
print("Gene annotation preview:")
|
| 142 |
+
print(preview_df(gene_annotation))
|
| 143 |
+
|
| 144 |
+
# Step 6: Gene Identifier Mapping
|
| 145 |
+
# 1-2. Decide identifier and gene symbol columns and build mapping dataframe
|
| 146 |
+
# Expression data uses probe IDs matching the 'ID' column in annotation.
|
| 147 |
+
# Gene symbols are embedded in the 'gene_assignment' column.
|
| 148 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='gene_assignment')
|
| 149 |
+
|
| 150 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 151 |
+
# Preserve the original probe-level data if needed
|
| 152 |
+
probe_data = gene_data
|
| 153 |
+
gene_data = apply_gene_mapping(expression_df=probe_data, mapping_df=mapping_df)
|
| 154 |
+
|
| 155 |
+
# Step 7: Data Normalization and Linking
|
| 156 |
+
import os
|
| 157 |
+
import pandas as pd
|
| 158 |
+
|
| 159 |
+
# 1. Normalize gene symbols and save
|
| 160 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 161 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 162 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 163 |
+
|
| 164 |
+
# 2. Link the clinical and genetic data
|
| 165 |
+
try:
|
| 166 |
+
clinical_df_use = selected_clinical_df
|
| 167 |
+
except NameError:
|
| 168 |
+
clinical_df_use = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 169 |
+
|
| 170 |
+
linked_data = geo_link_clinical_genetic_data(clinical_df_use, normalized_gene_data)
|
| 171 |
+
|
| 172 |
+
# 3. Handle missing values in the linked data
|
| 173 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 174 |
+
|
| 175 |
+
# 4. Determine bias and remove biased demographic features
|
| 176 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 177 |
+
|
| 178 |
+
# 5. Final quality validation and save cohort info
|
| 179 |
+
is_usable = validate_and_save_cohort_info(
|
| 180 |
+
is_final=True,
|
| 181 |
+
cohort=cohort,
|
| 182 |
+
info_path=json_path,
|
| 183 |
+
is_gene_available=True,
|
| 184 |
+
is_trait_available=True,
|
| 185 |
+
is_biased=is_trait_biased,
|
| 186 |
+
df=unbiased_linked_data
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
# 6. Save linked data if usable
|
| 190 |
+
if is_usable:
|
| 191 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 192 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Hypertension/code/GSE74144.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
cohort = "GSE74144"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertension"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertension/GSE74144"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertension/GSE74144.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/GSE74144.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/GSE74144.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertension/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 # Transcriptomic gene expression profiling indicated in series information
|
| 41 |
+
|
| 42 |
+
# Step 2: Variable Availability and Converters
|
| 43 |
+
# Based on Sample Characteristics Dictionary, 'subject status' is at key 0
|
| 44 |
+
trait_row = 0 # Maps to 'subject status'
|
| 45 |
+
age_row = None
|
| 46 |
+
gender_row = None
|
| 47 |
+
|
| 48 |
+
def convert_trait(x):
|
| 49 |
+
# Extract value after colon if present
|
| 50 |
+
if x is None:
|
| 51 |
+
return None
|
| 52 |
+
try:
|
| 53 |
+
val = x.split(":", 1)[1].strip().lower()
|
| 54 |
+
except Exception:
|
| 55 |
+
val = str(x).strip().lower()
|
| 56 |
+
if "hypertens" in val:
|
| 57 |
+
return 1
|
| 58 |
+
if "control" in val:
|
| 59 |
+
return 0
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
# Age and Gender are not available
|
| 63 |
+
convert_age = None
|
| 64 |
+
convert_gender = None
|
| 65 |
+
|
| 66 |
+
# Step 3: Initial filtering and save metadata
|
| 67 |
+
is_trait_available = trait_row is not None
|
| 68 |
+
_ = validate_and_save_cohort_info(
|
| 69 |
+
is_final=False,
|
| 70 |
+
cohort=cohort,
|
| 71 |
+
info_path=json_path,
|
| 72 |
+
is_gene_available=is_gene_available,
|
| 73 |
+
is_trait_available=is_trait_available
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# Step 4: Clinical Feature Extraction (only if trait_row is available)
|
| 77 |
+
if trait_row is not None:
|
| 78 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 79 |
+
clinical_df=clinical_data,
|
| 80 |
+
trait=trait,
|
| 81 |
+
trait_row=trait_row,
|
| 82 |
+
convert_trait=convert_trait,
|
| 83 |
+
age_row=age_row,
|
| 84 |
+
convert_age=convert_age,
|
| 85 |
+
gender_row=gender_row,
|
| 86 |
+
convert_gender=convert_gender
|
| 87 |
+
)
|
| 88 |
+
# Preview and save
|
| 89 |
+
preview = preview_df(selected_clinical_df)
|
| 90 |
+
print(preview)
|
| 91 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 92 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 93 |
+
|
| 94 |
+
# Step 3: Gene Data Extraction
|
| 95 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 96 |
+
gene_data = get_genetic_data(matrix_file)
|
| 97 |
+
|
| 98 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 99 |
+
print(gene_data.index[:20])
|
| 100 |
+
|
| 101 |
+
# Step 4: Gene Identifier Review
|
| 102 |
+
print("requires_gene_mapping = True")
|
| 103 |
+
|
| 104 |
+
# Step 5: Gene Annotation
|
| 105 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
| 106 |
+
gene_annotation = get_gene_annotation(soft_file)
|
| 107 |
+
|
| 108 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
| 109 |
+
print("Gene annotation preview:")
|
| 110 |
+
print(preview_df(gene_annotation))
|
| 111 |
+
|
| 112 |
+
# Step 6: Gene Identifier Mapping
|
| 113 |
+
# Determine the appropriate columns for probe IDs and gene symbols by checking overlaps and availability
|
| 114 |
+
# 1) Select the probe identifier column that best matches the expression data index
|
| 115 |
+
id_match_counts = {}
|
| 116 |
+
probe_index_set = set(gene_data.index.astype(str))
|
| 117 |
+
for col in gene_annotation.columns:
|
| 118 |
+
try:
|
| 119 |
+
col_series = gene_annotation[col].astype(str).str.strip()
|
| 120 |
+
id_match_counts[col] = col_series.isin(probe_index_set).sum()
|
| 121 |
+
except Exception:
|
| 122 |
+
continue
|
| 123 |
+
|
| 124 |
+
# Fallback to 'ID' if no matches found
|
| 125 |
+
probe_col = max(id_match_counts, key=id_match_counts.get) if id_match_counts else 'ID'
|
| 126 |
+
if id_match_counts and id_match_counts[probe_col] == 0 and 'ID' in gene_annotation.columns:
|
| 127 |
+
probe_col = 'ID'
|
| 128 |
+
|
| 129 |
+
# 2) Choose a gene symbol column, preferring canonical symbol fields
|
| 130 |
+
symbol_candidates = ['GENE_SYMBOL', 'GENE', 'SYMBOL', 'Gene Symbol', 'Symbol', 'GENE_NAME']
|
| 131 |
+
symbol_col = None
|
| 132 |
+
for cand in symbol_candidates:
|
| 133 |
+
if cand in gene_annotation.columns and gene_annotation[cand].notna().sum() > 0:
|
| 134 |
+
symbol_col = cand
|
| 135 |
+
break
|
| 136 |
+
# As a final fallback (unlikely to be ideal), use any non-empty textual column
|
| 137 |
+
if symbol_col is None:
|
| 138 |
+
non_empty_cols = [c for c in gene_annotation.columns if gene_annotation[c].notna().sum() > 0]
|
| 139 |
+
symbol_col = non_empty_cols[0] if non_empty_cols else 'GENE_SYMBOL'
|
| 140 |
+
|
| 141 |
+
# Build mapping dataframe and apply mapping to convert probe-level data to gene-level
|
| 142 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=symbol_col)
|
| 143 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 144 |
+
|
| 145 |
+
# Step 7: Data Normalization and Linking
|
| 146 |
+
# 1. Normalize gene symbols and save gene 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. Link clinical and genetic data
|
| 152 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 153 |
+
|
| 154 |
+
# 3. Handle missing values
|
| 155 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 156 |
+
|
| 157 |
+
# 4. Assess bias and drop biased demographics
|
| 158 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 159 |
+
|
| 160 |
+
# 5. Final validation and save cohort info
|
| 161 |
+
note = "INFO: Only trait is available; Age and Gender are not provided in this series."
|
| 162 |
+
is_usable = validate_and_save_cohort_info(
|
| 163 |
+
True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data, note=note
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
# 6. Save linked data if usable
|
| 167 |
+
if is_usable:
|
| 168 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 169 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Hypertension/code/GSE77627.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
cohort = "GSE77627"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertension"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertension/GSE77627"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertension/GSE77627.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/GSE77627.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/GSE77627.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertension/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
|
| 41 |
+
# 1) Determine gene expression availability
|
| 42 |
+
is_gene_available = True # Illumina Whole-Genome DASL HT BeadChip arrays indicate mRNA expression data
|
| 43 |
+
|
| 44 |
+
# 2) Variable availability and conversion functions
|
| 45 |
+
# From the provided Sample Characteristics Dictionary:
|
| 46 |
+
# {0: ['liver group: LC', 'liver group: INCPH', 'liver group: HNL'], 1: ['tissue: liver']}
|
| 47 |
+
trait_row = 0 # 'liver group' distinguishes INCPH cases from LC/HNL controls
|
| 48 |
+
age_row = None # Not available
|
| 49 |
+
gender_row = None # Not available
|
| 50 |
+
|
| 51 |
+
def _extract_value(x):
|
| 52 |
+
if x is None:
|
| 53 |
+
return None
|
| 54 |
+
s = str(x).strip().strip('"').strip("'")
|
| 55 |
+
if ':' in s:
|
| 56 |
+
s = s.split(':', 1)[1]
|
| 57 |
+
return s.strip()
|
| 58 |
+
|
| 59 |
+
def convert_trait(x):
|
| 60 |
+
"""
|
| 61 |
+
Convert 'liver group' to binary Hypertension label aligned to study design:
|
| 62 |
+
- INCPH (idiopathic non-cirrhotic portal hypertension) -> 1 (case)
|
| 63 |
+
- LC (cirrhosis) and HNL (histologically normal liver) -> 0 (controls)
|
| 64 |
+
Unknown or other -> None
|
| 65 |
+
"""
|
| 66 |
+
v = _extract_value(x)
|
| 67 |
+
if not v:
|
| 68 |
+
return None
|
| 69 |
+
v_low = v.lower()
|
| 70 |
+
if v_low == 'incph':
|
| 71 |
+
return 1
|
| 72 |
+
if v_low in {'lc', 'hnl'}:
|
| 73 |
+
return 0
|
| 74 |
+
return None
|
| 75 |
+
|
| 76 |
+
def convert_age(x):
|
| 77 |
+
"""
|
| 78 |
+
Generic age parser: extract numeric years if present; else None.
|
| 79 |
+
"""
|
| 80 |
+
v = _extract_value(x)
|
| 81 |
+
if not v:
|
| 82 |
+
return None
|
| 83 |
+
import re
|
| 84 |
+
m = re.search(r'(\d+(?:\.\d+)?)', v)
|
| 85 |
+
if not m:
|
| 86 |
+
return None
|
| 87 |
+
try:
|
| 88 |
+
return float(m.group(1))
|
| 89 |
+
except Exception:
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
def convert_gender(x):
|
| 93 |
+
"""
|
| 94 |
+
Map gender to binary: female->0, male->1.
|
| 95 |
+
"""
|
| 96 |
+
v = _extract_value(x)
|
| 97 |
+
if not v:
|
| 98 |
+
return None
|
| 99 |
+
v_low = v.lower()
|
| 100 |
+
if v_low in {'female', 'f', 'woman', 'women', 'girl'}:
|
| 101 |
+
return 0
|
| 102 |
+
if v_low in {'male', 'm', 'man', 'men', 'boy'}:
|
| 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 clinical data available)
|
| 117 |
+
if is_trait_available:
|
| 118 |
+
selected_clinical_df = geo_select_clinical_features(
|
| 119 |
+
clinical_df=clinical_data,
|
| 120 |
+
trait=trait,
|
| 121 |
+
trait_row=trait_row,
|
| 122 |
+
convert_trait=convert_trait,
|
| 123 |
+
age_row=age_row,
|
| 124 |
+
convert_age=convert_age,
|
| 125 |
+
gender_row=gender_row,
|
| 126 |
+
convert_gender=convert_gender
|
| 127 |
+
)
|
| 128 |
+
clinical_preview = preview_df(selected_clinical_df)
|
| 129 |
+
print(clinical_preview)
|
| 130 |
+
# Ensure output directory exists and save
|
| 131 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 132 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 133 |
+
|
| 134 |
+
# Step 3: Gene Data Extraction
|
| 135 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 136 |
+
gene_data = get_genetic_data(matrix_file)
|
| 137 |
+
|
| 138 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 139 |
+
print(gene_data.index[:20])
|
| 140 |
+
|
| 141 |
+
# Step 4: Gene Identifier Review
|
| 142 |
+
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 |
+
# Decide the columns for probe IDs and gene symbols based on annotation preview
|
| 155 |
+
probe_col = 'ID' # Matches ILMN_* probe identifiers seen in gene_data
|
| 156 |
+
gene_symbol_col = 'Symbol' # Contains gene symbols
|
| 157 |
+
|
| 158 |
+
# 2. Build the mapping dataframe
|
| 159 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
|
| 160 |
+
|
| 161 |
+
# 3. Apply mapping to convert probe-level data to gene-level expression
|
| 162 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
| 163 |
+
|
| 164 |
+
# Step 7: Data Normalization and Linking
|
| 165 |
+
import os
|
| 166 |
+
import pandas as pd
|
| 167 |
+
|
| 168 |
+
# 1. Normalize gene symbols and save
|
| 169 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 170 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 171 |
+
if not normalized_gene_data.empty:
|
| 172 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 173 |
+
|
| 174 |
+
# 2. Load clinical data from disk and link with genetic data
|
| 175 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 176 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 177 |
+
|
| 178 |
+
# 3. Handle missing values
|
| 179 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 180 |
+
|
| 181 |
+
# 4. Determine bias and remove biased demographic features if necessary
|
| 182 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 183 |
+
|
| 184 |
+
# 5. Final quality validation and save cohort info
|
| 185 |
+
is_gene_available = bool(normalized_gene_data.shape[0] > 0)
|
| 186 |
+
is_trait_available = bool((trait in linked_data.columns) and bool(linked_data[trait].notna().any()))
|
| 187 |
+
note = "INFO: Trait defined as INCPH (case) vs LC/HNL (controls); Age and Gender not available."
|
| 188 |
+
is_usable = validate_and_save_cohort_info(
|
| 189 |
+
is_final=True,
|
| 190 |
+
cohort=cohort,
|
| 191 |
+
info_path=json_path,
|
| 192 |
+
is_gene_available=is_gene_available,
|
| 193 |
+
is_trait_available=is_trait_available,
|
| 194 |
+
is_biased=bool(is_trait_biased),
|
| 195 |
+
df=unbiased_linked_data,
|
| 196 |
+
note=note
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
# 6. Save linked data if usable
|
| 200 |
+
if is_usable:
|
| 201 |
+
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
|
| 202 |
+
unbiased_linked_data.to_csv(out_data_file)
|
output/preprocess/Hypertension/code/TCGA.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertension"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z3/preprocess/Hypertension/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertension/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertension/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z3/preprocess/Hypertension/cohort_info.json"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Step 1: Initial Data Loading
|
| 18 |
+
import os
|
| 19 |
+
import pandas as pd
|
| 20 |
+
|
| 21 |
+
# Step 1: Select a TCGA subdirectory relevant to the trait "Hypertension"
|
| 22 |
+
dirnames = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
|
| 23 |
+
trait_lower = trait.lower()
|
| 24 |
+
|
| 25 |
+
# Define synonyms/related terms for hypertension
|
| 26 |
+
hypertension_keywords = [
|
| 27 |
+
"hypertension", "hypertensive", "blood pressure", "blood-pressure", "blood_pressure",
|
| 28 |
+
"high blood pressure", "bp", "cardiovascular", "cardiac", "heart"
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
def is_relevant(dirname: str, keywords):
|
| 32 |
+
name = dirname.lower()
|
| 33 |
+
return any(k in name for k in keywords)
|
| 34 |
+
|
| 35 |
+
candidate_dirs = [d for d in dirnames if is_relevant(d, hypertension_keywords)]
|
| 36 |
+
|
| 37 |
+
if not candidate_dirs:
|
| 38 |
+
print(f"No suitable TCGA cohort directory found for trait '{trait}'. Skipping this trait.")
|
| 39 |
+
# Record metadata as unavailable
|
| 40 |
+
validate_and_save_cohort_info(
|
| 41 |
+
is_final=False,
|
| 42 |
+
cohort="TCGA",
|
| 43 |
+
info_path=json_path,
|
| 44 |
+
is_gene_available=False,
|
| 45 |
+
is_trait_available=False
|
| 46 |
+
)
|
| 47 |
+
clinical_df = None
|
| 48 |
+
genetic_df = None
|
| 49 |
+
else:
|
| 50 |
+
# If multiple candidates, choose the most specific (longest name as a proxy)
|
| 51 |
+
selected_dir = sorted(candidate_dirs, key=lambda x: len(x), reverse=True)[0]
|
| 52 |
+
print(f"Selected TCGA cohort directory: {selected_dir}")
|
| 53 |
+
|
| 54 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 55 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
| 56 |
+
print(f"Clinical file: {clinical_file_path}")
|
| 57 |
+
print(f"Genetic file: {genetic_file_path}")
|
| 58 |
+
|
| 59 |
+
# Step 3: Load both files
|
| 60 |
+
clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False, compression='infer')
|
| 61 |
+
genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False, compression='infer')
|
| 62 |
+
|
| 63 |
+
# Step 4: Print clinical column names
|
| 64 |
+
print("Clinical data columns:")
|
| 65 |
+
print(list(clinical_df.columns))
|
output/preprocess/Hypertrophic_Cardiomyopathy/code/GSE36961.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertrophic_Cardiomyopathy"
|
| 6 |
+
cohort = "GSE36961"
|
| 7 |
+
|
| 8 |
+
# Input paths
|
| 9 |
+
in_trait_dir = "../DATA/GEO/Hypertrophic_Cardiomyopathy"
|
| 10 |
+
in_cohort_dir = "../DATA/GEO/Hypertrophic_Cardiomyopathy/GSE36961"
|
| 11 |
+
|
| 12 |
+
# Output paths
|
| 13 |
+
out_data_file = "./output/z3/preprocess/Hypertrophic_Cardiomyopathy/GSE36961.csv"
|
| 14 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertrophic_Cardiomyopathy/gene_data/GSE36961.csv"
|
| 15 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertrophic_Cardiomyopathy/clinical_data/GSE36961.csv"
|
| 16 |
+
json_path = "./output/z3/preprocess/Hypertrophic_Cardiomyopathy/cohort_info.json"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Step 1: Initial Data Loading
|
| 20 |
+
from tools.preprocess import *
|
| 21 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
| 22 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 23 |
+
|
| 24 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
| 25 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
| 26 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
| 27 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
| 28 |
+
|
| 29 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
| 30 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
| 31 |
+
|
| 32 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
| 33 |
+
print("Background Information:")
|
| 34 |
+
print(background_info)
|
| 35 |
+
print("Sample Characteristics Dictionary:")
|
| 36 |
+
print(sample_characteristics_dict)
|
| 37 |
+
|
| 38 |
+
# Step 2: Dataset Analysis and Clinical Feature Extraction
|
| 39 |
+
import os
|
| 40 |
+
import re
|
| 41 |
+
import pandas as pd
|
| 42 |
+
|
| 43 |
+
# 1) Gene expression data availability
|
| 44 |
+
is_gene_available = True # mRNA transcriptome per background info
|
| 45 |
+
|
| 46 |
+
# 2) Variable availability and conversion functions
|
| 47 |
+
trait_row = 3 # contains 'disease state: hypertrophic cardiomyopathy (HCM)' and 'sample type: control'
|
| 48 |
+
age_row = 1 # contains 'age (yrs): ...' (also has 'tissue: cardiac' which will be ignored by converter)
|
| 49 |
+
gender_row = 0 # contains 'Sex: male' / 'Sex: female'
|
| 50 |
+
|
| 51 |
+
def _after_colon(x):
|
| 52 |
+
if x is None or (isinstance(x, float) and pd.isna(x)):
|
| 53 |
+
return None
|
| 54 |
+
s = str(x)
|
| 55 |
+
parts = s.split(":", 1)
|
| 56 |
+
return parts[1].strip() if len(parts) > 1 else s.strip()
|
| 57 |
+
|
| 58 |
+
def convert_trait(x):
|
| 59 |
+
val = _after_colon(x)
|
| 60 |
+
if val is None:
|
| 61 |
+
return None
|
| 62 |
+
v = val.strip().lower()
|
| 63 |
+
# Map known case indicators
|
| 64 |
+
if 'hypertrophic cardiomyopathy' in v or v == 'hcm' or 'hcm' in v or 'case' in v or 'patient' in v:
|
| 65 |
+
return 1
|
| 66 |
+
# Map known control indicators
|
| 67 |
+
if 'control' in v or 'normal' in v or 'healthy' in v or 'donor' in v:
|
| 68 |
+
return 0
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
def convert_age(x):
|
| 72 |
+
val = _after_colon(x)
|
| 73 |
+
if val is None:
|
| 74 |
+
return None
|
| 75 |
+
# Extract first numeric token
|
| 76 |
+
m = re.search(r'[-+]?\d+\.?\d*', val)
|
| 77 |
+
if m:
|
| 78 |
+
try:
|
| 79 |
+
num = float(m.group(0))
|
| 80 |
+
# If age looks like an integer, keep as int; otherwise, float
|
| 81 |
+
return int(num) if num.is_integer() else num
|
| 82 |
+
except Exception:
|
| 83 |
+
return None
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
def convert_gender(x):
|
| 87 |
+
val = _after_colon(x)
|
| 88 |
+
if val is None:
|
| 89 |
+
return None
|
| 90 |
+
v = val.strip().lower()
|
| 91 |
+
if v.startswith('female') or v == 'f':
|
| 92 |
+
return 0
|
| 93 |
+
if v.startswith('male') or v == 'm':
|
| 94 |
+
return 1
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
# 3) Save metadata (initial filtering)
|
| 98 |
+
is_trait_available = trait_row is not None
|
| 99 |
+
_ = validate_and_save_cohort_info(
|
| 100 |
+
is_final=False,
|
| 101 |
+
cohort=cohort,
|
| 102 |
+
info_path=json_path,
|
| 103 |
+
is_gene_available=is_gene_available,
|
| 104 |
+
is_trait_available=is_trait_available
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# 4) Clinical feature extraction
|
| 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)
|
| 120 |
+
print("Clinical feature preview:", preview)
|
| 121 |
+
|
| 122 |
+
os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
|
| 123 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
| 124 |
+
|
| 125 |
+
# Step 3: Gene Data Extraction
|
| 126 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
| 127 |
+
gene_data = get_genetic_data(matrix_file)
|
| 128 |
+
|
| 129 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
| 130 |
+
print(gene_data.index[:20])
|
| 131 |
+
|
| 132 |
+
# Step 4: Gene Identifier Review
|
| 133 |
+
# Based on the observed identifiers (e.g., A1BG, A1CF, A2M), these are human gene symbols.
|
| 134 |
+
requires_gene_mapping = False
|
| 135 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
| 136 |
+
|
| 137 |
+
# Step 5: Data Normalization and Linking
|
| 138 |
+
import os
|
| 139 |
+
import pandas as pd
|
| 140 |
+
|
| 141 |
+
# Fallbacks for variables from previous steps
|
| 142 |
+
if 'matrix_file' not in globals():
|
| 143 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
| 144 |
+
|
| 145 |
+
if 'gene_data' not in globals():
|
| 146 |
+
gene_data = get_genetic_data(matrix_file)
|
| 147 |
+
|
| 148 |
+
if 'selected_clinical_df' not in globals():
|
| 149 |
+
if os.path.exists(out_clinical_data_file):
|
| 150 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
| 151 |
+
else:
|
| 152 |
+
raise FileNotFoundError("Clinical data not found in memory or on disk. Expected at: " + out_clinical_data_file)
|
| 153 |
+
|
| 154 |
+
# 1) Normalize gene symbols and save
|
| 155 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
| 156 |
+
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
|
| 157 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
| 158 |
+
|
| 159 |
+
# 2) Link clinical and genetic data
|
| 160 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
| 161 |
+
|
| 162 |
+
# For notes: capture counts before missing handling
|
| 163 |
+
covariate_cols = [trait, 'Age', 'Gender']
|
| 164 |
+
samples_before = len(linked_data)
|
| 165 |
+
genes_before = len([c for c in linked_data.columns if c not in covariate_cols])
|
| 166 |
+
|
| 167 |
+
# 3) Handle missing values
|
| 168 |
+
linked_data = handle_missing_values(linked_data, trait)
|
| 169 |
+
|
| 170 |
+
# Counts after missing handling (before bias removal)
|
| 171 |
+
samples_after = len(linked_data)
|
| 172 |
+
genes_after = len([c for c in linked_data.columns if c not in covariate_cols])
|
| 173 |
+
|
| 174 |
+
# 4) Bias check and remove biased demographic features
|
| 175 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
| 176 |
+
|
| 177 |
+
# 5) Final quality validation and metadata saving
|
| 178 |
+
note = (
|
| 179 |
+
f"INFO: Samples before/after missing handling: {samples_before}/{samples_after}; "
|
| 180 |
+
f"Genes before/after missing handling: {genes_before}/{genes_after}."
|
| 181 |
+
)
|
| 182 |
+
is_usable = validate_and_save_cohort_info(
|
| 183 |
+
is_final=True,
|
| 184 |
+
cohort=cohort,
|
| 185 |
+
info_path=json_path,
|
| 186 |
+
is_gene_available=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/Hypertrophic_Cardiomyopathy/code/TCGA.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Path Configuration
|
| 2 |
+
from tools.preprocess import *
|
| 3 |
+
|
| 4 |
+
# Processing context
|
| 5 |
+
trait = "Hypertrophic_Cardiomyopathy"
|
| 6 |
+
|
| 7 |
+
# Input paths
|
| 8 |
+
tcga_root_dir = "../DATA/TCGA"
|
| 9 |
+
|
| 10 |
+
# Output paths
|
| 11 |
+
out_data_file = "./output/z3/preprocess/Hypertrophic_Cardiomyopathy/TCGA.csv"
|
| 12 |
+
out_gene_data_file = "./output/z3/preprocess/Hypertrophic_Cardiomyopathy/gene_data/TCGA.csv"
|
| 13 |
+
out_clinical_data_file = "./output/z3/preprocess/Hypertrophic_Cardiomyopathy/clinical_data/TCGA.csv"
|
| 14 |
+
json_path = "./output/z3/preprocess/Hypertrophic_Cardiomyopathy/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 Hypertrophic Cardiomyopathy (unlikely 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 |
+
keywords = ['hypertrophic', 'cardiomyopathy', 'heart', 'cardio', 'hcm', 'myocard', 'ventric']
|
| 24 |
+
selected_dir = None
|
| 25 |
+
|
| 26 |
+
def score_dir(name: str) -> int:
|
| 27 |
+
lname = name.lower()
|
| 28 |
+
return sum(1 for k in keywords if k in lname)
|
| 29 |
+
|
| 30 |
+
scored = [(d, score_dir(d)) for d in subdirs]
|
| 31 |
+
scored.sort(key=lambda x: x[1], reverse=True)
|
| 32 |
+
if scored and scored[0][1] > 0:
|
| 33 |
+
selected_dir = scored[0][0]
|
| 34 |
+
|
| 35 |
+
if selected_dir is None:
|
| 36 |
+
print("No suitable TCGA cohort directory found for Hypertrophic Cardiomyopathy. Skipping this trait.")
|
| 37 |
+
# Record metadata and mark as completed for this trait with no available data
|
| 38 |
+
validate_and_save_cohort_info(
|
| 39 |
+
is_final=False,
|
| 40 |
+
cohort="TCGA",
|
| 41 |
+
info_path=json_path,
|
| 42 |
+
is_gene_available=False,
|
| 43 |
+
is_trait_available=False
|
| 44 |
+
)
|
| 45 |
+
# Prepare placeholders for potential downstream references
|
| 46 |
+
cohort_dir = None
|
| 47 |
+
clinical_df = None
|
| 48 |
+
genetic_df = None
|
| 49 |
+
else:
|
| 50 |
+
cohort_dir = os.path.join(tcga_root_dir, selected_dir)
|
| 51 |
+
|
| 52 |
+
# Step 2: Identify clinical and genetic data files
|
| 53 |
+
clinical_path, genetic_path = tcga_get_relevant_filepaths(cohort_dir)
|
| 54 |
+
|
| 55 |
+
# Step 3: Load both files
|
| 56 |
+
clinical_df = pd.read_csv(clinical_path, sep='\t', index_col=0, low_memory=False, compression='infer')
|
| 57 |
+
genetic_df = pd.read_csv(genetic_path, sep='\t', index_col=0, low_memory=False, compression='infer')
|
| 58 |
+
|
| 59 |
+
# Step 4: Print clinical column names
|
| 60 |
+
print(clinical_df.columns.tolist())
|
output/preprocess/Hypertrophic_Cardiomyopathy/cohort_info.json
CHANGED
|
@@ -1,22 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"GSE36961": {
|
| 3 |
-
"is_usable": true,
|
| 4 |
-
"is_gene_available": true,
|
| 5 |
-
"is_trait_available": true,
|
| 6 |
-
"is_available": true,
|
| 7 |
-
"is_biased": false,
|
| 8 |
-
"has_age": true,
|
| 9 |
-
"has_gender": true,
|
| 10 |
-
"sample_size": 142
|
| 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 |
+
{"GSE36961": {"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": 142, "note": "INFO: Samples before/after missing handling: 145/142; Genes before/after missing handling: 18660/18660."}, "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}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|