Liu-Hy commited on
Commit
6b8ee1b
·
verified ·
1 Parent(s): e9da0d2

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. output/preprocess/Crohns_Disease/gene_data/GSE66407.csv +0 -0
  2. output/preprocess/Crohns_Disease/gene_data/GSE83448.csv +0 -0
  3. output/preprocess/Cystic_Fibrosis/clinical_data/GSE100521.csv +4 -4
  4. output/preprocess/Cystic_Fibrosis/clinical_data/GSE60690.csv +4 -4
  5. output/preprocess/Cystic_Fibrosis/code/GSE100521.py +190 -0
  6. output/preprocess/Cystic_Fibrosis/code/GSE107846.py +183 -0
  7. output/preprocess/Cystic_Fibrosis/code/GSE129168.py +193 -0
  8. output/preprocess/Cystic_Fibrosis/code/GSE139038.py +100 -0
  9. output/preprocess/Cystic_Fibrosis/code/GSE142610.py +139 -0
  10. output/preprocess/Cystic_Fibrosis/code/GSE53543.py +141 -0
  11. output/preprocess/Cystic_Fibrosis/code/GSE60690.py +197 -0
  12. output/preprocess/Cystic_Fibrosis/code/GSE67698.py +205 -0
  13. output/preprocess/Cystic_Fibrosis/code/GSE71799.py +242 -0
  14. output/preprocess/Cystic_Fibrosis/code/GSE76347.py +218 -0
  15. output/preprocess/Cystic_Fibrosis/code/TCGA.py +57 -0
  16. output/preprocess/Cystic_Fibrosis/cohort_info.json +1 -112
  17. output/preprocess/Depression/GSE110298.csv +0 -0
  18. output/preprocess/Depression/GSE99725.csv +0 -0
  19. output/preprocess/Depression/clinical_data/GSE110298.csv +1 -1
  20. output/preprocess/Depression/clinical_data/GSE201332.csv +4 -4
  21. output/preprocess/Depression/code/GSE110298.py +204 -0
  22. output/preprocess/Depression/code/GSE128387.py +178 -0
  23. output/preprocess/Depression/code/GSE135524.py +192 -0
  24. output/preprocess/Depression/code/GSE138297.py +118 -0
  25. output/preprocess/Depression/code/GSE149980.py +197 -0
  26. output/preprocess/Depression/code/GSE201332.py +364 -0
  27. output/preprocess/Depression/code/GSE208668.py +137 -0
  28. output/preprocess/Depression/code/GSE273630.py +137 -0
  29. output/preprocess/Depression/code/GSE81761.py +154 -0
  30. output/preprocess/Depression/code/GSE99725.py +211 -0
  31. output/preprocess/Depression/code/TCGA.py +58 -0
  32. output/preprocess/Depression/cohort_info.json +1 -112
  33. output/preprocess/Depression/gene_data/GSE99725.csv +0 -0
  34. output/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/GSE13608.csv +4 -4
  35. output/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/GSE48828.csv +1 -1
  36. output/preprocess/Duchenne_Muscular_Dystrophy/code/GSE109178.py +201 -0
  37. output/preprocess/Duchenne_Muscular_Dystrophy/code/GSE13608.py +204 -0
  38. output/preprocess/Duchenne_Muscular_Dystrophy/code/GSE48828.py +216 -0
  39. output/preprocess/Duchenne_Muscular_Dystrophy/code/GSE79263.py +182 -0
  40. output/preprocess/Duchenne_Muscular_Dystrophy/code/TCGA.py +69 -0
  41. output/preprocess/Duchenne_Muscular_Dystrophy/cohort_info.json +1 -52
  42. output/preprocess/Eczema/GSE32924.csv +0 -0
  43. output/preprocess/Eczema/clinical_data/GSE120899.csv +1 -1
  44. output/preprocess/Eczema/clinical_data/GSE123086.csv +4 -4
  45. output/preprocess/Eczema/clinical_data/GSE123088.csv +1 -1
  46. output/preprocess/Eczema/clinical_data/GSE182740.csv +1 -3
  47. output/preprocess/Eczema/clinical_data/GSE32924.csv +2 -2
  48. output/preprocess/Eczema/clinical_data/GSE57225.csv +1 -1
  49. output/preprocess/Eczema/code/GSE120899.py +161 -0
  50. output/preprocess/Eczema/code/GSE123086.py +220 -0
output/preprocess/Crohns_Disease/gene_data/GSE66407.csv CHANGED
The diff for this file is too large to render. See raw diff
 
output/preprocess/Crohns_Disease/gene_data/GSE83448.csv CHANGED
The diff for this file is too large to render. See raw diff
 
output/preprocess/Cystic_Fibrosis/clinical_data/GSE100521.csv CHANGED
@@ -1,4 +1,4 @@
1
- 0,1,2
2
- 0.0,,
3
- ,27.0,
4
- ,,
 
1
+ ,GSM2685867,GSM2685868,GSM2685869,GSM2685870,GSM2685871,GSM2685872,GSM2685873,GSM2685874,GSM2685875,GSM2685876,GSM2685877,GSM2685878,GSM2685879,GSM2685880,GSM2685881,GSM2685882,GSM2685883,GSM2685884,GSM2685885,GSM2685886,GSM2685887,GSM2685888,GSM2685889,GSM2685890,GSM2685891,GSM2685892,GSM2685893,GSM2685894,GSM2685895,GSM2685896,GSM2685897,GSM2685898,GSM2685899,GSM2685900,GSM2685901,GSM2685902,GSM2685903,GSM2685904,GSM2685905,GSM2685906,GSM2685907,GSM2685908,GSM2685909,GSM2685910,GSM2685911,GSM2685912,GSM2685913,GSM2685914,GSM2685915,GSM2685916,GSM2685917,GSM2685918,GSM2685919,GSM2685920,GSM2685921,GSM2685922,GSM2685923,GSM2685924,GSM2685925,GSM2685926,GSM2685927,GSM2685928,GSM2685929,GSM2685930,GSM2685931,GSM2685932,GSM2685933,GSM2685934,GSM2685935,GSM2685936,GSM2685937,GSM2685938
2
+ Cystic_Fibrosis,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
+ Age,28.0,27.0,26.0,31.0,21.0,25.0,28.0,27.0,26.0,31.0,21.0,25.0,28.0,27.0,26.0,31.0,21.0,25.0,28.0,27.0,26.0,31.0,21.0,25.0,28.0,27.0,26.0,31.0,21.0,25.0,28.0,27.0,26.0,31.0,21.0,25.0,27.0,27.0,29.0,27.0,29.0,32.0,27.0,27.0,29.0,27.0,29.0,32.0,27.0,27.0,29.0,27.0,29.0,32.0,27.0,27.0,29.0,27.0,29.0,32.0,27.0,27.0,29.0,27.0,29.0,32.0,27.0,27.0,29.0,27.0,29.0,32.0
4
+ Gender,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.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,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.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,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0
output/preprocess/Cystic_Fibrosis/clinical_data/GSE60690.csv CHANGED
@@ -1,4 +1,4 @@
1
- ,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29
2
- Cystic_Fibrosis,0.92156,-0.79274,2.33374,-1.36666,2.86073,1.08383,1.15792,1.516,-0.77528,-0.35251,0.95176,-0.78019,-0.45468,1.14497,-0.47971,0.08552,-0.74197,-1.29147,0.81747,1.52976,1.78443,0.8515,1.98295,0.86374,0.94161,1.10084,-0.5591,0.84926,0.86596,1.3764
3
- Age,38.2,9.2,22.5,14.4,33.8,18.6,27.7,33.5,17.8,24.1,16.4,8.7,10.4,46.3,19.0,17.1,10.2,16.7,39.7,39.3,25.4,41.2,18.1,21.5,17.3,32.4,19.8,34.3,25.3,46.7
4
- Gender,1.0,0.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,
 
