2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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
24 import jalview.datamodel.*;
32 public class BLCFile extends AlignFile
37 * Creates a new BLCFile object.
44 * Creates a new BLCFile object.
54 public BLCFile(String inFile, String type) throws IOException
59 public BLCFile(FileParse source) throws IOException
67 public void initData()
70 titles = new Vector();
74 * Control the number of block iterations to skip before returning. set to 0
75 * to read first block file entry only set to -1 to read last block file entry
76 * only set to greater than zero to skip at most that many entries before
79 int iterationSkips = 0;
82 * The iteration number for the alignment actually parsed from the blc file
84 int iterationCount = 0;
89 public void parse() throws IOException
91 StringBuffer headerLines = new StringBuffer();
92 int numHeaderLines = 0; // number of lines appended.
93 StringBuffer[] seqstrings = null;
98 iterationSkips = Integer.parseInt(suffix);
99 } catch (NumberFormatException e)
101 iterationSkips = 0; // first
109 boolean idsFound = false;
110 boolean newids = false;
111 // search for ID header.
118 if (line.indexOf("*") > -1)
125 int abracket = line.indexOf(">");
130 if (iterationCount > 0 && !newids)
132 // we have a new set of IDs to record.
134 seqs.removeAllElements();
137 line = line.substring(abracket + 1);
139 Sequence seq = parseId(line);
140 seqs.addElement(seq);
144 // header lines - keep them for the alignment comments.
145 headerLines.append(line);
146 headerLines.append("\n");
151 break; // end of file.
152 int starCol = line.indexOf("*");
153 seqstrings = new StringBuffer[seqs.size()];
155 for (int i = 0; i < seqs.size(); i++)
157 if (seqstrings[i] == null)
159 seqstrings[i] = new StringBuffer();
166 while (line != null && line.indexOf("*") == -1)
168 for (int i = 0; i < seqs.size(); i++)
170 if (line.length() > (i + starCol))
172 seqstrings[i].append(line.charAt(i + starCol));
177 } catch (IOException e)
179 if (iterationCount == 0)
181 throw (e); // otherwise we've just run out of iterations.
189 } while (--iterationSkips != -1);
191 for (int i = 0; i < seqs.size(); i++)
193 Sequence newSeq = (Sequence) seqs.elementAt(i);
195 newSeq.setSequence(seqstrings[i].toString());
199 if (headerLines.length() > 1 + numHeaderLines) // could see if buffer is
200 // just whitespace or not.
201 setAlignmentProperty("Comments", headerLines.toString());
202 setAlignmentProperty("iteration", "" + iterationCount);
209 * @return DOCUMENT ME!
211 public String print()
213 return print(getSeqsAsArray());
222 * @return DOCUMENT ME!
224 public String print(SequenceI[] s)
226 StringBuffer out = new StringBuffer();
228 * A general parser for ids. Will look for dbrefs in Uniprot format
229 * source|id And also Jalview /start-end
231 * @String id Id to be parsed
236 while ((i < s.length) && (s[i] != null))
238 out.append(">" + printId(s[i]));
239 if (s[i].getDescription() != null)
241 out.append(" " + s[i].getDescription());
246 if (s[i].getSequence().length > max)
248 max = s[i].getSequence().length;
254 out.append("* iteration 1\n");
256 for (int j = 0; j < max; j++)
260 while ((i < s.length) && (s[i] != null))
262 if (s[i].getSequence().length > j)
264 out.append(s[i].getSequenceAsString(j, j + 1));
279 return out.toString();