1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertFalse; |
25 |
|
|
26 |
|
import jalview.gui.JvOptionPane; |
27 |
|
import jalview.util.Comparison; |
28 |
|
|
29 |
|
import org.testng.annotations.BeforeClass; |
30 |
|
import org.testng.annotations.Test; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
|
|
| 97.6% |
Uncovered Elements: 2 (83) |
Complexity: 12 |
Complexity Density: 0.19 |
|
35 |
|
public class SeqCigarTest |
36 |
|
{ |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
38 |
1 |
@BeforeClass(alwaysRun = true)... |
39 |
|
public void setUpJvOptionPane() |
40 |
|
{ |
41 |
1 |
JvOptionPane.setInteractiveMode(false); |
42 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
1PASS
|
|
45 |
1 |
@Test(groups = { "Functional" })... |
46 |
|
public void testFindPosition() |
47 |
|
{ |
48 |
1 |
SequenceI oseq = new Sequence("MySeq", "ASD---ASD---ASD", 37, 45); |
49 |
1 |
oseq.createDatasetSequence(); |
50 |
1 |
SeqCigar cs = new SeqCigar(oseq); |
51 |
1 |
assertEquals(oseq.getSequenceAsString(), cs.getSequenceString('-')); |
52 |
16 |
for (int c = 0, cLen = oseq.getLength(); c < cLen; c++) |
53 |
|
{ |
54 |
15 |
int os_p = oseq.findPosition(c); |
55 |
15 |
int cigar_p = cs.findPosition(c); |
56 |
15 |
if (Comparison.isGap(oseq.getCharAt(c))) |
57 |
|
{ |
58 |
6 |
assertEquals("Expected gap at position " + os_p + " column " + c, |
59 |
|
-1, cigar_p); |
60 |
|
} |
61 |
|
else |
62 |
|
{ |
63 |
9 |
assertEquals("Positions don't match for at column " + c, os_p, |
64 |
|
cigar_p); |
65 |
|
} |
66 |
|
} |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (54) |
Complexity: 5 |
Complexity Density: 0.11 |
1PASS
|
|
74 |
1 |
@Test(groups = { "Functional" })... |
75 |
|
public void testSomething() throws Exception |
76 |
|
{ |
77 |
1 |
String o_seq = "asdfktryasdtqwrtsaslldddptyipqqwaslchvhttt"; |
78 |
1 |
Sequence s = new Sequence("MySeq", o_seq, 39, 80); |
79 |
1 |
String orig_gapped = "----asdf------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhttt"; |
80 |
1 |
Sequence s_gapped = new Sequence("MySeq", orig_gapped, 39, 80); |
81 |
1 |
String ex_cs_gapped = "4I4M6I6M3I11M4I12M4I9M"; |
82 |
1 |
s_gapped.setDatasetSequence(s); |
83 |
1 |
String sub_gapped_s = "------ktryas---dtqwrtsasll----dddptyipqqwa----slchvh"; |
84 |
1 |
Sequence s_subsequence_gapped = new Sequence("MySeq", sub_gapped_s, 43, |
85 |
|
77); |
86 |
1 |
s_subsequence_gapped.setDatasetSequence(s); |
87 |
|
|
88 |
1 |
SeqCigar c_null = new SeqCigar(s); |
89 |
1 |
String cs_null = c_null.getCigarstring(); |
90 |
1 |
assertEquals("Failed to recover ungapped sequence cigar operations", |
91 |
|
"42M", cs_null); |
92 |
1 |
testCigar_string(s_gapped, ex_cs_gapped); |
93 |
1 |
SeqCigar gen_sgapped = SeqCigar.parseCigar(s, ex_cs_gapped); |
94 |
1 |
assertEquals("Failed parseCigar", ex_cs_gapped, |
95 |
|
gen_sgapped.getCigarstring()); |
96 |
|
|
97 |
1 |
testSeqRecovery(gen_sgapped, s_gapped); |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
1 |
SeqCigar sub_gapped = new SeqCigar(s_subsequence_gapped); |
103 |
1 |
testSeqRecovery(sub_gapped, s_subsequence_gapped); |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
1 |
assertEquals("Failed getWidth", sub_gapped_s.length(), |
109 |
|
sub_gapped.getWidth()); |
110 |
|
|
111 |
1 |
sub_gapped.getFullWidth(); |
112 |
1 |
assertFalse("hasDeletedRegions is incorrect", |
113 |
|
sub_gapped.hasDeletedRegions()); |
114 |
|
|
115 |
|
|
116 |
1 |
SeqCigar sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48); |
117 |
1 |
assertEquals( |
118 |
|
"SeqCigar(seq, start, end) not properly clipped alignsequence", |
119 |
|
41, sub_se_gp.getWidth()); |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
1 |
System.out.println("\nOriginal sequence align:\n" + sub_gapped_s |
125 |
|
+ "\nReconstructed window from 8 to 48\n" + "XXXXXXXX" |
126 |
|
+ sub_se_gp.getSequenceString('-') + "..." + "\nCigar String:" |
127 |
|
+ sub_se_gp.getCigarstring() + "\n"); |
128 |
1 |
SequenceI ssgp = sub_se_gp.getSeq('-'); |
129 |
1 |
System.out.println("\t " + ssgp.getSequenceAsString()); |
130 |
11 |
for (int r = 0; r < 10; r++) |
131 |
|
{ |
132 |
10 |
sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48); |
133 |
10 |
int sl = sub_se_gp.getWidth(); |
134 |
10 |
int st = sl - 1 - r; |
135 |
110 |
for (int rs = 0; rs < 10; rs++) |
136 |
|
{ |
137 |
100 |
int e = st + rs; |
138 |
100 |
sub_se_gp.deleteRange(st, e); |
139 |
100 |
String ssgapedseq = sub_se_gp.getSeq('-').getSequenceAsString(); |
140 |
100 |
System.out.println(st + "," + e + "\t:" + ssgapedseq); |
141 |
100 |
st -= 3; |
142 |
|
} |
143 |
|
} |
144 |
|
|
145 |
1 |
SeqCigar[] set = new SeqCigar[] { new SeqCigar(s), |
146 |
|
new SeqCigar(s_subsequence_gapped, 8, 48), new SeqCigar(s_gapped) }; |
147 |
1 |
Alignment al = new Alignment(set); |
148 |
4 |
for (int i = 0; i < al.getHeight(); i++) |
149 |
|
{ |
150 |
3 |
System.out.println("" + al.getSequenceAt(i).getName() + "\t" |
151 |
|
+ al.getSequenceAt(i).getStart() + "\t" |
152 |
|
+ al.getSequenceAt(i).getEnd() + "\t" |
153 |
|
+ al.getSequenceAt(i).getSequenceAsString()); |
154 |
|
} |
155 |
|
|
156 |
1 |
System.out.println("Gapped."); |
157 |
1 |
set = new SeqCigar[] { new SeqCigar(s), |
158 |
|
new SeqCigar(s_subsequence_gapped, 8, 48), new SeqCigar(s_gapped) }; |
159 |
1 |
set[0].deleteRange(20, 25); |
160 |
1 |
al = new Alignment(set); |
161 |
4 |
for (int i = 0; i < al.getHeight(); i++) |
162 |
|
{ |
163 |
3 |
System.out.println("" + al.getSequenceAt(i).getName() + "\t" |
164 |
|
+ al.getSequenceAt(i).getStart() + "\t" |
165 |
|
+ al.getSequenceAt(i).getEnd() + "\t" |
166 |
|
+ al.getSequenceAt(i).getSequenceAsString()); |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
@param |
177 |
|
|
178 |
|
@param |
179 |
|
|
180 |
|
@return |
181 |
|
|
182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
183 |
1 |
protected void testCigar_string(Sequence seq, String ex_cs_gapped)... |
184 |
|
{ |
185 |
1 |
SeqCigar c_sgapped = new SeqCigar(seq); |
186 |
1 |
String cs_gapped = c_sgapped.getCigarstring(); |
187 |
1 |
assertEquals("Failed getCigarstring", ex_cs_gapped, cs_gapped); |
188 |
|
} |
189 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
190 |
2 |
protected void testSeqRecovery(SeqCigar gen_sgapped, SequenceI s_gapped)... |
191 |
|
{ |
192 |
|
|
193 |
2 |
SequenceI gen_sgapped_s = gen_sgapped.getSeq('-'); |
194 |
|
|
195 |
|
|
196 |
2 |
if (!gen_sgapped_s.getSequenceAsString() |
197 |
|
.equals(s_gapped.getSequenceAsString())) |
198 |
|
{ |
199 |
|
|
200 |
|
|
201 |
0 |
System.err.println("Couldn't reconstruct sequence.\n" |
202 |
|
+ gen_sgapped_s.getSequenceAsString() + "\n" |
203 |
|
+ s_gapped.getSequenceAsString()); |
204 |
|
} |
205 |
|
} |
206 |
|
|
207 |
|
} |