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.analysis;
\r
23 import jalview.datamodel.*;
\r
28 * <p>Description: </p>
\r
29 * Routine which does approximate Sequence Id resolution by name using string containment rather than equivalence
\r
30 * <p>Copyright: Copyright (c) 2004</p>
\r
32 * <p>Company: Dundee University</p>
\r
34 * @author not attributable
\r
37 public class SequenceIdMatcher
\r
39 private Hashtable names;
\r
41 public SequenceIdMatcher(SequenceI[] seqs)
\r
43 names = new Hashtable();
\r
45 for (int i = 0; i < seqs.length; i++)
\r
47 names.put(new SeqIdName(seqs[i].getName()), seqs[i]);
\r
51 SequenceI findIdMatch(SequenceI seq)
\r
53 SeqIdName nam = new SeqIdName(seq.getName());
\r
55 if (names.containsKey(nam))
\r
57 return (SequenceI) names.get(nam);
\r
63 SequenceI findIdMatch(String seqnam)
\r
65 SeqIdName nam = new SeqIdName(seqnam);
\r
67 if (names.containsKey(nam))
\r
69 return (SequenceI) names.get(nam);
\r
78 * Return pointers to sequences (or sequence object containers)
\r
79 * which have same Id as a given set of different sequence objects
\r
81 * @param seqs SequenceI[]
\r
82 * @return SequenceI[]
\r
84 SequenceI[] findIdMatch(SequenceI[] seqs)
\r
86 SequenceI[] namedseqs = new SequenceI[seqs.length];
\r
91 if (seqs.length > 0)
\r
95 nam = new SeqIdName(seqs[i].getName());
\r
97 if (names.containsKey(nam))
\r
99 namedseqs[i] = (SequenceI) names.get(nam);
\r
103 namedseqs[i] = null;
\r
106 while (i++ < seqs.length);
\r
112 private class SeqIdName
\r
116 SeqIdName(String s)
\r
118 id = new String(s);
\r
121 public int hashCode()
\r
123 return (id.substring(0, 4).hashCode());
\r
126 public boolean equals(Object s)
\r
128 if (s instanceof SeqIdName)
\r
130 return this.equals( (SeqIdName) s);
\r
134 if (s instanceof String)
\r
136 return this.equals( (String) s);
\r
143 public boolean equals(SeqIdName s)
\r
145 if (id.startsWith(s.id) || s.id.startsWith(id))
\r
153 public boolean equals(String s)
\r
155 if (id.startsWith(s) || s.startsWith(id))
\r