JAL-1645 source formatting and organise imports
[jalview.git] / src / jalview / util / MappingUtils.java
index 4aed258..adfd397 100644 (file)
@@ -1,13 +1,5 @@
 package jalview.util;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import jalview.analysis.AlignmentSorter;
 import jalview.api.AlignViewportI;
 import jalview.commands.CommandI;
@@ -25,6 +17,14 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * Helper methods for manipulations involving sequence mappings.
  * 
@@ -200,8 +200,8 @@ public final class MappingUtils
              */
             int mappedEditPos = action == Action.DELETE_GAP ? match[0]
                     - mappedCount : match[0];
-            Edit e = result.new Edit(action, new SequenceI[]
-            { targetSeq }, mappedEditPos, mappedCount, gapChar);
+            Edit e = result.new Edit(action, new SequenceI[] { targetSeq },
+                    mappedEditPos, mappedCount, gapChar);
             result.addEdit(e);
 
             /*
@@ -339,7 +339,7 @@ public final class MappingUtils
        */
       int startResiduePos = selected.findPosition(firstUngappedPos);
       int endResiduePos = selected.findPosition(lastUngappedPos);
-      
+
       for (AlignedCodonFrame acf : codonFrames)
       {
         SequenceI mappedSequence = targetIsNucleotide ? acf
@@ -413,18 +413,19 @@ public final class MappingUtils
     SequenceI[] sortOrder = command.getSequenceOrder(undo);
     List<SequenceI> mappedOrder = new ArrayList<SequenceI>();
     int j = 0;
+
+    /*
+     * Assumption: we are only interested in a cDNA/protein mapping; refactor in
+     * future if we want to support sorting (c)dna as (c)dna or protein as
+     * protein
+     */
+    boolean mappingToNucleotide = mapTo.isNucleotide();
     for (SequenceI seq : sortOrder)
     {
       for (AlignedCodonFrame acf : mappings)
       {
-        /*
-         * Try protein-to-Dna, failing that try dna-to-protein
-         */
-        SequenceI mappedSeq = acf.getDnaForAaSeq(seq);
-        if (mappedSeq == null)
-        {
-          mappedSeq = acf.getAaForDnaSeq(seq);
-        }
+        SequenceI mappedSeq = mappingToNucleotide ? acf.getDnaForAaSeq(seq)
+                : acf.getAaForDnaSeq(seq);
         if (mappedSeq != null)
         {
           for (SequenceI seq2 : mapTo.getSequences())
@@ -494,6 +495,12 @@ public final class MappingUtils
     Set<AlignedCodonFrame> codonFrames = protein.getAlignment()
             .getCodonFrames();
     ColumnSelection mappedColumns = new ColumnSelection();
+
+    if (colsel == null)
+    {
+      return mappedColumns;
+    }
+
     char fromGapChar = mapFrom.getAlignment().getGapCharacter();
 
     // FIXME allow for hidden columns
@@ -639,8 +646,10 @@ public final class MappingUtils
     {
       return result;
     }
-    for (AlignedCodonFrame mapping : mappings) {
-      if (mapping.involvesSequence(sequence)) {
+    for (AlignedCodonFrame mapping : mappings)
+    {
+      if (mapping.involvesSequence(sequence))
+      {
         result.add(mapping);
       }
     }