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