2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
21 import jalview.datamodel.*;
\r
32 * @version $Revision$
\r
34 public abstract class AlignFile extends FileParse
\r
42 boolean jvSuffix = true;
\r
45 * Creates a new AlignFile object.
\r
53 * Constructor which parses the data from a file of some specified type.
\r
54 * @param inFile Filename to read from.
\r
55 * @param type What type of file to read from (File, URL)
\r
57 public AlignFile(String inFile, String type) throws IOException
\r
59 super(inFile, type);
\r
67 * Return the seqs Vector
\r
69 public Vector getSeqs()
\r
75 * Return the Sequences in the seqs Vector as an array of Sequences
\r
77 public SequenceI[] getSeqsAsArray()
\r
79 SequenceI[] s = new SequenceI[seqs.size()];
\r
81 for (int i = 0; i < seqs.size(); i++)
\r
83 s[i] = (SequenceI) seqs.elementAt(i);
\r
90 * Initialise objects to store sequence data in.
\r
92 protected void initData()
\r
94 seqs = new Vector();
\r
95 headers = new Vector();
\r
101 * @param s DOCUMENT ME!
\r
103 protected void setSeqs(SequenceI[] s)
\r
105 seqs = new Vector();
\r
107 for (int i = 0; i < s.length; i++)
\r
109 seqs.addElement(s[i]);
\r
113 // Checks whether sequence is valid aa characters
\r
114 protected boolean isValidProteinSequence(char [] sequence)
\r
116 for (int i = 0; i < sequence.length; i++)
\r
117 if (jalview.schemes.ResidueProperties.aaIndex[sequence[i]]==-1)
\r
119 invalidCharacter = sequence[i];
\r
126 char invalidCharacter;
\r
129 * This method must be implemented to parse the contents of the file.
\r
131 public abstract void parse() throws IOException;
\r
134 * Print out in alignment file format the Sequences in the seqs Vector.
\r
136 public abstract String print();
\r
138 public void addJVSuffix(boolean b)
\r
144 * A general parser for ids.
\r
146 * @String id Id to be parsed
\r
148 Sequence parseId(String id)
\r
150 Sequence seq = null;
\r
152 int space = id.indexOf(" ");
\r
155 seq = new Sequence(id.substring(0, space),"");
\r
156 seq.setDescription(id.substring(space+1));
\r
160 seq = new Sequence(id, "");
\r
167 * Creates the output id.
\r
168 * Adds prefix Uniprot format source|id
\r
169 * And suffix Jalview /start-end
\r
171 * @String id Id to be parsed
\r
173 String printId(SequenceI seq)
\r
175 return seq.getDisplayId(jvSuffix);
\r