1 package jalview.analysis;
3 import jalview.datamodel.SequenceI;
4 import java.util.Hashtable;
11 * <p>Copyright: Copyright (c) 2004</p>
13 * <p>Company: Dundee University</p>
15 * @author not attributable
18 public class SeqsetUtils
21 * Store essential properties of a sequence in a hashtable for later recovery
22 * Keys are Name, Start, End, SeqFeatures, PdbId
23 * @param seq SequenceI
26 public static Hashtable SeqCharacterHash(SequenceI seq) {
27 Hashtable sqinfo = new Hashtable();
28 sqinfo.put("Name", seq.getName());
29 sqinfo.put("Start", new Integer(seq.getStart()));
30 sqinfo.put("End", new Integer(seq.getEnd()));
31 sqinfo.put("SeqFeatures", seq.getSequenceFeatures());
32 sqinfo.put("PdbId", (seq.getPDBId()!=null) ? seq.getPDBId() : new String("") );
36 * Recover essential properties of a sequence from a hashtable
37 * TODO: replace these methods with something more elegant.
39 * @param sqinfo Hashtable
42 public static boolean SeqCharacterUnhash(SequenceI sq, Hashtable sqinfo) {
43 boolean namePresent = true;
44 String oldname = (String) sqinfo.get("Name");
45 Integer start = (Integer) sqinfo.get("Start");
46 Integer end = (Integer) sqinfo.get("End");
47 java.util.Vector sfeatures = (java.util.Vector) sqinfo.get("SeqFeatures");
48 String pdbid = (String) sqinfo.get("PdbId");
53 if (!pdbid.equals(""))
56 if ((start!=null) && (end!=null)) {
57 sq.setStart(start.intValue());
58 sq.setEnd(end.intValue());
61 sq.setSequenceFeatures(sfeatures);
66 * Form of the unique name used in uniquify for the i'th sequence in an ordered vector of sequences.
70 public static String unique_name(int i) {
71 return new String("Sequence"+i);
74 public static Hashtable uniquify(SequenceI[] sequences, boolean write_names)
76 // Generate a safely named sequence set and a hash to recover the sequence names
77 Hashtable map = new Hashtable();
78 String[] un_names = new String[sequences.length];
81 for (int i = 0; i < sequences.length; i++)
83 String safename = new String("Sequence" + i);
84 map.put(safename, SeqCharacterHash(sequences[i]));
86 sequences[i].setName(safename);
91 public static boolean deuniquify(Hashtable map, SequenceI[] sequences)
93 // recover unsafe sequence names for a sequence set
94 boolean allfound = true;
95 for (int i = 0; i < sequences.length; i++)
97 if (map.containsKey(sequences[i].getName()))
99 Hashtable sqinfo = (Hashtable) map.get(sequences[i].getName());
100 SeqCharacterUnhash(sequences[i], sqinfo);