Revert "Merge branch 'bug/JAL-3806_mappingCoversSequence' into releases/Release_2_11_...
[jalview.git] / src / jalview / util / Comparison.java
index 17d3a70..286bfb2 100644 (file)
@@ -268,37 +268,38 @@ public class Comparison
    */
   public static final boolean isNucleotide(SequenceI seq)
   {
-    return isNucleotide(new SequenceI[] { seq });
-  }
-
-  /**
-   * Answers true if more than 85% of the sequence residues (ignoring gaps) are
-   * A, G, C, T or U, else false. This is just a heuristic guess and may give a
-   * wrong answer (as AGCT are also amino acid codes).
-   * 
-   * @param seqs
-   * @return
-   */
-  public static final boolean isNucleotide(SequenceI[] seqs)
-  {
-    if (seqs == null)
+    if (seq==null)
     {
       return false;
     }
-    char[][] letters = new char[seqs.length][];
-    for (int i = 0; i < seqs.length; i++)
+    long ntCount = 0;
+    long aaCount = 0;
+
+    int len = seq.getLength();
+    for (int i = 0; i < len; i++)
     {
-      if (seqs[i] != null)
+      char c = seq.getCharAt(i);
+      if (isNucleotide(c))
       {
-        char[] sequence = seqs[i].getSequence();
-        if (sequence != null)
-        {
-          letters[i] = sequence;
-        }
+        ntCount++;
+      }
+      else if (!isGap(c))
+      {
+        aaCount++;
       }
     }
-
-    return areNucleotide(letters);
+    /*
+     * Check for nucleotide count > 85% of total count (in a form that evades
+     * int / float conversion or divide by zero).
+     */
+    if (ntCount * 100 > EIGHTY_FIVE * (ntCount + aaCount))
+    {
+      return true;
+    }
+    else
+    {
+      return false;
+    }
   }
 
   /**
@@ -306,47 +307,32 @@ public class Comparison
    * A, G, C, T or U, else false. This is just a heuristic guess and may give a
    * wrong answer (as AGCT are also amino acid codes).
    * 
-   * @param letters
+   * @param seqs
    * @return
    */
-  static final boolean areNucleotide(char[][] letters)
+  public static final boolean isNucleotide(SequenceI[] seqs)
   {
-    int ntCount = 0;
-    int aaCount = 0;
-    for (char[] seq : letters)
+    if (seqs == null)
+    {
+      return false;
+    }
+    // true if we have seen a nucleotide sequence
+    boolean na=false;
+    for (SequenceI seq : seqs)
     {
       if (seq == null)
       {
         continue;
       }
+      na=true;
       // TODO could possibly make an informed guess just from the first sequence
       // to save a lengthy calculation
-      for (char c : seq)
-      {
-        if (isNucleotide(c))
-        {
-          ntCount++;
-        }
-        else if (!isGap(c))
-        {
-          aaCount++;
-        }
+      if (seq.isProtein()) {
+        // if even one looks like protein, the alignment is protein
+        return false;
       }
     }
-
-    /*
-     * Check for nucleotide count > 85% of total count (in a form that evades
-     * int / float conversion or divide by zero).
-     */
-    if (ntCount * 100 > EIGHTY_FIVE * (ntCount + aaCount))
-    {
-      return true;
-    }
-    else
-    {
-      return false;
-    }
-
+    return na;
   }
 
   /**