JAL-2110 use shared alignment dataset when copying alignment for split
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 4 Jul 2016 14:21:49 +0000 (15:21 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 4 Jul 2016 14:21:49 +0000 (15:21 +0100)
frame

src/jalview/analysis/AlignmentUtils.java
src/jalview/gui/AlignFrame.java
test/jalview/analysis/AlignmentUtilsTests.java
test/jalview/datamodel/SequenceTest.java

index 9150d62..033f7e5 100644 (file)
@@ -2211,32 +2211,15 @@ public class AlignmentUtils
    * 
    * @param seqs
    * @param xrefs
+   * @param dataset
+   *          alignment dataset shared by the new copy
    * @return
    */
   public static AlignmentI makeCopyAlignment(SequenceI[] seqs,
-          SequenceI[] xrefs)
+          SequenceI[] xrefs, AlignmentI dataset)
   {
     AlignmentI copy = new Alignment(new Alignment(seqs));
-
-    /*
-     * add mappings between sequences to the new alignment
-     */
-    AlignedCodonFrame mappings = new AlignedCodonFrame();
-    copy.addCodonFrame(mappings);
-    for (int i = 0; i < copy.getHeight(); i++)
-    {
-      SequenceI from = seqs[i];
-      SequenceI to = copy.getSequenceAt(i);
-      if (to.getDatasetSequence() != null)
-      {
-        to = to.getDatasetSequence();
-      }
-      int start = from.getStart();
-      int end = from.getEnd();
-      MapList map = new MapList(new int[] { start, end }, new int[] {
-          start, end }, 1, 1);
-      mappings.addMap(to, from, map);
-    }
+    copy.setDataset(dataset);
 
     SequenceIdMatcher matcher = new SequenceIdMatcher(seqs);
     if (xrefs != null)
index b310ab9..15b1fb4 100644 (file)
@@ -4787,8 +4787,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           else
           {
+            /*
+             * copy peptide sequences, and add in any alternate products
+             * of their located coding xrefs
+             */
             copyAlignment = AlignmentUtils.makeCopyAlignment(
-                    sequenceSelection, xrefs.getSequencesArray());
+                    sequenceSelection, xrefs.getSequencesArray(), dataset);
           }
           copyAlignment.setGapCharacter(AlignFrame.this.viewport
                   .getGapCharacter());
index d704ec6..9394385 100644 (file)
@@ -1015,13 +1015,19 @@ public class AlignmentUtilsTests
             .contains(cds.getSequenceAt(1).getDatasetSequence()));
 
     /*
-     * Verify mappings from CDS to peptide, cDNA to CDS, and cDNA to peptide
-     * the mappings are on the shared alignment dataset
+     * verify cds has dbref with mapping to protein and vice versa
      */
-    List<AlignedCodonFrame> cdsMappings = cds.getDataset().getCodonFrames();
+    DBRefEntry[] cdsDbrefs = cds.getSequenceAt(0).getDBRefs();
+    // assertNotNull(cdsDbrefs);
+    // assertEquals(1, cdsDbrefs.length);
+    // assertNotNull(cdsDbrefs[0].getMap());
+
     /*
+     * Verify mappings from CDS to peptide, cDNA to CDS, and cDNA to peptide
+     * the mappings are on the shared alignment dataset
      * 6 mappings, 2*(DNA->CDS), 2*(DNA->Pep), 2*(CDS->Pep) 
      */
+    List<AlignedCodonFrame> cdsMappings = cds.getDataset().getCodonFrames();
     assertEquals(6, cdsMappings.size());
 
     /*
index 5c5c5c3..eb32e5d 100644 (file)
@@ -78,7 +78,18 @@ public class SequenceTest
     // change sequence, should trigger an update of cached result
     sq.setSequence("ASDFASDFADSF");
     assertTrue(sq.isProtein());
+
+    /*
+     * in situ change of sequence doesn't change hashcode :-O
+     * (sequence should not expose internal implementation)
+     */
+    for (int i = 0; i < sq.getSequence().length; i++)
+    {
+      sq.getSequence()[i] = "acgtu".charAt(i % 5);
+    }
+    assertTrue(sq.isProtein()); // but it isn't
   }
+
   @Test(groups = { "Functional" })
   public void testGetAnnotation()
   {