2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import jalview.datamodel.*;
31 public class BLCFile extends AlignFile
36 * Creates a new BLCFile object.
43 * Creates a new BLCFile object.
53 public BLCFile(String inFile, String type) throws IOException
58 public BLCFile(FileParse source) throws IOException
66 public void initData()
69 titles = new Vector();
73 * Control the number of block iterations to skip before returning. set to 0
74 * to read first block file entry only set to -1 to read last block file entry
75 * only set to greater than zero to skip at most that many entries before
78 int iterationSkips = 0;
81 * The iteration number for the alignment actually parsed from the blc file
83 int iterationCount = 0;
88 public void parse() throws IOException
90 StringBuffer headerLines = new StringBuffer();
91 int numHeaderLines = 0; // number of lines appended.
92 StringBuffer[] seqstrings = null;
97 iterationSkips = Integer.parseInt(suffix);
98 } catch (NumberFormatException e)
100 iterationSkips = 0; // first
108 boolean idsFound = false;
109 boolean newids = false;
110 // search for ID header.
117 if (line.indexOf("*") > -1)
124 int abracket = line.indexOf(">");
129 if (iterationCount > 0 && !newids)
131 // we have a new set of IDs to record.
133 seqs.removeAllElements();
136 line = line.substring(abracket + 1);
138 Sequence seq = parseId(line);
139 seqs.addElement(seq);
143 // header lines - keep them for the alignment comments.
144 headerLines.append(line);
145 headerLines.append(newline);
150 break; // end of file.
151 int starCol = line.indexOf("*");
152 seqstrings = new StringBuffer[seqs.size()];
154 for (int i = 0; i < seqs.size(); i++)
156 if (seqstrings[i] == null)
158 seqstrings[i] = new StringBuffer();
165 while (line != null && line.indexOf("*") == -1)
167 for (int i = 0; i < seqs.size(); i++)
169 if (line.length() > (i + starCol))
171 seqstrings[i].append(line.charAt(i + starCol));
176 } catch (IOException e)
178 if (iterationCount == 0)
180 throw (e); // otherwise we've just run out of iterations.
188 } while (--iterationSkips != -1);
190 for (int i = 0; i < seqs.size(); i++)
192 Sequence newSeq = (Sequence) seqs.elementAt(i);
194 newSeq.setSequence(seqstrings[i].toString());
198 if (headerLines.length() > 1 + numHeaderLines) // could see if buffer is
199 // just whitespace or not.
200 setAlignmentProperty("Comments", headerLines.toString());
201 setAlignmentProperty("iteration", "" + iterationCount);
208 * @return DOCUMENT ME!
210 public String print()
212 return print(getSeqsAsArray());
221 * @return DOCUMENT ME!
223 public String print(SequenceI[] s)
225 StringBuffer out = new StringBuffer();
227 * A general parser for ids. Will look for dbrefs in Uniprot format
228 * source|id And also Jalview /start-end
230 * @String id Id to be parsed
235 while ((i < s.length) && (s[i] != null))
237 out.append(">" + printId(s[i]));
238 if (s[i].getDescription() != null)
240 out.append(" " + s[i].getDescription());
245 if (s[i].getSequence().length > max)
247 max = s[i].getSequence().length;
253 out.append("* iteration 1");
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));
280 return out.toString();