-public class Comparison {\r
-\r
- public static float compare(SequenceI ii, SequenceI jj)\r
- {\r
- return Comparison.compare(ii,jj,0,ii.getLength()-1);\r
- }\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
-\r
- int ilen = end-start+1;\r
- int jlen = end-start+1;\r
-\r
- if ( si.substring(start + ilen).equals("-") ||\r
- si.substring(start + ilen).equals(".") ||\r
- si.substring(start + ilen).equals(" ")) {\r
-\r
- ilen--;\r
-\r
- while (si.substring(start + ilen,start + ilen+1).equals("-") ||\r
- si.substring(start + ilen,start + ilen+1).equals(".") ||\r
- si.substring(start + ilen,start + ilen+1).equals(" ")) {\r
- ilen--;\r
- }\r
- }\r
-\r
- if ( sj.substring(start + jlen).equals("-") ||\r
- sj.substring(start + jlen).equals(".") ||\r
- sj.substring(start + jlen).equals(" ")) {\r
- jlen--;\r
-\r
- while (sj.substring(start + jlen,start + jlen+1).equals("-") ||\r
- sj.substring(start + jlen,start + jlen+1).equals(".") ||\r
- sj.substring(start + jlen,start + jlen+1).equals(" ")) {\r
- jlen--;\r
- }\r
- }\r
-\r
- int count = 0;\r
- int match = 0;\r
- float pid = -1;\r
-\r
- if (ilen > jlen) {\r
-\r
- for (int j = 0; j < jlen; j++) {\r
- if (si.substring(start + j,start + j+1).equals(sj.substring(start + j,start + j+1))) {\r
- match++;\r
- }\r
- count++;\r
- }\r
- pid = (float)match/(float)ilen * 100;\r
- } else {\r
- for (int j = 0; j < jlen; j++) {\r
- if (si.substring(start + j,start + j+1).equals(sj.substring(start + j,start + j+1))) {\r
- match++;\r
- }\r
- count++;\r
- }\r
- pid = (float)match/(float)jlen * 100;\r
- }\r
-\r
- return pid;\r
- }\r
-\r
- /** */\r
- public static float PID(Sequence s1 , Sequence s2) {\r
- int res = 0;\r
- int len;\r
-\r
- if (s1.getSequence().length() > s2.getSequence().length()) {\r
- len = s1.getSequence().length();\r
- } else {\r
- len = s2.getSequence().length();\r
+\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+public class Comparison\r
+{\r
+ /** DOCUMENT ME!! */\r
+ public static String GapChars = " .-";\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param ii DOCUMENT ME!\r
+ * @param jj DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public static float compare(SequenceI ii, SequenceI jj)\r
+ {\r
+ return Comparison.compare(ii, jj, 0, ii.getLength() - 1);\r
+ }\r
+\r
+ /**\r
+ * this was supposed to be an ungapped pid calculation\r
+ * @param ii SequenceI\r
+ * @param jj SequenceI\r
+ * @param start int\r
+ * @param end int\r
+ * @return float\r
+ */\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
+\r
+ int ilen = si.length() - 1;\r
+ int jlen = sj.length() - 1;\r
+\r
+ while (jalview.util.Comparison.isGap(si.charAt(start + ilen)))\r
+ {\r
+ ilen--;\r
+ }\r
+\r
+ while (jalview.util.Comparison.isGap(sj.charAt(start + jlen)))\r
+ {\r
+ jlen--;\r
+ }\r
+\r
+ int count = 0;\r
+ int match = 0;\r
+ float pid = -1;\r
+\r
+ if (ilen > jlen)\r
+ {\r
+ for (int j = 0; j < jlen; j++)\r
+ {\r
+ if (si.substring(start + j, start + j + 1).equals(sj.substring(start +\r
+ j, start + j + 1)))\r
+ {\r
+ match++;\r
+ }\r
+\r
+ count++;\r
+ }\r
+\r
+ pid = (float) match / (float) ilen * 100;\r
+ }\r
+ else\r
+ {\r
+ for (int j = 0; j < jlen; j++)\r
+ {\r
+ if (si.substring(start + j, start + j + 1).equals(sj.substring(start +\r
+ j, start + j + 1)))\r
+ {\r
+ match++;\r
+ }\r
+\r
+ count++;\r
+ }\r
+\r
+ pid = (float) match / (float) jlen * 100;\r
+ }\r
+\r
+ return pid;\r
+ }\r
+\r
+ /**\r
+ * this is a gapped PID calculation\r
+ *\r
+ * @param s1 SequenceI\r
+ * @param s2 SequenceI\r
+ * @return float\r
+ */\r
+ public static float PID(SequenceI s1, SequenceI s2)\r
+ {\r
+ int len;\r
+\r
+ if (s1.getSequence().length() > s2.getSequence().length())\r
+ {\r
+ len = s1.getSequence().length();\r
+ }\r
+ else\r
+ {\r
+ len = s2.getSequence().length();\r
+ }\r
+\r
+ int bad = 0;\r
+\r
+ for (int i = 0; i < len; i++)\r
+ {\r
+ char chr1;\r
+ char chr2;\r
+\r
+ if (i < s1.getSequence().length())\r
+ {\r
+ chr1 = Character.toUpperCase(s1.getSequence().charAt(i));\r
+ }\r
+ else\r
+ {\r
+ chr1 = '.';\r
+ }\r
+\r
+ if (i < s2.getSequence().length())\r
+ {\r
+ chr2 = Character.toUpperCase(s2.getSequence().charAt(i));\r
+ }\r
+ else\r
+ {\r
+ chr2 = '.';\r
+ }\r
+\r
+ if (!(jalview.util.Comparison.isGap(chr1)) &&\r
+ !(jalview.util.Comparison.isGap(chr2)))\r
+ {\r
+ if (chr1 != chr2)\r
+ {\r
+ bad++;\r
+ }\r
+ }\r
+ }\r
+\r
+ return ((float) 100 * (len - bad)) / len;\r