Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io

File StockholmFileTest.java

 

Code metrics

80
175
16
1
657
494
83
0.47
10.94
16
5.19

Classes

Class Line # Actions
StockholmFileTest 46 175 83 25
0.9077490690.8%
 

Contributing tests

This file is covered by 12 tests. .

Source view

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  1 toggle @BeforeClass(alwaysRun = true)
50    public void setUpJvOptionPane()
51    {
52  1 JvOptionPane.setInteractiveMode(false);
53  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54    }
55   
56    static String PfamFile = "examples/PF00111_seed.stk",
57    RfamFile = "examples/RF00031_folded.stk";
58   
 
59  1 toggle @Test(groups = { "Functional" })
60    public void pfamFileIO() throws Exception
61    {
62  1 testFileIOwithFormat(new File(PfamFile), FileFormat.Stockholm, -1, 0,
63    false, false, false);
64    }
65   
 
66  1 toggle @Test(groups = { "Functional" })
67    public void pfamFileDataExtraction() throws Exception
68    {
69  1 AppletFormatAdapter af = new AppletFormatAdapter();
70  1 AlignmentI al = af.readFile(PfamFile, DataSourceType.FILE,
71    new IdentifyFile().identify(PfamFile, DataSourceType.FILE));
72  1 int numpdb = 0;
73  1 for (SequenceI sq : al.getSequences())
74    {
75  206 if (sq.getAllPDBEntries() != null)
76    {
77  206 numpdb += sq.getAllPDBEntries().size();
78    }
79    }
80  1 assertTrue(
81    "PF00111 seed alignment has at least 1 PDB file, but the reader found none.",
82    numpdb > 0);
83    }
84   
 
