}\r
}\r
\r
- public int countGaps(int j) {\r
+ public int countGaps(int j)\r
+ {\r
int count = 0;\r
\r
- for (int i = 0; i < sequences.size();i++) {\r
+ for (int i = 0; i < sequences.size();i++)\r
+ {\r
if( j+1 > ((Sequence)sequences.elementAt(i)).getSequence().length())\r
{ count++; continue;}\r
\r
- String tmp = ((Sequence)sequences.elementAt(i)).getSequence().substring(j,j+1);\r
- if (tmp.equals(" ") || tmp.equals(".") || tmp.equals("-")) {\r
+ char c = ((Sequence)sequences.elementAt(i)).getSequence().charAt(j);\r
+ if (jalview.util.Comparison.isGap((c)))\r
count++;\r
- }\r
+\r
}\r
return count;\r
}\r
\r
while (i< sequence.length() && j <= end && j <= pos) {\r
\r
- String s = sequence.substring(i,i+1);\r
+ char c = sequence.charAt(i);\r
\r
- if (!(s.equals(".") || s.equals("-") || s.equals(" "))) {\r
+ if (!jalview.util.Comparison.isGap((c)))\r
j++;\r
- }\r
+\r
i++;\r
}\r
- if (j == end && j < pos) {\r
+ if (j == end && j < pos)\r
return end+1;\r
- } else {\r
-\r
+ else\r
return i;\r
- }\r
+\r
}\r
\r
public int findPosition(int i) {\r
int j = 0;\r
int pos = start;\r
\r
- while (j < i) {\r
- String s = sequence.substring(j,j+1);\r
+ while (j < i)\r
+ {\r
+ char c = sequence.charAt(j);\r
\r
- if (!(s.equals(".") || s.equals("-") || s.equals(" "))) {\r
+ if (!jalview.util.Comparison.isGap((c)))\r
pos++;\r
- }\r
+\r
j++;\r
}\r
return pos;\r
}\r
\r
for (int i = fstart; i <= fend; i++) {\r
- String s = sequence.sequence.substring(i,i+1);\r
- if (!(s.equals(".") || s.equals("-") || s.equals(" "))) {\r
+ char c = sequence.sequence.charAt(i);\r
+ if (!jalview.util.Comparison.isGap((c)))\r
g.fillRect(x1+(i-fstart)*width,y1,width,height);\r
- } else {\r
+ else\r
g.drawString("-",x1+(i-fstart)*width,y1+height);\r
- }\r
+\r
}\r
\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
+ if ( jalview.util.Comparison.isGap( si.charAt(start+ilen)) )\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
+ while (jalview.util.Comparison.isGap( si.charAt(start+ilen)))\r
+ {\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
+ if ( jalview.util.Comparison.isGap( sj.charAt(start+jlen)) )\r
+ {\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
+ while (jalview.util.Comparison.isGap( sj.charAt(start+jlen)))\r
+ {\r
jlen--;\r
}\r
}\r
}\r
\r
/** */\r
- public static float PID(Sequence s1 , Sequence s2) {\r
- int res = 0;\r
+ public static float PID(Sequence s1 , Sequence s2)\r
+ {\r
int len;\r
\r
- if (s1.getSequence().length() > s2.getSequence().length()) {\r
+ if (s1.getSequence().length() > s2.getSequence().length())\r
len = s1.getSequence().length();\r
- } else {\r
+ else\r
len = s2.getSequence().length();\r
- }\r
+\r
\r
int bad = 0;\r
\r
- for (int i = 0; i < len; i++) {\r
- String str1 = "";\r
- String str2 = "";\r
+ for (int i = 0; i < len; i++)\r
+ {\r
+ char chr1;\r
+ char chr2;\r
\r
- if (i < s1.getSequence().length()) {\r
- str1 = s1.getSequence().substring(i,i+1);\r
- } else {\r
- str1 = ".";\r
- }\r
+ if (i < s1.getSequence().length())\r
+ chr1 = s1.getSequence().charAt(i);\r
+ else\r
+ chr1 = '.';\r
\r
- if (i < s2.getSequence().length()) {\r
- str2 = s2.getSequence().substring(i,i+1);\r
- } else {\r
- str2 = ".";\r
- }\r
\r
- if (!(str1.equals(".") ||\r
- str1.equals("-") ||\r
- str1.equals(" ")) &&\r
- !(str2.equals(".") ||\r
- str2.equals("-") ||\r
- str2.equals(" "))) {\r
+ if (i < s2.getSequence().length())\r
+ chr2 = s2.getSequence().charAt(i);\r
+ else\r
+ chr2 = '.';\r
+\r
\r
- if (!str1.equals(str2)) {\r
+ if (!(jalview.util.Comparison.isGap( chr1 )) && !(jalview.util.Comparison.isGap( chr2 )))\r
+ {\r
+ if (chr1!=chr2)\r
bad++;\r
- }\r
}\r
}\r
\r
return (float)100*(len-bad)/len;\r
}\r
+\r
+ public static boolean isGap(char c)\r
+ {\r
+ return (c != '.' && c != '-' && c != ' ') ? false : true;\r
+ }\r
}\r