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
24 public class Comparison {
\r
25 public static String GapChars = " .-";
\r
27 public static float compare(SequenceI ii, SequenceI jj) {
\r
28 return Comparison.compare(ii, jj, 0, ii.getLength() - 1);
\r
32 * this was supposed to be an ungapped pid calculation
\r
33 * @param ii SequenceI
\r
34 * @param jj SequenceI
\r
39 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
50 while (jalview.util.Comparison.isGap(sj.charAt(start + jlen))) {
\r
59 for (int j = 0; j < jlen; j++) {
\r
60 if (si.substring(start + j, start + j + 1).equals(sj.substring(start +
\r
61 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 +
\r
72 j, start + j + 1))) {
\r
79 pid = (float) match / (float) jlen * 100;
\r
86 * this is a gapped PID calculation
\r
88 * @param s1 SequenceI
\r
89 * @param s2 SequenceI
\r
92 public static float PID(SequenceI s1, SequenceI s2) {
\r
95 if (s1.getSequence().length() > s2.getSequence().length()) {
\r
96 len = s1.getSequence().length();
\r
98 len = s2.getSequence().length();
\r
103 for (int i = 0; i < len; i++) {
\r
107 if (i < s1.getSequence().length()) {
\r
108 chr1 = s1.getSequence().charAt(i);
\r
113 if (i < s2.getSequence().length()) {
\r
114 chr2 = s2.getSequence().charAt(i);
\r
119 if (!(jalview.util.Comparison.isGap(chr1)) &&
\r
120 !(jalview.util.Comparison.isGap(chr2))) {
\r
121 if (chr1 != chr2) {
\r
127 return ((float) 100 * (len - bad)) / len;
\r
130 // Another pid with region specification
\r
131 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
145 start = len - 1; // we just use a single residue for the difference
\r
150 for (int i = start; i < len; i++) {
\r
154 if (i < s1.getSequence().length()) {
\r
155 chr1 = s1.getSequence().charAt(i);
\r
160 if (i < s2.getSequence().length()) {
\r
161 chr2 = s2.getSequence().charAt(i);
\r
166 if (!(jalview.util.Comparison.isGap(chr1)) &&
\r
167 !(jalview.util.Comparison.isGap(chr2))) {
\r
168 if (chr1 != chr2) {
\r
174 return ((float) 100 * (len - bad)) / len;
\r
177 public static boolean isGap(char c) {
\r
178 return ((c != '.') && (c != '-') && (c != ' ')) ? false : true;
\r