2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import javax.xml.parsers.ParserConfigurationException;
25 import org.xml.sax.SAXException;
27 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
28 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
29 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
31 import jalview.datamodel.*;
39 public class BLCFile extends AlignFile
44 * Creates a new BLCFile object.
51 * Creates a new BLCFile object.
60 * @throws SAXException
61 * @throws ParserConfigurationException
62 * @throws ExceptionFileFormatOrSyntax
63 * @throws ExceptionLoadingFailed
64 * @throws ExceptionPermissionDenied
66 public BLCFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
71 public BLCFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
79 public void initData()
82 titles = new Vector();
86 * Control the number of block iterations to skip before returning. set to 0
87 * to read first block file entry only set to -1 to read last block file entry
88 * only set to greater than zero to skip at most that many entries before
91 int iterationSkips = 0;
94 * The iteration number for the alignment actually parsed from the blc file
96 int iterationCount = 0;
101 public void parse() throws IOException
103 StringBuffer headerLines = new StringBuffer();
104 int numHeaderLines = 0; // number of lines appended.
105 StringBuffer[] seqstrings = null;
110 iterationSkips = Integer.parseInt(suffix);
111 } catch (NumberFormatException e)
113 iterationSkips = 0; // first
121 boolean idsFound = false;
122 boolean newids = false;
123 // search for ID header.
130 if (line.indexOf("*") > -1)
137 int abracket = line.indexOf(">");
142 if (iterationCount > 0 && !newids)
144 // we have a new set of IDs to record.
146 seqs.removeAllElements();
149 line = line.substring(abracket + 1);
151 Sequence seq = parseId(line);
152 seqs.addElement(seq);
156 // header lines - keep them for the alignment comments.
157 headerLines.append(line);
158 headerLines.append(newline);
163 break; // end of file.
164 int starCol = line.indexOf("*");
165 seqstrings = new StringBuffer[seqs.size()];
167 for (int i = 0; i < seqs.size(); i++)
169 if (seqstrings[i] == null)
171 seqstrings[i] = new StringBuffer();
178 while (line != null && line.indexOf("*") == -1)
180 for (int i = 0; i < seqs.size(); i++)
182 if (line.length() > (i + starCol))
184 seqstrings[i].append(line.charAt(i + starCol));
189 } catch (IOException e)
191 if (iterationCount == 0)
193 throw (e); // otherwise we've just run out of iterations.
201 } while (--iterationSkips != -1);
203 for (int i = 0; i < seqs.size(); i++)
205 Sequence newSeq = (Sequence) seqs.elementAt(i);
207 newSeq.setSequence(seqstrings[i].toString());
211 if (headerLines.length() > 1 + numHeaderLines) // could see if buffer is
212 // just whitespace or not.
213 setAlignmentProperty("Comments", headerLines.toString());
214 setAlignmentProperty("iteration", "" + iterationCount);
221 * @return DOCUMENT ME!
223 public String print()
225 return print(getSeqsAsArray());
234 * @return DOCUMENT ME!
236 public String print(SequenceI[] s)
238 StringBuffer out = new StringBuffer();
240 * A general parser for ids. Will look for dbrefs in Uniprot format
241 * source|id And also Jalview /start-end
243 * @String id Id to be parsed
248 while ((i < s.length) && (s[i] != null))
250 out.append(">" + printId(s[i]));
251 if (s[i].getDescription() != null)
253 out.append(" " + s[i].getDescription());
258 if (s[i].getSequence().length > max)
260 max = s[i].getSequence().length;
266 out.append("* iteration 1");
269 for (int j = 0; j < max; j++)
273 while ((i < s.length) && (s[i] != null))
275 if (s[i].getSequence().length > j)
277 out.append(s[i].getSequenceAsString(j, j + 1));
293 return out.toString();