JAL-845 refactor / typo fix
[jalview.git] / src / jalview / util / MappingUtils.java
index 953bac1..9880ae7 100644 (file)
@@ -16,7 +16,6 @@ import jalview.datamodel.SearchResults.Match;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
-import jalview.gui.AlignViewport;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -285,9 +284,11 @@ public final class MappingUtils
             .getCodonFrames();
 
     /*
-     * Copy group name, colours, but not sequences
+     * Copy group name, name colours, but not sequences or sequence colour
+     * scheme
      */
     SequenceGroup mappedGroup = new SequenceGroup(sg);
+    mappedGroup.cs = mapTo.getGlobalColourScheme();
     mappedGroup.clear();
     // TODO set width of mapped group
 
@@ -384,8 +385,8 @@ public final class MappingUtils
     }
 
     /*
-     * Have to align the sequences before constructing the OrderCommand - which
-     * then realigns them?!?
+     * Have to sort the sequences before constructing the OrderCommand - which
+     * then resorts them?!?
      */
     final SequenceI[] mappedOrderArray = mappedOrder
             .toArray(new SequenceI[mappedOrder.size()]);
@@ -407,7 +408,7 @@ public final class MappingUtils
    * @return
    */
   public static ColumnSelection mapColumnSelection(ColumnSelection colsel,
-          AlignViewportI mapFrom, AlignViewport mapTo)
+          AlignViewportI mapFrom, AlignViewportI mapTo)
   {
     boolean targetIsNucleotide = mapTo.isNucleotide();
     AlignViewportI protein = targetIsNucleotide ? mapFrom : mapTo;
@@ -416,8 +417,15 @@ public final class MappingUtils
     ColumnSelection mappedColumns = new ColumnSelection();
     char fromGapChar = mapFrom.getAlignment().getGapCharacter();
 
-    for (int col : colsel.getSelected())
+    // FIXME allow for hidden columns
+
+    /*
+     * For each mapped column, find the range of columns that residues in that
+     * column map to.
+     */
+    for (Object obj : colsel.getSelected())
     {
+      int col = ((Integer) obj).intValue();
       int mappedToMin = Integer.MAX_VALUE;
       int mappedToMax = Integer.MIN_VALUE;
 
@@ -447,7 +455,8 @@ public final class MappingUtils
           SequenceI mappedSeq = m.getSequence();
 
           /*
-           * Locate the aligned sequence whose dataset is mappedSeq.
+           * Locate the aligned sequence whose dataset is mappedSeq. TODO a
+           * datamodel that can do this efficiently.
            */
           for (SequenceI toSeq : mapTo.getAlignment().getSequences())
           {
@@ -459,12 +468,16 @@ public final class MappingUtils
               mappedToMax = Math.max(mappedToMax, mappedEndCol);
               // System.out.println(fromSeq.getName() + " mapped to cols "
               // + mappedStartCol + ":" + mappedEndCol);
+              break;
+              // note: remove break if we ever want to map one to many sequences
             }
           }
         }
       }
       /*
-       * Add mapped columns to mapped selection (converting base 1 to base 0)
+       * Add the range of mapped columns to the mapped selection (converting
+       * base 1 to base 0). Note that this may include intron-only regions which
+       * lie between the start and end ranges of the selection.
        */
       for (int i = mappedToMin; i <= mappedToMax; i++)
       {