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
80 if (line.length() > 0)
\r
82 if (line.charAt(0)=='>')
\r
86 if (!isValidProteinSequence(sb.toString()))
\r
88 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS
\r
89 +" : "+seq.getName()
\r
90 +" : "+invalidCharacter);
\r
93 seq.setSequence(sb.toString());
\r
94 seqs.addElement(seq);
\r
97 seq = parseId(line.substring(1));
\r
100 sb = new StringBuffer();
\r
111 if (!isValidProteinSequence(sb.toString()))
\r
113 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS
\r
114 +" : "+seq.getName()
\r
115 +" : "+invalidCharacter);
\r
118 seq.setSequence(sb.toString());
\r
119 seqs.addElement(seq);
\r
127 * @param s DOCUMENT ME!
\r
128 * @param len DOCUMENT ME!
\r
129 * @param gaps DOCUMENT ME!
\r
130 * @param displayId DOCUMENT ME!
\r
132 * @return DOCUMENT ME!
\r
134 public String print(SequenceI[] s)
\r
137 StringBuffer out = new StringBuffer();
\r
140 while ((i < s.length) && (s[i] != null))
\r
142 out.append(">" + printId(s[i]));
\r
143 if(s[i].getDescription()!=null)
\r
144 out.append(" "+s[i].getDescription());
\r
148 int nochunks = (s[i].getLength() / len) + 1;
\r
150 for (int j = 0; j < nochunks; j++)
\r
152 int start = j * len;
\r
153 int end = start + len;
\r
155 if (end < s[i].getLength())
\r
157 out.append(s[i].getSequence(start, end) + "\n");
\r
159 else if (start < s[i].getLength())
\r
161 out.append(s[i].getSequence(start, s[i].getLength()) + "\n");
\r
168 return out.toString();
\r
174 * @return DOCUMENT ME!
\r
176 public String print()
\r
178 return print(getSeqsAsArray());
\r