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
65 * @throws InterruptedException
67 public BLCFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException
72 public BLCFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException
80 public void initData()
83 titles = new Vector();
87 * Control the number of block iterations to skip before returning. set to 0
88 * to read first block file entry only set to -1 to read last block file entry
89 * only set to greater than zero to skip at most that many entries before
92 int iterationSkips = 0;
95 * The iteration number for the alignment actually parsed from the blc file
97 int iterationCount = 0;
102 public void parse() throws IOException
104 StringBuffer headerLines = new StringBuffer();
105 int numHeaderLines = 0; // number of lines appended.
106 StringBuffer[] seqstrings = null;
111 iterationSkips = Integer.parseInt(suffix);
112 } catch (NumberFormatException e)
114 iterationSkips = 0; // first
122 boolean idsFound = false;
123 boolean newids = false;
124 // search for ID header.
131 if (line.indexOf("*") > -1)
138 int abracket = line.indexOf(">");
143 if (iterationCount > 0 && !newids)
145 // we have a new set of IDs to record.
147 seqs.removeAllElements();
150 line = line.substring(abracket + 1);
152 Sequence seq = parseId(line);
153 seqs.addElement(seq);
157 // header lines - keep them for the alignment comments.
158 headerLines.append(line);
159 headerLines.append(newline);
164 break; // end of file.
165 int starCol = line.indexOf("*");
166 seqstrings = new StringBuffer[seqs.size()];
168 for (int i = 0; i < seqs.size(); i++)
170 if (seqstrings[i] == null)
172 seqstrings[i] = new StringBuffer();
179 while (line != null && line.indexOf("*") == -1)
181 for (int i = 0; i < seqs.size(); i++)
183 if (line.length() > (i + starCol))
185 seqstrings[i].append(line.charAt(i + starCol));
190 } catch (IOException e)
192 if (iterationCount == 0)
194 throw (e); // otherwise we've just run out of iterations.
202 } while (--iterationSkips != -1);
204 for (int i = 0; i < seqs.size(); i++)
206 Sequence newSeq = (Sequence) seqs.elementAt(i);
208 newSeq.setSequence(seqstrings[i].toString());
212 if (headerLines.length() > 1 + numHeaderLines) // could see if buffer is
213 // just whitespace or not.
214 setAlignmentProperty("Comments", headerLines.toString());
215 setAlignmentProperty("iteration", "" + iterationCount);
222 * @return DOCUMENT ME!
224 public String print()
226 return print(getSeqsAsArray());
235 * @return DOCUMENT ME!
237 public String print(SequenceI[] s)
239 StringBuffer out = new StringBuffer();
241 * A general parser for ids. Will look for dbrefs in Uniprot format
242 * source|id And also Jalview /start-end
244 * @String id Id to be parsed
249 while ((i < s.length) && (s[i] != null))
251 out.append(">" + printId(s[i]));
252 if (s[i].getDescription() != null)
254 out.append(" " + s[i].getDescription());
259 if (s[i].getSequence().length > max)
261 max = s[i].getSequence().length;
267 out.append("* iteration 1");
270 for (int j = 0; j < max; j++)
274 while ((i < s.length) && (s[i] != null))
276 if (s[i].getSequence().length > j)
278 out.append(s[i].getSequenceAsString(j, j + 1));
294 return out.toString();