JAL-674 test for duplicate alignment annotation rows on aligment
[jalview.git] / test / jalview / io / AnnotatedPDBFileInputTest.java
1 package jalview.io;
2
3 import static org.junit.Assert.assertNotEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.AlignmentI;
8 import jalview.gui.AlignFrame;
9
10 import org.junit.Before;
11 import org.junit.Test;
12
13 public class AnnotatedPDBFileInputTest
14 {
15
16   AlignmentI al;
17
18   @Before
19   public void setup() throws Exception
20   {
21     FileLoader loader = new FileLoader(false);
22     AlignFrame af = loader.LoadFileWaitTillLoaded("examples/1gaq.txt",
23             FormatAdapter.FILE);
24     al = af.getViewport().getAlignment();
25   }
26
27   @Test
28   public void checkNoDuplicates()
29   {
30     // not strictly a requirement, but strange things may happen if multiple
31     // instances of the same annotation are placed in the alignment annotation
32     // vector
33     assertNotNull(al.getAlignmentAnnotation());
34     // verify that all sequence annotation is doubly referenced
35     AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
36     for (int p = 0; p < avec.length; p++)
37     {
38       for (int q = p + 1; q < avec.length; q++)
39       {
40         assertNotEquals(
41                 "Found a duplicate annotation row " + avec[p].label,
42                 avec[p], avec[q]);
43       }
44     }
45   }
46
47   @Test
48   public void checkAnnotationWiring()
49   {
50     assertTrue(al.getAlignmentAnnotation() != null);
51     // verify that all sequence annotation is doubly referenced
52     for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
53     {
54       if (aa.sequenceRef != null)
55       {
56         assertTrue(al.getSequences().contains(aa.sequenceRef));
57         assertNotNull(aa.sequenceRef.getAnnotation());
58         boolean found = false;
59         for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
60         {
61           if (sqan == aa)
62           {
63             found = true;
64             break;
65           }
66         }
67         assertTrue(
68                 "Couldn't find sequence associated annotation "
69                         + aa.label
70                         + " on the sequence it is associated with.\nSequence associated editing will fail.",
71                 found);
72       }
73     }
74   }
75 }