1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertTrue; |
24 |
|
import static org.testng.AssertJUnit.assertEquals; |
25 |
|
import static org.testng.AssertJUnit.assertNotNull; |
26 |
|
import static org.testng.AssertJUnit.assertTrue; |
27 |
|
import static org.testng.AssertJUnit.fail; |
28 |
|
|
29 |
|
import java.io.File; |
30 |
|
import java.util.Arrays; |
31 |
|
import java.util.BitSet; |
32 |
|
import java.util.HashMap; |
33 |
|
import java.util.List; |
34 |
|
import java.util.Map; |
35 |
|
import java.util.regex.Matcher; |
36 |
|
import java.util.regex.Pattern; |
37 |
|
|
38 |
|
import org.testng.Assert; |
39 |
|
import org.testng.annotations.BeforeClass; |
40 |
|
import org.testng.annotations.Test; |
41 |
|
|
42 |
|
import jalview.datamodel.Alignment; |
43 |
|
import jalview.datamodel.AlignmentAnnotation; |
44 |
|
import jalview.datamodel.AlignmentI; |
45 |
|
import jalview.datamodel.Annotation; |
46 |
|
import jalview.datamodel.DBRefEntry; |
47 |
|
import jalview.datamodel.Sequence; |
48 |
|
import jalview.datamodel.SequenceFeature; |
49 |
|
import jalview.datamodel.SequenceI; |
50 |
|
import jalview.gui.JvOptionPane; |
51 |
|
import jalview.util.DBRefUtils; |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 364 (364) |
Complexity: 93 |
Complexity Density: 0.37 |
|
53 |
|
public class StockholmFileTest |
54 |
|
{ |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
56 |
0 |
@BeforeClass(alwaysRun = true)... |
57 |
|
public void setUpJvOptionPane() |
58 |
|
{ |
59 |
0 |
JvOptionPane.setInteractiveMode(false); |
60 |
0 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
61 |
|
} |
62 |
|
|
63 |
|
static String PfamFile = "examples/PF00111_seed.stk", |
64 |
|
RfamFile = "examples/RF00031_folded.stk", |
65 |
|
RnaSSTestFile = "examples/rna_ss_test.stk"; |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
4-
|
|
67 |
0 |
@Test(groups = { "Functional" })... |
68 |
|
public void pfamFileIO() throws Exception |
69 |
|
{ |
70 |
0 |
testFileIOwithFormat(new File(PfamFile), FileFormat.Stockholm, -1, 0, |
71 |
|
false, false, false); |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
4-
|
|
74 |
0 |
@Test(groups = { "Functional" })... |
75 |
|
public void pfamFileDataExtraction() throws Exception |
76 |
|
{ |
77 |
0 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
78 |
0 |
AlignmentI al = af.readFile(PfamFile, DataSourceType.FILE, |
79 |
|
new IdentifyFile().identify(PfamFile, DataSourceType.FILE)); |
80 |
0 |
int numpdb = 0; |
81 |
0 |
for (SequenceI sq : al.getSequences()) |
82 |
|
{ |
83 |
0 |
if (sq.getAllPDBEntries() != null) |
84 |
|
{ |
85 |
0 |
numpdb += sq.getAllPDBEntries().size(); |
86 |
|
} |
87 |
|
} |
88 |
0 |
assertTrue( |
89 |
|
"PF00111 seed alignment has at least 1 PDB file, but the reader found none.", |
90 |
|
numpdb > 0); |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
4-
|
|
93 |
0 |
@Test(groups = { "Functional" })... |
94 |
|
public void rfamFileIO() throws Exception |
95 |
|
{ |
96 |
0 |
testFileIOwithFormat(new File(RfamFile), FileFormat.Stockholm, 2, 1, |
97 |
|
false, false, false); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
4-
|
|
104 |
0 |
@Test(groups = { "Functional" })... |
105 |
|
public void dbrefOutput() throws Exception |
106 |
|
{ |
107 |
|
|
108 |
|
|
109 |
0 |
SequenceI sq = new Sequence("FER2_SPIOL", "AASSDDDFFF"); |
110 |
0 |
sq.addDBRef(new DBRefEntry("UNIPROT", "1", "P00224")); |
111 |
0 |
sq.addDBRef(new DBRefEntry("PFAM", "1", "P00224.1")); |
112 |
0 |
sq.addDBRef(new DBRefEntry("PFAM", "1", "PF00111")); |
113 |
0 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
114 |
0 |
String toStockholm = af.formatSequences(FileFormat.Stockholm, |
115 |
|
new Alignment(new SequenceI[] |
116 |
|
{ sq }), false); |
117 |
0 |
System.out.println(toStockholm); |
118 |
|
|
119 |
0 |
assertTrue( |
120 |
|
Pattern.compile( |
121 |
|
"^#=GS\\s+FER2_SPIOL(/\\d+-\\d+)?\\s+AC\\s+P00224$", |
122 |
|
Pattern.MULTILINE).matcher(toStockholm).find(), |
123 |
|
"Couldn't locate UNIPROT Accession in generated Stockholm file."); |
124 |
0 |
AlignmentI fromStockholm = af.readFile(toStockholm, |
125 |
|
DataSourceType.PASTE, FileFormat.Stockholm); |
126 |
0 |
SequenceI importedSeq = fromStockholm.getSequenceAt(0); |
127 |
0 |
assertTrue(importedSeq.getDBRefs().size() == 1, |
128 |
|
"Expected just one database reference to be added to sequence."); |
129 |
0 |
assertTrue( |
130 |
|
importedSeq.getDBRefs().get(0).getAccessionId() |
131 |
|
.indexOf(" ") == -1, |
132 |
|
"Spaces were found in accession ID."); |
133 |
0 |
List<DBRefEntry> dbrefs = DBRefUtils.searchRefs(importedSeq.getDBRefs(), |
134 |
|
"P00224"); |
135 |
0 |
assertTrue(dbrefs.size() == 1, |
136 |
|
"Couldn't find Uniprot DBRef on re-imported sequence."); |
137 |
|
|
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
4-
|
|
140 |
0 |
@Test(groups = { "Functional" })... |
141 |
|
public void descriptionLineOutput() throws Exception |
142 |
|
{ |
143 |
|
|
144 |
|
|
145 |
0 |
SequenceI sq = new Sequence("FER2_SPIOL", "AASSDDDFFF"); |
146 |
0 |
String expected_descr = "This is a description !@&^%@£@"; |
147 |
0 |
sq.setDescription(expected_descr); |
148 |
0 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
149 |
0 |
String toStockholm = af.formatSequences(FileFormat.Stockholm, |
150 |
|
new Alignment(new SequenceI[] |
151 |
|
{ sq }), false); |
152 |
0 |
System.out.println(toStockholm); |
153 |
|
|
154 |
|
|
155 |
0 |
assertTrue(toStockholm.contains(expected_descr), |
156 |
|
"Couldn't locate expected description srting in generated Stockholm file."); |
157 |
|
|
158 |
0 |
AlignmentI fromStockholm = af.readFile(toStockholm, |
159 |
|
DataSourceType.PASTE, FileFormat.Stockholm); |
160 |
0 |
SequenceI importedSeq = fromStockholm.getSequenceAt(0); |
161 |
0 |
assertEquals("Description did not get reimported.", expected_descr, |
162 |
|
importedSeq.getDescription()); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
@param |
170 |
|
|
171 |
|
@param |
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
@param |
176 |
|
@param |
177 |
|
|
178 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 5 |
Complexity Density: 0.19 |
|
179 |
0 |
public static void testFileIOwithFormat(File f, FileFormatI ioformat,... |
180 |
|
int naliannot, int nminseqann, boolean ignoreFeatures, |
181 |
|
boolean ignoreRowVisibility, boolean allowNullAnnotations) |
182 |
|
{ |
183 |
0 |
System.out.println("Reading file: " + f); |
184 |
0 |
String ff = f.getPath(); |
185 |
0 |
try |
186 |
|
{ |
187 |
0 |
AppletFormatAdapter rf = new AppletFormatAdapter(); |
188 |
|
|
189 |
0 |
AlignmentI al = rf.readFile(ff, DataSourceType.FILE, |
190 |
|
new IdentifyFile().identify(ff, DataSourceType.FILE)); |
191 |
|
|
192 |
0 |
assertNotNull("Couldn't read supplied alignment data.", al); |
193 |
|
|
194 |
|
|
195 |
0 |
for (int i = 0; i < al.getSequencesArray().length; ++i) |
196 |
|
{ |
197 |
0 |
al.getSequenceAt(i).createDatasetSequence(); |
198 |
|
} |
199 |
0 |
String outputfile = rf.formatSequences(ioformat, al, true); |
200 |
0 |
System.out.println("Output file in '" + ioformat + "':\n" + outputfile |
201 |
|
+ "\n<<EOF\n"); |
202 |
|
|
203 |
0 |
AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile, |
204 |
|
DataSourceType.PASTE, ioformat); |
205 |
0 |
assertNotNull("Couldn't parse reimported alignment data.", al_input); |
206 |
|
|
207 |
0 |
FileFormatI identifyoutput = new IdentifyFile().identify(outputfile, |
208 |
|
DataSourceType.PASTE); |
209 |
0 |
assertNotNull("Identify routine failed for outputformat " + ioformat, |
210 |
|
identifyoutput); |
211 |
0 |
assertTrue( |
212 |
|
"Identify routine could not recognise output generated by '" |
213 |
|
+ ioformat + "' writer", |
214 |
|
ioformat.equals(identifyoutput)); |
215 |
0 |
testAlignmentEquivalence(al, al_input, ignoreFeatures, |
216 |
|
ignoreRowVisibility, allowNullAnnotations); |
217 |
0 |
int numaliannot = 0, numsqswithali = 0; |
218 |
0 |
for (AlignmentAnnotation ala : al_input.getAlignmentAnnotation()) |
219 |
|
{ |
220 |
0 |
if (ala.sequenceRef == null) |
221 |
|
{ |
222 |
0 |
numaliannot++; |
223 |
|
} |
224 |
|
else |
225 |
|
{ |
226 |
0 |
numsqswithali++; |
227 |
|
} |
228 |
|
} |
229 |
0 |
if (naliannot > -1) |
230 |
|
{ |
231 |
0 |
assertEquals("Number of alignment annotations", naliannot, |
232 |
|
numaliannot); |
233 |
|
} |
234 |
|
|
235 |
0 |
assertTrue( |
236 |
|
"Number of sequence associated annotations wasn't at least " |
237 |
|
+ nminseqann, |
238 |
|
numsqswithali >= nminseqann); |
239 |
|
|
240 |
|
} catch (Exception e) |
241 |
|
{ |
242 |
0 |
e.printStackTrace(); |
243 |
0 |
assertTrue("Couln't format the alignment for output file.", false); |
244 |
|
} |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
@param |
251 |
|
|
252 |
|
@param |
253 |
|
|
254 |
|
|
255 |
|
@param |
256 |
|
|
257 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
258 |
0 |
public static void testAlignmentEquivalence(AlignmentI al,... |
259 |
|
AlignmentI al_input, boolean ignoreFeatures) |
260 |
|
{ |
261 |
0 |
testAlignmentEquivalence(al, al_input, ignoreFeatures, false, false); |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
@param |
269 |
|
|
270 |
|
@param |
271 |
|
|
272 |
|
|
273 |
|
@param |
274 |
|
|
275 |
|
|
276 |
|
@param |
277 |
|
|
278 |
|
|
279 |
|
@param |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
|
|
| 0% |
Uncovered Elements: 114 (114) |
Complexity: 31 |
Complexity Density: 0.44 |
|
285 |
0 |
public static void testAlignmentEquivalence(AlignmentI al,... |
286 |
|
AlignmentI al_input, boolean ignoreFeatures, |
287 |
|
boolean ignoreRowVisibility, boolean allowNullAnnotation) |
288 |
|
{ |
289 |
0 |
assertNotNull("Original alignment was null", al); |
290 |
0 |
assertNotNull("Generated alignment was null", al_input); |
291 |
|
|
292 |
0 |
assertTrue( |
293 |
|
"Alignment dimension mismatch: original: " + al.getHeight() |
294 |
|
+ "x" + al.getWidth() + ", generated: " |
295 |
|
+ al_input.getHeight() + "x" + al_input.getWidth(), |
296 |
|
al.getHeight() == al_input.getHeight() |
297 |
|
&& al.getWidth() == al_input.getWidth()); |
298 |
|
|
299 |
|
|
300 |
0 |
AlignmentAnnotation[] aa_new = al_input.getAlignmentAnnotation(); |
301 |
0 |
AlignmentAnnotation[] aa_original = al.getAlignmentAnnotation(); |
302 |
0 |
boolean expectProteinSS = !al.isNucleotide(); |
303 |
0 |
assertTrue( |
304 |
|
"Alignments not both " |
305 |
0 |
+ (al.isNucleotide() ? "nucleotide" : "protein"), |
306 |
|
al_input.isNucleotide() == al.isNucleotide()); |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
0 |
int aa_new_size = (aa_new == null ? 0 : aa_new.length); |
312 |
0 |
int aa_original_size = (aa_original == null ? 0 : aa_original.length); |
313 |
0 |
Map<Integer, BitSet> orig_groups = new HashMap<>(); |
314 |
0 |
Map<Integer, BitSet> new_groups = new HashMap<>(); |
315 |
|
|
316 |
0 |
if (aa_new != null && aa_original != null) |
317 |
|
{ |
318 |
0 |
for (int i = 0; i < aa_original.length; i++) |
319 |
|
{ |
320 |
0 |
if (aa_new.length > i) |
321 |
|
{ |
322 |
0 |
assertEqualSecondaryStructure( |
323 |
|
"Different alignment annotation at position " + i, |
324 |
|
aa_original[i], aa_new[i], allowNullAnnotation); |
325 |
0 |
if (aa_original[i].hasIcons) |
326 |
|
{ |
327 |
0 |
assertTrue( |
328 |
|
"Secondary structure expected to be " |
329 |
0 |
+ (expectProteinSS ? "protein" : "nucleotide"), |
330 |
|
expectProteinSS == !aa_original[i].isRNA()); |
331 |
|
} |
332 |
|
|
333 |
0 |
assertEquals("Graph type not identical.", aa_original[i].graph, |
334 |
|
aa_new[i].graph); |
335 |
0 |
if (!ignoreRowVisibility) |
336 |
|
{ |
337 |
0 |
assertEquals("Visibility not identical.", |
338 |
|
aa_original[i].visible, aa_new[i].visible); |
339 |
|
} |
340 |
0 |
assertEquals("Threshold line not identical.", |
341 |
|
aa_original[i].threshold, aa_new[i].threshold); |
342 |
|
|
343 |
0 |
Integer o_ggrp = Integer.valueOf(aa_original[i].graphGroup + 2); |
344 |
0 |
Integer n_ggrp = Integer.valueOf(aa_new[i].graphGroup + 2); |
345 |
0 |
BitSet orig_g = orig_groups.get(o_ggrp); |
346 |
0 |
BitSet new_g = new_groups.get(n_ggrp); |
347 |
0 |
if (orig_g == null) |
348 |
|
{ |
349 |
0 |
orig_groups.put(o_ggrp, orig_g = new BitSet()); |
350 |
|
} |
351 |
0 |
if (new_g == null) |
352 |
|
{ |
353 |
0 |
new_groups.put(n_ggrp, new_g = new BitSet()); |
354 |
|
} |
355 |
0 |
assertEquals("Graph Group pattern differs at annotation " + i, |
356 |
|
orig_g, new_g); |
357 |
0 |
orig_g.set(i); |
358 |
0 |
new_g.set(i); |
359 |
|
} |
360 |
|
else |
361 |
|
{ |
362 |
0 |
System.err.println("No matching annotation row for " |
363 |
|
+ aa_original[i].toString()); |
364 |
|
} |
365 |
|
} |
366 |
|
} |
367 |
0 |
assertEquals( |
368 |
|
"Generated and imported alignment have different annotation sets", |
369 |
|
aa_original_size, aa_new_size); |
370 |
|
|
371 |
|
|
372 |
0 |
SequenceI[] seq_original = new SequenceI[al.getSequencesArray().length]; |
373 |
0 |
seq_original = al.getSequencesArray(); |
374 |
0 |
SequenceI[] seq_new = new SequenceI[al_input |
375 |
|
.getSequencesArray().length]; |
376 |
0 |
seq_new = al_input.getSequencesArray(); |
377 |
0 |
List<SequenceFeature> sequenceFeatures_original; |
378 |
0 |
List<SequenceFeature> sequenceFeatures_new; |
379 |
0 |
AlignmentAnnotation annot_original, annot_new; |
380 |
|
|
381 |
0 |
for (int i = 0; i < al.getSequencesArray().length; i++) |
382 |
|
{ |
383 |
0 |
String name = seq_original[i].getName(); |
384 |
0 |
int start = seq_original[i].getStart(); |
385 |
0 |
int end = seq_original[i].getEnd(); |
386 |
0 |
System.out |
387 |
|
.println("Check sequence: " + name + "/" + start + "-" + end); |
388 |
|
|
389 |
|
|
390 |
0 |
for (int in = 0; in < al_input.getSequencesArray().length; in++) |
391 |
|
{ |
392 |
0 |
if (name.equals(seq_new[in].getName()) |
393 |
|
&& start == seq_new[in].getStart() |
394 |
|
&& end == seq_new[in].getEnd()) |
395 |
|
{ |
396 |
0 |
String ss_original = seq_original[i].getSequenceAsString(); |
397 |
0 |
String ss_new = seq_new[in].getSequenceAsString(); |
398 |
0 |
assertEquals("The sequences " + name + "/" + start + "-" + end |
399 |
|
+ " are not equal", ss_original, ss_new); |
400 |
|
|
401 |
0 |
assertTrue( |
402 |
|
"Sequence Features were not equivalent" |
403 |
0 |
+ (ignoreFeatures ? " ignoring." : ""), |
404 |
|
ignoreFeatures |
405 |
|
|| (seq_original[i].getSequenceFeatures() == null |
406 |
|
&& seq_new[in] |
407 |
|
.getSequenceFeatures() == null) |
408 |
|
|| (seq_original[i].getSequenceFeatures() != null |
409 |
|
&& seq_new[in] |
410 |
|
.getSequenceFeatures() != null)); |
411 |
|
|
412 |
0 |
if (seq_original[i].getSequenceFeatures() != null |
413 |
|
&& seq_new[in].getSequenceFeatures() != null) |
414 |
|
{ |
415 |
0 |
System.out.println("There are feature!!!"); |
416 |
0 |
sequenceFeatures_original = seq_original[i] |
417 |
|
.getSequenceFeatures(); |
418 |
0 |
sequenceFeatures_new = seq_new[in].getSequenceFeatures(); |
419 |
|
|
420 |
0 |
assertEquals("different number of features", |
421 |
|
seq_original[i].getSequenceFeatures().size(), |
422 |
|
seq_new[in].getSequenceFeatures().size()); |
423 |
|
|
424 |
0 |
for (int feat = 0; feat < seq_original[i].getSequenceFeatures() |
425 |
|
.size(); feat++) |
426 |
|
{ |
427 |
0 |
assertEquals("Different features", |
428 |
|
sequenceFeatures_original.get(feat), |
429 |
|
sequenceFeatures_new.get(feat)); |
430 |
|
} |
431 |
|
} |
432 |
|
|
433 |
0 |
if (al.getSequenceAt(i).getAnnotation() != null |
434 |
|
&& al_input.getSequenceAt(in).getAnnotation() != null) |
435 |
|
{ |
436 |
0 |
for (int j = 0; j < al.getSequenceAt(i) |
437 |
|
.getAnnotation().length; j++) |
438 |
|
{ |
439 |
0 |
if (al.getSequenceAt(i).getAnnotation()[j] != null && al_input |
440 |
|
.getSequenceAt(in).getAnnotation()[j] != null) |
441 |
|
{ |
442 |
0 |
annot_original = al.getSequenceAt(i).getAnnotation()[j]; |
443 |
0 |
annot_new = al_input.getSequenceAt(in).getAnnotation()[j]; |
444 |
0 |
assertEqualSecondaryStructure( |
445 |
|
"Different annotation elements", annot_original, |
446 |
|
annot_new, allowNullAnnotation); |
447 |
|
} |
448 |
|
} |
449 |
|
} |
450 |
0 |
else if (al.getSequenceAt(i).getAnnotation() == null |
451 |
|
&& al_input.getSequenceAt(in).getAnnotation() == null) |
452 |
|
{ |
453 |
0 |
System.out.println("No annotations"); |
454 |
|
} |
455 |
0 |
else if (al.getSequenceAt(i).getAnnotation() != null |
456 |
|
&& al_input.getSequenceAt(in).getAnnotation() == null) |
457 |
|
{ |
458 |
0 |
fail("Annotations differed between sequences (" |
459 |
|
+ al.getSequenceAt(i).getName() + ") and (" |
460 |
|
+ al_input.getSequenceAt(i).getName() + ")"); |
461 |
|
} |
462 |
0 |
break; |
463 |
|
} |
464 |
|
} |
465 |
|
} |
466 |
|
} |
467 |
|
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
@param |
475 |
|
|
476 |
|
@param |
477 |
|
|
478 |
|
@param |
479 |
|
|
480 |
|
@param |
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
|
|
|
| 0% |
Uncovered Elements: 46 (46) |
Complexity: 31 |
Complexity Density: 1.55 |
|
485 |
0 |
private static void assertEqualSecondaryStructure(String message,... |
486 |
|
AlignmentAnnotation annot_or, AlignmentAnnotation annot_new, |
487 |
|
boolean allowNullEqivalence) |
488 |
|
{ |
489 |
|
|
490 |
|
|
491 |
0 |
if (annot_or.annotations.length != annot_new.annotations.length) |
492 |
|
{ |
493 |
0 |
fail("Different lengths for annotation row elements: " |
494 |
|
+ annot_or.annotations.length + "!=" |
495 |
|
+ annot_new.annotations.length); |
496 |
|
} |
497 |
0 |
boolean isRna = annot_or.isRNA(); |
498 |
0 |
assertTrue( |
499 |
0 |
"Expected " + (isRna ? " valid RNA " : " no RNA ") |
500 |
|
+ " secondary structure in the row.", |
501 |
|
isRna == annot_new.isRNA()); |
502 |
0 |
for (int i = 0; i < annot_or.annotations.length; i++) |
503 |
|
{ |
504 |
0 |
Annotation an_or = annot_or.annotations[i], |
505 |
|
an_new = annot_new.annotations[i]; |
506 |
0 |
if (an_or != null && an_new != null) |
507 |
|
{ |
508 |
|
|
509 |
0 |
if (isRna) |
510 |
|
{ |
511 |
0 |
if (an_or.secondaryStructure != an_new.secondaryStructure |
512 |
|
|| ((Float.isNaN(an_or.value) != Float |
513 |
|
.isNaN(an_new.value)) |
514 |
|
|| an_or.value != an_new.value)) |
515 |
|
{ |
516 |
0 |
fail("Different RNA secondary structure at column " + i |
517 |
|
+ " expected: [" + annot_or.annotations[i].toString() |
518 |
|
+ "] but got: [" + annot_new.annotations[i].toString() |
519 |
|
+ "]"); |
520 |
|
} |
521 |
|
} |
522 |
|
else |
523 |
|
{ |
524 |
|
|
525 |
0 |
if ((an_or.isWhitespace() != an_new.isWhitespace()) |
526 |
|
|| !an_or.displayCharacter.trim() |
527 |
|
.equals(an_new.displayCharacter.trim()) |
528 |
|
|| !("" + an_or.secondaryStructure).trim() |
529 |
|
.equals(("" + an_new.secondaryStructure).trim()) |
530 |
|
|| (an_or.description != an_new.description |
531 |
|
&& !((an_or.description == null |
532 |
|
&& an_new.description.trim() |
533 |
|
.length() == 0) |
534 |
|
|| (an_new.description == null |
535 |
|
&& an_or.description.trim() |
536 |
|
.length() == 0) |
537 |
|
|| an_or.description.trim().equals( |
538 |
|
an_new.description.trim()))) |
539 |
|
|| !((Float.isNaN(an_or.value) |
540 |
|
&& Float.isNaN(an_new.value)) |
541 |
|
|| an_or.value == an_new.value)) |
542 |
|
{ |
543 |
0 |
fail("Annotation Element Mismatch\nElement " + i |
544 |
|
+ " in original: " + annot_or.annotations[i].toString() |
545 |
|
+ "\nElement " + i + " in new: " |
546 |
|
+ annot_new.annotations[i].toString()); |
547 |
|
} |
548 |
|
} |
549 |
|
} |
550 |
0 |
else if (annot_or.annotations[i] == null |
551 |
|
&& annot_new.annotations[i] == null) |
552 |
|
{ |
553 |
0 |
continue; |
554 |
|
} |
555 |
|
else |
556 |
|
{ |
557 |
0 |
if (allowNullEqivalence) |
558 |
|
{ |
559 |
0 |
if (an_or != null && an_or.isWhitespace()) |
560 |
|
|
561 |
|
{ |
562 |
0 |
continue; |
563 |
|
} |
564 |
0 |
if (an_new != null && an_new.isWhitespace()) |
565 |
|
{ |
566 |
0 |
continue; |
567 |
|
} |
568 |
|
} |
569 |
|
|
570 |
0 |
fail("Annotation Element Mismatch\nElement " + i + " in original: " |
571 |
0 |
+ (an_or == null ? "is null" : an_or.toString()) |
572 |
|
+ "\nElement " + i + " in new: " |
573 |
0 |
+ (an_new == null ? "is null" : an_new.toString())); |
574 |
|
} |
575 |
|
} |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
|
@see |
580 |
|
|
581 |
|
@param |
582 |
|
@param |
583 |
|
@param |
584 |
|
@param |
585 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
586 |
0 |
public static void assertNotEqualSecondaryStructure(String message,... |
587 |
|
AlignmentAnnotation an_orig, AlignmentAnnotation an_new, |
588 |
|
boolean allowNullEquivalence) |
589 |
|
{ |
590 |
0 |
boolean thrown = false; |
591 |
0 |
try |
592 |
|
{ |
593 |
0 |
assertEqualSecondaryStructure("", an_orig, an_new, |
594 |
|
allowNullEquivalence); |
595 |
|
} catch (AssertionError af) |
596 |
|
{ |
597 |
0 |
thrown = true; |
598 |
|
} |
599 |
0 |
if (!thrown) |
600 |
|
{ |
601 |
0 |
fail("Expected difference for [" + an_orig + "] and [" + an_new |
602 |
|
+ "]"); |
603 |
|
} |
604 |
|
} |
605 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
606 |
0 |
private AlignmentAnnotation makeAnnot(Annotation ae)... |
607 |
|
{ |
608 |
0 |
return new AlignmentAnnotation("label", "description", |
609 |
|
new Annotation[] |
610 |
|
{ ae }); |
611 |
|
} |
612 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 4 |
Complexity Density: 0.14 |
4-
|
|
613 |
0 |
@Test(groups = { "Functional" })... |
614 |
|
public void testAnnotationEquivalence() |
615 |
|
{ |
616 |
0 |
AlignmentAnnotation one = makeAnnot(new Annotation("", "", ' ', 1)); |
617 |
0 |
AlignmentAnnotation anotherOne = makeAnnot( |
618 |
|
new Annotation("", "", ' ', 1)); |
619 |
0 |
AlignmentAnnotation sheet = makeAnnot(new Annotation("", "", 'E', 0f)); |
620 |
0 |
AlignmentAnnotation anotherSheet = makeAnnot( |
621 |
|
new Annotation("", "", 'E', 0f)); |
622 |
0 |
AlignmentAnnotation sheetWithLabel = makeAnnot( |
623 |
|
new Annotation("1", "", 'E', 0f)); |
624 |
0 |
AlignmentAnnotation anotherSheetWithLabel = makeAnnot( |
625 |
|
new Annotation("1", "", 'E', 0f)); |
626 |
0 |
AlignmentAnnotation rnaNoDC = makeAnnot( |
627 |
|
new Annotation("", "", '<', 0f)); |
628 |
0 |
AlignmentAnnotation anotherRnaNoDC = makeAnnot( |
629 |
|
new Annotation("", "", '<', 0f)); |
630 |
0 |
AlignmentAnnotation rnaWithDC = makeAnnot( |
631 |
|
new Annotation("B", "", '<', 0f)); |
632 |
0 |
AlignmentAnnotation anotherRnaWithDC = makeAnnot( |
633 |
|
new Annotation("B", "", '<', 0f)); |
634 |
|
|
635 |
|
|
636 |
0 |
for (boolean allowNull : new boolean[] { true, false }) |
637 |
|
{ |
638 |
0 |
assertEqualSecondaryStructure("Should be equal", one, anotherOne, |
639 |
|
allowNull); |
640 |
0 |
assertEqualSecondaryStructure("Should be equal", sheet, anotherSheet, |
641 |
|
allowNull); |
642 |
0 |
assertEqualSecondaryStructure("Should be equal", sheetWithLabel, |
643 |
|
anotherSheetWithLabel, allowNull); |
644 |
0 |
assertEqualSecondaryStructure("Should be equal", rnaNoDC, |
645 |
|
anotherRnaNoDC, allowNull); |
646 |
0 |
assertEqualSecondaryStructure("Should be equal", rnaWithDC, |
647 |
|
anotherRnaWithDC, allowNull); |
648 |
|
|
649 |
0 |
assertEqualSecondaryStructure("Should be equal", rnaWithDC, rnaNoDC, |
650 |
|
allowNull); |
651 |
0 |
assertEqualSecondaryStructure("Should be equal", rnaNoDC, rnaWithDC, |
652 |
|
allowNull); |
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
0 |
List<AlignmentAnnotation> aaSet = Arrays.asList(one, sheet, |
657 |
|
sheetWithLabel, rnaWithDC); |
658 |
0 |
for (int p = 0; p < aaSet.size(); p++) |
659 |
|
{ |
660 |
0 |
for (int q = 0; q < aaSet.size(); q++) |
661 |
|
{ |
662 |
0 |
if (p != q) |
663 |
|
{ |
664 |
0 |
assertNotEqualSecondaryStructure("Should be different", |
665 |
|
aaSet.get(p), aaSet.get(q), false); |
666 |
|
} |
667 |
|
else |
668 |
|
{ |
669 |
0 |
assertEqualSecondaryStructure("Should be same", aaSet.get(p), |
670 |
|
aaSet.get(q), false); |
671 |
0 |
assertEqualSecondaryStructure("Should be same", aaSet.get(p), |
672 |
|
aaSet.get(q), true); |
673 |
0 |
assertNotEqualSecondaryStructure( |
674 |
|
"Should be different to empty anot", aaSet.get(p), |
675 |
|
makeAnnot(Annotation.EMPTY_ANNOTATION), false); |
676 |
0 |
assertNotEqualSecondaryStructure( |
677 |
|
"Should be different to empty annot", |
678 |
|
makeAnnot(Annotation.EMPTY_ANNOTATION), aaSet.get(q), |
679 |
|
true); |
680 |
0 |
assertNotEqualSecondaryStructure("Should be different to null", |
681 |
|
aaSet.get(p), makeAnnot(null), false); |
682 |
0 |
assertNotEqualSecondaryStructure("Should be different to null", |
683 |
|
makeAnnot(null), aaSet.get(q), true); |
684 |
|
} |
685 |
|
} |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
} |
691 |
|
|
692 |
|
String aliFile = ">Dm\nAAACCCUUUUACACACGGGAAAGGG"; |
693 |
|
|
694 |
|
String annFile = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
695 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
696 |
|
+ "(|(|(|(|, .|, .|, .|, .|)|)|)|)|\t0.0\nROWPROPERTIES\t" |
697 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
698 |
|
|
699 |
|
String annFileCurlyWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
700 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
701 |
|
+ "(|(|(|(||{|{||{|{||)|)|)|)||}|}|}|}|\t0.0\nROWPROPERTIES\t" |
702 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
703 |
|
|
704 |
|
String annFileFullWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
705 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
706 |
|
+ "(|(|(|(||{|{||[|[||)|)|)|)||}|}|]|]|\t0.0\nROWPROPERTIES\t" |
707 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
708 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
4-
|
|
709 |
0 |
@Test(groups = { "Functional" })... |
710 |
|
public void secondaryStructureForRNASequence() throws Exception |
711 |
|
{ |
712 |
0 |
roundTripSSForRNA(aliFile, annFile); |
713 |
|
} |
714 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
4-
|
|
715 |
0 |
@Test(groups = { "Functional" })... |
716 |
|
public void curlyWUSSsecondaryStructureForRNASequence() throws Exception |
717 |
|
{ |
718 |
0 |
roundTripSSForRNA(aliFile, annFileCurlyWuss); |
719 |
|
} |
720 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
4-
|
|
721 |
0 |
@Test(groups = { "Functional" })... |
722 |
|
public void fullWUSSsecondaryStructureForRNASequence() throws Exception |
723 |
|
{ |
724 |
0 |
roundTripSSForRNA(aliFile, annFileFullWuss); |
725 |
|
} |
726 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4-
|
|
727 |
0 |
@Test(groups = { "Functional" })... |
728 |
|
public void detectWussBrackets() |
729 |
|
{ |
730 |
0 |
for (char ch : new char[] { '{', '}', '[', ']', '(', ')', '<', '>' }) |
731 |
|
{ |
732 |
0 |
Assert.assertTrue(StockholmFile.RNASS_BRACKETS.indexOf(ch) >= 0, |
733 |
|
"Didn't recognise '" + ch + "' as a WUSS bracket"); |
734 |
|
} |
735 |
0 |
for (char ch : new char[] { '@', '!', '*', ' ', '-', '.' }) |
736 |
|
{ |
737 |
0 |
Assert.assertFalse(StockholmFile.RNASS_BRACKETS.indexOf(ch) >= 0, |
738 |
|
"Shouldn't recognise '" + ch + "' as a WUSS bracket"); |
739 |
|
} |
740 |
|
} |
741 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
742 |
0 |
private static void roundTripSSForRNA(String aliFile, String annFile)... |
743 |
|
throws Exception |
744 |
|
{ |
745 |
0 |
AlignmentI al = new AppletFormatAdapter().readFile(aliFile, |
746 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Fasta); |
747 |
0 |
AnnotationFile aaf = new AnnotationFile(); |
748 |
0 |
aaf.readAnnotationFile(al, annFile, DataSourceType.PASTE); |
749 |
0 |
al.getAlignmentAnnotation()[0].visible = true; |
750 |
|
|
751 |
|
|
752 |
0 |
StockholmFile sf = new StockholmFile(al); |
753 |
|
|
754 |
0 |
String stockholmFile = sf.print(al.getSequencesArray(), true); |
755 |
|
|
756 |
0 |
AlignmentI newAl = new AppletFormatAdapter().readFile(stockholmFile, |
757 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Stockholm); |
758 |
|
|
759 |
|
|
760 |
|
|
761 |
0 |
testAlignmentEquivalence(al, newAl, true, true, true); |
762 |
|
|
763 |
|
} |
764 |
|
|
765 |
|
|
766 |
|
|
767 |
|
String aliFileRnaSS = ">Test.sequence/1-14\n" + "GUACAAAAAAAAAA"; |
768 |
|
|
769 |
|
String annFileRnaSSAlphaChars = "JALVIEW_ANNOTATION\n" |
770 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
771 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|(,(|E,E|H,H|B,B|h,h|e,e|b,b|(,(|E,E|),)|e,e|),)|>,>|\t2.0\n" |
772 |
|
+ "\n" |
773 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
774 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
775 |
|
|
776 |
|
String wrongAnnFileRnaSSAlphaChars = "JALVIEW_ANNOTATION\n" |
777 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
778 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|(,(|H,H|E,E|B,B|h,h|e,e|b,b|(,(|E,E|),)|e,e|),)|>,>|\t2.0\n" |
779 |
|
+ "\n" |
780 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
781 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
782 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 2 |
Complexity Density: 0.1 |
4-
|
|
783 |
0 |
@Test(groups = { "Functional" })... |
784 |
|
public void stockholmFileRnaSSAlphaChars() throws Exception |
785 |
|
{ |
786 |
0 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
787 |
0 |
AlignmentI al = af.readFile(RnaSSTestFile, DataSourceType.FILE, |
788 |
|
jalview.io.FileFormat.Stockholm); |
789 |
0 |
Iterable<AlignmentAnnotation> aai = al.findAnnotations(null, null, |
790 |
|
"Secondary Structure"); |
791 |
0 |
AlignmentAnnotation aa = aai.iterator().next(); |
792 |
0 |
Assert.assertTrue(aa.isRNA(), |
793 |
|
"'" + RnaSSTestFile + "' not recognised as RNA SS"); |
794 |
0 |
Assert.assertTrue(aa.isValidStruc(), |
795 |
|
"'" + RnaSSTestFile + "' not recognised as valid structure"); |
796 |
0 |
Annotation[] as = aa.annotations; |
797 |
0 |
char[] As = new char[as.length]; |
798 |
0 |
for (int i = 0; i < as.length; i++) |
799 |
|
{ |
800 |
0 |
As[i] = as[i].secondaryStructure; |
801 |
|
} |
802 |
0 |
char[] shouldBe = { '<', '(', 'E', 'H', 'B', 'h', 'e', 'b', '(', 'E', |
803 |
|
')', 'e', ')', '>' }; |
804 |
0 |
Assert.assertTrue(Arrays.equals(As, shouldBe), "Annotation is " |
805 |
|
+ new String(As) + " but should be " + new String(shouldBe)); |
806 |
|
|
807 |
|
|
808 |
0 |
AlignmentI newAl = new AppletFormatAdapter().readFile(aliFileRnaSS, |
809 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Fasta); |
810 |
0 |
AnnotationFile aaf = new AnnotationFile(); |
811 |
0 |
aaf.readAnnotationFile(newAl, annFileRnaSSAlphaChars, |
812 |
|
DataSourceType.PASTE); |
813 |
|
|
814 |
0 |
Assert.assertTrue( |
815 |
|
testRnaSSAnnotationsEquivalent(al.getAlignmentAnnotation()[0], |
816 |
|
newAl.getAlignmentAnnotation()[0]), |
817 |
|
"RNA SS Annotations SHOULD be pair-wise equivalent (but apparently aren't): \n" |
818 |
|
+ "RNA SS A 1:" + al.getAlignmentAnnotation()[0] + "\n" |
819 |
|
+ "RNA SS A 2:" + newAl.getAlignmentAnnotation()[0]); |
820 |
|
|
821 |
|
|
822 |
0 |
newAl = new AppletFormatAdapter().readFile(aliFileRnaSS, |
823 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Fasta); |
824 |
0 |
aaf = new AnnotationFile(); |
825 |
0 |
aaf.readAnnotationFile(newAl, wrongAnnFileRnaSSAlphaChars, |
826 |
|
DataSourceType.PASTE); |
827 |
|
|
828 |
0 |
boolean mismatch = testRnaSSAnnotationsEquivalent( |
829 |
|
al.getAlignmentAnnotation()[0], |
830 |
|
newAl.getAlignmentAnnotation()[0]); |
831 |
0 |
Assert.assertFalse(mismatch, |
832 |
|
"RNA SS Annotations SHOULD NOT be pair-wise equivalent (but apparently are): \n" |
833 |
|
+ "RNA SS A 1:" + al.getAlignmentAnnotation()[0] + "\n" |
834 |
|
+ "RNA SS A 2:" + newAl.getAlignmentAnnotation()[0]); |
835 |
|
} |
836 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
837 |
0 |
private static boolean testRnaSSAnnotationsEquivalent(... |
838 |
|
AlignmentAnnotation a1, AlignmentAnnotation a2) |
839 |
|
{ |
840 |
0 |
return a1.rnaSecondaryStructureEquivalent(a2); |
841 |
|
} |
842 |
|
|
843 |
|
String annFileRnaSSWithSpaceChars = "JALVIEW_ANNOTATION\n" |
844 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
845 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|.,.|H,H| , |B,B|h,h| , |b,b|(,(|E,E|.,.|e,e|),)|>,>|\t2.0\n" |
846 |
|
+ "\n" |
847 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
848 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
849 |
|
|
850 |
|
String annFileRnaSSWithoutSpaceChars = "JALVIEW_ANNOTATION\n" |
851 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
852 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|.,.|H,H|.,.|B,B|h,h|.,.|b,b|(,(|E,E|.,.|e,e|),)|>,>|\t2.0\n" |
853 |
|
+ "\n" |
854 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
855 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
856 |
|
|
857 |
|
String wrongAnnFileRnaSSWithoutSpaceChars = "JALVIEW_ANNOTATION\n" |
858 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
859 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|.,.|H,H|Z,Z|B,B|h,h|z,z|b,b|(,(|E,E|.,.|e,e|),)|>,>|\t2.0\n" |
860 |
|
+ "\n" |
861 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
862 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
863 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 2 |
Complexity Density: 0.07 |
4-
|
|
864 |
0 |
@Test(groups = { "Functional" })... |
865 |
|
public void stockholmFileRnaSSSpaceChars() throws Exception |
866 |
|
{ |
867 |
0 |
AlignmentI alWithSpaces = new AppletFormatAdapter().readFile( |
868 |
|
aliFileRnaSS, DataSourceType.PASTE, |
869 |
|
jalview.io.FileFormat.Fasta); |
870 |
0 |
AnnotationFile afWithSpaces = new AnnotationFile(); |
871 |
0 |
afWithSpaces.readAnnotationFile(alWithSpaces, |
872 |
|
annFileRnaSSWithSpaceChars, DataSourceType.PASTE); |
873 |
|
|
874 |
0 |
Iterable<AlignmentAnnotation> aaiWithSpaces = alWithSpaces |
875 |
|
.findAnnotations(null, null, "Secondary Structure"); |
876 |
0 |
AlignmentAnnotation aaWithSpaces = aaiWithSpaces.iterator().next(); |
877 |
0 |
Assert.assertTrue(aaWithSpaces.isRNA(), |
878 |
|
"'" + aaWithSpaces + "' not recognised as RNA SS"); |
879 |
0 |
Assert.assertTrue(aaWithSpaces.isValidStruc(), |
880 |
|
"'" + aaWithSpaces + "' not recognised as valid structure"); |
881 |
0 |
Annotation[] annWithSpaces = aaWithSpaces.annotations; |
882 |
0 |
char[] As = new char[annWithSpaces.length]; |
883 |
0 |
for (int i = 0; i < annWithSpaces.length; i++) |
884 |
|
{ |
885 |
0 |
As[i] = annWithSpaces[i].secondaryStructure; |
886 |
|
} |
887 |
|
|
888 |
0 |
char[] shouldBe = { '<', ' ', 'H', ' ', 'B', 'h', ' ', 'b', '(', 'E', |
889 |
|
' ', 'e', ')', '>' }; |
890 |
0 |
Assert.assertTrue(Arrays.equals(As, shouldBe), "Annotation is " |
891 |
|
+ new String(As) + " but should be " + new String(shouldBe)); |
892 |
|
|
893 |
|
|
894 |
0 |
AlignmentI alWithoutSpaces = new AppletFormatAdapter().readFile( |
895 |
|
aliFileRnaSS, DataSourceType.PASTE, |
896 |
|
jalview.io.FileFormat.Fasta); |
897 |
0 |
AnnotationFile afWithoutSpaces = new AnnotationFile(); |
898 |
0 |
afWithoutSpaces.readAnnotationFile(alWithoutSpaces, |
899 |
|
annFileRnaSSWithoutSpaceChars, DataSourceType.PASTE); |
900 |
|
|
901 |
0 |
Assert.assertTrue( |
902 |
|
testRnaSSAnnotationsEquivalent( |
903 |
|
alWithSpaces.getAlignmentAnnotation()[0], |
904 |
|
alWithoutSpaces.getAlignmentAnnotation()[0]), |
905 |
|
"RNA SS Annotations SHOULD be pair-wise equivalent (but apparently aren't): \n" |
906 |
|
+ "RNA SS A 1:" |
907 |
|
+ alWithSpaces.getAlignmentAnnotation()[0] |
908 |
|
.getRnaSecondaryStructure() |
909 |
|
+ "\n" + "RNA SS A 2:" |
910 |
|
+ alWithoutSpaces.getAlignmentAnnotation()[0] |
911 |
|
.getRnaSecondaryStructure()); |
912 |
|
|
913 |
|
|
914 |
0 |
AlignmentI wrongAlWithoutSpaces = new AppletFormatAdapter().readFile( |
915 |
|
aliFileRnaSS, DataSourceType.PASTE, |
916 |
|
jalview.io.FileFormat.Fasta); |
917 |
0 |
AnnotationFile wrongAfWithoutSpaces = new AnnotationFile(); |
918 |
0 |
wrongAfWithoutSpaces.readAnnotationFile(wrongAlWithoutSpaces, |
919 |
|
wrongAnnFileRnaSSWithoutSpaceChars, DataSourceType.PASTE); |
920 |
|
|
921 |
0 |
Assert.assertFalse( |
922 |
|
testRnaSSAnnotationsEquivalent( |
923 |
|
alWithSpaces.getAlignmentAnnotation()[0], |
924 |
|
wrongAlWithoutSpaces.getAlignmentAnnotation()[0]), |
925 |
|
"RNA SS Annotations SHOULD NOT be pair-wise equivalent (but apparently are): \n" |
926 |
|
+ "RNA SS A 1:" |
927 |
|
+ alWithSpaces.getAlignmentAnnotation()[0] |
928 |
|
.getRnaSecondaryStructure() |
929 |
|
+ "\n" + "RNA SS A 2:" |
930 |
|
+ wrongAlWithoutSpaces.getAlignmentAnnotation()[0] |
931 |
|
.getRnaSecondaryStructure()); |
932 |
|
|
933 |
|
|
934 |
|
|
935 |
0 |
alWithSpaces.getAlignmentAnnotation()[0].visible = true; |
936 |
0 |
StockholmFile sf = new StockholmFile(alWithSpaces); |
937 |
|
|
938 |
0 |
String stockholmFile = sf.print(alWithSpaces.getSequencesArray(), true); |
939 |
0 |
Pattern noSpacesInRnaSSAnnotation = Pattern |
940 |
|
.compile("\\n#=GC SS_cons\\s+\\S{14}\\n"); |
941 |
0 |
Matcher m = noSpacesInRnaSSAnnotation.matcher(stockholmFile); |
942 |
0 |
boolean matches = m.find(); |
943 |
0 |
Assert.assertTrue(matches, |
944 |
|
"StockholmFile output does not contain expected output (may contain spaces):\n" |
945 |
|
+ stockholmFile); |
946 |
|
|
947 |
|
} |
948 |
|
} |