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