Merge branch 'develop' into spike/JAL-4047/JAL-4048_columns_in_sequenceID
[jalview.git] / test / jalview / datamodel / SequenceTest.java
index 0151a12..7bbb9f3 100644 (file)
@@ -1052,6 +1052,38 @@ public class SequenceTest
     assertEquals("ABCDEF",
             derived.getDatasetSequence().getSequenceAsString());
   }
+  
+  /**
+   * test that creating a copy of an existing sequence with dataset sequence and
+   * associated contact matrix yields annotation associated with the same
+   * contact matrix in the copy
+   */
+  @Test(groups= {"Functional"})
+  public void testCopyPasteStyleDerivesequence_withcontactMatrixAnn()
+  {
+    SequenceI seq1=new Sequence("seq1","ACDACDACD");
+    seq1.createDatasetSequence();
+    ContactMatrixI cm = new SeqDistanceContactMatrix(seq1.getLength());
+    // addContactList needs to return annotation addable to the sequence reference it was called from
+    AlignmentAnnotation aann = seq1.addContactList(cm);
+    assertTrue(aann.sequenceRef==seq1);
+    assertEquals(1,seq1.getAnnotation().length);
+    assertNotNull(seq1.getContactListFor(seq1.getAnnotation()[0], 1));
+    
+    SequenceI seq_derived=seq1.deriveSequence();
+    assertEquals(1,seq_derived.getAnnotation().length);
+    assertTrue(cm==seq_derived.getContactMatrixFor(seq_derived.getAnnotation()[0]));
+    assertNotNull(seq_derived.getContactListFor(seq_derived.getAnnotation()[0], 1));
+    
+    // copy paste actually uses the copy constructor .. so
+    
+    SequenceI seq_copied=new Sequence((Sequence)seq_derived);
+    assertEquals(1,seq_copied.getAnnotation().length);
+    assertTrue(cm==seq_copied.getContactMatrixFor(seq_copied.getAnnotation()[0]));
+    assertNotNull(seq_copied.getContactListFor(seq_copied.getAnnotation()[0], 1));
+    
+    
+  }
 
   @Test(groups = { "Functional" })
   public void testCopyConstructor_noDataset()
@@ -2283,8 +2315,16 @@ public class SequenceTest
   {
     Sequence origSeq = new Sequence("MYSEQ", "THISISASEQ");
     Sequence toSeq = new Sequence("MYSEQ", "THISISASEQ");
+    origSeq.setDescription("DESCRIPTION");
     origSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q12345", null, true));
+
+    toSeq.transferAnnotation(origSeq, null);
+    assertEquals("DESCRIPTION",toSeq.getDescription());
+    toSeq = new Sequence("MYSEQ", "THISISASEQ");
+    toSeq.setDescription("unchanged");
     toSeq.transferAnnotation(origSeq, null);
+    assertEquals("unchanged",toSeq.getDescription());
+    
     assertTrue(toSeq.getDBRefs().size() == 1);
 
     assertTrue(toSeq.getDBRefs().get(0).isCanonical());