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
20 package jalview.util;
\r
22 import jalview.datamodel.*;
\r
24 public class Comparison {
\r
26 public static float compare(SequenceI ii, SequenceI jj)
\r
28 return Comparison.compare(ii,jj,0,ii.getLength()-1);
\r
31 * this was supposed to be an ungapped pid calculation
\r
32 * @param ii SequenceI
\r
33 * @param jj SequenceI
\r
38 public static float compare(SequenceI ii, SequenceI jj, int start, int end) {
\r
40 String si = ii.getSequence();
\r
41 String sj = jj.getSequence();
\r
43 int ilen = si.length()-1;
\r
44 int jlen = sj.length()-1;
\r
46 while (jalview.util.Comparison.isGap(si.charAt(start + ilen)))
\r
51 while (jalview.util.Comparison.isGap(sj.charAt(start + jlen)))
\r
62 for (int j = 0; j < jlen; j++) {
\r
63 if (si.substring(start + j,start + j+1).equals(sj.substring(start + j,start + j+1))) {
\r
68 pid = (float)match/(float)ilen * 100;
\r
70 for (int j = 0; j < jlen; j++) {
\r
71 if (si.substring(start + j,start + j+1).equals(sj.substring(start + j,start + j+1))) {
\r
76 pid = (float)match/(float)jlen * 100;
\r
83 * this is a gapped PID calculation
\r
85 * @param s1 SequenceI
\r
86 * @param s2 SequenceI
\r
89 public static float PID(SequenceI s1 , SequenceI s2)
\r
93 if (s1.getSequence().length() > s2.getSequence().length())
\r
94 len = s1.getSequence().length();
\r
96 len = s2.getSequence().length();
\r
101 for (int i = 0; i < len; i++)
\r
106 if (i < s1.getSequence().length())
\r
107 chr1 = s1.getSequence().charAt(i);
\r
112 if (i < s2.getSequence().length())
\r
113 chr2 = s2.getSequence().charAt(i);
\r
118 if (!(jalview.util.Comparison.isGap( chr1 )) && !(jalview.util.Comparison.isGap( chr2 )))
\r
125 return (float)100*(len-bad)/len;
\r
128 // Another pid with region specification
\r
130 public static float PID(SequenceI s1 , SequenceI s2, int start, int end)
\r
134 if (s1.getSequence().length() > s2.getSequence().length())
\r
135 len = s1.getSequence().length();
\r
137 len = s2.getSequence().length();
\r
143 start = len - 1; // we just use a single residue for the difference
\r
148 for (int i = start; i < len; i++)
\r
153 if (i < s1.getSequence().length())
\r
154 chr1 = s1.getSequence().charAt(i);
\r
159 if (i < s2.getSequence().length())
\r
160 chr2 = s2.getSequence().charAt(i);
\r
165 if (!(jalview.util.Comparison.isGap( chr1 )) && !(jalview.util.Comparison.isGap( chr2 )))
\r
172 return (float)100*(len-bad)/len;
\r
176 public static String GapChars = " .-";
\r
177 public static boolean isGap(char c)
\r
179 return (c != '.' && c != '-' && c != ' ') ? false : true;
\r