1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.analysis; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertNull; |
25 |
|
|
26 |
|
import jalview.datamodel.Mapping; |
27 |
|
import jalview.datamodel.Sequence; |
28 |
|
import jalview.datamodel.SequenceI; |
29 |
|
import jalview.gui.JvOptionPane; |
30 |
|
|
31 |
|
import java.io.PrintStream; |
32 |
|
import java.nio.charset.Charset; |
33 |
|
import java.util.Locale; |
34 |
|
|
35 |
|
import org.testng.annotations.BeforeClass; |
36 |
|
import org.testng.annotations.BeforeMethod; |
37 |
|
import org.testng.annotations.Test; |
38 |
|
|
39 |
|
import com.google.common.base.Charsets; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@author |
45 |
|
|
46 |
|
|
|
|
| 96.4% |
Uncovered Elements: 2 (56) |
Complexity: 10 |
Complexity Density: 0.22 |
|
47 |
|
public class TestAlignSeq |
48 |
|
{ |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
50 |
1 |
@BeforeClass(alwaysRun = true)... |
51 |
|
public void setUpJvOptionPane() |
52 |
|
{ |
53 |
1 |
JvOptionPane.setInteractiveMode(false); |
54 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
55 |
|
} |
56 |
|
|
57 |
|
SequenceI s1, s2, s3; |
58 |
|
|
59 |
|
|
60 |
|
@throws |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
62 |
4 |
@BeforeMethod(alwaysRun = true)... |
63 |
|
public void setUp() throws Exception |
64 |
|
{ |
65 |
4 |
s1 = new Sequence("Seq1", "ASDFAQQQRRRSSS"); |
66 |
4 |
s1.setStart(3); |
67 |
4 |
s1.setEnd(18); |
68 |
4 |
s2 = new Sequence("Seq2", "ASDFA"); |
69 |
4 |
s2.setStart(5); |
70 |
4 |
s2.setEnd(9); |
71 |
4 |
s3 = new Sequence("Seq3", "SDFAQQQSSS"); |
72 |
|
|
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
75 |
1 |
@Test(groups = { "Functional" })... |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
public void testGetMappingForS1() |
80 |
|
{ |
81 |
1 |
AlignSeq as = AlignSeq.doGlobalNWAlignment(s1, s2, AlignSeq.PEP); |
82 |
1 |
System.out.println("s1: " + as.getAStr1()); |
83 |
1 |
System.out.println("s2: " + as.getAStr2()); |
84 |
|
|
85 |
|
|
86 |
1 |
assertEquals("ASDFA", as.getAStr1()); |
87 |
1 |
assertEquals(as.getAStr1(), as.getAStr2()); |
88 |
|
|
89 |
1 |
Mapping s1tos2 = as.getMappingFromS1(false); |
90 |
1 |
checkMapping(s1tos2, s1, s2); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
93 |
2 |
public void checkMapping(Mapping s1tos2, SequenceI _s1, SequenceI _s2)... |
94 |
|
{ |
95 |
2 |
System.out.println(s1tos2.getMap().toString()); |
96 |
10 |
for (int i = _s2.getStart(); i < _s2.getEnd(); i++) |
97 |
|
{ |
98 |
8 |
int p = s1tos2.getPosition(i); |
99 |
8 |
char s2c = _s2.getCharAt(i - _s2.getStart()); |
100 |
8 |
char s1c = _s1.getCharAt(p - _s1.getStart()); |
101 |
8 |
System.out.println("Position in s2: " + i + s2c |
102 |
|
+ " maps to position in s1: " + p + s1c); |
103 |
8 |
assertEquals(s1c, s2c); |
104 |
|
} |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
107 |
1 |
@Test(groups = { "Functional" })... |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
public void testGetMappingForS1_withLowerCase() |
112 |
|
{ |
113 |
|
|
114 |
1 |
SequenceI ns2 = new Sequence(s2); |
115 |
1 |
ns2.replace('D', 'd'); |
116 |
1 |
AlignSeq as = AlignSeq.doGlobalNWAlignment(s1, ns2, AlignSeq.PEP); |
117 |
1 |
System.out.println("s1: " + as.getAStr1()); |
118 |
1 |
System.out.println("s2: " + as.getAStr2()); |
119 |
|
|
120 |
|
|
121 |
1 |
assertEquals("ASDFA", as.getAStr1()); |
122 |
1 |
assertEquals(as.getAStr1(), as.getAStr2().toUpperCase(Locale.ROOT)); |
123 |
|
|
124 |
1 |
Mapping s1tos2 = as.getMappingFromS1(false); |
125 |
1 |
assertEquals("ASdFA", as.getAStr2()); |
126 |
|
|
127 |
1 |
checkMapping(s1tos2, s1, s2); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
130 |
1 |
@Test(groups = { "Functional" })... |
131 |
|
public void testExtractGaps() |
132 |
|
{ |
133 |
1 |
assertNull(AlignSeq.extractGaps(null, null)); |
134 |
1 |
assertNull(AlignSeq.extractGaps(". -", null)); |
135 |
1 |
assertNull(AlignSeq.extractGaps(null, "AB-C")); |
136 |
|
|
137 |
1 |
assertEquals("ABCD", AlignSeq.extractGaps(" .-", ". -A-B.C D.")); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
140 |
1 |
@Test(groups = { "Functional" })... |
141 |
|
public void testPrintAlignment() |
142 |
|
{ |
143 |
1 |
AlignSeq as = AlignSeq.doGlobalNWAlignment(s1, s3, AlignSeq.PEP); |
144 |
1 |
final StringBuilder baos = new StringBuilder(); |
145 |
1 |
PrintStream ps = new PrintStream(System.out) |
146 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
1 |
@Override... |
148 |
|
public void print(String x) |
149 |
|
{ |
150 |
1 |
baos.append(x); |
151 |
|
} |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
153 |
0 |
@Override... |
154 |
|
public void println() |
155 |
|
{ |
156 |
0 |
baos.append("\n"); |
157 |
|
} |
158 |
|
}; |
159 |
|
|
160 |
1 |
as.printAlignment(ps); |
161 |
1 |
String expected = "Score = 320.0\nLength of alignment = 10\nSequence Seq1/4-13 (Sequence length = 14)\nSequence Seq3/1-10 (Sequence length = 10)\n\n" |
162 |
|
+ "Seq1/4-13 SDFAQQQRRR\n" + " ||||||| \n" |
163 |
|
+ "Seq3/1-10 SDFAQQQSSS\n\n" + "Percentage ID = 70.00\n\n"; |
164 |
1 |
assertEquals(expected, baos.toString()); |
165 |
|
} |
166 |
|
} |