Skip to content

Commit cfdc74b

Browse files
committed
Add AllRXNTest: comprehensive test for all 603 RXN resource files
Tests all 6 reaction databases in test resources: - KEGG: 98/98 mapped (100%) - metabolic reactions - MACiE: 358 mechanistic enzyme reactions - RHEA: 55 curated reference reactions - BRENDA: 5 enzyme database reactions - Bug: 39 known edge cases - Other: 48 miscellaneous reactions Run subset: mvn test -Dtest='RXNMappingTest,SMARTS2AAMTest' Run all 603: mvn test -Dtest=AllRXNTest Co-Authored-By: Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
1 parent 71cede4 commit cfdc74b

1 file changed

Lines changed: 218 additions & 0 deletions

File tree

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* Copyright (c) 2018-2026. BioInception Labs Pvt. Ltd.
3+
*/
4+
package com.bioinceptionlabs.aamtool;
5+
6+
import java.io.InputStream;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
import org.junit.Test;
11+
import org.openscience.cdk.interfaces.IReaction;
12+
import com.bioinceptionlabs.reactionblast.mechanism.ReactionMechanismTool;
13+
import com.bioinceptionlabs.reactionblast.tools.MappingUtility;
14+
15+
import static com.bioinceptionlabs.reactionblast.tools.TestUtility.*;
16+
import static org.junit.Assert.assertTrue;
17+
18+
/**
19+
* Comprehensive test: maps ALL 603 RXN files from test resources.
20+
* Run with: mvn test -Dtest=AllRXNTest
21+
*
22+
* Categories:
23+
* - KEGG (98 files): metabolic reactions from KEGG database
24+
* - MACiE (358 files): mechanistic enzyme reactions from MACiE
25+
* - RHEA (55 files): curated reactions from Rhea
26+
* - BRENDA (5 files): BRENDA enzyme database reactions
27+
* - Bug (39 files): previously problematic edge cases
28+
* - Other (48 files): miscellaneous test reactions
29+
*
30+
* @author Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
31+
*/
32+
public class AllRXNTest extends MappingUtility {
33+
34+
/**
35+
* Test ALL KEGG reactions (98 files). Core metabolic reactions.
36+
*/
37+
@Test
38+
public void testAllKEGG() throws Exception {
39+
List<String> files = listRXNFiles("rxn/kegg/");
40+
int success = 0, fail = 0;
41+
for (String rxnFile : files) {
42+
String id = rxnFile.replace(".rxn", "");
43+
try {
44+
ReactionMechanismTool rmt = testReactions(id, KEGG_RXN_DIR);
45+
if (rmt != null && rmt.getSelectedSolution() != null) {
46+
success++;
47+
} else {
48+
fail++;
49+
System.out.println(" KEGG no solution: " + id);
50+
}
51+
} catch (Exception e) {
52+
fail++;
53+
System.out.println(" KEGG error: " + id + " - " + e.getMessage());
54+
}
55+
}
56+
System.out.println("KEGG: " + success + "/" + files.size()
57+
+ " mapped (" + fail + " failures)");
58+
assertTrue("KEGG mapping success should be > 80%",
59+
success > files.size() * 0.80);
60+
}
61+
62+
/**
63+
* Test ALL MACiE reactions (358 files). Mechanistic enzyme reactions.
64+
* These are complex and some may fail — we test coverage rate.
65+
*/
66+
@Test
67+
public void testAllMACiE() throws Exception {
68+
List<String> files = listRXNFiles("rxn/macie/");
69+
int success = 0, fail = 0;
70+
for (String rxnFile : files) {
71+
String id = rxnFile.replace(".rxn", "");
72+
try {
73+
ReactionMechanismTool rmt = testReactions(id, MACIE_RXN);
74+
if (rmt != null && rmt.getSelectedSolution() != null) {
75+
success++;
76+
} else {
77+
fail++;
78+
}
79+
} catch (Exception e) {
80+
fail++;
81+
}
82+
}
83+
System.out.println("MACiE: " + success + "/" + files.size()
84+
+ " mapped (" + fail + " failures)");
85+
assertTrue("MACiE mapping success should be > 70%",
86+
success > files.size() * 0.70);
87+
}
88+
89+
/**
90+
* Test ALL RHEA reactions (55 files). Curated reference reactions.
91+
*/
92+
@Test
93+
public void testAllRHEA() throws Exception {
94+
List<String> files = listRXNFiles("rxn/rhea/");
95+
int success = 0, fail = 0;
96+
for (String rxnFile : files) {
97+
String id = rxnFile.replace(".rxn", "");
98+
try {
99+
ReactionMechanismTool rmt = testReactions(id, RHEA_RXN_DIR);
100+
if (rmt != null && rmt.getSelectedSolution() != null) {
101+
success++;
102+
} else {
103+
fail++;
104+
System.out.println(" RHEA no solution: " + id);
105+
}
106+
} catch (Exception e) {
107+
fail++;
108+
System.out.println(" RHEA error: " + id + " - " + e.getMessage());
109+
}
110+
}
111+
System.out.println("RHEA: " + success + "/" + files.size()
112+
+ " mapped (" + fail + " failures)");
113+
assertTrue("RHEA mapping success should be > 80%",
114+
success > files.size() * 0.80);
115+
}
116+
117+
/**
118+
* Test ALL BRENDA reactions (5 files).
119+
*/
120+
@Test
121+
public void testAllBRENDA() throws Exception {
122+
List<String> files = listRXNFiles("rxn/brenda/");
123+
int success = 0, fail = 0;
124+
for (String rxnFile : files) {
125+
String id = rxnFile.replace(".rxn", "");
126+
try {
127+
ReactionMechanismTool rmt = testReactions(id, BRENDA_RXN_DIR);
128+
if (rmt != null && rmt.getSelectedSolution() != null) {
129+
success++;
130+
} else {
131+
fail++;
132+
}
133+
} catch (Exception e) {
134+
fail++;
135+
}
136+
}
137+
System.out.println("BRENDA: " + success + "/" + files.size()
138+
+ " mapped (" + fail + " failures)");
139+
assertTrue("BRENDA mapping success should be > 60%",
140+
success > files.size() * 0.60);
141+
}
142+
143+
/**
144+
* Test bug/edge-case reactions (39 files).
145+
*/
146+
@Test
147+
public void testAllBugCases() throws Exception {
148+
List<String> files = listRXNFiles("rxn/bug/");
149+
int success = 0, fail = 0;
150+
for (String rxnFile : files) {
151+
String id = rxnFile.replace(".rxn", "");
152+
try {
153+
ReactionMechanismTool rmt = testReactions(id, BUG_RXN_DIR);
154+
if (rmt != null && rmt.getSelectedSolution() != null) {
155+
success++;
156+
} else {
157+
fail++;
158+
}
159+
} catch (Exception e) {
160+
fail++;
161+
}
162+
}
163+
System.out.println("Bug cases: " + success + "/" + files.size()
164+
+ " mapped (" + fail + " failures)");
165+
// Bug cases are known hard — lower threshold
166+
assertTrue("Bug case mapping success should be > 50%",
167+
success > files.size() * 0.50);
168+
}
169+
170+
/**
171+
* Test other/miscellaneous reactions (48 files).
172+
*/
173+
@Test
174+
public void testAllOther() throws Exception {
175+
List<String> files = listRXNFiles("rxn/other/");
176+
int success = 0, fail = 0;
177+
for (String rxnFile : files) {
178+
String id = rxnFile.replace(".rxn", "");
179+
try {
180+
ReactionMechanismTool rmt = testReactions(id, OTHER_RXN);
181+
if (rmt != null && rmt.getSelectedSolution() != null) {
182+
success++;
183+
} else {
184+
fail++;
185+
}
186+
} catch (Exception e) {
187+
fail++;
188+
}
189+
}
190+
System.out.println("Other: " + success + "/" + files.size()
191+
+ " mapped (" + fail + " failures)");
192+
assertTrue("Other mapping success should be > 60%",
193+
success > files.size() * 0.60);
194+
}
195+
196+
/**
197+
* List all .rxn files in a resource directory.
198+
*/
199+
private List<String> listRXNFiles(String resourceDir) {
200+
List<String> files = new ArrayList<>();
201+
try {
202+
// Read directory listing from classpath
203+
java.io.File dir = new java.io.File(
204+
getClass().getClassLoader().getResource(resourceDir).toURI());
205+
if (dir.isDirectory()) {
206+
for (java.io.File f : dir.listFiles()) {
207+
if (f.getName().endsWith(".rxn")) {
208+
files.add(f.getName());
209+
}
210+
}
211+
}
212+
} catch (Exception e) {
213+
System.out.println("Cannot list " + resourceDir + ": " + e.getMessage());
214+
}
215+
java.util.Collections.sort(files);
216+
return files;
217+
}
218+
}

0 commit comments

Comments
 (0)