JAL-653 realise virtual mappings and align when adding sequences
[jalview.git] / src / jalview / gui / AlignViewport.java
index 9ee88db..06dc4c4 100644 (file)
@@ -72,7 +72,6 @@ import java.awt.Rectangle;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
-import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.JInternalFrame;
@@ -461,7 +460,7 @@ public class AlignViewport extends AlignmentViewport implements
     AlignmentI al = getAlignment();
     if (al != null)
     {
-      Set<AlignedCodonFrame> mappings = al.getCodonFrames();
+      List<AlignedCodonFrame> mappings = al.getCodonFrames();
       if (mappings != null)
       {
         StructureSelectionManager ssm = StructureSelectionManager
@@ -855,7 +854,7 @@ public class AlignViewport extends AlignmentViewport implements
      * Check if any added sequence could be the object of a mapping or
      * cross-reference; if so, make the mapping explicit 
      */
-    realiseMappings(getAlignment(), toAdd);
+    getAlignment().realiseMappings(toAdd.getSequences());
 
     /*
      * If any cDNA/protein mappings exist or can be made between the alignments, 
@@ -878,60 +877,26 @@ public class AlignViewport extends AlignmentViewport implements
     // TODO: JAL-407 regardless of above - identical sequences (based on ID and
     // provenance) should share the same dataset sequence
 
+    AlignmentI al = getAlignment();
+    String gap = String.valueOf(al.getGapCharacter());
     for (int i = 0; i < toAdd.getHeight(); i++)
     {
-      getAlignment().addSequence(toAdd.getSequenceAt(i));
-    }
-
-    setEndSeq(getAlignment().getHeight());
-    firePropertyChange("alignment", null, getAlignment().getSequences());
-  }
-
-  /**
-   * Check if any added sequence could be the object of a mapping or
-   * cross-reference; if so, make the mapping explicit. Returns the count of
-   * mappings updated.
-   * 
-   * @param al
-   * @param toAdd
-   */
-  protected int realiseMappings(AlignmentI al, AlignmentI toAdd)
-  {
-    // TODO this is proof of concept
-    // we might want to give the user some choice here
-    int count = 0;
-    for (SequenceI seq : toAdd.getSequences())
-    {
-      count += realiseMappingsTo(al, seq);
-    }
-    return count;
-  }
-
-  /**
-   * If the alignment holds any mappings to a virtual (placeholder) sequence
-   * that matches all or part of the given sequence, then update the mapping to
-   * point to the sequence. Returns the number of mappings updated.
-   * 
-   * @param al
-   * @param seq
-   * @return
-   */
-  protected int realiseMappingsTo(AlignmentI al, SequenceI seq)
-  {
-    int count = 0;
-    Set<AlignedCodonFrame> mappings = al.getCodonFrames();
-    for (AlignedCodonFrame mapping : mappings)
-    {
+      SequenceI seq = toAdd.getSequenceAt(i);
       /*
-       * TODO could just go straight to realiseWith() here unless we want
-       * to give the user some choice before going ahead
+       * experimental!
+       * - 'align' any mapped sequences as per existing 
+       *    e.g. cdna to genome, domain hit to protein sequence
+       * very experimental! (need a separate menu option for this)
+       * - only add mapped sequences ('select targets from a dataset')
        */
-      if (mapping.isRealisableWith(seq))
+      if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
       {
-        count += mapping.realiseWith(seq);
+        al.addSequence(seq);
       }
     }
-    return count;
+
+    setEndSeq(getAlignment().getHeight());
+    firePropertyChange("alignment", null, getAlignment().getSequences());
   }
 
   /**