JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / src / jalview / analysis / AAFrequency.java
index 50045dc..fb49541 100755 (executable)
@@ -32,7 +32,6 @@ import jalview.util.QuickSort;
 import java.util.Arrays;
 import java.util.Hashtable;
 import java.util.List;
-import java.util.Set;
 
 /**
  * Takes in a vector or array of sequences and column start and column end and
@@ -198,9 +197,8 @@ public class AAFrequency
       if (profile)
       {
         // TODO use a 1-dimensional array with jSize, nongap in [0] and [1]
-        residueHash.put(PROFILE, new int[][]
-        { values, new int[]
-        { jSize, nongap } });
+        residueHash.put(PROFILE, new int[][] { values,
+            new int[] { jSize, nongap } });
       }
       residueHash.put(MAXCOUNT, new Integer(maxCount));
       residueHash.put(MAXRESIDUE, maxResidue);
@@ -369,8 +367,7 @@ public class AAFrequency
                 .append("%");
       }
       consensus.annotations[i] = new Annotation(maxRes,
-              mouseOver.toString(), ' ',
-              value);
+              mouseOver.toString(), ' ', value);
     }
   }
 
@@ -462,7 +459,8 @@ public class AAFrequency
    * @param hashtable
    * @return
    */
-  public static int[] extractCdnaProfile(Hashtable hashtable, boolean ignoreGaps)
+  public static int[] extractCdnaProfile(Hashtable hashtable,
+          boolean ignoreGaps)
   {
     // this holds #seqs, #ungapped, and then codon count, indexed by encoded
     // codon triplet
@@ -507,7 +505,7 @@ public class AAFrequency
     result[1] = distinctValuesCount;
     return Arrays.copyOfRange(result, 0, j);
   }
-    
+
   /**
    * Compute a consensus for the cDNA coding for a protein alignment.
    * 
@@ -521,7 +519,7 @@ public class AAFrequency
           Hashtable[] hconsensus)
   {
     final char gapCharacter = alignment.getGapCharacter();
-    Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
+    List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
     if (mappings == null || mappings.isEmpty())
     {
       return;
@@ -542,12 +540,16 @@ public class AAFrequency
         {
           continue;
         }
-        char[] codon = MappingUtils.findCodonFor(seq, col, mappings);
-        int codonEncoded = CodingUtils.encodeCodon(codon);
-        if (codonEncoded >= 0)
+        List<char[]> codons = MappingUtils
+                .findCodonsFor(seq, col, mappings);
+        for (char[] codon : codons)
         {
-          codonCounts[codonEncoded + 2]++;
-          ungappedCount++;
+          int codonEncoded = CodingUtils.encodeCodon(codon);
+          if (codonEncoded >= 0)
+          {
+            codonCounts[codonEncoded + 2]++;
+            ungappedCount++;
+          }
         }
       }
       codonCounts[1] = ungappedCount;
@@ -622,8 +624,11 @@ public class AAFrequency
       String modalCodon = String.valueOf(CodingUtils
               .decodeCodon(modalCodonEncoded));
       if (sortedCodonCounts.length > 1
-              && sortedCodonCounts[codons.length - 2] == modalCodonEncoded)
+              && sortedCodonCounts[codons.length - 2] == sortedCodonCounts[codons.length - 1])
       {
+        /*
+         * two or more codons share the modal count
+         */
         modalCodon = "+";
       }
       float pid = sortedCodonCounts[sortedCodonCounts.length - 1] * 100
@@ -664,8 +669,7 @@ public class AAFrequency
         final int pct = codonCount * 100 / totalCount;
         String codon = String
                 .valueOf(CodingUtils.decodeCodon(codonEncoded));
-        percent = fmt == null ? Integer.toString(pct) : fmt
-                .form(pct);
+        percent = fmt == null ? Integer.toString(pct) : fmt.form(pct);
         if (showProfileLogo || codonCount == modalCodonCount)
         {
           if (percent.equals(lastPercent) && j > 0)
@@ -678,8 +682,7 @@ public class AAFrequency
             if (samePercent.length() > 0)
             {
               mouseOver.append(samePercent).append(": ")
-                      .append(lastPercent)
-                      .append("% ");
+                      .append(lastPercent).append("% ");
             }
             samePercent.setLength(0);
             samePercent.append(codon);