JAL-1778 reinstated this.ssm to handle 'close all windows' robustly
[jalview.git] / test / jalview / datamodel / AlignmentAnnotationTests.java
index 7df6255..7c1aa81 100644 (file)
@@ -1,21 +1,28 @@
 package jalview.datamodel;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
-import java.awt.Frame;
-
-import javax.swing.JFrame;
-import javax.swing.SwingWorker;
+import org.junit.Test;
 
 import jalview.analysis.AlignSeq;
-import jalview.gui.AlignFrame;
 import jalview.io.AppletFormatAdapter;
-import jalview.io.FormatAdapter;
-
-import org.junit.Test;
 
 public class AlignmentAnnotationTests
 {
+  @Test
+  public void testCopyConstructor()
+  {
+    SequenceI sq = new Sequence("Foo", "ARAARARARAWEAWEAWRAWEAWE");
+    createAnnotation(sq);
+    AlignmentAnnotation alc, alo = sq.getAnnotation()[0];
+    alc = new AlignmentAnnotation(alo);
+    for (String key : alo.getProperties())
+    {
+      assertEquals("Property mismatch", alo.getProperty(key),
+              alc.getProperty(key));
+    }
+  }
   /**
    * create some dummy annotation derived from the sequence
    * 
@@ -27,12 +34,13 @@ public class AlignmentAnnotationTests
     for (int i = 0; i < al.length; i++)
     {
       al[i] = new Annotation(new Annotation("" + sq.getCharAt(i), "",
-              (char) 0, (float) sq.findPosition(i)));
+              (char) 0, sq.findPosition(i)));
     }
     AlignmentAnnotation alan = new AlignmentAnnotation("For "
             + sq.getName(), "Fake alignment annot", al);
     // create a sequence mapping for the annotation vector in its current state
     alan.createSequenceMapping(sq, sq.getStart(), false);
+    alan.setProperty("CreatedBy", "createAnnotation");
     sq.addAlignmentAnnotation(alan);
   }
 
@@ -147,7 +155,48 @@ public class AlignmentAnnotationTests
                       : "Out of range");
       assertEquals("Position " + p + " " + alm1 + " " + alm2, alm1, alm2);
     }
-    // new jalview.io.FormatAdapter().formatSequences("STOCKHOLM", n)
   }
 
+  @Test
+  public void testAdjustForAlignment()
+  {
+    SequenceI seq = new Sequence("TestSeq", "ABCDEFG");
+    seq.createDatasetSequence();
+
+    /*
+     * Annotate positions 3/4/5 (CDE) with values 1/2/3
+     */
+    Annotation[] anns = new Annotation[]
+    { null, null, new Annotation(1), new Annotation(2), new Annotation(3) };
+    AlignmentAnnotation ann = new AlignmentAnnotation("SS",
+            "secondary structure", anns);
+    seq.addAlignmentAnnotation(ann);
+
+    /*
+     * Check annotation map before modifying aligned sequence
+     */
+    assertNull(ann.getAnnotationForPosition(1));
+    assertNull(ann.getAnnotationForPosition(2));
+    assertNull(ann.getAnnotationForPosition(6));
+    assertNull(ann.getAnnotationForPosition(7));
+    assertEquals(1, ann.getAnnotationForPosition(3).value, 0.001d);
+    assertEquals(2, ann.getAnnotationForPosition(4).value, 0.001d);
+    assertEquals(3, ann.getAnnotationForPosition(5).value, 0.001d);
+
+    /*
+     * Trim the displayed sequence to BCD and adjust annotations
+     */
+    seq.setSequence("BCD");
+    seq.setStart(2);
+    seq.setEnd(4);
+    ann.adjustForAlignment();
+
+    /*
+     * Should now have annotations for aligned positions 2, 3Q (CD) only
+     */
+    assertEquals(3, ann.annotations.length);
+    assertNull(ann.annotations[0]);
+    assertEquals(1, ann.annotations[1].value, 0.001);
+    assertEquals(2, ann.annotations[2].value, 0.001);
+  }
 }