Skip to content

Commit 7be152f

Browse files
committed
Create a test for the new parameters of the SmithWaterman3Daligner biojava#552
1 parent c5f666f commit 7be152f

5 files changed

Lines changed: 78 additions & 7 deletions

File tree

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/align/AlignmentToolsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,5 @@ public boolean containsKey(Object key) {
443443
return true;
444444
}
445445
}
446+
446447
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.biojava.nbio.structure.test.align.seq;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.io.IOException;
6+
7+
import org.biojava.nbio.structure.Atom;
8+
import org.biojava.nbio.structure.Structure;
9+
import org.biojava.nbio.structure.StructureException;
10+
import org.biojava.nbio.structure.StructureTools;
11+
import org.biojava.nbio.structure.align.model.AFPChain;
12+
import org.biojava.nbio.structure.align.seq.SmithWaterman3DParameters;
13+
import org.biojava.nbio.structure.align.seq.SmithWaterman3Daligner;
14+
import org.junit.Test;
15+
16+
/**
17+
* Test the superposition based on a sequence alignment on different cases.
18+
*
19+
* @author Aleix Lafita
20+
*
21+
*/
22+
public class TestSmithWaterman3Daligner {
23+
24+
/**
25+
* Test the changes in the alignment by the max RMSD parameter. Use the
26+
* chain A and B of hemoglobin, because they have very similar sequences,
27+
* but some columns of the alignment have to be removed for a better
28+
* superposition (lower RMSD).
29+
*/
30+
@Test
31+
public void testMaxRMSD() throws StructureException, IOException {
32+
33+
Structure s1 = StructureTools.getStructure("1A3N.A");
34+
Structure s2 = StructureTools.getStructure("1A3N.B");
35+
36+
Atom[] ca1 = StructureTools.getRepresentativeAtomArray(s1);
37+
Atom[] ca2 = StructureTools.getRepresentativeAtomArray(s2);
38+
39+
SmithWaterman3Daligner aligner = new SmithWaterman3Daligner();
40+
SmithWaterman3DParameters params = new SmithWaterman3DParameters();
41+
42+
// Use no restriction on the RMSD
43+
params.setMaxRmsd(99.0);
44+
45+
AFPChain afpChain = aligner.align(ca1, ca2, params);
46+
47+
assertEquals("RMSD is wrong", 1.39, afpChain.getTotalRmsdOpt(), 0.005);
48+
assertEquals("Length is wrong", 137, afpChain.getOptLength());
49+
50+
// Restrict it to 1A RMSD (18 columns have to be dropped)
51+
params.setMaxRmsd(1.0);
52+
53+
afpChain = aligner.align(ca1, ca2, params);
54+
55+
assertTrue("RMSD is above the threshold", afpChain.getTotalRmsdOpt() < 1.0);
56+
assertEquals("Length is wrong", 119, afpChain.getOptLength());
57+
58+
// Restrict it to 0A RMSD (the minimum length is relevant )
59+
params.setMaxRmsd(0.0);
60+
params.setMinLen(30);
61+
62+
afpChain = aligner.align(ca1, ca2, params);
63+
64+
assertEquals("Length shoild be the minimum possible", 30, afpChain.getOptLength());
65+
66+
}
67+
}

biojava-structure/src/main/java/org/biojava/nbio/structure/StructureTools.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.biojava.nbio.structure.contact.Grid;
4646
import org.biojava.nbio.structure.io.FileParsingParameters;
4747
import org.biojava.nbio.structure.io.PDBFileParser;
48-
import org.biojava.nbio.structure.io.mmcif.model.ChemComp;
4948
import org.biojava.nbio.structure.io.util.FileDownloadUtils;
5049
import org.slf4j.Logger;
5150
import org.slf4j.LoggerFactory;

biojava-structure/src/main/java/org/biojava/nbio/structure/align/seq/SmithWaterman3Daligner.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public class SmithWaterman3Daligner extends AbstractStructureAlignment implement
7171

7272
/**
7373
* version history:
74-
* 1.1 - Added more parameters to the command line, including maximum RMSD
75-
* and minimum length
74+
* 1.1 - Added a maxRMSD and minLen parameters
7675
* 1.0 - Initial version
7776
*/
7877
private static final String version = "1.1";
@@ -147,7 +146,7 @@ public AFPChain align(Atom[] ca1, Atom[] ca2, Object parameters)
147146
afpChain = convert(ca1,ca2,pair, smithWaterman);
148147

149148
// Perform an iterative dropping of the columns
150-
while (afpChain.getAlnLength() > params.getMinLen()
149+
while (afpChain.getOptLength() > params.getMinLen()
151150
&& afpChain.getTotalRmsdOpt() > params.getMaxRmsd()) {
152151
afpChain = AlignmentTools.deleteHighestDistanceColumn(afpChain, ca1, ca2);
153152
}

biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AlignmentTools.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,11 +1425,16 @@ public static AFPChain deleteHighestDistanceColumn(AFPChain afpChain,
14251425

14261426
for (int b = 0; b < optAln.length; b++) {
14271427
for (int p = 0; p < optAln[b][0].length; p++) {
1428+
Atom ca2clone = ca2[optAln[b][1][p]];
1429+
Calc.rotate(ca2clone, afpChain.getBlockRotationMatrix()[b]);
1430+
Calc.shift(ca2clone, afpChain.getBlockShiftVector()[b]);
1431+
14281432
double distance = Calc.getDistance(ca1[optAln[b][0][p]],
1429-
ca2[optAln[b][1][p]]);
1433+
ca2clone);
14301434
if (distance > maxDistance) {
14311435
maxBlock = b;
14321436
maxPos = p;
1437+
maxDistance = distance;
14331438
}
14341439
}
14351440
}
@@ -1479,8 +1484,8 @@ public static AFPChain deleteColumn(AFPChain afpChain, Atom[] ca1,
14791484
if (p == pos)
14801485
continue;
14811486

1482-
newPos0[position] = optAln[block][0][position];
1483-
newPos1[position] = optAln[block][1][position];
1487+
newPos0[position] = optAln[block][0][p];
1488+
newPos1[position] = optAln[block][1][p];
14841489

14851490
position++;
14861491
}

0 commit comments

Comments
 (0)