2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.util;
\r
21 import jalview.datamodel.*;
\r
28 * @version $Revision$
\r
30 public class Comparison
\r
32 /** DOCUMENT ME!! */
\r
33 public static String GapChars = " .-";
\r
38 * @param ii DOCUMENT ME!
\r
39 * @param jj DOCUMENT ME!
\r
41 * @return DOCUMENT ME!
\r
43 public static float compare(SequenceI ii, SequenceI jj)
\r
45 return Comparison.compare(ii, jj, 0, ii.getLength() - 1);
\r
49 * this was supposed to be an ungapped pid calculation
\r
50 * @param ii SequenceI
\r
51 * @param jj SequenceI
\r
56 public static float compare(SequenceI ii, SequenceI jj, int start, int end)
\r
58 String si = ii.getSequence();
\r
59 String sj = jj.getSequence();
\r
61 int ilen = si.length() - 1;
\r
62 int jlen = sj.length() - 1;
\r
64 while (jalview.util.Comparison.isGap(si.charAt(start + ilen)))
\r
69 while (jalview.util.Comparison.isGap(sj.charAt(start + jlen)))
\r
80 for (int j = 0; j < jlen; j++)
\r
82 if (si.substring(start + j, start + j + 1).equals(sj.substring(start +
\r
91 pid = (float) match / (float) ilen * 100;
\r
95 for (int j = 0; j < jlen; j++)
\r
97 if (si.substring(start + j, start + j + 1).equals(sj.substring(start +
\r
106 pid = (float) match / (float) jlen * 100;
\r
113 * this is a gapped PID calculation
\r
115 * @param s1 SequenceI
\r
116 * @param s2 SequenceI
\r
119 public static float PID(SequenceI s1, SequenceI s2)
\r
123 if (s1.getSequence().length() > s2.getSequence().length())
\r
125 len = s1.getSequence().length();
\r
129 len = s2.getSequence().length();
\r
134 for (int i = 0; i < len; i++)
\r
139 if (i < s1.getSequence().length())
\r
141 chr1 = s1.getSequence().charAt(i);
\r
148 if (i < s2.getSequence().length())
\r
150 chr2 = s2.getSequence().charAt(i);
\r
157 if (!(jalview.util.Comparison.isGap(chr1)) &&
\r
158 !(jalview.util.Comparison.isGap(chr2)))
\r
167 return ((float) 100 * (len - bad)) / len;
\r
170 // Another pid with region specification
\r
171 public static float PID(SequenceI s1, SequenceI s2, int start, int end)
\r
175 if (s1.getSequence().length() > s2.getSequence().length())
\r
177 len = s1.getSequence().length();
\r
181 len = s2.getSequence().length();
\r
191 start = len - 1; // we just use a single residue for the difference
\r
196 for (int i = start; i < len; i++)
\r
201 if (i < s1.getSequence().length())
\r
203 chr1 = s1.getSequence().charAt(i);
\r
210 if (i < s2.getSequence().length())
\r
212 chr2 = s2.getSequence().charAt(i);
\r
219 if (!(jalview.util.Comparison.isGap(chr1)) &&
\r
220 !(jalview.util.Comparison.isGap(chr2)))
\r
229 return ((float) 100 * (len - bad)) / len;
\r
235 * @param c DOCUMENT ME!
\r
237 * @return DOCUMENT ME!
\r
239 public static boolean isGap(char c)
\r
241 return ((c != '.') && (c != '-') && (c != ' ')) ? false : true;
\r