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
37 protected Vector seqs;
38 protected Vector annotations;
41 boolean jvSuffix = true;
44 * Creates a new AlignFile object.
51 * Constructor which parses the data from a file of some specified type.
52 * @param inFile Filename to read from.
53 * @param type What type of file to read from (File, URL)
55 public AlignFile(String inFile, String type)
66 * Return the seqs Vector
68 public Vector getSeqs()
74 * Return the Sequences in the seqs Vector as an array of Sequences
76 public SequenceI[] getSeqsAsArray()
78 SequenceI[] s = new SequenceI[seqs.size()];
80 for (int i = 0; i < seqs.size(); i++)
82 s[i] = (SequenceI) seqs.elementAt(i);
88 public void addAnnotations(Alignment al)
90 for (int i = 0; i < annotations.size(); i++)
93 (AlignmentAnnotation) annotations.elementAt(i)
100 * Initialise objects to store sequence data in.
102 protected void initData()
105 annotations = new Vector();
111 * @param s DOCUMENT ME!
113 protected void setSeqs(SequenceI[] s)
117 for (int i = 0; i < s.length; i++)
119 seqs.addElement(s[i]);
124 * This method must be implemented to parse the contents of the file.
126 public abstract void parse()
130 * Print out in alignment file format the Sequences in the seqs Vector.
132 public abstract String print();
134 public void addJVSuffix(boolean b)
140 * A general parser for ids.
142 * @String id Id to be parsed
144 Sequence parseId(String id)
148 int space = id.indexOf(" ");
151 seq = new Sequence(id.substring(0, space), "");
152 seq.setDescription(id.substring(space + 1));
156 seq = new Sequence(id, "");
163 * Creates the output id.
164 * Adds prefix Uniprot format source|id
165 * And suffix Jalview /start-end
167 * @String id Id to be parsed
169 String printId(SequenceI seq)
171 return seq.getDisplayId(jvSuffix);