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
19 package jalview.analysis;
\r
21 import jalview.datamodel.SequenceI;
\r
23 import java.util.Hashtable;
\r
29 * <p>Description: </p>
31 * <p>Copyright: Copyright (c) 2004</p>
33 * <p>Company: Dundee University</p>
35 * @author not attributable
38 public class SeqsetUtils {
\r
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) {
\r
46 Hashtable sqinfo = new Hashtable();
\r
47 sqinfo.put("Name", seq.getName());
\r
48 sqinfo.put("Start", new Integer(seq.getStart()));
\r
49 sqinfo.put("End", new Integer(seq.getEnd()));
\r
50 sqinfo.put("SeqFeatures", seq.getSequenceFeatures());
\r
52 (seq.getPDBId() != null) ? seq.getPDBId() : new String(""));
\r
58 * Recover essential properties of a sequence from a hashtable
59 * TODO: replace these methods with something more elegant.
61 * @param sqinfo Hashtable
64 public static boolean SeqCharacterUnhash(SequenceI sq, Hashtable sqinfo) {
\r
65 boolean namePresent = true;
\r
66 String oldname = (String) sqinfo.get("Name");
\r
67 Integer start = (Integer) sqinfo.get("Start");
\r
68 Integer end = (Integer) sqinfo.get("End");
\r
69 java.util.Vector sfeatures = (java.util.Vector) sqinfo.get(
\r
71 String pdbid = (String) sqinfo.get("PdbId");
\r
73 if (oldname == null) {
\r
74 namePresent = false;
\r
76 sq.setName(oldname);
\r
79 if (!pdbid.equals("")) {
\r
83 if ((start != null) && (end != null)) {
\r
84 sq.setStart(start.intValue());
\r
85 sq.setEnd(end.intValue());
\r
88 if (sfeatures != null) {
\r
89 sq.setSequenceFeatures(sfeatures);
\r
96 * Form of the unique name used in uniquify for the i'th sequence in an ordered vector of sequences.
100 public static String unique_name(int i) {
\r
101 return new String("Sequence" + i);
\r
104 public static Hashtable uniquify(SequenceI[] sequences, boolean write_names) {
\r
105 // Generate a safely named sequence set and a hash to recover the sequence names
\r
106 Hashtable map = new Hashtable();
\r
107 String[] un_names = new String[sequences.length];
\r
109 if (!write_names) {
\r
110 for (int i = 0; i < sequences.length; i++) {
\r
111 String safename = new String("Sequence" + i);
\r
112 map.put(safename, SeqCharacterHash(sequences[i]));
\r
115 sequences[i].setName(safename);
\r
123 public static boolean deuniquify(Hashtable map, SequenceI[] sequences) {
\r
124 // recover unsafe sequence names for a sequence set
\r
125 boolean allfound = true;
\r
127 for (int i = 0; i < sequences.length; i++) {
\r
128 if (map.containsKey(sequences[i].getName())) {
\r
129 Hashtable sqinfo = (Hashtable) map.get(sequences[i].getName());
\r
130 SeqCharacterUnhash(sequences[i], sqinfo);
\r