JAL-2507 - required callers to specify exact ignore flags for StockholmFileTest.testA...
[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     SequenceFeature[] sequenceFeatures_original, sequenceFeatures_new;
291     AlignmentAnnotation annot_original, annot_new;
292     //
293     for (int i = 0; i < al.getSequencesArray().length; i++)
294     {
295       String name = seq_original[i].getName();
296       int start = seq_original[i].getStart();
297       int end = seq_original[i].getEnd();
298       System.out.println("Check sequence: " + name + "/" + start + "-"
299               + end);
300
301       // search equal sequence
302       for (int in = 0; in < al_input.getSequencesArray().length; in++)
303       {
304         if (name.equals(seq_new[in].getName())
305                 && start == seq_new[in].getStart()
306                 && end == seq_new[in].getEnd())
307         {
308           String ss_original = seq_original[i].getSequenceAsString();
309           String ss_new = seq_new[in].getSequenceAsString();
310           assertEquals("The sequences " + name + "/" + start + "-" + end
311                   + " are not equal", ss_original, ss_new);
312
313           assertTrue(
314                   "Sequence Features were not equivalent"
315                           + (ignoreFeatures ? " ignoring." : ""),
316                   ignoreFeatures
317                           || (seq_original[i].getSequenceFeatures() == null && seq_new[in]
318                                   .getSequenceFeatures() == null)
319                           || (seq_original[i].getSequenceFeatures() != null && seq_new[in]
320                                   .getSequenceFeatures() != null));
321           // compare sequence features
322           if (seq_original[i].getSequenceFeatures() != null
323                   && seq_new[in].getSequenceFeatures() != null)
324           {
325             System.out.println("There are feature!!!");
326             sequenceFeatures_original = new SequenceFeature[seq_original[i]
327                     .getSequenceFeatures().length];
328             sequenceFeatures_original = seq_original[i]
329                     .getSequenceFeatures();
330             sequenceFeatures_new = new SequenceFeature[seq_new[in]
331                     .getSequenceFeatures().length];
332             sequenceFeatures_new = seq_new[in].getSequenceFeatures();
333
334             assertEquals("different number of features",
335                     seq_original[i].getSequenceFeatures().length,
336                     seq_new[in].getSequenceFeatures().length);
337
338             for (int feat = 0; feat < seq_original[i].getSequenceFeatures().length; feat++)
339             {
340               assertEquals("Different features",
341                       sequenceFeatures_original[feat],
342                       sequenceFeatures_new[feat]);
343             }
344           }
345           // compare alignment annotation
346           if (al.getSequenceAt(i).getAnnotation() != null
347                   && al_input.getSequenceAt(in).getAnnotation() != null)
348           {
349             for (int j = 0; j < al.getSequenceAt(i).getAnnotation().length; j++)
350             {
351               if (al.getSequenceAt(i).getAnnotation()[j] != null
352                       && al_input.getSequenceAt(in).getAnnotation()[j] != null)
353               {
354                 annot_original = al.getSequenceAt(i).getAnnotation()[j];
355                 annot_new = al_input.getSequenceAt(in).getAnnotation()[j];
356                 assertEqualSecondaryStructure(
357                         "Different annotation elements", annot_original,
358                         annot_new, allowNullAnnotation);
359               }
360             }
361           }
362           else if (al.getSequenceAt(i).getAnnotation() == null
363                   && al_input.getSequenceAt(in).getAnnotation() == null)
364           {
365             System.out.println("No annotations");
366           }
367           else if (al.getSequenceAt(i).getAnnotation() != null
368                   && al_input.getSequenceAt(in).getAnnotation() == null)
369           {
370             fail("Annotations differed between sequences ("
371                     + al.getSequenceAt(i).getName() + ") and ("
372                     + al_input.getSequenceAt(i).getName() + ")");
373           }
374           break;
375         }
376       }
377     }
378   }
379
380   /**
381    * compare two annotation rows, with special support for secondary structure
382    * comparison. With RNA, only the value and the secondaryStructure symbols are
383    * compared, displayCharacter and description are ignored. Annotations where
384    * Annotation.isWhitespace() is true are always considered equal.
385    * 
386    * @param message
387    *          - not actually used yet..
388    * @param annot_or
389    *          - the original annotation
390    * @param annot_new
391    *          - the one compared to the original annotation
392    * @param allowNullEquivalence
393    *          when true, positions in alignment annotation that are null will be
394    *          considered equal to non-null positions for which
395    *          Annotation.isWhitespace() is true.
396    */
397   private static void assertEqualSecondaryStructure(String message,
398           AlignmentAnnotation annot_or, AlignmentAnnotation annot_new,
399           boolean allowNullEqivalence)
400   {
401     // TODO: test to cover this assert behaves correctly for all allowed
402     // variations of secondary structure annotation row equivalence
403     if (annot_or.annotations.length != annot_new.annotations.length)
404     {
405       fail("Different lengths for annotation row elements: "
406               + annot_or.annotations.length + "!="
407               + annot_new.annotations.length);
408     }
409     boolean isRna = annot_or.isRNA();
410     assertTrue("Expected " + (isRna ? " valid RNA " : " no RNA ")
411             + " secondary structure in the row.",
412             isRna == annot_new.isRNA());
413     for (int i = 0; i < annot_or.annotations.length; i++)
414     {
415       Annotation an_or = annot_or.annotations[i], an_new = annot_new.annotations[i];
416       if (an_or != null && an_new != null)
417       {
418
419         if (isRna)
420         {
421           if (an_or.secondaryStructure != an_new.secondaryStructure
422                   || ((Float.isNaN(an_or.value) != Float
423                           .isNaN(an_new.value)) || an_or.value != an_new.value))
424           {
425             fail("Different RNA secondary structure at column " + i
426                     + " expected: [" + annot_or.annotations[i].toString()
427                     + "] but got: [" + annot_new.annotations[i].toString()
428                     + "]");
429           }
430         }
431         else
432         {
433           // not RNA secondary structure, so expect all elements to match...
434           if ((an_or.isWhitespace() != an_new.isWhitespace())
435                   || !an_or.displayCharacter.trim().equals(
436                   an_new.displayCharacter.trim())
437                   || !("" + an_or.secondaryStructure).trim().equals(
438                           ("" + an_new.secondaryStructure).trim())
439                   || (an_or.description != an_new.description && !((an_or.description == null && an_new.description
440                           .trim().length() == 0)
441                           || (an_new.description == null && an_or.description
442                                   .trim().length() == 0) || an_or.description
443                           .trim().equals(an_new.description.trim())))
444                   || !((Float.isNaN(an_or.value) && Float
445                           .isNaN(an_new.value)) || an_or.value == an_new.value))
446           {
447             fail("Annotation Element Mismatch\nElement " + i
448                     + " in original: " + annot_or.annotations[i].toString()
449                     + "\nElement " + i + " in new: "
450                     + annot_new.annotations[i].toString());
451           }
452         }
453       }
454       else if (annot_or.annotations[i] == null
455               && annot_new.annotations[i] == null)
456       {
457         continue;
458       }
459       else
460       {
461         if (allowNullEqivalence)
462         {
463           if (an_or != null && an_or.isWhitespace())
464
465           {
466             continue;
467           }
468           if (an_new != null && an_new.isWhitespace())
469           {
470             continue;
471           }
472         }
473         // need also to test for null in one, non-SS annotation in other...
474         fail("Annotation Element Mismatch\nElement " + i + " in original: "
475                 + (an_or == null ? "is null" : an_or.toString())
476                 + "\nElement " + i + " in new: "
477                 + (an_new == null ? "is null" : an_new.toString()));
478       }
479     }
480   }
481
482   /**
483    * @see assertEqualSecondaryStructure - test if two secondary structure
484    *      annotations are not equal
485    * @param message
486    * @param an_orig
487    * @param an_new
488    * @param allowNullEquivalence
489    */
490   public static void assertNotEqualSecondaryStructure(String message,
491           AlignmentAnnotation an_orig, AlignmentAnnotation an_new,
492           boolean allowNullEquivalence)
493   {
494     boolean thrown = false;
495     try
496     {
497       assertEqualSecondaryStructure("", an_orig, an_new,
498               allowNullEquivalence);
499     } catch (AssertionError af)
500     {
501       thrown = true;
502     }
503     if (!thrown)
504     {
505       fail("Expected difference for [" + an_orig + "] and [" + an_new + "]");
506     }
507   }
508   private AlignmentAnnotation makeAnnot(Annotation ae)
509   {
510     return new AlignmentAnnotation("label", "description", new Annotation[]
511     { ae });
512   }
513
514   @Test(groups={"Functional"})
515   public void testAnnotationEquivalence()
516   {
517     AlignmentAnnotation one = makeAnnot(new Annotation("", "", ' ', 1));
518     AlignmentAnnotation anotherOne = makeAnnot(new Annotation("", "", ' ',
519             1));
520     AlignmentAnnotation sheet = makeAnnot(new Annotation("","",'E',0f));
521     AlignmentAnnotation anotherSheet = makeAnnot(new Annotation("","",'E',0f)); 
522     AlignmentAnnotation sheetWithLabel = makeAnnot(new Annotation("1", "",
523             'E', 0f));
524     AlignmentAnnotation anotherSheetWithLabel = makeAnnot(new Annotation(
525             "1", "", 'E', 0f));
526     AlignmentAnnotation rnaNoDC = makeAnnot(new Annotation("","",'<',0f));
527     AlignmentAnnotation anotherRnaNoDC = makeAnnot(new Annotation("","",'<',0f));
528     AlignmentAnnotation rnaWithDC = makeAnnot(new Annotation("B", "", '<',
529             0f));
530     AlignmentAnnotation anotherRnaWithDC = makeAnnot(new Annotation("B",
531             "", '<', 0f));
532     
533     // check self equivalence
534     for (boolean allowNull : new boolean[] { true, false })
535     {
536       assertEqualSecondaryStructure("Should be equal", one, anotherOne,
537               allowNull);
538       assertEqualSecondaryStructure("Should be equal", sheet, anotherSheet,
539               allowNull);
540       assertEqualSecondaryStructure("Should be equal", sheetWithLabel,
541               anotherSheetWithLabel, allowNull);
542       assertEqualSecondaryStructure("Should be equal", rnaNoDC,
543               anotherRnaNoDC, allowNull);
544       assertEqualSecondaryStructure("Should be equal", rnaWithDC,
545               anotherRnaWithDC, allowNull);
546       // display character doesn't matter for RNA structure (for 2.10.2)
547       assertEqualSecondaryStructure("Should be equal", rnaWithDC, rnaNoDC,
548               allowNull);
549       assertEqualSecondaryStructure("Should be equal", rnaNoDC, rnaWithDC,
550               allowNull);
551     }
552
553     // verify others are different
554     List<AlignmentAnnotation> aaSet = Arrays.asList(one, sheet,
555             sheetWithLabel, rnaWithDC);
556     for (int p = 0; p < aaSet.size(); p++)
557     {
558       for (int q = 0; q < aaSet.size(); q++)
559       {
560         if (p != q)
561         {
562           assertNotEqualSecondaryStructure("Should be different",
563                     aaSet.get(p), aaSet.get(q), false);
564         }
565         else
566         {
567           assertEqualSecondaryStructure("Should be same", aaSet.get(p),
568                   aaSet.get(q), false);
569           assertEqualSecondaryStructure("Should be same", aaSet.get(p),
570                   aaSet.get(q), true);
571           assertNotEqualSecondaryStructure(
572                   "Should be different to empty anot", aaSet.get(p),
573                   makeAnnot(Annotation.EMPTY_ANNOTATION), false);
574           assertNotEqualSecondaryStructure(
575                   "Should be different to empty annot",
576                   makeAnnot(Annotation.EMPTY_ANNOTATION), aaSet.get(q),
577                   true);
578           assertNotEqualSecondaryStructure("Should be different to null",
579                   aaSet.get(p), makeAnnot(null), false);
580           assertNotEqualSecondaryStructure("Should be different to null",
581                   makeAnnot(null), aaSet.get(q), true);
582         }
583       }
584     }
585
586     // test null
587
588   }
589
590   String aliFile = ">Dm\nAAACCCUUUUACACACGGGAAAGGG";
591   String annFile = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n"
592           + "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t"
593           + "(|(|(|(|, .|, .|, .|, .|)|)|)|)|\t0.0\nROWPROPERTIES\t"
594           + "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false";
595
596   String annFileCurlyWuss = "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   String annFileFullWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n"
601           + "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t"
602           + "(|(|(|(||{|{||[|[||)|)|)|)||}|}|]|]|\t0.0\nROWPROPERTIES\t"
603           + "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false";
604
605   @Test(groups = { "Functional" })
606   public void secondaryStructureForRNASequence() throws Exception
607   {
608     roundTripSSForRNA(aliFile, annFile);
609   }
610
611   @Test(groups = { "Functional" })
612   public void curlyWUSSsecondaryStructureForRNASequence() throws Exception
613   {
614     roundTripSSForRNA(aliFile, annFileCurlyWuss);
615   }
616
617   @Test(groups = { "Functional" })
618   public void fullWUSSsecondaryStructureForRNASequence() throws Exception
619   {
620     roundTripSSForRNA(aliFile, annFileFullWuss);
621   }
622
623   @Test(groups = { "Functional" })
624   public void detectWussBrackets()
625   {
626     for (char ch : new char[] { '{', '}', '[', ']', '(', ')', '<', '>' })
627     {
628       Assert.assertTrue(StockholmFile.DETECT_BRACKETS.matchAt("" + ch, 0),
629               "Didn't recognise " + ch + " as a WUSS bracket");
630     }
631     for (char ch : new char[] { '@', '!', 'V', 'Q', '*', ' ', '-', '.' })
632     {
633       Assert.assertFalse(StockholmFile.DETECT_BRACKETS.matchAt("" + ch, 0),
634               "Shouldn't recognise " + ch + " as a WUSS bracket");
635     }
636   }
637   private static void roundTripSSForRNA(String aliFile, String annFile)
638           throws Exception
639   {
640     AlignmentI al = new AppletFormatAdapter().readFile(aliFile,
641             DataSourceType.PASTE, jalview.io.FileFormat.Fasta);
642     AnnotationFile aaf = new AnnotationFile();
643     aaf.readAnnotationFile(al, annFile, DataSourceType.PASTE);
644     al.getAlignmentAnnotation()[0].visible = true;
645
646     // TODO: create a better 'save as <format>' pattern
647     StockholmFile sf = new StockholmFile(al);
648
649     String stockholmFile = sf.print(al.getSequencesArray(), true);
650
651     AlignmentI newAl = new AppletFormatAdapter().readFile(stockholmFile,
652             DataSourceType.PASTE, jalview.io.FileFormat.Stockholm);
653     // AlignmentUtils.showOrHideSequenceAnnotations(newAl.getViewport()
654     // .getAlignment(), Arrays.asList("Secondary Structure"), newAl
655     // .getViewport().getAlignment().getSequences(), true, true);
656     testAlignmentEquivalence(al, newAl, true, true, true);
657
658   }
659 }