1
+ ,GSM1485230,GSM1485231,GSM1485232,GSM1485233,GSM1485234,GSM1485235,GSM1485236,GSM1485237,GSM1485238,GSM1485239,GSM1485240,GSM1485241,GSM1485242,GSM1485243,GSM1485244,GSM1485245,GSM1485246,GSM1485247,GSM1485248,GSM1485249,GSM1485250,GSM1485251,GSM1485252,GSM1485253,GSM1485254,GSM1485255,GSM1485256,GSM1485257,GSM1485258,GSM1485259,GSM1485260,GSM1485261,GSM1485262,GSM1485263,GSM1485264,GSM1485265,GSM1485266,GSM1485267,GSM1485268,GSM1485269,GSM1485270,GSM1485271,GSM1485272,GSM1485273,GSM1485274,GSM1485275,GSM1485276,GSM1485277,GSM1485278,GSM1485279,GSM1485280,GSM1485281,GSM1485282,GSM1485283,GSM1485284,GSM1485285,GSM1485286,GSM1485287,GSM1485288,GSM1485289,GSM1485290,GSM1485291,GSM1485292,GSM1485293,GSM1485294,GSM1485295,GSM1485296,GSM1485297,GSM1485298,GSM1485299,GSM1485300,GSM1485301,GSM1485302,GSM1485303,GSM1485304,GSM1485305,GSM1485306,GSM1485307,GSM1485308,GSM1485309,GSM1485310,GSM1485311,GSM1485312,GSM1485313,GSM1485314,GSM1485315,GSM1485316,GSM1485317,GSM1485318,GSM1485319,GSM1485320,GSM1485321,GSM1485322,GSM1485323,GSM1485324,GSM1485325,GSM1485326,GSM1485327,GSM1485328,GSM1485329,GSM1485330,GSM1485331,GSM1485332,GSM1485333,GSM1485334,GSM1485335,GSM1485336,GSM1485337,GSM1485338,GSM1485339,GSM1485340,GSM1485341,GSM1485342,GSM1485343,GSM1485344,GSM1485345,GSM1485346,GSM1485347,GSM1485348,GSM1485349,GSM1485350,GSM1485351,GSM1485352,GSM1485353,GSM1485354,GSM1485355,GSM1485356,GSM1485357,GSM1485358,GSM1485359,GSM1485360,GSM1485361,GSM1485362,GSM1485363,GSM1485364,GSM1485365,GSM1485366,GSM1485367,GSM1485368,GSM1485369,GSM1485370,GSM1485371,GSM1485372,GSM1485373,GSM1485374,GSM1485375,GSM1485376,GSM1485377,GSM1485378,GSM1485379,GSM1485380,GSM1485381,GSM1485382,GSM1485383,GSM1485384,GSM1485385,GSM1485386,GSM1485387,GSM1485388,GSM1485389,GSM1485390,GSM1485391,GSM1485392,GSM1485393,GSM1485394,GSM1485395,GSM1485396,GSM1485397,GSM1485398,GSM1485399,GSM1485400,GSM1485401,GSM1485402,GSM1485403,GSM1485404,GSM1485405,GSM1485406,GSM1485407,GSM1485408,GSM1485409,GSM1485410,GSM1485411,GSM1485412,GSM1485413,GSM1485414,GSM1485415,GSM1485416,GSM1485417,GSM1485418,GSM1485419,GSM1485420,GSM1485421,GSM1485422,GSM1485423,GSM1485424,GSM1485425,GSM1485426,GSM1485427,GSM1485428,GSM1485429,GSM1485430,GSM1485431,GSM1485432,GSM1485433,GSM1485434,GSM1485435,GSM1485436,GSM1485437,GSM1485438,GSM1485439,GSM1485440,GSM1485441,GSM1485442,GSM1485443,GSM1485444,GSM1485445,GSM1485446,GSM1485447,GSM1485448,GSM1485449,GSM1485450,GSM1485451,GSM1485452,GSM1485453,GSM1485454,GSM1485455,GSM1485456,GSM1485457,GSM1485458,GSM1485459,GSM1485460,GSM1485461,GSM1485462,GSM1485463,GSM1485464,GSM1485465,GSM1485466,GSM1485467,GSM1485468,GSM1485469,GSM1485470,GSM1485471,GSM1485472,GSM1485473,GSM1485474,GSM1485475,GSM1485476,GSM1485477,GSM1485478,GSM1485479,GSM1485480,GSM1485481,GSM1485482,GSM1485483,GSM1485484,GSM1485485,GSM1485486,GSM1485487,GSM1485488,GSM1485489,GSM1485490,GSM1485491,GSM1485492,GSM1485493,GSM1485494,GSM1485495,GSM1485496,GSM1485497,GSM1485498,GSM1485499,GSM1485500,GSM1485501,GSM1485502,GSM1485503,GSM1485504,GSM1485505,GSM1485506,GSM1485507,GSM1485508,GSM1485509,GSM1485510,GSM1485511,GSM1485512,GSM1485513,GSM1485514,GSM1485515,GSM1485516,GSM1485517,GSM1485518,GSM1485519,GSM1485520,GSM1485521,GSM1485522,GSM1485523,GSM1485524,GSM1485525,GSM1485526,GSM1485527,GSM1485528,GSM1485529,GSM1485530,GSM1485531,GSM1485532,GSM1485533,GSM1485534,GSM1485535,GSM1485536,GSM1485537,GSM1485538,GSM1485539,GSM1485540,GSM1485541,GSM1485542,GSM1485543,GSM1485544,GSM1485545,GSM1485546,GSM1485547,GSM1485548,GSM1485549,GSM1485550,GSM1485551,GSM1485552,GSM1485553,GSM1485554,GSM1485555,GSM1485556,GSM1485557,GSM1485558,GSM1485559,GSM1485560,GSM1485561,GSM1485562,GSM1485563,GSM1485564,GSM1485565,GSM1485566,GSM1485567,GSM1485568,GSM1485569,GSM1485570,GSM1485571,GSM1485572,GSM1485573,GSM1485574,GSM1485575,GSM1485576,GSM1485577,GSM1485578,GSM1485579,GSM1485580,GSM1485581,GSM1485582,GSM1485583,GSM1485584,GSM1485585,GSM1485586,GSM1485587,GSM1485588,GSM1485589,GSM1485590,GSM1485591,GSM1485592,GSM1485593,GSM1485594,GSM1485595,GSM1485596,GSM1485597,GSM1485598,GSM1485599,GSM1485600,GSM1485601,GSM1485602,GSM1485603,GSM1485604,GSM1485605,GSM1485606,GSM1485607,GSM1485608,GSM1485609,GSM1485610,GSM1485611,GSM1485612,GSM1485613,GSM1485614,GSM1485615,GSM1485616,GSM1485617,GSM1485618,GSM1485619,GSM1485620,GSM1485621,GSM1485622,GSM1485623,GSM1485624,GSM1485625,GSM1485626,GSM1485627,GSM1485628,GSM1485629,GSM1485630,GSM1485631,GSM1485632,GSM1485633,GSM1485634,GSM1485635,GSM1485636,GSM1485637,GSM1485638,GSM1485639,GSM1485640,GSM1485641,GSM1485642,GSM1485643,GSM1485644,GSM1485645,GSM1485646,GSM1485647,GSM1485648,GSM1485649,GSM1485650,GSM1485651,GSM1485652,GSM1485653,GSM1485654,GSM1485655,GSM1485656,GSM1485657,GSM1485658,GSM1485659,GSM1485660,GSM1485661,GSM1485662,GSM1485663,GSM1485664,GSM1485665,GSM1485666,GSM1485667,GSM1485668,GSM1485669,GSM1485670,GSM1485671,GSM1485672,GSM1485673,GSM1485674,GSM1485675,GSM1485676,GSM1485677,GSM1485678,GSM1485679,GSM1485680,GSM1485681,GSM1485682,GSM1485683,GSM1485684,GSM1485685,GSM1485686,GSM1485687,GSM1485688,GSM1485689,GSM1485690,GSM1485691,GSM1485692,GSM1485693,GSM1485694,GSM1485695,GSM1485696,GSM1485697,GSM1485698,GSM1485699,GSM1485700,GSM1485701,GSM1485702,GSM1485703,GSM1485704,GSM1485705,GSM1485706,GSM1485707,GSM1485708,GSM1485709,GSM1485710,GSM1485711,GSM1485712,GSM1485713,GSM1485714,GSM1485715,GSM1485716,GSM1485717,GSM1485718,GSM1485719,GSM1485720,GSM1485721,GSM1485722,GSM1485723,GSM1485724,GSM1485725,GSM1485726,GSM1485727,GSM1485728,GSM1485729,GSM1485730,GSM1485731,GSM1485732,GSM1485733,GSM1485734,GSM1485735,GSM1485736,GSM1485737,GSM1485738,GSM1485739,GSM1485740,GSM1485741,GSM1485742,GSM1485743,GSM1485744,GSM1485745,GSM1485746,GSM1485747,GSM1485748,GSM1485749,GSM1485750,GSM1485751,GSM1485752,GSM1485753,GSM1485754,GSM1485755,GSM1485756,GSM1485757,GSM1485758,GSM1485759,GSM1485760,GSM1485761,GSM1485762,GSM1485763,GSM1485764,GSM1485765,GSM1485766,GSM1485767,GSM1485768,GSM1485769,GSM1485770,GSM1485771,GSM1485772,GSM1485773,GSM1485774,GSM1485775,GSM1485776,GSM1485777,GSM1485778,GSM1485779,GSM1485780,GSM1485781,GSM1485782,GSM1485783,GSM1485784,GSM1485785,GSM1485786,GSM1485787,GSM1485788,GSM1485789,GSM1485790,GSM1485791,GSM1485792,GSM1485793,GSM1485794,GSM1485795,GSM1485796,GSM1485797,GSM1485798,GSM1485799,GSM1485800,GSM1485801,GSM1485802,GSM1485803,GSM1485804,GSM1485805,GSM1485806,GSM1485807,GSM1485808,GSM1485809,GSM1485810,GSM1485811,GSM1485812,GSM1485813,GSM1485814,GSM1485815,GSM1485816,GSM1485817,GSM1485818,GSM1485819,GSM1485820,GSM1485821,GSM1485822,GSM1485823,GSM1485824,GSM1485825,GSM1485826,GSM1485827,GSM1485828,GSM1485829,GSM1485830,GSM1485831,GSM1485832,GSM1485833,GSM1485834,GSM1485835,GSM1485836,GSM1485837,GSM1485838,GSM1485839,GSM1485840,GSM1485841,GSM1485842,GSM1485843,GSM1485844,GSM1485845,GSM1485846,GSM1485847,GSM1485848,GSM1485849,GSM1485850,GSM1485851,GSM1485852,GSM1485853,GSM1485854,GSM1485855,GSM1485856,GSM1485857,GSM1485858,GSM1485859,GSM1485860,GSM1485861,GSM1485862,GSM1485863,GSM1485864,GSM1485865,GSM1485866,GSM1485867,GSM1485868,GSM1485869,GSM1485870,GSM1485871,GSM1485872,GSM1485873,GSM1485874,GSM1485875,GSM1485876,GSM1485877,GSM1485878,GSM1485879,GSM1485880,GSM1485881,GSM1485882,GSM1485883,GSM1485884,GSM1485885,GSM1485886,GSM1485887,GSM1485888,GSM1485889,GSM1485890,GSM1485891,GSM1485892,GSM1485893,GSM1485894,GSM1485895,GSM1485896,GSM1485897,GSM1485898,GSM1485899,GSM1485900,GSM1485901,GSM1485902,GSM1485903,GSM1485904,GSM1485905,GSM1485906,GSM1485907,GSM1485908,GSM1485909,GSM1485910,GSM1485911,GSM1485912,GSM1485913,GSM1485914,GSM1485915,GSM1485916,GSM1485917,GSM1485918,GSM1485919,GSM1485920,GSM1485921,GSM1485922,GSM1485923,GSM1485924,GSM1485925,GSM1485926,GSM1485927,GSM1485928,GSM1485929,GSM1485930,GSM1485931,GSM1485932,GSM1485933,GSM1485934,GSM1485935,GSM1485936,GSM1485937,GSM1485938,GSM1485939,GSM1485940,GSM1485941,GSM1485942,GSM1485943,GSM1485944,GSM1485945,GSM1485946,GSM1485947,GSM1485948,GSM1485949,GSM1485950,GSM1485951,GSM1485952,GSM1485953,GSM1485954,GSM1485955,GSM1485956,GSM1485957,GSM1485958,GSM1485959,GSM1485960,GSM1485961,GSM1485962,GSM1485963,GSM1485964,GSM1485965,GSM1485966,GSM1485967,GSM1485968,GSM1485969,GSM1485970,GSM1485971,GSM1485972,GSM1485973,GSM1485974,GSM1485975,GSM1485976,GSM1485977,GSM1485978,GSM1485979,GSM1485980,GSM1485981,GSM1485982,GSM1485983
2
+ Cystic_Fibrosis,0.92156,-0.79274,2.33374,-1.36666,2.86073,1.08383,1.15792,1.516,-0.77528,-0.35251,0.95176,-0.78019,-0.45468,1.14497,-0.47971,0.08552,-0.74197,-1.29147,0.81747,1.52976,1.78443,0.8515,1.98295,0.86374,0.94161,1.10084,-0.5591,0.84926,0.86596,1.3764,1.58803,-1.42981,0.41955,-1.06725,-0.73025,1.11236,1.5707,-0.22187,1.11423,0.19069,-0.16056,-0.10308,0.74876,2.59927,-1.14978,1.33201,0.71361,1.59888,0.62198,0.94943,1.15061,-0.44422,0.60454,-0.3472,-0.81067,1.35473,0.51605,0.67777,-0.84568,-0.11724,1.47788,-0.80634,0.98946,0.39554,2.10932,-0.60253,1.15376,1.8699,1.0951,1.98885,1.34465,0.93908,1.62136,0.86086,1.18657,0.81277,-0.88437,1.44946,1.61083,-0.61218,0.31041,1.12896,2.18756,1.60152,-0.69788,1.50791,0.8614,0.67293,-0.86024,1.59023,-0.92336,-0.85566,-0.03719,1.28825,1.01312,-0.42281,0.20243,1.31772,0.88303,1.41734,1.5214,-0.41068,1.29711,1.95614,0.94653,-0.22111,1.00444,-0.70561,1.26576,1.31609,-0.30831,-0.70565,-0.25663,0.14704,1.53139,0.8776,-1.20456,1.1345,0.66688,1.41212,0.76677,0.13187,0.58694,1.02139,-1.41169,-0.15094,0.74355,-0.41289,0.86337,-0.10408,1.50031,-0.1838,1.44159,1.15678,0.15381,1.36838,1.51145,1.34038,0.97747,1.01735,-1.23094,0.58015,0.92807,-0.38794,0.26616,2.01339,-1.06073,-0.13638,2.01586,-0.32574,1.14286,1.34802,1.15201,-0.3349,-0.71269,0.96017,0.56489,1.36118,0.54689,1.0122,1.28948,0.46538,-1.161,1.53865,-0.23283,1.49624,0.62987,0.52467,-0.43049,-0.15048,1.3643,1.86161,1.58096,2.18008,-0.1094,0.20982,-0.05197,0.96521,1.40141,1.32123,1.19667,1.55608,0.72107,1.1934,1.32735,2.23593,-0.24392,1.48014,0.69842,1.85498,1.31409,0.59783,1.04943,-1.46812,-1.13401,-0.14649,-0.28581,-0.0862,-0.19153,-0.20656,-0.08135,0.73449,1.68383,0.27949,0.54642,2.30664,0.14923,1.53812,-0.71812,-0.69881,0.80034,0.60038,0.8284,1.39502,1.0303,1.83367,1.32284,1.36882,0.81341,0.12801,-0.5574,0.88671,-1.03121,1.21603,1.04606,-0.68033,0.04278,0.63902,0.4542,1.65754,1.26839,-0.61033,1.56672,-0.61804,0.83875,1.45733,1.70987,-0.77868,1.19695,2.17695,0.52934,0.89594,-0.92873,-0.57066,1.9759,-0.12834,1.32616,-1.12969,0.71715,1.56505,0.59081,-0.26722,-0.96504,2.23285,1.05784,2.65882,1.44487,0.95249,0.63325,0.94241,2.05113,1.33409,1.06864,1.32454,0.85966,0.69055,-0.71945,0.56647,-1.19613,1.48824,0.03874,1.81695,1.24392,1.16361,1.02542,1.11462,2.6814,0.64126,-0.99642,0.27484,-0.28634,-0.53881,1.90948,1.65464,0.94002,1.35045,-0.30675,1.04579,1.27372,0.76914,1.01868,0.07858,1.11367,0.42152,0.01244,1.99577,-1.38469,0.69382,-0.45346,1.3149,1.13536,0.78524,-1.54158,0.19559,1.00482,1.11878,-0.16407,-0.5996,1.72263,0.91769,0.94851,1.05588,-0.52356,-0.59398,0.59045,0.46938,0.92796,-0.20176,1.09586,0.95437,1.21818,-1.14898,0.22141,0.90657,-1.38999,1.44016,1.8012,-1.02374,-0.91411,-0.3635,-0.5264,0.92916,-0.77745,0.05011,0.95306,1.94399,1.26293,-1.23755,1.72352,-0.89519,-1.40313,0.92046,1.82854,0.82502,-0.3693,0.63955,1.09043,0.83725,0.67395,-0.69551,-1.31674,-0.22962,0.99038,-0.56139,1.19661,0.60895,2.01971,-0.49866,-0.0761,-0.27978,1.13706,-1.00227,0.89157,-0.56536,-0.77226,-1.66729,-0.5874,-0.04949,1.31257,0.04184,0.25484,-0.06241,1.24603,1.07136,0.83388,0.97526,0.48039,1.85549,1.18901,-0.16192,-0.22085,0.64575,0.89188,2.04047,0.37922,1.498,1.74525,1.828,1.03971,-0.66373,-0.68338,0.99747,0.68336,-0.23816,0.89354,0.6803,1.51829,0.34785,0.0259,1.62578,0.12237,0.44876,-1.14523,-0.00642,1.36369,0.94228,1.10933,1.38742,1.17461,-0.19275,2.15993,-0.82576,-0.0533,-1.0646,1.28982,-0.58489,0.06572,1.47219,1.02516,-0.30547,-0.37462,-0.71644,0.38008,0.79368,-0.23912,1.22204,1.2758,1.81875,1.5929,-0.27252,-0.07023,1.01006,1.47777,-0.57181,0.87271,-1.88248,-0.75109,0.87227,1.17893,-1.69292,1.56122,-0.1645,2.50727,-0.50207,0.9459,1.601,-0.7515,1.13733,1.29803,-0.85498,1.93039,1.16508,-1.50648,-0.81059,1.26691,-0.35312,1.26365,-0.20501,1.31048,0.12992,0.20087,-1.47815,-1.09669,1.20705,1.55756,1.42565,-0.54397,1.44083,-0.13237,1.64768,-0.2465,1.46994,1.47311,-0.35863,2.17888,1.45841,-0.6027,1.1772,1.44182,-0.21852,1.37708,-0.98222,-0.82264,-0.58504,1.61905,1.43458,1.63937,-0.8884,0.90391,-0.90093,1.46216,1.22475,-0.4765,1.39563,1.05319,-0.86471,0.99983,-1.75064,-0.0604,-0.74263,-0.88796,1.15518,1.94128,1.54595,-0.33324,-0.91393,-1.0166,-0.4586,-0.84138,-0.0728,1.15253,-0.40097,-0.8019,2.49047,1.11237,1.88311,2.27768,1.34266,-0.91584,2.32135,1.08812,-0.73253,-0.66689,-0.46323,-0.32627,1.07652,1.17419,-0.57476,0.91342,1.1458,1.73862,1.21526,0.96759,1.43957,-0.11342,-0.71944,-0.01756,-0.59165,1.09436,2.59998,-0.33232,-1.47203,-0.29625,-0.95612,1.17874,-0.6494,1.38519,1.29624,-0.82184,1.02808,0.85919,0.90761,-0.83791,0.99642,-0.98447,1.64431,-0.9365,1.33703,1.38555,1.16994,-0.99217,1.35496,-0.58614,1.47883,1.46902,1.43255,1.20366,-0.75796,-1.3924,-0.00469,-0.47973,-0.86932,-0.84773,-0.92913,-1.21792,-0.05961,1.47301,0.89963,1.21215,-0.42147,-0.81618,-1.25346,-1.55974,-0.10105,-1.35728,-0.66503,-0.77148,-0.52559,0.90093,1.93222,0.93942,1.52617,2.09861,-0.94987,-0.19552,1.50892,0.87291,-0.4945,-0.19308,-0.18078,1.23419,-0.6492,-0.56378,-1.91165,1.10027,1.24411,-0.47591,-0.25666,0.89576,0.43759,-0.81369,-0.24181,-1.33675,-0.3708,-0.78278,-0.5614,1.49215,-0.45029,1.29145,-0.98062,1.35656,1.8866,1.2835,1.43356,-0.04791,-0.34807,0.95595,-1.29166,-0.68496,-0.94096,1.64973,-0.33753,0.17557,0.48531,1.63084,2.0495,1.35109,-1.03216,-0.33741,1.16501,1.87839,-0.28466,-1.10253,1.87558,0.19522,1.31513,1.12246,-0.11744,2.14548,-0.85098,-1.47212,-0.07703,-0.52329,-0.8381,-0.585,-0.2546,-1.33776,-0.21855,1.01261,0.80303,-1.48359,-0.94997,0.97487,1.75235,1.39789,0.90016,0.92505,1.52189,1.02563,1.32248,-0.96954,-0.42049,-1.20699,1.43231,1.61862,-0.89647,-0.88597,1.73408,1.80437,0.30479,1.21472,1.0387,1.41264,1.07469,1.22324,-0.89445,-0.44958,0.94916,1.28335,1.35647,2.31673,-1.30771,1.11287,1.7175,-0.16635,-0.55271,1.08644,1.49519,1.87647,0.8345,0.08579,0.84226,0.60659,-0.72935,1.8187,1.50448,-0.43112,1.64975,0.80629,-0.2485,1.06377,-0.68798,1.00751,1.26296,2.03152,-0.52116,1.98575,-0.64812,0.89837,-0.09073,0.77444,1.28576,1.49728,-0.34531,-0.43106,2.05402,1.71585,1.43842,-1.12377,1.34007,-1.04041,0.66693,-0.50808,1.08035,-0.78962,-0.50904,-0.34134,1.1356,-1.18661,1.7079,1.32187,1.43677,1.30141,-0.42515,1.71817,-0.30676,1.48309,-1.61766,-1.89891,2.31375,-0.35972,-0.30861,1.73405,-0.33349
3
+ Age,38.2,9.2,22.5,14.4,33.8,18.6,27.7,33.5,17.8,24.1,16.4,8.7,10.4,46.3,19.0,17.1,10.2,16.7,39.7,39.3,25.4,41.2,18.1,21.5,17.3,32.4,19.8,34.3,25.3,46.7,35.9,10.1,21.7,17.5,21.3,39.1,16.5,11.3,38.3,14.9,19.0,20.8,26.6,16.7,9.3,49.9,32.8,36.1,15.3,37.2,43.2,20.0,32.7,18.5,18.0,18.2,36.0,36.7,18.2,23.9,29.2,17.8,21.5,34.9,39.3,15.1,15.6,23.8,16.4,15.4,20.6,17.5,30.3,42.0,25.4,32.5,18.9,16.3,38.0,18.4,38.9,16.6,38.4,16.8,14.8,16.1,38.8,16.0,8.4,33.0,21.2,15.3,24.7,46.2,22.2,15.7,21.2,35.1,17.1,33.5,36.5,24.7,43.7,18.4,16.5,16.8,15.2,15.1,20.1,34.9,8.8,19.9,9.2,26.3,24.4,20.0,17.0,34.4,16.9,52.9,17.4,21.0,29.4,28.6,11.8,18.6,21.2,18.3,25.0,14.9,42.2,10.3,18.0,23.1,23.2,30.7,35.8,20.3,15.4,23.8,12.4,10.9,23.3,23.8,18.7,21.7,17.0,14.3,43.0,14.9,23.4,16.4,15.7,19.8,19.0,37.1,21.7,18.4,17.0,44.9,41.1,18.8,11.7,48.9,8.8,28.2,23.1,11.8,16.7,22.3,49.8,35.1,28.6,20.4,22.6,21.0,10.6,21.7,31.7,19.0,16.4,32.2,37.9,22.5,15.3,38.4,19.4,40.5,18.3,35.4,20.3,34.7,43.3,9.0,16.4,18.3,15.2,15.2,26.0,21.6,12.2,18.5,45.6,20.0,31.4,48.0,19.8,45.1,10.5,20.0,38.9,16.0,20.1,29.2,19.2,46.1,25.2,39.0,36.9,26.0,20.3,22.1,19.1,30.4,21.8,21.1,22.0,15.0,34.7,55.0,25.6,24.0,19.5,19.0,31.2,40.2,44.2,18.0,22.4,32.5,40.8,37.6,18.2,21.2,21.1,19.8,29.0,9.5,33.3,24.3,44.8,18.9,13.0,41.8,16.2,23.7,15.6,15.2,32.9,35.6,25.1,29.3,22.7,32.8,38.5,38.8,19.4,20.2,12.9,44.1,19.1,19.4,16.5,40.4,28.1,20.2,25.6,37.5,19.5,18.2,18.6,18.1,36.4,23.4,24.2,16.8,19.0,46.1,21.1,33.6,37.9,19.0,21.1,34.0,25.8,22.2,14.9,33.1,16.2,23.7,15.6,16.7,15.4,16.0,36.3,26.2,13.2,15.9,25.0,20.2,40.2,20.5,15.5,9.1,36.8,34.7,39.1,23.0,33.4,37.2,27.4,11.8,10.4,17.0,14.7,15.4,45.5,13.3,18.5,20.0,12.5,19.9,20.3,19.0,35.9,18.5,42.1,16.6,27.7,18.7,17.7,22.9,28.9,40.4,16.9,38.2,16.3,38.8,15.8,10.6,17.0,29.3,41.4,11.3,15.9,33.2,21.1,19.7,16.0,25.1,30.1,8.0,43.9,8.2,14.1,14.2,18.8,9.7,17.3,11.2,17.1,14.1,19.5,37.8,16.4,21.5,21.7,32.4,30.4,20.8,21.7,21.4,28.8,19.0,34.3,18.7,16.6,36.1,45.3,21.9,11.6,30.7,23.2,24.3,34.2,32.4,49.3,17.5,25.6,43.8,17.9,26.7,10.8,15.5,29.1,18.8,24.5,19.9,20.3,20.0,21.6,19.8,12.7,8.0,41.0,21.3,12.1,33.3,32.6,21.9,10.7,17.4,41.8,23.4,23.4,17.8,27.0,16.8,17.7,19.1,15.5,31.8,22.2,16.3,22.2,8.5,13.4,15.9,17.8,8.5,21.7,19.1,38.5,20.3,26.0,46.1,21.5,17.8,19.3,11.0,46.6,22.9,13.8,18.0,26.3,14.7,21.7,15.8,30.3,25.9,17.2,13.5,17.0,33.3,41.6,40.0,17.5,16.3,8.9,19.1,14.8,31.9,21.9,23.7,22.9,17.1,16.6,28.7,30.6,23.0,16.8,18.6,15.1,17.6,49.4,17.3,21.2,21.4,28.1,19.3,33.7,28.9,11.0,52.0,20.3,10.3,30.7,13.0,8.6,17.9,11.1,15.7,21.7,28.5,14.4,14.7,12.1,24.5,14.7,10.5,18.8,23.7,22.2,17.6,46.8,15.4,28.8,24.2,19.0,17.1,25.5,16.3,13.5,8.5,15.3,15.3,18.8,17.5,22.7,22.5,57.6,31.2,29.0,22.7,10.3,19.0,19.1,15.4,23.6,17.0,19.9,15.9,25.2,11.4,29.6,14.5,27.8,34.6,13.5,21.0,17.3,32.1,16.3,35.8,18.5,22.9,19.2,37.2,32.1,17.4,9.6,40.4,21.8,48.4,17.0,31.5,32.9,16.4,14.3,16.9,16.2,12.2,16.9,11.8,14.6,19.6,19.1,28.7,19.8,26.3,21.2,11.9,8.4,21.5,15.0,18.8,14.9,12.2,20.5,29.1,19.6,15.0,19.8,8.1,8.4,26.8,17.1,11.9,23.2,26.3,24.0,13.6,14.7,9.8,27.1,19.7,14.3,20.2,17.2,36.7,16.9,19.3,15.3,22.8,14.1,8.5,47.5,14.0,24.6,11.1,36.5,24.5,23.0,47.2,22.6,26.0,30.9,16.8,15.5,15.1,17.2,19.0,15.5,35.4,18.0,44.8,52.1,18.1,18.2,25.7,26.9,15.7,14.7,22.8,17.1,18.7,27.4,19.2,35.2,15.4,14.3,18.8,9.9,19.6,14.5,15.8,14.8,23.0,23.1,28.7,11.0,15.4,23.4,19.0,17.8,28.0,16.6,16.5,27.4,15.3,15.3,23.3,12.7,26.3,35.4,17.1,14.2,17.0,28.9,23.5,40.3,16.4,26.1,24.7,23.0,20.0,12.5,15.6,29.2,38.5,54.2,14.3,39.6,19.1,23.0,16.9,16.3,17.6,31.3,17.1,18.2,21.0,37.9,9.0,26.3,41.4,14.0,37.2,24.0,15.5,31.3,12.6,16.0,39.4,28.2,22.5,40.1,10.6,22.3,16.0,24.3,16.7,20.5,20.5,16.3,19.6,17.0,19.6,16.0,48.5,17.6,17.1,13.1,23.3,15.6,21.4,9.2,16.0,12.2,42.6,25.3,34.2,33.1,11.8,42.6,19.2,17.7,10.3,9.3,15.2,16.6,24.5,19.9,14.9
4
+ Gender,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.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,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.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,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.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,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.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,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,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,0.0,0.0,0.0,1.0,1.0,0.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,0.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,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0
output/preprocess/Cystic_Fibrosis/code/GSE100521.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE100521"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE100521"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE100521.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE100521.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE100521.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/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 # Illumina HumanHT-12 v4 BeadChip = mRNA expression
45
+
46
+ # 2) Variable availability (keys from the provided Sample Characteristics Dictionary)
47
+ trait_row = 0 # From "patient identification number: Non CF subject X" vs "CF patient X"
48
+ age_row = 1 # From "age: N"
49
+ gender_row = 2 # From "gender: Male/Female"
50
+
51
+ # 2.2) Converters
52
+ def convert_trait(x):
53
+ if x is None or (isinstance(x, float) and pd.isna(x)):
54
+ return None
55
+ s = str(x)
56
+ if ':' in s:
57
+ s = s.split(':', 1)[1]
58
+ s = s.strip().lower()
59
+ # Map CF status: Non CF => 0, CF => 1
60
+ if 'non' in s and 'cf' in s:
61
+ return 0
62
+ if 'cf' in s:
63
+ return 1
64
+ return None
65
+
66
+ def convert_age(x):
67
+ if x is None or (isinstance(x, float) and pd.isna(x)):
68
+ return None
69
+ s = str(x)
70
+ if ':' in s:
71
+ s = s.split(':', 1)[1]
72
+ s = s.strip()
73
+ m = re.search(r'[-+]?\d+(\.\d+)?', s)
74
+ if m:
75
+ try:
76
+ return float(m.group())
77
+ except Exception:
78
+ return None
79
+ return None
80
+
81
+ def convert_gender(x):
82
+ if x is None or (isinstance(x, float) and pd.isna(x)):
83
+ return None
84
+ s = str(x)
85
+ if ':' in s:
86
+ s = s.split(':', 1)[1]
87
+ s = s.strip().lower()
88
+ if s in ['female', 'f']:
89
+ return 0
90
+ if s in ['male', 'm']:
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 (only if trait_row 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
+ preview = preview_df(selected_clinical_df)
117
+ print(preview)
118
+
119
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
120
+ selected_clinical_df.to_csv(out_clinical_data_file)
121
+
122
+ # Step 3: Gene Data Extraction
123
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
124
+ gene_data = get_genetic_data(matrix_file)
125
+
126
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
127
+ print(gene_data.index[:20])
128
+
129
+ # Step 4: Gene Identifier Review
130
+ # ILMN_* identifiers are Illumina probe IDs, not human gene symbols.
131
+ requires_gene_mapping = True
132
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
133
+
134
+ # Step 5: Gene Annotation
135
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
136
+ gene_annotation = get_gene_annotation(soft_file)
137
+
138
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
139
+ print("Gene annotation preview:")
140
+ print(preview_df(gene_annotation))
141
+
142
+ # Step 6: Gene Identifier Mapping
143
+ # Identify the correct columns for probe IDs and gene symbols in the annotation
144
+ probe_col = 'ID' # Matches ILMN_* probe IDs in the expression data
145
+ gene_symbol_col = 'Symbol' # Contains gene symbols
146
+
147
+ # Build mapping dataframe
148
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
149
+
150
+ # Apply mapping to convert probe-level data to gene-level expression
151
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
152
+
153
+ # Step 7: Data Normalization and Linking
154
+ import os
155
+
156
+ # 1) Normalize gene symbols and save gene-level data
157
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
158
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
159
+ normalized_gene_data.to_csv(out_gene_data_file)
160
+
161
+ # 2) Link clinical and genetic data (use the correct variable name from Step 2)
162
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
163
+
164
+ # Optional sanity checks
165
+ print(f"Normalized gene data shape: {normalized_gene_data.shape}")
166
+ print(f"Linked data shape (before missing handling): {linked_data.shape}")
167
+
168
+ # 3) Handle missing values
169
+ linked_data = handle_missing_values(linked_data, trait)
170
+
171
+ # 4) Bias assessment and demographic pruning
172
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
173
+
174
+ # 5) Final validation and save cohort info
175
+ note = "INFO: Illumina HT-12 v4 probes mapped to gene symbols; symbols normalized to NCBI Gene preferred names."
176
+ is_usable = validate_and_save_cohort_info(
177
+ is_final=True,
178
+ cohort=cohort,
179
+ info_path=json_path,
180
+ is_gene_available=True,
181
+ is_trait_available=True,
182
+ is_biased=is_trait_biased,
183
+ df=unbiased_linked_data,
184
+ note=note
185
+ )
186
+
187
+ # 6) Save linked data if usable
188
+ if is_usable:
189
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
190
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Cystic_Fibrosis/code/GSE107846.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE107846"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE107846"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE107846.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE107846.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE107846.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/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 data availability
42
+ is_gene_available = True # Based on GEO context and lack of miRNA/methylation indication
43
+
44
+ # 2) Variable availability
45
+ trait_row = 5 # 'state: CF' vs 'state: Healthy'
46
+ age_row = 1 # 'age: <float>'
47
+ gender_row = 2 # 'Sex: F' / 'Sex: M'
48
+
49
+ # 2.2) Conversion functions
50
+ def _extract_value(x):
51
+ if x is None:
52
+ return None
53
+ s = str(x)
54
+ if ':' in s:
55
+ s = s.split(':', 1)[1]
56
+ return s.strip()
57
+
58
+ def convert_trait(x):
59
+ v = _extract_value(x)
60
+ if v is None or v == '':
61
+ return None
62
+ lv = v.lower()
63
+ # Positive (has CF) -> 1; Healthy/Control -> 0
64
+ if lv in {'cf', 'cystic fibrosis', 'cystic_fibrosis'}:
65
+ return 1
66
+ if lv in {'healthy', 'control', 'non-cf', 'non cf', 'no cf'}:
67
+ return 0
68
+ return None
69
+
70
+ def convert_age(x):
71
+ v = _extract_value(x)
72
+ if v is None or v == '':
73
+ return None
74
+ v = v.replace('years', '').replace('year', '').strip()
75
+ # Handle values like "<1"
76
+ if v.startswith('<'):
77
+ # approximate to midpoint
78
+ try:
79
+ num = float(v[1:].strip())
80
+ return max(num / 2.0, 0.5)
81
+ except Exception:
82
+ return None
83
+ try:
84
+ return float(v)
85
+ except Exception:
86
+ return None
87
+
88
+ def convert_gender(x):
89
+ v = _extract_value(x)
90
+ if v is None or v == '':
91
+ return None
92
+ lv = v.lower()
93
+ if lv in {'f', 'female', 'woman', 'girl'}:
94
+ return 0
95
+ if lv in {'m', 'male', 'man', 'boy'}:
96
+ return 1
97
+ return None
98
+
99
+ # 3) Save metadata (initial filtering)
100
+ is_trait_available = trait_row is not None
101
+ _ = validate_and_save_cohort_info(
102
+ is_final=False,
103
+ cohort=cohort,
104
+ info_path=json_path,
105
+ is_gene_available=is_gene_available,
106
+ is_trait_available=is_trait_available
107
+ )
108
+
109
+ # 4) Clinical feature extraction
110
+ if trait_row is not None:
111
+ selected_clinical_df = geo_select_clinical_features(
112
+ clinical_df=clinical_data,
113
+ trait=trait,
114
+ trait_row=trait_row,
115
+ convert_trait=convert_trait,
116
+ age_row=age_row,
117
+ convert_age=convert_age,
118
+ gender_row=gender_row,
119
+ convert_gender=convert_gender
120
+ )
121
+ preview = preview_df(selected_clinical_df)
122
+ print(preview)
123
+
124
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
125
+ selected_clinical_df.to_csv(out_clinical_data_file)
126
+
127
+ # Step 3: Gene Data Extraction
128
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
129
+ gene_data = get_genetic_data(matrix_file)
130
+
131
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
132
+ print(gene_data.index[:20])
133
+
134
+ # Step 4: Gene Identifier Review
135
+ print("requires_gene_mapping = True")
136
+
137
+ # Step 5: Gene Annotation
138
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
139
+ gene_annotation = get_gene_annotation(soft_file)
140
+
141
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
142
+ print("Gene annotation preview:")
143
+ print(preview_df(gene_annotation))
144
+
145
+ # Step 6: Gene Identifier Mapping
146
+ # Identify appropriate columns for mapping: probe IDs in 'ID', gene symbols in 'SYMBOL'
147
+ prob_col = 'ID'
148
+ gene_col = 'SYMBOL'
149
+
150
+ # 2. Build 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
+ probe_data = gene_data # preserve original probe-level data
155
+ gene_data = apply_gene_mapping(probe_data, mapping_df)
156
+
157
+ # Step 7: Data Normalization and Linking
158
+ import os
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 the clinical and genetic data
166
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
167
+
168
+ # 3. Handle missing values in the linked data
169
+ linked_data = handle_missing_values(linked_data, trait)
170
+
171
+ # 4. Determine bias and remove biased demographic features
172
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
173
+
174
+ # 5. Final validation and save cohort information
175
+ note_msg = "INFO: Mapped Illumina probe IDs to symbols; normalized gene symbols; handled missingness per protocol."
176
+ is_usable = validate_and_save_cohort_info(
177
+ True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data, note=note_msg
178
+ )
179
+
180
+ # 6. Save the usable linked data
181
+ if is_usable:
182
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
183
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Cystic_Fibrosis/code/GSE129168.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE129168"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE129168"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE129168.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE129168.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE129168.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/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
+ # Step 1: Determine data availability
43
+ is_gene_available = True # Based on series background indicating gene expression profiling, not miRNA/methylation
44
+
45
+ # Step 2: Identify rows for trait, age, gender from the Sample Characteristics Dictionary
46
+ trait_row = 2 # 'genotype' field distinguishes CF (p.Phe508del) vs WT/gene-corrected
47
+ age_row = None # No age information found
48
+ gender_row = None # No gender information found
49
+
50
+ # Step 2.2: Conversion functions
51
+ def convert_trait(x):
52
+ # Converts genotype-related strings to binary CF status: CF=1, non-CF=0
53
+ if x is None:
54
+ return None
55
+ s = str(x)
56
+ # Extract value after colon
57
+ if ':' in s:
58
+ s = s.split(':', 1)[1]
59
+ v = s.strip()
60
+ if v == '' or v.lower() in {'na', 'n/a', 'none', 'unknown'}:
61
+ return None
62
+
63
+ # Normalize common unicode and separators
64
+ v = v.replace('Δ', 'delta')
65
+ v_low = v.lower()
66
+
67
+ # If explicitly gene-corrected, treat as non-CF
68
+ if 'gene corrected' in v_low or 'corrected' in v_low:
69
+ return 0
70
+
71
+ # Tokens for safer matching
72
+ tokens = set(t for t in re.split(r'\W+', v_low) if t)
73
+
74
+ # CF mutation indicators
75
+ if (
76
+ 'f508del' in v_low or
77
+ 'p.phe508del' in v_low or
78
+ 'deltaf508' in v_low or
79
+ 'delta f508' in v_low or
80
+ 'del f508' in v_low
81
+ ):
82
+ return 1
83
+
84
+ # Explicit non-CF indicators
85
+ if 'wild type' in v_low or 'wild-type' in v_low or 'cftr wt' in v_low or 'ips cftr wt' in v_low or 'cf wt' in v_low:
86
+ return 0
87
+ if 'wt' in tokens:
88
+ return 0
89
+
90
+ return None
91
+
92
+ def convert_age(x):
93
+ # Not available in this dataset
94
+ return None
95
+
96
+ def convert_gender(x):
97
+ # Not available in this dataset
98
+ return None
99
+
100
+ # Step 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
+ # Step 4: Clinical Feature Extraction (only if trait is available)
111
+ if trait_row is not None:
112
+ selected_clinical_df = geo_select_clinical_features(
113
+ clinical_df=clinical_data,
114
+ trait=trait,
115
+ trait_row=trait_row,
116
+ convert_trait=convert_trait,
117
+ age_row=age_row,
118
+ convert_age=None,
119
+ gender_row=gender_row,
120
+ convert_gender=None
121
+ )
122
+ preview = preview_df(selected_clinical_df, n=5)
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
+ print("requires_gene_mapping = True")
136
+
137
+ # Step 5: Gene Annotation
138
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
139
+ gene_annotation = get_gene_annotation(soft_file)
140
+
141
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
142
+ print("Gene annotation preview:")
143
+ print(preview_df(gene_annotation))
144
+
145
+ # Step 6: Gene Identifier Mapping
146
+ # 1-2. Determine identifier and gene symbol columns and create mapping dataframe
147
+ probe_col = 'ID' # Matches probe IDs in gene_data index (e.g., A_23_P100001)
148
+ gene_symbol_col = 'GENE_SYMBOL' # Column containing human gene symbols
149
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_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
+ import pandas as pd
157
+
158
+ # 1. Normalize gene symbols and save
159
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
160
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
161
+ normalized_gene_data.to_csv(out_gene_data_file)
162
+
163
+ # 2. Link clinical and genetic data
164
+ # Ensure clinical dataframe is available
165
+ if 'selected_clinical_df' not in locals():
166
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
167
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
168
+
169
+ # 3. Handle missing values
170
+ linked_data = handle_missing_values(linked_data, trait)
171
+
172
+ # 4. Bias check and removal of biased covariates
173
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
174
+
175
+ # 5. Final validation and save cohort info
176
+ is_gene_available = normalized_gene_data.shape[0] > 0
177
+ is_trait_available = trait in unbiased_linked_data.columns
178
+ note = "INFO: Only trait available; Age and Gender not provided in clinical annotations."
179
+ is_usable = validate_and_save_cohort_info(
180
+ is_final=True,
181
+ cohort=cohort,
182
+ info_path=json_path,
183
+ is_gene_available=is_gene_available,
184
+ is_trait_available=is_trait_available,
185
+ is_biased=is_trait_biased,
186
+ df=unbiased_linked_data,
187
+ note=note
188
+ )
189
+
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/Cystic_Fibrosis/code/GSE139038.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE139038"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE139038"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE139038.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE139038.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE139038.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ # Determine data availability based on provided background and sample characteristics
40
+ is_gene_available = True # Gene expression microarray study (two-dye), not miRNA-only or methylation-only
41
+
42
+ # Variable availability
43
+ trait_row = None # The cohort is breast cancer-related; no Cystic Fibrosis information available
44
+ age_row = 0 # Ages are provided under key 0
45
+ gender_row = None # Only 'Female' appears under gender, so it's a constant feature and considered unavailable
46
+
47
+ # Converters
48
+ def convert_trait(x):
49
+ # No cystic fibrosis status available in this dataset
50
+ return None
51
+
52
+ def convert_age(x):
53
+ if x is None:
54
+ return None
55
+ try:
56
+ # Expect formats like 'age: 48'
57
+ val = str(x).split(':', 1)[-1].strip()
58
+ if val in {'NA', 'N/A', '', 'nan', 'None', 'Unknown', 'Not Available'}:
59
+ return None
60
+ return float(val)
61
+ except Exception:
62
+ return None
63
+
64
+ def convert_gender(x):
65
+ if x is None:
66
+ return None
67
+ try:
68
+ val = str(x).split(':', 1)[-1].strip().lower()
69
+ if val in {'female', 'f'}:
70
+ return 0
71
+ if val in {'male', 'm'}:
72
+ return 1
73
+ return None
74
+ except Exception:
75
+ return None
76
+
77
+ # Initial filtering and save metadata
78
+ is_trait_available = trait_row is not None
79
+ _ = validate_and_save_cohort_info(
80
+ is_final=False,
81
+ cohort=cohort,
82
+ info_path=json_path,
83
+ is_gene_available=is_gene_available,
84
+ is_trait_available=is_trait_available
85
+ )
86
+
87
+ # Clinical feature extraction is skipped because trait_row is None
88
+ # If trait_row were available, we would run:
89
+ # selected_clinical_df = geo_select_clinical_features(
90
+ # clinical_df=clinical_data,
91
+ # trait=trait,
92
+ # trait_row=trait_row,
93
+ # convert_trait=convert_trait,
94
+ # age_row=age_row,
95
+ # convert_age=convert_age,
96
+ # gender_row=gender_row,
97
+ # convert_gender=convert_gender
98
+ # )
99
+ # preview = preview_df(selected_clinical_df)
100
+ # selected_clinical_df.to_csv(out_clinical_data_file, index=True)
output/preprocess/Cystic_Fibrosis/code/GSE142610.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE142610"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE142610"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE142610.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE142610.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE142610.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import re
40
+ import pandas as pd
41
+
42
+ # 1) Gene expression availability
43
+ # This series profiles transcriptional responses in a CFBE cell line under various treatments/temperatures.
44
+ # It is likely standard gene expression (mRNA) data, not pure miRNA-only or methylation-only.
45
+ is_gene_available = True
46
+
47
+ # 2) Variable availability and converters
48
+ # Sample characteristics indicate a single cell line ("CFBE") and various treatments; no human subjects, no age/gender.
49
+ # Trait is constant (CFBE across all), thus not useful for association. Age/Gender not present.
50
+ trait_row = None
51
+ age_row = None
52
+ gender_row = None
53
+
54
+ def _after_colon(x: object) -> str:
55
+ if x is None or (isinstance(x, float) and pd.isna(x)):
56
+ return None
57
+ s = str(x)
58
+ if ':' in s:
59
+ s = s.split(':', 1)[1]
60
+ return s.strip()
61
+
62
+ def convert_trait(x: object) -> int:
63
+ """
64
+ Map CF status to binary: CF -> 1, non-CF -> 0.
65
+ Heuristics to handle common labels across GEO datasets.
66
+ """
67
+ s = _after_colon(x)
68
+ if s is None:
69
+ return None
70
+ sl = s.lower()
71
+ # Negative/controls first
72
+ if any(k in sl for k in ['non-cf', 'healthy', 'control', 'wildtype', 'wt', 'nhbe', 'normal']):
73
+ return 0
74
+ # Positive CF indicators
75
+ if any(k in sl for k in ['cfbe', 'cystic fibrosis', 'Δf508', 'df508', 'deltaf508', 'f508del', 'cf ']) or sl == 'cf':
76
+ return 1
77
+ return None
78
+
79
+ def convert_age(x: object) -> float:
80
+ """
81
+ Extract numeric age; returns years as float if possible.
82
+ """
83
+ s = _after_colon(x)
84
+ if s is None:
85
+ return None
86
+ sl = s.lower()
87
+ m = re.search(r'(\d+(\.\d+)?)', sl)
88
+ if not m:
89
+ return None
90
+ val = float(m.group(1))
91
+ # Unit handling
92
+ if 'month' in sl:
93
+ return round(val / 12.0, 3)
94
+ if 'day' in sl or 'd ' in sl:
95
+ return round(val / 365.0, 3)
96
+ # default assume years
97
+ return val
98
+
99
+ def convert_gender(x: object) -> int:
100
+ """
101
+ Map gender to binary: female -> 0, male -> 1.
102
+ """
103
+ s = _after_colon(x)
104
+ if s is None:
105
+ return None
106
+ sl = s.strip().lower()
107
+ if sl in ['female', 'f', 'woman', 'girl']:
108
+ return 0
109
+ if sl in ['male', 'm', 'man', 'boy']:
110
+ return 1
111
+ return None
112
+
113
+ # 3) Save metadata (initial filtering)
114
+ is_trait_available = trait_row is not None
115
+ _ = validate_and_save_cohort_info(
116
+ is_final=False,
117
+ cohort=cohort,
118
+ info_path=json_path,
119
+ is_gene_available=is_gene_available,
120
+ is_trait_available=is_trait_available
121
+ )
122
+
123
+ # 4) Clinical feature extraction (skip since no trait_row)
124
+ if trait_row is not None:
125
+ selected_clinical_df = geo_select_clinical_features(
126
+ clinical_df=clinical_data,
127
+ trait=trait,
128
+ trait_row=trait_row,
129
+ convert_trait=convert_trait,
130
+ age_row=age_row,
131
+ convert_age=convert_age,
132
+ gender_row=gender_row,
133
+ convert_gender=convert_gender
134
+ )
135
+ clinical_preview = preview_df(selected_clinical_df)
136
+ # Save clinical features
137
+ out_dir = os.path.dirname(out_clinical_data_file)
138
+ os.makedirs(out_dir, exist_ok=True)
139
+ selected_clinical_df.to_csv(out_clinical_data_file)
output/preprocess/Cystic_Fibrosis/code/GSE53543.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE53543"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE53543"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE53543.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE53543.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE53543.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import re
40
+
41
+ # 1) Gene expression data availability
42
+ is_gene_available = True # Illumina HumanHT-12 v4 Expression BeadChip indicates mRNA gene expression data
43
+
44
+ # 2) Variable availability based on the provided Sample Characteristics Dictionary
45
+ # Keys observed:
46
+ # 0: subject id
47
+ # 1: gender
48
+ # 2: sample group (Uninfected / RV_infected) - experimental condition, not the human trait
49
+ # 3: cell type (constant)
50
+ # 4: treated with (experimental condition)
51
+ trait_row = None # No cystic fibrosis status available; treat as not available
52
+ age_row = None # No age information
53
+ gender_row = 1 # Gender available
54
+
55
+ # 2.2) Converters
56
+ def _after_colon(value: str) -> str:
57
+ if value is None:
58
+ return ""
59
+ parts = str(value).split(":", 1)
60
+ return parts[1].strip() if len(parts) == 2 else str(value).strip()
61
+
62
+ def convert_trait(value):
63
+ # Binary: 1 = cystic fibrosis, 0 = non-cystic fibrosis
64
+ v = _after_colon(value).lower()
65
+ if not v:
66
+ return None
67
+ # Heuristics for CF status if ever present
68
+ # Positive indicators
69
+ pos_patterns = [
70
+ r"\bcystic fibrosis\b", r"\bcf\b", r"\bpatient\b", r"\bdisease\b\s*[:=]?\s*(cf|cystic fibrosis)",
71
+ r"\bcase\b", r"\baffected\b"
72
+ ]
73
+ # Negative indicators
74
+ neg_patterns = [
75
+ r"\bcontrol\b", r"\bhealthy\b", r"\bnon-?cf\b", r"\bno cystic fibrosis\b",
76
+ r"\bunaffected\b"
77
+ ]
78
+ if any(re.search(p, v) for p in pos_patterns):
79
+ # Exclude clear negatives overriding positives
80
+ if any(re.search(p, v) for p in neg_patterns):
81
+ return 0
82
+ return 1
83
+ if any(re.search(p, v) for p in neg_patterns):
84
+ return 0
85
+ # Explicit yes/no
86
+ if v in {"yes", "y", "true", "1"}:
87
+ return 1
88
+ if v in {"no", "n", "false", "0"}:
89
+ return 0
90
+ return None
91
+
92
+ def convert_age(value):
93
+ # Continuous age in years; extract first float-like number
94
+ v = _after_colon(value).lower()
95
+ if not v or v in {"na", "n/a", "nan", "none", "unknown", "missing"}:
96
+ return None
97
+ m = re.search(r"(-?\d+(?:\.\d+)?)", v)
98
+ if not m:
99
+ return None
100
+ try:
101
+ age = float(m.group(1))
102
+ if age < 0 or age > 120:
103
+ return None
104
+ return age
105
+ except Exception:
106
+ return None
107
+
108
+ def convert_gender(value):
109
+ # Binary: female=0, male=1
110
+ v = _after_colon(value).strip().lower()
111
+ if v in {"female", "f", "woman", "women", "girl"}:
112
+ return 0
113
+ if v in {"male", "m", "man", "men", "boy"}:
114
+ return 1
115
+ return None
116
+
117
+ # 3) Initial filtering and save metadata
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 since trait_row is None)
128
+ if is_trait_available:
129
+ selected = 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, n=5)
140
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
141
+ selected.to_csv(out_clinical_data_file)
output/preprocess/Cystic_Fibrosis/code/GSE60690.py ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE60690"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE60690"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE60690.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE60690.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE60690.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/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 # Global gene expression in RNA from LCLs (not miRNA/methylation)
41
+
42
+ # Use a relevant phenotype available in this cohort as the trait: consortium lung phenotype (continuous)
43
+ trait_row = 1
44
+ age_row = 2 # 'age of enrollment'
45
+ gender_row = 0 # 'Sex'
46
+
47
+ def _after_colon(x):
48
+ if x is None:
49
+ return None
50
+ s = str(x)
51
+ if ":" in s:
52
+ return s.split(":", 1)[1].strip()
53
+ return s.strip()
54
+
55
+ def convert_trait(x):
56
+ # Convert "consortium lung phenotype: <value>" to float
57
+ v = _after_colon(x)
58
+ if v is None or v == "" or v.lower() in {"na", "n/a", "unknown", "unk"}:
59
+ return None
60
+ try:
61
+ return float(v)
62
+ except Exception:
63
+ import re
64
+ m = re.search(r"[-+]?\d*\.?\d+", v)
65
+ if m:
66
+ try:
67
+ return float(m.group(0))
68
+ except Exception:
69
+ return None
70
+ return None
71
+
72
+ def convert_age(x):
73
+ v = _after_colon(x)
74
+ if v is None or v == "" or v.lower() in {"na", "n/a", "unknown", "unk"}:
75
+ return None
76
+ try:
77
+ return float(v)
78
+ except Exception:
79
+ # Handle possible units or text; extract leading numeric token
80
+ import re
81
+ m = re.search(r"[-+]?\d*\.?\d+", v)
82
+ if m:
83
+ try:
84
+ return float(m.group(0))
85
+ except Exception:
86
+ return None
87
+ return None
88
+
89
+ def convert_gender(x):
90
+ v = _after_colon(x)
91
+ if v is None or v == "":
92
+ return None
93
+ vlow = v.lower()
94
+ if vlow in {"female", "f", "0"}:
95
+ return 0
96
+ if vlow in {"male", "m", "1"}:
97
+ return 1
98
+ if vlow in {"na", "n/a", "unknown", "unk"}:
99
+ return None
100
+ return None
101
+
102
+ # Initial filtering metadata save
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
+ # Clinical feature extraction since trait is available
113
+ import os
114
+
115
+ selected_clinical_df = geo_select_clinical_features(
116
+ clinical_df=clinical_data,
117
+ trait=trait,
118
+ trait_row=trait_row,
119
+ convert_trait=convert_trait,
120
+ age_row=age_row,
121
+ convert_age=convert_age,
122
+ gender_row=gender_row,
123
+ convert_gender=convert_gender
124
+ )
125
+ preview = preview_df(selected_clinical_df, n=5)
126
+
127
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
128
+ selected_clinical_df.to_csv(out_clinical_data_file)
129
+
130
+ # Step 3: Gene Data Extraction
131
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
132
+ gene_data = get_genetic_data(matrix_file)
133
+
134
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
135
+ print(gene_data.index[:20])
136
+
137
+ # Step 4: Gene Identifier Review
138
+ print("requires_gene_mapping = True")
139
+
140
+ # Step 5: Gene Annotation
141
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
142
+ gene_annotation = get_gene_annotation(soft_file)
143
+
144
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
145
+ print("Gene annotation preview:")
146
+ print(preview_df(gene_annotation))
147
+
148
+ # Step 6: Gene Identifier Mapping
149
+ # 1-2. Decide mapping columns and build mapping dataframe
150
+ # Probe IDs match the 'ID' column; gene symbols can be parsed from 'gene_assignment'.
151
+ probe_col = 'ID'
152
+ gene_symbol_col = 'gene_assignment'
153
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
154
+
155
+ # 3. Apply mapping to convert probe-level data to gene-level expression
156
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
157
+
158
+ # Optionally save the processed gene expression data
159
+ import os
160
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
161
+ gene_data.to_csv(out_gene_data_file)
162
+
163
+ # Step 7: Data Normalization and Linking
164
+ import os
165
+
166
+ # 1. Normalize gene symbols and save
167
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
168
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
169
+ normalized_gene_data.to_csv(out_gene_data_file)
170
+
171
+ # 2. Link clinical and genetic data (fix variable name)
172
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
173
+
174
+ # 3. Handle missing values
175
+ linked_data = handle_missing_values(linked_data, trait)
176
+
177
+ # 4. Assess bias and drop biased demographics
178
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
179
+
180
+ # 5. Final validation and save cohort info
181
+ note = ("INFO: Trait is 'consortium lung phenotype' (continuous). Age is 'age of enrollment'; "
182
+ "Gender from 'Sex'. Platform required probe->gene mapping; gene symbols normalized by NCBI synonyms.")
183
+ is_usable = validate_and_save_cohort_info(
184
+ is_final=True,
185
+ cohort=cohort,
186
+ info_path=json_path,
187
+ is_gene_available=True,
188
+ is_trait_available=True,
189
+ is_biased=is_trait_biased,
190
+ df=unbiased_linked_data,
191
+ note=note
192
+ )
193
+
194
+ # 6. Save linked data if usable
195
+ if is_usable:
196
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
197
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Cystic_Fibrosis/code/GSE67698.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE67698"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE67698"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE67698.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE67698.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE67698.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+
42
+ # 1) Gene expression availability
43
+ is_gene_available = True # Two-color transcriptional profiling (mRNA), not miRNA/methylation
44
+
45
+ # 2) Variable availability and converters
46
+ # Based on the sample characteristics dictionary:
47
+ # {0: ['cell line: polarized CFBE41o-cell line'],
48
+ # 1: ['transduction: TranzVector lentivectors containing deltaF508 CFTR (CFBE41o-deltaF508CFTR)',
49
+ # 'transduction: TranzVector lentivectors containing wildtype CFTR (CFBE41o-CFTR)']}
50
+ trait_row = 1
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
+ return s.split(':', 1)[1].strip() if ':' in s else s.strip()
59
+
60
+ def convert_trait(x):
61
+ # Map CF (deltaF508 mutation) -> 1, wildtype -> 0
62
+ v = _extract_value(x)
63
+ if v is None:
64
+ return None
65
+ vlo = v.lower()
66
+ # Detect deltaF508 / F508del variants (including unicode delta)
67
+ if ('deltaf508' in vlo) or ('f508del' in vlo) or ('df508' in vlo) or ('del f508' in vlo) or ('Δf508' in v) or ('∆f508' in v):
68
+ return 1
69
+ # Detect wildtype/WT
70
+ if ('wildtype' in vlo) or (re.search(r'\bwt\b', vlo) is not None):
71
+ return 0
72
+ return None
73
+
74
+ def convert_age(x):
75
+ v = _extract_value(x)
76
+ if v is None:
77
+ return None
78
+ m = re.search(r'(-?\d+(\.\d+)?)', v)
79
+ return float(m.group(1)) if m else None
80
+
81
+ def convert_gender(x):
82
+ v = _extract_value(x)
83
+ if v is None:
84
+ return None
85
+ vlo = v.lower()
86
+ if vlo in {'female', 'f', 'woman', 'women'}:
87
+ return 0
88
+ if vlo in {'male', 'm', 'man', 'men'}:
89
+ return 1
90
+ # Handle encoded forms
91
+ if 'female' in vlo:
92
+ return 0
93
+ if 'male' in vlo:
94
+ return 1
95
+ return None
96
+
97
+ # 3) Save initial metadata
98
+ is_trait_available = trait_row is not None
99
+ _ = validate_and_save_cohort_info(
100
+ is_final=False,
101
+ cohort=cohort,
102
+ info_path=json_path,
103
+ is_gene_available=is_gene_available,
104
+ is_trait_available=is_trait_available
105
+ )
106
+
107
+ # 4) Clinical feature extraction (only if trait data is available)
108
+ if is_trait_available:
109
+ selected_clinical_df = geo_select_clinical_features(
110
+ clinical_df=clinical_data,
111
+ trait=trait,
112
+ trait_row=trait_row,
113
+ convert_trait=convert_trait,
114
+ age_row=age_row,
115
+ convert_age=convert_age if age_row is not None else None,
116
+ gender_row=gender_row,
117
+ convert_gender=convert_gender if gender_row is not None else None
118
+ )
119
+ preview = preview_df(selected_clinical_df)
120
+ print(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
+ 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
+ # Decide columns for probe IDs and gene symbols based on annotation preview
146
+ probe_col = 'ID'
147
+ gene_symbol_col = 'GENE_SYMBOL'
148
+
149
+ # 2) Build mapping dataframe from annotation
150
+ gene_mapping = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
151
+
152
+ # 3) Apply mapping to convert probe-level data to gene-level expression
153
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=gene_mapping)
154
+
155
+ # Step 7: Data Normalization and Linking
156
+ import os
157
+ import pandas as pd
158
+
159
+ # 1) Normalize gene symbols and save gene expression data
160
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
161
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
162
+ normalized_gene_data.to_csv(out_gene_data_file)
163
+
164
+ # 2) Link clinical and genetic data
165
+ try:
166
+ selected_clinical_df
167
+ except NameError:
168
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
169
+
170
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
171
+
172
+ # 3) Handle missing values
173
+ linked_data = handle_missing_values(linked_data, trait)
174
+
175
+ # 4) Bias check on trait and demographics
176
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
177
+
178
+ # 5) Final validation and save cohort info (ensure native Python types for JSON)
179
+ is_gene_available_flag = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
180
+ if trait in selected_clinical_df.index:
181
+ trait_series = selected_clinical_df.loc[trait]
182
+ is_trait_available_flag = bool(pd.Series(trait_series).notna().any())
183
+ else:
184
+ is_trait_available_flag = False
185
+
186
+ # Sanitize df to avoid numpy types in metadata
187
+ df_for_meta = unbiased_linked_data.copy()
188
+ df_for_meta.columns = list(df_for_meta.columns)
189
+
190
+ note = "INFO: Trait inferred from CFTR status in CFBE41o cell lines; two-color microarray; in vitro dataset."
191
+ is_usable = validate_and_save_cohort_info(
192
+ is_final=True,
193
+ cohort=cohort,
194
+ info_path=json_path,
195
+ is_gene_available=is_gene_available_flag,
196
+ is_trait_available=is_trait_available_flag,
197
+ is_biased=bool(is_trait_biased),
198
+ df=df_for_meta,
199
+ note=note
200
+ )
201
+
202
+ # 6) Save linked data if usable
203
+ if is_usable:
204
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
205
+ df_for_meta.to_csv(out_data_file)
output/preprocess/Cystic_Fibrosis/code/GSE71799.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE71799"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE71799"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE71799.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE71799.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE71799.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/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
+ import pandas as pd
43
+
44
+ # 1) Gene expression availability
45
+ is_gene_available = True # Gene expression analysis was performed (not miRNA/methylation only)
46
+
47
+ # 2) Variable availability and converters
48
+ # Based on the provided sample characteristics dictionary, no usable keys for trait/age/gender were found.
49
+ trait_row = None
50
+ age_row = None
51
+ gender_row = None
52
+
53
+ def _extract_after_colon(x: Any) -> str:
54
+ if x is None or (isinstance(x, float) and pd.isna(x)):
55
+ return ''
56
+ s = str(x).strip()
57
+ # Take the part after the last colon if present
58
+ if ':' in s:
59
+ s = s.split(':')[-1].strip()
60
+ return s
61
+
62
+ def convert_trait(x: Any) -> Optional[int]:
63
+ """
64
+ Binary: 1 = cystic fibrosis, 0 = healthy control.
65
+ Heuristics map common labels (e.g., 'CF', 'cystic fibrosis', 'uHC', 'control', 'healthy').
66
+ """
67
+ s = _extract_after_colon(x).lower()
68
+ if not s:
69
+ return None
70
+ # Positive (CF) indicators
71
+ if any(k in s for k in ['cystic fibrosis', ' cf ', ' cf', 'cf ', 'c.f.', 'cystic-fibrosis']):
72
+ return 1
73
+ if any(k in s for k in ['patient', 'case']) and 'control' not in s:
74
+ return 1
75
+ # Negative (control) indicators
76
+ if any(k in s for k in ['healthy', 'control', 'uhc', 'unrelated healthy control']):
77
+ return 0
78
+ return None
79
+
80
+ def convert_age(x: Any) -> Optional[float]:
81
+ """
82
+ Continuous: extract numeric age in years if present.
83
+ """
84
+ s = _extract_after_colon(x).lower()
85
+ if not s or s in {'na', 'n/a', 'nan', 'none', 'unknown', 'unk'}:
86
+ return None
87
+ m = re.search(r'[-+]?\d*\.?\d+', s)
88
+ if m:
89
+ try:
90
+ return float(m.group())
91
+ except ValueError:
92
+ return None
93
+ return None
94
+
95
+ def convert_gender(x: Any) -> Optional[int]:
96
+ """
97
+ Binary: female=0, male=1.
98
+ """
99
+ s = _extract_after_colon(x).lower()
100
+ if not s:
101
+ return None
102
+ if s in {'male', 'm', 'man', 'boy'}:
103
+ return 1
104
+ if s in {'female', 'f', 'woman', 'girl'}:
105
+ return 0
106
+ if 'male' in s and 'fe' not in s:
107
+ return 1
108
+ if 'female' in s:
109
+ return 0
110
+ return None
111
+
112
+ # 3) Save metadata with initial filtering
113
+ is_trait_available = trait_row is not None
114
+ _ = validate_and_save_cohort_info(
115
+ is_final=False,
116
+ cohort=cohort,
117
+ info_path=json_path,
118
+ is_gene_available=is_gene_available,
119
+ is_trait_available=is_trait_available
120
+ )
121
+
122
+ # 4) Clinical feature extraction (skip because trait_row is None)
123
+ if trait_row is not None:
124
+ selected_clinical_df = geo_select_clinical_features(
125
+ clinical_df=clinical_data,
126
+ trait=trait,
127
+ trait_row=trait_row,
128
+ convert_trait=convert_trait,
129
+ age_row=age_row,
130
+ convert_age=convert_age,
131
+ gender_row=gender_row,
132
+ convert_gender=convert_gender
133
+ )
134
+ _ = preview_df(selected_clinical_df)
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
+ # 1-2. Identify relevant columns and create the mapping dataframe
158
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
159
+
160
+ # 3. Apply mapping to convert probe-level data to gene-level expression
161
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
162
+
163
+ # Step 7: Data Normalization and Linking
164
+ import os
165
+
166
+ # 1. Normalize gene symbols and save gene expression data
167
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
168
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
169
+ normalized_gene_data.to_csv(out_gene_data_file)
170
+
171
+ # Determine availability of clinical trait data from previous steps
172
+ try:
173
+ trait_row
174
+ except NameError:
175
+ trait_row = None
176
+ try:
177
+ age_row
178
+ except NameError:
179
+ age_row = None
180
+ try:
181
+ gender_row
182
+ except NameError:
183
+ gender_row = None
184
+
185
+ # 2-6. Branch depending on clinical availability
186
+ linked_data = None
187
+ is_trait_available = trait_row is not None
188
+
189
+ if is_trait_available:
190
+ # Recompute clinical features to ensure availability in this step
191
+ selected_clinical_data = geo_select_clinical_features(
192
+ clinical_df=clinical_data,
193
+ trait=trait,
194
+ trait_row=trait_row,
195
+ convert_trait=convert_trait,
196
+ age_row=age_row,
197
+ convert_age=convert_age,
198
+ gender_row=gender_row,
199
+ convert_gender=convert_gender
200
+ )
201
+ # Optionally save clinical features for traceability
202
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
203
+ selected_clinical_data.to_csv(out_clinical_data_file)
204
+
205
+ # Link clinical and genetic data
206
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
207
+
208
+ # 3. Handle missing values
209
+ linked_data = handle_missing_values(linked_data, trait)
210
+
211
+ # 4. Assess bias and remove biased demographics
212
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
213
+
214
+ # 5. Final validation and metadata saving
215
+ is_usable = validate_and_save_cohort_info(
216
+ is_final=True,
217
+ cohort=cohort,
218
+ info_path=json_path,
219
+ is_gene_available=True,
220
+ is_trait_available=True,
221
+ is_biased=is_trait_biased,
222
+ df=unbiased_linked_data,
223
+ note="INFO: Linked clinical-genetic dataset generated."
224
+ )
225
+
226
+ # 6. Save linked data if usable
227
+ if is_usable:
228
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
229
+ unbiased_linked_data.to_csv(out_data_file)
230
+ else:
231
+ # Clinical trait unavailable: skip linking and downstream steps
232
+ # Still record final metadata correctly with trait unavailable
233
+ is_usable = validate_and_save_cohort_info(
234
+ is_final=True,
235
+ cohort=cohort,
236
+ info_path=json_path,
237
+ is_gene_available=True,
238
+ is_trait_available=False,
239
+ is_biased=False, # Ignored since is_available will be False
240
+ df=normalized_gene_data,
241
+ note="INFO: Trait/clinical features unavailable; saved normalized gene expression only."
242
+ )
output/preprocess/Cystic_Fibrosis/code/GSE76347.py ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+ cohort = "GSE76347"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Cystic_Fibrosis"
10
+ in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE76347"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/GSE76347.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/GSE76347.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/GSE76347.csv"
16
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import re
40
+ import os
41
+
42
+ # 1) Gene expression data availability
43
+ is_gene_available = True # Microarray gene expression in nasal epithelial cells per summary
44
+
45
+ # 2) Variable availability and converters
46
+
47
+ # From the provided sample characteristics:
48
+ # 0: disease state: CF (constant -> not useful for association; treat as unavailable)
49
+ # No explicit age or gender fields present.
50
+ trait_row = None
51
+ age_row = None
52
+ gender_row = None
53
+
54
+ def _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) > 1 else str(x).strip()
59
+
60
+ def convert_trait(x):
61
+ # Binary: CF (1) vs non-CF/controls (0)
62
+ val = _after_colon(x).lower()
63
+ if val in ("", "na", "n/a", "none", "unknown"):
64
+ return None
65
+ if "cystic fibrosis" in val or val == "cf":
66
+ return 1
67
+ if "control" in val or "healthy" in val or "non-cf" in val:
68
+ return 0
69
+ return None
70
+
71
+ def convert_age(x):
72
+ # Continuous (years). Extract first number.
73
+ val = _after_colon(x).lower()
74
+ if val in ("", "na", "n/a", "none", "unknown"):
75
+ return None
76
+ m = re.search(r"(-?\d+\.?\d*)", val)
77
+ if m:
78
+ try:
79
+ return float(m.group(1))
80
+ except:
81
+ return None
82
+ return None
83
+
84
+ def convert_gender(x):
85
+ # Binary: female -> 0, male -> 1
86
+ val = _after_colon(x).lower()
87
+ if val in ("", "na", "n/a", "none", "unknown"):
88
+ return None
89
+ if val in ("female", "f", "woman", "women"):
90
+ return 0
91
+ if val in ("male", "m", "man", "men"):
92
+ return 1
93
+ return None
94
+
95
+ # 3) Save metadata (initial filtering)
96
+ is_trait_available = trait_row is not None
97
+ _ = validate_and_save_cohort_info(
98
+ is_final=False,
99
+ cohort=cohort,
100
+ info_path=json_path,
101
+ is_gene_available=is_gene_available,
102
+ is_trait_available=is_trait_available
103
+ )
104
+
105
+ # 4) Clinical feature extraction (skip because trait_row is None)
106
+ if trait_row is not None:
107
+ selected_clinical_df = geo_select_clinical_features(
108
+ clinical_df=clinical_data,
109
+ trait=trait,
110
+ trait_row=trait_row,
111
+ convert_trait=convert_trait,
112
+ age_row=age_row,
113
+ convert_age=convert_age,
114
+ gender_row=gender_row,
115
+ convert_gender=convert_gender
116
+ )
117
+ print(preview_df(selected_clinical_df))
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
+ print("requires_gene_mapping = True")
130
+
131
+ # Step 5: Gene Annotation
132
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
133
+ gene_annotation = get_gene_annotation(soft_file)
134
+
135
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
136
+ print("Gene annotation preview:")
137
+ print(preview_df(gene_annotation))
138
+
139
+ # Step 6: Gene Identifier Mapping
140
+ # Decide annotation columns:
141
+ # - Probe/identifier column matches expression IDs: 'ID'
142
+ # - Gene symbol information is embedded in: 'gene_assignment'
143
+ probe_col = 'ID'
144
+ gene_symbol_col = 'gene_assignment'
145
+
146
+ # 2) Build mapping dataframe
147
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
148
+
149
+ # 3) Apply mapping to convert probe-level to gene-level expression
150
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
151
+
152
+ # Step 7: Data Normalization and Linking
153
+ import os
154
+ import pandas as pd
155
+
156
+ # 1) Normalize gene symbols and save gene expression data
157
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
158
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
159
+ normalized_gene_data.to_csv(out_gene_data_file)
160
+
161
+ # Determine trait availability based on previous step's decision
162
+ trait_available = ('trait_row' in globals()) and (trait_row is not None)
163
+
164
+ if trait_available:
165
+ # Reconstruct clinical features deterministically
166
+ selected_clinical_data = geo_select_clinical_features(
167
+ clinical_df=clinical_data,
168
+ trait=trait,
169
+ trait_row=trait_row,
170
+ convert_trait=convert_trait,
171
+ age_row=age_row,
172
+ convert_age=convert_age,
173
+ gender_row=gender_row,
174
+ convert_gender=convert_gender
175
+ )
176
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
177
+ selected_clinical_data.to_csv(out_clinical_data_file)
178
+
179
+ # 2) Link clinical and genetic data
180
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
181
+
182
+ # 3) Handle missing values
183
+ linked_data = handle_missing_values(linked_data, trait)
184
+
185
+ # 4) Bias checks and remove biased demographic features if any
186
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
187
+
188
+ # 5) Final validation and save cohort info
189
+ is_usable = validate_and_save_cohort_info(
190
+ is_final=True,
191
+ cohort=cohort,
192
+ info_path=json_path,
193
+ is_gene_available=True,
194
+ is_trait_available=True,
195
+ is_biased=is_trait_biased,
196
+ df=unbiased_linked_data,
197
+ note="INFO: Linked gene and clinical data; completed preprocessing."
198
+ )
199
+
200
+ # 6) Save linked dataset 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)
204
+ else:
205
+ # Trait not available: perform final metadata save without triggering abnormality override
206
+ # Use a minimal non-empty placeholder dataframe to avoid the override in validate_and_save_cohort_info
207
+ placeholder_df = normalized_gene_data.T.iloc[:1, :5] # 1 sample x 5 genes
208
+
209
+ _ = validate_and_save_cohort_info(
210
+ is_final=True,
211
+ cohort=cohort,
212
+ info_path=json_path,
213
+ is_gene_available=True,
214
+ is_trait_available=False,
215
+ is_biased=False, # Ignored since is_available will be False
216
+ df=placeholder_df,
217
+ note="WARNING: Trait not available; clinical-genetic linking skipped. Gene data saved."
218
+ )
output/preprocess/Cystic_Fibrosis/code/TCGA.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Cystic_Fibrosis"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/z2/preprocess/Cystic_Fibrosis/TCGA.csv"
12
+ out_gene_data_file = "./output/z2/preprocess/Cystic_Fibrosis/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/z2/preprocess/Cystic_Fibrosis/clinical_data/TCGA.csv"
14
+ json_path = "./output/z2/preprocess/Cystic_Fibrosis/cohort_info.json"
15
+
16
+
17
+ # Step 1: Initial Data Loading
18
+ import os
19
+ import pandas as pd
20
+
21
+ # List subdirectories under TCGA root
22
+ subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
23
+
24
+ # Try to find a cohort matching Cystic Fibrosis (CF). TCGA is cancer-focused; CF is not a cancer.
25
+ # Only match strict synonyms to avoid inappropriate selection.
26
+ keywords = ["cystic fibrosis", "mucoviscidosis", "cf"]
27
+ matched_dirs = []
28
+ for d in subdirs:
29
+ name_l = d.lower()
30
+ if any(k in name_l for k in keywords):
31
+ matched_dirs.append(d)
32
+
33
+ if len(matched_dirs) == 0:
34
+ # No suitable cohort found; record and skip this trait for TCGA
35
+ _ = validate_and_save_cohort_info(
36
+ is_final=False,
37
+ cohort="TCGA",
38
+ info_path=json_path,
39
+ is_gene_available=False,
40
+ is_trait_available=False
41
+ )
42
+ clinical_df = None
43
+ genetic_df = None
44
+ else:
45
+ # If multiple matches, choose the most specific (longest name as proxy)
46
+ selected_dir = sorted(matched_dirs, key=len, reverse=True)[0]
47
+ cohort_dir = os.path.join(tcga_root_dir, selected_dir)
48
+
49
+ # Locate clinical and genetic file paths
50
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
51
+
52
+ # Load dataframes
53
+ clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False, compression='infer')
54
+ genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False, compression='infer')
55
+
56
+ # Print clinical columns
57
+ print(clinical_df.columns.tolist())
output/preprocess/Cystic_Fibrosis/cohort_info.json CHANGED
@@ -1,112 +1 @@
1
- {
2
- "GSE76347": {
3
- "is_usable": false,
4
- "is_gene_available": true,
5
- "is_trait_available": true,
6
- "is_available": true,
7
- "is_biased": true,
8
- "has_age": false,
9
- "has_gender": false,
10
- "sample_size": 46
11
- },
12
- "GSE71799": {
13
- "is_usable": true,
14
- "is_gene_available": true,
15
- "is_trait_available": true,
16
- "is_available": true,
17
- "is_biased": false,
18
- "has_age": false,
19
- "has_gender": false,
20
- "sample_size": 134
21
- },
22
- "GSE67698": {
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": false,
29
- "has_gender": false,
30
- "sample_size": 122
31
- },
32
- "GSE60690": {
33
- "is_usable": false,
34
- "is_gene_available": false,
35
- "is_trait_available": false,
36
- "is_available": false,
37
- "is_biased": null,
38
- "has_age": null,
39
- "has_gender": null,
40
- "sample_size": null
41
- },
42
- "GSE53543": {
43
- "is_usable": false,
44
- "is_gene_available": true,
45
- "is_trait_available": false,
46
- "is_available": false,
47
- "is_biased": null,
48
- "has_age": null,
49
- "has_gender": null,
50
- "sample_size": null
51
- },
52
- "GSE142610": {
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": 60
61
- },
62
- "GSE139038": {
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": true,
69
- "has_gender": false,
70
- "sample_size": 65
71
- },
72
- "GSE129168": {
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
- "GSE107846": {
83
- "is_usable": true,
84
- "is_gene_available": true,
85
- "is_trait_available": true,
86
- "is_available": true,
87
- "is_biased": false,
88
- "has_age": true,
89
- "has_gender": true,
90
- "sample_size": 40
91
- },
92
- "GSE100521": {
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": false,
104
- "is_gene_available": false,
105
- "is_trait_available": false,
106
- "is_available": false,
107
- "is_biased": null,
108
- "has_age": null,
109
- "has_gender": null,
110
- "sample_size": null
111
- }
112
- }
 
1
+ {"GSE76347": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "WARNING: Trait not available; clinical-genetic linking skipped. Gene data saved."}, "GSE71799": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "INFO: Trait/clinical features unavailable; saved normalized gene expression only."}, "GSE67698": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": false, "has_gender": false, "sample_size": 122, "note": "INFO: Trait inferred from CFTR status in CFBE41o cell lines; two-color microarray; in vitro dataset."}, "GSE60690": {"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": 754, "note": "INFO: Trait is 'consortium lung phenotype' (continuous). Age is 'age of enrollment'; Gender from 'Sex'. Platform required probe->gene mapping; gene symbols normalized by NCBI synonyms."}, "GSE53543": {"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}, "GSE142610": {"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}, "GSE139038": {"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}, "GSE129168": {"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: Only trait available; Age and Gender not provided in clinical annotations."}, "GSE107846": {"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": 40, "note": "INFO: Mapped Illumina probe IDs to symbols; normalized gene symbols; handled missingness per protocol."}, "GSE100521": {"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": 72, "note": "INFO: Illumina HT-12 v4 probes mapped to gene symbols; symbols normalized to NCBI Gene preferred names."}, "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/Depression/GSE110298.csv CHANGED
The diff for this file is too large to render. See raw diff
 
