Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +16 -0
- p1/preprocess/COVID-19/GSE212865.csv +3 -0
- p1/preprocess/COVID-19/GSE212866.csv +3 -0
- p1/preprocess/COVID-19/gene_data/GSE212865.csv +3 -0
- p1/preprocess/COVID-19/gene_data/GSE212866.csv +3 -0
- p1/preprocess/Crohns_Disease/GSE169568.csv +3 -0
- p1/preprocess/Crohns_Disease/gene_data/GSE169568.csv +3 -0
- p1/preprocess/Crohns_Disease/gene_data/GSE186963.csv +3 -0
- p1/preprocess/Crohns_Disease/gene_data/GSE207022.csv +3 -0
- p1/preprocess/Crohns_Disease/gene_data/GSE83448.csv +0 -0
- p1/preprocess/Cystic_Fibrosis/GSE100521.csv +3 -0
- p1/preprocess/Cystic_Fibrosis/GSE107846.csv +0 -0
- p1/preprocess/Cystic_Fibrosis/GSE129168.csv +0 -0
- p1/preprocess/Cystic_Fibrosis/clinical_data/GSE100521.csv +4 -0
- p1/preprocess/Cystic_Fibrosis/clinical_data/GSE107846.csv +4 -0
- p1/preprocess/Cystic_Fibrosis/clinical_data/GSE129168.csv +2 -0
- p1/preprocess/Cystic_Fibrosis/clinical_data/GSE67698.csv +2 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE100521.py +213 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE107846.py +184 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE129168.py +169 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE139038.py +192 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE142610.py +100 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE53543.py +185 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE60690.py +165 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE67698.py +178 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE71799.py +125 -0
- p1/preprocess/Cystic_Fibrosis/code/GSE76347.py +144 -0
- p1/preprocess/Cystic_Fibrosis/code/TCGA.py +54 -0
- p1/preprocess/Cystic_Fibrosis/gene_data/GSE100521.csv +3 -0
- p1/preprocess/Cystic_Fibrosis/gene_data/GSE107846.csv +0 -0
- p1/preprocess/Cystic_Fibrosis/gene_data/GSE129168.csv +0 -0
- p1/preprocess/Cystic_Fibrosis/gene_data/GSE139038.csv +0 -0
- p1/preprocess/Cystic_Fibrosis/gene_data/GSE53543.csv +3 -0
- p1/preprocess/Cystic_Fibrosis/gene_data/GSE67698.csv +3 -0
- p1/preprocess/Cystic_Fibrosis/gene_data/GSE71799.csv +3 -0
- p1/preprocess/Cystic_Fibrosis/gene_data/GSE76347.csv +3 -0
- p1/preprocess/Depression/GSE110298.csv +0 -0
- p1/preprocess/Depression/GSE208668.csv +0 -0
- p1/preprocess/Depression/GSE99725.csv +0 -0
- p1/preprocess/Depression/clinical_data/GSE110298.csv +4 -0
- p1/preprocess/Depression/clinical_data/GSE201332.csv +4 -0
- p1/preprocess/Depression/clinical_data/GSE208668.csv +4 -0
- p1/preprocess/Depression/clinical_data/GSE99725.csv +2 -0
- p1/preprocess/Depression/code/GSE110298.py +224 -0
- p1/preprocess/Depression/code/GSE128387.py +106 -0
- p1/preprocess/Depression/code/GSE135524.py +166 -0
- p1/preprocess/Depression/code/GSE138297.py +147 -0
- p1/preprocess/Depression/code/GSE149980.py +125 -0
- p1/preprocess/Depression/code/GSE201332.py +241 -0
- p1/preprocess/Depression/code/GSE208668.py +223 -0
.gitattributes
CHANGED
@@ -1032,3 +1032,19 @@ p1/preprocess/COVID-19/gene_data/GSE185658.csv filter=lfs diff=lfs merge=lfs -te
|
|
1032 |
p1/preprocess/COVID-19/gene_data/GSE213313.csv filter=lfs diff=lfs merge=lfs -text
|
1033 |
p1/preprocess/Crohns_Disease/GSE207022.csv filter=lfs diff=lfs merge=lfs -text
|
1034 |
p1/preprocess/Cervical_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1032 |
p1/preprocess/COVID-19/gene_data/GSE213313.csv filter=lfs diff=lfs merge=lfs -text
|
1033 |
p1/preprocess/Crohns_Disease/GSE207022.csv filter=lfs diff=lfs merge=lfs -text
|
1034 |
p1/preprocess/Cervical_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
1035 |
+
p1/preprocess/COVID-19/GSE212865.csv filter=lfs diff=lfs merge=lfs -text
|
1036 |
+
p1/preprocess/COVID-19/GSE212866.csv filter=lfs diff=lfs merge=lfs -text
|
1037 |
+
p1/preprocess/Crohns_Disease/gene_data/GSE207022.csv filter=lfs diff=lfs merge=lfs -text
|
1038 |
+
p1/preprocess/Crohns_Disease/GSE169568.csv filter=lfs diff=lfs merge=lfs -text
|
1039 |
+
p1/preprocess/Crohns_Disease/gene_data/GSE186963.csv filter=lfs diff=lfs merge=lfs -text
|
1040 |
+
p1/preprocess/Cystic_Fibrosis/GSE100521.csv filter=lfs diff=lfs merge=lfs -text
|
1041 |
+
p1/preprocess/COVID-19/gene_data/GSE212865.csv filter=lfs diff=lfs merge=lfs -text
|
1042 |
+
p1/preprocess/COVID-19/gene_data/GSE212866.csv filter=lfs diff=lfs merge=lfs -text
|
1043 |
+
p1/preprocess/Cystic_Fibrosis/gene_data/GSE100521.csv filter=lfs diff=lfs merge=lfs -text
|
1044 |
+
p1/preprocess/Crohns_Disease/gene_data/GSE169568.csv filter=lfs diff=lfs merge=lfs -text
|
1045 |
+
p1/preprocess/Cystic_Fibrosis/gene_data/GSE76347.csv filter=lfs diff=lfs merge=lfs -text
|
1046 |
+
p1/preprocess/Cystic_Fibrosis/gene_data/GSE53543.csv filter=lfs diff=lfs merge=lfs -text
|
1047 |
+
p1/preprocess/Cystic_Fibrosis/gene_data/GSE67698.csv filter=lfs diff=lfs merge=lfs -text
|
1048 |
+
p1/preprocess/Cystic_Fibrosis/gene_data/GSE71799.csv filter=lfs diff=lfs merge=lfs -text
|
1049 |
+
p1/preprocess/Depression/gene_data/GSE138297.csv filter=lfs diff=lfs merge=lfs -text
|
1050 |
+
p1/preprocess/Depression/gene_data/GSE149980.csv filter=lfs diff=lfs merge=lfs -text
|
p1/preprocess/COVID-19/GSE212865.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cb042e755616c53d4990b419a105ad11e2532e37aab30e3fa0f45aae0070503e
|
3 |
+
size 51823778
|
p1/preprocess/COVID-19/GSE212866.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cb042e755616c53d4990b419a105ad11e2532e37aab30e3fa0f45aae0070503e
|
3 |
+
size 51823778
|
p1/preprocess/COVID-19/gene_data/GSE212865.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:adb0aac4837a250cbb20bc4c1ca80e27ba417f7ffff99bdd849b49805c8a32cc
|
3 |
+
size 51823225
|
p1/preprocess/COVID-19/gene_data/GSE212866.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:adb0aac4837a250cbb20bc4c1ca80e27ba417f7ffff99bdd849b49805c8a32cc
|
3 |
+
size 51823225
|
p1/preprocess/Crohns_Disease/GSE169568.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f25a25a74716d1efc79f6bfaa0ad07115cfbef83094de8a7b51869c109ff74e0
|
3 |
+
size 38295205
|
p1/preprocess/Crohns_Disease/gene_data/GSE169568.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:49bdc43ec969dd89b6a8063c43713a6aa25567edd04f0b3ebd4bc03adc0e156d
|
3 |
+
size 38292518
|
p1/preprocess/Crohns_Disease/gene_data/GSE186963.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2fb5425699f7cacb17c55ffb49a08c0808fe0ffce2821001b47184b0d5230427
|
3 |
+
size 25484219
|
p1/preprocess/Crohns_Disease/gene_data/GSE207022.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:209048a473969d55d990dabecb6545c7f60f0e58a27061dd21378272959356bf
|
3 |
+
size 19292986
|
p1/preprocess/Crohns_Disease/gene_data/GSE83448.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Cystic_Fibrosis/GSE100521.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4f1e611df5e91917f2323b9f896cec66c19db812b5b1b564896bbce42882e5e5
|
3 |
+
size 18339664
|
p1/preprocess/Cystic_Fibrosis/GSE107846.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Cystic_Fibrosis/GSE129168.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Cystic_Fibrosis/clinical_data/GSE100521.csv
ADDED
@@ -0,0 +1,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
|
p1/preprocess/Cystic_Fibrosis/clinical_data/GSE107846.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GSM2881538,GSM2881539,GSM2881540,GSM2881541,GSM2881542,GSM2881543,GSM2881544,GSM2881545,GSM2881546,GSM2881547,GSM2881548,GSM2881549,GSM2881550,GSM2881551,GSM2881552,GSM2881553,GSM2881554,GSM2881555,GSM2881556,GSM2881557,GSM2881558,GSM2881559,GSM2881560,GSM2881561,GSM2881562,GSM2881563,GSM2881564,GSM2881565,GSM2881566,GSM2881567,GSM2881568,GSM2881569,GSM2881570,GSM2881571,GSM2881572,GSM2881573,GSM2881574,GSM2881575,GSM2881576,GSM2881577
|
2 |
+
0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,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 |
+
9.0,3.8,5.1,3.4,7.0,2.8,4.3,2.3,9.9,7.8,2.3,3.4,7.25,4.0,2.333,1.917,8.583,6.8,2.667,9.917,1.083,2.25,7.75,6.833,4.583,6.417,7.0,4.75,4.333,5.25,4.25,6.0,6.167,2.417,4.667,2.5,5.0,5.417,5.25,4.0
|
4 |
+
0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0
|
p1/preprocess/Cystic_Fibrosis/clinical_data/GSE129168.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GSM3701915,GSM3701916,GSM3701917,GSM3701918,GSM3701919,GSM3701920,GSM3701921,GSM3701922,GSM3701923,GSM3701924,GSM3701925,GSM3701926,GSM3701927,GSM3701928,GSM3701929,GSM3701930,GSM3701931,GSM3701932,GSM3701933,GSM3701934,GSM3701935,GSM3701936,GSM3701937,GSM3701938,GSM3701939,GSM3701940,GSM3701941,GSM3701942,GSM3701943,GSM3701944,GSM3701945,GSM3701946
|
2 |
+
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
|
p1/preprocess/Cystic_Fibrosis/clinical_data/GSE67698.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
,GSM1946634,GSM1946635,GSM1946636,GSM1946637,GSM1946638,GSM1946639,GSM1946640,GSM1946641,GSM1946642,GSM1946643,GSM1946644,GSM1946645,GSM1946646,GSM1946647,GSM1946648,GSM1946649,GSM1946650,GSM1946651,GSM1946652,GSM1946653,GSM1946654,GSM1946655,GSM1946656,GSM1946657,GSM1946658,GSM1946659,GSM1946660,GSM1946661,GSM1946662,GSM1946663,GSM1946664,GSM1946665,GSM1946666,GSM1946667,GSM1946668,GSM1946669,GSM1946670,GSM1946671,GSM1946672,GSM1946673,GSM1946674,GSM1946675,GSM1946676,GSM1946677,GSM1946678,GSM1946679,GSM1946680,GSM1946681,GSM1946682,GSM1946683,GSM1946684,GSM1946685,GSM1946686,GSM1946687,GSM1946688,GSM1946689,GSM1946690,GSM1946691,GSM1946692,GSM1946693,GSM1946694,GSM1946695,GSM1946696,GSM1946697,GSM1946698,GSM1946699,GSM1946700,GSM1946701,GSM1946702,GSM1946703,GSM1946704,GSM1946705,GSM1946706,GSM1946707,GSM1946708,GSM1946709,GSM1946710,GSM1946711,GSM1946712,GSM1946713,GSM1946714,GSM1946715,GSM1946716,GSM1946717,GSM1946718,GSM1946719,GSM1946720,GSM1946721,GSM1946722,GSM1946723,GSM1946724,GSM1946725,GSM1946726,GSM1946727,GSM1946728,GSM1946729,GSM1946730,GSM1946731,GSM1946732,GSM1946733,GSM1946734,GSM1946735,GSM1946736,GSM1946737,GSM1946738,GSM1946739,GSM1946740,GSM1946741,GSM1946742,GSM1946743,GSM1946744,GSM1946745,GSM1946746,GSM1946747,GSM1946748,GSM1946749,GSM1946750,GSM1946751,GSM1946752,GSM1946753,GSM1946754,GSM1946755
|
2 |
+
Cystic_Fibrosis,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
|
p1/preprocess/Cystic_Fibrosis/code/GSE100521.py
ADDED
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE100521.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE100521.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE100521.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
import re
|
37 |
+
import pandas as pd
|
38 |
+
|
39 |
+
# 1. Gene Expression Data Availability
|
40 |
+
is_gene_available = True # Based on the background info, this dataset has Illumina HumanHT-12 v4 microarray data
|
41 |
+
|
42 |
+
# 2. Variable Availability and Data Type Conversion
|
43 |
+
|
44 |
+
# 2.1 Find rows for trait, age, and gender
|
45 |
+
trait_row = 0 # row 0 contains CF vs Non CF info
|
46 |
+
age_row = 1 # row 1 contains age info
|
47 |
+
gender_row = 2 # row 2 contains gender info
|
48 |
+
|
49 |
+
# 2.2 Define data conversion functions
|
50 |
+
def convert_trait(value: str):
|
51 |
+
"""
|
52 |
+
Convert a string describing the subject's CF status to a binary value:
|
53 |
+
0 for Non-CF subject, 1 for CF patient.
|
54 |
+
Unknown values => None
|
55 |
+
"""
|
56 |
+
# Extract the part after the colon
|
57 |
+
parts = value.split(':')
|
58 |
+
if len(parts) < 2:
|
59 |
+
return None
|
60 |
+
val = parts[1].strip().lower()
|
61 |
+
if 'non cf subject' in val:
|
62 |
+
return 0
|
63 |
+
elif 'cf patient' in val:
|
64 |
+
return 1
|
65 |
+
else:
|
66 |
+
return None
|
67 |
+
|
68 |
+
def convert_age(value: str):
|
69 |
+
"""
|
70 |
+
Convert a string describing the age to a continuous (float) value.
|
71 |
+
Unknown values => None
|
72 |
+
"""
|
73 |
+
parts = value.split(':')
|
74 |
+
if len(parts) < 2:
|
75 |
+
return None
|
76 |
+
val = parts[1].strip()
|
77 |
+
# Attempt to convert to float
|
78 |
+
try:
|
79 |
+
return float(val)
|
80 |
+
except ValueError:
|
81 |
+
return None
|
82 |
+
|
83 |
+
def convert_gender(value: str):
|
84 |
+
"""
|
85 |
+
Convert a string describing gender to a binary value:
|
86 |
+
female => 0, male => 1
|
87 |
+
Unknown values => None
|
88 |
+
"""
|
89 |
+
parts = value.split(':')
|
90 |
+
if len(parts) < 2:
|
91 |
+
return None
|
92 |
+
val = parts[1].strip().lower()
|
93 |
+
if val == 'female':
|
94 |
+
return 0
|
95 |
+
elif val == 'male':
|
96 |
+
return 1
|
97 |
+
else:
|
98 |
+
return None
|
99 |
+
|
100 |
+
# We assume the variable "clinical_data" is available in this environment,
|
101 |
+
# containing the sample characteristics as a DataFrame.
|
102 |
+
|
103 |
+
# 3. Save Metadata (initial filtering)
|
104 |
+
is_trait_available = (trait_row is not None)
|
105 |
+
is_usable = validate_and_save_cohort_info(
|
106 |
+
is_final=False,
|
107 |
+
cohort=cohort,
|
108 |
+
info_path=json_path,
|
109 |
+
is_gene_available=is_gene_available,
|
110 |
+
is_trait_available=is_trait_available
|
111 |
+
)
|
112 |
+
|
113 |
+
# 4. Clinical Feature Extraction (only if trait_row is not None)
|
114 |
+
if trait_row is not None:
|
115 |
+
selected_clinical_df = geo_select_clinical_features(
|
116 |
+
clinical_df=clinical_data,
|
117 |
+
trait=trait,
|
118 |
+
trait_row=trait_row,
|
119 |
+
convert_trait=convert_trait,
|
120 |
+
age_row=age_row,
|
121 |
+
convert_age=convert_age,
|
122 |
+
gender_row=gender_row,
|
123 |
+
convert_gender=convert_gender
|
124 |
+
)
|
125 |
+
# Preview
|
126 |
+
preview_output = preview_df(selected_clinical_df)
|
127 |
+
print("Preview of selected clinical features:", preview_output)
|
128 |
+
|
129 |
+
# Save to CSV
|
130 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=True)
|
131 |
+
# STEP3
|
132 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
133 |
+
gene_data = get_genetic_data(matrix_file)
|
134 |
+
|
135 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
136 |
+
print(gene_data.index[:20])
|
137 |
+
# Based on biomedical expertise, 'ILMN_xxxxx' identifiers are Illumina probe IDs and not human gene symbols.
|
138 |
+
# Therefore, they require mapping to gene symbols.
|
139 |
+
|
140 |
+
print("requires_gene_mapping = True")
|
141 |
+
# STEP5
|
142 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
143 |
+
gene_annotation = get_gene_annotation(soft_file)
|
144 |
+
|
145 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
146 |
+
print("Gene annotation preview:")
|
147 |
+
print(preview_df(gene_annotation))
|
148 |
+
# STEP: Gene Identifier Mapping
|
149 |
+
|
150 |
+
# 1. Identify the columns in the gene_annotation dataframe that match the probe identifiers in gene_data (ILMN_xxx)
|
151 |
+
# and those that represent gene symbols. From the annotation preview, 'ID' matches 'ILMN_xxx' and 'Symbol' is the gene symbol.
|
152 |
+
|
153 |
+
# 2. Create a gene mapping dataframe using the identified columns
|
154 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol')
|
155 |
+
|
156 |
+
# 3. Convert probe-level measurements to gene-level expression data by applying the mapping
|
157 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
158 |
+
|
159 |
+
# (Optional) Quick check - display the shape or a small preview
|
160 |
+
print("Mapped gene_data shape:", gene_data.shape)
|
161 |
+
print("Mapped gene_data head:\n", gene_data.head(5))
|
162 |
+
import pandas as pd
|
163 |
+
|
164 |
+
# STEP7
|
165 |
+
|
166 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
167 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
168 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
169 |
+
|
170 |
+
# 2. Check trait availability
|
171 |
+
is_trait_available = True
|
172 |
+
|
173 |
+
if not is_trait_available:
|
174 |
+
# If trait is unavailable, skip further processing
|
175 |
+
empty_df = pd.DataFrame()
|
176 |
+
validate_and_save_cohort_info(
|
177 |
+
is_final=True,
|
178 |
+
cohort=cohort,
|
179 |
+
info_path=json_path,
|
180 |
+
is_gene_available=True,
|
181 |
+
is_trait_available=False,
|
182 |
+
is_biased=True,
|
183 |
+
df=empty_df,
|
184 |
+
note="Trait data not available; skipping further steps."
|
185 |
+
)
|
186 |
+
else:
|
187 |
+
# Read the previously saved clinical data with index_col=0
|
188 |
+
selected_clinical_data = pd.read_csv(out_clinical_data_file, index_col=0)
|
189 |
+
|
190 |
+
# 3. Link the clinical and genetic data
|
191 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
192 |
+
|
193 |
+
# 4. Handle missing values in the linked data
|
194 |
+
linked_data = handle_missing_values(linked_data, trait)
|
195 |
+
|
196 |
+
# 5. Determine whether the trait and demographic features are severely biased
|
197 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
198 |
+
|
199 |
+
# 6. Final quality check and record the dataset info
|
200 |
+
is_usable = validate_and_save_cohort_info(
|
201 |
+
is_final=True,
|
202 |
+
cohort=cohort,
|
203 |
+
info_path=json_path,
|
204 |
+
is_gene_available=True,
|
205 |
+
is_trait_available=True,
|
206 |
+
is_biased=is_trait_biased,
|
207 |
+
df=unbiased_linked_data,
|
208 |
+
note="Final check after linking and missing-value handling."
|
209 |
+
)
|
210 |
+
|
211 |
+
# 7. If usable, save the final linked data
|
212 |
+
if is_usable:
|
213 |
+
unbiased_linked_data.to_csv(out_data_file)
|
p1/preprocess/Cystic_Fibrosis/code/GSE107846.py
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE107846.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE107846.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE107846.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
is_gene_available = True # Based on the GEO entry, we assume it's a gene expression dataset.
|
38 |
+
|
39 |
+
# 2. Variable Availability
|
40 |
+
trait_row = 5 # "state: CF" or "state: Healthy"
|
41 |
+
age_row = 1 # "age: ..."
|
42 |
+
gender_row = 2 # "Sex: F" / "Sex: M"
|
43 |
+
|
44 |
+
# 2.2 Data Type Conversions
|
45 |
+
def convert_trait(value: str):
|
46 |
+
# Extract the text after the first colon
|
47 |
+
val = value.split(":", 1)[1].strip() if ":" in value else value.strip()
|
48 |
+
# Convert to binary: CF -> 1, Healthy -> 0
|
49 |
+
if val.upper() == "CF":
|
50 |
+
return 1
|
51 |
+
elif val.upper() == "HEALTHY":
|
52 |
+
return 0
|
53 |
+
return None
|
54 |
+
|
55 |
+
def convert_age(value: str):
|
56 |
+
# Extract the text after the first colon
|
57 |
+
val = value.split(":", 1)[1].strip() if ":" in value else value.strip()
|
58 |
+
# Convert to float if possible
|
59 |
+
try:
|
60 |
+
return float(val)
|
61 |
+
except ValueError:
|
62 |
+
return None
|
63 |
+
|
64 |
+
def convert_gender(value: str):
|
65 |
+
# Extract the text after the first colon
|
66 |
+
val = value.split(":", 1)[1].strip() if ":" in value else value.strip()
|
67 |
+
# Convert to binary: F -> 0, M -> 1
|
68 |
+
if val.upper() == "F":
|
69 |
+
return 0
|
70 |
+
elif val.upper() == "M":
|
71 |
+
return 1
|
72 |
+
return None
|
73 |
+
|
74 |
+
# 3. Save Metadata (initial filtering)
|
75 |
+
is_trait_available = (trait_row is not None)
|
76 |
+
validate_and_save_cohort_info(
|
77 |
+
is_final=False,
|
78 |
+
cohort=cohort,
|
79 |
+
info_path=json_path,
|
80 |
+
is_gene_available=is_gene_available,
|
81 |
+
is_trait_available=is_trait_available
|
82 |
+
)
|
83 |
+
|
84 |
+
# 4. Clinical Feature Extraction if trait data is available
|
85 |
+
if trait_row is not None:
|
86 |
+
selected_clinical_df = geo_select_clinical_features(
|
87 |
+
clinical_df=clinical_data,
|
88 |
+
trait=trait,
|
89 |
+
trait_row=trait_row,
|
90 |
+
convert_trait=convert_trait,
|
91 |
+
age_row=age_row,
|
92 |
+
convert_age=convert_age,
|
93 |
+
gender_row=gender_row,
|
94 |
+
convert_gender=convert_gender
|
95 |
+
)
|
96 |
+
preview = preview_df(selected_clinical_df)
|
97 |
+
print("Preview of selected clinical features:", preview)
|
98 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
99 |
+
# STEP3
|
100 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
101 |
+
gene_data = get_genetic_data(matrix_file)
|
102 |
+
|
103 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
104 |
+
print(gene_data.index[:20])
|
105 |
+
# Based on the gene identifiers (ILMN_XXXXXX), these appear to be Illumina probe IDs.
|
106 |
+
# Therefore, they require mapping to standard gene symbols.
|
107 |
+
|
108 |
+
requires_gene_mapping = True
|
109 |
+
# STEP5
|
110 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
111 |
+
gene_annotation = get_gene_annotation(soft_file)
|
112 |
+
|
113 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
114 |
+
print("Gene annotation preview:")
|
115 |
+
print(preview_df(gene_annotation))
|
116 |
+
# STEP: Gene Identifier Mapping
|
117 |
+
|
118 |
+
# 1. Decide which key in the gene annotation corresponds to the same identifier type as in the gene expression data
|
119 |
+
# and which key corresponds to the gene symbols.
|
120 |
+
# From observation, 'ID' matches ILMN probe identifiers (e.g., "ILMN_1245321") and 'SYMBOL' stores gene symbols.
|
121 |
+
|
122 |
+
# 2. Get a gene mapping dataframe.
|
123 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="SYMBOL")
|
124 |
+
|
125 |
+
# 3. Convert probe-level measurements to gene expression data by applying the gene mapping.
|
126 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
127 |
+
|
128 |
+
# (gene_data now contains gene expression values indexed by gene symbols)
|
129 |
+
print("Mapped gene_data shape:", gene_data.shape)
|
130 |
+
print("First few rows of mapped gene expression data:\n", gene_data.head())
|
131 |
+
import pandas as pd
|
132 |
+
|
133 |
+
# STEP7
|
134 |
+
|
135 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
136 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
137 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
138 |
+
|
139 |
+
# Based on Step 2, we concluded trait_row=5 (thus trait data is available).
|
140 |
+
is_trait_available = True
|
141 |
+
|
142 |
+
if not is_trait_available:
|
143 |
+
# 2-4: Skip linking, missing value handling, and bias checks because trait is unavailable.
|
144 |
+
empty_df = pd.DataFrame()
|
145 |
+
validate_and_save_cohort_info(
|
146 |
+
is_final=True,
|
147 |
+
cohort=cohort,
|
148 |
+
info_path=json_path,
|
149 |
+
is_gene_available=True,
|
150 |
+
is_trait_available=False,
|
151 |
+
is_biased=True,
|
152 |
+
df=empty_df,
|
153 |
+
note="Trait data not available; skipping further steps."
|
154 |
+
)
|
155 |
+
else:
|
156 |
+
# 2. Load the clinical data. Since the CSV was saved with index=False, we first read the file,
|
157 |
+
# then manually set the row index to ["Cystic_Fibrosis","Age","Gender"].
|
158 |
+
selected_clinical_data = pd.read_csv(out_clinical_data_file, header=0)
|
159 |
+
selected_clinical_data.index = [trait, "Age", "Gender"]
|
160 |
+
|
161 |
+
# 3. Link the clinical and genetic data
|
162 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
163 |
+
|
164 |
+
# 4. Handle missing values in the linked data
|
165 |
+
linked_data = handle_missing_values(linked_data, trait)
|
166 |
+
|
167 |
+
# 5. Determine whether the trait and demographic features are severely biased
|
168 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
169 |
+
|
170 |
+
# 6. Conduct final quality validation and save the cohort information
|
171 |
+
is_usable = validate_and_save_cohort_info(
|
172 |
+
is_final=True,
|
173 |
+
cohort=cohort,
|
174 |
+
info_path=json_path,
|
175 |
+
is_gene_available=True,
|
176 |
+
is_trait_available=True,
|
177 |
+
is_biased=is_trait_biased,
|
178 |
+
df=unbiased_linked_data,
|
179 |
+
note="Final check after linking and missing-value handling."
|
180 |
+
)
|
181 |
+
|
182 |
+
# 7. If the dataset is usable, save it as CSV
|
183 |
+
if is_usable:
|
184 |
+
unbiased_linked_data.to_csv(out_data_file)
|
p1/preprocess/Cystic_Fibrosis/code/GSE129168.py
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE129168.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE129168.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE129168.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1) Gene expression data availability
|
37 |
+
is_gene_available = True # This dataset provides transcriptome data for CF iPSCs, so we consider it as gene expression data.
|
38 |
+
|
39 |
+
# 2) Variable Availability
|
40 |
+
# Observing the sample characteristics dictionary, row=2 contains genotype info
|
41 |
+
# indicating CF vs non-CF lines (p.Phe508del vs gene-corrected/WT).
|
42 |
+
# No suitable age or gender info is present.
|
43 |
+
trait_row = 2
|
44 |
+
age_row = None
|
45 |
+
gender_row = None
|
46 |
+
|
47 |
+
# 2) Data Type Conversion
|
48 |
+
def convert_trait(value):
|
49 |
+
if not value or pd.isnull(value):
|
50 |
+
return None
|
51 |
+
val = value.split(':')[-1].strip().lower()
|
52 |
+
# Mark p.Phe508del (but not gene-corrected) as CF
|
53 |
+
if 'p.phe508del' in val and 'gene corrected' not in val:
|
54 |
+
return 1
|
55 |
+
return 0
|
56 |
+
|
57 |
+
def convert_age(value):
|
58 |
+
return None # Not available
|
59 |
+
|
60 |
+
def convert_gender(value):
|
61 |
+
return None # Not available
|
62 |
+
|
63 |
+
# 3) Save Metadata: initial filtering
|
64 |
+
is_trait_available = (trait_row is not None)
|
65 |
+
is_usable = validate_and_save_cohort_info(
|
66 |
+
is_final=False,
|
67 |
+
cohort=cohort,
|
68 |
+
info_path=json_path,
|
69 |
+
is_gene_available=is_gene_available,
|
70 |
+
is_trait_available=is_trait_available
|
71 |
+
)
|
72 |
+
|
73 |
+
# 4) Clinical Feature Extraction
|
74 |
+
# Proceed only if the trait data is available
|
75 |
+
if trait_row is not None:
|
76 |
+
selected_clinical_df = geo_select_clinical_features(
|
77 |
+
clinical_df=clinical_data,
|
78 |
+
trait=trait,
|
79 |
+
trait_row=trait_row,
|
80 |
+
convert_trait=convert_trait,
|
81 |
+
age_row=age_row,
|
82 |
+
convert_age=convert_age,
|
83 |
+
gender_row=gender_row,
|
84 |
+
convert_gender=convert_gender
|
85 |
+
)
|
86 |
+
# Preview
|
87 |
+
preview_result = preview_df(selected_clinical_df)
|
88 |
+
print("Preview of selected clinical features:", preview_result)
|
89 |
+
# Save to CSV
|
90 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
91 |
+
# STEP3
|
92 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
93 |
+
gene_data = get_genetic_data(matrix_file)
|
94 |
+
|
95 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
96 |
+
print(gene_data.index[:20])
|
97 |
+
# Based on the index names like "A_23_P100001", these are array probe IDs rather than standard human gene symbols.
|
98 |
+
# Therefore, they need to be mapped to gene symbols.
|
99 |
+
requires_gene_mapping = True
|
100 |
+
# STEP5
|
101 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
102 |
+
gene_annotation = get_gene_annotation(soft_file)
|
103 |
+
|
104 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
105 |
+
print("Gene annotation preview:")
|
106 |
+
print(preview_df(gene_annotation))
|
107 |
+
# STEP: Gene Identifier Mapping
|
108 |
+
# 1) Identify the columns in gene_annotation that correspond to the probe ID and gene symbol
|
109 |
+
probe_col = "ID"
|
110 |
+
symbol_col = "GENE_SYMBOL"
|
111 |
+
|
112 |
+
# 2) Obtain the mapping dataframe
|
113 |
+
mapping_df = get_gene_mapping(gene_annotation, probe_col, symbol_col)
|
114 |
+
|
115 |
+
# 3) Convert probe-level measurements to gene expression data by applying the mapping
|
116 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
117 |
+
import pandas as pd
|
118 |
+
|
119 |
+
# STEP7
|
120 |
+
|
121 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
122 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
123 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
124 |
+
|
125 |
+
# Based on Step 2, we concluded trait_row = 2 (thus trait data is available).
|
126 |
+
is_trait_available = True
|
127 |
+
|
128 |
+
if not is_trait_available:
|
129 |
+
# 2-4: Skip linking, missing value handling, and bias checks because trait is unavailable.
|
130 |
+
empty_df = pd.DataFrame()
|
131 |
+
validate_and_save_cohort_info(
|
132 |
+
is_final=True,
|
133 |
+
cohort=cohort,
|
134 |
+
info_path=json_path,
|
135 |
+
is_gene_available=True,
|
136 |
+
is_trait_available=False,
|
137 |
+
is_biased=True,
|
138 |
+
df=empty_df,
|
139 |
+
note="Trait data not available; skipping further steps."
|
140 |
+
)
|
141 |
+
else:
|
142 |
+
# 2. Load the clinical data from the previous step and set its index to the trait name
|
143 |
+
selected_clinical_data = pd.read_csv(out_clinical_data_file)
|
144 |
+
selected_clinical_data.index = [trait]
|
145 |
+
|
146 |
+
# Link the clinical and genetic data
|
147 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
148 |
+
|
149 |
+
# 3. Handle missing values in the linked data
|
150 |
+
linked_data = handle_missing_values(linked_data, trait)
|
151 |
+
|
152 |
+
# 4. Determine whether the trait and demographic features are severely biased
|
153 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
154 |
+
|
155 |
+
# 5. Conduct final quality validation and save the cohort information
|
156 |
+
is_usable = validate_and_save_cohort_info(
|
157 |
+
is_final=True,
|
158 |
+
cohort=cohort,
|
159 |
+
info_path=json_path,
|
160 |
+
is_gene_available=True,
|
161 |
+
is_trait_available=True,
|
162 |
+
is_biased=is_trait_biased,
|
163 |
+
df=unbiased_linked_data,
|
164 |
+
note="Final check after linking and missing-value handling."
|
165 |
+
)
|
166 |
+
|
167 |
+
# 6. If the dataset is usable, save it as CSV
|
168 |
+
if is_usable:
|
169 |
+
unbiased_linked_data.to_csv(out_data_file)
|
p1/preprocess/Cystic_Fibrosis/code/GSE139038.py
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE139038.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE139038.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE139038.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
is_gene_available = True # Based on the series info indicating a gene expression study
|
38 |
+
|
39 |
+
# 2. Variable Availability and Data Type Conversion
|
40 |
+
|
41 |
+
# Looking at the sample characteristics dictionary,
|
42 |
+
# - For "trait" (Cystic_Fibrosis), no matching or inferable data was found. So trait_row = None.
|
43 |
+
# - For "age", it appears in row 0 and has multiple unique values. So age_row = 0.
|
44 |
+
# - For "gender", row 1 has only "Female" (constant). Hence, it's not useful for association. gender_row = None.
|
45 |
+
|
46 |
+
trait_row = None
|
47 |
+
age_row = 0
|
48 |
+
gender_row = None
|
49 |
+
|
50 |
+
# Define the data conversion functions.
|
51 |
+
def convert_trait(val: str):
|
52 |
+
"""
|
53 |
+
Convert trait data to binary (1/0). Return None if unknown.
|
54 |
+
"""
|
55 |
+
parts = val.split(':', 1)
|
56 |
+
if len(parts) < 2:
|
57 |
+
return None
|
58 |
+
raw = parts[1].strip().lower()
|
59 |
+
# Example placeholder logic:
|
60 |
+
# If the variable explicitly indicated "cystic fibrosis," return 1;
|
61 |
+
# if it indicated "normal"/"control," return 0; else None.
|
62 |
+
if raw == "cystic fibrosis":
|
63 |
+
return 1
|
64 |
+
elif raw in ["normal", "control", "no"]:
|
65 |
+
return 0
|
66 |
+
return None
|
67 |
+
|
68 |
+
def convert_age(val: str):
|
69 |
+
"""
|
70 |
+
Convert age data to continuous (float). Return None if unknown.
|
71 |
+
"""
|
72 |
+
parts = val.split(':', 1)
|
73 |
+
if len(parts) < 2:
|
74 |
+
return None
|
75 |
+
raw = parts[1].strip()
|
76 |
+
try:
|
77 |
+
return float(raw)
|
78 |
+
except ValueError:
|
79 |
+
return None
|
80 |
+
|
81 |
+
def convert_gender(val: str):
|
82 |
+
"""
|
83 |
+
Convert gender data to binary (female=0, male=1). Return None if unknown.
|
84 |
+
"""
|
85 |
+
parts = val.split(':', 1)
|
86 |
+
if len(parts) < 2:
|
87 |
+
return None
|
88 |
+
raw = parts[1].strip().lower()
|
89 |
+
if raw == "female":
|
90 |
+
return 0
|
91 |
+
elif raw == "male":
|
92 |
+
return 1
|
93 |
+
return None
|
94 |
+
|
95 |
+
# 3. Save Metadata - Initial Filtering
|
96 |
+
# Trait data availability depends on whether trait_row is None.
|
97 |
+
is_trait_available = (trait_row is not None)
|
98 |
+
|
99 |
+
is_usable = validate_and_save_cohort_info(
|
100 |
+
is_final=False,
|
101 |
+
cohort=cohort,
|
102 |
+
info_path=json_path,
|
103 |
+
is_gene_available=is_gene_available,
|
104 |
+
is_trait_available=is_trait_available
|
105 |
+
)
|
106 |
+
|
107 |
+
# 4. Clinical Feature Extraction
|
108 |
+
# Since trait_row is None, we skip extracting clinical features.
|
109 |
+
# STEP3
|
110 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
111 |
+
gene_data = get_genetic_data(matrix_file)
|
112 |
+
|
113 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
114 |
+
print(gene_data.index[:20])
|
115 |
+
# These identifiers (e.g., "10_10_1", "10_10_10") are not standard human gene symbols.
|
116 |
+
# They appear to be platform-specific probe references, so a mapping to human gene symbols is needed.
|
117 |
+
|
118 |
+
requires_gene_mapping = True
|
119 |
+
# STEP5
|
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 |
+
# STEP: Gene Identifier Mapping
|
127 |
+
|
128 |
+
# 1. We have determined that the gene annotation column "ID" matches the identifier in the gene expression data index,
|
129 |
+
# and "Gene_Symbol" provides the corresponding gene symbols.
|
130 |
+
|
131 |
+
# 2. Create a gene mapping dataframe from the annotation dataframe using the appropriate columns.
|
132 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene_Symbol')
|
133 |
+
|
134 |
+
# 3. Apply the mapping to convert probe-level data to gene-level data.
|
135 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
136 |
+
|
137 |
+
# Optionally print shape or a small preview to verify results
|
138 |
+
print("Mapped gene_data shape:", gene_data.shape)
|
139 |
+
print(gene_data.head())
|
140 |
+
import pandas as pd
|
141 |
+
|
142 |
+
# STEP7
|
143 |
+
|
144 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
145 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
146 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
147 |
+
|
148 |
+
# Check if trait data was actually available from previous steps
|
149 |
+
# (In previous steps, we set is_trait_available = (trait_row is not None).)
|
150 |
+
# We'll assume here it's accessible in the environment, or re-derive it:
|
151 |
+
is_trait_available = False # Reflecting the outcome from prior steps
|
152 |
+
|
153 |
+
if not is_trait_available:
|
154 |
+
# 2-4: Skip linking, missing value handling, and bias checks because trait is unavailable.
|
155 |
+
# 5. Conduct final validation with an empty DataFrame, forcing the dataset to be marked not usable.
|
156 |
+
empty_df = pd.DataFrame()
|
157 |
+
validate_and_save_cohort_info(
|
158 |
+
is_final=True,
|
159 |
+
cohort=cohort,
|
160 |
+
info_path=json_path,
|
161 |
+
is_gene_available=True, # The expression data exists
|
162 |
+
is_trait_available=False, # Trait data is not available
|
163 |
+
is_biased=True, # Force as biased so the dataset is not usable
|
164 |
+
df=empty_df,
|
165 |
+
note="Trait data not available; skipping further steps."
|
166 |
+
)
|
167 |
+
else:
|
168 |
+
# 2. Define a placeholder for selected_clinical_data (if we actually had trait data).
|
169 |
+
# In this dataset, trait_row was None, so this part won't run.
|
170 |
+
selected_clinical_data = pd.DataFrame() # Placeholder if trait were available
|
171 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
172 |
+
|
173 |
+
# 3. Handle missing values in the linked data
|
174 |
+
linked_data = handle_missing_values(linked_data, trait)
|
175 |
+
|
176 |
+
# 4. Determine whether the trait and demographic features are severely biased
|
177 |
+
is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)
|
178 |
+
|
179 |
+
# 5. Conduct final quality validation and save the cohort information
|
180 |
+
is_usable = validate_and_save_cohort_info(
|
181 |
+
is_final=True,
|
182 |
+
cohort=cohort,
|
183 |
+
info_path=json_path,
|
184 |
+
is_gene_available=True,
|
185 |
+
is_trait_available=True,
|
186 |
+
is_biased=is_trait_biased,
|
187 |
+
df=unbiased_linked_data
|
188 |
+
)
|
189 |
+
|
190 |
+
# 6. If the dataset is usable, save it as CSV
|
191 |
+
if is_usable:
|
192 |
+
unbiased_linked_data.to_csv(out_data_file)
|
p1/preprocess/Cystic_Fibrosis/code/GSE142610.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE142610.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE142610.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE142610.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Determine if gene expression data is likely available
|
37 |
+
is_gene_available = True # Based on the series summary describing transcriptomic (gene expression) analysis
|
38 |
+
|
39 |
+
# 2. Determine data availability (trait, age, gender)
|
40 |
+
# We see that all samples are from a CF cell line without variation. Hence, trait is constant.
|
41 |
+
# No age or gender information is provided. Therefore:
|
42 |
+
trait_row = None
|
43 |
+
age_row = None
|
44 |
+
gender_row = None
|
45 |
+
|
46 |
+
# 2.2 Define conversion functions.
|
47 |
+
# Since trait_row, age_row, and gender_row are None, these functions will not be used here,
|
48 |
+
# but we provide them for completeness.
|
49 |
+
|
50 |
+
def convert_trait(raw_value: str):
|
51 |
+
return None
|
52 |
+
|
53 |
+
def convert_age(raw_value: str):
|
54 |
+
return None
|
55 |
+
|
56 |
+
def convert_gender(raw_value: str):
|
57 |
+
return None
|
58 |
+
|
59 |
+
# 3. Save metadata with initial filtering
|
60 |
+
is_trait_available = (trait_row is not None)
|
61 |
+
is_usable = validate_and_save_cohort_info(
|
62 |
+
is_final=False,
|
63 |
+
cohort=cohort,
|
64 |
+
info_path=json_path,
|
65 |
+
is_gene_available=is_gene_available,
|
66 |
+
is_trait_available=is_trait_available
|
67 |
+
)
|
68 |
+
|
69 |
+
# 4. Since trait_row is None (trait not available), we skip clinical feature extraction.
|
70 |
+
# STEP3
|
71 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
72 |
+
gene_data = get_genetic_data(matrix_file)
|
73 |
+
|
74 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
75 |
+
print(gene_data.index[:20])
|
76 |
+
# Based on inspection, some identifiers (e.g., "7A5", "A2BP1") appear to be synonyms or outdated symbols
|
77 |
+
# rather than standard HGNC gene symbols. Therefore, they may require mapping to unify them into
|
78 |
+
# current official human gene symbols.
|
79 |
+
|
80 |
+
print("Some gene identifiers are synonyms or aliases rather than current official gene symbols.")
|
81 |
+
print("requires_gene_mapping = True")
|
82 |
+
# STEP5
|
83 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
84 |
+
gene_annotation = get_gene_annotation(soft_file)
|
85 |
+
|
86 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
87 |
+
print("Gene annotation preview:")
|
88 |
+
print(preview_df(gene_annotation))
|
89 |
+
# STEP: Gene Identifier Mapping
|
90 |
+
|
91 |
+
# 1. Decide which key in the gene annotation DataFrame matches the gene expression data IDs
|
92 |
+
# and which key contains the gene symbols.
|
93 |
+
# From the preview, both "ID" and "ORF" columns appear to match the probe IDs in the expression data,
|
94 |
+
# but "ORF" likely corresponds to the gene symbol we want.
|
95 |
+
|
96 |
+
# 2. Get a gene mapping DataFrame using the library function get_gene_mapping
|
97 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='ORF')
|
98 |
+
|
99 |
+
# 3. Convert (probe-level) gene expression data to (gene-level) data
|
100 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
p1/preprocess/Cystic_Fibrosis/code/GSE53543.py
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE53543.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE53543.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE53543.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
is_gene_available = True # Based on the background info, this dataset contains gene expression data
|
38 |
+
|
39 |
+
# 2. Variable Availability
|
40 |
+
# After examining the sample characteristics dictionary, we see:
|
41 |
+
# - There is no row containing Cystic Fibrosis information, so trait_row = None
|
42 |
+
# - There is no row containing age information, so age_row = None
|
43 |
+
# - Row 1 contains gender information with two distinct values (Female, Male), so gender_row = 1
|
44 |
+
trait_row = None
|
45 |
+
age_row = None
|
46 |
+
gender_row = 1
|
47 |
+
|
48 |
+
# 2.2 Data Type Conversion Functions
|
49 |
+
def convert_trait(x: str):
|
50 |
+
"""
|
51 |
+
Convert string to an appropriate trait value.
|
52 |
+
Since we have no trait data, the function returns None for any input.
|
53 |
+
"""
|
54 |
+
return None
|
55 |
+
|
56 |
+
def convert_age(x: str):
|
57 |
+
"""
|
58 |
+
Convert string to a continuous value for age.
|
59 |
+
Since age data is not available in this dataset, the function returns None for any input.
|
60 |
+
"""
|
61 |
+
return None
|
62 |
+
|
63 |
+
def convert_gender(x: str):
|
64 |
+
"""
|
65 |
+
Convert string to a binary value for gender: female -> 0, male -> 1.
|
66 |
+
Any unknown token returns None.
|
67 |
+
"""
|
68 |
+
if not x:
|
69 |
+
return None
|
70 |
+
val = x.split(":", 1)[-1].strip().lower()
|
71 |
+
if val == "female":
|
72 |
+
return 0
|
73 |
+
elif val == "male":
|
74 |
+
return 1
|
75 |
+
return None
|
76 |
+
|
77 |
+
# 3. Save Metadata (Initial Filtering)
|
78 |
+
# Trait data availability is determined by whether trait_row is None
|
79 |
+
is_trait_available = (trait_row is not None)
|
80 |
+
|
81 |
+
is_usable = validate_and_save_cohort_info(
|
82 |
+
is_final=False,
|
83 |
+
cohort=cohort,
|
84 |
+
info_path=json_path,
|
85 |
+
is_gene_available=is_gene_available,
|
86 |
+
is_trait_available=is_trait_available
|
87 |
+
)
|
88 |
+
|
89 |
+
# 4. Clinical Feature Extraction
|
90 |
+
# This step is skipped because 'trait_row' is None
|
91 |
+
# (no trait data available to extract).
|
92 |
+
# STEP3
|
93 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
94 |
+
gene_data = get_genetic_data(matrix_file)
|
95 |
+
|
96 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
97 |
+
print(gene_data.index[:20])
|
98 |
+
# Observed gene identifiers (e.g., "ILMN_1651229") are Illumina probe IDs, not standard human gene symbols.
|
99 |
+
# They require mapping to official gene symbols.
|
100 |
+
|
101 |
+
requires_gene_mapping = True
|
102 |
+
# STEP5
|
103 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
104 |
+
gene_annotation = get_gene_annotation(soft_file)
|
105 |
+
|
106 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
107 |
+
print("Gene annotation preview:")
|
108 |
+
print(preview_df(gene_annotation))
|
109 |
+
# STEP: Gene Identifier Mapping
|
110 |
+
|
111 |
+
# 1. Identify the columns in the annotation dataframe that match the gene_expression data's probe IDs and gene symbols
|
112 |
+
probe_col = "ID" # This column in 'gene_annotation' matches the probe IDs in 'gene_data'
|
113 |
+
symbol_col = "Symbol" # This column in 'gene_annotation' holds the gene symbols
|
114 |
+
|
115 |
+
# 2. Extract the mapping info from the annotation dataframe
|
116 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=symbol_col)
|
117 |
+
|
118 |
+
# 3. Apply the gene mapping to convert probe-level data to gene-level data
|
119 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
120 |
+
# STEP7
|
121 |
+
# Since trait_row = None, we have no trait data. Therefore, we cannot remove samples for a nonexistent trait,
|
122 |
+
# nor perform trait-based bias checks. We will still normalize and link the available clinical data (gender only)
|
123 |
+
# with gene data. Finally, we record that the dataset lacks trait data and is thus not fully usable.
|
124 |
+
|
125 |
+
# 1. Define the selected clinical data (which has gender info but no trait info).
|
126 |
+
selected_clinical_data = clinical_data
|
127 |
+
|
128 |
+
# 2. Normalize the obtained gene expression data using synonym information and save to CSV.
|
129 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
130 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
131 |
+
|
132 |
+
# 3. Link the (gender-only) clinical data and gene data.
|
133 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
134 |
+
|
135 |
+
# 4. We skip handle_missing_values() and bias checks because there's no trait column at all.
|
136 |
+
# Attempting them would cause a KeyError on "Cystic_Fibrosis".
|
137 |
+
|
138 |
+
# 5. Perform final validation, marking that no trait data is available. This dataset is not fully usable for
|
139 |
+
# trait-based analyses, but we still record its metadata in the JSON file.
|
140 |
+
is_usable = validate_and_save_cohort_info(
|
141 |
+
is_final=True,
|
142 |
+
cohort=cohort,
|
143 |
+
info_path=json_path,
|
144 |
+
is_gene_available=True,
|
145 |
+
is_trait_available=False,
|
146 |
+
is_biased=None,
|
147 |
+
df=None,
|
148 |
+
note="No trait data available. Only gender is present."
|
149 |
+
)
|
150 |
+
|
151 |
+
# 6. Because the dataset lacks trait data, it won't be marked as fully usable, so we do not save any final linked CSV.
|
152 |
+
# STEP8
|
153 |
+
# As determined, this dataset lacks a valid trait column ("Cystic_Fibrosis"), so we cannot run
|
154 |
+
# trait-based missing value checks or bias assessments. We will still normalize and link
|
155 |
+
# the data, then record that the dataset is not fully usable (no trait data).
|
156 |
+
|
157 |
+
# 1. Normalize the obtained gene data
|
158 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
159 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
160 |
+
|
161 |
+
# 2. Link the clinical (gender-only) and genetic data
|
162 |
+
# Assuming 'selected_clinical_data' is simply 'clinical_data' from our previous steps.
|
163 |
+
selected_clinical_data = clinical_data
|
164 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_data, normalized_gene_data)
|
165 |
+
|
166 |
+
# 3. Because there is no 'Cystic_Fibrosis' column, we skip handle_missing_values() and bias checks.
|
167 |
+
|
168 |
+
# 4. Conduct the final quality validation and record metadata.
|
169 |
+
# The trait is not available, so we pass `is_trait_available=False`. The function requires is_biased to be boolean.
|
170 |
+
# We set it to False to fulfill the function's requirements and note that the dataset lacks trait-based analysis.
|
171 |
+
is_usable = validate_and_save_cohort_info(
|
172 |
+
is_final=True,
|
173 |
+
cohort=cohort,
|
174 |
+
info_path=json_path,
|
175 |
+
is_gene_available=True,
|
176 |
+
is_trait_available=False,
|
177 |
+
is_biased=False, # Manually setting to False; no trait data => no trait bias check
|
178 |
+
df=linked_data,
|
179 |
+
note="No trait column found; cannot perform trait-based analysis. Only gender is present."
|
180 |
+
)
|
181 |
+
|
182 |
+
# 5. If the dataset were usable for trait-based analysis, we would save the final linked CSV.
|
183 |
+
# But since it's not, we skip saving to `out_data_file`.
|
184 |
+
if is_usable:
|
185 |
+
linked_data.to_csv(out_data_file)
|
p1/preprocess/Cystic_Fibrosis/code/GSE60690.py
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE60690.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE60690.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE60690.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
# From the background info ("global gene expression was measured in RNA from LCLs"),
|
38 |
+
# it is clear that the dataset contains gene expression data.
|
39 |
+
is_gene_available = True
|
40 |
+
|
41 |
+
# 2. Variable Availability and Data Type Conversion
|
42 |
+
# 2.1 Data Availability
|
43 |
+
# - The "trait" here is "Cystic_Fibrosis", but the background indicates
|
44 |
+
# this dataset is entirely CF patients (no variation). Hence treat as not available.
|
45 |
+
trait_row = None
|
46 |
+
|
47 |
+
# - Age is found in row 2 ("age of enrollment: ...").
|
48 |
+
age_row = 2
|
49 |
+
|
50 |
+
# - Gender is found in row 0 ("Sex: Male", "Sex: Female").
|
51 |
+
gender_row = 0
|
52 |
+
|
53 |
+
# 2.2 Data Type Conversion
|
54 |
+
import re
|
55 |
+
|
56 |
+
def convert_trait(value: str) -> int:
|
57 |
+
"""
|
58 |
+
Although trait_row is None (trait not available),
|
59 |
+
define a function for completeness.
|
60 |
+
Returns None if called, as there's no variation here.
|
61 |
+
"""
|
62 |
+
return None
|
63 |
+
|
64 |
+
def convert_age(value: str) -> float:
|
65 |
+
"""
|
66 |
+
Convert 'age of enrollment: 38.2' -> 38.2 (float).
|
67 |
+
If 'NA', return None.
|
68 |
+
"""
|
69 |
+
# Extract the portion after the colon
|
70 |
+
parts = value.split(':')
|
71 |
+
if len(parts) < 2:
|
72 |
+
return None
|
73 |
+
age_str = parts[1].strip()
|
74 |
+
if age_str.upper() == 'NA':
|
75 |
+
return None
|
76 |
+
try:
|
77 |
+
return float(age_str)
|
78 |
+
except ValueError:
|
79 |
+
return None
|
80 |
+
|
81 |
+
def convert_gender(value: str) -> int:
|
82 |
+
"""
|
83 |
+
Convert 'Sex: Male' -> 1
|
84 |
+
'Sex: Female' -> 0
|
85 |
+
Otherwise return None.
|
86 |
+
"""
|
87 |
+
parts = value.split(':')
|
88 |
+
if len(parts) < 2:
|
89 |
+
return None
|
90 |
+
gender_str = parts[1].strip().lower()
|
91 |
+
if gender_str == 'male':
|
92 |
+
return 1
|
93 |
+
elif gender_str == 'female':
|
94 |
+
return 0
|
95 |
+
return None
|
96 |
+
|
97 |
+
# 3. Save Metadata
|
98 |
+
# trait data availability depends on trait_row.
|
99 |
+
is_trait_available = trait_row is not None
|
100 |
+
|
101 |
+
usable_status = 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 |
+
# Skip this step because trait_row is None (no trait variation).
|
111 |
+
# Thus, we do not call geo_select_clinical_features.
|
112 |
+
# STEP3
|
113 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
114 |
+
gene_data = get_genetic_data(matrix_file)
|
115 |
+
|
116 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
117 |
+
print(gene_data.index[:20])
|
118 |
+
print("requires_gene_mapping = True")
|
119 |
+
# STEP5
|
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 |
+
# STEP6: Gene Identifier Mapping
|
127 |
+
|
128 |
+
# 1. Identify the columns in 'gene_annotation' that match the probe IDs in 'gene_data'
|
129 |
+
# and the column that stores gene symbols. Based on inspection, "ID" aligns with
|
130 |
+
# the probe identifiers in the expression data, and "gene_assignment" stores gene symbols.
|
131 |
+
probe_col = "ID"
|
132 |
+
gene_symbol_col = "gene_assignment"
|
133 |
+
|
134 |
+
# 2. Extract a mapping dataframe containing these two columns
|
135 |
+
mapping_df = get_gene_mapping(gene_annotation, probe_col, gene_symbol_col)
|
136 |
+
|
137 |
+
# 3. Apply the mapping to convert the probe-level expression data to gene-level data
|
138 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
139 |
+
# STEP 7
|
140 |
+
|
141 |
+
# 1) Normalize the gene symbols in the obtained gene expression data
|
142 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
143 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
144 |
+
|
145 |
+
# The dataset lacks trait variation (only CF patients), so no clinical data can be used for association.
|
146 |
+
# We skip linking to clinical data and skip further steps requiring trait info.
|
147 |
+
|
148 |
+
# 2) Final validation and saving metadata
|
149 |
+
# The library requires non-None boolean for 'is_biased' when is_final=True.
|
150 |
+
# Since there's no trait variation, we consider it "biased" for association.
|
151 |
+
is_biased = True
|
152 |
+
|
153 |
+
_ = validate_and_save_cohort_info(
|
154 |
+
is_final=True,
|
155 |
+
cohort=cohort,
|
156 |
+
info_path=json_path,
|
157 |
+
is_gene_available=True,
|
158 |
+
is_trait_available=False,
|
159 |
+
is_biased=is_biased,
|
160 |
+
df=pd.DataFrame(), # Passing an empty DataFrame as the dataset for final validation
|
161 |
+
note="All samples are CF patients; no variation in the trait."
|
162 |
+
)
|
163 |
+
|
164 |
+
# 3) Because the trait is unavailable for association, the dataset is not usable.
|
165 |
+
# We therefore do not create or save any linked data CSV file.
|
p1/preprocess/Cystic_Fibrosis/code/GSE67698.py
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE67698.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE67698.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE67698.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
is_gene_available = True # "Transcriptional profiling" implies likely RNA gene expression
|
38 |
+
|
39 |
+
# 2. Variable Availability and Data Type Conversion
|
40 |
+
# Based on the sample characteristics dictionary, row=1 has two unique values indicating
|
41 |
+
# deltaF508 CFTR or wildtype CFTR, which can be mapped to the trait (Cystic_Fibrosis vs. not).
|
42 |
+
# Age and gender do not appear to be present.
|
43 |
+
|
44 |
+
trait_row = 1
|
45 |
+
age_row = None
|
46 |
+
gender_row = None
|
47 |
+
|
48 |
+
def convert_trait(value: str) -> Optional[int]:
|
49 |
+
"""
|
50 |
+
Convert the trait (CF vs. non-CF) to a binary integer.
|
51 |
+
Values containing 'deltaF508' -> 1 (CF)
|
52 |
+
Values containing 'wildtype' -> 0 (non-CF)
|
53 |
+
Otherwise -> None
|
54 |
+
"""
|
55 |
+
# Attempt to split by colon, keep the part after it
|
56 |
+
parts = value.split(':', 1)
|
57 |
+
if len(parts) == 2:
|
58 |
+
val = parts[1].strip().lower()
|
59 |
+
else:
|
60 |
+
val = value.strip().lower()
|
61 |
+
|
62 |
+
if 'deltaf508' in val:
|
63 |
+
return 1
|
64 |
+
elif 'wildtype' in val:
|
65 |
+
return 0
|
66 |
+
return None
|
67 |
+
|
68 |
+
def convert_age(value: str) -> Optional[float]:
|
69 |
+
# Age data not available, return None
|
70 |
+
return None
|
71 |
+
|
72 |
+
def convert_gender(value: str) -> Optional[int]:
|
73 |
+
# Gender data not available, return None
|
74 |
+
return None
|
75 |
+
|
76 |
+
# 3. Save Metadata (initial filtering)
|
77 |
+
is_trait_available = (trait_row is not None)
|
78 |
+
is_usable = validate_and_save_cohort_info(
|
79 |
+
is_final=False,
|
80 |
+
cohort=cohort,
|
81 |
+
info_path=json_path,
|
82 |
+
is_gene_available=is_gene_available,
|
83 |
+
is_trait_available=is_trait_available
|
84 |
+
)
|
85 |
+
|
86 |
+
# 4. Clinical Feature Extraction
|
87 |
+
if trait_row is not None:
|
88 |
+
selected_clinical_df = geo_select_clinical_features(
|
89 |
+
clinical_df=clinical_data,
|
90 |
+
trait=trait,
|
91 |
+
trait_row=trait_row,
|
92 |
+
convert_trait=convert_trait,
|
93 |
+
age_row=age_row,
|
94 |
+
convert_age=convert_age,
|
95 |
+
gender_row=gender_row,
|
96 |
+
convert_gender=convert_gender
|
97 |
+
)
|
98 |
+
# Preview the extracted clinical features
|
99 |
+
preview = preview_df(selected_clinical_df)
|
100 |
+
print("Preview of selected clinical features:", preview)
|
101 |
+
|
102 |
+
# Save the clinical dataframe to CSV
|
103 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
104 |
+
# STEP3
|
105 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
106 |
+
gene_data = get_genetic_data(matrix_file)
|
107 |
+
|
108 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
109 |
+
print(gene_data.index[:20])
|
110 |
+
# Based on observation, the identifiers (e.g., "A_23_P100001") are not standard human gene symbols.
|
111 |
+
# They appear to be array probe IDs that need to be mapped to gene symbols.
|
112 |
+
print("requires_gene_mapping = True")
|
113 |
+
# STEP5
|
114 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
115 |
+
gene_annotation = get_gene_annotation(soft_file)
|
116 |
+
|
117 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
118 |
+
print("Gene annotation preview:")
|
119 |
+
print(preview_df(gene_annotation))
|
120 |
+
# STEP6: Gene Identifier Mapping
|
121 |
+
|
122 |
+
# 1. Identify the columns in the annotation that match the expression data's probe IDs and human gene symbols.
|
123 |
+
# From inspection, 'ID' matches the "A_23_P..." probe IDs, and 'GENE_SYMBOL' holds the human gene symbols.
|
124 |
+
|
125 |
+
# 2. Build a gene mapping dataframe using these columns.
|
126 |
+
mapping_df = get_gene_mapping(
|
127 |
+
annotation=gene_annotation,
|
128 |
+
prob_col="ID",
|
129 |
+
gene_col="GENE_SYMBOL"
|
130 |
+
)
|
131 |
+
|
132 |
+
# 3. Convert probe-level measurements to gene-level expression data by applying the gene mapping.
|
133 |
+
gene_data = apply_gene_mapping(
|
134 |
+
expression_df=gene_data,
|
135 |
+
mapping_df=mapping_df
|
136 |
+
)
|
137 |
+
|
138 |
+
# (Optional) Display some basic information about the newly mapped gene_data.
|
139 |
+
print("Mapped gene_data shape:", gene_data.shape)
|
140 |
+
print("First 5 rows of mapped gene_data:")
|
141 |
+
print(gene_data.head())
|
142 |
+
import os
|
143 |
+
import pandas as pd
|
144 |
+
|
145 |
+
# STEP 7 (Corrected)
|
146 |
+
|
147 |
+
# 1) Normalize gene symbols in the obtained gene expression data
|
148 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
149 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
150 |
+
|
151 |
+
# 2) Instead of reloading the clinical data from CSV (which was saved without index),
|
152 |
+
# we directly use the in-memory DataFrame "selected_clinical_df" from earlier steps.
|
153 |
+
# That DataFrame already has the trait as a row label, which is required downstream.
|
154 |
+
|
155 |
+
# 3) Link the clinical and genetic data on sample IDs
|
156 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
157 |
+
|
158 |
+
# 4) Handle missing values in the linked data
|
159 |
+
linked_data = handle_missing_values(linked_data, trait)
|
160 |
+
|
161 |
+
# 5) Check for biased features (including the trait)
|
162 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
163 |
+
|
164 |
+
# 6) Final validation and saving metadata
|
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=trait_biased,
|
172 |
+
df=linked_data,
|
173 |
+
note="Data from GSE123086, trait is Crohn's disease."
|
174 |
+
)
|
175 |
+
|
176 |
+
# 7) If the dataset is usable, save the linked data
|
177 |
+
if is_usable:
|
178 |
+
linked_data.to_csv(out_data_file)
|
p1/preprocess/Cystic_Fibrosis/code/GSE71799.py
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE71799.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE71799.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE71799.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
# According to the background summary, gene expression analysis was performed, so:
|
38 |
+
is_gene_available = True
|
39 |
+
|
40 |
+
# 2. Variable Availability and Data Type Conversion
|
41 |
+
|
42 |
+
# Based on the sample characteristics dictionary:
|
43 |
+
# {0: ['responder cells: UPN727 cells']}
|
44 |
+
# There's a single key (0) with the same value for all samples, which does not provide trait,
|
45 |
+
# age, or gender variability. Therefore, all three are considered not available.
|
46 |
+
|
47 |
+
trait_row = None
|
48 |
+
age_row = None
|
49 |
+
gender_row = None
|
50 |
+
|
51 |
+
# Define conversion functions (though they won't be used due to None rows).
|
52 |
+
def convert_trait(value: str):
|
53 |
+
# No actual data keys to parse, return None
|
54 |
+
return None
|
55 |
+
|
56 |
+
def convert_age(value: str):
|
57 |
+
# No actual data keys to parse, return None
|
58 |
+
return None
|
59 |
+
|
60 |
+
def convert_gender(value: str):
|
61 |
+
# No actual data keys to parse, return None
|
62 |
+
return None
|
63 |
+
|
64 |
+
# 3. Save metadata with initial filtering
|
65 |
+
# Trait availability depends on whether trait_row is None.
|
66 |
+
is_trait_available = (trait_row is not None)
|
67 |
+
is_usable = validate_and_save_cohort_info(
|
68 |
+
is_final=False,
|
69 |
+
cohort=cohort,
|
70 |
+
info_path=json_path,
|
71 |
+
is_gene_available=is_gene_available,
|
72 |
+
is_trait_available=is_trait_available
|
73 |
+
)
|
74 |
+
|
75 |
+
# 4. Clinical Feature Extraction
|
76 |
+
# Since trait_row is None, we skip this step.
|
77 |
+
# STEP3
|
78 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
79 |
+
gene_data = get_genetic_data(matrix_file)
|
80 |
+
|
81 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
82 |
+
print(gene_data.index[:20])
|
83 |
+
print("requires_gene_mapping = True")
|
84 |
+
# STEP5
|
85 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
86 |
+
gene_annotation = get_gene_annotation(soft_file)
|
87 |
+
|
88 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
89 |
+
print("Gene annotation preview:")
|
90 |
+
print(preview_df(gene_annotation))
|
91 |
+
# STEP: Gene Identifier Mapping
|
92 |
+
|
93 |
+
# 1. Identify columns in the annotation dataframe: 'ID' for probe identifiers and 'Gene Symbol' for gene symbols
|
94 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Gene Symbol")
|
95 |
+
|
96 |
+
# 2. Convert probe-level expression data to gene-level expression data
|
97 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
98 |
+
import os
|
99 |
+
import pandas as pd
|
100 |
+
|
101 |
+
# STEP 7 (Revised with dummy DataFrame for final validation)
|
102 |
+
|
103 |
+
# 1) Normalize gene symbols in the obtained gene expression data
|
104 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
105 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
106 |
+
|
107 |
+
# Because trait_row is None, there's no clinical data to link, so we skip trait-related steps.
|
108 |
+
|
109 |
+
# 2) Provide a dummy DataFrame and is_biased flag for final validation
|
110 |
+
dummy_df = pd.DataFrame()
|
111 |
+
dummy_is_biased = False
|
112 |
+
|
113 |
+
# 3) Final validation
|
114 |
+
is_usable = validate_and_save_cohort_info(
|
115 |
+
is_final=True,
|
116 |
+
cohort=cohort,
|
117 |
+
info_path=json_path,
|
118 |
+
is_gene_available=True,
|
119 |
+
is_trait_available=False,
|
120 |
+
is_biased=dummy_is_biased,
|
121 |
+
df=dummy_df,
|
122 |
+
note="No trait data in GSE71799, only gene expression data."
|
123 |
+
)
|
124 |
+
|
125 |
+
# 4) Since the dataset is not usable due to no trait data, do not save any linked data.
|
p1/preprocess/Cystic_Fibrosis/code/GSE76347.py
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/GSE76347.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE76347.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE76347.csv"
|
16 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Determine if gene expression data is available
|
37 |
+
is_gene_available = True # Microarray data is mentioned in the background
|
38 |
+
|
39 |
+
# 2. Determine availability of trait, age, and gender
|
40 |
+
# and define data conversion functions
|
41 |
+
|
42 |
+
# From the sample characteristics dictionary, there is only one unique trait value ("CF"),
|
43 |
+
# so it is effectively constant (not useful for association), thus not available.
|
44 |
+
trait_row = None
|
45 |
+
|
46 |
+
# No information about age or gender in the dictionary, so set them to None
|
47 |
+
age_row = None
|
48 |
+
gender_row = None
|
49 |
+
|
50 |
+
# Define the data conversion functions
|
51 |
+
def convert_trait(x: str):
|
52 |
+
# Since trait_row is None, we won't actually use this, but defining for completeness
|
53 |
+
parts = x.split(':', 1)
|
54 |
+
if len(parts) < 2:
|
55 |
+
return None
|
56 |
+
val = parts[1].strip().lower()
|
57 |
+
# If trait were variable, we'd map values accordingly, but it's constant in this dataset
|
58 |
+
return None
|
59 |
+
|
60 |
+
def convert_age(x: str):
|
61 |
+
# Since age_row is None, we won't actually use this, but defining for completeness
|
62 |
+
parts = x.split(':', 1)
|
63 |
+
if len(parts) < 2:
|
64 |
+
return None
|
65 |
+
val = parts[1].strip().lower()
|
66 |
+
# Normally, parse to a float/int if valid; otherwise None
|
67 |
+
return None
|
68 |
+
|
69 |
+
def convert_gender(x: str):
|
70 |
+
# Since gender_row is None, we won't actually use this, but defining for completeness
|
71 |
+
parts = x.split(':', 1)
|
72 |
+
if len(parts) < 2:
|
73 |
+
return None
|
74 |
+
val = parts[1].strip().lower()
|
75 |
+
# Typically, 'female' -> 0, 'male' -> 1; else None
|
76 |
+
return None
|
77 |
+
|
78 |
+
# 3. Save Metadata (initial filtering)
|
79 |
+
is_trait_available = (trait_row is not None)
|
80 |
+
is_usable = validate_and_save_cohort_info(
|
81 |
+
is_final=False,
|
82 |
+
cohort=cohort,
|
83 |
+
info_path=json_path,
|
84 |
+
is_gene_available=is_gene_available,
|
85 |
+
is_trait_available=is_trait_available
|
86 |
+
)
|
87 |
+
|
88 |
+
# 4. Clinical Feature Extraction
|
89 |
+
# Only proceed if trait_row is available (not None), otherwise skip
|
90 |
+
if trait_row is not None:
|
91 |
+
selected_clinical_df = geo_select_clinical_features(
|
92 |
+
clinical_data,
|
93 |
+
trait=trait,
|
94 |
+
trait_row=trait_row,
|
95 |
+
convert_trait=convert_trait,
|
96 |
+
age_row=age_row,
|
97 |
+
convert_age=convert_age,
|
98 |
+
gender_row=gender_row,
|
99 |
+
convert_gender=convert_gender
|
100 |
+
)
|
101 |
+
print("Preview of extracted clinical features:")
|
102 |
+
print(preview_df(selected_clinical_df))
|
103 |
+
selected_clinical_df.to_csv(out_clinical_data_file)
|
104 |
+
# STEP3
|
105 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
106 |
+
gene_data = get_genetic_data(matrix_file)
|
107 |
+
|
108 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
109 |
+
print(gene_data.index[:20])
|
110 |
+
# Observing the IDs: they appear to be numeric probe identifiers (e.g., from an array platform).
|
111 |
+
# These are not standard human gene symbols and likely need to be mapped to gene symbols.
|
112 |
+
|
113 |
+
print("requires_gene_mapping = True")
|
114 |
+
# STEP5
|
115 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
116 |
+
gene_annotation = get_gene_annotation(soft_file)
|
117 |
+
|
118 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
119 |
+
print("Gene annotation preview:")
|
120 |
+
print(preview_df(gene_annotation))
|
121 |
+
# STEP: Gene Identifier Mapping
|
122 |
+
|
123 |
+
# 1. Identify which columns correspond to the probe IDs and gene symbols in the annotation
|
124 |
+
# - The "ID" column in gene_annotation matches the probe IDs in gene_data
|
125 |
+
# - The "gene_assignment" column contains gene symbol information
|
126 |
+
|
127 |
+
# 2. Get a gene mapping dataframe
|
128 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='gene_assignment')
|
129 |
+
|
130 |
+
# 3. Convert probe-level measurements into gene expression data
|
131 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
132 |
+
import os
|
133 |
+
import pandas as pd
|
134 |
+
|
135 |
+
# STEP 7
|
136 |
+
|
137 |
+
# 1) Normalize gene symbols in the obtained gene expression data
|
138 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
139 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
140 |
+
|
141 |
+
# Since we have no trait data (trait_row was None), we skip linking clinical data,
|
142 |
+
# missing value handling, bias checks, and final validation for this dataset.
|
143 |
+
# The partial validation has already been done previously (is_final=False), indicating
|
144 |
+
# that trait data is missing and thus the dataset is not usable for associative studies.
|
p1/preprocess/Cystic_Fibrosis/code/TCGA.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Cystic_Fibrosis/TCGA.csv"
|
12 |
+
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/TCGA.csv"
|
13 |
+
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/TCGA.csv"
|
14 |
+
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json"
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
# 1. Identify subdirectories under tcga_root_dir
|
20 |
+
subdirectories = os.listdir(tcga_root_dir)
|
21 |
+
|
22 |
+
# Attempt to locate a subdirectory related to "Cystic_Fibrosis"
|
23 |
+
# (Looking for any name containing "cystic" or "fibrosis")
|
24 |
+
trait_subdir = None
|
25 |
+
for d in subdirectories:
|
26 |
+
lower_d = d.lower().replace('_', ' ')
|
27 |
+
if "cystic" in lower_d and "fibrosis" in lower_d:
|
28 |
+
trait_subdir = d
|
29 |
+
break
|
30 |
+
|
31 |
+
# If none found, skip this trait
|
32 |
+
if not trait_subdir:
|
33 |
+
print("No suitable subdirectory found for trait 'Cystic_Fibrosis'. Skipping...")
|
34 |
+
is_gene_available = False
|
35 |
+
is_trait_available = False
|
36 |
+
validate_and_save_cohort_info(
|
37 |
+
is_final=False,
|
38 |
+
cohort="TCGA",
|
39 |
+
info_path=json_path,
|
40 |
+
is_gene_available=is_gene_available,
|
41 |
+
is_trait_available=is_trait_available
|
42 |
+
)
|
43 |
+
else:
|
44 |
+
# 2. Identify paths to the clinical and genetic data files
|
45 |
+
full_subdir_path = os.path.join(tcga_root_dir, trait_subdir)
|
46 |
+
clinical_path, genetic_path = tcga_get_relevant_filepaths(full_subdir_path)
|
47 |
+
|
48 |
+
# 3. Load data into DataFrames
|
49 |
+
clinical_df = pd.read_csv(clinical_path, index_col=0, sep='\t')
|
50 |
+
genetic_df = pd.read_csv(genetic_path, index_col=0, sep='\t')
|
51 |
+
|
52 |
+
# 4. Print the column names of the clinical data for inspection
|
53 |
+
print("Clinical Data Columns:")
|
54 |
+
print(clinical_df.columns.tolist())
|
p1/preprocess/Cystic_Fibrosis/gene_data/GSE100521.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:755c1b82840b6f6d1048b7cf2c18b982b6c839f3356e2e0064e58ba0f5b45250
|
3 |
+
size 18338705
|
p1/preprocess/Cystic_Fibrosis/gene_data/GSE107846.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Cystic_Fibrosis/gene_data/GSE129168.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Cystic_Fibrosis/gene_data/GSE139038.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Cystic_Fibrosis/gene_data/GSE53543.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1b3d31e790d43703fae5e61d5b9a7f004629a173084bed93d0ef0286a56a80f1
|
3 |
+
size 24255296
|
p1/preprocess/Cystic_Fibrosis/gene_data/GSE67698.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b5debcb1fde444713779eb28ea53e4d9bb3422da7eba5bf8fadcc86b4796e403
|
3 |
+
size 20220285
|
p1/preprocess/Cystic_Fibrosis/gene_data/GSE71799.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7903e22d5fcdd3b3d196dbbb637d009e3b76e76aa4d59a6d5c5f3bad17e810a1
|
3 |
+
size 25978567
|
p1/preprocess/Cystic_Fibrosis/gene_data/GSE76347.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:866242e882712a8615ea58dd5bed82bc0b2f914495d634793cb9a23d783b1598
|
3 |
+
size 11628157
|
p1/preprocess/Depression/GSE110298.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Depression/GSE208668.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Depression/GSE99725.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Depression/clinical_data/GSE110298.csv
ADDED
@@ -0,0 +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 |
+
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 |
+
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 |
+
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
|
p1/preprocess/Depression/clinical_data/GSE201332.csv
ADDED
@@ -0,0 +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
|
p1/preprocess/Depression/clinical_data/GSE208668.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GSM6360934,GSM6360935,GSM6360936,GSM6360937,GSM6360938,GSM6360939,GSM6360940,GSM6360941,GSM6360942,GSM6360943,GSM6360944,GSM6360945,GSM6360946,GSM6360947,GSM6360948,GSM6360949,GSM6360950,GSM6360951,GSM6360952,GSM6360953,GSM6360954,GSM6360955,GSM6360956,GSM6360957,GSM6360958,GSM6360959,GSM6360960,GSM6360961,GSM6360962,GSM6360963,GSM6360964,GSM6360965,GSM6360966,GSM6360967,GSM6360968,GSM6360969,GSM6360970,GSM6360971,GSM6360972,GSM6360973,GSM6360974,GSM6360975
|
2 |
+
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,0.0,0.0,1.0,0.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,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0
|
3 |
+
65.0,75.0,77.0,64.0,60.0,67.0,72.0,62.0,73.0,74.0,73.0,68.0,62.0,73.0,70.0,60.0,61.0,66.0,69.0,62.0,67.0,62.0,71.0,63.0,62.0,61.0,67.0,78.0,79.0,72.0,73.0,77.0,72.0,62.0,70.0,65.0,63.0,74.0,71.0,80.0,78.0,65.0
|
4 |
+
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,0.0,0.0,0.0,0.0,0.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,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0
|
p1/preprocess/Depression/clinical_data/GSE99725.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
,GSM2650879,GSM2650880,GSM2650881,GSM2650882,GSM2650883,GSM2650884,GSM2650885,GSM2650886,GSM2650887,GSM2650888,GSM2650889,GSM2650890,GSM2650891,GSM2650892,GSM2650893,GSM2650894,GSM2650895,GSM2650896,GSM2650897,GSM2650898,GSM2650899,GSM2650900,GSM2650901,GSM2650902,GSM2650903,GSM2650904,GSM2650905,GSM2650906,GSM2650907,GSM2650908,GSM2650909,GSM2650910,GSM2650911,GSM2650912,GSM2650913,GSM2650914,GSM2650915,GSM2650916,GSM2650917,GSM2650918,GSM2650919,GSM2650920,GSM2650921,GSM2650922,GSM2650923,GSM2650924,GSM2650925,GSM2650926,GSM2650927,GSM2650928,GSM2650929,GSM2650930,GSM2650931,GSM2650932,GSM2650933,GSM2650934,GSM2650935
|
2 |
+
Depression,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,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,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,0.0,0.0
|
p1/preprocess/Depression/code/GSE110298.py
ADDED
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Depression/GSE110298.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Depression/gene_data/GSE110298.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Depression/clinical_data/GSE110298.csv"
|
16 |
+
json_path = "./output/preprocess/1/Depression/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
import re
|
37 |
+
|
38 |
+
# 1. Gene Expression Data Availability
|
39 |
+
is_gene_available = True # Based on the background info ("microarrays" mentioned, suggesting gene expression data)
|
40 |
+
|
41 |
+
# 2. Variable Availability and Data Type Conversion
|
42 |
+
|
43 |
+
# 2.1 Data Availability
|
44 |
+
# From the sample characteristics dictionary, depression data is at key=6, age at key=2, gender at key=1
|
45 |
+
trait_row = 6
|
46 |
+
age_row = 2
|
47 |
+
gender_row = 1
|
48 |
+
|
49 |
+
# 2.2 Data Type Conversion
|
50 |
+
|
51 |
+
def convert_trait(value: str):
|
52 |
+
"""Convert the depression value (after colon) into a float/int. Unknown -> None."""
|
53 |
+
parts = value.split(":")
|
54 |
+
if len(parts) < 2:
|
55 |
+
return None
|
56 |
+
raw = parts[-1].strip()
|
57 |
+
# Attempt to convert to a float or integer
|
58 |
+
try:
|
59 |
+
return float(raw)
|
60 |
+
except ValueError:
|
61 |
+
return None
|
62 |
+
|
63 |
+
def convert_age(value: str):
|
64 |
+
"""Convert the age value (after colon) into an integer. Unknown -> None."""
|
65 |
+
parts = value.split(":")
|
66 |
+
if len(parts) < 2:
|
67 |
+
return None
|
68 |
+
raw = parts[-1].strip()
|
69 |
+
try:
|
70 |
+
return int(raw)
|
71 |
+
except ValueError:
|
72 |
+
return None
|
73 |
+
|
74 |
+
def convert_gender(value: str):
|
75 |
+
"""Convert gender to 0 (female) or 1 (male). Unknown -> None."""
|
76 |
+
parts = value.split(":")
|
77 |
+
if len(parts) < 2:
|
78 |
+
return None
|
79 |
+
raw = parts[-1].strip().lower()
|
80 |
+
if raw == "female":
|
81 |
+
return 0
|
82 |
+
elif raw == "male":
|
83 |
+
return 1
|
84 |
+
else:
|
85 |
+
return None
|
86 |
+
|
87 |
+
# 3. Save Metadata (Initial Filtering)
|
88 |
+
is_trait_available = (trait_row is not None)
|
89 |
+
is_usable = validate_and_save_cohort_info(
|
90 |
+
is_final=False,
|
91 |
+
cohort=cohort,
|
92 |
+
info_path=json_path,
|
93 |
+
is_gene_available=is_gene_available,
|
94 |
+
is_trait_available=is_trait_available
|
95 |
+
)
|
96 |
+
|
97 |
+
# 4. Clinical Feature Extraction (only if trait_row is not None)
|
98 |
+
if trait_row is not None:
|
99 |
+
# Suppose 'clinical_data' is the DataFrame we obtained from previous parsing steps
|
100 |
+
selected_clinical_df = geo_select_clinical_features(
|
101 |
+
clinical_df=clinical_data,
|
102 |
+
trait=trait,
|
103 |
+
trait_row=trait_row,
|
104 |
+
convert_trait=convert_trait,
|
105 |
+
age_row=age_row,
|
106 |
+
convert_age=convert_age,
|
107 |
+
gender_row=gender_row,
|
108 |
+
convert_gender=convert_gender
|
109 |
+
)
|
110 |
+
|
111 |
+
# Preview and save
|
112 |
+
print(preview_df(selected_clinical_df, n=5))
|
113 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
114 |
+
# STEP3
|
115 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
116 |
+
gene_data = get_genetic_data(matrix_file)
|
117 |
+
|
118 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
119 |
+
print(gene_data.index[:20])
|
120 |
+
# We observe that the gene identifiers look like Affymetrix probe set IDs rather than
|
121 |
+
# standard gene symbols. Therefore, they likely require mapping to gene symbols.
|
122 |
+
|
123 |
+
print("The gene identifiers appear to be Affymetrix probe IDs and are not standard gene symbols.")
|
124 |
+
print("requires_gene_mapping = True")
|
125 |
+
# STEP5
|
126 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
127 |
+
gene_annotation = get_gene_annotation(soft_file)
|
128 |
+
|
129 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
130 |
+
print("Gene annotation preview:")
|
131 |
+
print(preview_df(gene_annotation))
|
132 |
+
# STEP: Gene Identifier Mapping
|
133 |
+
|
134 |
+
# 1 & 2. Identify the columns in 'gene_annotation' corresponding to the probe IDs and gene symbols
|
135 |
+
# and extract them into a mapping dataframe.
|
136 |
+
mapping_df = get_gene_mapping(
|
137 |
+
annotation=gene_annotation,
|
138 |
+
prob_col="ID",
|
139 |
+
gene_col="Gene Symbol"
|
140 |
+
)
|
141 |
+
|
142 |
+
# 3. Convert probe-level measurements to gene expression data using the mapping dataframe.
|
143 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
144 |
+
|
145 |
+
# For verification, let's display the new gene_data dimensions and the first few gene symbols.
|
146 |
+
print("Gene expression dataframe shape:", gene_data.shape)
|
147 |
+
print("First few gene symbols in the processed gene_data index:")
|
148 |
+
print(gene_data.index.tolist()[:20])
|
149 |
+
import pandas as pd
|
150 |
+
|
151 |
+
# STEP 7 (Corrected)
|
152 |
+
|
153 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
154 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
155 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
156 |
+
|
157 |
+
# 2. Load the final clinical data generated in Step 2 (it contains the "Depression" row).
|
158 |
+
# This file was saved without an index, so we read it with index_col=0 to restore
|
159 |
+
# the row index as ["Depression", "Age", "Gender"] and sample IDs as columns.
|
160 |
+
clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
|
161 |
+
|
162 |
+
# 3. Link the clinical and genetic data on sample IDs.
|
163 |
+
linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
|
164 |
+
|
165 |
+
# 4. Handle missing values in the linked dataset, including removal and imputation.
|
166 |
+
final_data = handle_missing_values(linked_data, trait_col=trait)
|
167 |
+
|
168 |
+
# 5. Determine whether the trait and some demographic features in the dataset are severely biased.
|
169 |
+
trait_biased, final_data = judge_and_remove_biased_features(final_data, trait)
|
170 |
+
|
171 |
+
# 6. Perform final validation and record dataset metadata.
|
172 |
+
is_usable = validate_and_save_cohort_info(
|
173 |
+
is_final=True,
|
174 |
+
cohort=cohort,
|
175 |
+
info_path=json_path,
|
176 |
+
is_gene_available=True,
|
177 |
+
is_trait_available=True,
|
178 |
+
is_biased=trait_biased,
|
179 |
+
df=final_data,
|
180 |
+
note="Trait data is present and has undergone final preprocessing."
|
181 |
+
)
|
182 |
+
|
183 |
+
# 7. If the dataset is usable, save the final linked data; otherwise, skip.
|
184 |
+
if is_usable:
|
185 |
+
final_data.to_csv(out_data_file)
|
186 |
+
import pandas as pd
|
187 |
+
|
188 |
+
# STEP 8 (Corrected)
|
189 |
+
|
190 |
+
# 1. Normalize gene symbols in the obtained gene expression data.
|
191 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
192 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
193 |
+
|
194 |
+
# 2. Read the final clinical data that was saved in a previous step
|
195 |
+
# It was saved with index=False, so we read it normally and then manually set the row index.
|
196 |
+
temp_clinical_df = pd.read_csv(out_clinical_data_file)
|
197 |
+
# The dataframe should have shape (3, number_of_samples).
|
198 |
+
# Assign the row index to ["Depression", "Age", "Gender"].
|
199 |
+
temp_clinical_df.index = ["Depression", "Age", "Gender"]
|
200 |
+
|
201 |
+
# 3. Link clinical and genetic data on sample IDs.
|
202 |
+
linked_data = geo_link_clinical_genetic_data(temp_clinical_df, normalized_gene_data)
|
203 |
+
|
204 |
+
# 4. Handle missing values in the linked dataset.
|
205 |
+
final_data = handle_missing_values(linked_data, trait_col=trait)
|
206 |
+
|
207 |
+
# 5. Determine whether the trait and some demographic features are severely biased.
|
208 |
+
trait_biased, final_data = judge_and_remove_biased_features(final_data, trait)
|
209 |
+
|
210 |
+
# 6. Perform final validation and record dataset metadata, indicating trait availability.
|
211 |
+
is_usable = validate_and_save_cohort_info(
|
212 |
+
is_final=True,
|
213 |
+
cohort=cohort,
|
214 |
+
info_path=json_path,
|
215 |
+
is_gene_available=True,
|
216 |
+
is_trait_available=True,
|
217 |
+
is_biased=trait_biased,
|
218 |
+
df=final_data,
|
219 |
+
note="Successfully linked and processed GSE110298 with trait='Depression'."
|
220 |
+
)
|
221 |
+
|
222 |
+
# 7. If the dataset is deemed usable, save the final linked data.
|
223 |
+
if is_usable:
|
224 |
+
final_data.to_csv(out_data_file)
|
p1/preprocess/Depression/code/GSE128387.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Depression/GSE128387.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Depression/gene_data/GSE128387.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Depression/clinical_data/GSE128387.csv"
|
16 |
+
json_path = "./output/preprocess/1/Depression/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
is_gene_available = True # The dataset uses Affymetrix microarrays, indicating gene expression data.
|
38 |
+
|
39 |
+
# 2. Variable Availability and Data Type Conversion
|
40 |
+
|
41 |
+
# Looking at the sample characteristics dictionary, we see:
|
42 |
+
# 0: ['tissue: Blood']
|
43 |
+
# 1: ['illness: Major Depressive Disorder']
|
44 |
+
# 2: ['age: 16', 'age: 13', 'age: 12', 'age: 14', 'age: 17', 'age: 15']
|
45 |
+
# 3: ['Sex: female', 'Sex: male']
|
46 |
+
|
47 |
+
# - The trait "Depression" is constant across all samples (everyone has Major Depressive Disorder).
|
48 |
+
# Hence there is no meaningful variation in the trait for association studies.
|
49 |
+
trait_row = None
|
50 |
+
|
51 |
+
# - Age is available at row index 2 with multiple distinct values.
|
52 |
+
age_row = 2
|
53 |
+
|
54 |
+
# - Gender is available at row index 3 with two distinct values.
|
55 |
+
gender_row = 3
|
56 |
+
|
57 |
+
# Define conversion functions as required:
|
58 |
+
def convert_trait(x: str) -> int:
|
59 |
+
"""
|
60 |
+
Since 'trait' is effectively unavailable (no variation),
|
61 |
+
we define a placeholder function that returns None.
|
62 |
+
"""
|
63 |
+
return None
|
64 |
+
|
65 |
+
def convert_age(x: str) -> float:
|
66 |
+
"""
|
67 |
+
Convert 'age: XX' to a continuous float.
|
68 |
+
Unknown or invalid values return None.
|
69 |
+
"""
|
70 |
+
parts = x.split(':')
|
71 |
+
if len(parts) < 2:
|
72 |
+
return None
|
73 |
+
val_str = parts[1].strip()
|
74 |
+
try:
|
75 |
+
return float(val_str)
|
76 |
+
except ValueError:
|
77 |
+
return None
|
78 |
+
|
79 |
+
def convert_gender(x: str) -> int:
|
80 |
+
"""
|
81 |
+
Convert 'Sex: male' to 1 and 'Sex: female' to 0.
|
82 |
+
Unknown or invalid values return None.
|
83 |
+
"""
|
84 |
+
parts = x.split(':')
|
85 |
+
if len(parts) < 2:
|
86 |
+
return None
|
87 |
+
val_str = parts[1].strip().lower()
|
88 |
+
if val_str == 'female':
|
89 |
+
return 0
|
90 |
+
elif val_str == 'male':
|
91 |
+
return 1
|
92 |
+
else:
|
93 |
+
return None
|
94 |
+
|
95 |
+
# 3. Save Metadata (Initial Filtering)
|
96 |
+
is_trait_available = (trait_row is not None)
|
97 |
+
is_usable = 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
|
106 |
+
# Skip this step because trait_row is None (the trait is not available).
|
p1/preprocess/Depression/code/GSE135524.py
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Depression/GSE135524.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Depression/gene_data/GSE135524.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Depression/clinical_data/GSE135524.csv"
|
16 |
+
json_path = "./output/preprocess/1/Depression/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Determine if the dataset has gene expression data
|
37 |
+
is_gene_available = True # Based on the series title indicating "Gene expression"
|
38 |
+
|
39 |
+
# 2. Identify data availability for trait, age, and gender
|
40 |
+
# The dataset seems to contain only depressed patients, so no variation in "Depression" => None
|
41 |
+
trait_row = None
|
42 |
+
age_row = 1
|
43 |
+
gender_row = 2
|
44 |
+
|
45 |
+
# 2.2 Create conversion functions
|
46 |
+
|
47 |
+
def convert_trait(x: str) -> int:
|
48 |
+
"""
|
49 |
+
Convert depression trait to some numeric or binary code if available.
|
50 |
+
However, we have concluded there is no variation in the depression trait for this dataset,
|
51 |
+
so we'll just return None for completeness.
|
52 |
+
"""
|
53 |
+
return None
|
54 |
+
|
55 |
+
def convert_age(x: str) -> Optional[float]:
|
56 |
+
"""
|
57 |
+
Parse the age after the colon and convert to float.
|
58 |
+
Unknown values or malformed inputs => None
|
59 |
+
Example: "age: 55" -> 55.0
|
60 |
+
"""
|
61 |
+
try:
|
62 |
+
# Extract the substring after "age:"
|
63 |
+
parts = x.split(":", 1)
|
64 |
+
if len(parts) < 2:
|
65 |
+
return None
|
66 |
+
val = parts[1].strip()
|
67 |
+
return float(val)
|
68 |
+
except:
|
69 |
+
return None
|
70 |
+
|
71 |
+
def convert_gender(x: str) -> Optional[int]:
|
72 |
+
"""
|
73 |
+
Convert gender to binary: female -> 0, male -> 1.
|
74 |
+
Example: "Sex: Male" -> 1, "Sex: Female" -> 0
|
75 |
+
Unknown or malformed -> None
|
76 |
+
"""
|
77 |
+
parts = x.split(":", 1)
|
78 |
+
if len(parts) < 2:
|
79 |
+
return None
|
80 |
+
val = parts[1].strip().lower()
|
81 |
+
if val in ["female"]:
|
82 |
+
return 0
|
83 |
+
elif val in ["male"]:
|
84 |
+
return 1
|
85 |
+
return None
|
86 |
+
|
87 |
+
# Since 'trait_row' is None, trait is not available (no variation).
|
88 |
+
is_trait_available = (trait_row is not None)
|
89 |
+
|
90 |
+
# 3. Perform initial filtering and save info
|
91 |
+
is_usable = validate_and_save_cohort_info(
|
92 |
+
is_final=False,
|
93 |
+
cohort=cohort,
|
94 |
+
info_path=json_path,
|
95 |
+
is_gene_available=is_gene_available,
|
96 |
+
is_trait_available=is_trait_available
|
97 |
+
)
|
98 |
+
|
99 |
+
# 4. Because trait_row is None, we skip the clinical feature extraction step.
|
100 |
+
# No further action is needed for substep 4.
|
101 |
+
# STEP3
|
102 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
103 |
+
gene_data = get_genetic_data(matrix_file)
|
104 |
+
|
105 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
106 |
+
print(gene_data.index[:20])
|
107 |
+
# These ILMN_ identifiers are Illumina probe IDs, not human gene symbols
|
108 |
+
# They require mapping to gene symbols.
|
109 |
+
print("requires_gene_mapping = True")
|
110 |
+
# STEP5
|
111 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
112 |
+
gene_annotation = get_gene_annotation(soft_file)
|
113 |
+
|
114 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
115 |
+
print("Gene annotation preview:")
|
116 |
+
print(preview_df(gene_annotation))
|
117 |
+
# STEP: Gene Identifier Mapping
|
118 |
+
# 1. Identify the columns in the gene_annotation dataframe that match the probe IDs (in gene_data.index)
|
119 |
+
# and the gene symbols. From the preview, 'ID' stores Illumina probe IDs, and 'Symbol' stores gene symbols.
|
120 |
+
probe_col = "ID"
|
121 |
+
gene_col = "Symbol"
|
122 |
+
|
123 |
+
# 2. Get the gene mapping by extracting the two relevant columns.
|
124 |
+
mapping_df = get_gene_mapping(gene_annotation, probe_col, gene_col)
|
125 |
+
|
126 |
+
# 3. Convert probe-level measurements to gene-level expression data using the mapping,
|
127 |
+
# distributing each probe's expression equally across its mapped genes.
|
128 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
129 |
+
import pandas as pd
|
130 |
+
|
131 |
+
# STEP7
|
132 |
+
|
133 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
134 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
135 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
136 |
+
|
137 |
+
# 2. Link the clinical and genetic data on sample IDs, even if the trait is missing.
|
138 |
+
linked_data = geo_link_clinical_genetic_data(clinical_data, normalized_gene_data)
|
139 |
+
|
140 |
+
# 3. Because the trait is unavailable (trait_row=None), ensure a placeholder column exists for it
|
141 |
+
# so that the missing-value handling and bias checking can still run.
|
142 |
+
if trait not in linked_data.columns:
|
143 |
+
linked_data[trait] = None
|
144 |
+
|
145 |
+
# 4. Handle missing values (will remove samples missing the trait, which are all samples in this case)
|
146 |
+
final_data = handle_missing_values(linked_data, trait_col=trait)
|
147 |
+
|
148 |
+
# 5. Determine whether the trait is severely biased (the function requires a trait column).
|
149 |
+
trait_biased, final_data = judge_and_remove_biased_features(final_data, trait)
|
150 |
+
|
151 |
+
# 6. Perform final validation and record dataset metadata. Since trait is not available,
|
152 |
+
# the dataset will not be marked as usable for trait-based analysis.
|
153 |
+
is_usable = validate_and_save_cohort_info(
|
154 |
+
is_final=True,
|
155 |
+
cohort=cohort,
|
156 |
+
info_path=json_path,
|
157 |
+
is_gene_available=True, # We do have gene expression data
|
158 |
+
is_trait_available=False, # but the trait is absent
|
159 |
+
is_biased=trait_biased,
|
160 |
+
df=final_data,
|
161 |
+
note="The dataset lacks trait data, but partial preprocessing was still performed."
|
162 |
+
)
|
163 |
+
|
164 |
+
# 7. If the dataset is somehow deemed usable, save the final linked data; otherwise, skip.
|
165 |
+
if is_usable:
|
166 |
+
final_data.to_csv(out_data_file)
|
p1/preprocess/Depression/code/GSE138297.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Depression/GSE138297.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Depression/gene_data/GSE138297.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Depression/clinical_data/GSE138297.csv"
|
16 |
+
json_path = "./output/preprocess/1/Depression/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene expression data availability
|
37 |
+
is_gene_available = True # Based on microarray analysis mentioned in the summary
|
38 |
+
|
39 |
+
# 2.1 Variable availability
|
40 |
+
# No row for Depression (trait) found; multiple unique values for age (row 3) and gender (row 1)
|
41 |
+
trait_row = None
|
42 |
+
age_row = 3
|
43 |
+
gender_row = 1
|
44 |
+
|
45 |
+
# 2.2 Data type conversion functions
|
46 |
+
def convert_trait(value: str):
|
47 |
+
# For this dataset, no trait data is available, but we define the function.
|
48 |
+
return None
|
49 |
+
|
50 |
+
def convert_age(value: str):
|
51 |
+
# Example format: "age (yrs): 49"
|
52 |
+
try:
|
53 |
+
val_str = value.split(":", 1)[1].strip()
|
54 |
+
return float(val_str)
|
55 |
+
except:
|
56 |
+
return None
|
57 |
+
|
58 |
+
def convert_gender(value: str):
|
59 |
+
# Example format: "sex (female=1, male=0): 1"
|
60 |
+
# We invert: female->0, male->1
|
61 |
+
try:
|
62 |
+
val_str = value.split(":", 1)[1].strip()
|
63 |
+
if val_str == "1":
|
64 |
+
return 0 # female
|
65 |
+
elif val_str == "0":
|
66 |
+
return 1 # male
|
67 |
+
else:
|
68 |
+
return None
|
69 |
+
except:
|
70 |
+
return None
|
71 |
+
|
72 |
+
# 3. Save metadata (initial filtering)
|
73 |
+
is_trait_available = (trait_row is not None)
|
74 |
+
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. Skip clinical feature extraction because trait_row is None
|
83 |
+
# STEP3
|
84 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
85 |
+
gene_data = get_genetic_data(matrix_file)
|
86 |
+
|
87 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
88 |
+
print(gene_data.index[:20])
|
89 |
+
# These numeric IDs are not standard human gene symbols and likely require mapping.
|
90 |
+
requires_gene_mapping = True
|
91 |
+
# STEP5
|
92 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
93 |
+
gene_annotation = get_gene_annotation(soft_file)
|
94 |
+
|
95 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
96 |
+
print("Gene annotation preview:")
|
97 |
+
print(preview_df(gene_annotation))
|
98 |
+
# STEP: Gene Identifier Mapping
|
99 |
+
|
100 |
+
# 1. Decide which key in 'gene_annotation' is the identifier that matches 'gene_data.index',
|
101 |
+
# and which key stores the gene symbol.
|
102 |
+
# Based on observation, the 'ID' column matches the probe IDs in 'gene_data.index',
|
103 |
+
# and the 'gene_assignment' column contains the gene symbols.
|
104 |
+
|
105 |
+
# 2. Extract the two columns to create the mapping dataframe.
|
106 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="gene_assignment")
|
107 |
+
|
108 |
+
# 3. Convert the probe-level data in 'gene_data' to gene-level data using the mapping.
|
109 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
110 |
+
import pandas as pd
|
111 |
+
|
112 |
+
# STEP7
|
113 |
+
|
114 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
115 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
116 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
117 |
+
|
118 |
+
# 2. Link the clinical and genetic data on sample IDs, even if the trait is missing.
|
119 |
+
linked_data = geo_link_clinical_genetic_data(clinical_data, normalized_gene_data)
|
120 |
+
|
121 |
+
# 3. Because the trait is unavailable (trait_row=None), ensure a placeholder column exists for it
|
122 |
+
# so that the missing-value handling and bias checking can still run.
|
123 |
+
if trait not in linked_data.columns:
|
124 |
+
linked_data[trait] = None
|
125 |
+
|
126 |
+
# 4. Handle missing values (will remove samples missing the trait, which are all samples in this case)
|
127 |
+
final_data = handle_missing_values(linked_data, trait_col=trait)
|
128 |
+
|
129 |
+
# 5. Determine whether the trait is severely biased (the function requires a trait column).
|
130 |
+
trait_biased, final_data = judge_and_remove_biased_features(final_data, trait)
|
131 |
+
|
132 |
+
# 6. Perform final validation and record dataset metadata. Since trait is not available,
|
133 |
+
# the dataset will not be marked as usable for trait-based analysis.
|
134 |
+
is_usable = validate_and_save_cohort_info(
|
135 |
+
is_final=True,
|
136 |
+
cohort=cohort,
|
137 |
+
info_path=json_path,
|
138 |
+
is_gene_available=True, # We do have gene expression data
|
139 |
+
is_trait_available=False, # but the trait is absent
|
140 |
+
is_biased=trait_biased,
|
141 |
+
df=final_data,
|
142 |
+
note="The dataset lacks trait data, but partial preprocessing was still performed."
|
143 |
+
)
|
144 |
+
|
145 |
+
# 7. If the dataset is somehow deemed usable, save the final linked data; otherwise, skip.
|
146 |
+
if is_usable:
|
147 |
+
final_data.to_csv(out_data_file)
|
p1/preprocess/Depression/code/GSE149980.py
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Depression/GSE149980.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Depression/gene_data/GSE149980.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Depression/clinical_data/GSE149980.csv"
|
16 |
+
json_path = "./output/preprocess/1/Depression/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Determine if the dataset contains suitable gene expression data
|
37 |
+
is_gene_available = True # The series background indicates whole gene expression profiling
|
38 |
+
|
39 |
+
# 2. Identify variable availability from the sample characteristics
|
40 |
+
# (All participants are depressed; there's no variation for 'Depression' as a trait here)
|
41 |
+
trait_row = None
|
42 |
+
age_row = None
|
43 |
+
gender_row = None
|
44 |
+
|
45 |
+
# 2.2 Define data type conversion functions
|
46 |
+
def convert_trait(value: str):
|
47 |
+
return None # No usable variation for the 'Depression' trait
|
48 |
+
|
49 |
+
def convert_age(value: str):
|
50 |
+
return None # Age data not available
|
51 |
+
|
52 |
+
def convert_gender(value: str):
|
53 |
+
return None # Gender data not available
|
54 |
+
|
55 |
+
# 3. Save initial metadata
|
56 |
+
is_trait_available = (trait_row is not None)
|
57 |
+
is_usable = validate_and_save_cohort_info(
|
58 |
+
is_final=False,
|
59 |
+
cohort=cohort,
|
60 |
+
info_path=json_path,
|
61 |
+
is_gene_available=is_gene_available,
|
62 |
+
is_trait_available=is_trait_available
|
63 |
+
)
|
64 |
+
|
65 |
+
# 4. Clinical feature extraction is skipped because `trait_row` is None
|
66 |
+
# STEP3
|
67 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
68 |
+
gene_data = get_genetic_data(matrix_file)
|
69 |
+
|
70 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
71 |
+
print(gene_data.index[:20])
|
72 |
+
# Observing the given identifiers, they appear to be microarray probe IDs or synthetic constructs,
|
73 |
+
# not standard human gene symbols. Therefore, they require gene symbol mapping.
|
74 |
+
|
75 |
+
print("requires_gene_mapping = True")
|
76 |
+
# STEP5
|
77 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
78 |
+
gene_annotation = get_gene_annotation(soft_file)
|
79 |
+
|
80 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
81 |
+
print("Gene annotation preview:")
|
82 |
+
print(preview_df(gene_annotation))
|
83 |
+
# 1. Define which columns correspond to the probe IDs and which correspond to gene symbols
|
84 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="GENE_SYMBOL")
|
85 |
+
|
86 |
+
# 2. Convert probe-level measurements to gene-level by applying the mapping
|
87 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
88 |
+
import pandas as pd
|
89 |
+
|
90 |
+
# STEP7
|
91 |
+
|
92 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
93 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
94 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
95 |
+
|
96 |
+
# 2. Link the clinical and genetic data on sample IDs, even if the trait is missing.
|
97 |
+
linked_data = geo_link_clinical_genetic_data(clinical_data, normalized_gene_data)
|
98 |
+
|
99 |
+
# 3. Because the trait is unavailable (trait_row=None), ensure a placeholder column exists for it
|
100 |
+
# so that the missing-value handling and bias checking can still run.
|
101 |
+
if trait not in linked_data.columns:
|
102 |
+
linked_data[trait] = None
|
103 |
+
|
104 |
+
# 4. Handle missing values (will remove samples missing the trait, which are all samples in this case)
|
105 |
+
final_data = handle_missing_values(linked_data, trait_col=trait)
|
106 |
+
|
107 |
+
# 5. Determine whether the trait is severely biased (the function requires a trait column).
|
108 |
+
trait_biased, final_data = judge_and_remove_biased_features(final_data, trait)
|
109 |
+
|
110 |
+
# 6. Perform final validation and record dataset metadata. Since trait is not available,
|
111 |
+
# the dataset will not be marked as usable for trait-based analysis.
|
112 |
+
is_usable = validate_and_save_cohort_info(
|
113 |
+
is_final=True,
|
114 |
+
cohort=cohort,
|
115 |
+
info_path=json_path,
|
116 |
+
is_gene_available=True, # We do have gene expression data
|
117 |
+
is_trait_available=False, # but the trait is absent
|
118 |
+
is_biased=trait_biased,
|
119 |
+
df=final_data,
|
120 |
+
note="The dataset lacks trait data, but partial preprocessing was still performed."
|
121 |
+
)
|
122 |
+
|
123 |
+
# 7. If the dataset is somehow deemed usable, save the final linked data; otherwise, skip.
|
124 |
+
if is_usable:
|
125 |
+
final_data.to_csv(out_data_file)
|
p1/preprocess/Depression/code/GSE201332.py
ADDED
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Depression/GSE201332.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Depression/gene_data/GSE201332.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Depression/clinical_data/GSE201332.csv"
|
16 |
+
json_path = "./output/preprocess/1/Depression/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# Step 1: Determine if gene expression data is available
|
37 |
+
is_gene_available = True # Based on "Transcriptional profiling" from the series description
|
38 |
+
|
39 |
+
# Step 2.1: Identify variable availability
|
40 |
+
trait_row = 1 # "subject status: healthy controls" vs. "subject status: MDD patients"
|
41 |
+
age_row = 3 # "age: 48y", "age: 33y", etc.
|
42 |
+
gender_row = 2 # "gender: male", "gender: female"
|
43 |
+
|
44 |
+
# Step 2.2: Define conversion functions
|
45 |
+
def convert_trait(x: str):
|
46 |
+
if ":" in x:
|
47 |
+
val = x.split(":", 1)[1].strip().lower()
|
48 |
+
if "heathy" in val or "healthy" in val:
|
49 |
+
return 0
|
50 |
+
elif "mdd" in val:
|
51 |
+
return 1
|
52 |
+
return None
|
53 |
+
|
54 |
+
def convert_age(x: str):
|
55 |
+
if ":" in x:
|
56 |
+
val = x.split(":", 1)[1].strip().lower().replace("y", "")
|
57 |
+
try:
|
58 |
+
return float(val)
|
59 |
+
except:
|
60 |
+
return None
|
61 |
+
return None
|
62 |
+
|
63 |
+
def convert_gender(x: str):
|
64 |
+
if ":" in x:
|
65 |
+
val = x.split(":", 1)[1].strip().lower()
|
66 |
+
if "female" in val:
|
67 |
+
return 0
|
68 |
+
elif "male" in val:
|
69 |
+
return 1
|
70 |
+
return None
|
71 |
+
|
72 |
+
# Step 3: Initial filtering and saving metadata
|
73 |
+
is_trait_available = (trait_row is not None)
|
74 |
+
is_usable = 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 |
+
# Step 4: Clinical feature extraction if trait is available
|
83 |
+
if trait_row is not None:
|
84 |
+
selected_clinical_df = geo_select_clinical_features(
|
85 |
+
clinical_data,
|
86 |
+
trait=trait,
|
87 |
+
trait_row=trait_row,
|
88 |
+
convert_trait=convert_trait,
|
89 |
+
age_row=age_row,
|
90 |
+
convert_age=convert_age,
|
91 |
+
gender_row=gender_row,
|
92 |
+
convert_gender=convert_gender
|
93 |
+
)
|
94 |
+
print("Preview of selected clinical features:")
|
95 |
+
print(preview_df(selected_clinical_df))
|
96 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
97 |
+
# STEP3
|
98 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
99 |
+
gene_data = get_genetic_data(matrix_file)
|
100 |
+
|
101 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
102 |
+
print(gene_data.index[:20])
|
103 |
+
# The provided gene identifiers ("1", "2", "3", ...) are numeric indices, which are not standard human gene symbols.
|
104 |
+
# Hence, they must be mapped to gene symbols.
|
105 |
+
print("requires_gene_mapping = True")
|
106 |
+
# STEP5
|
107 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
108 |
+
gene_annotation = get_gene_annotation(soft_file)
|
109 |
+
|
110 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
111 |
+
print("Gene annotation preview:")
|
112 |
+
print(preview_df(gene_annotation))
|
113 |
+
# STEP: Gene Identifier Mapping
|
114 |
+
|
115 |
+
# 1. From the preview, the "ID" column in the gene_annotation matches the gene expression "ID" from gene_data.
|
116 |
+
# The "NAME" column in gene_annotation appears to store the gene symbol (though it contains corner controls in the preview).
|
117 |
+
|
118 |
+
# 2. Get the gene mapping dataframe
|
119 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='NAME')
|
120 |
+
|
121 |
+
# 3. Convert probe-level measurements into gene-level data
|
122 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
123 |
+
import pandas as pd
|
124 |
+
|
125 |
+
# STEP 7
|
126 |
+
|
127 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
128 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
129 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
130 |
+
|
131 |
+
# 2. Read the clinical data (which was saved with index=False) and reconstruct its original shape,
|
132 |
+
# i.e. row index = ['Depression','Age','Gender'] and columns = [sample IDs].
|
133 |
+
raw_df = pd.read_csv(out_clinical_data_file, header=None)
|
134 |
+
# Use the first row as column names
|
135 |
+
raw_df.columns = raw_df.iloc[0]
|
136 |
+
# Drop the first row (already used as header)
|
137 |
+
raw_df = raw_df.drop(raw_df.index[0])
|
138 |
+
# Now the first column contains the row labels 'Depression', 'Age', 'Gender'
|
139 |
+
raw_df = raw_df.set_index(raw_df.columns[0])
|
140 |
+
# Drop that column so that only sample IDs remain as columns
|
141 |
+
selected_clinical_df = raw_df.drop(raw_df.columns[0], axis=1)
|
142 |
+
|
143 |
+
# Link the clinical and genetic data
|
144 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
145 |
+
|
146 |
+
# 3. Handle missing values (drop missing trait, remove high-missing genes/samples, impute)
|
147 |
+
linked_data = handle_missing_values(linked_data, trait_col=trait)
|
148 |
+
|
149 |
+
# 4. Determine if the trait or demographic features are severely biased
|
150 |
+
is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
151 |
+
|
152 |
+
# 5. Final quality validation and metadata recording
|
153 |
+
is_usable = validate_and_save_cohort_info(
|
154 |
+
is_final=True,
|
155 |
+
cohort=cohort,
|
156 |
+
info_path=json_path,
|
157 |
+
is_gene_available=True,
|
158 |
+
is_trait_available=True,
|
159 |
+
is_biased=is_trait_biased,
|
160 |
+
df=linked_data,
|
161 |
+
note="All steps completed successfully."
|
162 |
+
)
|
163 |
+
|
164 |
+
# 6. If the dataset is usable, save the final linked data
|
165 |
+
if is_usable:
|
166 |
+
linked_data.to_csv(out_data_file)
|
167 |
+
import pandas as pd
|
168 |
+
|
169 |
+
# STEP 8
|
170 |
+
|
171 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
172 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
173 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
174 |
+
|
175 |
+
# 2. Read the clinical data that was saved with index=False, using the first column as index ('Depression','Age','Gender'),
|
176 |
+
# and the remaining columns as sample IDs.
|
177 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0) # Row index will be ['Depression','Age','Gender']
|
178 |
+
# The columns should match the sample IDs.
|
179 |
+
|
180 |
+
# 3. Link clinical and gene expression data
|
181 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
182 |
+
|
183 |
+
# 4. Handle missing values (drop missing trait, remove high-missing genes/samples, impute)
|
184 |
+
linked_data = handle_missing_values(linked_data, trait_col=trait)
|
185 |
+
|
186 |
+
# 5. Determine if the trait or demographic features are severely biased, removing biased demographics
|
187 |
+
is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
188 |
+
|
189 |
+
# 6. Final quality validation and metadata recording
|
190 |
+
is_usable = validate_and_save_cohort_info(
|
191 |
+
is_final=True,
|
192 |
+
cohort=cohort,
|
193 |
+
info_path=json_path,
|
194 |
+
is_gene_available=True,
|
195 |
+
is_trait_available=True,
|
196 |
+
is_biased=is_trait_biased,
|
197 |
+
df=linked_data,
|
198 |
+
note="All steps completed successfully."
|
199 |
+
)
|
200 |
+
|
201 |
+
# 7. If the dataset is deemed usable, save the final linked data
|
202 |
+
if is_usable:
|
203 |
+
linked_data.to_csv(out_data_file)
|
204 |
+
import pandas as pd
|
205 |
+
|
206 |
+
# STEP 9
|
207 |
+
|
208 |
+
# 1. Normalize the gene data using synonyms and save it.
|
209 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
210 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
211 |
+
|
212 |
+
# 2. Read the clinical data that was saved with index=False.
|
213 |
+
# The first row in the CSV is the sample IDs, and the next rows are the values for [trait, Age, Gender].
|
214 |
+
# Restore the row index to [trait, "Age", "Gender"] so columns become sample IDs.
|
215 |
+
clinical_df = pd.read_csv(out_clinical_data_file, header=0)
|
216 |
+
clinical_df.index = [trait, "Age", "Gender"]
|
217 |
+
|
218 |
+
# 3. Link clinical and gene expression data by sample (column) alignment.
|
219 |
+
linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
|
220 |
+
|
221 |
+
# 4. Handle missing values (remove samples with missing trait, remove genes/samples with high missingness, then impute).
|
222 |
+
linked_data = handle_missing_values(linked_data, trait_col=trait)
|
223 |
+
|
224 |
+
# 5. Determine if the trait or demographic features are severely biased, dropping biased demographics if necessary.
|
225 |
+
is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
226 |
+
|
227 |
+
# 6. Final quality validation and metadata recording.
|
228 |
+
is_usable = validate_and_save_cohort_info(
|
229 |
+
is_final=True,
|
230 |
+
cohort=cohort,
|
231 |
+
info_path=json_path,
|
232 |
+
is_gene_available=True,
|
233 |
+
is_trait_available=True,
|
234 |
+
is_biased=is_trait_biased,
|
235 |
+
df=linked_data,
|
236 |
+
note="All steps completed successfully."
|
237 |
+
)
|
238 |
+
|
239 |
+
# 7. If the dataset is deemed usable, save the final linked data.
|
240 |
+
if is_usable:
|
241 |
+
linked_data.to_csv(out_data_file)
|
p1/preprocess/Depression/code/GSE208668.py
ADDED
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/preprocess/1/Depression/GSE208668.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Depression/gene_data/GSE208668.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Depression/clinical_data/GSE208668.csv"
|
16 |
+
json_path = "./output/preprocess/1/Depression/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Determine if gene expression data is available
|
37 |
+
# Based on the series description ("Genome-wide transcriptional profiling results"), we treat it as gene expression data
|
38 |
+
is_gene_available = True
|
39 |
+
|
40 |
+
# 2. Identify availability of variables and define their row keys
|
41 |
+
# Our trait of interest is "Depression", and we see "history of depression: yes/no" in row 9.
|
42 |
+
# Hence trait_row=9. Age is in row 1. Gender is in row 2.
|
43 |
+
trait_row = 9
|
44 |
+
age_row = 1
|
45 |
+
gender_row = 2
|
46 |
+
|
47 |
+
# 2.2 Define data type conversion functions
|
48 |
+
def convert_trait(value):
|
49 |
+
if not value or ':' not in value:
|
50 |
+
return None
|
51 |
+
val = value.split(':', 1)[1].strip().lower()
|
52 |
+
if val == 'yes':
|
53 |
+
return 1
|
54 |
+
elif val == 'no':
|
55 |
+
return 0
|
56 |
+
else:
|
57 |
+
return None
|
58 |
+
|
59 |
+
def convert_age(value):
|
60 |
+
if not value or ':' not in value:
|
61 |
+
return None
|
62 |
+
val = value.split(':', 1)[1].strip()
|
63 |
+
try:
|
64 |
+
return float(val)
|
65 |
+
except:
|
66 |
+
return None
|
67 |
+
|
68 |
+
def convert_gender(value):
|
69 |
+
if not value or ':' not in value:
|
70 |
+
return None
|
71 |
+
val = value.split(':', 1)[1].strip().lower()
|
72 |
+
if val == 'female':
|
73 |
+
return 0
|
74 |
+
elif val == 'male':
|
75 |
+
return 1
|
76 |
+
else:
|
77 |
+
return None
|
78 |
+
|
79 |
+
# 3. Conduct initial filtering on dataset usability and save metadata
|
80 |
+
is_trait_available = (trait_row is not None)
|
81 |
+
|
82 |
+
is_usable = validate_and_save_cohort_info(
|
83 |
+
is_final=False,
|
84 |
+
cohort=cohort,
|
85 |
+
info_path=json_path,
|
86 |
+
is_gene_available=is_gene_available,
|
87 |
+
is_trait_available=is_trait_available
|
88 |
+
)
|
89 |
+
|
90 |
+
# 4. If trait data is available, extract clinical features
|
91 |
+
if trait_row is not None:
|
92 |
+
df_clinical = geo_select_clinical_features(
|
93 |
+
clinical_data,
|
94 |
+
trait=trait,
|
95 |
+
trait_row=trait_row,
|
96 |
+
convert_trait=convert_trait,
|
97 |
+
age_row=age_row,
|
98 |
+
convert_age=convert_age,
|
99 |
+
gender_row=gender_row,
|
100 |
+
convert_gender=convert_gender
|
101 |
+
)
|
102 |
+
|
103 |
+
# Preview and save clinical data
|
104 |
+
preview_output = preview_df(df_clinical)
|
105 |
+
print("Preview of extracted clinical features:")
|
106 |
+
print(preview_output)
|
107 |
+
|
108 |
+
df_clinical.to_csv(out_clinical_data_file, index=False)
|
109 |
+
# STEP3
|
110 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
111 |
+
gene_data = get_genetic_data(matrix_file)
|
112 |
+
|
113 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
114 |
+
print(gene_data.index[:20])
|
115 |
+
# Based on observation, some identifiers like "7A5" appear to be alternative or outdated gene symbols.
|
116 |
+
# To ensure consistent and up-to-date identifiers, gene mapping is needed.
|
117 |
+
|
118 |
+
requires_gene_mapping = True
|
119 |
+
print(f"requires_gene_mapping = {requires_gene_mapping}")
|
120 |
+
# STEP5
|
121 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
122 |
+
gene_annotation = get_gene_annotation(soft_file)
|
123 |
+
|
124 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
125 |
+
print("Gene annotation preview:")
|
126 |
+
print(preview_df(gene_annotation))
|
127 |
+
# STEP6: Gene Identifier Mapping
|
128 |
+
|
129 |
+
# 1. Decide which columns match the gene identifiers in the expression data and which contain the gene symbols.
|
130 |
+
# From the annotation preview, "ID" matches the identifiers in gene_data's index, and "ORF" contains the gene symbols.
|
131 |
+
|
132 |
+
# 2. Get a gene mapping dataframe by selecting "ID" and "ORF" from the gene annotation.
|
133 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='ORF')
|
134 |
+
|
135 |
+
# 3. Convert probe-level measurements to gene expression data by applying the mapping.
|
136 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
137 |
+
|
138 |
+
# For verification of shape or quick sanity check, we print the shape of the resulting gene_data dataframe
|
139 |
+
print("Mapped gene_data shape:", gene_data.shape)
|
140 |
+
import pandas as pd
|
141 |
+
|
142 |
+
# STEP7
|
143 |
+
|
144 |
+
# 1. Normalize gene symbols in the gene expression data and save the result.
|
145 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
146 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
147 |
+
|
148 |
+
# 2. Read the clinical feature data. Since it was saved with index=False (causing the first row to become headers),
|
149 |
+
# we specify header=0 and then set "Unnamed: 0" as the index. This recovers rows like "Depression", "Age", "Gender".
|
150 |
+
df_temp = pd.read_csv(out_clinical_data_file, header=0)
|
151 |
+
df_temp.set_index("Unnamed: 0", inplace=True)
|
152 |
+
df_clinical = df_temp
|
153 |
+
|
154 |
+
# 3. Link the clinical data and gene data.
|
155 |
+
linked_data = geo_link_clinical_genetic_data(df_clinical, normalized_gene_data)
|
156 |
+
|
157 |
+
# 4. Handle missing values systematically (drop missing trait, drop genes >20% missing, etc.).
|
158 |
+
linked_data = handle_missing_values(linked_data, trait)
|
159 |
+
|
160 |
+
# 5. Judge and remove biased features. If the trait is biased, we record it.
|
161 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
162 |
+
|
163 |
+
# 6. Conduct final validation and save cohort info.
|
164 |
+
is_usable = validate_and_save_cohort_info(
|
165 |
+
is_final=True,
|
166 |
+
cohort=cohort,
|
167 |
+
info_path=json_path,
|
168 |
+
is_gene_available=True,
|
169 |
+
is_trait_available=True,
|
170 |
+
is_biased=trait_biased,
|
171 |
+
df=linked_data,
|
172 |
+
note="All steps completed for GSE208668."
|
173 |
+
)
|
174 |
+
|
175 |
+
# 7. If usable, save the final linked data.
|
176 |
+
if is_usable:
|
177 |
+
linked_data.to_csv(out_data_file)
|
178 |
+
import pandas as pd
|
179 |
+
|
180 |
+
# STEP8
|
181 |
+
|
182 |
+
# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.
|
183 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
184 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
185 |
+
|
186 |
+
# 2. Read the clinical CSV. Since we saved it with index=False, the trait, age, and gender rows
|
187 |
+
# are now just 3 data rows. Hence we'll read without specifying an index, and then manually
|
188 |
+
# assign the correct row labels.
|
189 |
+
df_clinical = pd.read_csv(out_clinical_data_file)
|
190 |
+
# The DataFrame should now have shape (3, number_of_samples), with the columns being sample IDs
|
191 |
+
# and the row indices just 0,1,2. We rename them to [trait, "Age", "Gender"].
|
192 |
+
if df_clinical.shape[0] == 3:
|
193 |
+
df_clinical.index = [trait, "Age", "Gender"]
|
194 |
+
else:
|
195 |
+
# If we unexpectedly have more or fewer rows, you may need to adjust this code.
|
196 |
+
raise ValueError(f"Unexpected shape in clinical data: {df_clinical.shape}")
|
197 |
+
|
198 |
+
# 3. Link the clinical and genetic data on sample IDs.
|
199 |
+
linked_data = geo_link_clinical_genetic_data(df_clinical, normalized_gene_data)
|
200 |
+
|
201 |
+
# 4. Handle missing values systematically.
|
202 |
+
# This requires the trait to be a column in linked_data; with our structure,
|
203 |
+
# 'Depression' is indeed a column after transposing in geo_link_clinical_genetic_data.
|
204 |
+
linked_data = handle_missing_values(linked_data, trait)
|
205 |
+
|
206 |
+
# 5. Determine whether the trait is severely biased; remove biased demographic covariates.
|
207 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
208 |
+
|
209 |
+
# 6. Conduct final quality validation and save cohort metadata.
|
210 |
+
is_usable = validate_and_save_cohort_info(
|
211 |
+
is_final=True,
|
212 |
+
cohort=cohort,
|
213 |
+
info_path=json_path,
|
214 |
+
is_gene_available=True,
|
215 |
+
is_trait_available=True,
|
216 |
+
is_biased=trait_biased,
|
217 |
+
df=linked_data,
|
218 |
+
note="All steps completed for GSE208668."
|
219 |
+
)
|
220 |
+
|
221 |
+
# 7. If the dataset is usable, save the final linked data.
|
222 |
+
if is_usable:
|
223 |
+
linked_data.to_csv(out_data_file)
|