2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 import jalview.datamodel.*;
34 public abstract class AlignFile extends FileParse
42 boolean jvSuffix = true;
45 * Creates a new AlignFile object.
53 * Constructor which parses the data from a file of some specified type.
54 * @param inFile Filename to read from.
55 * @param type What type of file to read from (File, URL)
57 public AlignFile(String inFile, String type) throws IOException
67 * Return the seqs Vector
69 public Vector getSeqs()
75 * Return the Sequences in the seqs Vector as an array of Sequences
77 public SequenceI[] getSeqsAsArray()
79 SequenceI[] s = new SequenceI[seqs.size()];
81 for (int i = 0; i < seqs.size(); i++)
83 s[i] = (SequenceI) seqs.elementAt(i);
90 * Initialise objects to store sequence data in.
92 protected void initData()
95 headers = new Vector();
101 * @param s DOCUMENT ME!
103 protected void setSeqs(SequenceI[] s)
107 for (int i = 0; i < s.length; i++)
109 seqs.addElement(s[i]);
113 // Checks whether sequence is valid aa characters
114 protected boolean isValidProteinSequence(String sequence)
116 for (int i = 0; i < sequence.length(); i++)
117 if (!jalview.schemes.ResidueProperties.aaHash.containsKey(
118 String.valueOf(sequence.charAt(i))))
120 invalidCharacter = sequence.charAt(i);
127 char invalidCharacter;
130 * This method must be implemented to parse the contents of the file.
132 public abstract void parse() throws IOException;
135 * Print out in alignment file format the Sequences in the seqs Vector.
137 public abstract String print();
139 public void addJVSuffix(boolean b)
145 * A general parser for ids.
147 * @String id Id to be parsed
149 Sequence parseId(String id)
153 int space = id.indexOf(" ");
156 seq = new Sequence(id.substring(0, space),"");
157 seq.setDescription(id.substring(space+1));
161 seq = new Sequence(id, "");
168 * Creates the output id.
169 * Adds prefix Uniprot format source|id
170 * And suffix Jalview /start-end
172 * @String id Id to be parsed
174 String printId(SequenceI seq)
176 return seq.getDisplayId(jvSuffix);