Spaces:
Paused
Paused
add ec number prediction backend with model and config
Browse files- data/ec_class_names.json +412 -0
- data/models/ec/prothgt-ec-config.yaml +27 -0
- data/models/ec/prothgt-ec-model.pt +3 -0
- run_prothgt_ec_app.py +226 -0
data/ec_class_names.json
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"1": "Oxidoreductases",
|
| 3 |
+
"1.1": "Acting on the CH-OH group of donors",
|
| 4 |
+
"1.1.1": "With NAD(+) or NADP(+) as acceptor",
|
| 5 |
+
"1.1.2": "With a cytochrome as acceptor",
|
| 6 |
+
"1.1.3": "With oxygen as acceptor",
|
| 7 |
+
"1.1.4": "With a disulfide as acceptor",
|
| 8 |
+
"1.1.5": "With a quinone or similar compound as acceptor",
|
| 9 |
+
"1.1.7": "With an iron-sulfur protein as acceptor",
|
| 10 |
+
"1.1.9": "With a copper protein as acceptor",
|
| 11 |
+
"1.1.98": "With other, known, acceptors",
|
| 12 |
+
"1.1.99": "With other acceptors",
|
| 13 |
+
"1.2": "Acting on the aldehyde or oxo group of donors",
|
| 14 |
+
"1.2.1": "With NAD(+) or NADP(+) as acceptor",
|
| 15 |
+
"1.2.2": "With a cytochrome as acceptor",
|
| 16 |
+
"1.2.3": "With oxygen as acceptor",
|
| 17 |
+
"1.2.4": "With a disulfide as acceptor",
|
| 18 |
+
"1.2.5": "With a quinone or similar compound as acceptor",
|
| 19 |
+
"1.2.7": "With an iron-sulfur protein as acceptor",
|
| 20 |
+
"1.2.8": "With a flavin or flavoprotein as acceptor",
|
| 21 |
+
"1.2.98": "With other, known, acceptors",
|
| 22 |
+
"1.2.99": "With other acceptors",
|
| 23 |
+
"1.3": "Acting on the CH-CH group of donors",
|
| 24 |
+
"1.3.1": "With NAD(+) or NADP(+) as acceptor",
|
| 25 |
+
"1.3.2": "With a cytochrome as acceptor",
|
| 26 |
+
"1.3.3": "With oxygen as acceptor",
|
| 27 |
+
"1.3.4": "With a disulfide as acceptor",
|
| 28 |
+
"1.3.5": "With a quinone or related compound as acceptor",
|
| 29 |
+
"1.3.7": "With an iron-sulfur protein as acceptor",
|
| 30 |
+
"1.3.8": "With a flavin as acceptor",
|
| 31 |
+
"1.3.98": "With other, known, acceptors",
|
| 32 |
+
"1.3.99": "With other acceptors",
|
| 33 |
+
"1.4": "Acting on the CH-NH2 group of donors",
|
| 34 |
+
"1.4.1": "With NAD(+) or NADP(+) as acceptor",
|
| 35 |
+
"1.4.2": "With a cytochrome as acceptor",
|
| 36 |
+
"1.4.3": "With oxygen as acceptor",
|
| 37 |
+
"1.4.4": "With a disulfide as acceptor",
|
| 38 |
+
"1.4.5": "With a quinone or similar compound as acceptor",
|
| 39 |
+
"1.4.7": "With an iron-sulfur protein as acceptor",
|
| 40 |
+
"1.4.9": "With a copper protein as acceptor",
|
| 41 |
+
"1.4.98": "With other, known, acceptors",
|
| 42 |
+
"1.4.99": "With other acceptors",
|
| 43 |
+
"1.5": "Acting on the CH-NH group of donors",
|
| 44 |
+
"1.5.1": "With NAD(+) or NADP(+) as acceptor",
|
| 45 |
+
"1.5.3": "With oxygen as acceptor",
|
| 46 |
+
"1.5.4": "With a disulfide as acceptor",
|
| 47 |
+
"1.5.5": "With a quinone or similar compound as acceptor",
|
| 48 |
+
"1.5.7": "With an iron-sulfur protein as acceptor",
|
| 49 |
+
"1.5.8": "With a flavin as acceptor",
|
| 50 |
+
"1.5.98": "With other, known, acceptors",
|
| 51 |
+
"1.5.99": "With other acceptors",
|
| 52 |
+
"1.6": "Acting on NADH or NADPH",
|
| 53 |
+
"1.6.1": "With NAD(+) or NADP(+) as acceptor",
|
| 54 |
+
"1.6.2": "With a heme protein as acceptor",
|
| 55 |
+
"1.6.3": "With oxygen as acceptor",
|
| 56 |
+
"1.6.4": "With a disulfide as acceptor",
|
| 57 |
+
"1.6.5": "With a quinone or similar compound as acceptor",
|
| 58 |
+
"1.6.6": "With a nitrogenous group as acceptor",
|
| 59 |
+
"1.6.7": "With a iron-sulfur protein as acceptor",
|
| 60 |
+
"1.6.8": "With a flavin as acceptor",
|
| 61 |
+
"1.6.99": "With other acceptors",
|
| 62 |
+
"1.7": "Acting on other nitrogenous compounds as donors",
|
| 63 |
+
"1.7.1": "With NAD(+) or NADP(+) as acceptor",
|
| 64 |
+
"1.7.2": "With a cytochrome as acceptor",
|
| 65 |
+
"1.7.3": "With oxygen as acceptor",
|
| 66 |
+
"1.7.5": "With a quinone or similar compound as acceptor",
|
| 67 |
+
"1.7.6": "With a nitrogenous group as acceptor",
|
| 68 |
+
"1.7.7": "With an iron-sulfur protein as acceptor",
|
| 69 |
+
"1.7.9": "With a copper protein as acceptor",
|
| 70 |
+
"1.7.99": "With other acceptors",
|
| 71 |
+
"1.8": "Acting on a sulfur group of donors",
|
| 72 |
+
"1.8.1": "With NAD(+) or NADP(+) as acceptor",
|
| 73 |
+
"1.8.2": "With a cytochrome as acceptor",
|
| 74 |
+
"1.8.3": "With oxygen as acceptor",
|
| 75 |
+
"1.8.4": "With a disulfide as acceptor",
|
| 76 |
+
"1.8.5": "With a quinone or similar compound as acceptor",
|
| 77 |
+
"1.8.6": "With an nitrogenous group as acceptor",
|
| 78 |
+
"1.8.7": "With an iron-sulfur protein as acceptor",
|
| 79 |
+
"1.8.98": "With other, known, acceptors",
|
| 80 |
+
"1.8.99": "With other acceptors",
|
| 81 |
+
"1.9": "Acting on a heme group of donors",
|
| 82 |
+
"1.9.3": "With oxygen as acceptor",
|
| 83 |
+
"1.9.6": "With a nitrogenous group as acceptor",
|
| 84 |
+
"1.9.98": "With other, known, acceptors",
|
| 85 |
+
"1.9.99": "With other acceptors",
|
| 86 |
+
"1.10": "Acting on diphenols and related substances as donors",
|
| 87 |
+
"1.10.1": "With NAD(+) or NADP(+) as acceptor",
|
| 88 |
+
"1.10.2": "With a cytochrome as acceptor",
|
| 89 |
+
"1.10.3": "With oxygen as acceptor",
|
| 90 |
+
"1.10.5": "With a quinone or related compound as acceptor",
|
| 91 |
+
"1.10.9": "With a copper protein as acceptor",
|
| 92 |
+
"1.10.98": "With other, known, acceptors",
|
| 93 |
+
"1.10.99": "With other acceptors",
|
| 94 |
+
"1.11": "Acting on a peroxide as acceptor",
|
| 95 |
+
"1.11.1": "Peroxidases",
|
| 96 |
+
"1.11.2": "With H2O2 as acceptor, one oxygen atom of which is incorporated into the product",
|
| 97 |
+
"1.12": "Acting on hydrogen as donors",
|
| 98 |
+
"1.12.1": "With NAD(+) or NADP(+) as acceptor",
|
| 99 |
+
"1.12.2": "With a cytochrome as acceptor",
|
| 100 |
+
"1.12.5": "With a quinone or similar compound as acceptor",
|
| 101 |
+
"1.12.7": "With an iron-sulfur protein as acceptor",
|
| 102 |
+
"1.12.98": "With other, known, acceptors",
|
| 103 |
+
"1.12.99": "With other acceptors",
|
| 104 |
+
"1.13": "Acting on single donors with incorporation of molecular oxygen (oxygenases). The oxygen incorporated need not be derived from O2",
|
| 105 |
+
"1.13.1": "With NADH or NADPH as one donor",
|
| 106 |
+
"1.13.11": "With incorporation of two atoms of oxygen",
|
| 107 |
+
"1.13.12": "With incorporation of one atom of oxygen (internal monooxygenases or internal mixed function oxidases)",
|
| 108 |
+
"1.13.99": "Miscellaneous",
|
| 109 |
+
"1.14": "Acting on paired donors, with incorporation or reduction of molecular oxygen. The oxygen incorporated need not be derived from O2",
|
| 110 |
+
"1.14.1": "With NADH or NADPH as one donor",
|
| 111 |
+
"1.14.2": "With ascorbate as one donor",
|
| 112 |
+
"1.14.3": "With reduced pteridine as one donor",
|
| 113 |
+
"1.14.11": "With 2-oxoglutarate as one donor, and incorporation of one atom each of oxygen into both donors",
|
| 114 |
+
"1.14.12": "With NADH or NADPH as one donor, and incorporation of two atoms of oxygen into one donor",
|
| 115 |
+
"1.14.13": "With NADH or NADPH as one donor, and incorporation of one atom of oxygen",
|
| 116 |
+
"1.14.14": "With reduced flavin or flavoprotein as one donor, and incorporation of one atom of oxygen",
|
| 117 |
+
"1.14.15": "With reduced iron-sulfur protein as one donor, and incorporation of one atom of oxygen",
|
| 118 |
+
"1.14.16": "With reduced pteridine as one donor, and incorporation of one atom of oxygen",
|
| 119 |
+
"1.14.17": "With reduced ascorbate as one donor, and incorporation of one atom of oxygen",
|
| 120 |
+
"1.14.18": "With another compound as one donor, and incorporation of one atom of oxygen",
|
| 121 |
+
"1.14.19": "With oxidation of a pair of donors resulting in the reduction of molecular oxygen to two molecules of water",
|
| 122 |
+
"1.14.20": "With 2-oxoglutarate as one donor, and the other dehydrogenated",
|
| 123 |
+
"1.14.21": "With NADH or NADPH as one donor, and the other dehydrogenated",
|
| 124 |
+
"1.14.99": "Miscellaneous",
|
| 125 |
+
"1.15": "Acting on superoxide as acceptor",
|
| 126 |
+
"1.15.1": "Acting on superoxide as acceptor",
|
| 127 |
+
"1.16": "Oxidizing metal ions",
|
| 128 |
+
"1.16.1": "With NAD(+) or NADP(+) as acceptor",
|
| 129 |
+
"1.16.2": "With a cytochrome as acceptor",
|
| 130 |
+
"1.16.3": "With oxygen as acceptor",
|
| 131 |
+
"1.16.5": "With a quinone or similar compound as acceptor",
|
| 132 |
+
"1.16.8": "With a flavin as acceptor",
|
| 133 |
+
"1.16.9": "With a copper protein as acceptor",
|
| 134 |
+
"1.16.98": "With other known acceptors",
|
| 135 |
+
"1.16.99": "With other acceptors",
|
| 136 |
+
"1.17": "Acting on CH or CH2 groups",
|
| 137 |
+
"1.17.1": "With NAD(+) or NADP(+) as acceptor",
|
| 138 |
+
"1.17.2": "With a cytochrome as acceptor",
|
| 139 |
+
"1.17.3": "With oxygen as acceptor",
|
| 140 |
+
"1.17.4": "With a disulfide as acceptor",
|
| 141 |
+
"1.17.5": "With a quinone or similar compound as acceptor",
|
| 142 |
+
"1.17.7": "With an iron-sulfur protein as acceptor",
|
| 143 |
+
"1.17.8": "With a flavin as acceptor",
|
| 144 |
+
"1.17.9": "With a copper protein as acceptor",
|
| 145 |
+
"1.17.98": "With other, known, acceptors",
|
| 146 |
+
"1.17.99": "With other acceptors",
|
| 147 |
+
"1.18": "Acting on iron-sulfur proteins as donors",
|
| 148 |
+
"1.18.1": "With NAD(+) or NADP(+) as acceptor",
|
| 149 |
+
"1.18.2": "With dinitrogen as acceptor",
|
| 150 |
+
"1.18.3": "With H(+) as acceptor",
|
| 151 |
+
"1.18.6": "With dinitrogen as acceptor",
|
| 152 |
+
"1.18.96": "With other, known, acceptors",
|
| 153 |
+
"1.18.99": "With H(+) as acceptor",
|
| 154 |
+
"1.19": "Acting on reduced flavodoxin as donor",
|
| 155 |
+
"1.19.1": "With NAD(+) or NADP(+) as acceptor",
|
| 156 |
+
"1.19.6": "With dinitrogen as acceptor",
|
| 157 |
+
"1.20": "Acting on phosphorus or arsenic in donors",
|
| 158 |
+
"1.20.1": "With NAD(+) or NADP(+) as acceptor",
|
| 159 |
+
"1.20.2": "With a cytochrome as acceptor",
|
| 160 |
+
"1.20.4": "With disulfide as acceptor",
|
| 161 |
+
"1.20.9": "With a copper protein as acceptor",
|
| 162 |
+
"1.20.98": "With other, known acceptors",
|
| 163 |
+
"1.20.99": "With other acceptors",
|
| 164 |
+
"1.21": "Catalyzing the reaction X-H + Y-H = 'X-Y'",
|
| 165 |
+
"1.21.1": "With NAD(+) or NADP(+) as acceptor",
|
| 166 |
+
"1.21.3": "With oxygen as acceptor",
|
| 167 |
+
"1.21.4": "With a disulfide as acceptor",
|
| 168 |
+
"1.21.98": "With other, known acceptors",
|
| 169 |
+
"1.21.99": "With other acceptors",
|
| 170 |
+
"1.22": "Acting on halogen in donors",
|
| 171 |
+
"1.22.1": "With NAD(+) or NADP(+) as acceptor",
|
| 172 |
+
"1.23": "Reducing C-O-C group as acceptor",
|
| 173 |
+
"1.23.1": "With NADH or NADPH as donor",
|
| 174 |
+
"1.23.5": "With a quinone or similar compound as acceptor",
|
| 175 |
+
"1.97": "Other oxidoreductases",
|
| 176 |
+
"1.97.1": "Other oxidoreductases",
|
| 177 |
+
"1.98": "Enzymes using H2 as reductant",
|
| 178 |
+
"1.98.1": "Other oxidoreductases",
|
| 179 |
+
"1.99": "Other enzymes using O2 as oxidant",
|
| 180 |
+
"1.99.1": "Hydroxylases",
|
| 181 |
+
"1.99.2": "Oxygenases",
|
| 182 |
+
"2": "Transferases",
|
| 183 |
+
"2.1": "Transferring one-carbon groups",
|
| 184 |
+
"2.1.1": "Methyltransferases",
|
| 185 |
+
"2.1.2": "Hydroxymethyl-, formyl- and related transferases",
|
| 186 |
+
"2.1.3": "Carboxy- and carbamoyltransferases",
|
| 187 |
+
"2.1.4": "Amidinotransferases",
|
| 188 |
+
"2.1.5": "Methylenetransferases",
|
| 189 |
+
"2.2": "Transferring aldehyde or ketonic groups",
|
| 190 |
+
"2.2.1": "Transketolases and transaldolases",
|
| 191 |
+
"2.3": "Acyltransferases",
|
| 192 |
+
"2.3.1": "Transferring groups other than amino-acyl groups",
|
| 193 |
+
"2.3.2": "Aminoacyltransferases",
|
| 194 |
+
"2.3.3": "Acyl groups converted into alkyl groups on transfer",
|
| 195 |
+
"2.4": "Glycosyltransferases",
|
| 196 |
+
"2.4.1": "Hexosyltransferases",
|
| 197 |
+
"2.4.2": "Pentosyltransferases",
|
| 198 |
+
"2.4.3": "Sialyltransferases",
|
| 199 |
+
"2.4.99": "Transferring other glycosyl groups",
|
| 200 |
+
"2.5": "Transferring alkyl or aryl groups, other than methyl groups",
|
| 201 |
+
"2.5.1": "Transferring alkyl or aryl groups, other than methyl groups",
|
| 202 |
+
"2.6": "Transferring nitrogenous groups",
|
| 203 |
+
"2.6.1": "Transaminases",
|
| 204 |
+
"2.6.2": "Amidinotransferases",
|
| 205 |
+
"2.6.3": "Oximinotransferases",
|
| 206 |
+
"2.6.99": "Transferring other nitrogenous groups",
|
| 207 |
+
"2.7": "Transferring phosphorus-containing groups",
|
| 208 |
+
"2.7.1": "Phosphotransferases with an alcohol group as acceptor",
|
| 209 |
+
"2.7.2": "Phosphotransferases with a carboxy group as acceptor",
|
| 210 |
+
"2.7.3": "Phosphotransferases with a nitrogenous group as acceptor",
|
| 211 |
+
"2.7.4": "Phosphotransferases with a phosphate group as acceptor",
|
| 212 |
+
"2.7.5": "Phosphotransferases with regeneration of donors, apparently catalyzing intramolecular transfers",
|
| 213 |
+
"2.7.6": "Diphosphotransferases",
|
| 214 |
+
"2.7.7": "Nucleotidyltransferases",
|
| 215 |
+
"2.7.8": "Transferases for other substituted phosphate groups",
|
| 216 |
+
"2.7.9": "Phosphotransferases with paired acceptors",
|
| 217 |
+
"2.7.10": "Protein-tyrosine kinases",
|
| 218 |
+
"2.7.11": "Protein-serine/threonine kinases",
|
| 219 |
+
"2.7.12": "Dual-specificity kinases (those acting on Ser/Thr and Tyr residues)",
|
| 220 |
+
"2.7.13": "Protein-histidine kinases",
|
| 221 |
+
"2.7.14": "Protein-arginine kinases",
|
| 222 |
+
"2.7.99": "Other protein kinases",
|
| 223 |
+
"2.8": "Transferring sulfur-containing groups",
|
| 224 |
+
"2.8.1": "Sulfurtransferases",
|
| 225 |
+
"2.8.2": "Sulfotransferases",
|
| 226 |
+
"2.8.3": "CoA-transferases",
|
| 227 |
+
"2.8.4": "Transferring alkylthio groups",
|
| 228 |
+
"2.8.5": "Thiosulfotransferases",
|
| 229 |
+
"2.9": "Transferring selenium-containing groups",
|
| 230 |
+
"2.9.1": "Selenotransferases",
|
| 231 |
+
"2.10": "Transferring molybdenum- or tungsten-containing groups",
|
| 232 |
+
"2.10.1": "Molybdenumtransferases or tungstentransferases with sulfide groups as acceptors",
|
| 233 |
+
"3": "Hydrolases",
|
| 234 |
+
"3.1": "Acting on ester bonds",
|
| 235 |
+
"3.1.1": "Carboxylic ester hydrolases",
|
| 236 |
+
"3.1.2": "Thiolester hydrolases",
|
| 237 |
+
"3.1.3": "Phosphoric monoester hydrolases",
|
| 238 |
+
"3.1.4": "Phosphoric diester hydrolases",
|
| 239 |
+
"3.1.5": "Triphosphoric monoester hydrolases",
|
| 240 |
+
"3.1.6": "Sulfuric ester hydrolases",
|
| 241 |
+
"3.1.7": "Diphosphoric monoester hydrolases",
|
| 242 |
+
"3.1.8": "Phosphoric triester hydrolases",
|
| 243 |
+
"3.1.11": "Exodeoxyribonucleases producing 5'-phosphomonoesters",
|
| 244 |
+
"3.1.12": "Exodeoxyribonucleases producing 3'-phosphomonoesters",
|
| 245 |
+
"3.1.13": "Exoribonucleases producing 5'-phosphomonoesters",
|
| 246 |
+
"3.1.14": "Exoribonucleases producing 3'-phosphomonoesters",
|
| 247 |
+
"3.1.15": "Exonucleases active with either ribo- or deoxyribonucleic acids and producing 5'-phosphomonoesters",
|
| 248 |
+
"3.1.16": "Exonucleases active with either ribo- or deoxyribonucleic acids and producing 3'-phosphomonoesters",
|
| 249 |
+
"3.1.21": "Endodeoxyribonucleases producing 5'-phosphomonoesters",
|
| 250 |
+
"3.1.22": "Endodeoxyribonucleases producing other than 5'-phosphomonoesters",
|
| 251 |
+
"3.1.23": "Site specific endodeoxyribonucleases: cleavage is sequence specific",
|
| 252 |
+
"3.1.24": "Site specific endodeoxyribonucleases: cleavage is not sequence specific",
|
| 253 |
+
"3.1.25": "Site-specific endodeoxyribonucleases specific for altered bases",
|
| 254 |
+
"3.1.26": "Endoribonucleases producing 5'-phosphomonoesters",
|
| 255 |
+
"3.1.27": "Endoribonucleases producing other than 5'-phosphomonoesters",
|
| 256 |
+
"3.1.30": "Endoribonucleases active with either ribo- or deoxyribonucleic acids and producing 5'-phosphomonoesters",
|
| 257 |
+
"3.1.31": "Endoribonucleases active with either ribo- or deoxyribonucleic acids and producing 3'-phosphomonoesters",
|
| 258 |
+
"3.2": "Glycosylases",
|
| 259 |
+
"3.2.1": "Glycosidases, i.e. enzymes hydrolyzing O- and S-glycosyl compounds",
|
| 260 |
+
"3.2.2": "Hydrolyzing N-glycosyl compounds",
|
| 261 |
+
"3.2.3": "Hydrolyzing S-glycosyl compounds",
|
| 262 |
+
"3.3": "Acting on ether bonds",
|
| 263 |
+
"3.3.1": "Thioether and trialkylsulfonium hydrolases",
|
| 264 |
+
"3.3.2": "Ether hydrolases",
|
| 265 |
+
"3.4": "Acting on peptide bonds (peptidases)",
|
| 266 |
+
"3.4.1": "alpha-Amino-acyl-peptide hydrolases",
|
| 267 |
+
"3.4.2": "Peptidyl-amino-acid hydrolases",
|
| 268 |
+
"3.4.3": "Dipeptide hydrolases",
|
| 269 |
+
"3.4.4": "Peptidyl peptide hydrolases",
|
| 270 |
+
"3.4.11": "Aminopeptidases",
|
| 271 |
+
"3.4.12": "Peptidylamino-acid hydrolases or acylamino-acid hydrolases",
|
| 272 |
+
"3.4.13": "Dipeptidases",
|
| 273 |
+
"3.4.14": "Dipeptidyl-peptidases and tripeptidyl-peptidases",
|
| 274 |
+
"3.4.15": "Peptidyl-dipeptidases",
|
| 275 |
+
"3.4.16": "Serine-type carboxypeptidases",
|
| 276 |
+
"3.4.17": "Metallocarboxypeptidases",
|
| 277 |
+
"3.4.18": "Cysteine-type carboxypeptidases",
|
| 278 |
+
"3.4.19": "Omega peptidases",
|
| 279 |
+
"3.4.21": "Serine endopeptidases",
|
| 280 |
+
"3.4.22": "Cysteine endopeptidases",
|
| 281 |
+
"3.4.23": "Aspartic endopeptidases",
|
| 282 |
+
"3.4.24": "Metalloendopeptidases",
|
| 283 |
+
"3.4.25": "Threonine endopeptidases",
|
| 284 |
+
"3.4.26": "Glutamic endopeptidases",
|
| 285 |
+
"3.4.99": "Endopeptidases of unknown catalytic mechanism",
|
| 286 |
+
"3.5": "Acting on carbon-nitrogen bonds, other than peptide bonds",
|
| 287 |
+
"3.5.1": "In linear amides",
|
| 288 |
+
"3.5.2": "In cyclic amides",
|
| 289 |
+
"3.5.3": "In linear amidines",
|
| 290 |
+
"3.5.4": "In cyclic amidines",
|
| 291 |
+
"3.5.5": "In nitriles",
|
| 292 |
+
"3.5.99": "In other compounds",
|
| 293 |
+
"3.6": "Acting on acid anhydrides",
|
| 294 |
+
"3.6.1": "In phosphorus-containing anhydrides",
|
| 295 |
+
"3.6.2": "In sulfonyl-containing anhydrides",
|
| 296 |
+
"3.6.3": "Acting on acid anhydrides; catalyzing transmembrane movement of substances",
|
| 297 |
+
"3.6.4": "Acting on ATP; involved in cellular and subcellular movement",
|
| 298 |
+
"3.6.5": "Acting on GTP; involved in cellular and subcellular movement",
|
| 299 |
+
"3.7": "Acting on carbon-carbon bonds",
|
| 300 |
+
"3.7.1": "In ketonic substances",
|
| 301 |
+
"3.8": "Acting on halide bonds",
|
| 302 |
+
"3.8.1": "In C-halide compounds",
|
| 303 |
+
"3.8.2": "In P-halide compounds",
|
| 304 |
+
"3.9": "Acting on phosphorus-nitrogen bonds",
|
| 305 |
+
"3.9.1": "Acting on phosphorus-nitrogen bonds",
|
| 306 |
+
"3.10": "Acting on sulfur-nitrogen bonds",
|
| 307 |
+
"3.10.1": "Acting on sulfur-nitrogen bonds",
|
| 308 |
+
"3.11": "Acting on carbon-phosphorus bonds",
|
| 309 |
+
"3.11.1": "Acting on carbon-phosphorus bonds",
|
| 310 |
+
"3.12": "Acting on sulfur-sulfur bonds",
|
| 311 |
+
"3.12.1": "Acting on sulfur-sulfur bonds",
|
| 312 |
+
"3.13": "Acting on carbon-sulfur bonds",
|
| 313 |
+
"3.13.1": "Acting on carbon-sulfur bonds",
|
| 314 |
+
"3.13.2": "Thioether and trialkylsulfonium hydrolases",
|
| 315 |
+
"4": "Lyases",
|
| 316 |
+
"4.1": "Carbon-carbon lyases",
|
| 317 |
+
"4.1.1": "Carboxy-lyases",
|
| 318 |
+
"4.1.2": "Aldehyde-lyases",
|
| 319 |
+
"4.1.3": "Oxo-acid-lyases",
|
| 320 |
+
"4.1.99": "Other carbon-carbon lyases",
|
| 321 |
+
"4.2": "Carbon-oxygen lyases",
|
| 322 |
+
"4.2.1": "Hydro-lyases",
|
| 323 |
+
"4.2.2": "Acting on polysaccharides",
|
| 324 |
+
"4.2.3": "Acting on phosphates",
|
| 325 |
+
"4.2.99": "Other carbon-oxygen lyases",
|
| 326 |
+
"4.3": "Carbon-nitrogen lyases",
|
| 327 |
+
"4.3.1": "Ammonia-lyases",
|
| 328 |
+
"4.3.2": "Lyases acting on amides, amidines, etc",
|
| 329 |
+
"4.3.3": "Amine-lyases",
|
| 330 |
+
"4.3.99": "Other carbon-nitrogen lyases",
|
| 331 |
+
"4.4": "Carbon-sulfur lyases",
|
| 332 |
+
"4.4.1": "Carbon-sulfur lyases",
|
| 333 |
+
"4.5": "Carbon-halide lyases",
|
| 334 |
+
"4.5.1": "Carbon-halide lyases",
|
| 335 |
+
"4.6": "Phosphorus-oxygen lyases",
|
| 336 |
+
"4.6.1": "Phosphorus-oxygen lyases",
|
| 337 |
+
"4.7": "Carbon-phosphorus lyases",
|
| 338 |
+
"4.7.1": "Carbon-phosphorus lyases",
|
| 339 |
+
"4.8": "Nitrogen-oxygen lyases",
|
| 340 |
+
"4.8.1": "Hydro-lyases",
|
| 341 |
+
"4.98": "ATP-independent chelatases",
|
| 342 |
+
"4.98.1": "Forming coordination complexes",
|
| 343 |
+
"4.99": "Other lyases",
|
| 344 |
+
"4.99.1": "Other lyases",
|
| 345 |
+
"5": "Isomerases",
|
| 346 |
+
"5.1": "Racemases and epimerases",
|
| 347 |
+
"5.1.1": "Acting on amino acids and derivatives",
|
| 348 |
+
"5.1.2": "Acting on hydroxy acids and derivatives",
|
| 349 |
+
"5.1.3": "Acting on carbohydrates and derivatives",
|
| 350 |
+
"5.1.99": "Acting on other compounds",
|
| 351 |
+
"5.2": "Cis-trans-isomerases",
|
| 352 |
+
"5.2.1": "Cis-trans isomerases",
|
| 353 |
+
"5.3": "Intramolecular oxidoreductases",
|
| 354 |
+
"5.3.1": "Interconverting aldoses and ketoses",
|
| 355 |
+
"5.3.2": "Interconverting keto- and enol-groups",
|
| 356 |
+
"5.3.3": "Transposing C=C bonds",
|
| 357 |
+
"5.3.4": "Transposing S-S bonds",
|
| 358 |
+
"5.3.99": "Other intramolecular oxidoreductases",
|
| 359 |
+
"5.4": "Intramolecular transferases",
|
| 360 |
+
"5.4.1": "Transferring acyl groups",
|
| 361 |
+
"5.4.2": "Phosphotransferases (phosphomutases)",
|
| 362 |
+
"5.4.3": "Transferring amino groups",
|
| 363 |
+
"5.4.4": "Transferring hydroxy groups",
|
| 364 |
+
"5.4.99": "Transferring other groups",
|
| 365 |
+
"5.5": "Intramolecular lyases",
|
| 366 |
+
"5.5.1": "Intramolecular lyases",
|
| 367 |
+
"5.6": "Isomerases altering macromolecular conformation",
|
| 368 |
+
"5.6.1": "Enzymes altering polypeptide conformation or assembly",
|
| 369 |
+
"5.6.2": "Enzymes altering nucleic acid conformation",
|
| 370 |
+
"5.99": "Other isomerases",
|
| 371 |
+
"5.99.1": "Other isomerases",
|
| 372 |
+
"6": "Ligases",
|
| 373 |
+
"6.1": "Forming carbon-oxygen bonds",
|
| 374 |
+
"6.1.1": "Ligases forming aminoacyl-tRNA and related compounds",
|
| 375 |
+
"6.1.2": "Acid--alcohol ligases (ester synthases)",
|
| 376 |
+
"6.1.3": "Cyclo-ligases",
|
| 377 |
+
"6.2": "Forming carbon-sulfur bonds",
|
| 378 |
+
"6.2.1": "Acid--thiol ligases",
|
| 379 |
+
"6.2.2": "Amide--thiol ligases",
|
| 380 |
+
"6.3": "Forming carbon-nitrogen bonds",
|
| 381 |
+
"6.3.1": "Acid--ammonia (or amine) ligases (amide synthases)",
|
| 382 |
+
"6.3.2": "Acid--amino-acid ligases (peptide synthases)",
|
| 383 |
+
"6.3.3": "Cyclo-ligases",
|
| 384 |
+
"6.3.4": "Other carbon--nitrogen ligases",
|
| 385 |
+
"6.3.5": "Carbon--nitrogen ligases with glutamine as amido-N-donor",
|
| 386 |
+
"6.4": "Forming carbon-carbon bonds",
|
| 387 |
+
"6.4.1": "Forming carbon-carbon bonds",
|
| 388 |
+
"6.5": "Forming phosphoric ester bonds",
|
| 389 |
+
"6.5.1": "Forming phosphoric ester bonds",
|
| 390 |
+
"6.6": "Forming nitrogen-metal bonds",
|
| 391 |
+
"6.6.1": "Forming coordination complexes",
|
| 392 |
+
"6.7": "Forming nitrogen-nitrogen bonds",
|
| 393 |
+
"6.7.1": "Forming diazo bonds",
|
| 394 |
+
"7": "Translocases",
|
| 395 |
+
"7.1": "Catalysing the translocation of hydrons",
|
| 396 |
+
"7.1.1": "Hydron translocation or charge separation linked to oxidoreductase reactions",
|
| 397 |
+
"7.1.2": "Hydron translocation linked to the hydrolysis of a nucleoside triphosphate",
|
| 398 |
+
"7.1.3": "Hydron translocation linked to the hydrolysis of diphosphate",
|
| 399 |
+
"7.2": "Catalysing the translocation of inorganic cations",
|
| 400 |
+
"7.2.1": "Linked to oxidoreductase reactions",
|
| 401 |
+
"7.2.2": "Linked to the hydrolysis of a nucleoside triphosphate",
|
| 402 |
+
"7.2.3": "Linked to the hydrolysis of diphosphate",
|
| 403 |
+
"7.2.4": "Linked to decarboxylation",
|
| 404 |
+
"7.3": "Catalysing the translocation of inorganic anions and their chelates",
|
| 405 |
+
"7.3.2": "Linked to the hydrolysis of a nucleoside triphosphate",
|
| 406 |
+
"7.4": "Catalysing the translocation amino acids and peptides",
|
| 407 |
+
"7.4.2": "Linked to the hydrolysis of a nucleoside triphosphate",
|
| 408 |
+
"7.5": "Catalysing the translocation carbohydrates and their derivatives",
|
| 409 |
+
"7.5.2": "Linked to the hydrolysis of a nucleoside triphosphate",
|
| 410 |
+
"7.6": "Catalysing the translocation of other compounds",
|
| 411 |
+
"7.6.2": "Linked to the hydrolysis of a nucleoside triphosphate"
|
| 412 |
+
}
|
data/models/ec/prothgt-ec-config.yaml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"lr": 0.001,
|
| 3 |
+
"mlp_lr": 0.005,
|
| 4 |
+
"wd": 5e-05,
|
| 5 |
+
"mlp_wd": 0.0,
|
| 6 |
+
"epochs": 80,
|
| 7 |
+
"tr_batch_size": 1024,
|
| 8 |
+
"hidden_channels": 256,
|
| 9 |
+
"num_heads": 16,
|
| 10 |
+
"num_layers": 2,
|
| 11 |
+
"num_neighbors": [32],
|
| 12 |
+
"disjoint_train_ratio": 0.3,
|
| 13 |
+
"mlp_dropout": 0.1,
|
| 14 |
+
"grad_clip_norm": 5.0,
|
| 15 |
+
"eval_threshold": 0.5,
|
| 16 |
+
"neg_sampling_ratio_l1": 6,
|
| 17 |
+
"pos_weight_l1": 6,
|
| 18 |
+
"neg_sampling_ratio_l2": 70,
|
| 19 |
+
"pos_weight_l2": 70,
|
| 20 |
+
"neg_sampling_ratio_l3": 100,
|
| 21 |
+
"pos_weight_l3": 100,
|
| 22 |
+
"neg_sampling_ratio_l4": 100,
|
| 23 |
+
"pos_weight_l4": 100,
|
| 24 |
+
"test_on_cpu": true,
|
| 25 |
+
"checkpoint_interval": 20,
|
| 26 |
+
"val_eval_num_proteins": 500
|
| 27 |
+
}
|
data/models/ec/prothgt-ec-model.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e6a4f28a81b46c259c9964b9502dbece97a51ca9b6db371fce0e2684ae39272e
|
| 3 |
+
size 44855705
|
run_prothgt_ec_app.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""EC number prediction backend for the ProtHGT Space.
|
| 2 |
+
|
| 3 |
+
Unlike GO term prediction (one flat decoder per sub-ontology), EC prediction uses
|
| 4 |
+
a single joint model with a shared HGT backbone (plus a normalized skip
|
| 5 |
+
connection) and four level-specific decoders, run as a top-down cascade so the
|
| 6 |
+
predicted EC levels form a consistent hierarchy.
|
| 7 |
+
"""
|
| 8 |
+
import os
|
| 9 |
+
import gzip
|
| 10 |
+
import json
|
| 11 |
+
import shutil
|
| 12 |
+
from functools import lru_cache
|
| 13 |
+
|
| 14 |
+
import torch
|
| 15 |
+
from torch.nn import Linear, LayerNorm
|
| 16 |
+
from torch_geometric.nn import HGTConv, MLP
|
| 17 |
+
import pandas as pd
|
| 18 |
+
import yaml
|
| 19 |
+
from huggingface_hub import hf_hub_download
|
| 20 |
+
|
| 21 |
+
from run_prothgt_app import load_name_info
|
| 22 |
+
|
| 23 |
+
EC_MODELS_DIR = os.path.join("data", "models", "ec")
|
| 24 |
+
EC_CONFIG_PATH = os.path.join(EC_MODELS_DIR, "prothgt-ec-config.yaml")
|
| 25 |
+
EC_MODEL_PATH = os.path.join(EC_MODELS_DIR, "prothgt-ec-model.pt")
|
| 26 |
+
EC_KG_PATH = os.path.join("data", "prothgt-ec-kg.pt")
|
| 27 |
+
# EC class/subclass/sub-subclass (L1-L3) names from the ExPASy ENZYME nomenclature;
|
| 28 |
+
# L4 (full EC number) names come from name_info instead.
|
| 29 |
+
EC_CLASS_NAMES_PATH = os.path.join("data", "ec_class_names.json")
|
| 30 |
+
|
| 31 |
+
LEVELS = ['l1', 'l2', 'l3', 'l4']
|
| 32 |
+
LEVEL_TARGET_TYPE = {'l1': 'EC_class_1', 'l2': 'EC_class_2', 'l3': 'EC_class_3', 'l4': 'EC_number'}
|
| 33 |
+
LEVEL_LABEL = {'l1': 'L1', 'l2': 'L2', 'l3': 'L3', 'l4': 'L4'}
|
| 34 |
+
CHILDREN_KEY = {'l2': 'l1_children', 'l3': 'l2_children', 'l4': 'l3_children'}
|
| 35 |
+
|
| 36 |
+
# EC taxonomy edges used to find each node's children for the cascade.
|
| 37 |
+
CHILD_EDGE_TYPES = {
|
| 38 |
+
'l1_children': ('EC_class_1', 'rev_ec_parent_1', 'EC_class_2'),
|
| 39 |
+
'l2_children': ('EC_class_2', 'rev_ec_parent_2', 'EC_class_3'),
|
| 40 |
+
'l3_children': ('EC_class_3', 'rev_ec_parent_3', 'EC_number'),
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
@lru_cache(maxsize=1)
|
| 44 |
+
def load_ec_class_names(path=EC_CLASS_NAMES_PATH):
|
| 45 |
+
"""{EC class prefix (L1-L3) -> name}, e.g. '2.7.11' -> 'Protein-serine/threonine kinases'."""
|
| 46 |
+
with open(path, encoding='utf-8') as f:
|
| 47 |
+
return json.load(f)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# ---------------------------------------------------------------------------
|
| 51 |
+
# Model (ported from the ProtHGT src/ec package)
|
| 52 |
+
# ---------------------------------------------------------------------------
|
| 53 |
+
class ProtHGT(torch.nn.Module):
|
| 54 |
+
"""HGT backbone with a normalized pre/post-GNN skip connection."""
|
| 55 |
+
def __init__(self, data, hidden_channels, num_heads, num_layers, mlp_hidden_layers, mlp_dropout):
|
| 56 |
+
super().__init__()
|
| 57 |
+
self.lin_dict = torch.nn.ModuleDict()
|
| 58 |
+
for node_type in data.node_types:
|
| 59 |
+
self.lin_dict[node_type] = Linear(data[node_type].x.size(1), hidden_channels)
|
| 60 |
+
|
| 61 |
+
self.convs = torch.nn.ModuleList()
|
| 62 |
+
for _ in range(num_layers):
|
| 63 |
+
self.convs.append(HGTConv(hidden_channels, hidden_channels, data.metadata(), num_heads, group='sum'))
|
| 64 |
+
|
| 65 |
+
self.initial_norm = LayerNorm(hidden_channels)
|
| 66 |
+
self.gnn_norm = LayerNorm(hidden_channels)
|
| 67 |
+
self.mlp = MLP(mlp_hidden_layers, dropout=mlp_dropout, norm=None)
|
| 68 |
+
|
| 69 |
+
def generate_embeddings(self, x_dict, edge_index_dict):
|
| 70 |
+
initial_dict = {nt: self.lin_dict[nt](x).relu_() for nt, x in x_dict.items()}
|
| 71 |
+
gnn_dict = initial_dict
|
| 72 |
+
for conv in self.convs:
|
| 73 |
+
out = conv(gnn_dict, edge_index_dict)
|
| 74 |
+
gnn_dict = {nt: (out[nt] if out.get(nt) is not None else prev)
|
| 75 |
+
for nt, prev in gnn_dict.items()}
|
| 76 |
+
return {nt: torch.cat([self.initial_norm(initial_dict[nt]), self.gnn_norm(gnn_dict[nt])], dim=-1)
|
| 77 |
+
for nt in initial_dict}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class ProtHGTHier(torch.nn.Module):
|
| 81 |
+
"""Shared ProtHGT backbone + one MLP decoder per EC level."""
|
| 82 |
+
def __init__(self, data, hidden_channels, num_heads, num_layers, mlp_hidden_layers, mlp_dropout):
|
| 83 |
+
super().__init__()
|
| 84 |
+
self.backbone = ProtHGT(data, hidden_channels, num_heads, num_layers, mlp_hidden_layers, mlp_dropout)
|
| 85 |
+
self.backbone.mlp = torch.nn.Identity()
|
| 86 |
+
self.decoders = torch.nn.ModuleDict({
|
| 87 |
+
level: MLP(mlp_hidden_layers, dropout=mlp_dropout, norm=None) for level in LEVELS
|
| 88 |
+
})
|
| 89 |
+
|
| 90 |
+
def generate_embeddings(self, x_dict, edge_index_dict):
|
| 91 |
+
return self.backbone.generate_embeddings(x_dict, edge_index_dict)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def load_hierarchy_masks(data):
|
| 95 |
+
"""{'l1_children': {ec_class_1_idx: [ec_class_2_idx, ...]}, ...} from the EC taxonomy edges."""
|
| 96 |
+
from collections import defaultdict
|
| 97 |
+
masks = {}
|
| 98 |
+
for name, et in CHILD_EDGE_TYPES.items():
|
| 99 |
+
row, col = data[et].edge_index
|
| 100 |
+
children = defaultdict(list)
|
| 101 |
+
for r, c in zip(row.tolist(), col.tolist()):
|
| 102 |
+
children[r].append(c)
|
| 103 |
+
masks[name] = dict(children)
|
| 104 |
+
return masks
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
# ---------------------------------------------------------------------------
|
| 108 |
+
# Loading
|
| 109 |
+
# ---------------------------------------------------------------------------
|
| 110 |
+
def load_ec_kg(output=EC_KG_PATH):
|
| 111 |
+
"""Download (if needed) and load the EC knowledge graph. Callers should cache the result."""
|
| 112 |
+
if not os.path.exists(output):
|
| 113 |
+
cached_path = hf_hub_download(
|
| 114 |
+
repo_id="HUBioDataLab/ProtHGT",
|
| 115 |
+
filename="knowledge_graphs/ec/prothgt-ec-kg.pt",
|
| 116 |
+
repo_type="dataset",
|
| 117 |
+
)
|
| 118 |
+
os.makedirs(os.path.dirname(output), exist_ok=True)
|
| 119 |
+
shutil.copy(cached_path, output)
|
| 120 |
+
print(f"EC KG downloaded to {output}")
|
| 121 |
+
print('Loading EC knowledge graph...')
|
| 122 |
+
return torch.load(output)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def load_ec_model(heterodata, config_path=EC_CONFIG_PATH, model_path=EC_MODEL_PATH):
|
| 126 |
+
"""Build ProtHGTHier and load its weights. Callers should cache the result."""
|
| 127 |
+
with open(config_path) as f:
|
| 128 |
+
cfg = yaml.safe_load(f)
|
| 129 |
+
h = cfg['hidden_channels']
|
| 130 |
+
model = ProtHGTHier(
|
| 131 |
+
heterodata, hidden_channels=h, num_heads=cfg['num_heads'], num_layers=cfg['num_layers'],
|
| 132 |
+
mlp_hidden_layers=[4 * h, h, 1], mlp_dropout=cfg['mlp_dropout'],
|
| 133 |
+
)
|
| 134 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 135 |
+
model.load_state_dict(torch.load(model_path, map_location=device))
|
| 136 |
+
model.eval()
|
| 137 |
+
print(f'Loaded EC model weights from {model_path}')
|
| 138 |
+
return model
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
# ---------------------------------------------------------------------------
|
| 142 |
+
# Cascade prediction
|
| 143 |
+
# ---------------------------------------------------------------------------
|
| 144 |
+
@torch.no_grad()
|
| 145 |
+
def _cascade_protein(model, x_dict, masks, protein_idx, inv_maps, threshold, device):
|
| 146 |
+
"""Top-down cascade for one protein: L1 over all classes, each deeper level only
|
| 147 |
+
over the children of the kept nodes above. Returns (level_key, ec_string, prob) rows."""
|
| 148 |
+
rows = []
|
| 149 |
+
kept_prev = []
|
| 150 |
+
for level in LEVELS:
|
| 151 |
+
target_type = LEVEL_TARGET_TYPE[level]
|
| 152 |
+
if level == 'l1':
|
| 153 |
+
candidates = list(range(x_dict[target_type].size(0)))
|
| 154 |
+
else:
|
| 155 |
+
ckey = CHILDREN_KEY[level]
|
| 156 |
+
candidates = sorted({c for p in kept_prev for c in masks[ckey].get(p, [])})
|
| 157 |
+
if not candidates:
|
| 158 |
+
break
|
| 159 |
+
|
| 160 |
+
cand = torch.tensor(candidates, dtype=torch.long, device=device)
|
| 161 |
+
p_emb = x_dict['Protein'][protein_idx].unsqueeze(0).expand(len(candidates), -1)
|
| 162 |
+
z = torch.cat([p_emb, x_dict[target_type][cand]], dim=-1)
|
| 163 |
+
probs = torch.sigmoid(model.decoders[level](z).view(-1))
|
| 164 |
+
|
| 165 |
+
keep = (probs > threshold).nonzero(as_tuple=False).view(-1)
|
| 166 |
+
kept_prev = [candidates[i] for i in keep.tolist()]
|
| 167 |
+
for i in keep.tolist():
|
| 168 |
+
rows.append((level, inv_maps[target_type][candidates[i]], float(probs[i])))
|
| 169 |
+
return rows
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def generate_ec_prediction_df(protein_ids, heterodata, model, threshold=0.5, progress_callback=None):
|
| 173 |
+
"""Cascade EC predictions for the given proteins. The backbone embeddings are
|
| 174 |
+
computed once over the whole graph; the decoders then run per protein."""
|
| 175 |
+
if isinstance(protein_ids, str):
|
| 176 |
+
protein_ids = [protein_ids]
|
| 177 |
+
|
| 178 |
+
# The full-graph forward over the whole KG is memory-heavy for this model
|
| 179 |
+
# (hidden=256); fall back to CPU if a GPU runs out of memory.
|
| 180 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 181 |
+
|
| 182 |
+
def _embed(dev):
|
| 183 |
+
model.to(dev)
|
| 184 |
+
hd = heterodata.to(dev)
|
| 185 |
+
with torch.no_grad():
|
| 186 |
+
return hd, model.generate_embeddings(hd.x_dict, hd.edge_index_dict)
|
| 187 |
+
|
| 188 |
+
try:
|
| 189 |
+
heterodata, x_dict = _embed(device)
|
| 190 |
+
except RuntimeError as e:
|
| 191 |
+
if device.type == 'cuda' and 'out of memory' in str(e).lower():
|
| 192 |
+
print('GPU out of memory during the full-graph forward; falling back to CPU...')
|
| 193 |
+
torch.cuda.empty_cache()
|
| 194 |
+
device = torch.device('cpu')
|
| 195 |
+
heterodata, x_dict = _embed(device)
|
| 196 |
+
else:
|
| 197 |
+
raise
|
| 198 |
+
masks = load_hierarchy_masks(heterodata)
|
| 199 |
+
inv_maps = {
|
| 200 |
+
LEVEL_TARGET_TYPE[level]: {idx: tok for tok, idx in heterodata[LEVEL_TARGET_TYPE[level]]['id_mapping'].items()}
|
| 201 |
+
for level in LEVELS
|
| 202 |
+
}
|
| 203 |
+
id_mapping = heterodata['Protein']['id_mapping']
|
| 204 |
+
name_info = load_name_info()
|
| 205 |
+
ec_l4_names = name_info['EC_number'] # full EC number (L4) -> enzyme name
|
| 206 |
+
ec_class_names = load_ec_class_names() # L1-L3 class prefix -> class name
|
| 207 |
+
|
| 208 |
+
rows = []
|
| 209 |
+
for i, pid in enumerate(protein_ids):
|
| 210 |
+
if progress_callback is not None:
|
| 211 |
+
progress_callback(i, len(protein_ids))
|
| 212 |
+
protein_name = name_info['Protein'].get(pid, pid)
|
| 213 |
+
for level, token, prob in _cascade_protein(
|
| 214 |
+
model, x_dict, masks, id_mapping[pid], inv_maps, threshold, device):
|
| 215 |
+
ec_name = ec_l4_names.get(token, '') if level == 'l4' else ec_class_names.get(token, '')
|
| 216 |
+
rows.append({
|
| 217 |
+
'UniProt_ID': pid,
|
| 218 |
+
'Protein': protein_name,
|
| 219 |
+
'EC': token,
|
| 220 |
+
'EC_name': ec_name,
|
| 221 |
+
'EC_level': LEVEL_LABEL[level],
|
| 222 |
+
'Probability': prob,
|
| 223 |
+
})
|
| 224 |
+
|
| 225 |
+
df = pd.DataFrame(rows, columns=['UniProt_ID', 'Protein', 'EC', 'EC_name', 'EC_level', 'Probability'])
|
| 226 |
+
return heterodata, df
|