JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / util / Comparison.java
index e224b71..c491be4 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -22,6 +22,9 @@ package jalview.util;
 
 import jalview.datamodel.SequenceI;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * Assorted methods for analysing or comparing sequences.
  */
@@ -37,8 +40,8 @@ public class Comparison
 
   private static final char GAP_DASH = '-';
 
-  public static final String GapChars = new String(new char[]
-  { GAP_SPACE, GAP_DOT, GAP_DASH });
+  public static final String GapChars = new String(new char[] { GAP_SPACE,
+      GAP_DOT, GAP_DASH });
 
   /**
    * DOCUMENT ME!
@@ -248,7 +251,7 @@ public class Comparison
   /**
    * 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 animo acid codes).
+   * wrong answer (as AGCT are also amino acid codes).
    * 
    * @param seqs
    * @return
@@ -263,6 +266,12 @@ public class Comparison
     int aaCount = 0;
     for (SequenceI seq : seqs)
     {
+      if (seq == null)
+      {
+        continue;
+      }
+      // TODO could possibly make an informed guess just from the first sequence
+      // to save a lengthy calculation
       for (char c : seq.getSequence())
       {
         if ('a' <= c && c <= 'z')
@@ -295,4 +304,29 @@ public class Comparison
     }
 
   }
+
+  /**
+   * Convenience overload of isNucleotide
+   * 
+   * @param seqs
+   * @return
+   */
+  public static boolean isNucleotide(SequenceI[][] seqs)
+  {
+    if (seqs == null)
+    {
+      return false;
+    }
+    List<SequenceI> flattened = new ArrayList<SequenceI>();
+    for (SequenceI[] ss : seqs)
+    {
+      for (SequenceI s : ss)
+      {
+        flattened.add(s);
+      }
+    }
+    final SequenceI[] oneDArray = flattened.toArray(new SequenceI[flattened
+            .size()]);
+    return isNucleotide(oneDArray);
+  }
 }