Skip to content

Commit 17b44ad

Browse files
committed
Extract magic numbers to constants, add 14 RXN/BRENDA tests
Constants: - GameTheory*: MAX_MAPPING_ITERATIONS = 100 - GraphMatcher: MAX_MCS_THREADS = 8, LARGE_JOB_THRESHOLD = 1000 - FragmentFilter/ChemicalFilters: MAX_FRAGMENT_SCORE = 9999 Tests (14 new, all pass): - KEGG: R00001, R00002, R00004, R00005, R00006, R00009, R00010, R00015, R00024, R00090, R09688, R09907, R10106 - BRENDA: 391.rxn (RXNMappingTest excluded from default surefire — run with -Dtest=) Author: Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
1 parent 2e6ca03 commit 17b44ad

8 files changed

Lines changed: 246 additions & 13 deletions

File tree

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryMax.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
final class GameTheoryMax extends BaseGameTheory {
7575

7676
private final static boolean DEBUG = false;
77+
private static final int MAX_MAPPING_ITERATIONS = 100;
7778
private static final long serialVersionUID = 1887868678797L;
7879
private static final ILoggingTool LOGGER = LoggingToolFactory.createLoggingTool(GameTheoryMax.class);
7980
private final List<String> eductList;
@@ -121,10 +122,9 @@ final class GameTheoryMax extends BaseGameTheory {
121122

122123
private synchronized void GenerateMapping(boolean flag) throws Exception {
123124
boolean ruleMatchingFlag = flag;
124-
int maxIterations = 100;
125125
int iteration = 0;
126126
boolean continueMapping = true;
127-
while (continueMapping && iteration < maxIterations) {
127+
while (continueMapping && iteration < MAX_MAPPING_ITERATIONS) {
128128
this.counter++;
129129

130130
if (DEBUG) {

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryMin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
final class GameTheoryMin extends BaseGameTheory {
7676

7777
private final static boolean DEBUG = false;
78+
private static final int MAX_MAPPING_ITERATIONS = 100;
7879
private static final long serialVersionUID = 1808979786969868698L;
7980
private static final ILoggingTool LOGGER = LoggingToolFactory.createLoggingTool(GameTheoryMin.class);
8081
private final List<String> eductList;
@@ -147,10 +148,9 @@ private synchronized void GenerateIsoMorphismMapping() throws Exception {
147148

148149
private synchronized void GenerateMapping(boolean flag) throws Exception {
149150
boolean ruleMatchingFlag = flag;
150-
int maxIterations = 100;
151151
int iteration = 0;
152152
boolean continueMapping = true;
153-
while (continueMapping && iteration < maxIterations) {
153+
while (continueMapping && iteration < MAX_MAPPING_ITERATIONS) {
154154
this.counter++;
155155
if (DEBUG) {
156156
LOGGER.debug("**********Orignal Matrix**************");

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryMixture.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
final class GameTheoryMixture extends BaseGameTheory {
7373

7474
private final static boolean DEBUG = false;
75+
private static final int MAX_MAPPING_ITERATIONS = 100;
7576
private static final long serialVersionUID = 1808979786969868698L;
7677
private static final ILoggingTool LOGGER = LoggingToolFactory.createLoggingTool(GameTheoryMixture.class);
7778
private final List<String> eductList;
@@ -149,10 +150,9 @@ private synchronized void GenerateIsoMorphismMapping() throws Exception {
149150

150151
private synchronized void GenerateMapping(boolean flag) throws Exception {
151152
boolean ruleMatchingFlag = flag;
152-
int maxIterations = 100;
153153
int iteration = 0;
154154
boolean continueMapping = true;
155-
while (continueMapping && iteration < maxIterations) {
155+
while (continueMapping && iteration < MAX_MAPPING_ITERATIONS) {
156156
if (DEBUG) {
157157
printMatrixAtomContainer(mh, eductList, productList);
158158
LOGGER.debug("**********Orignal Matrix**************");

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryRings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
final class GameTheoryRings extends BaseGameTheory {
7676

7777
private final static boolean DEBUG = false;
78+
private static final int MAX_MAPPING_ITERATIONS = 100;
7879
private static final long serialVersionUID = 0x152ec264bc2L;
7980
private static final ILoggingTool LOGGER
8081
= LoggingToolFactory.createLoggingTool(GameTheoryRings.class);
@@ -159,10 +160,9 @@ private synchronized void GenerateIsoMorphismMapping() throws Exception {
159160
}
160161

161162
private synchronized void GenerateMapping() throws Exception {
162-
int maxIterations = 100;
163163
int iteration = 0;
164164
boolean continueMapping = true;
165-
while (continueMapping && iteration < maxIterations) {
165+
while (continueMapping && iteration < MAX_MAPPING_ITERATIONS) {
166166
LOGGER.debug("GenerateMapping");
167167
if (DEBUG) {
168168
LOGGER.debug("**********Orignal Matrix**************");

src/main/java/com/bioinceptionlabs/reactionblast/mapping/graph/GraphMatcher.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
*/
6262
public class GraphMatcher extends Debugger {
6363

64+
private static final int MAX_MCS_THREADS = 8;
65+
private static final int LARGE_JOB_THRESHOLD = 1000;
6466
private final static ILoggingTool LOGGER
6567
= createLoggingTool(GraphMatcher.class);
6668

@@ -153,8 +155,8 @@ public synchronized static Collection<MCSSolution> matcher(Holder mh) throws Exc
153155
threadsAvailable = jobMap.size();
154156
}
155157

156-
if (threadsAvailable > 8) {
157-
threadsAvailable = 8;
158+
if (threadsAvailable > MAX_MCS_THREADS) {
159+
threadsAvailable = MAX_MCS_THREADS;
158160
}
159161

160162
LOGGER.debug(threadsAvailable + " threads requested for MCS in " + mh.getTheory());
@@ -286,7 +288,7 @@ Ring matcher is set true if both sides have rings else it set to false (IMP for
286288
/*
287289
* Choose unique combination to run
288290
*/
289-
if (listOfJobs.size() > 1000) {
291+
if (listOfJobs.size() > LARGE_JOB_THRESHOLD) {
290292
LOGGER.warn("holy moly...thats alot of molecules to compare...time for a coffee break!");
291293
}
292294
if (!listOfJobs.isEmpty()) {

src/main/java/org/openscience/smsd/filters/ChemicalFilters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void sortResultsByFragments() {
120120
int minFragmentScore = fragmentFilter.sortResults(allFragmentAtomMCS, fragmentScoreMap);
121121

122122
boolean flag = false;
123-
if (minFragmentScore < 9999) {
123+
if (minFragmentScore < FragmentFilter.MAX_FRAGMENT_SCORE) {
124124
flag = true;
125125
clear();
126126
}

src/main/java/org/openscience/smsd/filters/FragmentFilter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
*/
4444
public final class FragmentFilter extends Sotter implements IChemicalFilter<Integer> {
4545

46+
static final int MAX_FRAGMENT_SCORE = 9999;
47+
4648
private final List<Integer> fragmentSize;
4749
private final ChemicalFilters chemfilter;
4850

@@ -56,7 +58,7 @@ public synchronized Integer sortResults(
5658
Map<Integer, AtomAtomMapping> allFragmentAtomMCS,
5759
Map<Integer, Integer> fragmentScoreMap) throws CDKException {
5860

59-
int _minFragmentScore = 9999;
61+
int _minFragmentScore = MAX_FRAGMENT_SCORE;
6062
for (Integer key : allFragmentAtomMCS.keySet()) {
6163
AtomAtomMapping mcsAtom = allFragmentAtomMCS.get(key);
6264
int fragmentCount = getMappedMoleculeFragmentSize(mcsAtom);

src/test/java/com/bioinceptionlabs/aamtool/RXNMappingTest.java

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.bioinceptionlabs.reactionblast.fingerprints.interfaces.IFeature;
4141
import static com.bioinceptionlabs.reactionblast.tools.ReactionSimilarityTool.getSimilarity;
4242
import static com.bioinceptionlabs.reactionblast.tools.TestUtility.BUG_RXN_DIR;
43+
import static com.bioinceptionlabs.reactionblast.tools.TestUtility.BRENDA_RXN_DIR;
4344
import static com.bioinceptionlabs.reactionblast.tools.TestUtility.KEGG_RXN_DIR;
4445

4546
/**
@@ -1906,6 +1907,234 @@ public void Rhea10074() throws Exception {
19061907
// .getFormedCleavedWFingerprint();
19071908
// assertEquals(1, formedCleavedWFingerprint.getFeatureCount());
19081909
// }
1910+
1911+
/**
1912+
* R00001 - Polyphosphate polyphosphohydrolase (fundamental hydrolysis reaction)
1913+
* This reaction may have zero formed/cleaved bonds but should still produce a valid solution.
1914+
*
1915+
* @throws Exception
1916+
*/
1917+
@Test
1918+
public void R00001() throws Exception {
1919+
String reactionID = "R00001";
1920+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
1921+
BondChangeCalculator bcc = testReactions
1922+
.getSelectedSolution()
1923+
.getBondChangeCalculator();
1924+
int totalChanges = bcc.getFormedCleavedWFingerprint().getFeatureCount()
1925+
+ bcc.getOrderChangesWFingerprint().getFeatureCount()
1926+
+ bcc.getStereoChangesWFingerprint().getFeatureCount();
1927+
assertTrue(totalChanges >= 0);
1928+
}
1929+
1930+
/**
1931+
* R00002 - Polyphosphate kinase / ATP diphosphohydrolase
1932+
*
1933+
* @throws Exception
1934+
*/
1935+
@Test
1936+
public void R00002() throws Exception {
1937+
String reactionID = "R00002";
1938+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
1939+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
1940+
.getSelectedSolution()
1941+
.getBondChangeCalculator()
1942+
.getFormedCleavedWFingerprint();
1943+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
1944+
}
1945+
1946+
/**
1947+
* R00004 - Adenylate kinase / ATP-AMP transphosphorylase
1948+
*
1949+
* @throws Exception
1950+
*/
1951+
@Test
1952+
public void R00004() throws Exception {
1953+
String reactionID = "R00004";
1954+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
1955+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
1956+
.getSelectedSolution()
1957+
.getBondChangeCalculator()
1958+
.getFormedCleavedWFingerprint();
1959+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
1960+
}
1961+
1962+
/**
1963+
* R00005 - Nucleoside-diphosphate kinase / ATP-nucleotide transphosphorylase
1964+
*
1965+
* @throws Exception
1966+
*/
1967+
@Test
1968+
public void R00005() throws Exception {
1969+
String reactionID = "R00005";
1970+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
1971+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
1972+
.getSelectedSolution()
1973+
.getBondChangeCalculator()
1974+
.getFormedCleavedWFingerprint();
1975+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
1976+
}
1977+
1978+
/**
1979+
* R00006 - ATP phosphohydrolase
1980+
*
1981+
* @throws Exception
1982+
*/
1983+
@Test
1984+
public void R00006() throws Exception {
1985+
String reactionID = "R00006";
1986+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
1987+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
1988+
.getSelectedSolution()
1989+
.getBondChangeCalculator()
1990+
.getFormedCleavedWFingerprint();
1991+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
1992+
}
1993+
1994+
/**
1995+
* R00009 - ATP pyrophosphohydrolase
1996+
*
1997+
* @throws Exception
1998+
*/
1999+
@Test
2000+
public void R00009() throws Exception {
2001+
String reactionID = "R00009";
2002+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
2003+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2004+
.getSelectedSolution()
2005+
.getBondChangeCalculator()
2006+
.getFormedCleavedWFingerprint();
2007+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2008+
}
2009+
2010+
/**
2011+
* R00010 - ITP pyrophosphohydrolase
2012+
*
2013+
* @throws Exception
2014+
*/
2015+
@Test
2016+
public void R00010() throws Exception {
2017+
String reactionID = "R00010";
2018+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
2019+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2020+
.getSelectedSolution()
2021+
.getBondChangeCalculator()
2022+
.getFormedCleavedWFingerprint();
2023+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2024+
}
2025+
2026+
/**
2027+
* R00015 - ATP adenylyltransferase
2028+
*
2029+
* @throws Exception
2030+
*/
2031+
@Test
2032+
public void R00015() throws Exception {
2033+
String reactionID = "R00015";
2034+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
2035+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2036+
.getSelectedSolution()
2037+
.getBondChangeCalculator()
2038+
.getFormedCleavedWFingerprint();
2039+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2040+
}
2041+
2042+
/**
2043+
* R00024 - GTP cyclohydrolase
2044+
*
2045+
* @throws Exception
2046+
*/
2047+
@Test
2048+
public void R00024() throws Exception {
2049+
String reactionID = "R00024";
2050+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
2051+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2052+
.getSelectedSolution()
2053+
.getBondChangeCalculator()
2054+
.getFormedCleavedWFingerprint();
2055+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2056+
}
2057+
2058+
/**
2059+
* R00090 - Succinate-CoA ligase
2060+
*
2061+
* @throws Exception
2062+
*/
2063+
@Test
2064+
public void R00090() throws Exception {
2065+
String reactionID = "R00090";
2066+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
2067+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2068+
.getSelectedSolution()
2069+
.getBondChangeCalculator()
2070+
.getFormedCleavedWFingerprint();
2071+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2072+
}
2073+
2074+
/**
2075+
* R09688 - KEGG reaction
2076+
*
2077+
* @throws Exception
2078+
*/
2079+
@Test
2080+
public void R09688() throws Exception {
2081+
String reactionID = "R09688";
2082+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
2083+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2084+
.getSelectedSolution()
2085+
.getBondChangeCalculator()
2086+
.getFormedCleavedWFingerprint();
2087+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2088+
}
2089+
2090+
/**
2091+
* R09907 - KEGG reaction
2092+
*
2093+
* @throws Exception
2094+
*/
2095+
@Test
2096+
public void R09907() throws Exception {
2097+
String reactionID = "R09907";
2098+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
2099+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2100+
.getSelectedSolution()
2101+
.getBondChangeCalculator()
2102+
.getFormedCleavedWFingerprint();
2103+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2104+
}
2105+
2106+
/**
2107+
* R10106 - KEGG reaction
2108+
*
2109+
* @throws Exception
2110+
*/
2111+
@Test
2112+
public void R10106() throws Exception {
2113+
String reactionID = "R10106";
2114+
ReactionMechanismTool testReactions = testReactions(reactionID, KEGG_RXN_DIR);
2115+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2116+
.getSelectedSolution()
2117+
.getBondChangeCalculator()
2118+
.getFormedCleavedWFingerprint();
2119+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2120+
}
2121+
2122+
/**
2123+
* BRENDA reaction 391
2124+
*
2125+
* @throws Exception
2126+
*/
2127+
@Test
2128+
public void Brenda391() throws Exception {
2129+
String reactionID = "391";
2130+
ReactionMechanismTool testReactions = testReactions(reactionID, BRENDA_RXN_DIR);
2131+
IPatternFingerprinter formedCleavedWFingerprint = testReactions
2132+
.getSelectedSolution()
2133+
.getBondChangeCalculator()
2134+
.getFormedCleavedWFingerprint();
2135+
assertTrue(formedCleavedWFingerprint.getFeatureCount() > 0);
2136+
}
2137+
19092138
private Set<IFeature> ignoreHydrogenChanges(Collection<IFeature> features) {
19102139
Set<IFeature> selected = new TreeSet<>();
19112140
features.stream().filter((f) -> (!f.getPattern().contains("H"))).forEachOrdered((f) -> {

0 commit comments

Comments
 (0)