2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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)
57 public BLCFile(FileParse source) throws IOException
65 public void initData()
68 titles = new Vector();
71 * Control the number of block iterations to skip before returning.
72 * set to 0 to read first block file entry only
73 * set to -1 to read last block file entry only
74 * set to greater than zero to skip at most that many entries before parsing
78 * The iteration number for the alignment actually parsed from the blc file
88 StringBuffer headerLines=new StringBuffer();
89 int numHeaderLines = 0; // number of lines appended.
90 StringBuffer[] seqstrings=null;
93 iterationSkips = Integer.parseInt(suffix);
94 } catch (NumberFormatException e) {
95 iterationSkips = 0; // first
102 boolean idsFound = false;
103 boolean newids = false;
104 // search for ID header.
111 if (line.indexOf("*") > -1)
118 int abracket = line.indexOf(">");
123 if (iterationCount>0 && !newids) {
124 // we have a new set of IDs to record.
126 seqs.removeAllElements();
129 line = line.substring(abracket + 1);
131 Sequence seq = parseId(line);
132 seqs.addElement(seq);
134 // header lines - keep them for the alignment comments.
135 headerLines.append(line);
136 headerLines.append("\n");
142 break; // end of file.
143 int starCol = line.indexOf("*");
144 seqstrings = new StringBuffer[seqs.size()];
146 for (int i = 0; i < seqs.size(); i++)
148 if (seqstrings[i] == null)
150 seqstrings[i] = new StringBuffer();
156 while (line!=null && line.indexOf("*") == -1)
158 for (int i = 0; i < seqs.size(); i++)
160 if (line.length() > (i + starCol))
162 seqstrings[i].append(line.charAt(i + starCol));
167 } catch (IOException e) {
168 if (iterationCount==0) {
169 throw(e); // otherwise we've just run out of iterations.
175 } while (--iterationSkips!=-1);
177 for (int i = 0; i < seqs.size(); i++)
179 Sequence newSeq = (Sequence) seqs.elementAt(i);
181 newSeq.setSequence(seqstrings[i].toString());
185 if (headerLines.length()>1+numHeaderLines) // could see if buffer is just whitespace or not.
186 setAlignmentProperty("Comments", headerLines.toString());
187 setAlignmentProperty("iteration", ""+iterationCount);
194 * @return DOCUMENT ME!
196 public String print()
198 return print(getSeqsAsArray());
204 * @param s DOCUMENT ME!
206 * @return DOCUMENT ME!
208 public String print(SequenceI[] s)
210 StringBuffer out = new StringBuffer();
212 * A general parser for ids. Will look for dbrefs in
213 * Uniprot format source|id
214 * And also Jalview /start-end
216 * @String id Id to be parsed
221 while ( (i < s.length) && (s[i] != null))
223 out.append(">" + printId(s[i]));
224 if (s[i].getDescription() != null)
226 out.append(" " + s[i].getDescription());
231 if (s[i].getSequence().length > max)
233 max = s[i].getSequence().length;
239 out.append("* iteration 1\n");
241 for (int j = 0; j < max; j++)
245 while ( (i < s.length) && (s[i] != null))
247 if (s[i].getSequence().length > j)
249 out.append(s[i].getSequenceAsString(j, j + 1));
264 return out.toString();