2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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
30 * @version $Revision$
\r
32 public class FastaFile extends AlignFile
\r
35 * Creates a new FastaFile object.
\r
42 * Creates a new FastaFile object.
\r
44 * @param inFile DOCUMENT ME!
\r
45 * @param type DOCUMENT ME!
\r
47 * @throws IOException DOCUMENT ME!
\r
49 public FastaFile(String inFile, String type) throws IOException
\r
51 super(inFile, type);
\r
57 * @throws IOException DOCUMENT ME!
\r
59 public void parse() throws IOException
\r
61 StringBuffer sb = new StringBuffer();
\r
65 Sequence seq = null;
\r
67 while ((line = nextLine()) != null)
\r
70 if (line.length() > 0)
\r
72 if (line.charAt(0)=='>')
\r
76 if (!isValidProteinSequence(sb.toString()))
\r
78 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS
\r
79 +" : "+seq.getName()
\r
80 +" : "+invalidCharacter);
\r
83 seq.setSequence(sb.toString());
\r
84 seqs.addElement(seq);
\r
87 seq = parseId(line.substring(1));
\r
90 sb = new StringBuffer();
\r
101 if (!isValidProteinSequence(sb.toString()))
\r
103 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS
\r
104 +" : "+seq.getName()
\r
105 +" : "+invalidCharacter);
\r
108 seq.setSequence(sb.toString());
\r
109 seqs.addElement(seq);
\r
117 * @param s DOCUMENT ME!
\r
118 * @param len DOCUMENT ME!
\r
119 * @param gaps DOCUMENT ME!
\r
120 * @param displayId DOCUMENT ME!
\r
122 * @return DOCUMENT ME!
\r
124 public String print(SequenceI[] s)
\r
127 StringBuffer out = new StringBuffer();
\r
130 while ((i < s.length) && (s[i] != null))
\r
132 out.append(">" + printId(s[i]));
\r
133 if(s[i].getDescription()!=null)
\r
134 out.append(" "+s[i].getDescription());
\r
138 int nochunks = (s[i].getLength() / len) + 1;
\r
140 for (int j = 0; j < nochunks; j++)
\r
142 int start = j * len;
\r
143 int end = start + len;
\r
145 if (end < s[i].getLength())
\r
147 out.append(s[i].getSequence(start, end) + "\n");
\r
149 else if (start < s[i].getLength())
\r
151 out.append(s[i].getSequence(start, s[i].getLength()) + "\n");
\r
158 return out.toString();
\r
164 * @return DOCUMENT ME!
\r
166 public String print()
\r
168 return print(getSeqsAsArray());
\r