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 jalview.datamodel.Alignment; |
24 |
|
import jalview.datamodel.AlignmentI; |
25 |
|
import jalview.datamodel.ColumnSelection; |
26 |
|
import jalview.datamodel.Sequence; |
27 |
|
import jalview.datamodel.SequenceGroup; |
28 |
|
import jalview.datamodel.SequenceI; |
29 |
|
import jalview.gui.JvOptionPane; |
30 |
|
|
31 |
|
import java.util.Arrays; |
32 |
|
|
33 |
|
import org.testng.AssertJUnit; |
34 |
|
import org.testng.annotations.BeforeClass; |
35 |
|
import org.testng.annotations.Test; |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 4 |
Complexity Density: 0.2 |
|
37 |
|
public class GroupingTest |
38 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
39 |
1 |
@BeforeClass(alwaysRun = true)... |
40 |
|
public void setUpJvOptionPane() |
41 |
|
{ |
42 |
1 |
JvOptionPane.setInteractiveMode(false); |
43 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
44 |
|
} |
45 |
|
|
46 |
|
Sequence s1 = new Sequence("s1", "AAAADDDDEEEE"); |
47 |
|
|
48 |
|
Sequence s2 = new Sequence("s2", "AAAADDDDEEEE"); |
49 |
|
|
50 |
|
Sequence s3 = new Sequence("s3", "ACAADDEDEEEE"); |
51 |
|
|
52 |
|
Sequence s4 = new Sequence("s4", "AAAADDEDEEEE"); |
53 |
|
|
54 |
|
Sequence s5 = new Sequence("s5", "AAAADDEDTTEE"); |
55 |
|
|
56 |
|
SequenceGroup sg_12 = new SequenceGroup( |
57 |
|
Arrays.asList(new SequenceI[] |
58 |
|
{ s1, s2 }), "Group1", null, false, false, false, 0, 5); |
59 |
|
|
60 |
|
SequenceGroup sg_345 = new SequenceGroup( |
61 |
|
Arrays.asList(new SequenceI[] |
62 |
|
{ s3, s4, s5 }), "Group2", null, false, false, false, 0, 5); |
63 |
|
|
64 |
|
AlignmentI alignment = new Alignment( |
65 |
|
new SequenceI[] |
66 |
|
{ s1, s2, s3, s4, s5 }); |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
int[] positions = new int[] { 7, 9, 1 }; |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 3 |
Complexity Density: 0.17 |
1PASS
|
|
74 |
1 |
@Test(groups = { "Functional" })... |
75 |
|
public void testMakeGroupsWithBoth() |
76 |
|
{ |
77 |
1 |
String[] str = new String[alignment.getHeight()]; |
78 |
1 |
int seq = 0; |
79 |
1 |
for (SequenceI s : alignment.getSequences()) |
80 |
|
{ |
81 |
5 |
StringBuilder sb = new StringBuilder(); |
82 |
5 |
for (int p : positions) |
83 |
|
{ |
84 |
15 |
sb.append(s.getCharAt(p)); |
85 |
|
} |
86 |
5 |
str[seq++] = sb.toString(); |
87 |
|
} |
88 |
1 |
SequenceGroup[] seqgroupsString = Grouping.makeGroupsFrom( |
89 |
|
alignment.getSequencesArray(), str, |
90 |
|
Arrays.asList(new SequenceGroup[] |
91 |
|
{ sg_12, sg_345 })); |
92 |
|
|
93 |
1 |
ColumnSelection cs = new ColumnSelection(); |
94 |
1 |
for (int p : positions) |
95 |
|
{ |
96 |
3 |
cs.addElement(p); |
97 |
|
} |
98 |
1 |
SequenceGroup[] seqgroupsColSel = Grouping.makeGroupsFromCols( |
99 |
|
alignment.getSequencesArray(), cs, |
100 |
|
Arrays.asList(new SequenceGroup[] |
101 |
|
{ sg_12, sg_345 })); |
102 |
1 |
AssertJUnit.assertEquals(seqgroupsString.length, |
103 |
|
seqgroupsColSel.length); |
104 |
5 |
for (int p = 0; p < seqgroupsString.length; p++) |
105 |
|
{ |
106 |
4 |
AssertJUnit.assertEquals(seqgroupsString[p].getName(), |
107 |
|
seqgroupsColSel[p].getName()); |
108 |
4 |
AssertJUnit.assertArrayEquals( |
109 |
|
seqgroupsString[p].getSequencesInOrder(alignment), |
110 |
|
seqgroupsColSel[p].getSequencesInOrder(alignment)); |
111 |
4 |
if (seqgroupsString[p].getSequences().contains(s2)) |
112 |
|
{ |
113 |
1 |
AssertJUnit.assertTrue(seqgroupsString[p].getSize() == 2); |
114 |
|
} |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
} |