JAL-674 test for the test for presence of annotation derived from particular PDB...
[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.datamodel.SequenceI;
9 import jalview.gui.AlignFrame;
10
11 import org.junit.Before;
12 import org.junit.Test;
13
14 public class AnnotatedPDBFileInputTest
15 {
16
17   AlignmentI al;
18
19   String pdbStr = "examples/2GIS.pdb";
20   @Before
21   public void setup() throws Exception
22   {
23     FileLoader loader = new FileLoader(false);
24     AlignFrame af = loader.LoadFileWaitTillLoaded(pdbStr,
25             FormatAdapter.FILE);
26     al = af.getViewport().getAlignment();
27   }
28
29   @Test
30   public void checkNoDuplicates()
31   {
32     // not strictly a requirement, but strange things may happen if multiple
33     // instances of the same annotation are placed in the alignment annotation
34     // vector
35     assertNotNull(al.getAlignmentAnnotation());
36     // verify that all sequence annotation is doubly referenced
37     AlignmentAnnotation[] avec = al.getAlignmentAnnotation();
38     for (int p = 0; p < avec.length; p++)
39     {
40       for (int q = p + 1; q < avec.length; q++)
41       {
42         assertNotEquals(
43                 "Found a duplicate annotation row " + avec[p].label,
44                 avec[p], avec[q]);
45       }
46     }
47   }
48
49   @Test
50   public void checkPDBannotationSource()
51   {
52
53     for (SequenceI asq : al.getSequences())
54     {
55       for (AlignmentAnnotation aa : asq.getAnnotation())
56       {
57
58         System.out.println("CalcId: " + aa.getCalcId());
59         assertTrue(MCview.PDBfile.isCalcIdForFile(aa.getCalcId(), pdbStr));
60       }
61     }
62   }
63
64   @Test
65   public void checkAnnotationWiring()
66   {
67     assertTrue(al.getAlignmentAnnotation() != null);
68     // verify that all sequence annotation is doubly referenced
69     for (AlignmentAnnotation aa : al.getAlignmentAnnotation())
70     {
71       if (aa.sequenceRef != null)
72       {
73         assertTrue(al.getSequences().contains(aa.sequenceRef));
74         assertNotNull(aa.sequenceRef.getAnnotation());
75         boolean found = false;
76         for (AlignmentAnnotation sqan : aa.sequenceRef.getAnnotation())
77         {
78           if (sqan == aa)
79           {
80             found = true;
81             break;
82           }
83         }
84         assertTrue(
85                 "Couldn't find sequence associated annotation "
86                         + aa.label
87                         + " on the sequence it is associated with.\nSequence associated editing will fail.",
88                 found);
89       }
90     }
91   }
92 }