2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
24 import jalview.datamodel.*;
32 public abstract class AlignFile
38 * Sequences to be added to form a new alignment.
40 protected Vector seqs;
42 * annotation to be added to generated alignment object
44 protected Vector annotations;
46 * Properties to be added to generated alignment object
48 protected Hashtable properties;
51 boolean jvSuffix = true;
54 * Creates a new AlignFile object.
61 * Constructor which parses the data from a file of some specified type.
62 * @param inFile Filename to read from.
63 * @param type What type of file to read from (File, URL)
65 public AlignFile(String inFile, String type)
76 * Return the seqs Vector
78 public Vector getSeqs()
84 * Return the Sequences in the seqs Vector as an array of Sequences
86 public SequenceI[] getSeqsAsArray()
88 SequenceI[] s = new SequenceI[seqs.size()];
90 for (int i = 0; i < seqs.size(); i++)
92 s[i] = (SequenceI) seqs.elementAt(i);
98 * called by AppletFormatAdapter to generate
99 * an annotated alignment, rather than bare
103 public void addAnnotations(Alignment al)
106 for (int i = 0; i < annotations.size(); i++)
109 (AlignmentAnnotation) annotations.elementAt(i)
115 * Add any additional information extracted
116 * from the file to the alignment properties.
117 * @note implicitly called by addAnnotations()
120 public void addProperties(Alignment al)
122 if (properties!=null && properties.size()>0)
124 Enumeration keys = properties.keys();
125 Enumeration vals = properties.elements();
126 while (keys.hasMoreElements())
128 al.setProperty(keys.nextElement(), vals.nextElement());
133 * Store a non-null key-value pair in a hashtable used to set alignment properties
134 * note: null keys will raise an error, null values will result in the key/value pair being silently ignored.
135 * @param key - non-null key object
136 * @param value - non-null value
138 protected void setAlignmentProperty(Object key, Object value)
142 throw new Error("Implementation error: Cannot have null alignment property key.");
146 return; // null properties are ignored.
148 if (properties==null)
150 properties = new Hashtable();
152 properties.put(key, value);
154 protected Object getAlignmentProperty(Object key)
156 if (properties!=null && key!=null)
158 return properties.get(key);
163 * Initialise objects to store sequence data in.
165 protected void initData()
168 annotations = new Vector();
174 * @param s DOCUMENT ME!
176 protected void setSeqs(SequenceI[] s)
180 for (int i = 0; i < s.length; i++)
182 seqs.addElement(s[i]);
187 * This method must be implemented to parse the contents of the file.
189 public abstract void parse()
193 * Print out in alignment file format the Sequences in the seqs Vector.
195 public abstract String print();
197 public void addJVSuffix(boolean b)
203 * A general parser for ids.
205 * @String id Id to be parsed
207 Sequence parseId(String id)
211 int space = id.indexOf(" ");
214 seq = new Sequence(id.substring(0, space), "");
215 seq.setDescription(id.substring(space + 1));
219 seq = new Sequence(id, "");
226 * Creates the output id.
227 * Adds prefix Uniprot format source|id
228 * And suffix Jalview /start-end
230 * @String id Id to be parsed
232 String printId(SequenceI seq)
234 return seq.getDisplayId(jvSuffix);
237 * vector of String[] treeName, newickString pairs
239 Vector newickStrings=null;
241 protected void addNewickTree(String treeName, String newickString)
243 if (newickStrings == null)
245 newickStrings = new Vector();
247 newickStrings.addElement(new String[] { treeName, newickString});
250 protected int getTreeCount()
252 if (newickStrings==null)
256 return newickStrings.size();