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[] seqstrings=null;
87 iterationSkips = Integer.parseInt(suffix);
88 } catch (NumberFormatException e) {
89 iterationSkips = 0; // first
96 boolean idsFound = false;
97 boolean newids = false;
98 // search for ID header.
105 if (line.indexOf("*") > -1)
112 int abracket = line.indexOf(">");
117 if (iterationCount>0 && !newids) {
118 // we have a new set of IDs to record.
120 seqs.removeAllElements();
123 line = line.substring(abracket + 1);
125 Sequence seq = parseId(line);
126 seqs.addElement(seq);
131 break; // end of file.
132 int starCol = line.indexOf("*");
133 seqstrings = new StringBuffer[seqs.size()];
135 for (int i = 0; i < seqs.size(); i++)
137 if (seqstrings[i] == null)
139 seqstrings[i] = new StringBuffer();
145 while (line!=null && line.indexOf("*") == -1)
147 for (int i = 0; i < seqs.size(); i++)
149 if (line.length() > (i + starCol))
151 seqstrings[i].append(line.charAt(i + starCol));
156 } catch (IOException e) {
157 if (iterationCount==0) {
158 throw(e); // otherwise we've just run out of iterations.
164 } while (--iterationSkips!=-1);
166 for (int i = 0; i < seqs.size(); i++)
168 Sequence newSeq = (Sequence) seqs.elementAt(i);
170 newSeq.setSequence(seqstrings[i].toString());
178 * @return DOCUMENT ME!
180 public String print()
182 return print(getSeqsAsArray());
188 * @param s DOCUMENT ME!
190 * @return DOCUMENT ME!
192 public String print(SequenceI[] s)
194 StringBuffer out = new StringBuffer();
196 * A general parser for ids. Will look for dbrefs in
197 * Uniprot format source|id
198 * And also Jalview /start-end
200 * @String id Id to be parsed
205 while ( (i < s.length) && (s[i] != null))
207 out.append(">" + printId(s[i]));
208 if (s[i].getDescription() != null)
210 out.append(" " + s[i].getDescription());
215 if (s[i].getSequence().length > max)
217 max = s[i].getSequence().length;
223 out.append("* iteration 1\n");
225 for (int j = 0; j < max; j++)
229 while ( (i < s.length) && (s[i] != null))
231 if (s[i].getSequence().length > j)
233 out.append(s[i].getSequenceAsString(j, j + 1));
248 return out.toString();