2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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 extends FileParse
39 * Sequences to be added to form a new alignment.
41 protected Vector seqs;
44 * annotation to be added to generated alignment object
46 protected Vector annotations;
49 * Properties to be added to generated alignment object
51 protected Hashtable properties;
57 boolean jvSuffix = true;
60 * Creates a new AlignFile object.
67 * Constructor which parses the data from a file of some specified type.
70 * Filename to read from.
72 * What type of file to read from (File, URL)
74 public AlignFile(String inFile, String type) throws IOException
84 * Attempt to read from the position where some other parsing process left
90 public AlignFile(FileParse source) throws IOException
98 * Return the seqs Vector
100 public Vector getSeqs()
106 * Return the Sequences in the seqs Vector as an array of Sequences
108 public SequenceI[] getSeqsAsArray()
110 SequenceI[] s = new SequenceI[seqs.size()];
112 for (int i = 0; i < seqs.size(); i++)
114 s[i] = (SequenceI) seqs.elementAt(i);
121 * called by AppletFormatAdapter to generate an annotated alignment, rather
122 * than bare sequences.
126 public void addAnnotations(Alignment al)
129 for (int i = 0; i < annotations.size(); i++)
131 al.addAnnotation((AlignmentAnnotation) annotations.elementAt(i));
137 * Add any additional information extracted from the file to the alignment
140 * @note implicitly called by addAnnotations()
143 public void addProperties(Alignment al)
145 if (properties != null && properties.size() > 0)
147 Enumeration keys = properties.keys();
148 Enumeration vals = properties.elements();
149 while (keys.hasMoreElements())
151 al.setProperty(keys.nextElement(), vals.nextElement());
157 * Store a non-null key-value pair in a hashtable used to set alignment
158 * properties note: null keys will raise an error, null values will result in
159 * the key/value pair being silently ignored.
162 * non-null key object
166 protected void setAlignmentProperty(Object key, Object value)
171 "Implementation error: Cannot have null alignment property key.");
175 return; // null properties are ignored.
177 if (properties == null)
179 properties = new Hashtable();
181 properties.put(key, value);
184 protected Object getAlignmentProperty(Object key)
186 if (properties != null && key != null)
188 return properties.get(key);
194 * Initialise objects to store sequence data in.
196 protected void initData()
199 annotations = new Vector();
208 protected void setSeqs(SequenceI[] s)
212 for (int i = 0; i < s.length; i++)
214 seqs.addElement(s[i]);
219 * This method must be implemented to parse the contents of the file.
221 public abstract void parse() throws IOException;
224 * Print out in alignment file format the Sequences in the seqs Vector.
226 public abstract String print();
228 public void addJVSuffix(boolean b)
234 * A general parser for ids.
236 * @String id Id to be parsed
238 Sequence parseId(String id)
242 int space = id.indexOf(" ");
245 seq = new Sequence(id.substring(0, space), "");
246 seq.setDescription(id.substring(space + 1));
250 seq = new Sequence(id, "");
257 * Creates the output id. Adds prefix Uniprot format source|id And suffix
260 * @String id Id to be parsed
262 String printId(SequenceI seq)
264 return seq.getDisplayId(jvSuffix);
268 * vector of String[] treeName, newickString pairs
270 Vector newickStrings = null;
272 protected void addNewickTree(String treeName, String newickString)
274 if (newickStrings == null)
276 newickStrings = new Vector();
278 newickStrings.addElement(new String[]
279 { treeName, newickString });
282 protected int getTreeCount()
284 if (newickStrings == null)
288 return newickStrings.size();