output/preprocess/Depression/GSE99725.csv CHANGED
The diff for this file is too large to render. See raw diff
 
output/preprocess/Depression/clinical_data/GSE110298.csv CHANGED
@@ -1,4 +1,4 @@
1
  ,GSM2985507,GSM2985508,GSM2985509,GSM2985510,GSM2985511,GSM2985512,GSM2985513,GSM2985514,GSM2985515,GSM2985516,GSM2985517,GSM2985518,GSM2985519,GSM2985520,GSM2985521,GSM2985522,GSM2985523,GSM2985524,GSM2985525,GSM2985526,GSM2985527,GSM2985528,GSM2985529,GSM2985530,GSM2985531,GSM2985532,GSM2985533,GSM2985534,GSM2985535,GSM2985536,GSM2985537,GSM2985538,GSM2985539,GSM2985540
2
- Depression,0.0,0.0,1.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,1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0
3
  Age,89.0,95.0,84.0,76.0,86.0,96.0,80.0,101.0,85.0,92.0,92.0,78.0,85.0,86.0,88.0,89.0,81.0,91.0,89.0,88.0,99.0,89.0,92.0,80.0,86.0,81.0,89.0,92.0,85.0,79.0,93.0,76.0,87.0,95.0
4
  Gender,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0
 
