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());
132 protected void setAlignmentProperty(Object key, Object value)
136 throw new Error("Implementation error: Cannot have null alignment property key.");
138 if (properties==null)
140 properties = new Hashtable();
142 properties.put(key, value);
144 protected Object getAlignmentProperty(Object key)
146 if (properties!=null && key!=null)
148 return properties.get(key);
153 * Initialise objects to store sequence data in.
155 protected void initData()
158 annotations = new Vector();
164 * @param s DOCUMENT ME!
166 protected void setSeqs(SequenceI[] s)
170 for (int i = 0; i < s.length; i++)
172 seqs.addElement(s[i]);
177 * This method must be implemented to parse the contents of the file.
179 public abstract void parse()
183 * Print out in alignment file format the Sequences in the seqs Vector.
185 public abstract String print();
187 public void addJVSuffix(boolean b)
193 * A general parser for ids.
195 * @String id Id to be parsed
197 Sequence parseId(String id)
201 int space = id.indexOf(" ");
204 seq = new Sequence(id.substring(0, space), "");
205 seq.setDescription(id.substring(space + 1));
209 seq = new Sequence(id, "");
216 * Creates the output id.
217 * Adds prefix Uniprot format source|id
218 * And suffix Jalview /start-end
220 * @String id Id to be parsed
222 String printId(SequenceI seq)
224 return seq.getDisplayId(jvSuffix);