removed Iterator usage.
[jalview.git] / src / jalview / util / Comparison.java
index 9e0aef6..67a668a 100755 (executable)
@@ -1,26 +1,25 @@
 /*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
-*/\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 package jalview.util;\r
 \r
 import jalview.datamodel.*;\r
 \r
-\r
 /**\r
  * DOCUMENT ME!\r
  *\r
@@ -30,7 +29,7 @@ import jalview.datamodel.*;
 public class Comparison\r
 {\r
   /** DOCUMENT ME!! */\r
-  public static String GapChars = " .-";\r
+  public static final String GapChars = " .-";\r
 \r
   /**\r
    * DOCUMENT ME!\r
@@ -40,7 +39,7 @@ public class Comparison
    *\r
    * @return DOCUMENT ME!\r
    */\r
-  public static float compare(SequenceI ii, SequenceI jj)\r
+  public static final float compare(SequenceI ii, SequenceI jj)\r
   {\r
     return Comparison.compare(ii, jj, 0, ii.getLength() - 1);\r
   }\r
@@ -55,8 +54,8 @@ public class Comparison
    */\r
   public static float compare(SequenceI ii, SequenceI jj, int start, int end)\r
   {\r
-    String si = ii.getSequence();\r
-    String sj = jj.getSequence();\r
+    String si = ii.getSequenceAsString();\r
+    String sj = jj.getSequenceAsString();\r
 \r
     int ilen = si.length() - 1;\r
     int jlen = sj.length() - 1;\r
@@ -116,21 +115,19 @@ public class Comparison
    * @param s2 SequenceI\r
    * @return float\r
    */\r
-  public final static float PID(SequenceI seq1, SequenceI seq2)\r
+  public final static float PID(String seq1, String seq2)\r
   {\r
-    return PID(seq1, seq2, 0, seq1.getLength());\r
+    return PID(seq1, seq2, 0, seq1.length());\r
   }\r
 \r
   static final int caseShift = 'a' - 'A';\r
 \r
   // Another pid with region specification\r
-  public final static  float PID(SequenceI seq1, SequenceI seq2, int start, int end)\r
+  public final static float PID(String seq1, String seq2, int start, int end)\r
   {\r
-    String s1 = seq1.getSequence();//.toUpperCase();\r
-    String s2 = seq2.getSequence();//.toUpperCase();\r
-    int s1len = s1.length();\r
-    int s2len = s2.length();\r
 \r
+    int s1len = seq1.length();\r
+    int s2len = seq2.length();\r
 \r
     int len = Math.min(s1len, s2len);\r
 \r
@@ -144,17 +141,15 @@ public class Comparison
       start = len - 1; // we just use a single residue for the difference\r
     }\r
 \r
-\r
     int bad = 0;\r
     char chr1;\r
     char chr2;\r
 \r
-\r
     for (int i = start; i < len; i++)\r
     {\r
-      chr1 =  s1.charAt(i) ;\r
+      chr1 = seq1.charAt(i);\r
 \r
-      chr2 =  s2.charAt(i) ;\r
+      chr2 = seq2.charAt(i);\r
 \r
       if ('a' <= chr1 && chr1 <= 'z')\r
       {\r
@@ -169,10 +164,9 @@ public class Comparison
         chr2 -= caseShift;\r
       }\r
 \r
-\r
-      if (chr1!=chr2 && !isGap(chr1) && !isGap(chr2) )\r
+      if (chr1 != chr2 && !isGap(chr1) && !isGap(chr2))\r
       {\r
-          bad++;\r
+        bad++;\r
       }\r
     }\r
 \r
@@ -186,12 +180,12 @@ public class Comparison
    *\r
    * @return DOCUMENT ME!\r
    */\r
-  public static boolean isGap(char c)\r
+  public static final boolean isGap(char c)\r
   {\r
     return (c == '-' || c == '.' || c == ' ') ? true : false;\r
   }\r
 \r
-  public static boolean isNucleotide(SequenceI [] seqs)\r
+  public static final boolean isNucleotide(SequenceI[] seqs)\r
   {\r
     int i = 0, iSize = seqs.length, j, jSize;\r
     float nt = 0, aa = 0;\r
@@ -203,11 +197,15 @@ public class Comparison
       {\r
         c = seqs[i].getCharAt(j);\r
         if ('a' <= c && c <= 'z')\r
+        {\r
           c -= ('a' - 'A');\r
+        }\r
 \r
         if (c == 'A' || c == 'G' || c == 'C' || c == 'T' || c == 'U')\r
+        {\r
           nt++;\r
-        else if (!jalview.util.Comparison.isGap( seqs[i].getCharAt(j)))\r
+        }\r
+        else if (!jalview.util.Comparison.isGap(seqs[i].getCharAt(j)))\r
         {\r
           aa++;\r
         }\r
@@ -216,9 +214,13 @@ public class Comparison
     }\r
 \r
     if ( (nt / (nt + aa)) > 0.85f)\r
+    {\r
       return true;\r
+    }\r
     else\r
+    {\r
       return false;\r
+    }\r
 \r
   }\r
 }\r