1
  ,GSM2985507,GSM2985508,GSM2985509,GSM2985510,GSM2985511,GSM2985512,GSM2985513,GSM2985514,GSM2985515,GSM2985516,GSM2985517,GSM2985518,GSM2985519,GSM2985520,GSM2985521,GSM2985522,GSM2985523,GSM2985524,GSM2985525,GSM2985526,GSM2985527,GSM2985528,GSM2985529,GSM2985530,GSM2985531,GSM2985532,GSM2985533,GSM2985534,GSM2985535,GSM2985536,GSM2985537,GSM2985538,GSM2985539,GSM2985540
2
+ Depression,0.0,0.0,2.0,0.0,0.0,2.0,8.0,1.0,1.0,2.0,3.0,0.0,0.0,4.0,0.0,0.0,1.0,0.0,0.0,1.0,3.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,3.0,1.0,3.0,1.0,0.0
3
  Age,89.0,95.0,84.0,76.0,86.0,96.0,80.0,101.0,85.0,92.0,92.0,78.0,85.0,86.0,88.0,89.0,81.0,91.0,89.0,88.0,99.0,89.0,92.0,80.0,86.0,81.0,89.0,92.0,85.0,79.0,93.0,76.0,87.0,95.0
4
  Gender,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0
output/preprocess/Depression/clinical_data/GSE201332.csv CHANGED
@@ -1,4 +1,4 @@
1
- """GSM6058641""","""GSM6058642""","""GSM6058643""","""GSM6058644""","""GSM6058645""","""GSM6058646""","""GSM6058647""","""GSM6058648""","""GSM6058649""","""GSM6058650""","""GSM6058651""","""GSM6058652""","""GSM6058653""","""GSM6058654""","""GSM6058655""","""GSM6058656""","""GSM6058657""","""GSM6058658""","""GSM6058659""","""GSM6058660""","""GSM6058661""","""GSM6058662""","""GSM6058663""","""GSM6058664""","""GSM6058665""","""GSM6058666""","""GSM6058667""","""GSM6058668""","""GSM6058669""","""GSM6058670""","""GSM6058671""","""GSM6058672""","""GSM6058673""","""GSM6058674""","""GSM6058675""","""GSM6058676""","""GSM6058677""","""GSM6058678""","""GSM6058679""","""GSM6058680"""
2
- 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
- 48.0,33.0,43.0,24.0,24.0,45.0,36.0,59.0,51.0,51.0,26.0,25.0,24.0,26.0,43.0,32.0,32.0,39.0,41.0,43.0,52.0,24.0,43.0,43.0,53.0,44.0,22.0,36.0,32.0,45.0,47.0,25.0,54.0,47.0,25.0,28.0,52.0,33.0,30.0,51.0
4
- 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,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0
 
