2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
27 * @version $Revision$
\r
29 public class Comparison
\r
31 /** DOCUMENT ME!! */
\r
32 public static final String GapChars = " .-";
\r
37 * @param ii DOCUMENT ME!
\r
38 * @param jj DOCUMENT ME!
\r
40 * @return DOCUMENT ME!
\r
42 public static final float compare(SequenceI ii, SequenceI jj)
\r
44 return Comparison.compare(ii, jj, 0, ii.getLength() - 1);
\r
48 * this was supposed to be an ungapped pid calculation
\r
49 * @param ii SequenceI
\r
50 * @param jj SequenceI
\r
55 public static float compare(SequenceI ii, SequenceI jj, int start, int end)
\r
57 String si = ii.getSequenceAsString();
\r
58 String sj = jj.getSequenceAsString();
\r
60 int ilen = si.length() - 1;
\r
61 int jlen = sj.length() - 1;
\r
63 while (jalview.util.Comparison.isGap(si.charAt(start + ilen)))
\r
68 while (jalview.util.Comparison.isGap(sj.charAt(start + jlen)))
\r
79 for (int j = 0; j < jlen; j++)
\r
81 if (si.substring(start + j, start + j + 1).equals(sj.substring(start +
\r
90 pid = (float) match / (float) ilen * 100;
\r
94 for (int j = 0; j < jlen; j++)
\r
96 if (si.substring(start + j, start + j + 1).equals(sj.substring(start +
\r
105 pid = (float) match / (float) jlen * 100;
\r
112 * this is a gapped PID calculation
\r
114 * @param s1 SequenceI
\r
115 * @param s2 SequenceI
\r
118 public final static float PID(String seq1, String seq2)
\r
120 return PID(seq1, seq2, 0, seq1.length());
\r
123 static final int caseShift = 'a' - 'A';
\r
125 // Another pid with region specification
\r
126 public final static float PID(String seq1, String seq2, int start, int end)
\r
129 int s1len = seq1.length();
\r
130 int s2len = seq2.length();
\r
132 int len = Math.min(s1len, s2len);
\r
141 start = len - 1; // we just use a single residue for the difference
\r
148 for (int i = start; i < len; i++)
\r
150 chr1 = seq1.charAt(i);
\r
152 chr2 = seq2.charAt(i);
\r
154 if ('a' <= chr1 && chr1 <= 'z')
\r
156 // TO UPPERCASE !!!
\r
157 //Faster than toUpperCase
\r
160 if ('a' <= chr2 && chr2 <= 'z')
\r
162 // TO UPPERCASE !!!
\r
163 //Faster than toUpperCase
\r
167 if (chr1 != chr2 && !isGap(chr1) && !isGap(chr2))
\r
173 return ( (float) 100 * (len - bad)) / len;
\r
179 * @param c DOCUMENT ME!
\r
181 * @return DOCUMENT ME!
\r
183 public static final boolean isGap(char c)
\r
185 return (c == '-' || c == '.' || c == ' ') ? true : false;
\r
188 public static final boolean isNucleotide(SequenceI[] seqs)
\r
190 int i = 0, iSize = seqs.length, j, jSize;
\r
191 float nt = 0, aa = 0;
\r
195 jSize = seqs[i].getLength();
\r
196 for (j = 0; j < jSize; j++)
\r
198 c = seqs[i].getCharAt(j);
\r
199 if ('a' <= c && c <= 'z')
\r
204 if (c == 'A' || c == 'G' || c == 'C' || c == 'T' || c == 'U')
\r
208 else if (!jalview.util.Comparison.isGap(seqs[i].getCharAt(j)))
\r
216 if ( (nt / (nt + aa)) > 0.85f)
\r