JAL-2507 JAL-2509 allow whitespace==null for annotation row comparison, and test...
[jalview.git] / test / jalview / io / StockholmFileTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.io;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
26 import static org.testng.AssertJUnit.fail;
27
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.Annotation;
31 import jalview.datamodel.SequenceFeature;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.JvOptionPane;
34
35 import java.io.File;
36 import java.util.Arrays;
37 import java.util.BitSet;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 import org.testng.Assert;
43 import org.testng.annotations.BeforeClass;
44 import org.testng.annotations.Test;
45
46 public class StockholmFileTest
47 {
48
49   @BeforeClass(alwaysRun = true)
50   public void setUpJvOptionPane()
51   {
52     JvOptionPane.setInteractiveMode(false);
53     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54   }
55
56   static String PfamFile = "examples/PF00111_seed.stk",
57           RfamFile = "examples/RF00031_folded.stk";
58
59   @Test(groups = { "Functional" })
60   public void pfamFileIO() throws Exception
61   {
62     testFileIOwithFormat(new File(PfamFile), FileFormat.Stockholm, -1, 0,
63             false);
64   }
65
66   @Test(groups = { "Functional" })
67   public void pfamFileDataExtraction() throws Exception
68   {
69     AppletFormatAdapter af = new AppletFormatAdapter();
70     AlignmentI al = af.readFile(PfamFile, DataSourceType.FILE,
71             new IdentifyFile().identify(PfamFile, DataSourceType.FILE));
72     int numpdb = 0;
73     for (SequenceI sq : al.getSequences())
74     {
75       if (sq.getAllPDBEntries() != null)
76       {
77         numpdb += sq.getAllPDBEntries().size();
78       }
79     }
80     assertTrue(
81             "PF00111 seed alignment has at least 1 PDB file, but the reader found none.",
82             numpdb > 0);
83   }
84
85   @Test(groups = { "Functional" })
86   public void rfamFileIO() throws Exception
87   {
88     testFileIOwithFormat(new File(RfamFile), FileFormat.Stockholm, 2, 1,
89             false);
90   }
91
92   /**
93    * test alignment data in given file can be imported, exported and reimported
94    * with no dataloss
95    * 
96    * @param f
97    *          - source datafile (IdentifyFile.identify() should work with it)
98    * @param ioformat
99    *          - label for IO class used to write and read back in the data from
100    *          f
101    * @param ignoreRowVisibility
102    */
103
104   public static void testFileIOwithFormat(File f, FileFormatI ioformat,
105           int naliannot, int nminseqann, boolean ignoreRowVisibility)
106   {
107     System.out.println("Reading file: " + f);
108     String ff = f.getPath();
109     try
110     {
111       AppletFormatAdapter rf = new AppletFormatAdapter();
112
113       AlignmentI al = rf.readFile(ff, DataSourceType.FILE,
114               new IdentifyFile().identify(ff, DataSourceType.FILE));
115
116       assertNotNull("Couldn't read supplied alignment data.", al);
117
118       // make sure dataset is initialised ? not sure about this
119       for (int i = 0; i < al.getSequencesArray().length; ++i)
120       {
121         al.getSequenceAt(i).createDatasetSequence();
122       }
123       String outputfile = rf.formatSequences(ioformat, al, true);
124       System.out.println("Output file in '" + ioformat + "':\n"
125               + outputfile + "\n<<EOF\n");
126       // test for consistency in io
127       AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile,
128               DataSourceType.PASTE, ioformat);
129       assertNotNull("Couldn't parse reimported alignment data.", al_input);
130
131       FileFormatI identifyoutput = new IdentifyFile().identify(outputfile,
132               DataSourceType.PASTE);
133       assertNotNull("Identify routine failed for outputformat " + ioformat,
134               identifyoutput);
135       assertTrue(
136               "Identify routine could not recognise output generated by '"
137                       + ioformat + "' writer",
138               ioformat.equals(identifyoutput));
139       testAlignmentEquivalence(al, al_input, false);
140       int numaliannot = 0, numsqswithali = 0;
141       for (AlignmentAnnotation ala : al_input.getAlignmentAnnotation())
142       {
143         if (ala.sequenceRef == null)
144         {
145           numaliannot++;
146         }
147         else
148         {
149           numsqswithali++;
150         }
151       }
152       if (naliannot > -1)
153       {
154         assertEquals("Number of alignment annotations", naliannot,
155                 numaliannot);
156       }
157
158       assertTrue(
159               "Number of sequence associated annotations wasn't at least "
160                       + nminseqann, numsqswithali >= nminseqann);
161
162     } catch (Exception e)
163     {
164       e.printStackTrace();
165       assertTrue("Couln't format the alignment for output file.", false);
166     }
167   }
168
169   /**
170    * assert alignment equivalence
171    * 
172    * @param al
173    *          'original'
174    * @param al_input
175    *          'secondary' or generated alignment from some datapreserving
176    *          transformation
177    * @param ignoreFeatures
178    *          when true, differences in sequence feature annotation are ignored
179    */
180   public static void testAlignmentEquivalence(AlignmentI al,
181           AlignmentI al_input, boolean ignoreFeatures)
182   {
183     testAlignmentEquivalence(al, al_input, ignoreFeatures, false, false);
184   }
185
186   /**
187    * assert alignment equivalence - uses special comparators for RNA structure
188    * annotation rows.
189    * 
190    * @param al
191    *          'original'
192    * @param al_input
193    *          'secondary' or generated alignment from some datapreserving
194    *          transformation
195    * @param ignoreFeatures
196    *          when true, differences in sequence feature annotation are ignored
197    * 
198    * @param ignoreRowVisibility
199    *          when true, do not fail if there are differences in the visibility
200    *          of annotation rows
201    * @param allowNullAnnotation
202    *          when true, positions in alignment annotation that are null will be
203    *          considered equal to positions containing annotation where
204    *          Annotation.isWhitespace() returns true.
205    * 
206    */
207   public static void testAlignmentEquivalence(AlignmentI al,
208           AlignmentI al_input, boolean ignoreFeatures,
209           boolean ignoreRowVisibility, boolean allowNullAnnotation)
210   {
211     assertNotNull("Original alignment was null", al);
212     assertNotNull("Generated alignment was null", al_input);
213
214     assertTrue("Alignment dimension mismatch: original: " + al.getHeight()
215             + "x" + al.getWidth() + ", generated: " + al_input.getHeight()
216             + "x" + al_input.getWidth(),
217             al.getHeight() == al_input.getHeight()
218                     && al.getWidth() == al_input.getWidth());
219
220     // check Alignment annotation
221     AlignmentAnnotation[] aa_new = al_input.getAlignmentAnnotation();
222     AlignmentAnnotation[] aa_original = al.getAlignmentAnnotation();
223
224     // note - at moment we do not distinguish between alignment without any
225     // annotation rows and alignment with no annotation row vector
226     // we might want to revise this in future
227     int aa_new_size = (aa_new == null ? 0 : aa_new.length);
228     int aa_original_size = (aa_original == null ? 0 : aa_original.length);
229     Map<Integer, BitSet> orig_groups = new HashMap<Integer, BitSet>();
230     Map<Integer, BitSet> new_groups = new HashMap<Integer, BitSet>();
231
232     if (aa_new != null && aa_original != null)
233     {
234       for (int i = 0; i < aa_original.length; i++)
235       {
236         if (aa_new.length > i)
237         {
238           assertEqualSecondaryStructure(
239                   "Different alignment annotation at position " + i,
240                   aa_original[i], aa_new[i], allowNullAnnotation);
241           // compare graphGroup or graph properties - needed to verify JAL-1299
242           assertEquals("Graph type not identical.", aa_original[i].graph,
243                   aa_new[i].graph);
244           if (!ignoreRowVisibility)
245           {
246             assertEquals("Visibility not identical.",
247                     aa_original[i].visible,
248                   aa_new[i].visible);
249           }
250           assertEquals("Threshold line not identical.",
251                   aa_original[i].threshold, aa_new[i].threshold);
252           // graphGroup may differ, but pattern should be the same
253           Integer o_ggrp = new Integer(aa_original[i].graphGroup + 2);
254           Integer n_ggrp = new Integer(aa_new[i].graphGroup + 2);
255           BitSet orig_g = orig_groups.get(o_ggrp);
256           BitSet new_g = new_groups.get(n_ggrp);
257           if (orig_g == null)
258           {
259             orig_groups.put(o_ggrp, orig_g = new BitSet());
260           }
261           if (new_g == null)
262           {
263             new_groups.put(n_ggrp, new_g = new BitSet());
264           }
265           assertEquals("Graph Group pattern differs at annotation " + i,
266                   orig_g, new_g);
267           orig_g.set(i);
268           new_g.set(i);
269         }
270         else
271         {
272           System.err.println("No matching annotation row for "
273                   + aa_original[i].toString());
274         }
275       }
276     }
277     assertEquals(
278             "Generated and imported alignment have different annotation sets",
279             aa_original_size, aa_new_size);
280
281     // check sequences, annotation and features
282     SequenceI[] seq_original = new SequenceI[al.getSequencesArray().length];
283     seq_original = al.getSequencesArray();
284     SequenceI[] seq_new = new SequenceI[al_input.getSequencesArray().length];
285     seq_new = al_input.getSequencesArray();
286     SequenceFeature[] sequenceFeatures_original, sequenceFeatures_new;
287     AlignmentAnnotation annot_original, annot_new;
288     //
289     for (int i = 0; i < al.getSequencesArray().length; i++)
290     {
291       String name = seq_original[i].getName();
292       int start = seq_original[i].getStart();
293       int end = seq_original[i].getEnd();
294       System.out.println("Check sequence: " + name + "/" + start + "-"
295               + end);
296
297       // search equal sequence
298       for (int in = 0; in < al_input.getSequencesArray().length; in++)
299       {
300         if (name.equals(seq_new[in].getName())
301                 && start == seq_new[in].getStart()
302                 && end == seq_new[in].getEnd())
303         {
304           String ss_original = seq_original[i].getSequenceAsString();
305           String ss_new = seq_new[in].getSequenceAsString();
306           assertEquals("The sequences " + name + "/" + start + "-" + end
307                   + " are not equal", ss_original, ss_new);
308
309           assertTrue(
310                   "Sequence Features were not equivalent"
311                           + (ignoreFeatures ? " ignoring." : ""),
312                   ignoreFeatures
313                           || (seq_original[i].getSequenceFeatures() == null && seq_new[in]
314                                   .getSequenceFeatures() == null)
315                           || (seq_original[i].getSequenceFeatures() != null && seq_new[in]
316                                   .getSequenceFeatures() != null));
317           // compare sequence features
318           if (seq_original[i].getSequenceFeatures() != null
319                   && seq_new[in].getSequenceFeatures() != null)
320           {
321             System.out.println("There are feature!!!");
322             sequenceFeatures_original = new SequenceFeature[seq_original[i]
323                     .getSequenceFeatures().length];
324             sequenceFeatures_original = seq_original[i]
325                     .getSequenceFeatures();
326             sequenceFeatures_new = new SequenceFeature[seq_new[in]
327                     .getSequenceFeatures().length];
328             sequenceFeatures_new = seq_new[in].getSequenceFeatures();
329
330             assertEquals("different number of features",
331                     seq_original[i].getSequenceFeatures().length,
332                     seq_new[in].getSequenceFeatures().length);
333
334             for (int feat = 0; feat < seq_original[i].getSequenceFeatures().length; feat++)
335             {
336               assertEquals("Different features",
337                       sequenceFeatures_original[feat],
338                       sequenceFeatures_new[feat]);
339             }
340           }
341           // compare alignment annotation
342           if (al.getSequenceAt(i).getAnnotation() != null
343                   && al_input.getSequenceAt(in).getAnnotation() != null)
344           {
345             for (int j = 0; j < al.getSequenceAt(i).getAnnotation().length; j++)
346             {
347               if (al.getSequenceAt(i).getAnnotation()[j] != null
348                       && al_input.getSequenceAt(in).getAnnotation()[j] != null)
349               {
350                 annot_original = al.getSequenceAt(i).getAnnotation()[j];
351                 annot_new = al_input.getSequenceAt(in).getAnnotation()[j];
352                 assertEqualSecondaryStructure(
353                         "Different annotation elements", annot_original,
354                         annot_new, allowNullAnnotation);
355               }
356             }
357           }
358           else if (al.getSequenceAt(i).getAnnotation() == null
359                   && al_input.getSequenceAt(in).getAnnotation() == null)
360           {
361             System.out.println("No annotations");
362           }
363           else if (al.getSequenceAt(i).getAnnotation() != null
364                   && al_input.getSequenceAt(in).getAnnotation() == null)
365           {
366             fail("Annotations differed between sequences ("
367                     + al.getSequenceAt(i).getName() + ") and ("
368                     + al_input.getSequenceAt(i).getName() + ")");
369           }
370           break;
371         }
372       }
373     }
374   }
375
376   /**
377    * compare two annotation rows, with special support for secondary structure
378    * comparison. With RNA, only the value and the secondaryStructure symbols are
379    * compared, displayCharacter and description are ignored. Annotations where
380    * Annotation.isWhitespace() is true are always considered equal.
381    * 
382    * @param message
383    *          - not actually used yet..
384    * @param annot_or
385    *          - the original annotation
386    * @param annot_new
387    *          - the one compared to the original annotation
388    * @param allowNullEquivalence
389    *          when true, positions in alignment annotation that are null will be
390    *          considered equal to non-null positions for which
391    *          Annotation.isWhitespace() is true.
392    */
393   private static void assertEqualSecondaryStructure(String message,
394           AlignmentAnnotation annot_or, AlignmentAnnotation annot_new,
395           boolean allowNullEqivalence)
396   {
397     // TODO: test to cover this assert behaves correctly for all allowed
398     // variations of secondary structure annotation row equivalence
399     if (annot_or.annotations.length != annot_new.annotations.length)
400     {
401       fail("Different lengths for annotation row elements: "
402               + annot_or.annotations.length + "!="
403               + annot_new.annotations.length);
404     }
405     boolean isRna = annot_or.isRNA();
406     assertTrue("Expected " + (isRna ? " valid RNA " : " no RNA ")
407             + " secondary structure in the row.",
408             isRna == annot_new.isRNA());
409     for (int i = 0; i < annot_or.annotations.length; i++)
410     {
411       Annotation an_or = annot_or.annotations[i], an_new = annot_new.annotations[i];
412       if (an_or != null && an_new != null)
413       {
414
415         if (isRna)
416         {
417           if (an_or.secondaryStructure != an_new.secondaryStructure
418                   || ((Float.isNaN(an_or.value) != Float
419                           .isNaN(an_new.value)) || an_or.value != an_new.value))
420           {
421             fail("Different RNA secondary structure at column " + i
422                     + " expected: [" + annot_or.annotations[i].toString()
423                     + "] but got: [" + annot_new.annotations[i].toString()
424                     + "]");
425           }
426         }
427         else
428         {
429           // not RNA secondary structure, so expect all elements to match...
430           if ((an_or.isWhitespace() != an_new.isWhitespace())
431                   || !an_or.displayCharacter.trim().equals(
432                   an_new.displayCharacter.trim())
433                   || !("" + an_or.secondaryStructure).trim().equals(
434                           ("" + an_new.secondaryStructure).trim())
435                   || (an_or.description != an_new.description && !((an_or.description == null && an_new.description
436                           .trim().length() == 0)
437                           || (an_new.description == null && an_or.description
438                                   .trim().length() == 0) || an_or.description
439                           .trim().equals(an_new.description.trim())))
440                   || !((Float.isNaN(an_or.value) && Float
441                           .isNaN(an_new.value)) || an_or.value == an_new.value))
442           {
443             fail("Annotation Element Mismatch\nElement " + i
444                     + " in original: " + annot_or.annotations[i].toString()
445                     + "\nElement " + i + " in new: "
446                     + annot_new.annotations[i].toString());
447           }
448         }
449       }
450       else if (annot_or.annotations[i] == null
451               && annot_new.annotations[i] == null)
452       {
453         continue;
454       }
455       else
456       {
457         if (allowNullEqivalence)
458         {
459           if (an_or != null && an_or.isWhitespace())
460
461           {
462             continue;
463           }
464           if (an_new != null && an_new.isWhitespace())
465           {
466             continue;
467           }
468         }
469         // need also to test for null in one, non-SS annotation in other...
470         fail("Annotation Element Mismatch\nElement " + i + " in original: "
471                 + (an_or == null ? "is null" : an_or.toString())
472                 + "\nElement " + i + " in new: "
473                 + (an_new == null ? "is null" : an_new.toString()));
474       }
475     }
476   }
477
478   /**
479    * @see assertEqualSecondaryStructure - test if two secondary structure
480    *      annotations are not equal
481    * @param message
482    * @param an_orig
483    * @param an_new
484    * @param allowNullEquivalence
485    */
486   public static void assertNotEqualSecondaryStructure(String message,
487           AlignmentAnnotation an_orig, AlignmentAnnotation an_new,
488           boolean allowNullEquivalence)
489   {
490     boolean thrown = false;
491     try
492     {
493       assertEqualSecondaryStructure("", an_orig, an_new,
494               allowNullEquivalence);
495     } catch (AssertionError af)
496     {
497       thrown = true;
498     }
499     if (!thrown)
500     {
501       fail("Expected difference for [" + an_orig + "] and [" + an_new + "]");
502     }
503   }
504   private AlignmentAnnotation makeAnnot(Annotation ae)
505   {
506     return new AlignmentAnnotation("label", "description", new Annotation[]
507     { ae });
508   }
509
510   @Test(groups={"Functional"})
511   public void testAnnotationEquivalence()
512   {
513     AlignmentAnnotation one = makeAnnot(new Annotation("", "", ' ', 1));
514     AlignmentAnnotation anotherOne = makeAnnot(new Annotation("", "", ' ',
515             1));
516     AlignmentAnnotation sheet = makeAnnot(new Annotation("","",'E',0f));
517     AlignmentAnnotation anotherSheet = makeAnnot(new Annotation("","",'E',0f)); 
518     AlignmentAnnotation sheetWithLabel = makeAnnot(new Annotation("1", "",
519             'E', 0f));
520     AlignmentAnnotation anotherSheetWithLabel = makeAnnot(new Annotation(
521             "1", "", 'E', 0f));
522     AlignmentAnnotation rnaNoDC = makeAnnot(new Annotation("","",'<',0f));
523     AlignmentAnnotation anotherRnaNoDC = makeAnnot(new Annotation("","",'<',0f));
524     AlignmentAnnotation rnaWithDC = makeAnnot(new Annotation("B", "", '<',
525             0f));
526     AlignmentAnnotation anotherRnaWithDC = makeAnnot(new Annotation("B",
527             "", '<', 0f));
528     
529     // check self equivalence
530     for (boolean allowNull : new boolean[] { true, false })
531     {
532       assertEqualSecondaryStructure("Should be equal", one, anotherOne,
533               allowNull);
534       assertEqualSecondaryStructure("Should be equal", sheet, anotherSheet,
535               allowNull);
536       assertEqualSecondaryStructure("Should be equal", sheetWithLabel,
537               anotherSheetWithLabel, allowNull);
538       assertEqualSecondaryStructure("Should be equal", rnaNoDC,
539               anotherRnaNoDC, allowNull);
540       assertEqualSecondaryStructure("Should be equal", rnaWithDC,
541               anotherRnaWithDC, allowNull);
542       // display character doesn't matter for RNA structure (for 2.10.2)
543       assertEqualSecondaryStructure("Should be equal", rnaWithDC, rnaNoDC,
544               allowNull);
545       assertEqualSecondaryStructure("Should be equal", rnaNoDC, rnaWithDC,
546               allowNull);
547     }
548
549     // verify others are different
550     List<AlignmentAnnotation> aaSet = Arrays.asList(one, sheet,
551             sheetWithLabel, rnaWithDC);
552     for (int p = 0; p < aaSet.size(); p++)
553     {
554       for (int q = 0; q < aaSet.size(); q++)
555       {
556         if (p != q)
557         {
558           assertNotEqualSecondaryStructure("Should be different",
559                     aaSet.get(p), aaSet.get(q), false);
560         }
561         else
562         {
563           assertEqualSecondaryStructure("Should be same", aaSet.get(p),
564                   aaSet.get(q), false);
565           assertEqualSecondaryStructure("Should be same", aaSet.get(p),
566                   aaSet.get(q), true);
567           assertNotEqualSecondaryStructure(
568                   "Should be different to empty anot", aaSet.get(p),
569                   makeAnnot(Annotation.EMPTY_ANNOTATION), false);
570           assertNotEqualSecondaryStructure(
571                   "Should be different to empty annot",
572                   makeAnnot(Annotation.EMPTY_ANNOTATION), aaSet.get(q),
573                   true);
574           assertNotEqualSecondaryStructure("Should be different to null",
575                   aaSet.get(p), makeAnnot(null), false);
576           assertNotEqualSecondaryStructure("Should be different to null",
577                   makeAnnot(null), aaSet.get(q), true);
578         }
579       }
580     }
581
582     // test null
583
584   }
585
586   String aliFile = ">Dm\nAAACCCUUUUACACACGGGAAAGGG";
587   String annFile = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n"
588           + "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t"
589           + "(|(|(|(|, .|, .|, .|, .|)|)|)|)|\t0.0\nROWPROPERTIES\t"
590           + "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false";
591
592   String annFileCurlyWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n"
593           + "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t"
594           + "(|(|(|(||{|{||{|{||)|)|)|)||}|}|}|}|\t0.0\nROWPROPERTIES\t"
595           + "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false";
596   String annFileFullWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n"
597           + "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t"
598           + "(|(|(|(||{|{||[|[||)|)|)|)||}|}|]|]|\t0.0\nROWPROPERTIES\t"
599           + "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false";
600
601   @Test(groups = { "Functional" })
602   public void secondaryStructureForRNASequence() throws Exception
603   {
604     roundTripSSForRNA(aliFile, annFile);
605   }
606
607   @Test(groups = { "Functional" })
608   public void curlyWUSSsecondaryStructureForRNASequence() throws Exception
609   {
610     roundTripSSForRNA(aliFile, annFileCurlyWuss);
611   }
612
613   @Test(groups = { "Functional" })
614   public void fullWUSSsecondaryStructureForRNASequence() throws Exception
615   {
616     roundTripSSForRNA(aliFile, annFileFullWuss);
617   }
618
619   @Test(groups = { "Functional" })
620   public void detectWussBrackets()
621   {
622     for (char ch : new char[] { '{', '}', '[', ']', '(', ')', '<', '>' })
623     {
624       Assert.assertTrue(StockholmFile.DETECT_BRACKETS.matchAt("" + ch, 0),
625               "Didn't recognise " + ch + " as a WUSS bracket");
626     }
627     for (char ch : new char[] { '@', '!', 'V', 'Q', '*', ' ', '-', '.' })
628     {
629       Assert.assertFalse(StockholmFile.DETECT_BRACKETS.matchAt("" + ch, 0),
630               "Shouldn't recognise " + ch + " as a WUSS bracket");
631     }
632   }
633   private static void roundTripSSForRNA(String aliFile, String annFile)
634           throws Exception
635   {
636     AlignmentI al = new AppletFormatAdapter().readFile(aliFile,
637             DataSourceType.PASTE, jalview.io.FileFormat.Fasta);
638     AnnotationFile aaf = new AnnotationFile();
639     aaf.readAnnotationFile(al, annFile, DataSourceType.PASTE);
640     al.getAlignmentAnnotation()[0].visible = true;
641
642     // TODO: create a better 'save as <format>' pattern
643     StockholmFile sf = new StockholmFile(al);
644
645     String stockholmFile = sf.print(al.getSequencesArray(), true);
646
647     AlignmentI newAl = new AppletFormatAdapter().readFile(stockholmFile,
648             DataSourceType.PASTE, jalview.io.FileFormat.Stockholm);
649     // AlignmentUtils.showOrHideSequenceAnnotations(newAl.getViewport()
650     // .getAlignment(), Arrays.asList("Secondary Structure"), newAl
651     // .getViewport().getAlignment().getSequences(), true, true);
652     testAlignmentEquivalence(al, newAl, true, true, true);
653
654   }
655 }