1
+ ,GSM6058641,GSM6058642,GSM6058643,GSM6058644,GSM6058645,GSM6058646,GSM6058647,GSM6058648,GSM6058649,GSM6058650,GSM6058651,GSM6058652,GSM6058653,GSM6058654,GSM6058655,GSM6058656,GSM6058657,GSM6058658,GSM6058659,GSM6058660,GSM6058661,GSM6058662,GSM6058663,GSM6058664,GSM6058665,GSM6058666,GSM6058667,GSM6058668,GSM6058669,GSM6058670,GSM6058671,GSM6058672,GSM6058673,GSM6058674,GSM6058675,GSM6058676,GSM6058677,GSM6058678,GSM6058679,GSM6058680
2
+ Depression,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
+ Age,48.0,33.0,43.0,24.0,24.0,45.0,36.0,59.0,51.0,51.0,26.0,25.0,24.0,26.0,43.0,32.0,32.0,39.0,41.0,43.0,52.0,24.0,43.0,43.0,53.0,44.0,22.0,36.0,32.0,45.0,47.0,25.0,54.0,47.0,25.0,28.0,52.0,33.0,30.0,51.0
4
+ Gender,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,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0
output/preprocess/Depression/code/GSE110298.py ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE110298"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE110298"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE110298.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE110298.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE110298.csv"
16
+ json_path = "./output/z2/preprocess/Depression/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
+ import pandas as pd
42
+
43
+ # 1) Gene expression data availability (based on series summary: hippocampal gene expression microarrays)
44
+ is_gene_available = True
45
+
46
+ # 2) Identify rows in the Sample Characteristics Dictionary
47
+ trait_row = 6 # 'depression: ...'
48
+ age_row = 2 # 'age: ...'
49
+ gender_row = 1 # 'sex (self-reported): ...'
50
+
51
+ # 2.2) Converters
52
+ def _after_colon(x: str) -> str:
53
+ if x is None or (isinstance(x, float) and math.isnan(x)):
54
+ return ''
55
+ # Use the last segment after colon to handle fields with multiple colons in other keys
56
+ parts = str(x).split(':')
57
+ return parts[-1].strip() if len(parts) >= 2 else str(x).strip()
58
+
59
+ def _to_number(val: str):
60
+ try:
61
+ if val == '' or val.lower() in {'na', 'n/a', 'nan', 'none', 'null', 'missing', '.'}:
62
+ return None
63
+ # Prefer int if it looks like int
64
+ f = float(val)
65
+ if f.is_integer():
66
+ return int(f)
67
+ return f
68
+ except Exception:
69
+ return None
70
+
71
+ # Trait is continuous (depressive symptom count/score)
72
+ def convert_trait(x):
73
+ val = _after_colon(x)
74
+ return _to_number(val)
75
+
76
+ # Age is continuous
77
+ def convert_age(x):
78
+ val = _after_colon(x)
79
+ return _to_number(val)
80
+
81
+ # Gender is binary: female -> 0, male -> 1
82
+ def convert_gender(x):
83
+ val = _after_colon(x).lower()
84
+ if val in {'female', 'f', 'woman', 'women'}:
85
+ return 0
86
+ if val in {'male', 'm', 'man', 'men'}:
87
+ return 1
88
+ return None
89
+
90
+ # 3) Save initial metadata
91
+ is_trait_available = trait_row is not None
92
+ _ = validate_and_save_cohort_info(
93
+ is_final=False,
94
+ cohort=cohort,
95
+ info_path=json_path,
96
+ is_gene_available=is_gene_available,
97
+ is_trait_available=is_trait_available
98
+ )
99
+
100
+ # 4) Clinical Feature Extraction (only if trait_row is available)
101
+ if trait_row is not None:
102
+ selected_clinical_df = geo_select_clinical_features(
103
+ clinical_df=clinical_data,
104
+ trait=trait,
105
+ trait_row=trait_row,
106
+ convert_trait=convert_trait,
107
+ age_row=age_row,
108
+ convert_age=convert_age,
109
+ gender_row=gender_row,
110
+ convert_gender=convert_gender
111
+ )
112
+ # Preview and save
113
+ preview = preview_df(selected_clinical_df, n=5)
114
+ print("Selected clinical features preview:", preview)
115
+
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
+ # Affymetrix probe set IDs detected (e.g., '1007_s_at'); mapping to gene symbols is required
128
+ requires_gene_mapping = True
129
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
130
+
131
+ # Step 5: Gene Annotation
132
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
133
+ gene_annotation = get_gene_annotation(soft_file)
134
+
135
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
136
+ print("Gene annotation preview:")
137
+ print(preview_df(gene_annotation))
138
+
139
+ # Step 6: Gene Identifier Mapping
140
+ # Ensure required dataframes are available from previous steps
141
+ try:
142
+ gene_annotation
143
+ except NameError:
144
+ gene_annotation = get_gene_annotation(soft_file)
145
+
146
+ try:
147
+ gene_data
148
+ except NameError:
149
+ gene_data = get_genetic_data(matrix_file)
150
+
151
+ # 1-2) Build mapping from probe IDs to gene symbols
152
+ # Probe ID column: 'ID'; Gene symbol column: 'Gene Symbol'
153
+ gene_mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
154
+
155
+ # 3) Apply mapping to convert probe-level data to gene-level expression
156
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=gene_mapping_df)
157
+
158
+ # Step 7: Data Normalization and Linking
159
+ import os
160
+ import pandas as pd
161
+
162
+ # 1. Normalize gene symbols and save
163
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
164
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
165
+ normalized_gene_data.to_csv(out_gene_data_file)
166
+
167
+ # 2. Link clinical and genetic data
168
+ # Use the correctly named clinical dataframe; if missing (e.g., new session), load from file
169
+ if 'selected_clinical_df' not in globals():
170
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
171
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
172
+
173
+ # 3. Handle missing values
174
+ linked_data = handle_missing_values(linked_data, trait)
175
+
176
+ # 4. Bias checks (remove biased covariates if needed)
177
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
178
+
179
+ # 5. Final validation and save cohort info
180
+ # Ensure pure Python bools for JSON serialization
181
+ is_gene_available_final = bool((normalized_gene_data.shape[0] > 0) and (normalized_gene_data.shape[1] > 0))
182
+ trait_col_present = bool(trait in linked_data.columns)
183
+ has_any_trait = bool(linked_data[trait].notna().any()) if trait_col_present else False
184
+ is_trait_available_final = bool(trait_col_present and has_any_trait)
185
+ is_trait_biased = bool(is_trait_biased)
186
+
187
+ note = ("INFO: Affymetrix probe sets mapped to gene symbols; hippocampal tissue; "
188
+ "Depression treated as continuous symptom count; Age and Gender included; "
189
+ "standard missingness filtering and imputation applied.")
190
+ is_usable = validate_and_save_cohort_info(
191
+ is_final=True,
192
+ cohort=cohort,
193
+ info_path=json_path,
194
+ is_gene_available=is_gene_available_final,
195
+ is_trait_available=is_trait_available_final,
196
+ is_biased=is_trait_biased,
197
+ df=unbiased_linked_data,
198
+ note=note
199
+ )
200
+
201
+ # 6. Save linked data only if usable
202
+ if is_usable:
203
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
204
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Depression/code/GSE128387.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE128387"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE128387"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE128387.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE128387.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE128387.csv"
16
+ json_path = "./output/z2/preprocess/Depression/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 # Affymetrix microarrays; expression data from blood
44
+
45
+ # 2) Variable availability
46
+ trait_row = None # "illness: Major Depressive Disorder" appears constant across samples
47
+ age_row = 2
48
+ gender_row = 3
49
+
50
+ # 2.2) Converters
51
+ def _extract_value(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
+ v = parts[1] if len(parts) > 1 else parts[0]
57
+ return v.strip()
58
+
59
+ def convert_trait(x):
60
+ # Not used since trait_row is None, but implemented for completeness.
61
+ v = _extract_value(x)
62
+ if v is None:
63
+ return None
64
+ vl = v.lower()
65
+ # Map depressive disorder cases to 1, healthy/control to 0
66
+ if any(k in vl for k in ["major depressive", "mdd", "depress"]):
67
+ return 1
68
+ if any(k in vl for k in ["control", "healthy", "normal", "no depression", "non-depressed"]):
69
+ return 0
70
+ return None
71
+
72
+ def convert_age(x):
73
+ v = _extract_value(x)
74
+ if v is None:
75
+ return None
76
+ # Extract first numeric token (handles '16', '16 years', etc.)
77
+ m = re.search(r"[-+]?\d*\.?\d+", v)
78
+ if not m:
79
+ return None
80
+ try:
81
+ age_val = float(m.group())
82
+ # Return int if it's whole number
83
+ return int(age_val) if age_val.is_integer() else age_val
84
+ except Exception:
85
+ return None
86
+
87
+ def convert_gender(x):
88
+ v = _extract_value(x)
89
+ if v is None:
90
+ return None
91
+ vl = v.strip().lower()
92
+ # Map female->0, male->1
93
+ if vl in {"female", "f", "woman", "girl"}:
94
+ return 0
95
+ if vl in {"male", "m", "man", "boy"}:
96
+ return 1
97
+ return None
98
+
99
+ # 3) Save metadata (initial filtering)
100
+ is_trait_available = trait_row is not None
101
+ _ = validate_and_save_cohort_info(
102
+ is_final=False,
103
+ cohort=cohort,
104
+ info_path=json_path,
105
+ is_gene_available=is_gene_available,
106
+ is_trait_available=is_trait_available
107
+ )
108
+
109
+ # 4) Clinical feature extraction (skip because trait_row is None)
110
+ # If trait_row becomes available in future, uncomment the following block:
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_df(selected_clinical_df)
123
+ # selected_clinical_df.to_csv(out_clinical_data_file, index=True)
124
+
125
+ # Step 3: Gene Data Extraction
126
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
127
+ gene_data = get_genetic_data(matrix_file)
128
+
129
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
130
+ print(gene_data.index[:20])
131
+
132
+ # Step 4: Gene Identifier Review
133
+ # The observed identifiers are numeric probe-like IDs (e.g., '16657436'), not human gene symbols.
134
+ print("requires_gene_mapping = True")
135
+
136
+ # Step 5: Gene Annotation
137
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
138
+ gene_annotation = get_gene_annotation(soft_file)
139
+
140
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
141
+ print("Gene annotation preview:")
142
+ print(preview_df(gene_annotation))
143
+
144
+ # Step 6: Gene Identifier Mapping
145
+ # Decide columns for probe IDs and gene symbols based on annotation preview
146
+ probe_col = 'ID' if 'ID' in gene_annotation.columns else 'probeset_id'
147
+ gene_symbol_col = 'gene_assignment' if 'gene_assignment' in gene_annotation.columns else 'mrna_assignment'
148
+
149
+ # Build mapping dataframe (ID -> Gene text)
150
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
151
+
152
+ # Apply mapping to convert probe-level expression to gene-level expression
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
+ # 1. Normalize gene symbols and save gene expression data
160
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
161
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
162
+ normalized_gene_data.to_csv(out_gene_data_file)
163
+
164
+ # 2-6. Trait data is unavailable for this cohort (trait_row is None), so linking is not possible.
165
+ # Perform final validation to record metadata accordingly.
166
+ is_usable = validate_and_save_cohort_info(
167
+ is_final=True,
168
+ cohort=cohort,
169
+ info_path=json_path,
170
+ is_gene_available=True,
171
+ is_trait_available=False,
172
+ is_biased=False,
173
+ df=pd.DataFrame(), # No linked data due to missing trait
174
+ note="INFO: Trait not available per sample; cohort reports constant illness (MDD) without case/control labels, so no linking performed."
175
+ )
176
+
177
+ # No linked data to save
178
+ linked_data = None
output/preprocess/Depression/code/GSE135524.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE135524"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE135524"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE135524.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE135524.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE135524.csv"
16
+ json_path = "./output/z2/preprocess/Depression/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
40
+ is_gene_available = True # Based on series title and design, this is a gene expression dataset (whole blood)
41
+
42
+ # Step 2: Variable availability and converters
43
+ # From the sample characteristics:
44
+ # 0: individual, 1: age, 2: Sex, 3: bmi, 4: race, 5: HAMD score (severity), 6: college, 7: psychomotor score, 8: tissue
45
+ # No diagnosis/control field; background indicates all are depressed → trait (Depression) is constant → not available
46
+ trait_row = None
47
+ age_row = 1
48
+ gender_row = 2
49
+
50
+ def _after_colon(value: str) -> str:
51
+ try:
52
+ return value.split(":", 1)[1].strip()
53
+ except Exception:
54
+ return value
55
+
56
+ def convert_trait(x):
57
+ # Generic heuristic if ever used: map depression/MDD/case to 1, control/healthy to 0; otherwise None
58
+ v = _after_colon(str(x)).lower()
59
+ if any(k in v for k in ["control", "healthy", "hc", "non-depressed", "nondepressed"]):
60
+ return 0
61
+ if any(k in v for k in ["depress", "mdd", "case", "patient"]):
62
+ return 1
63
+ return None
64
+
65
+ def convert_age(x):
66
+ v = _after_colon(str(x))
67
+ try:
68
+ age_val = float(v)
69
+ # Basic sanity check for human ages
70
+ if 0 < age_val < 120:
71
+ return age_val
72
+ except Exception:
73
+ pass
74
+ return None
75
+
76
+ def convert_gender(x):
77
+ v = _after_colon(str(x)).strip().lower()
78
+ # Map female→0, male→1
79
+ if v in ["female", "f", "0"]:
80
+ return 0
81
+ if v in ["male", "m", "1"]:
82
+ return 1
83
+ return None
84
+
85
+ # Step 3: Save metadata with initial filtering
86
+ is_trait_available = trait_row is not None
87
+ _ = validate_and_save_cohort_info(
88
+ is_final=False,
89
+ cohort=cohort,
90
+ info_path=json_path,
91
+ is_gene_available=is_gene_available,
92
+ is_trait_available=is_trait_available
93
+ )
94
+
95
+ # Step 4: Clinical feature extraction (skip because trait not available)
96
+ if is_trait_available:
97
+ selected_clinical_df = geo_select_clinical_features(
98
+ clinical_df=clinical_data,
99
+ trait=trait,
100
+ trait_row=trait_row,
101
+ convert_trait=convert_trait,
102
+ age_row=age_row,
103
+ convert_age=convert_age,
104
+ gender_row=gender_row,
105
+ convert_gender=convert_gender
106
+ )
107
+ _prev = preview_df(selected_clinical_df)
108
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
109
+ selected_clinical_df.to_csv(out_clinical_data_file)
110
+
111
+ # Step 3: Gene Data Extraction
112
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
113
+ gene_data = get_genetic_data(matrix_file)
114
+
115
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
116
+ print(gene_data.index[:20])
117
+
118
+ # Step 4: Gene Identifier Review
119
+ # Illumina probe IDs (e.g., 'ILMN_1343291') are not human gene symbols and require mapping.
120
+ requires_gene_mapping = True
121
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
122
+
123
+ # Step 5: Gene Annotation
124
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
125
+ gene_annotation = get_gene_annotation(soft_file)
126
+
127
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
128
+ print("Gene annotation preview:")
129
+ print(preview_df(gene_annotation))
130
+
131
+ # Step 6: Gene Identifier Mapping
132
+ # Identify appropriate columns in the annotation for probe IDs and gene symbols
133
+ probe_col = 'ID' # Matches probe IDs like 'ILMN_1343291' in expression data
134
+ gene_symbol_col = 'Symbol' # Contains gene symbols
135
+
136
+ # Build mapping dataframe (ID -> Gene)
137
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
138
+
139
+ # Apply mapping to convert probe-level data to gene-level expression
140
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
141
+
142
+ # Step 7: Data Normalization and Linking
143
+ import os
144
+
145
+ # 1. Normalize gene symbols and save gene data
146
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
147
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
148
+ normalized_gene_data.to_csv(out_gene_data_file)
149
+
150
+ # 2-6. Link and downstream processing only if clinical trait data is available
151
+ linked_data = None
152
+ trait_available = ('selected_clinical_data' in locals()) and (trait in getattr(selected_clinical_data, 'index', []))
153
+
154
+ if trait_available:
155
+ # Link clinical and genetic data
156
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
157
+
158
+ # Handle missing values
159
+ linked_data = handle_missing_values(linked_data, trait)
160
+
161
+ # Bias assessment and removal of biased demographics
162
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
163
+
164
+ # Final validation and metadata saving
165
+ is_usable = validate_and_save_cohort_info(
166
+ is_final=True,
167
+ cohort=cohort,
168
+ info_path=json_path,
169
+ is_gene_available=True,
170
+ is_trait_available=True,
171
+ is_biased=is_trait_biased,
172
+ df=unbiased_linked_data,
173
+ note="INFO: Clinical features extracted; proceeded with linking and QC."
174
+ )
175
+
176
+ # Save linked data only if usable
177
+ if is_usable:
178
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
179
+ unbiased_linked_data.to_csv(out_data_file)
180
+
181
+ else:
182
+ # Trait not available: record metadata and do not attempt linking
183
+ _ = validate_and_save_cohort_info(
184
+ is_final=True,
185
+ cohort=cohort,
186
+ info_path=json_path,
187
+ is_gene_available=True,
188
+ is_trait_available=False,
189
+ is_biased=False, # Ignored since trait is unavailable
190
+ df=normalized_gene_data.T, # Non-empty df for validation
191
+ note="INFO: Trait not available (all subjects depressed); skipped linking and downstream analysis."
192
+ )
output/preprocess/Depression/code/GSE138297.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE138297"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE138297"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE138297.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE138297.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE138297.csv"
16
+ json_path = "./output/z2/preprocess/Depression/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
40
+ is_gene_available = True # Microarray analysis on sigmoid biopsies indicates gene expression data
41
+
42
+ # Step 2: Identify rows and define converters
43
+ trait_row = None # No Depression-related data available in this cohort
44
+ age_row = 3
45
+ gender_row = 1
46
+
47
+ def convert_trait(x):
48
+ # Trait (Depression) not available in this dataset
49
+ return None
50
+
51
+ def convert_age(x):
52
+ try:
53
+ # Extract value after colon
54
+ val = str(x).split(":", 1)[1].strip()
55
+ except Exception:
56
+ val = str(x).strip()
57
+ # Handle missing/unknown
58
+ if val in {"", "NA", "N/A", "nan", "NaN", None}:
59
+ return None
60
+ # Convert to float
61
+ try:
62
+ return float(val)
63
+ except Exception:
64
+ return None
65
+
66
+ def convert_gender(x):
67
+ s = str(x)
68
+ # Extract value after colon, but keep header for potential mapping hints
69
+ parts = s.split(":", 1)
70
+ header = parts[0].lower() if parts else ""
71
+ val = parts[1].strip() if len(parts) > 1 else s.strip()
72
+ vlow = val.lower()
73
+
74
+ # Direct string mapping
75
+ if any(k in vlow for k in ["female", "f"]):
76
+ return 0
77
+ if any(k in vlow for k in ["male", "m"]):
78
+ return 1
79
+
80
+ # Numeric mapping with hint in header (female=1, male=0)
81
+ if "female=1" in header and "male=0" in header:
82
+ if val == "1":
83
+ return 0 # female -> 0
84
+ if val == "0":
85
+ return 1 # male -> 1
86
+
87
+ # Fallback: try common encodings
88
+ if val in {"0", "1"}:
89
+ # Without reliable header, assume 0=male, 1=female then convert to required scheme female=0, male=1
90
+ # But given this dataset includes header, this path is unlikely.
91
+ return 1 if val == "0" else 0
92
+
93
+ return None
94
+
95
+ # Step 3: Initial filtering and save metadata
96
+ is_trait_available = trait_row is not None
97
+ validate_and_save_cohort_info(
98
+ is_final=False,
99
+ cohort=cohort,
100
+ info_path=json_path,
101
+ is_gene_available=is_gene_available,
102
+ is_trait_available=is_trait_available
103
+ )
104
+
105
+ # Step 4: Clinical feature extraction (skip because trait_row is None)
106
+ # If in future trait_row becomes available, the following pattern should be used:
107
+ # selected_clinical_df = geo_select_clinical_features(
108
+ # clinical_df=clinical_data,
109
+ # trait=trait,
110
+ # trait_row=trait_row,
111
+ # convert_trait=convert_trait,
112
+ # age_row=age_row,
113
+ # convert_age=convert_age,
114
+ # gender_row=gender_row,
115
+ # convert_gender=convert_gender
116
+ # )
117
+ # preview = preview_df(selected_clinical_df)
118
+ # selected_clinical_df.to_csv(out_clinical_data_file)
output/preprocess/Depression/code/GSE149980.py ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE149980"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE149980"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE149980.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE149980.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE149980.csv"
16
+ json_path = "./output/z2/preprocess/Depression/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 (whole gene expression profiling; not miRNA/methylation)
43
+ is_gene_available = True
44
+
45
+ # 2) Variable availability based on provided sample characteristics:
46
+ # Sample Characteristics show only:
47
+ # 0: 'response status: responder/non-responder' (not our trait "Depression")
48
+ # 1: 'tissue: LCLs'
49
+ trait_row = None # "Depression" status is constant (all depressed) and not explicitly provided
50
+ age_row = None # No age information present
51
+ gender_row = None # No gender information present
52
+
53
+ # 2.2) Conversion functions
54
+ def _after_colon(x):
55
+ if pd.isna(x):
56
+ return None
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
+ """
63
+ Binary: depressed=1, control=0. Unknown -> None.
64
+ Designed generally for GEO clinical strings; not used here since trait_row=None.
65
+ """
66
+ v = _after_colon(x)
67
+ if v is None:
68
+ return None
69
+ v_low = v.lower().strip()
70
+
71
+ positive = {
72
+ "depression", "depressed", "mdd", "major depressive disorder",
73
+ "unipolar depression", "patient", "case"
74
+ }
75
+ negative = {
76
+ "control", "healthy", "normal", "non-depressed", "nondepressed",
77
+ "no depression", "hc"
78
+ }
79
+
80
+ if v_low in positive:
81
+ return 1
82
+ if v_low in negative:
83
+ return 0
84
+
85
+ # Heuristics
86
+ if "depress" in v_low or "mdd" in v_low:
87
+ return 1
88
+ if "control" in v_low or "healthy" in v_low or "normal" in v_low:
89
+ return 0
90
+
91
+ return None
92
+
93
+ def convert_age(x):
94
+ """
95
+ Continuous: age in years as float. Unknown -> None.
96
+ """
97
+ v = _after_colon(x)
98
+ if v is None:
99
+ return None
100
+ v_low = v.lower()
101
+
102
+ # Extract first number (integer or float)
103
+ m = re.search(r"[-+]?\d*\.?\d+", v_low)
104
+ if not m:
105
+ return None
106
+ try:
107
+ return float(m.group())
108
+ except Exception:
109
+ return None
110
+
111
+ def convert_gender(x):
112
+ """
113
+ Binary: female=0, male=1. Unknown -> None.
114
+ """
115
+ v = _after_colon(x)
116
+ if v is None:
117
+ return None
118
+ v_low = v.lower().strip()
119
+
120
+ if v_low in {"male", "m", "man"}:
121
+ return 1
122
+ if v_low in {"female", "f", "woman"}:
123
+ return 0
124
+
125
+ # Heuristics
126
+ if v_low.startswith("m "):
127
+ return 1
128
+ if v_low.startswith("f "):
129
+ return 0
130
+
131
+ return None
132
+
133
+ # 3) Save metadata (initial filtering)
134
+ is_trait_available = trait_row is not None
135
+ _ = validate_and_save_cohort_info(
136
+ is_final=False,
137
+ cohort=cohort,
138
+ info_path=json_path,
139
+ is_gene_available=is_gene_available,
140
+ is_trait_available=is_trait_available
141
+ )
142
+
143
+ # 4) Clinical feature extraction skipped because trait_row is None
144
+
145
+ # Step 3: Gene Data Extraction
146
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
147
+ gene_data = get_genetic_data(matrix_file)
148
+
149
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
150
+ print(gene_data.index[:20])
151
+
152
+ # Step 4: Gene Identifier Review
153
+ requires_gene_mapping = True
154
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
155
+
156
+ # Step 5: Gene Annotation
157
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
158
+ gene_annotation = get_gene_annotation(soft_file)
159
+
160
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
161
+ print("Gene annotation preview:")
162
+ print(preview_df(gene_annotation))
163
+
164
+ # Step 6: Gene Identifier Mapping
165
+ # Identify appropriate columns in annotation for mapping
166
+ # Probe/ID column: 'ID'; Gene symbol column: 'GENE_SYMBOL'
167
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')
168
+
169
+ # Apply mapping to convert probe-level data to gene-level expression
170
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
171
+
172
+ # Step 7: Data Normalization and Linking
173
+ # 1. Normalize gene symbols and save gene-level expression
174
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
175
+ normalized_gene_data.to_csv(out_gene_data_file)
176
+
177
+ # 2-6. Trait unavailable -> skip linking and downstream processing; record metadata accordingly
178
+ is_trait_available = False
179
+ note = ("INFO: Trait 'Depression' not available in clinical annotations for cohort GSE149980. "
180
+ "All samples are depressed patients; only 'response status' is provided. "
181
+ "Association analysis for the specified trait cannot be performed.")
182
+
183
+ # Use gene expression (transposed) to avoid abnormality override in validation
184
+ dummy_df = normalized_gene_data.T if not normalized_gene_data.empty else normalized_gene_data
185
+
186
+ is_usable = validate_and_save_cohort_info(
187
+ is_final=True,
188
+ cohort=cohort,
189
+ info_path=json_path,
190
+ is_gene_available=True,
191
+ is_trait_available=is_trait_available,
192
+ is_biased=False,
193
+ df=dummy_df,
194
+ note=note
195
+ )
196
+
197
+ # No linked data to save since trait is unavailable
output/preprocess/Depression/code/GSE201332.py ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE201332"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE201332"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE201332.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE201332.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE201332.csv"
16
+ json_path = "./output/z2/preprocess/Depression/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import re
40
+ import os
41
+
42
+ # 1) Gene Expression Data Availability
43
+ is_gene_available = True # "Transcriptional profiling" of whole blood for DEGs indicates mRNA expression data.
44
+
45
+ # 2) Variable Availability and Converters
46
+ trait_row = 1 # 'subject status: heathy controls' vs 'subject status: MDD patients'
47
+ age_row = 3 # 'age: 43y', etc.
48
+ gender_row = 2 # 'gender: male' / 'gender: female'
49
+
50
+ def _after_colon(val):
51
+ if val is None:
52
+ return None
53
+ s = str(val).strip()
54
+ if ':' in s:
55
+ s = s.split(':', 1)[1].strip()
56
+ return s
57
+
58
+ def convert_trait(val):
59
+ s = _after_colon(val)
60
+ if s is None or s == '':
61
+ return None
62
+ s_low = s.lower()
63
+ # Map MDD/depression to 1, controls/healthy to 0
64
+ if any(k in s_low for k in ['mdd', 'depress']):
65
+ return 1
66
+ if any(k in s_low for k in ['control', 'healthy', 'normal', 'hc']):
67
+ return 0
68
+ return None
69
+
70
+ def convert_age(val):
71
+ s = _after_colon(val)
72
+ if s is None or s == '':
73
+ return None
74
+ m = re.search(r'(\d+(\.\d+)?)', s)
75
+ if m:
76
+ num = float(m.group(1))
77
+ return num
78
+ return None
79
+
80
+ def convert_gender(val):
81
+ s = _after_colon(val)
82
+ if s is None or s == '':
83
+ return None
84
+ s_low = s.lower()
85
+ if s_low in ['male', 'm']:
86
+ return 1
87
+ if s_low in ['female', 'f']:
88
+ return 0
89
+ return None
90
+
91
+ # 3) Save Metadata (initial filtering)
92
+ is_trait_available = trait_row is not None
93
+ _ = validate_and_save_cohort_info(
94
+ is_final=False,
95
+ cohort=cohort,
96
+ info_path=json_path,
97
+ is_gene_available=is_gene_available,
98
+ is_trait_available=is_trait_available
99
+ )
100
+
101
+ # 4) Clinical Feature Extraction (only if clinical data is available)
102
+ if trait_row is not None:
103
+ selected_clinical_df = geo_select_clinical_features(
104
+ clinical_df=clinical_data,
105
+ trait=trait,
106
+ trait_row=trait_row,
107
+ convert_trait=convert_trait,
108
+ age_row=age_row,
109
+ convert_age=convert_age,
110
+ gender_row=gender_row,
111
+ convert_gender=convert_gender
112
+ )
113
+ preview = preview_df(selected_clinical_df)
114
+ print(preview)
115
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
116
+ selected_clinical_df.to_csv(out_clinical_data_file, index=True)
117
+
118
+ # Step 3: Gene Data Extraction
119
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
120
+ gene_data = get_genetic_data(matrix_file)
121
+
122
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
123
+ print(gene_data.index[:20])
124
+
125
+ # Step 4: Gene Identifier Review
126
+ # The observed identifiers are numeric (e.g., '1', '2', ...), consistent with Entrez Gene IDs, not human gene symbols.
127
+ requires_gene_mapping = True
128
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
129
+
130
+ # Step 5: Gene Annotation
131
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
132
+ gene_annotation = get_gene_annotation(soft_file)
133
+
134
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
135
+ print("Gene annotation preview:")
136
+ print(preview_df(gene_annotation))
137
+
138
+ # Step 6: Gene Identifier Mapping
139
+ # Determine the probe ID column and candidate gene symbol columns
140
+ probe_col = 'ID' if 'ID' in gene_annotation.columns else None
141
+ if probe_col is None:
142
+ raise ValueError("Probe ID column 'ID' was not found in the gene annotation dataframe.")
143
+
144
+ # Candidate columns that may contain gene symbols or descriptions from which symbols can be extracted
145
+ candidate_gene_cols = [
146
+ 'GENE_SYMBOL', 'Gene Symbol', 'Symbol', 'SYMBOL', 'Gene', 'GENE',
147
+ 'GENE_NAME', 'Gene Name', 'GENE_TITLE', 'GENE TITLE', 'GENE_SYMBOLS',
148
+ 'DESCRIPTION', 'DEFINITION', 'Product', 'PRODUCT', 'RefSeq', 'REFSEQ',
149
+ 'ENTREZ_GENE_ID', 'ENTREZID', 'GB_ACC', 'SEQ_ACC', 'ORF', 'ACCNUM',
150
+ 'SPOT_ID', 'NAME', 'SEQUENCE', 'CHROMOSOMAL_LOCATION'
151
+ ]
152
+ present_gene_cols = [c for c in candidate_gene_cols if c in gene_annotation.columns]
153
+
154
+ if not present_gene_cols:
155
+ # Fallback: try any non-ID textual columns
156
+ present_gene_cols = [c for c in gene_annotation.columns if c != probe_col]
157
+
158
+ # Score candidate columns by how many rows yield at least one human gene symbol
159
+ best_col = None
160
+ best_count = -1
161
+ for c in present_gene_cols:
162
+ try:
163
+ tmp_map = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=c)
164
+ except Exception:
165
+ continue
166
+ if tmp_map.empty:
167
+ continue
168
+ # Restrict to probes present in the expression data
169
+ tmp_map = tmp_map[tmp_map['ID'].isin(gene_data.index)]
170
+ if tmp_map.empty:
171
+ continue
172
+ # Count rows with at least one extracted human gene symbol
173
+ count_nonempty = tmp_map['Gene'].apply(extract_human_gene_symbols).apply(lambda x: len(x) if isinstance(x, list) else 0).gt(0).sum()
174
+ if count_nonempty > best_count:
175
+ best_count = count_nonempty
176
+ best_col = c
177
+
178
+ if best_col is None or best_count <= 0:
179
+ # As a last resort, use 'NAME' if available, otherwise raise an error
180
+ if 'NAME' in gene_annotation.columns:
181
+ best_col = 'NAME'
182
+ else:
183
+ raise ValueError("Could not identify a suitable annotation column containing gene symbols.")
184
+
185
+ # Build final mapping using the selected column
186
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=best_col)
187
+
188
+ # Convert probe-level data to gene-level expression using the mapping
189
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
190
+
191
+ # Step 7: Data Normalization and Linking
192
+ import os
193
+
194
+ # 1. Normalize gene symbols and save
195
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
196
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
197
+ normalized_gene_data.to_csv(out_gene_data_file)
198
+
199
+ # 2. Link clinical and genetic data (fix variable name)
200
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
201
+
202
+ # 3. Handle missing values
203
+ linked_data = handle_missing_values(linked_data, trait)
204
+
205
+ # 4. Bias assessment and removal of biased demographics
206
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
207
+
208
+ # 5. Final validation and metadata
209
+ is_usable = validate_and_save_cohort_info(
210
+ True,
211
+ cohort,
212
+ json_path,
213
+ True,
214
+ True,
215
+ is_trait_biased,
216
+ unbiased_linked_data,
217
+ note="INFO: Probes mapped to symbols via annotation; symbols normalized using NCBI synonyms."
218
+ )
219
+
220
+ # 6. Save linked data if usable
221
+ if is_usable:
222
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
223
+ unbiased_linked_data.to_csv(out_data_file)
224
+
225
+ # Step 8: Gene Identifier Mapping
226
+ import json
227
+ import re
228
+
229
+ # Reload raw expression data to ensure probe IDs
230
+ raw_expression_df = get_genetic_data(matrix_file)
231
+
232
+ # 1) Identify identifier column in annotation
233
+ probe_col = 'ID' if 'ID' in gene_annotation.columns else None
234
+ if probe_col is None:
235
+ raise ValueError("Probe ID column 'ID' was not found in the gene annotation dataframe.")
236
+
237
+ # Probes present in expression data
238
+ expr_probe_ids = set(raw_expression_df.index.astype(str))
239
+
240
+ # Exclude known control probes if CONTROL_TYPE is present
241
+ if 'CONTROL_TYPE' in gene_annotation.columns:
242
+ control_flags = gene_annotation['CONTROL_TYPE'].astype(str).str.lower()
243
+ non_control_mask = ~control_flags.isin(['pos', 'neg', 'control', 'empty', 'ignore'])
244
+ non_control_ids = set(gene_annotation.loc[non_control_mask, probe_col].astype(str))
245
+ else:
246
+ non_control_ids = set(gene_annotation[probe_col].astype(str))
247
+
248
+ valid_probe_ids = expr_probe_ids.intersection(non_control_ids)
249
+
250
+ # 2) Select the best annotation column containing gene symbols/descriptors
251
+ candidate_gene_cols = [
252
+ 'GENE_SYMBOL', 'Gene Symbol', 'Symbol', 'SYMBOL', 'Gene', 'GENE',
253
+ 'GENE_NAME', 'Gene Name', 'GENE_TITLE', 'GENE TITLE', 'GENE_SYMBOLS',
254
+ 'DESCRIPTION', 'DEFINITION', 'Product', 'PRODUCT', 'RefSeq', 'REFSEQ',
255
+ 'ENTREZ_GENE_ID', 'ENTREZID', 'GB_ACC', 'SEQ_ACC', 'ORF', 'ACCNUM',
256
+ 'NAME', 'SEQUENCE', 'SPOT_ID', 'CHROMOSOMAL_LOCATION'
257
+ ]
258
+ present_gene_cols = [c for c in candidate_gene_cols if c in gene_annotation.columns]
259
+ if not present_gene_cols:
260
+ present_gene_cols = [c for c in gene_annotation.columns if c != probe_col]
261
+
262
+ # Load synonym dictionary to score columns
263
+ with open("./metadata/gene_synonym.json", "r") as f:
264
+ synonym_dict = json.load(f)
265
+ synonym_keys = set(synonym_dict.keys())
266
+
267
+ # Token exclusion patterns (spike-ins, controls, generic RNA placeholders)
268
+ exclude_exact = {"GE_BRIGHTCORNER", "DARKCORNER", "EMPTY", "CONTROL", "NEG", "POS"}
269
+ exclude_regex = [
270
+ re.compile(r'^ERCC[\w-]*$', re.IGNORECASE),
271
+ re.compile(r'^RNA\d+$', re.IGNORECASE),
272
+ re.compile(r'^RNA\d+-\d+$', re.IGNORECASE),
273
+ re.compile(r'^NEG[\w-]*$', re.IGNORECASE),
274
+ re.compile(r'^POS[\w-]*$', re.IGNORECASE),
275
+ ]
276
+
277
+ def filter_tokens(tokens):
278
+ kept = []
279
+ for t in tokens:
280
+ if not isinstance(t, str):
281
+ continue
282
+ u = t.upper()
283
+ if u in exclude_exact:
284
+ continue
285
+ if any(rx.match(u) for rx in exclude_regex):
286
+ continue
287
+ # Only keep tokens recognized by synonym dictionary
288
+ if u in synonym_keys:
289
+ kept.append(u)
290
+ return kept
291
+
292
+ def score_column(col_name):
293
+ tmp_map = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=col_name)
294
+ if tmp_map.empty:
295
+ return 0, set()
296
+ tmp_map = tmp_map[tmp_map['ID'].astype(str).isin(valid_probe_ids)]
297
+ if tmp_map.empty:
298
+ return 0, set()
299
+ extracted = tmp_map['Gene'].apply(extract_human_gene_symbols)
300
+ # Filter symbols
301
+ filtered_lists = extracted.apply(filter_tokens)
302
+ # Count unique recognized symbols
303
+ uniq_syms = set(sym for lst in filtered_lists if isinstance(lst, list) for sym in lst)
304
+ return len(uniq_syms), uniq_syms
305
+
306
+ # First pass: score all present columns
307
+ scores = {}
308
+ uniq_syms_by_col = {}
309
+ for c in present_gene_cols:
310
+ cnt, uniq = score_column(c)
311
+ scores[c] = cnt
312
+ uniq_syms_by_col[c] = uniq
313
+
314
+ # Choose the best column by recognized count
315
+ best_col = max(scores, key=lambda k: scores[k]) if scores else None
316
+ best_count = scores.get(best_col, 0) if best_col is not None else 0
317
+
318
+ # Enforce fallback strategy if no recognized symbols
319
+ if best_count <= 0:
320
+ for fallback in ['NAME', 'SEQUENCE']:
321
+ if fallback in gene_annotation.columns:
322
+ cnt, uniq = score_column(fallback)
323
+ if cnt > 0:
324
+ best_col = fallback
325
+ best_count = cnt
326
+ uniq_syms_by_col[best_col] = uniq
327
+ break
328
+
329
+ # As a safety, avoid SPOT_ID unless it yields recognized symbols
330
+ if (best_col is None) or (best_count <= 0) or (best_col == 'SPOT_ID' and best_count <= 0):
331
+ raise ValueError("Could not identify an annotation column that yields recognized human gene symbols.")
332
+
333
+ print(f"Selected identifier column: {probe_col}")
334
+ print(f"Selected gene annotation column: {best_col} (recognized_symbols={best_count})")
335
+
336
+ # 3) Build mapping and apply to convert probes -> genes, with explicit filtering
337
+ mapping_df_raw = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=best_col)
338
+ mapping_df_raw = mapping_df_raw[mapping_df_raw['ID'].astype(str).isin(valid_probe_ids)].copy()
339
+
340
+ # Extract and filter tokens per row
341
+ extracted = mapping_df_raw['Gene'].apply(extract_human_gene_symbols)
342
+ filtered_tokens = extracted.apply(filter_tokens)
343
+
344
+ # Keep rows that have at least one recognized, non-excluded symbol
345
+ keep_mask = filtered_tokens.apply(lambda lst: isinstance(lst, list) and len(lst) > 0)
346
+ mapping_df_filtered = mapping_df_raw.loc[keep_mask, ['ID']].copy()
347
+ # Join tokens back to a single string so that apply_gene_mapping can re-extract correctly
348
+ mapping_df_filtered['Gene'] = filtered_tokens.loc[keep_mask].apply(lambda lst: ';'.join(lst))
349
+
350
+ print(f"Mapping dataframe shape after filtering: {mapping_df_filtered.shape}")
351
+
352
+ # Show a small sample of recognized symbols we will map
353
+ recognized_syms_sample = sorted(list(set(sym for lst in filtered_tokens.loc[keep_mask] for sym in lst)))[:15]
354
+ print(f"Sample of recognized symbols to be mapped: {recognized_syms_sample}")
355
+
356
+ if mapping_df_filtered.empty:
357
+ raise ValueError("Derived mapping_df is empty after filtering; cannot map probes to gene symbols.")
358
+
359
+ gene_data = apply_gene_mapping(expression_df=raw_expression_df, mapping_df=mapping_df_filtered)
360
+
361
+ print(f"Gene-level expression shape: {gene_data.shape}")
362
+ print(f"First 10 genes mapped: {list(gene_data.index[:10])}")
363
+ if gene_data.empty:
364
+ raise ValueError("Resulting gene_data is empty after applying mapping.")
output/preprocess/Depression/code/GSE208668.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE208668"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE208668"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE208668.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE208668.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE208668.csv"
16
+ json_path = "./output/z2/preprocess/Depression/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ # Step 1: Determine gene expression data availability based on background info
40
+ # Background explicitly states raw data was lost and not included -> no usable gene expression data.
41
+ is_gene_available = False
42
+
43
+ # Step 2: Identify rows for trait, age, and gender from the Sample Characteristics Dictionary
44
+ trait_row = 9 # 'history of depression: yes/no' -> aligns with trait "Depression"
45
+ age_row = 1 # 'age: <number>'
46
+ gender_row = 2 # 'gender: female/male'
47
+
48
+ # Data availability flags
49
+ is_trait_available = trait_row is not None
50
+
51
+ # Step 2.2: Define conversion functions
52
+ def _after_colon(x):
53
+ if x is None:
54
+ return None
55
+ s = str(x)
56
+ if ':' in s:
57
+ s = s.split(':', 1)[1]
58
+ return s.strip().strip('"').strip("'")
59
+
60
+ def convert_trait(x):
61
+ """
62
+ Map history of depression to binary: no->0, yes->1
63
+ """
64
+ v = _after_colon(x)
65
+ if v is None or v == '':
66
+ return None
67
+ v_lower = v.strip().lower()
68
+ mapping_yes = {'yes', 'y', '1', 'true', 'present', 'positive', 'pos'}
69
+ mapping_no = {'no', 'n', '0', 'false', 'absent', 'negative', 'neg'}
70
+ if v_lower in mapping_yes:
71
+ return 1
72
+ if v_lower in mapping_no:
73
+ return 0
74
+ # Heuristic: if contains 'yes' or 'no' substrings
75
+ if 'yes' in v_lower:
76
+ return 1
77
+ if 'no' in v_lower:
78
+ return 0
79
+ return None
80
+
81
+ def convert_age(x):
82
+ """
83
+ Convert age to continuous (float).
84
+ """
85
+ v = _after_colon(x)
86
+ if v is None or v == '':
87
+ return None
88
+ try:
89
+ return float(str(v).strip())
90
+ except Exception:
91
+ return None
92
+
93
+ def convert_gender(x):
94
+ """
95
+ Map gender to binary: female->0, male->1
96
+ """
97
+ v = _after_colon(x)
98
+ if v is None or v == '':
99
+ return None
100
+ v_lower = v.strip().lower()
101
+ if v_lower in {'female', 'f', 'woman', 'women', 'girl'}:
102
+ return 0
103
+ if v_lower in {'male', 'm', 'man', 'men', 'boy'}:
104
+ return 1
105
+ # Sometimes encoded as 0/1 or F/M
106
+ if v_lower in {'0'}:
107
+ return 0
108
+ if v_lower in {'1'}:
109
+ return 1
110
+ return None
111
+
112
+ # Step 3: Initial filtering and save metadata
113
+ _ = validate_and_save_cohort_info(
114
+ is_final=False,
115
+ cohort=cohort,
116
+ info_path=json_path,
117
+ is_gene_available=is_gene_available,
118
+ is_trait_available=is_trait_available
119
+ )
120
+
121
+ # Step 4: Clinical feature extraction (only if trait_row is available)
122
+ if trait_row is not None:
123
+ selected_clinical_df = geo_select_clinical_features(
124
+ clinical_df=clinical_data,
125
+ trait=trait,
126
+ trait_row=trait_row,
127
+ convert_trait=convert_trait,
128
+ age_row=age_row,
129
+ convert_age=convert_age,
130
+ gender_row=gender_row,
131
+ convert_gender=convert_gender
132
+ )
133
+ # Preview and save
134
+ preview = preview_df(selected_clinical_df)
135
+ print(preview)
136
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
137
+ selected_clinical_df.to_csv(out_clinical_data_file)
output/preprocess/Depression/code/GSE273630.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE273630"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE273630"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE273630.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE273630.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE273630.csv"
16
+ json_path = "./output/z2/preprocess/Depression/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 Nanostring digital transcript panel for inflammatory genes -> gene expression available
43
+ is_gene_available = True
44
+
45
+ # 2. Variable availability and data type conversion
46
+
47
+ # No usable clinical keys for trait/age/gender found in the sample characteristics.
48
+ # Background indicates all participants are male (constant -> not usable). Age not present as a field.
49
+ trait_row = None
50
+ age_row = None
51
+ gender_row = None
52
+
53
+ def _extract_value(x):
54
+ if x is None:
55
+ return None
56
+ if isinstance(x, (int, float)):
57
+ return x
58
+ s = str(x)
59
+ # take substring after the last colon if present
60
+ parts = s.split(":")
61
+ val = parts[-1].strip() if len(parts) > 1 else s.strip()
62
+ return val if val != "" else None
63
+
64
+ # Depression (trait): choose binary mapping if present
65
+ def convert_trait(x):
66
+ val = _extract_value(x)
67
+ if val is None:
68
+ return None
69
+ v = str(val).strip().lower()
70
+ # common positive indicators
71
+ pos = {"depression", "depressed", "mdd", "major depressive disorder", "case", "patient", "yes", "mds"}
72
+ neg = {"control", "healthy", "non-depressed", "no depression", "no", "hc"}
73
+ if v in pos:
74
+ return 1
75
+ if v in neg:
76
+ return 0
77
+ # heuristic patterns
78
+ if "depress" in v or "mdd" in v:
79
+ return 1
80
+ if "control" in v or "healthy" in v:
81
+ return 0
82
+ return None # unknown or non-depression-related field
83
+
84
+ # Age: continuous
85
+ def convert_age(x):
86
+ val = _extract_value(x)
87
+ if val is None:
88
+ return None
89
+ v = str(val).lower()
90
+ nums = re.findall(r"\d+\.?\d*", v)
91
+ if not nums:
92
+ return None
93
+ try:
94
+ age_val = float(nums[0])
95
+ if 0 < age_val < 120:
96
+ return age_val
97
+ except Exception:
98
+ return None
99
+ return None
100
+
101
+ # Gender: binary female->0, male->1
102
+ def convert_gender(x):
103
+ val = _extract_value(x)
104
+ if val is None:
105
+ return None
106
+ v = str(val).strip().lower()
107
+ if v in {"male", "m", "man", "boy"}:
108
+ return 1
109
+ if v in {"female", "f", "woman", "girl"}:
110
+ return 0
111
+ return None
112
+
113
+ # 3. Save metadata (initial filtering)
114
+ is_trait_available = trait_row is not None
115
+ _ = validate_and_save_cohort_info(
116
+ is_final=False,
117
+ cohort=cohort,
118
+ info_path=json_path,
119
+ is_gene_available=is_gene_available,
120
+ is_trait_available=is_trait_available
121
+ )
122
+
123
+ # 4. Clinical feature extraction (skip because trait_row is None)
124
+ if trait_row is not None:
125
+ selected_clinical_df = geo_select_clinical_features(
126
+ clinical_df=clinical_data,
127
+ trait=trait,
128
+ trait_row=trait_row,
129
+ convert_trait=convert_trait,
130
+ age_row=age_row,
131
+ convert_age=convert_age,
132
+ gender_row=gender_row,
133
+ convert_gender=convert_gender
134
+ )
135
+ _ = preview_df(selected_clinical_df)
136
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
137
+ selected_clinical_df.to_csv(out_clinical_data_file)
output/preprocess/Depression/code/GSE81761.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE81761"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE81761"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE81761.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE81761.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE81761.csv"
16
+ json_path = "./output/z2/preprocess/Depression/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 availability based on platform description (Affymetrix HG-U133 Plus 2.0 => mRNA expression)
40
+ is_gene_available = True
41
+
42
+ # 2) Variable availability (rows inferred from provided Sample Characteristics Dictionary)
43
+ # Keys:
44
+ # 0: tissue
45
+ # 1: case/control (PTSD vs No PTSD)
46
+ # 2: ptsd subgroup
47
+ # 3: timepoint
48
+ # 4: Sex
49
+ # 5: age
50
+ # 6: race
51
+ # 7: ethnicity
52
+
53
+ # Trait of interest is Depression, which is not present in this dataset => not available
54
+ trait_row = None
55
+
56
+ # Age and Gender are available
57
+ age_row = 5
58
+ gender_row = 4
59
+
60
+ # 2.2 Converters
61
+ def _after_colon(x):
62
+ if x is None:
63
+ return None
64
+ s = str(x)
65
+ parts = s.split(":", 1)
66
+ return parts[1].strip() if len(parts) == 2 else s.strip()
67
+
68
+ def convert_trait(x):
69
+ # Depression not provided in this PTSD-focused dataset
70
+ return None
71
+
72
+ def convert_age(x):
73
+ val = _after_colon(x)
74
+ if val is None or val == "":
75
+ return None
76
+ # Keep only digits and dot
77
+ import re
78
+ m = re.search(r"[-+]?\d*\.?\d+", val)
79
+ if not m:
80
+ return None
81
+ try:
82
+ return float(m.group(0))
83
+ except Exception:
84
+ return None
85
+
86
+ def convert_gender(x):
87
+ val = _after_colon(x)
88
+ if val is None:
89
+ return None
90
+ v = val.strip().lower()
91
+ # Map female->0, male->1
92
+ if v in {"female", "f", "woman", "women"}:
93
+ return 0
94
+ if v in {"male", "m", "man", "men"}:
95
+ return 1
96
+ return None
97
+
98
+ # 3) Initial filtering and save metadata
99
+ is_trait_available = trait_row is not None
100
+ _ = validate_and_save_cohort_info(
101
+ is_final=False,
102
+ cohort=cohort,
103
+ info_path=json_path,
104
+ is_gene_available=is_gene_available,
105
+ is_trait_available=is_trait_available
106
+ )
107
+
108
+ # 4) Clinical Feature Extraction (skip because trait is not available)
109
+ # If trait_row becomes available in future adjustments, uncomment below:
110
+ if trait_row is not None:
111
+ selected_clinical_df = geo_select_clinical_features(
112
+ clinical_df=clinical_data,
113
+ trait=trait,
114
+ trait_row=trait_row,
115
+ convert_trait=convert_trait,
116
+ age_row=age_row,
117
+ convert_age=convert_age,
118
+ gender_row=gender_row,
119
+ convert_gender=convert_gender
120
+ )
121
+ _ = preview_df(selected_clinical_df)
122
+ # Ensure output directory exists and save
123
+ import os
124
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
125
+ selected_clinical_df.to_csv(out_clinical_data_file, index=True)
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 gene symbols and require 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
+ # 1-2. Determine the appropriate columns for mapping and construct the mapping dataframe
149
+ probe_col = 'ID' # Matches probe identifiers in the expression matrix
150
+ gene_col = 'Gene Symbol' # Column containing gene symbols (may include multiple per probe)
151
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_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(expression_df=gene_data, mapping_df=mapping_df)
output/preprocess/Depression/code/GSE99725.py ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+ cohort = "GSE99725"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Depression"
10
+ in_cohort_dir = "../DATA/GEO/Depression/GSE99725"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Depression/GSE99725.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/GSE99725.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/GSE99725.csv"
16
+ json_path = "./output/z2/preprocess/Depression/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 (whole-genome expression profiling from peripheral blood)
44
+ is_gene_available = True
45
+
46
+ # 2) Variable availability and conversion functions
47
+ # From the sample characteristics dictionary:
48
+ # 0: patient IDs (not useful for analysis)
49
+ # 1: time: M0 / M6 (time point)
50
+ # 2: MADRS: A / B (use as proxy for Depression status)
51
+ # 3: tissue: Venous blood (constant)
52
+ trait_row = 2
53
+ age_row = None
54
+ gender_row = None
55
+
56
+ def _extract_value_after_colon(x):
57
+ if x is None or (isinstance(x, float) and pd.isna(x)):
58
+ return None
59
+ s = str(x)
60
+ if ':' in s:
61
+ s = s.split(':', 1)[1]
62
+ return s.strip()
63
+
64
+ def convert_trait(x):
65
+ """
66
+ Convert MADRS grouping or depression-related labels to binary:
67
+ - Map 'A' (group A) -> 1, 'B' (group B) -> 0
68
+ - Also handle common synonyms if present.
69
+ """
70
+ v = _extract_value_after_colon(x)
71
+ if v is None:
72
+ return None
73
+ lv = v.strip().lower()
74
+
75
+ # Direct group labels
76
+ if lv in {'a', 'group a'}:
77
+ return 1
78
+ if lv in {'b', 'group b'}:
79
+ return 0
80
+
81
+ # Common semantic fallbacks if present
82
+ if lv in {'depressed', 'depression', 'mdd', 'case', 'patient', 'baseline', 'm0'}:
83
+ return 1
84
+ if lv in {'remitted', 'non-depressed', 'control', 'healthy', 'post-op', 'postoperative', 'm6'}:
85
+ return 0
86
+
87
+ # If numeric MADRS score was provided, classify using a common clinical threshold
88
+ # (>=7 often indicates at least mild depression)
89
+ try:
90
+ score = float(re.findall(r'[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?', lv)[0])
91
+ return 1 if score >= 7 else 0
92
+ except Exception:
93
+ return None
94
+
95
+ def convert_age(x):
96
+ v = _extract_value_after_colon(x)
97
+ if v is None:
98
+ return None
99
+ nums = re.findall(r'\d+\.?\d*', v)
100
+ if not nums:
101
+ return None
102
+ try:
103
+ return float(nums[0])
104
+ except Exception:
105
+ return None
106
+
107
+ def convert_gender(x):
108
+ v = _extract_value_after_colon(x)
109
+ if v is None:
110
+ return None
111
+ lv = v.strip().lower()
112
+ if lv in {'female', 'f', 'woman', 'women'}:
113
+ return 0
114
+ if lv in {'male', 'm', 'man', 'men'}:
115
+ return 1
116
+ return None
117
+
118
+ # 3) Save metadata (initial filtering)
119
+ is_trait_available = trait_row is not None
120
+ _ = validate_and_save_cohort_info(
121
+ is_final=False,
122
+ cohort=cohort,
123
+ info_path=json_path,
124
+ is_gene_available=is_gene_available,
125
+ is_trait_available=is_trait_available
126
+ )
127
+
128
+ # 4) Clinical feature extraction (only if trait is available)
129
+ if trait_row is not None:
130
+ selected_clinical_df = geo_select_clinical_features(
131
+ clinical_df=clinical_data,
132
+ trait=trait,
133
+ trait_row=trait_row,
134
+ convert_trait=convert_trait,
135
+ age_row=age_row,
136
+ convert_age=None,
137
+ gender_row=gender_row,
138
+ convert_gender=None
139
+ )
140
+
141
+ # Preview and save
142
+ preview = preview_df(selected_clinical_df)
143
+ print(preview)
144
+
145
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
146
+ selected_clinical_df.to_csv(out_clinical_data_file)
147
+
148
+ # Step 3: Gene Data Extraction
149
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
150
+ gene_data = get_genetic_data(matrix_file)
151
+
152
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
153
+ print(gene_data.index[:20])
154
+
155
+ # Step 4: Gene Identifier Review
156
+ print("requires_gene_mapping = True")
157
+
158
+ # Step 5: Gene Annotation
159
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
160
+ gene_annotation = get_gene_annotation(soft_file)
161
+
162
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
163
+ print("Gene annotation preview:")
164
+ print(preview_df(gene_annotation))
165
+
166
+ # Step 6: Gene Identifier Mapping
167
+ # Determine appropriate columns for mapping: probe IDs and gene symbols
168
+ id_col = 'ID'
169
+ gene_symbol_col = 'GENE_SYMBOL'
170
+ assert id_col in gene_annotation.columns and gene_symbol_col in gene_annotation.columns
171
+
172
+ # 2) Build mapping dataframe (probe -> gene symbol)
173
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=gene_symbol_col)
174
+
175
+ # 3) Apply mapping to convert probe-level data to gene-level expression
176
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
177
+
178
+ # Step 7: Data Normalization and Linking
179
+ import os
180
+
181
+ # 1. Normalize gene symbols and save
182
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
183
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
184
+ normalized_gene_data.to_csv(out_gene_data_file)
185
+
186
+ # 2. Link clinical and genetic data
187
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
188
+
189
+ # 3. Handle missing values
190
+ linked_data = handle_missing_values(linked_data, trait)
191
+
192
+ # 4. Assess bias and remove biased demographic features
193
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
194
+
195
+ # 5. Final validation and save cohort info
196
+ note = "INFO: Trait derived from MADRS grouping (A=case, B=control) as proxy for Depression status."
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=note
206
+ )
207
+
208
+ # 6. Save linked dataset if usable
209
+ if is_usable:
210
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
211
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Depression/code/TCGA.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Depression"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/z2/preprocess/Depression/TCGA.csv"
12
+ out_gene_data_file = "./output/z2/preprocess/Depression/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/z2/preprocess/Depression/clinical_data/TCGA.csv"
14
+ json_path = "./output/z2/preprocess/Depression/cohort_info.json"
15
+
16
+
17
+ # Step 1: Initial Data Loading
18
+ import os
19
+ import pandas as pd
20
+
21
+ # Step 1: Select TCGA subdirectory relevant to the trait "Depression"
22
+ keywords = [
23
+ 'depress', 'mdd', 'major_depress', 'depressive', 'mood',
24
+ 'psychi', 'mental', 'affective', 'sadness'
25
+ ]
26
+
27
+ subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
28
+ matches = []
29
+ for d in subdirs:
30
+ name_l = d.lower()
31
+ if any(k in name_l for k in keywords):
32
+ matches.append(d)
33
+
34
+ selected_tcga_dir = None
35
+ if len(matches) > 0:
36
+ # Choose the most specific match by the longest directory name (heuristic for specificity)
37
+ selected_tcga_dir = max(matches, key=len)
38
+ else:
39
+ # No suitable cohort for depression in TCGA cancer cohorts; record and skip this trait
40
+ print("No suitable TCGA cohort found for trait 'Depression'. Skipping preprocessing for this trait.")
41
+ _ = validate_and_save_cohort_info(
42
+ is_final=False,
43
+ cohort="TCGA",
44
+ info_path=json_path,
45
+ is_gene_available=False,
46
+ is_trait_available=False
47
+ )
48
+
49
+ # Step 2-4: If a directory was selected, identify files, load data, and print clinical column names
50
+ clinical_df, genetic_df = None, None
51
+ if selected_tcga_dir is not None:
52
+ cohort_dir = os.path.join(tcga_root_dir, selected_tcga_dir)
53
+ clinical_path, genetic_path = tcga_get_relevant_filepaths(cohort_dir)
54
+
55
+ clinical_df = pd.read_csv(clinical_path, sep="\t", index_col=0, low_memory=False)
56
+ genetic_df = pd.read_csv(genetic_path, sep="\t", index_col=0, low_memory=False)
57
+
58
+ print(list(clinical_df.columns))
output/preprocess/Depression/cohort_info.json CHANGED
@@ -1,112 +1 @@
1
- {
2
- "GSE99725": {
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": 57
11
- },
12
- "GSE81761": {
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": 109
21
- },
22
- "GSE273630": {
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
- "GSE208668": {
33
- "is_usable": true,
34
- "is_gene_available": true,
35
- "is_trait_available": true,
36
- "is_available": true,
37
- "is_biased": false,
38
- "has_age": true,
39
- "has_gender": true,
40
- "sample_size": 42
41
- },
42
- "GSE201332": {
43
- "is_usable": false,
44
- "is_gene_available": true,
45
- "is_trait_available": false,
46
- "is_available": false,
47
- "is_biased": null,
48
- "has_age": null,
49
- "has_gender": null,
50
- "sample_size": null
51
- },
52
- "GSE149980": {
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": 68
61
- },
62
- "GSE138297": {
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
- "GSE135524": {
73
- "is_usable": true,
74
- "is_gene_available": true,
75
- "is_trait_available": true,
76
- "is_available": true,
77
- "is_biased": false,
78
- "has_age": true,
79
- "has_gender": true,
80
- "sample_size": 88
81
- },
82
- "GSE128387": {
83
- "is_usable": false,
84
- "is_gene_available": true,
85
- "is_trait_available": true,
86
- "is_available": true,
87
- "is_biased": true,
88
- "has_age": true,
89
- "has_gender": false,
90
- "sample_size": 32
91
- },
92
- "GSE110298": {
93
- "is_usable": true,
94
- "is_gene_available": true,
95
- "is_trait_available": true,
96
- "is_available": true,
97
- "is_biased": false,
98
- "has_age": true,
99
- "has_gender": true,
100
- "sample_size": 34
101
- },
102
- "TCGA": {
103
- "is_usable": false,
104
- "is_gene_available": false,
105
- "is_trait_available": false,
106
- "is_available": false,
107
- "is_biased": null,
108
- "has_age": null,
109
- "has_gender": null,
110
- "sample_size": null
111
- }
112
- }
 
1
+ {"GSE99725": {"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": 57, "note": "INFO: Trait derived from MADRS grouping (A=case, B=control) as proxy for Depression status."}, "GSE81761": {"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}, "GSE273630": {"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}, "GSE208668": {"is_usable": false, "is_gene_available": false, "is_trait_available": true, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}, "GSE201332": {"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": "INFO: Probes mapped to symbols via annotation; symbols normalized using NCBI synonyms."}, "GSE149980": {"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 'Depression' not available in clinical annotations for cohort GSE149980. All samples are depressed patients; only 'response status' is provided. Association analysis for the specified trait cannot be performed."}, "GSE138297": {"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}, "GSE135524": {"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 (all subjects depressed); skipped linking and downstream analysis."}, "GSE128387": {"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": "INFO: Trait not available per sample; cohort reports constant illness (MDD) without case/control labels, so no linking performed."}, "GSE110298": {"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": 34, "note": "INFO: Affymetrix probe sets mapped to gene symbols; hippocampal tissue; Depression treated as continuous symptom count; Age and Gender included; standard missingness filtering and imputation applied."}, "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/Depression/gene_data/GSE99725.csv CHANGED
The diff for this file is too large to render. See raw diff
 
output/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/GSE13608.csv CHANGED
@@ -1,4 +1,4 @@
1
- 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29
2
- 0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,,,,,,,,,,,,,,,,,,,,,
3
- ,55.0,54.0,25.0,29.0,21.0,71.0,39.0,69.0,68.0,32.0,47.0,57.0,43.0,37.0,65.0,42.0,50.0,51.0,58.0,28.0,49.0,75.0,73.0,53.0,36.0,46.0,48.0,61.0,85.0
4
- 0.0,1.0,,,,,,,,,,,,,,,,,,,,,,,,,,,,
 
1
+ ,GSM343029,GSM343030,GSM343031,GSM343032,GSM343033,GSM343034,GSM343035,GSM343036,GSM343037,GSM343038,GSM343039,GSM343040,GSM343041,GSM343042,GSM343043,GSM343044,GSM343045,GSM343046,GSM343047,GSM343048,GSM343049,GSM343050,GSM343051,GSM343052,GSM343053,GSM343054,GSM343055,GSM343056,GSM343057,GSM343058,GSM343059,GSM343060,GSM343061,GSM343062,GSM343063,GSM343064,GSM343065,GSM343066,GSM343067,GSM343068,GSM343069,GSM343070,GSM343071,GSM343072,GSM343073,GSM343074,GSM343075,GSM343076,GSM343077,GSM343078,GSM343079,GSM343080,GSM343081,GSM343082,GSM343083,GSM343084,GSM343085,GSM343086,GSM343087,GSM343088,GSM343089,GSM343090,GSM343091,GSM343092,GSM343093,GSM343094,GSM343095,GSM343096
2
+ Duchenne_Muscular_Dystrophy,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0
3
+ Age,,,,55.0,,54.0,25.0,29.0,,21.0,71.0,39.0,69.0,,68.0,32.0,47.0,57.0,43.0,37.0,47.0,54.0,43.0,65.0,42.0,50.0,51.0,58.0,51.0,55.0,28.0,49.0,,,75.0,73.0,55.0,,,,,53.0,36.0,46.0,48.0,69.0,61.0,85.0,43.0,43.0,26.0,43.0,,,,,,50.0,45.0,26.0,5.0,8.0,20.0,64.0,58.0,88.0,58.0,
4
+ Gender,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.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,0.0,1.0,1.0,1.0,1.0,,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0
output/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/GSE48828.csv CHANGED
@@ -1,4 +1,4 @@
1
  ,GSM1185341,GSM1185342,GSM1185343,GSM1185344,GSM1185345,GSM1185346,GSM1185347,GSM1185348,GSM1185349,GSM1185350,GSM1185351,GSM1185352,GSM1185353,GSM1185354,GSM1185355,GSM1185356,GSM1185357,GSM1185358,GSM1185359,GSM1185360,GSM1185361,GSM1185362,GSM1185363,GSM1185364,GSM1185365,GSM1185366,GSM1185367,GSM1185368
2
  Duchenne_Muscular_Dystrophy,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,,,54.0,29.0,25.0,21.0,55.0,,39.0,58.0,50.0,51.0,43.0,51.0,37.0,43.0,65.0,55.0,50.0,45.0,26.0,20.0,58.0,88.0,61.0,43.0,85.0,43.0
4
- Gender,,,,,,,,,,,,,,,,,,,,,,,,,,,,
 
1
  ,GSM1185341,GSM1185342,GSM1185343,GSM1185344,GSM1185345,GSM1185346,GSM1185347,GSM1185348,GSM1185349,GSM1185350,GSM1185351,GSM1185352,GSM1185353,GSM1185354,GSM1185355,GSM1185356,GSM1185357,GSM1185358,GSM1185359,GSM1185360,GSM1185361,GSM1185362,GSM1185363,GSM1185364,GSM1185365,GSM1185366,GSM1185367,GSM1185368
2
  Duchenne_Muscular_Dystrophy,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,,,54.0,29.0,25.0,21.0,55.0,,39.0,58.0,50.0,51.0,43.0,51.0,37.0,43.0,65.0,55.0,50.0,45.0,26.0,20.0,58.0,88.0,61.0,43.0,85.0,43.0
4
+ Gender,0.0,0.0,0.0,0.0,1.0,1.0,0.0,,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0
output/preprocess/Duchenne_Muscular_Dystrophy/code/GSE109178.py ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Duchenne_Muscular_Dystrophy"
6
+ cohort = "GSE109178"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Duchenne_Muscular_Dystrophy"
10
+ in_cohort_dir = "../DATA/GEO/Duchenne_Muscular_Dystrophy/GSE109178"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/GSE109178.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/gene_data/GSE109178.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/GSE109178.csv"
16
+ json_path = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/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: Gene expression availability (Affymetrix HG-U133 Plus 2.0 mRNA arrays)
40
+ is_gene_available = True
41
+
42
+ # Step 2.1: Determine availability rows from the provided Sample Characteristics Dictionary
43
+ # Trait (Duchenne Muscular Dystrophy) label is not explicitly present -> cannot infer reliably from provided keys
44
+ trait_row = None
45
+
46
+ # Age is available at key 0
47
+ age_row = 0
48
+
49
+ # Gender is available at key 3
50
+ gender_row = 3
51
+
52
+ # Step 2.2: Conversion functions
53
+
54
+ def _after_colon(val: str) -> str:
55
+ if val is None:
56
+ return ""
57
+ parts = str(val).split(":", 1)
58
+ v = parts[1] if len(parts) > 1 else parts[0]
59
+ return v.strip()
60
+
61
+ def convert_trait(val):
62
+ # No trait field available; return None to indicate missing
63
+ _ = _after_colon(val)
64
+ return None
65
+
66
+ def convert_age(val):
67
+ v = _after_colon(val).lower()
68
+ if v in {"na", "n/a", "", "none"}:
69
+ return None
70
+ # remove potential units and commas
71
+ v = v.replace("years", "").replace("year", "").replace("yrs", "").replace("yr", "").replace(",", "").strip()
72
+ try:
73
+ return float(v)
74
+ except Exception:
75
+ return None
76
+
77
+ def convert_gender(val):
78
+ v = _after_colon(val).strip().lower()
79
+ if v in {"m", "male"}:
80
+ return 1
81
+ if v in {"f", "female"}:
82
+ return 0
83
+ if v in {"na", "n/a", "", "none"}:
84
+ return None
85
+ # occasional typos or single letters
86
+ if v.startswith("m"):
87
+ return 1
88
+ if v.startswith("f"):
89
+ return 0
90
+ return None
91
+
92
+ # Step 3: Initial filtering metadata save
93
+ is_trait_available = trait_row is not None
94
+ _ = validate_and_save_cohort_info(
95
+ is_final=False,
96
+ cohort=cohort,
97
+ info_path=json_path,
98
+ is_gene_available=is_gene_available,
99
+ is_trait_available=is_trait_available
100
+ )
101
+
102
+ # Step 4: Clinical feature extraction (skip because trait_row is None)
103
+ if trait_row is not None:
104
+ selected_clinical_df = geo_select_clinical_features(
105
+ clinical_df=clinical_data,
106
+ trait=trait,
107
+ trait_row=trait_row,
108
+ convert_trait=convert_trait,
109
+ age_row=age_row,
110
+ convert_age=convert_age,
111
+ gender_row=gender_row,
112
+ convert_gender=convert_gender
113
+ )
114
+ print(preview_df(selected_clinical_df))
115
+ # Save clinical data
116
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
117
+ selected_clinical_df.to_csv(out_clinical_data_file, index=True)
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
+ # Affymetrix probe set IDs detected (e.g., "1007_s_at", "1552256_a_at"), not HGNC gene symbols.
128
+ requires_gene_mapping = True
129
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
130
+
131
+ # Step 5: Gene Annotation
132
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
133
+ gene_annotation = get_gene_annotation(soft_file)
134
+
135
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
136
+ print("Gene annotation preview:")
137
+ print(preview_df(gene_annotation))
138
+
139
+ # Step 6: Gene Identifier Mapping
140
+ # Identify the appropriate columns for mapping based on the annotation preview
141
+ probe_id_col = 'ID'
142
+ gene_symbol_col = 'Gene Symbol'
143
+
144
+ # Extract the mapping dataframe
145
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_id_col, gene_col=gene_symbol_col)
146
+
147
+ # Apply mapping to convert probe-level data to gene-level expression
148
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
149
+
150
+ # Step 7: Data Normalization and Linking
151
+ import os
152
+
153
+ # 1. Normalize gene symbols and save gene-level data
154
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
155
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
156
+ normalized_gene_data.to_csv(out_gene_data_file)
157
+
158
+ # 2. Attempt to link only if clinical data with trait is available
159
+ clinical = None
160
+ if 'selected_clinical_data' in globals():
161
+ clinical = selected_clinical_data
162
+ elif 'selected_clinical_df' in globals():
163
+ clinical = selected_clinical_df
164
+
165
+ has_trait_data = (clinical is not None) and (trait in getattr(clinical, 'index', []))
166
+
167
+ if has_trait_data:
168
+ # 2. Link
169
+ linked_data = geo_link_clinical_genetic_data(clinical, normalized_gene_data)
170
+
171
+ # 3. Handle missing values
172
+ linked_data = handle_missing_values(linked_data, trait)
173
+
174
+ # 4. Bias checks
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
+ is_usable = validate_and_save_cohort_info(
179
+ is_final=True,
180
+ cohort=cohort,
181
+ info_path=json_path,
182
+ is_gene_available=True,
183
+ is_trait_available=True,
184
+ is_biased=is_trait_biased,
185
+ df=unbiased_linked_data,
186
+ note="INFO: Trait labels available and data linked."
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, index=True)
193
+ else:
194
+ # Trait not available: skip linking and final validation; ensure metadata reflects unavailability.
195
+ _ = validate_and_save_cohort_info(
196
+ is_final=False,
197
+ cohort=cohort,
198
+ info_path=json_path,
199
+ is_gene_available=True,
200
+ is_trait_available=False
201
+ )
output/preprocess/Duchenne_Muscular_Dystrophy/code/GSE13608.py ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Duchenne_Muscular_Dystrophy"
6
+ cohort = "GSE13608"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Duchenne_Muscular_Dystrophy"
10
+ in_cohort_dir = "../DATA/GEO/Duchenne_Muscular_Dystrophy/GSE13608"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/GSE13608.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/gene_data/GSE13608.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/GSE13608.csv"
16
+ json_path = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/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 # mRNA expression microarray of skeletal muscle biopsies
45
+
46
+ # 2) Variable availability and converters based on the provided Sample Characteristics Dictionary
47
+ trait_row = 1 # Contains disease labels including 'Duchenne Muscular Dystrophy patient'
48
+ age_row = 2 # Contains entries like 'age 43', 'age unknown', 'age f'
49
+ gender_row = 3 # Contains 'Gender: M', 'Gender: F', 'Gender M/F pool'
50
+
51
+ is_trait_available = trait_row is not None
52
+
53
+ def _after_colon(value: str) -> str:
54
+ s = str(value).strip()
55
+ if ':' in s:
56
+ s = s.split(':', 1)[1].strip()
57
+ return s
58
+
59
+ def convert_trait(value):
60
+ if value is None:
61
+ return None
62
+ s = _after_colon(value)
63
+ s_low = s.lower()
64
+ # Explicit DMD mapping
65
+ if 'duchenne' in s_low:
66
+ return 1
67
+ # Known non-DMD categories -> 0
68
+ if any(k in s_low for k in [
69
+ 'dm1', 'dm2', 'dmx',
70
+ 'becker', 'bmd',
71
+ 'tmd', 'tibial',
72
+ 'myotonia', 'myotonic',
73
+ 'normal', 'mc-ad'
74
+ ]):
75
+ return 0
76
+ # Generic fallback: if looks like a patient label or normal but not DMD -> 0
77
+ if 'patient' in s_low or 'normal' in s_low:
78
+ return 0
79
+ return None
80
+
81
+ def convert_age(value):
82
+ if value is None:
83
+ return None
84
+ s = _after_colon(value).strip().lower()
85
+ # Tidy leading keyword 'age'
86
+ if s.startswith('age'):
87
+ s = s[3:].strip()
88
+ # Handles 'unknown' or fetal notation 'f'
89
+ if s in {'', 'unknown', 'f'}:
90
+ return None
91
+ # Extract first integer found
92
+ m = re.search(r'(\d+)', s)
93
+ if m:
94
+ try:
95
+ return float(m.group(1))
96
+ except Exception:
97
+ return None
98
+ return None
99
+
100
+ def convert_gender(value):
101
+ if value is None:
102
+ return None
103
+ s = str(value).strip()
104
+ # Normalize representation 'Gender M/F pool' or 'Gender: ...'
105
+ s = s.replace('Gender', '').replace('gender', '').replace(':', '').strip().lower()
106
+ if 'pool' in s or 'm/f' in s or s == '':
107
+ return None
108
+ if s in {'m', 'male'}:
109
+ return 1
110
+ if s in {'f', 'female'}:
111
+ return 0
112
+ return None
113
+
114
+ # 3) Initial filtering and save metadata
115
+ _ = validate_and_save_cohort_info(
116
+ is_final=False,
117
+ cohort=cohort,
118
+ info_path=json_path,
119
+ is_gene_available=is_gene_available,
120
+ is_trait_available=is_trait_available
121
+ )
122
+
123
+ # 4) Clinical feature extraction (only if trait available)
124
+ if trait_row is not None:
125
+ selected_clinical_df = geo_select_clinical_features(
126
+ clinical_df=clinical_data,
127
+ trait=trait,
128
+ trait_row=trait_row,
129
+ convert_trait=convert_trait,
130
+ age_row=age_row,
131
+ convert_age=convert_age,
132
+ gender_row=gender_row,
133
+ convert_gender=convert_gender
134
+ )
135
+
136
+ # Preview and save
137
+ clinical_preview = preview_df(selected_clinical_df)
138
+ print("Selected clinical features preview:", clinical_preview)
139
+
140
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
141
+ selected_clinical_df.to_csv(out_clinical_data_file, index=True)
142
+
143
+ # Step 3: Gene Data Extraction
144
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
145
+ gene_data = get_genetic_data(matrix_file)
146
+
147
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
148
+ print(gene_data.index[:20])
149
+
150
+ # Step 4: Gene Identifier Review
151
+ # Affymetrix probe set IDs (e.g., 1007_s_at) require mapping to human gene symbols
152
+ requires_gene_mapping = True
153
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
154
+
155
+ # Step 5: Gene Annotation
156
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
157
+ gene_annotation = get_gene_annotation(soft_file)
158
+
159
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
160
+ print("Gene annotation preview:")
161
+ print(preview_df(gene_annotation))
162
+
163
+ # Step 6: Gene Identifier Mapping
164
+ # Identify columns for probe IDs and gene symbols in the annotation
165
+ probe_col = 'ID'
166
+ gene_symbol_col = 'Gene Symbol'
167
+
168
+ # Build probe-to-gene mapping dataframe
169
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=gene_symbol_col)
170
+
171
+ # Convert probe-level data to gene-level expression using the mapping
172
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
173
+
174
+ # Step 7: Data Normalization and Linking
175
+ import os
176
+
177
+ # 1. Normalize gene symbols and save gene data
178
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
179
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
180
+ normalized_gene_data.to_csv(out_gene_data_file)
181
+
182
+ # 2. Link clinical and genetic data
183
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
184
+
185
+ # 3. Handle missing values
186
+ linked_data = handle_missing_values(linked_data, trait)
187
+
188
+ # 4. Determine bias and remove biased demographic features
189
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
190
+
191
+ # Prepare an informative note about class imbalance
192
+ n_samples = len(unbiased_linked_data)
193
+ n_cases = int(unbiased_linked_data[trait].sum()) if trait in unbiased_linked_data.columns else 0
194
+ note = f"INFO: Trait class imbalance; {n_cases} DMD cases out of {n_samples} samples after preprocessing."
195
+
196
+ # 5. Final validation and save cohort information
197
+ is_usable = validate_and_save_cohort_info(
198
+ True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data, note
199
+ )
200
+
201
+ # 6. Save linked data only if usable
202
+ if is_usable:
203
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
204
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Duchenne_Muscular_Dystrophy/code/GSE48828.py ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Duchenne_Muscular_Dystrophy"
6
+ cohort = "GSE48828"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Duchenne_Muscular_Dystrophy"
10
+ in_cohort_dir = "../DATA/GEO/Duchenne_Muscular_Dystrophy/GSE48828"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/GSE48828.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/gene_data/GSE48828.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/GSE48828.csv"
16
+ json_path = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+ import pandas as pd
42
+
43
+ # 1) Gene expression data availability
44
+ is_gene_available = True # Affymetrix Human Exon 1.0 ST array indicates mRNA expression profiling
45
+
46
+ # 2) Variable availability and converters based on provided Sample Characteristics Dictionary
47
+ # Keys:
48
+ # 0: diagnosis includes 'Duchenne Muscular Dystrophy' among others
49
+ # 1: gender: F/M/Not available
50
+ # 2: age (yrs): numeric and Not available/na
51
+
52
+ trait_row = 0
53
+ age_row = 2
54
+ gender_row = 1
55
+
56
+ def _after_colon(value):
57
+ if value is None:
58
+ return None
59
+ if isinstance(value, str):
60
+ parts = value.split(":", 1)
61
+ v = parts[1] if len(parts) > 1 else parts[0]
62
+ return v.strip()
63
+ return value
64
+
65
+ def convert_trait(value):
66
+ v = _after_colon(value)
67
+ if v is None:
68
+ return None
69
+ v_low = v.strip().lower()
70
+ # Map DMD to 1, all others (DM1, DM2, BMD, TMD, Normal, etc.) to 0
71
+ if "duchenne" in v_low:
72
+ return 1
73
+ # If it's a diagnosis but not DMD, map to 0; unknowns remain None
74
+ known_diagnoses_keywords = ["myotonic", "becker", "tibial", "normal", "muscular dystrophy", "dystrophy"]
75
+ if any(k in v_low for k in known_diagnoses_keywords):
76
+ return 0
77
+ return None
78
+
79
+ def convert_age(value):
80
+ v = _after_colon(value)
81
+ if v is None:
82
+ return None
83
+ v_low = v.lower()
84
+ if v_low in {"na", "not available", "n/a", "unknown", ""}:
85
+ return None
86
+ # Extract numeric (integer or float)
87
+ m = re.search(r"[-+]?\d*\.?\d+", v)
88
+ if m:
89
+ try:
90
+ return float(m.group())
91
+ except Exception:
92
+ return None
93
+ return None
94
+
95
+ def convert_gender(value):
96
+ v = _after_colon(value)
97
+ if v is None:
98
+ return None
99
+ v_low = v.lower()
100
+ if v_low in {"f", "female"}:
101
+ return 0
102
+ if v_low in {"m", "male"}:
103
+ return 1
104
+ return None
105
+
106
+ # 3) Save metadata with initial filtering
107
+ is_trait_available = trait_row is not None
108
+ _ = validate_and_save_cohort_info(
109
+ is_final=False,
110
+ cohort=cohort,
111
+ info_path=json_path,
112
+ is_gene_available=is_gene_available,
113
+ is_trait_available=is_trait_available
114
+ )
115
+
116
+ # 4) Clinical feature extraction (only if trait_row is available)
117
+ if trait_row is not None:
118
+ selected_clinical_df = geo_select_clinical_features(
119
+ clinical_df=clinical_data,
120
+ trait=trait,
121
+ trait_row=trait_row,
122
+ convert_trait=convert_trait,
123
+ age_row=age_row,
124
+ convert_age=convert_age,
125
+ gender_row=gender_row,
126
+ convert_gender=convert_gender
127
+ )
128
+
129
+ # Preview
130
+ preview = preview_df(selected_clinical_df)
131
+ print(preview)
132
+
133
+ # Save clinical data
134
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
135
+ selected_clinical_df.to_csv(out_clinical_data_file)
136
+
137
+ # Step 3: Gene Data Extraction
138
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
139
+ gene_data = get_genetic_data(matrix_file)
140
+
141
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
142
+ print(gene_data.index[:20])
143
+
144
+ # Step 4: Gene Identifier Review
145
+ import re
146
+
147
+ # Given identifiers from previous step
148
+ ids = ['2315588', '2315589', '2315591', '2315594', '2315595', '2315596',
149
+ '2315598', '2315602', '2315603', '2315604', '2315607', '2315638',
150
+ '2315639', '2315640', '2315641', '2315642', '2315643', '2315644',
151
+ '2315645', '2315690']
152
+
153
+ # Consider as gene symbols only if any identifier contains alphabetic characters
154
+ requires_gene_mapping = not any(re.search('[A-Za-z]', x) for x in ids)
155
+
156
+ print(f"requires_gene_mapping = {requires_gene_mapping}")
157
+
158
+ # Step 5: Gene Annotation
159
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
160
+ gene_annotation = get_gene_annotation(soft_file)
161
+
162
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
163
+ print("Gene annotation preview:")
164
+ print(preview_df(gene_annotation))
165
+
166
+ # Step 6: Gene Identifier Mapping
167
+ # Decide columns for mapping based on annotation preview:
168
+ # - Probe/feature identifiers: 'ID' (matches numeric IDs in expression data)
169
+ # - Gene symbols embedded in: 'gene_assignment'
170
+ id_col = 'ID'
171
+ gene_col = 'gene_assignment'
172
+
173
+ # 2) Build mapping dataframe
174
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=id_col, gene_col=gene_col)
175
+
176
+ # 3) Apply mapping to convert probe-level data to gene-level expression
177
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
178
+
179
+ # Step 7: Data Normalization and Linking
180
+ import os
181
+
182
+ # 1. Normalize gene symbols and save normalized gene data
183
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
184
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
185
+ normalized_gene_data.to_csv(out_gene_data_file)
186
+
187
+ # 2. Link clinical and genetic data
188
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
189
+
190
+ # 3. Handle missing values
191
+ linked_data = handle_missing_values(linked_data, trait)
192
+
193
+ # 4. Determine bias and remove biased demographic features
194
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
195
+
196
+ # 5. Final validation and save cohort info
197
+ try:
198
+ trait_counts = unbiased_linked_data[trait].value_counts().to_dict()
199
+ note = f"WARNING: Trait distribution after preprocessing: {trait_counts}. Extremely imbalanced if minor class <10%."
200
+ except Exception:
201
+ note = "WARNING: Unable to compute trait distribution for note."
202
+ is_usable = validate_and_save_cohort_info(
203
+ is_final=True,
204
+ cohort=cohort,
205
+ info_path=json_path,
206
+ is_gene_available=True,
207
+ is_trait_available=True,
208
+ is_biased=is_trait_biased,
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/Duchenne_Muscular_Dystrophy/code/GSE79263.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Duchenne_Muscular_Dystrophy"
6
+ cohort = "GSE79263"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Duchenne_Muscular_Dystrophy"
10
+ in_cohort_dir = "../DATA/GEO/Duchenne_Muscular_Dystrophy/GSE79263"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/GSE79263.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/gene_data/GSE79263.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/GSE79263.csv"
16
+ json_path = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/cohort_info.json"
17
+
18
+
19
+ # Step 1: Initial Data Loading
20
+ from tools.preprocess import *
21
+ # 1. Identify the paths to the SOFT file and the matrix file
22
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
23
+
24
+ # 2. Read the matrix file to obtain background information and sample characteristics data
25
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
26
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
27
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
28
+
29
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
30
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
31
+
32
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
33
+ print("Background Information:")
34
+ print(background_info)
35
+ print("Sample Characteristics Dictionary:")
36
+ print(sample_characteristics_dict)
37
+
38
+ # Step 2: Dataset Analysis and Clinical Feature Extraction
39
+ import os
40
+ import re
41
+
42
+ # 1) Gene expression availability
43
+ is_gene_available = True # Transcriptomic gene expression per background info
44
+
45
+ # 2) Variable availability
46
+ trait_row = 2 # 'disease state' with values like Duchenne muscular dystrophy / healthy
47
+ age_row = 4 # 'age' with numeric years or unknown
48
+ gender_row = None # No gender information found
49
+
50
+ # 2.2) Converters
51
+ def _after_colon(value: str) -> str:
52
+ if value is None:
53
+ return ""
54
+ s = str(value).strip()
55
+ if ":" in s:
56
+ s = s.split(":", 1)[1].strip()
57
+ return s
58
+
59
+ def convert_trait(value):
60
+ v = _after_colon(value).strip().lower()
61
+ if v in {"na", "n/a", "unknown", ""}:
62
+ return None
63
+ # Map DMD cases to 1
64
+ if ("duchenne" in v) or (v == "dmd") or ("duchenne muscular dystropy" in v):
65
+ return 1
66
+ # Map healthy/control to 0
67
+ if v in {"healthy", "control", "normal"}:
68
+ return 0
69
+ return None
70
+
71
+ def convert_age(value):
72
+ v = _after_colon(value).strip().lower()
73
+ if v in {"na", "n/a", "unknown", ""}:
74
+ return None
75
+ m = re.search(r"(\d+(\.\d+)?)", v)
76
+ if m:
77
+ try:
78
+ # Return as float if decimals exist, else int
79
+ num = float(m.group(1))
80
+ return int(num) if num.is_integer() else num
81
+ except Exception:
82
+ return None
83
+ return None
84
+
85
+ def convert_gender(value):
86
+ v = _after_colon(value).strip().lower()
87
+ if v in {"female", "f"}:
88
+ return 0
89
+ if v in {"male", "m"}:
90
+ return 1
91
+ if v in {"na", "n/a", "unknown", ""}:
92
+ return None
93
+ return None
94
+
95
+ # 3) Save initial metadata
96
+ is_trait_available = trait_row is not None
97
+ _ = validate_and_save_cohort_info(
98
+ is_final=False,
99
+ cohort=cohort,
100
+ info_path=json_path,
101
+ is_gene_available=is_gene_available,
102
+ is_trait_available=is_trait_available
103
+ )
104
+
105
+ # 4) Clinical feature extraction (only if trait data is available)
106
+ if trait_row is not None:
107
+ selected_clinical_df = geo_select_clinical_features(
108
+ clinical_df=clinical_data,
109
+ trait=trait,
110
+ trait_row=trait_row,
111
+ convert_trait=convert_trait,
112
+ age_row=age_row,
113
+ convert_age=convert_age,
114
+ gender_row=gender_row,
115
+ convert_gender=convert_gender
116
+ )
117
+ preview = preview_df(selected_clinical_df)
118
+ print(preview)
119
+
120
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
121
+ selected_clinical_df.to_csv(out_clinical_data_file)
122
+
123
+ # Step 3: Gene Data Extraction
124
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
125
+ gene_data = get_genetic_data(matrix_file)
126
+
127
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
128
+ print(gene_data.index[:20])
129
+
130
+ # Step 4: Gene Identifier Review
131
+ print("requires_gene_mapping = True")
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
+ # Select appropriate columns for mapping: probe IDs ('ID') and gene symbols ('Symbol')
143
+ prob_col = 'ID'
144
+ gene_col = 'Symbol'
145
+
146
+ # Build mapping dataframe from annotation
147
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=prob_col, gene_col=gene_col)
148
+
149
+ # Apply mapping to convert probe-level data to gene-level data
150
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
151
+
152
+ # Normalize gene symbols to standard symbols and aggregate duplicates
153
+ gene_data = normalize_gene_symbols_in_index(gene_data)
154
+
155
+ # Step 7: Data Normalization and Linking
156
+ import os
157
+
158
+ # 1. Normalize gene symbols and save normalized gene expression data
159
+ # Note: gene_data was already normalized in Step 6; calling again is idempotent and safe.
160
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
161
+
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
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
167
+
168
+ # 3. Handle missing values
169
+ linked_data = handle_missing_values(linked_data, trait)
170
+
171
+ # 4. Assess bias and remove biased demographic features
172
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
173
+
174
+ # 5. Final validation and save cohort info
175
+ is_usable = validate_and_save_cohort_info(
176
+ True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data
177
+ )
178
+
179
+ # 6. Save linked data if usable
180
+ if is_usable:
181
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
182
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Duchenne_Muscular_Dystrophy/code/TCGA.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Duchenne_Muscular_Dystrophy"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/TCGA.csv"
12
+ out_gene_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/clinical_data/TCGA.csv"
14
+ json_path = "./output/z2/preprocess/Duchenne_Muscular_Dystrophy/cohort_info.json"
15
+
16
+
17
+ # Step 1: Initial Data Loading
18
+ import os
19
+ import pandas as pd
20
+
21
+ # Discover available subdirectories (cohorts)
22
+ subdirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))]
23
+
24
+ # Try to find a TCGA cohort relevant to Duchenne Muscular Dystrophy (DMD) — TCGA is cancer-focused, so expect none.
25
+ terms = ["duchenne muscular dystrophy", "dystrophin", "dmd"]
26
+ lower_map = {d.lower(): d for d in subdirs}
27
+
28
+ def score_dir(name: str) -> int:
29
+ name_l = name.lower()
30
+ score = 0
31
+ if "duchenne muscular dystrophy" in name_l:
32
+ score += 3
33
+ if "dystrophin" in name_l:
34
+ score += 2
35
+ if "dmd" in name_l:
36
+ score += 1
37
+ return score
38
+
39
+ scored = [(score_dir(d), d) for d in subdirs]
40
+ scored = [item for item in scored if item[0] > 0]
41
+
42
+ if len(scored) == 0:
43
+ print("No suitable TCGA cohort matches Duchenne Muscular Dystrophy. Skipping this trait for TCGA.")
44
+ # Record unusable dataset for this trait within TCGA
45
+ validate_and_save_cohort_info(
46
+ is_final=False,
47
+ cohort="TCGA_Duchenne_Muscular_Dystrophy",
48
+ info_path=json_path,
49
+ is_gene_available=False,
50
+ is_trait_available=False
51
+ )
52
+ # Prepare empty placeholders to avoid downstream NameErrors if any
53
+ clinical_df = pd.DataFrame()
54
+ genetic_df = pd.DataFrame()
55
+ else:
56
+ # Select the best-matching cohort
57
+ selected_dir = sorted(scored, key=lambda x: (-x[0], len(x[1])))[0][1]
58
+ cohort_dir = os.path.join(tcga_root_dir, selected_dir)
59
+ print(f"Selected TCGA cohort: {selected_dir}")
60
+
61
+ # Identify relevant file paths
62
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
63
+
64
+ # Load clinical and genetic data
65
+ clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, low_memory=False)
66
+ genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, low_memory=False)
67
+
68
+ # Print clinical column names
69
+ print(list(clinical_df.columns))
output/preprocess/Duchenne_Muscular_Dystrophy/cohort_info.json CHANGED
@@ -1,52 +1 @@
1
- {
2
- "GSE79263": {
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": false,
10
- "sample_size": 86
11
- },
12
- "GSE48828": {
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
- "GSE13608": {
23
- "is_usable": false,
24
- "is_gene_available": false,
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
- "GSE109178": {
33
- "is_usable": false,
34
- "is_gene_available": false,
35
- "is_trait_available": false,
36
- "is_available": false,
37
- "is_biased": null,
38
- "has_age": null,
39
- "has_gender": null,
40
- "sample_size": null
41
- },
42
- "TCGA": {
43
- "is_usable": false,
44
- "is_gene_available": false,
45
- "is_trait_available": false,
46
- "is_available": false,
47
- "is_biased": null,
48
- "has_age": null,
49
- "has_gender": null,
50
- "sample_size": null
51
- }
52
- }
 
1
+ {"GSE79263": {"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": 86, "note": ""}, "GSE48828": {"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": "WARNING: Trait distribution after preprocessing: {}. Extremely imbalanced if minor class <10%."}, "GSE13608": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": true, "has_gender": true, "sample_size": 68, "note": "INFO: Trait class imbalance; 3 DMD cases out of 68 samples after preprocessing."}, "GSE109178": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}, "TCGA_Duchenne_Muscular_Dystrophy": {"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/Eczema/GSE32924.csv ADDED
The diff for this file is too large to render. See raw diff
 
output/preprocess/Eczema/clinical_data/GSE120899.csv CHANGED
@@ -1,2 +1,2 @@
1
  ,GSM3418016,GSM3418017,GSM3418018,GSM3418019,GSM3418020,GSM3418021,GSM3418022,GSM3418023,GSM3418024,GSM3418025,GSM3418026,GSM3418027,GSM3418028,GSM3418029,GSM3418030,GSM3418031,GSM3418032,GSM3418033,GSM3418034,GSM3418035,GSM3418036,GSM3418037,GSM3418038,GSM3418039,GSM3418040,GSM3418041,GSM3418042,GSM3418043,GSM3418044,GSM3418045,GSM3418046,GSM3418047,GSM3418048,GSM3418049,GSM3418050,GSM3418051,GSM3418052,GSM3418053,GSM3418054,GSM3418055,GSM3418056,GSM3418057,GSM3418058,GSM3418059,GSM3418060,GSM3418061,GSM3418062,GSM3418063,GSM3418064,GSM3418065,GSM3418066,GSM3418067,GSM3418068,GSM3418069,GSM3418070,GSM3418071,GSM3418072,GSM3418073
2
- Eczema,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.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,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0
 
1
  ,GSM3418016,GSM3418017,GSM3418018,GSM3418019,GSM3418020,GSM3418021,GSM3418022,GSM3418023,GSM3418024,GSM3418025,GSM3418026,GSM3418027,GSM3418028,GSM3418029,GSM3418030,GSM3418031,GSM3418032,GSM3418033,GSM3418034,GSM3418035,GSM3418036,GSM3418037,GSM3418038,GSM3418039,GSM3418040,GSM3418041,GSM3418042,GSM3418043,GSM3418044,GSM3418045,GSM3418046,GSM3418047,GSM3418048,GSM3418049,GSM3418050,GSM3418051,GSM3418052,GSM3418053,GSM3418054,GSM3418055,GSM3418056,GSM3418057,GSM3418058,GSM3418059,GSM3418060,GSM3418061,GSM3418062,GSM3418063,GSM3418064,GSM3418065,GSM3418066,GSM3418067,GSM3418068,GSM3418069,GSM3418070,GSM3418071,GSM3418072,GSM3418073
2
+ Eczema,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,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
output/preprocess/Eczema/clinical_data/GSE123086.csv CHANGED
@@ -1,4 +1,4 @@
1
- 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29
2
- ,,,,,1.0,0.0,,,,,,,,,,,,,,,,,,,,,,,
3
- 56.0,,20.0,51.0,37.0,61.0,31.0,41.0,80.0,53.0,73.0,60.0,76.0,77.0,74.0,69.0,81.0,70.0,82.0,67.0,78.0,72.0,66.0,36.0,45.0,65.0,48.0,50.0,24.0,42.0
4
- 1.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
2
+ Eczema,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
+ Age,56.0,,20.0,51.0,37.0,61.0,,31.0,56.0,41.0,61.0,,80.0,53.0,61.0,73.0,60.0,76.0,77.0,74.0,69.0,77.0,81.0,70.0,82.0,69.0,82.0,67.0,67.0,78.0,67.0,74.0,,51.0,72.0,66.0,80.0,36.0,67.0,31.0,31.0,45.0,56.0,65.0,53.0,48.0,50.0,76.0,,24.0,42.0,76.0,22.0,,23.0,34.0,43.0,47.0,24.0,55.0,48.0,58.0,30.0,28.0,41.0,63.0,55.0,55.0,67.0,47.0,46.0,49.0,23.0,68.0,39.0,24.0,36.0,58.0,38.0,27.0,67.0,61.0,69.0,63.0,60.0,17.0,10.0,9.0,13.0,10.0,13.0,15.0,12.0,13.0,81.0,94.0,51.0,40.0,,97.0,23.0,93.0,58.0,28.0,54.0,15.0,8.0,11.0,12.0,8.0,14.0,8.0,10.0,14.0,13.0,40.0,52.0,42.0,29.0,43.0,41.0,54.0,42.0,49.0,45.0,56.0,64.0,71.0,48.0,20.0,53.0,32.0,26.0,28.0,47.0,24.0,48.0,,19.0,41.0,38.0,,15.0,12.0,13.0,,11.0,,16.0,11.0,,35.0,26.0,39.0,46.0,42.0,20.0,69.0,69.0,47.0,47.0,56.0,54.0,53.0,50.0,22.0
4
+ Gender,1.0,,0.0,0.0,1.0,1.0,,1.0,0.0,0.0,0.0,,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,,0.0,0.0,1.0,1.0,,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,,0.0,0.0,0.0,,0.0,1.0,0.0,,1.0,,1.0,1.0,,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0
output/preprocess/Eczema/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
- Eczema,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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
 
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
+ Eczema,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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/Eczema/clinical_data/GSE182740.csv CHANGED
@@ -1,4 +1,2 @@
1
  ,GSM5535864,GSM5535865,GSM5535866,GSM5535867,GSM5535868,GSM5535869,GSM5535870,GSM5535871,GSM5535872,GSM5535873,GSM5535874,GSM5535875,GSM5535876,GSM5535877,GSM5535878,GSM5535879,GSM5535880,GSM5535881,GSM5535882,GSM5535883,GSM5535884,GSM5535885,GSM5535886,GSM5535887,GSM5535888,GSM5535889,GSM5535890,GSM5535891,GSM5535892,GSM5535893,GSM5535894,GSM5535895,GSM5535896,GSM5535897,GSM5535898,GSM5535899,GSM5535900,GSM5535901,GSM5535902,GSM5535903,GSM5535904,GSM5535905,GSM5535906,GSM5535907,GSM5535908,GSM5535909,GSM5535910,GSM5535911,GSM5535912,GSM5535913,GSM5535914,GSM5535915,GSM5535916,GSM5535917,GSM5535918,GSM5535919,GSM5535920,GSM5535921,GSM5535922,GSM5535923,GSM5535924,GSM5535925,GSM5535926,GSM5535927,GSM5535928,GSM5535929,GSM5535930,GSM5535931,GSM5535932,GSM5535933,GSM5535934,GSM5535935,GSM5535936,GSM5535937,GSM5535938
2
- Eczema,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
3
- Age,19.0,41.0,41.0,46.0,46.0,36.0,36.0,81.0,81.0,39.0,51.0,17.0,35.0,29.0,43.0,43.0,42.0,42.0,13.0,13.0,14.0,36.0,17.0,36.0,21.0,21.0,18.0,18.0,30.0,30.0,17.0,17.0,16.0,14.0,16.0,12.0,12.0,16.0,16.0,32.0,32.0,14.0,14.0,30.0,14.0,30.0,29.0,29.0,33.0,33.0,12.0,12.0,19.0,19.0,36.0,76.0,36.0,17.0,17.0,18.0,18.0,38.0,38.0,19.0,76.0,76.0,76.0,35.0,35.0,0.0,0.0,0.0,0.0,0.0,0.0
4
- Gender,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
 
1
  ,GSM5535864,GSM5535865,GSM5535866,GSM5535867,GSM5535868,GSM5535869,GSM5535870,GSM5535871,GSM5535872,GSM5535873,GSM5535874,GSM5535875,GSM5535876,GSM5535877,GSM5535878,GSM5535879,GSM5535880,GSM5535881,GSM5535882,GSM5535883,GSM5535884,GSM5535885,GSM5535886,GSM5535887,GSM5535888,GSM5535889,GSM5535890,GSM5535891,GSM5535892,GSM5535893,GSM5535894,GSM5535895,GSM5535896,GSM5535897,GSM5535898,GSM5535899,GSM5535900,GSM5535901,GSM5535902,GSM5535903,GSM5535904,GSM5535905,GSM5535906,GSM5535907,GSM5535908,GSM5535909,GSM5535910,GSM5535911,GSM5535912,GSM5535913,GSM5535914,GSM5535915,GSM5535916,GSM5535917,GSM5535918,GSM5535919,GSM5535920,GSM5535921,GSM5535922,GSM5535923,GSM5535924,GSM5535925,GSM5535926,GSM5535927,GSM5535928,GSM5535929,GSM5535930,GSM5535931,GSM5535932,GSM5535933,GSM5535934,GSM5535935,GSM5535936,GSM5535937,GSM5535938
2
+ Eczema,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0
 
 
output/preprocess/Eczema/clinical_data/GSE32924.csv CHANGED
@@ -1,2 +1,2 @@
1
- ,GSM1,GSM2,GSM3,GSM4,GSM5,GSM6,GSM7,GSM8,GSM9,GSM10,GSM11,GSM12,GSM13,GSM14,GSM15,GSM16,GSM17,GSM18,GSM19,GSM20,GSM21,GSM22
2
- Eczema,1.0,1.0,0.0,,,,,,,,,,,,,,,,,,,
 
1
+ GSM815426,GSM815427,GSM815428,GSM815429,GSM815430,GSM815431,GSM815432,GSM815433,GSM815434,GSM815435,GSM815436,GSM815437,GSM815438,GSM815439,GSM815440,GSM815441,GSM815442,GSM815443,GSM815444,GSM815445,GSM815446,GSM815447,GSM815448,GSM815449,GSM815450,GSM815451,GSM815452,GSM815453,GSM815454,GSM815455,GSM815456,GSM815457,GSM815458
2
+ 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
output/preprocess/Eczema/clinical_data/GSE57225.csv CHANGED
@@ -1,4 +1,4 @@
1
  ,GSM1377461,GSM1377462,GSM1377463,GSM1377464,GSM1377465,GSM1377466,GSM1377467,GSM1377468,GSM1377469,GSM1377470,GSM1377471,GSM1377472,GSM1377473,GSM1377474,GSM1377475,GSM1377476,GSM1377477,GSM1377478,GSM1377479,GSM1377480,GSM1377481,GSM1377482,GSM1377483,GSM1377484,GSM1377485,GSM1377486,GSM1377487,GSM1377488,GSM1377489,GSM1377490,GSM1377491,GSM1377492,GSM1377493,GSM1377494,GSM1377495,GSM1377496,GSM1377497,GSM1377498,GSM1377499,GSM1377500,GSM1377501,GSM1377502,GSM1377503,GSM1377504,GSM1377505,GSM1377506,GSM1377507,GSM1377508,GSM1377509,GSM1377510,GSM1377511,GSM1377512,GSM1377513,GSM1377514,GSM1377515,GSM1377516,GSM1377517,GSM1377518,GSM1377519,GSM1377520,GSM1377521,GSM1377522
2
- Eczema,,1.0,,1.0,0.0,,1.0,,1.0,,1.0,,1.0,0.0,,1.0,0.0,,1.0,0.0,,1.0,0.0,,1.0,0.0,,1.0,0.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,,1.0,1.0,0.0,,1.0,0.0,1.0,0.0,,0.0,1.0,0.0,
3
  Age,48.0,48.0,40.0,40.0,65.0,65.0,65.0,35.0,35.0,27.0,27.0,65.0,65.0,72.0,72.0,72.0,33.0,33.0,33.0,48.0,48.0,48.0,58.0,58.0,58.0,65.0,65.0,65.0,56.0,56.0,56.0,46.0,46.0,46.0,55.0,55.0,46.0,46.0,46.0,53.0,53.0,31.0,31.0,31.0,42.0,42.0,42.0,43.0,43.0,43.0,33.0,33.0,33.0,20.0,20.0,41.0,41.0,41.0,20.0,48.0,48.0,48.0
4
  Gender,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0
 
1
  ,GSM1377461,GSM1377462,GSM1377463,GSM1377464,GSM1377465,GSM1377466,GSM1377467,GSM1377468,GSM1377469,GSM1377470,GSM1377471,GSM1377472,GSM1377473,GSM1377474,GSM1377475,GSM1377476,GSM1377477,GSM1377478,GSM1377479,GSM1377480,GSM1377481,GSM1377482,GSM1377483,GSM1377484,GSM1377485,GSM1377486,GSM1377487,GSM1377488,GSM1377489,GSM1377490,GSM1377491,GSM1377492,GSM1377493,GSM1377494,GSM1377495,GSM1377496,GSM1377497,GSM1377498,GSM1377499,GSM1377500,GSM1377501,GSM1377502,GSM1377503,GSM1377504,GSM1377505,GSM1377506,GSM1377507,GSM1377508,GSM1377509,GSM1377510,GSM1377511,GSM1377512,GSM1377513,GSM1377514,GSM1377515,GSM1377516,GSM1377517,GSM1377518,GSM1377519,GSM1377520,GSM1377521,GSM1377522
2
+ Eczema,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0
3
  Age,48.0,48.0,40.0,40.0,65.0,65.0,65.0,35.0,35.0,27.0,27.0,65.0,65.0,72.0,72.0,72.0,33.0,33.0,33.0,48.0,48.0,48.0,58.0,58.0,58.0,65.0,65.0,65.0,56.0,56.0,56.0,46.0,46.0,46.0,55.0,55.0,46.0,46.0,46.0,53.0,53.0,31.0,31.0,31.0,42.0,42.0,42.0,43.0,43.0,43.0,33.0,33.0,33.0,20.0,20.0,41.0,41.0,41.0,20.0,48.0,48.0,48.0
4
  Gender,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0
output/preprocess/Eczema/code/GSE120899.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Eczema"
6
+ cohort = "GSE120899"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Eczema"
10
+ in_cohort_dir = "../DATA/GEO/Eczema/GSE120899"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Eczema/GSE120899.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Eczema/gene_data/GSE120899.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Eczema/clinical_data/GSE120899.csv"
16
+ json_path = "./output/z2/preprocess/Eczema/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 # Background mentions "mRNA expression" analysis
41
+
42
+ # 2. Variable Availability and Data Type Conversion
43
+
44
+ # 2.1 Data Availability
45
+ trait_row = 1 # tissue types indicate disease status: 'Normal' vs 'lesional skin'/'non-lesional skin'
46
+ age_row = None # No age information available
47
+ gender_row = None # No gender information available
48
+
49
+ # 2.2 Data Type Conversion
50
+ def convert_trait(value):
51
+ """Convert tissue type to binary eczema status"""
52
+ if ':' in str(value):
53
+ tissue_type = str(value).split(':')[1].strip()
54
+ else:
55
+ tissue_type = str(value).strip()
56
+
57
+ if tissue_type.lower() == 'normal':
58
+ return 0 # No eczema
59
+ elif tissue_type.lower() in ['lesional skin', 'non-lesional skin']:
60
+ return 1 # Has eczema
61
+ else:
62
+ return None
63
+
64
+ def convert_age(value):
65
+ """Age conversion function (not used since age_row is None)"""
66
+ return None
67
+
68
+ def convert_gender(value):
69
+ """Gender conversion function (not used since gender_row is None)"""
70
+ return None
71
+
72
+ # 3. Save Metadata
73
+ is_trait_available = trait_row is not None
74
+ save_cohort_info = validate_and_save_cohort_info(
75
+ is_final=False,
76
+ cohort=cohort,
77
+ info_path=json_path,
78
+ is_gene_available=is_gene_available,
79
+ is_trait_available=is_trait_available
80
+ )
81
+
82
+ # 4. Clinical Feature Extraction
83
+ if trait_row is not None:
84
+ selected_clinical_data = geo_select_clinical_features(
85
+ clinical_data, trait, trait_row, convert_trait,
86
+ age_row, convert_age, gender_row, convert_gender
87
+ )
88
+
89
+ csv_path = out_clinical_data_file
90
+ selected_clinical_data.to_csv(csv_path)
91
+
92
+ print("Clinical data preview:")
93
+ print(preview_df(selected_clinical_data))
94
+
95
+ # Step 3: Gene Data Extraction
96
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
97
+ gene_data = get_genetic_data(matrix_file)
98
+
99
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
100
+ print(gene_data.index[:20])
101
+
102
+ # Step 4: Gene Identifier Review
103
+ # Review the gene identifiers from the previous step output
104
+ sample_identifiers = ['1007_s_at', '1053_at', '117_at', '121_at', '1255_g_at', '1294_at',
105
+ '1316_at', '1320_at', '1405_i_at', '1431_at', '1438_at', '1487_at',
106
+ '1494_f_at', '1552256_a_at', '1552257_a_at', '1552258_at', '1552261_at',
107
+ '1552263_at', '1552264_a_at', '1552266_at']
108
+
109
+ print("Sample gene identifiers:")
110
+ print(f"First few identifiers: {sample_identifiers[:10]}")
111
+ print(f"Pattern analysis:")
112
+ print(f"- All identifiers contain '_at' suffixes")
113
+ print(f"- Format appears to be numeric/alphanumeric + suffix")
114
+ print(f"- These are Affymetrix probe IDs, not human gene symbols")
115
+ print(f"- Gene symbols would be like 'BRCA1', 'TP53', 'EGFR', etc.")
116
+
117
+ requires_gene_mapping = True
118
+
119
+ # Step 5: Gene Annotation
120
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
121
+ gene_annotation = get_gene_annotation(soft_file)
122
+
123
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
124
+ print("Gene annotation preview:")
125
+ print(preview_df(gene_annotation))
126
+
127
+ # Step 6: Gene Identifier Mapping
128
+ # 1. Based on the previews, 'ID' column contains probe identifiers that match gene expression data,
129
+ # and 'Gene Symbol' column contains the gene symbols we need to map to
130
+ prob_col = 'ID'
131
+ gene_col = 'Gene Symbol'
132
+
133
+ # 2. Get gene mapping dataframe by extracting the two relevant columns
134
+ gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col)
135
+
136
+ # 3. Apply gene mapping to convert probe-level measurements to gene expression data
137
+ gene_data = apply_gene_mapping(gene_data, gene_mapping)
138
+
139
+ print(f"Gene expression data shape after mapping: {gene_data.shape}")
140
+ print(f"First few gene symbols: {list(gene_data.index[:10])}")
141
+
142
+ # Step 7: Data Normalization and Linking
143
+ # 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
144
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
145
+ normalized_gene_data.to_csv(out_gene_data_file)
146
+
147
+ # 2. Link the clinical and genetic data with the 'geo_link_clinical_genetic_data' function from the library.
148
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
149
+
150
+ # 3. Handle missing values in the linked data
151
+ linked_data = handle_missing_values(linked_data, trait)
152
+
153
+ # 4. Determine whether the trait and some demographic features are severely biased, and remove biased features.
154
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
155
+
156
+ # 5. Conduct quality check and save the cohort information.
157
+ is_usable = validate_and_save_cohort_info(True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data)
158
+
159
+ # 6. If the linked data is usable, save it as a CSV file to 'out_data_file'.
160
+ if is_usable:
161
+ unbiased_linked_data.to_csv(out_data_file)
output/preprocess/Eczema/code/GSE123086.py ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Eczema"
6
+ cohort = "GSE123086"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Eczema"
10
+ in_cohort_dir = "../DATA/GEO/Eczema/GSE123086"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/z2/preprocess/Eczema/GSE123086.csv"
14
+ out_gene_data_file = "./output/z2/preprocess/Eczema/gene_data/GSE123086.csv"
15
+ out_clinical_data_file = "./output/z2/preprocess/Eczema/clinical_data/GSE123086.csv"
16
+ json_path = "./output/z2/preprocess/Eczema/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
41
+
42
+ # 2. Variable Availability and Data Type Conversion
43
+
44
+ # 2.1 Data Availability
45
+ trait_row = 1 # 'primary diagnosis: ATOPIC_ECZEMA' found in key 1
46
+ age_row = 3 # 'age: X' values found in key 3
47
+ gender_row = 2 # 'Sex: Female', 'Sex: Male' found in key 2
48
+
49
+ # 2.2 Data Type Conversion
50
+ def convert_trait(value):
51
+ """Convert trait values to binary (0/1) for Eczema study"""
52
+ if value is None or pd.isna(value):
53
+ return None
54
+ if ':' in str(value):
55
+ actual_value = str(value).split(':')[1].strip()
56
+ else:
57
+ actual_value = str(value).strip()
58
+
59
+ if actual_value.upper() == 'ATOPIC_ECZEMA':
60
+ return 1
61
+ else:
62
+ return 0
63
+
64
+ def convert_age(value):
65
+ """Convert age values to continuous numeric type"""
66
+ if value is None or pd.isna(value):
67
+ return None
68
+ if ':' in str(value):
69
+ actual_value = str(value).split(':')[1].strip()
70
+ else:
71
+ actual_value = str(value).strip()
72
+
73
+ try:
74
+ return float(actual_value)
75
+ except:
76
+ return None
77
+
78
+ def convert_gender(value):
79
+ """Convert gender values to binary (0=Female, 1=Male)"""
80
+ if value is None or pd.isna(value):
81
+ return None
82
+ if ':' in str(value):
83
+ actual_value = str(value).split(':')[1].strip()
84
+ else:
85
+ actual_value = str(value).strip()
86
+
87
+ if actual_value.upper() == 'FEMALE':
88
+ return 0
89
+ elif actual_value.upper() == 'MALE':
90
+ return 1
91
+ else:
92
+ return None
93
+
94
+ # 3. Save Metadata
95
+ is_trait_available = trait_row is not None
96
+ validate_and_save_cohort_info(is_final=False, cohort=cohort, info_path=json_path,
97
+ is_gene_available=is_gene_available, is_trait_available=is_trait_available)
98
+
99
+ # 4. Clinical Feature Extraction
100
+ if trait_row is not None:
101
+ selected_clinical_df = geo_select_clinical_features(clinical_data, trait, trait_row, convert_trait,
102
+ age_row, convert_age, gender_row, convert_gender)
103
+ csv_data = preview_df(selected_clinical_df)
104
+ print("Clinical data preview:")
105
+ print(csv_data)
106
+
107
+ # Save to CSV
108
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
109
+ selected_clinical_df.to_csv(out_clinical_data_file)
110
+
111
+ # Step 3: Gene Data Extraction
112
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
113
+ gene_data = get_genetic_data(matrix_file)
114
+
115
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
116
+ print(gene_data.index[:20])
117
+
118
+ # Step 4: Gene Identifier Review
119
+ # The gene identifiers from the previous step are numeric strings
120
+ gene_identifiers = ['1', '2', '3', '9', '10', '12', '13', '14', '15', '16', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27']
121
+
122
+ print("Sample gene identifiers:", gene_identifiers[:10])
123
+ print("Gene identifier characteristics:")
124
+ print(f"- All numeric: {all(id.isdigit() for id in gene_identifiers)}")
125
+ print(f"- Example format: {gene_identifiers[0]} (type: {type(gene_identifiers[0])})")
126
+
127
+ # Human gene symbols are typically alphabetic names like 'BRCA1', 'TP53', 'EGFR'
128
+ # These numeric identifiers are likely probe IDs, Entrez Gene IDs, or other database identifiers
129
+ # that need to be mapped to actual gene symbols for biological interpretation
130
+
131
+ requires_gene_mapping = True
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. Print all column names to see the complete structure
138
+ print("All columns:", gene_annotation.columns.tolist())
139
+ print("Dataframe shape:", gene_annotation.shape)
140
+
141
+ # 3. Use the 'preview_df' function from the library to preview the data with increased scope
142
+ print("Gene annotation preview:")
143
+ print(preview_df(gene_annotation, max_items=500))
144
+
145
+ # Step 6: Gene Identifier Mapping
146
+ # 1. Let's examine the gene annotation more thoroughly to find actual gene symbols
147
+ print("Gene annotation full structure:")
148
+ print(f"Columns: {gene_annotation.columns.tolist()}")
149
+ print(f"Shape: {gene_annotation.shape}")
150
+
151
+ # Let's look at a larger sample to see if there are patterns we missed
152
+ print("\nFirst 20 rows of gene annotation:")
153
+ for i in range(min(20, len(gene_annotation))):
154
+ print(f"Row {i}: ID={gene_annotation.iloc[i]['ID']}, ENTREZ_GENE_ID={gene_annotation.iloc[i]['ENTREZ_GENE_ID']}, SPOT_ID={gene_annotation.iloc[i]['SPOT_ID']}")
155
+
156
+ # Check if there are any non-numeric values in ENTREZ_GENE_ID that might be gene symbols
157
+ print("\nUnique ENTREZ_GENE_ID values (first 50):")
158
+ unique_entrez = gene_annotation['ENTREZ_GENE_ID'].unique()
159
+ print(unique_entrez[:50])
160
+
161
+ # Let's also check if the SOFT file has additional annotation sections
162
+ print("\nRe-examining SOFT file structure for gene symbols...")
163
+ # Try extracting with different prefixes to see if we missed gene symbol information
164
+ alternative_annotation = filter_content_by_prefix(soft_file, prefixes_a=['!platform_table_begin'],
165
+ unselect=False, source_type='file', return_df_a=False)
166
+ if alternative_annotation[0]:
167
+ print("Found platform_table_begin section:")
168
+ print(alternative_annotation[0][:1000]) # First 1000 characters
169
+
170
+ # Since the numeric IDs appear to be Entrez Gene IDs, let's try a different approach
171
+ # Use the numeric IDs directly as gene identifiers without mapping
172
+ print(f"\nUsing numeric gene identifiers directly...")
173
+ print(f"Original gene expression shape: {gene_data.shape}")
174
+ print(f"Gene identifiers (first 10): {gene_data.index[:10].tolist()}")
175
+
176
+ # Since mapping failed, let's keep the original gene_data as is
177
+ # The numeric identifiers are likely Entrez Gene IDs which can be used for analysis
178
+ gene_data = get_genetic_data(matrix_file) # Restore original data
179
+ print(f"Final gene expression data shape: {gene_data.shape}")
180
+ print(f"Final gene identifiers (first 10): {gene_data.index[:10].tolist()}")
181
+
182
+ # Step 7: Data Normalization and Linking
183
+ # 1. Normalize gene symbols and save
184
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
185
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
186
+ normalized_gene_data.to_csv(out_gene_data_file)
187
+
188
+ print(f"Normalized gene data shape: {normalized_gene_data.shape}")
189
+ print(f"Clinical data shape: {selected_clinical_df.shape}")
190
+
191
+ # 2. Link clinical and genetic data
192
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
193
+ print(f"Linked data shape after linking: {linked_data.shape}")
194
+ print(f"Missing values in trait column before handling: {linked_data[trait].isna().sum()}")
195
+
196
+ # 3. Handle missing values with debugging
197
+ print("Before missing value handling:")
198
+ print(f"Total samples: {len(linked_data)}")
199
+ print(f"Samples with trait data: {linked_data[trait].notna().sum()}")
200
+ if 'Age' in linked_data.columns:
201
+ print(f"Samples with age data: {linked_data['Age'].notna().sum()}")
202
+ if 'Gender' in linked_data.columns:
203
+ print(f"Samples with gender data: {linked_data['Gender'].notna().sum()}")
204
+
205
+ linked_data = handle_missing_values(linked_data, trait)
206
+ print(f"Linked data shape after missing value handling: {linked_data.shape}")
207
+
208
+ # 4. Check for biased features
209
+ is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
210
+
211
+ # 5. Validate and save cohort info
212
+ is_usable = validate_and_save_cohort_info(True, cohort, json_path, True, True, is_trait_biased, unbiased_linked_data)
213
+
214
+ # 6. Save final data if usable
215
+ if is_usable:
216
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
217
+ unbiased_linked_data.to_csv(out_data_file)
218
+ print(f"Final usable data saved with shape: {unbiased_linked_data.shape}")
219
+ else:
220
+ print("Dataset determined to be unusable - not saved")