2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import jalview.datamodel.*;
38 * Creates a new BLCFile object.
45 * Creates a new BLCFile object.
47 * @param inFile DOCUMENT ME!
48 * @param type DOCUMENT ME!
50 * @throws IOException DOCUMENT ME!
52 public BLCFile(String inFile, String type)
61 public void initData()
64 titles = new Vector();
67 * Control the number of block iterations to skip before returning.
68 * set to 0 to read first block file entry only
69 * set to -1 to read last block file entry only
70 * set to greater than zero to skip at most that many entries before parsing
74 * The iteration number for the alignment actually parsed from the blc file
84 StringBuffer headerLines=new StringBuffer();
85 int numHeaderLines = 0; // number of lines appended.
86 StringBuffer[] seqstrings=null;
89 iterationSkips = Integer.parseInt(suffix);
90 } catch (NumberFormatException e) {
91 iterationSkips = 0; // first
98 boolean idsFound = false;
99 boolean newids = false;
100 // search for ID header.
107 if (line.indexOf("*") > -1)
114 int abracket = line.indexOf(">");
119 if (iterationCount>0 && !newids) {
120 // we have a new set of IDs to record.
122 seqs.removeAllElements();
125 line = line.substring(abracket + 1);
127 Sequence seq = parseId(line);
128 seqs.addElement(seq);
130 // header lines - keep them for the alignment comments.
131 headerLines.append(line);
132 headerLines.append("\n");
138 break; // end of file.
139 int starCol = line.indexOf("*");
140 seqstrings = new StringBuffer[seqs.size()];
142 for (int i = 0; i < seqs.size(); i++)
144 if (seqstrings[i] == null)
146 seqstrings[i] = new StringBuffer();
152 while (line!=null && line.indexOf("*") == -1)
154 for (int i = 0; i < seqs.size(); i++)
156 if (line.length() > (i + starCol))
158 seqstrings[i].append(line.charAt(i + starCol));
163 } catch (IOException e) {
164 if (iterationCount==0) {
165 throw(e); // otherwise we've just run out of iterations.
171 } while (--iterationSkips!=-1);
173 for (int i = 0; i < seqs.size(); i++)
175 Sequence newSeq = (Sequence) seqs.elementAt(i);
177 newSeq.setSequence(seqstrings[i].toString());
181 if (headerLines.length()>1+numHeaderLines) // could see if buffer is just whitespace or not.
182 setAlignmentProperty("Comments", headerLines.toString());
183 setAlignmentProperty("iteration", ""+iterationCount);
190 * @return DOCUMENT ME!
192 public String print()
194 return print(getSeqsAsArray());
200 * @param s DOCUMENT ME!
202 * @return DOCUMENT ME!
204 public String print(SequenceI[] s)
206 StringBuffer out = new StringBuffer();
208 * A general parser for ids. Will look for dbrefs in
209 * Uniprot format source|id
210 * And also Jalview /start-end
212 * @String id Id to be parsed
217 while ( (i < s.length) && (s[i] != null))
219 out.append(">" + printId(s[i]));
220 if (s[i].getDescription() != null)
222 out.append(" " + s[i].getDescription());
227 if (s[i].getSequence().length > max)
229 max = s[i].getSequence().length;
235 out.append("* iteration 1\n");
237 for (int j = 0; j < max; j++)
241 while ( (i < s.length) && (s[i] != null))
243 if (s[i].getSequence().length > j)
245 out.append(s[i].getSequenceAsString(j, j + 1));
260 return out.toString();