2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 import jalview.datamodel.*;
29 public class Comparison
32 public static final String GapChars = " .-";
42 * @return DOCUMENT ME!
44 public static final float compare(SequenceI ii, SequenceI jj)
46 return Comparison.compare(ii, jj, 0, ii.getLength() - 1);
50 * this was supposed to be an ungapped pid calculation
62 public static float compare(SequenceI ii, SequenceI jj, int start, int end)
64 String si = ii.getSequenceAsString();
65 String sj = jj.getSequenceAsString();
67 int ilen = si.length() - 1;
68 int jlen = sj.length() - 1;
70 while (jalview.util.Comparison.isGap(si.charAt(start + ilen)))
75 while (jalview.util.Comparison.isGap(sj.charAt(start + jlen)))
86 for (int j = 0; j < jlen; j++)
88 if (si.substring(start + j, start + j + 1).equals(
89 sj.substring(start + j, start + j + 1)))
97 pid = (float) match / (float) ilen * 100;
101 for (int j = 0; j < jlen; j++)
103 if (si.substring(start + j, start + j + 1).equals(
104 sj.substring(start + j, start + j + 1)))
112 pid = (float) match / (float) jlen * 100;
119 * this is a gapped PID calculation
127 public final static float PID(String seq1, String seq2)
129 return PID(seq1, seq2, 0, seq1.length());
132 static final int caseShift = 'a' - 'A';
134 // Another pid with region specification
135 public final static float PID(String seq1, String seq2, int start, int end)
138 int s1len = seq1.length();
139 int s2len = seq2.length();
141 int len = Math.min(s1len, s2len);
150 start = len - 1; // we just use a single residue for the difference
157 for (int i = start; i < len; i++)
159 chr1 = seq1.charAt(i);
161 chr2 = seq2.charAt(i);
163 if ('a' <= chr1 && chr1 <= 'z')
166 // Faster than toUpperCase
169 if ('a' <= chr2 && chr2 <= 'z')
172 // Faster than toUpperCase
176 if (chr1 != chr2 && !isGap(chr1) && !isGap(chr2))
182 return ((float) 100 * (len - bad)) / len;
191 * @return DOCUMENT ME!
193 public static final boolean isGap(char c)
195 return (c == '-' || c == '.' || c == ' ') ? true : false;
198 public static final boolean isNucleotide(SequenceI[] seqs)
200 int i = 0, iSize = seqs.length, j, jSize;
201 float nt = 0, aa = 0;
205 jSize = seqs[i].getLength();
206 for (j = 0; j < jSize; j++)
208 c = seqs[i].getCharAt(j);
209 if ('a' <= c && c <= 'z')
214 if (c == 'A' || c == 'G' || c == 'C' || c == 'T' || c == 'U')
218 else if (!jalview.util.Comparison.isGap(seqs[i].getCharAt(j)))
226 if ((nt / (nt + aa)) > 0.85f)