2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
26 import jalview.datamodel.*;
34 public class BLCFile extends AlignFile
39 * Creates a new BLCFile object.
46 * Creates a new BLCFile object.
56 public BLCFile(String inFile, String type) throws IOException
61 public BLCFile(FileParse source) throws IOException
69 public void initData()
72 titles = new Vector();
76 * Control the number of block iterations to skip before returning. set to 0
77 * to read first block file entry only set to -1 to read last block file entry
78 * only set to greater than zero to skip at most that many entries before
81 int iterationSkips = 0;
84 * The iteration number for the alignment actually parsed from the blc file
86 int iterationCount = 0;
91 public void parse() throws IOException
93 StringBuffer headerLines = new StringBuffer();
94 int numHeaderLines = 0; // number of lines appended.
95 StringBuffer[] seqstrings = null;
100 iterationSkips = Integer.parseInt(suffix);
101 } catch (NumberFormatException e)
103 iterationSkips = 0; // first
111 boolean idsFound = false;
112 boolean newids = false;
113 // search for ID header.
120 if (line.indexOf("*") > -1)
127 int abracket = line.indexOf(">");
132 if (iterationCount > 0 && !newids)
134 // we have a new set of IDs to record.
136 seqs.removeAllElements();
139 line = line.substring(abracket + 1);
141 Sequence seq = parseId(line);
142 seqs.addElement(seq);
146 // header lines - keep them for the alignment comments.
147 headerLines.append(line);
148 headerLines.append(newline);
153 break; // end of file.
154 int starCol = line.indexOf("*");
155 seqstrings = new StringBuffer[seqs.size()];
157 for (int i = 0; i < seqs.size(); i++)
159 if (seqstrings[i] == null)
161 seqstrings[i] = new StringBuffer();
168 while (line != null && line.indexOf("*") == -1)
170 for (int i = 0; i < seqs.size(); i++)
172 if (line.length() > (i + starCol))
174 seqstrings[i].append(line.charAt(i + starCol));
179 } catch (IOException e)
181 if (iterationCount == 0)
183 throw (e); // otherwise we've just run out of iterations.
191 } while (--iterationSkips != -1);
193 for (int i = 0; i < seqs.size(); i++)
195 Sequence newSeq = (Sequence) seqs.elementAt(i);
197 newSeq.setSequence(seqstrings[i].toString());
201 if (headerLines.length() > 1 + numHeaderLines) // could see if buffer is
202 // just whitespace or not.
203 setAlignmentProperty("Comments", headerLines.toString());
204 setAlignmentProperty("iteration", "" + iterationCount);
211 * @return DOCUMENT ME!
213 public String print()
215 return print(getSeqsAsArray());
224 * @return DOCUMENT ME!
226 public String print(SequenceI[] s)
228 StringBuffer out = new StringBuffer();
230 * A general parser for ids. Will look for dbrefs in Uniprot format
231 * source|id And also Jalview /start-end
233 * @String id Id to be parsed
238 while ((i < s.length) && (s[i] != null))
240 out.append(">" + printId(s[i]));
241 if (s[i].getDescription() != null)
243 out.append(" " + s[i].getDescription());
248 if (s[i].getSequence().length > max)
250 max = s[i].getSequence().length;
256 out.append("* iteration 1");
259 for (int j = 0; j < max; j++)
263 while ((i < s.length) && (s[i] != null))
265 if (s[i].getSequence().length > j)
267 out.append(s[i].getSequenceAsString(j, j + 1));
283 return out.toString();