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 jalview.datamodel.SequenceI;
23 import java.util.Hashtable;
28 * <p>Description: </p>
30 * <p>Copyright: Copyright (c) 2004</p>
32 * <p>Company: Dundee University</p>
34 * @author not attributable
37 public class SeqsetUtils
40 * Store essential properties of a sequence in a hashtable for later recovery
41 * Keys are Name, Start, End, SeqFeatures, PdbId
42 * @param seq SequenceI
45 public static Hashtable SeqCharacterHash(SequenceI seq) {
46 Hashtable sqinfo = new Hashtable();
47 sqinfo.put("Name", seq.getName());
48 sqinfo.put("Start", new Integer(seq.getStart()));
49 sqinfo.put("End", new Integer(seq.getEnd()));
50 sqinfo.put("SeqFeatures", seq.getSequenceFeatures());
51 sqinfo.put("PdbId", (seq.getPDBId()!=null) ? seq.getPDBId() : new String("") );
55 * Recover essential properties of a sequence from a hashtable
56 * TODO: replace these methods with something more elegant.
58 * @param sqinfo Hashtable
61 public static boolean SeqCharacterUnhash(SequenceI sq, Hashtable sqinfo) {
62 boolean namePresent = true;
63 String oldname = (String) sqinfo.get("Name");
64 Integer start = (Integer) sqinfo.get("Start");
65 Integer end = (Integer) sqinfo.get("End");
66 java.util.Vector sfeatures = (java.util.Vector) sqinfo.get("SeqFeatures");
67 String pdbid = (String) sqinfo.get("PdbId");
72 if (!pdbid.equals(""))
75 if ((start!=null) && (end!=null)) {
76 sq.setStart(start.intValue());
77 sq.setEnd(end.intValue());
80 sq.setSequenceFeatures(sfeatures);
85 * Form of the unique name used in uniquify for the i'th sequence in an ordered vector of sequences.
89 public static String unique_name(int i) {
90 return new String("Sequence"+i);
93 public static Hashtable uniquify(SequenceI[] sequences, boolean write_names)
95 // Generate a safely named sequence set and a hash to recover the sequence names
96 Hashtable map = new Hashtable();
97 String[] un_names = new String[sequences.length];
100 for (int i = 0; i < sequences.length; i++)
102 String safename = new String("Sequence" + i);
103 map.put(safename, SeqCharacterHash(sequences[i]));
105 sequences[i].setName(safename);
110 public static boolean deuniquify(Hashtable map, SequenceI[] sequences)
112 // recover unsafe sequence names for a sequence set
113 boolean allfound = true;
114 for (int i = 0; i < sequences.length; i++)
116 if (map.containsKey(sequences[i].getName()))
118 Hashtable sqinfo = (Hashtable) map.get(sequences[i].getName());
119 SeqCharacterUnhash(sequences[i], sqinfo);