2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
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(newline);
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");
257 for (int j = 0; j < max; j++)
261 while ((i < s.length) && (s[i] != null))
263 if (s[i].getSequence().length > j)
265 out.append(s[i].getSequenceAsString(j, j + 1));
281 return out.toString();