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, String type) throws IOException
62 public BLCFile(FileParse source) throws IOException
70 public void initData()
73 titles = new Vector();
77 * Control the number of block iterations to skip before returning. set to 0
78 * to read first block file entry only set to -1 to read last block file entry
79 * only set to greater than zero to skip at most that many entries before
82 int iterationSkips = 0;
85 * The iteration number for the alignment actually parsed from the blc file
87 int iterationCount = 0;
92 public void parse() throws IOException
94 StringBuffer headerLines = new StringBuffer();
95 int numHeaderLines = 0; // number of lines appended.
96 StringBuffer[] seqstrings = null;
101 iterationSkips = Integer.parseInt(suffix);
102 } catch (NumberFormatException e)
104 iterationSkips = 0; // first
112 boolean idsFound = false;
113 boolean newids = false;
114 // search for ID header.
123 if (line.indexOf("*") > -1)
130 int abracket = line.indexOf(">");
135 if (iterationCount > 0 && !newids)
137 // we have a new set of IDs to record.
139 seqs.removeAllElements();
142 line = line.substring(abracket + 1);
144 Sequence seq = parseId(line);
145 seqs.addElement(seq);
149 // header lines - keep them for the alignment comments.
150 headerLines.append(line);
151 headerLines.append(newline);
157 break; // end of file.
159 int starCol = line.indexOf("*");
160 seqstrings = new StringBuffer[seqs.size()];
162 for (int i = 0; i < seqs.size(); i++)
164 if (seqstrings[i] == null)
166 seqstrings[i] = new StringBuffer();
173 while (line != null && line.indexOf("*") == -1)
175 for (int i = 0; i < seqs.size(); i++)
177 if (line.length() > (i + starCol))
179 seqstrings[i].append(line.charAt(i + starCol));
184 } catch (IOException e)
186 if (iterationCount == 0)
188 throw (e); // otherwise we've just run out of iterations.
196 } while (--iterationSkips != -1);
198 for (int i = 0; i < seqs.size(); i++)
200 Sequence newSeq = (Sequence) seqs.elementAt(i);
202 newSeq.setSequence(seqstrings[i].toString());
206 if (headerLines.length() > 1 + numHeaderLines)
208 // just whitespace or not.
209 setAlignmentProperty("Comments", headerLines.toString());
211 setAlignmentProperty("iteration", "" + iterationCount);
218 * @return DOCUMENT ME!
220 public String print()
222 return print(getSeqsAsArray());
231 * @return DOCUMENT ME!
233 public String print(SequenceI[] s)
235 StringBuffer out = new StringBuffer();
237 * A general parser for ids. Will look for dbrefs in Uniprot format
238 * source|id And also Jalview /start-end
240 * @String id Id to be parsed
245 while ((i < s.length) && (s[i] != null))
247 out.append(">" + printId(s[i]));
248 if (s[i].getDescription() != null)
250 out.append(" " + s[i].getDescription());
255 if (s[i].getSequence().length > max)
257 max = s[i].getSequence().length;
263 out.append("* iteration 1");
266 for (int j = 0; j < max; j++)
270 while ((i < s.length) && (s[i] != null))
272 if (s[i].getSequence().length > j)
274 out.append(s[i].getSequenceAsString(j, j + 1));
290 return out.toString();