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 inStr DOCUMENT ME!
\r
46 public FastaFile(String inStr)
\r
52 * Creates a new FastaFile object.
\r
54 * @param inFile DOCUMENT ME!
\r
55 * @param type DOCUMENT ME!
\r
57 * @throws IOException DOCUMENT ME!
\r
59 public FastaFile(String inFile, String type) throws IOException
\r
61 super(inFile, type);
\r
67 * @throws IOException DOCUMENT ME!
\r
69 public void parse() throws IOException
\r
71 StringBuffer sb = new StringBuffer();
\r
75 Sequence seq = null;
\r
77 while ((line = nextLine()) != null)
\r
79 if (line.length() > 0)
\r
81 if (line.charAt(0)=='>')
\r
85 seq.setSequence(sb.toString());
\r
86 seqs.addElement(seq);
\r
89 seq = parseId(line.substring(1));
\r
92 sb = new StringBuffer();
\r
103 if (!isValidProteinSequence(sb.toString().toUpperCase()))
\r
105 throw new IOException("Invalid protein sequence");
\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