2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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)
75 * Attempt to read from the position where some other parsing process left off.
79 public AlignFile(FileParse source) throws IOException
86 * Return the seqs Vector
88 public Vector getSeqs()
94 * Return the Sequences in the seqs Vector as an array of Sequences
96 public SequenceI[] getSeqsAsArray()
98 SequenceI[] s = new SequenceI[seqs.size()];
100 for (int i = 0; i < seqs.size(); i++)
102 s[i] = (SequenceI) seqs.elementAt(i);
108 * called by AppletFormatAdapter to generate
109 * an annotated alignment, rather than bare
113 public void addAnnotations(Alignment al)
116 for (int i = 0; i < annotations.size(); i++)
119 (AlignmentAnnotation) annotations.elementAt(i)
125 * Add any additional information extracted
126 * from the file to the alignment properties.
127 * @note implicitly called by addAnnotations()
130 public void addProperties(Alignment al)
132 if (properties!=null && properties.size()>0)
134 Enumeration keys = properties.keys();
135 Enumeration vals = properties.elements();
136 while (keys.hasMoreElements())
138 al.setProperty(keys.nextElement(), vals.nextElement());
143 * Store a non-null key-value pair in a hashtable used to set alignment properties
144 * note: null keys will raise an error, null values will result in the key/value pair being silently ignored.
145 * @param key - non-null key object
146 * @param value - non-null value
148 protected void setAlignmentProperty(Object key, Object value)
152 throw new Error("Implementation error: Cannot have null alignment property key.");
156 return; // null properties are ignored.
158 if (properties==null)
160 properties = new Hashtable();
162 properties.put(key, value);
164 protected Object getAlignmentProperty(Object key)
166 if (properties!=null && key!=null)
168 return properties.get(key);
173 * Initialise objects to store sequence data in.
175 protected void initData()
178 annotations = new Vector();
184 * @param s DOCUMENT ME!
186 protected void setSeqs(SequenceI[] s)
190 for (int i = 0; i < s.length; i++)
192 seqs.addElement(s[i]);
197 * This method must be implemented to parse the contents of the file.
199 public abstract void parse()
203 * Print out in alignment file format the Sequences in the seqs Vector.
205 public abstract String print();
207 public void addJVSuffix(boolean b)
213 * A general parser for ids.
215 * @String id Id to be parsed
217 Sequence parseId(String id)
221 int space = id.indexOf(" ");
224 seq = new Sequence(id.substring(0, space), "");
225 seq.setDescription(id.substring(space + 1));
229 seq = new Sequence(id, "");
236 * Creates the output id.
237 * Adds prefix Uniprot format source|id
238 * And suffix Jalview /start-end
240 * @String id Id to be parsed
242 String printId(SequenceI seq)
244 return seq.getDisplayId(jvSuffix);
247 * vector of String[] treeName, newickString pairs
249 Vector newickStrings=null;
251 protected void addNewickTree(String treeName, String newickString)
253 if (newickStrings == null)
255 newickStrings = new Vector();
257 newickStrings.addElement(new String[] { treeName, newickString});
260 protected int getTreeCount()
262 if (newickStrings==null)
266 return newickStrings.size();