2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.
23 import jalview.datamodel.Sequence;
24 import jalview.datamodel.SequenceI;
26 import java.io.IOException;
27 import java.util.Vector;
35 public class BLCFile extends AlignFile
40 * Creates a new BLCFile object.
47 * Creates a new BLCFile object.
57 public BLCFile(String inFile, DataSourceType sourceType)
60 super(inFile, sourceType);
63 public BLCFile(FileParse source) throws IOException
72 public void initData()
75 titles = new Vector();
79 * Control the number of block iterations to skip before returning. set to 0
80 * to read first block file entry only set to -1 to read last block file entry
81 * only set to greater than zero to skip at most that many entries before
84 int iterationSkips = 0;
87 * The iteration number for the alignment actually parsed from the blc file
89 int iterationCount = 0;
95 public void parse() throws IOException
97 StringBuffer headerLines = new StringBuffer();
98 int numHeaderLines = 0; // number of lines appended.
99 StringBuffer[] seqstrings = null;
104 iterationSkips = Integer.parseInt(suffix);
105 } catch (NumberFormatException e)
107 iterationSkips = 0; // first
115 boolean idsFound = false;
116 boolean newids = false;
117 // search for ID header.
126 if (line.indexOf("*") > -1)
133 int abracket = line.indexOf(">");
138 if (iterationCount > 0 && !newids)
140 // we have a new set of IDs to record.
142 seqs.removeAllElements();
145 line = line.substring(abracket + 1);
147 Sequence seq = parseId(line);
148 seqs.addElement(seq);
152 // header lines - keep them for the alignment comments.
153 headerLines.append(line);
154 headerLines.append(newline);
160 break; // end of file.
162 int starCol = line.indexOf("*");
163 seqstrings = new StringBuffer[seqs.size()];
165 for (int i = 0; i < seqs.size(); i++)
167 if (seqstrings[i] == null)
169 seqstrings[i] = new StringBuffer();
176 while (line != null && line.indexOf("*") == -1)
178 for (int i = 0; i < seqs.size(); i++)
180 if (line.length() > (i + starCol))
182 seqstrings[i].append(line.charAt(i + starCol));
187 } catch (IOException e)
189 if (iterationCount == 0)
191 throw (e); // otherwise we've just run out of iterations.
199 } while (--iterationSkips != -1);
201 for (int i = 0; i < seqs.size(); i++)
203 Sequence newSeq = (Sequence) seqs.elementAt(i);
205 newSeq.setSequence(seqstrings[i].toString());
209 if (headerLines.length() > 1 + numHeaderLines)
211 // just whitespace or not.
212 setAlignmentProperty("Comments", headerLines.toString());
214 setAlignmentProperty("iteration", "" + iterationCount);
224 * @return DOCUMENT ME!
227 public String print(SequenceI[] s, boolean jvsuffix)
229 StringBuffer out = new StringBuffer();
231 * A general parser for ids. Will look for dbrefs in Uniprot format
232 * source|id And also Jalview /start-end
234 * @String id Id to be parsed
239 while ((i < s.length) && (s[i] != null))
241 out.append(">" + printId(s[i], jvsuffix));
242 if (s[i].getDescription() != null)
244 out.append(" " + s[i].getDescription());
249 max = Math.max(max, s[i].getLength());
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();