85  1 toggle @Test(groups = { "Functional" })
86    public void rfamFileIO() throws Exception
87    {
88  1 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  3 toggle public static void testFileIOwithFormat(File f, FileFormatI ioformat,
107    int naliannot, int nminseqann, boolean ignoreFeatures,
108    boolean ignoreRowVisibility, boolean allowNullAnnotations)
109    {
110  3 System.out.println("Reading file: " + f);
111  3 String ff = f.getPath();
112  3 try
113    {
114  3 AppletFormatAdapter rf = new AppletFormatAdapter();
115   
116  3 AlignmentI al = rf.readFile(ff, DataSourceType.FILE,
117    new IdentifyFile().identify(ff, DataSourceType.FILE));
118   
119  3 assertNotNull("Couldn't read supplied alignment data.", al);
120   
121    // make sure dataset is initialised ? not sure about this
122  272 for (int i = 0; i < al.getSequencesArray().length; ++i)
123    {
124  269 al.getSequenceAt(i).createDatasetSequence();
125    }
126  3 String outputfile = rf.formatSequences(ioformat, al, true);
127  3 System.out.println("Output file in '" + ioformat + "':\n"
128    + outputfile + "\n<<EOF\n");
129    // test for consistency in io
130  3 AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile,
131    DataSourceType.PASTE, ioformat);
132  3 assertNotNull("Couldn't parse reimported alignment data.", al_input);
133   
134  3 FileFormatI identifyoutput = new IdentifyFile().identify(outputfile,
135    DataSourceType.PASTE);
136  3 assertNotNull("Identify routine failed for outputformat " + ioformat,
137    identifyoutput);
138  3 assertTrue(
139    "Identify routine could not recognise output generated by '"
140    + ioformat + "' writer",
141    ioformat.equals(identifyoutput));
142  3 testAlignmentEquivalence(al, al_input, ignoreFeatures,
143    ignoreRowVisibility, allowNullAnnotations);
144  3 int numaliannot = 0, numsqswithali = 0;
145  3 for (AlignmentAnnotation ala : al_input.getAlignmentAnnotation())
146    {
147  80 if (ala.sequenceRef == null)
148    {
149  4 numaliannot++;
150    }
151    else
152    {
153  76 numsqswithali++;
154    }
155    }
156  3 if (naliannot > -1)
157    {
158  1 assertEquals("Number of alignment annotations", naliannot,
159    numaliannot);
160    }
161   
162  3 assertTrue(
163    "Number of sequence associated annotations wasn't at least "
164    + nminseqann, numsqswithali >= nminseqann);
165   
166    } catch (Exception e)
167    {
168  0 e.printStackTrace();
169  0 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  0 toggle public static void testAlignmentEquivalence(AlignmentI al,
185    AlignmentI al_input, boolean ignoreFeatures)
186    {
187  0 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  13 toggle public static void testAlignmentEquivalence(AlignmentI al,
212    AlignmentI al_input, boolean ignoreFeatures,
213    boolean ignoreRowVisibility, boolean allowNullAnnotation)
214    {
215  13 assertNotNull("Original alignment was null", al);
216  13 assertNotNull("Generated alignment was null", al_input);
217   
218  13 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  13 AlignmentAnnotation[] aa_new = al_input.getAlignmentAnnotation();
226  13 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  13 int aa_new_size = (aa_new == null ? 0 : aa_new.length);
232  13 int aa_original_size = (aa_original == null ? 0 : aa_original.length);
233  13 Map<Integer, BitSet> orig_groups = new HashMap<Integer, BitSet>();
234  13 Map<Integer, BitSet> new_groups = new HashMap<Integer, BitSet>();
235   
236  13 if (aa_new != null && aa_original != null)
237    {
238  173 for (int i = 0; i < aa_original.length; i++)
239    {
240  163 if (aa_new.length > i)
241    {
242  163 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  163 assertEquals("Graph type not identical.", aa_original[i].graph,
247    aa_new[i].graph);
248  163 if (!ignoreRowVisibility)
249    {
250  158 assertEquals("Visibility not identical.",
251    aa_original[i].visible,
252    aa_new[i].visible);
253    }
254  163 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  163 Integer o_ggrp = new Integer(aa_original[i].graphGroup + 2);
258  163 Integer n_ggrp = new Integer(aa_new[i].graphGroup + 2);
259  163 BitSet orig_g = orig_groups.get(o_ggrp);
260  163 BitSet new_g = new_groups.get(n_ggrp);
261  163 if (orig_g == null)
262    {
263  43 orig_groups.put(o_ggrp, orig_g = new BitSet());
264    }
265  163 if (new_g == null)
266    {
267  43 new_groups.put(n_ggrp, new_g = new BitSet());
268    }
269  163 assertEquals("Graph Group pattern differs at annotation " + i,
270    orig_g, new_g);
271  163 orig_g.set(i);
272  163 new_g.set(i);
273    }
274    else
275    {
276  0 System.err.println("No matching annotation row for "
277    + aa_original[i].toString());
278    }
279    }
280    }
281  13 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  13 SequenceI[] seq_original = new SequenceI[al.getSequencesArray().length];
287  13 seq_original = al.getSequencesArray();
288  13 SequenceI[] seq_new = new SequenceI[al_input.getSequencesArray().length];
289  13 seq_new = al_input.getSequencesArray();
290  13 List<SequenceFeature> sequenceFeatures_original;
291  13 List<SequenceFeature> sequenceFeatures_new;
292  13 AlignmentAnnotation annot_original, annot_new;
293    //
294  380 for (int i = 0; i < al.getSequencesArray().length; i++)
295    {
296  367 String name = seq_original[i].getName();
297  367 int start = seq_original[i].getStart();
298  367 int end = seq_original[i].getEnd();
299  367 System.out.println("Check sequence: " + name + "/" + start + "-"
300    + end);
301   
302    // search equal sequence
303  23928 for (int in = 0; in < al_input.getSequencesArray().length; in++)
304    {
305  23928 if (name.equals(seq_new[in].getName())
306    && start == seq_new[in].getStart()
307    && end == seq_new[in].getEnd())
308    {
309  367 String ss_original = seq_original[i].getSequenceAsString();
310  367 String ss_new = seq_new[in].getSequenceAsString();
311  367 assertEquals("The sequences " + name + "/" + start + "-" + end
312    + " are not equal", ss_original, ss_new);
313   
314  367 assertTrue(
315    "Sequence Features were not equivalent"
316  367 + (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  367 if (seq_original[i].getSequenceFeatures() != null
324    && seq_new[in].getSequenceFeatures() != null)
325    {
326  367 System.out.println("There are feature!!!");
327  367 sequenceFeatures_original = seq_original[i]
328    .getSequenceFeatures();
329  367 sequenceFeatures_new = seq_new[in].getSequenceFeatures();
330   
331  367 assertEquals("different number of features", seq_original[i]
332    .getSequenceFeatures().size(), seq_new[in]
333    .getSequenceFeatures().size());
334   
335  367 for (int feat = 0; feat < seq_original[i].getSequenceFeatures()
336    .size(); feat++)
337    {
338  0 assertEquals("Different features",
339    sequenceFeatures_original.get(feat),
340    sequenceFeatures_new.get(feat));
341    }
342    }
343    // compare alignment annotation
344  367 if (al.getSequenceAt(i).getAnnotation() != null
345    && al_input.getSequenceAt(in).getAnnotation() != null)
346    {
347  264 for (int j = 0; j < al.getSequenceAt(i).getAnnotation().length; j++)
348    {
349  153 if (al.getSequenceAt(i).getAnnotation()[j] != null
350    && al_input.getSequenceAt(in).getAnnotation()[j] != null)
351    {
352  153 annot_original = al.getSequenceAt(i).getAnnotation()[j];
353  153 annot_new = al_input.getSequenceAt(in).getAnnotation()[j];
354  153 assertEqualSecondaryStructure(
355    "Different annotation elements", annot_original,
356    annot_new, allowNullAnnotation);
357    }
358    }
359    }
360  256 else if (al.getSequenceAt(i).getAnnotation() == null
361    && al_input.getSequenceAt(in).getAnnotation() == null)
362    {
363  256 System.out.println("No annotations");
364    }
365  0 else if (al.getSequenceAt(i).getAnnotation() != null
366    && al_input.getSequenceAt(in).getAnnotation() == null)
367    {
368  0 fail("Annotations differed between sequences ("
369    + al.getSequenceAt(i).getName() + ") and ("
370    + al_input.getSequenceAt(i).getName() + ")");
371    }
372  367 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  366 toggle 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  366 if (annot_or.annotations.length != annot_new.annotations.length)
402    {
403  0 fail("Different lengths for annotation row elements: "
404    + annot_or.annotations.length + "!="
405    + annot_new.annotations.length);
406    }
407  366 boolean isRna = annot_or.isRNA();
408  366 assertTrue("Expected " + (isRna ? " valid RNA " : " no RNA ")
409    + " secondary structure in the row.",
410    isRna == annot_new.isRNA());
411  40796 for (int i = 0; i < annot_or.annotations.length; i++)
412    {
413  40458 Annotation an_or = annot_or.annotations[i], an_new = annot_new.annotations[i];
414  40458 if (an_or != null && an_new != null)
415    {
416   
417  28788 if (isRna)
418    {
419  9141 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  0 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  19647 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  12 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  11670 else if (annot_or.annotations[i] == null
453    && annot_new.annotations[i] == null)
454    {
455  11602 continue;
456    }
457    else
458    {
459  68 if (allowNullEqivalence)
460    {
461  65 if (an_or != null && an_or.isWhitespace())
462   
463    {
464  0 continue;
465    }
466  65 if (an_new != null && an_new.isWhitespace())
467    {
468  62 continue;
469    }
470    }
471    // need also to test for null in one, non-SS annotation in other...
472  6 fail("Annotation Element Mismatch\nElement " + i + " in original: "
473  6 + (an_or == null ? "is null" : an_or.toString())
474    + "\nElement " + i + " in new: "
475  6 + (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  28 toggle public static void assertNotEqualSecondaryStructure(String message,
489    AlignmentAnnotation an_orig, AlignmentAnnotation an_new,
490    boolean allowNullEquivalence)
491    {
492  28 boolean thrown = false;
493  28 try
494    {
495  28 assertEqualSecondaryStructure("", an_orig, an_new,
496    allowNullEquivalence);
497    } catch (AssertionError af)
498    {
499  28 thrown = true;
500    }
501  28 if (!thrown)
502    {
503  0 fail("Expected difference for [" + an_orig + "] and [" + an_new + "]");
504    }
505    }
 
506  26 toggle private AlignmentAnnotation makeAnnot(Annotation ae)
507    {
508  26 return new AlignmentAnnotation("label", "description", new Annotation[]
509    { ae });
510    }
511   
 
512  1 toggle @Test(groups={"Functional"})
513    public void testAnnotationEquivalence()
514    {
515  1 AlignmentAnnotation one = makeAnnot(new Annotation("", "", ' ', 1));
516  1 AlignmentAnnotation anotherOne = makeAnnot(new Annotation("", "", ' ',
517    1));
518  1 AlignmentAnnotation sheet = makeAnnot(new Annotation("","",'E',0f));
519  1 AlignmentAnnotation anotherSheet = makeAnnot(new Annotation("","",'E',0f));
520  1 AlignmentAnnotation sheetWithLabel = makeAnnot(new Annotation("1", "",
521    'E', 0f));
522  1 AlignmentAnnotation anotherSheetWithLabel = makeAnnot(new Annotation(
523    "1", "", 'E', 0f));
524  1 AlignmentAnnotation rnaNoDC = makeAnnot(new Annotation("","",'<',0f));
525  1 AlignmentAnnotation anotherRnaNoDC = makeAnnot(new Annotation("","",'<',0f));
526  1 AlignmentAnnotation rnaWithDC = makeAnnot(new Annotation("B", "", '<',
527    0f));
528  1 AlignmentAnnotation anotherRnaWithDC = makeAnnot(new Annotation("B",
529    "", '<', 0f));
530   
531    // check self equivalence
532  1 for (boolean allowNull : new boolean[] { true, false })
533    {
534  2 assertEqualSecondaryStructure("Should be equal", one, anotherOne,
535    allowNull);
536  2 assertEqualSecondaryStructure("Should be equal", sheet, anotherSheet,
537    allowNull);
538  2 assertEqualSecondaryStructure("Should be equal", sheetWithLabel,
539    anotherSheetWithLabel, allowNull);
540  2 assertEqualSecondaryStructure("Should be equal", rnaNoDC,
541    anotherRnaNoDC, allowNull);
542  2 assertEqualSecondaryStructure("Should be equal", rnaWithDC,
543    anotherRnaWithDC, allowNull);
544    // display character doesn't matter for RNA structure (for 2.10.2)
545  2 assertEqualSecondaryStructure("Should be equal", rnaWithDC, rnaNoDC,
546    allowNull);
547  2 assertEqualSecondaryStructure("Should be equal", rnaNoDC, rnaWithDC,
548    allowNull);
549    }
550   
551    // verify others are different
552  1 List<AlignmentAnnotation> aaSet = Arrays.asList(one, sheet,
553    sheetWithLabel, rnaWithDC);
554  5 for (int p = 0; p < aaSet.size(); p++)
555    {
556  20 for (int q = 0; q < aaSet.size(); q++)
557    {
558  16 if (p != q)
559    {
560  12 assertNotEqualSecondaryStructure("Should be different",
561    aaSet.get(p), aaSet.get(q), false);
562    }
563    else
564    {
565  4 assertEqualSecondaryStructure("Should be same", aaSet.get(p),
566    aaSet.get(q), false);
567  4 assertEqualSecondaryStructure("Should be same", aaSet.get(p),
568    aaSet.get(q), true);
569  4 assertNotEqualSecondaryStructure(
570    "Should be different to empty anot", aaSet.get(p),
571    makeAnnot(Annotation.EMPTY_ANNOTATION), false);
572  4 assertNotEqualSecondaryStructure(
573    "Should be different to empty annot",
574    makeAnnot(Annotation.EMPTY_ANNOTATION), aaSet.get(q),
575    true);
576  4 assertNotEqualSecondaryStructure("Should be different to null",
577    aaSet.get(p), makeAnnot(null), false);
578  4 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  1 toggle @Test(groups = { "Functional" })
604    public void secondaryStructureForRNASequence() throws Exception
605    {
606  1 roundTripSSForRNA(aliFile, annFile);
607    }
608   
 
609  1 toggle @Test(groups = { "Functional" })
610    public void curlyWUSSsecondaryStructureForRNASequence() throws Exception
611    {
612  1 roundTripSSForRNA(aliFile, annFileCurlyWuss);
613    }
614   
 
615  1 toggle @Test(groups = { "Functional" })
616    public void fullWUSSsecondaryStructureForRNASequence() throws Exception
617    {
618  1 roundTripSSForRNA(aliFile, annFileFullWuss);
619    }
620   
 
621  1 toggle @Test(groups = { "Functional" })
622    public void detectWussBrackets()
623    {
624  1 for (char ch : new char[] { '{', '}', '[', ']', '(', ')', '<', '>' })
625    {
626  8 Assert.assertTrue(StockholmFile.DETECT_BRACKETS.matchAt("" + ch, 0),
627    "Didn't recognise " + ch + " as a WUSS bracket");
628    }
629  1 for (char ch : new char[] { '@', '!', 'V', 'Q', '*', ' ', '-', '.' })
630    {
631  8 Assert.assertFalse(StockholmFile.DETECT_BRACKETS.matchAt("" + ch, 0),
632    "Shouldn't recognise " + ch + " as a WUSS bracket");
633    }
634    }
 
635  3 toggle private static void roundTripSSForRNA(String aliFile, String annFile)
636    throws Exception
637    {
638  3 AlignmentI al = new AppletFormatAdapter().readFile(aliFile,
639    DataSourceType.PASTE, jalview.io.FileFormat.Fasta);
640  3 AnnotationFile aaf = new AnnotationFile();
641  3 aaf.readAnnotationFile(al, annFile, DataSourceType.PASTE);
642  3 al.getAlignmentAnnotation()[0].visible = true;
643   
644    // TODO: create a better 'save as <format>' pattern
645  3 StockholmFile sf = new StockholmFile(al);
646   
647  3 String stockholmFile = sf.print(al.getSequencesArray(), true);
648   
649  3 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  3 testAlignmentEquivalence(al, newAl, true, true, true);
655   
656    }
657    }