2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import jalview.datamodel.*;
31 public abstract class AlignFile extends FileParse
38 * Sequences to be added to form a new alignment.
40 protected Vector seqs;
43 * annotation to be added to generated alignment object
45 protected Vector annotations;
48 * Properties to be added to generated alignment object
50 protected Hashtable properties;
56 boolean jvSuffix = true;
59 * Creates a new AlignFile object.
66 * Constructor which parses the data from a file of some specified type.
69 * Filename to read from.
71 * What type of file to read from (File, URL)
73 public AlignFile(String inFile, String type) throws IOException
83 * Attempt to read from the position where some other parsing process left
89 public AlignFile(FileParse source) throws IOException
97 * Return the seqs Vector
99 public Vector getSeqs()
105 * Return the Sequences in the seqs Vector as an array of Sequences
107 public SequenceI[] getSeqsAsArray()
109 SequenceI[] s = new SequenceI[seqs.size()];
111 for (int i = 0; i < seqs.size(); i++)
113 s[i] = (SequenceI) seqs.elementAt(i);
120 * called by AppletFormatAdapter to generate an annotated alignment, rather
121 * than bare sequences.
125 public void addAnnotations(Alignment al)
128 for (int i = 0; i < annotations.size(); i++)
130 al.addAnnotation((AlignmentAnnotation) annotations.elementAt(i));
136 * Add any additional information extracted from the file to the alignment
139 * @note implicitly called by addAnnotations()
142 public void addProperties(Alignment al)
144 if (properties != null && properties.size() > 0)
146 Enumeration keys = properties.keys();
147 Enumeration vals = properties.elements();
148 while (keys.hasMoreElements())
150 al.setProperty(keys.nextElement(), vals.nextElement());
156 * Store a non-null key-value pair in a hashtable used to set alignment
157 * properties note: null keys will raise an error, null values will result in
158 * the key/value pair being silently ignored.
161 * - non-null key object
165 protected void setAlignmentProperty(Object key, Object value)
170 "Implementation error: Cannot have null alignment property key.");
174 return; // null properties are ignored.
176 if (properties == null)
178 properties = new Hashtable();
180 properties.put(key, value);
183 protected Object getAlignmentProperty(Object key)
185 if (properties != null && key != null)
187 return properties.get(key);
193 * Initialise objects to store sequence data in.
195 protected void initData()
198 annotations = new Vector();
207 protected void setSeqs(SequenceI[] s)
211 for (int i = 0; i < s.length; i++)
213 seqs.addElement(s[i]);
218 * This method must be implemented to parse the contents of the file.
220 public abstract void parse() throws IOException;
223 * Print out in alignment file format the Sequences in the seqs Vector.
225 public abstract String print();
227 public void addJVSuffix(boolean b)
233 * A general parser for ids.
235 * @String id Id to be parsed
237 Sequence parseId(String id)
241 int space = id.indexOf(" ");
244 seq = new Sequence(id.substring(0, space), "");
245 seq.setDescription(id.substring(space + 1));
249 seq = new Sequence(id, "");
256 * Creates the output id. Adds prefix Uniprot format source|id And suffix
259 * @String id Id to be parsed
261 String printId(SequenceI seq)
263 return seq.getDisplayId(jvSuffix);
267 * vector of String[] treeName, newickString pairs
269 Vector newickStrings = null;
271 protected void addNewickTree(String treeName, String newickString)
273 if (newickStrings == null)
275 newickStrings = new Vector();
277 newickStrings.addElement(new String[]
278 { treeName, newickString });
281 protected int getTreeCount()
283 if (newickStrings == null)
287 return newickStrings.size();