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
30 * <p>Copyright: Copyright (c) 2004</p>
\r
32 * <p>Company: Dundee University</p>
\r
34 * @author not attributable
\r
37 public class SeqsetUtils
\r
40 * Store essential properties of a sequence in a hashtable for later recovery
\r
41 * Keys are Name, Start, End, SeqFeatures, PdbId
\r
42 * @param seq SequenceI
\r
45 public static Hashtable SeqCharacterHash(SequenceI seq)
\r
47 Hashtable sqinfo = new Hashtable();
\r
48 sqinfo.put("Name", seq.getName());
\r
49 sqinfo.put("Start", new Integer(seq.getStart()));
\r
50 sqinfo.put("End", new Integer(seq.getEnd()));
\r
51 sqinfo.put("SeqFeatures", seq.getSequenceFeatures());
\r
53 (seq.getPDBId() != null) ? seq.getPDBId() : new String(""));
\r
59 * Recover essential properties of a sequence from a hashtable
\r
60 * TODO: replace these methods with something more elegant.
\r
61 * @param sq SequenceI
\r
62 * @param sqinfo Hashtable
\r
65 public static boolean SeqCharacterUnhash(SequenceI sq, Hashtable sqinfo)
\r
67 boolean namePresent = true;
\r
68 String oldname = (String) sqinfo.get("Name");
\r
69 Integer start = (Integer) sqinfo.get("Start");
\r
70 Integer end = (Integer) sqinfo.get("End");
\r
71 java.util.Vector sfeatures = (java.util.Vector) sqinfo.get(
\r
73 String pdbid = (String) sqinfo.get("PdbId");
\r
75 if (oldname == null)
\r
77 namePresent = false;
\r
81 sq.setName(oldname);
\r
84 if (!pdbid.equals(""))
\r
89 if ( (start != null) && (end != null))
\r
91 sq.setStart(start.intValue());
\r
92 sq.setEnd(end.intValue());
\r
95 if (sfeatures != null)
\r
97 sq.setSequenceFeatures(sfeatures);
\r
100 return namePresent;
\r
104 * Form of the unique name used in uniquify for the i'th sequence in an ordered vector of sequences.
\r
108 public static String unique_name(int i)
\r
110 return new String("Sequence" + i);
\r
113 public static Hashtable uniquify(SequenceI[] sequences, boolean write_names)
\r
115 // Generate a safely named sequence set and a hash to recover the sequence names
\r
116 Hashtable map = new Hashtable();
\r
117 String[] un_names = new String[sequences.length];
\r
121 for (int i = 0; i < sequences.length; i++)
\r
123 String safename = new String("Sequence" + i);
\r
124 map.put(safename, SeqCharacterHash(sequences[i]));
\r
128 sequences[i].setName(safename);
\r
136 public static boolean deuniquify(Hashtable map, SequenceI[] sequences)
\r
138 // recover unsafe sequence names for a sequence set
\r
139 boolean allfound = true;
\r
141 for (int i = 0; i < sequences.length; i++)
\r
143 if (map.containsKey(sequences[i].getName()))
\r
145 Hashtable sqinfo = (Hashtable) map.get(sequences[i].getName());
\r
146 SeqCharacterUnhash(sequences[i], sqinfo);
\r