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 // detect if annotations.elementAt(i) rna secondary structure
133 * SequenceFeature[] pairArray =
134 * Rna.GetBasePairsFromAlignmentAnnotation(annotations.elementAt(i));
135 * Rna.HelixMap(pairArray);
137 AlignmentAnnotation an = (AlignmentAnnotation) annotations
139 an.validateRangeAndDisplay();
140 al.addAnnotation(an);
146 * Add any additional information extracted from the file to the alignment
149 * @note implicitly called by addAnnotations()
152 public void addProperties(Alignment al)
154 if (properties != null && properties.size() > 0)
156 Enumeration keys = properties.keys();
157 Enumeration vals = properties.elements();
158 while (keys.hasMoreElements())
160 al.setProperty(keys.nextElement(), vals.nextElement());
166 * Store a non-null key-value pair in a hashtable used to set alignment
167 * properties note: null keys will raise an error, null values will result in
168 * the key/value pair being silently ignored.
171 * - non-null key object
175 protected void setAlignmentProperty(Object key, Object value)
180 "Implementation error: Cannot have null alignment property key.");
184 return; // null properties are ignored.
186 if (properties == null)
188 properties = new Hashtable();
190 properties.put(key, value);
193 protected Object getAlignmentProperty(Object key)
195 if (properties != null && key != null)
197 return properties.get(key);
203 * Initialise objects to store sequence data in.
205 protected void initData()
208 annotations = new Vector();
217 protected void setSeqs(SequenceI[] s)
221 for (int i = 0; i < s.length; i++)
223 seqs.addElement(s[i]);
228 * This method must be implemented to parse the contents of the file.
230 public abstract void parse() throws IOException;
233 * Print out in alignment file format the Sequences in the seqs Vector.
235 public abstract String print();
237 public void addJVSuffix(boolean b)
243 * A general parser for ids.
245 * @String id Id to be parsed
247 Sequence parseId(String id)
251 int space = id.indexOf(" ");
254 seq = new Sequence(id.substring(0, space), "");
255 seq.setDescription(id.substring(space + 1));
259 seq = new Sequence(id, "");
266 * Creates the output id. Adds prefix Uniprot format source|id And suffix
269 * @String id Id to be parsed
271 String printId(SequenceI seq)
273 return seq.getDisplayId(jvSuffix);
277 * vector of String[] treeName, newickString pairs
279 Vector newickStrings = null;
281 protected void addNewickTree(String treeName, String newickString)
283 if (newickStrings == null)
285 newickStrings = new Vector();
287 newickStrings.addElement(new String[]
288 { treeName, newickString });
291 protected int getTreeCount()
293 if (newickStrings == null)
297 return newickStrings.size();