2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2005 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
20 package jalview.analysis;
22 import java.util.Vector;
23 import java.util.Hashtable;
24 import jalview.datamodel.SequenceI;
29 * <p>Description: </p>
30 * Routine which does approximate Sequence Id resolution by name using string containment rather than equivalence
31 * <p>Copyright: Copyright (c) 2004</p>
33 * <p>Company: Dundee University</p>
35 * @author not attributable
38 public class SequenceIdMatcher
41 private class SeqIdName
52 return (id.substring(0, 4).hashCode());
55 public boolean equals(Object s)
57 if (s instanceof SeqIdName)
59 return this.equals( (SeqIdName) s);
63 if (s instanceof String)
65 return this.equals( (String) s);
71 public boolean equals(SeqIdName s)
73 if (id.startsWith(s.id) || s.id.startsWith(id))
80 public boolean equals(String s)
82 if (id.startsWith(s) || s.startsWith(id))
90 private Hashtable names;
92 public SequenceIdMatcher(SequenceI[] seqs)
94 names = new Hashtable();
95 for (int i = 0; i < seqs.length; i++)
97 names.put(new SeqIdName(seqs[i].getName()), seqs[i]);
101 SequenceI findIdMatch(SequenceI seq)
103 SeqIdName nam = new SeqIdName(seq.getName());
104 if (names.containsKey(nam))
106 return (SequenceI) names.get(nam);
111 SequenceI findIdMatch(String seqnam)
113 SeqIdName nam = new SeqIdName(seqnam);
114 if (names.containsKey(nam))
116 return (SequenceI) names.get(nam);
124 * Return pointers to sequences (or sequence object containers)
125 * which have same Id as a given set of different sequence objects
127 * @param seqs SequenceI[]
128 * @return SequenceI[]
131 SequenceI[] findIdMatch(SequenceI[] seqs)
133 SequenceI[] namedseqs = new SequenceI[seqs.length];
141 nam = new SeqIdName(seqs[i].getName());
142 if (names.containsKey(nam))
144 namedseqs[i] = (SequenceI) names.get(nam);
151 while (i++ < seqs.length);