2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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;
30 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
32 import jalview.datamodel.*;
40 public class BLCFile extends AlignFile
45 * Creates a new BLCFile object.
52 * Creates a new BLCFile object.
61 * @throws SAXException
62 * @throws ParserConfigurationException
63 * @throws ExceptionFileFormatOrSyntax
64 * @throws ExceptionLoadingFailed
65 * @throws ExceptionPermissionDenied
66 * @throws InterruptedException
67 * @throws ExceptionUnmatchedClosingParentheses
69 public BLCFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
74 public BLCFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
82 public void initData()
85 titles = new Vector();
89 * Control the number of block iterations to skip before returning. set to 0
90 * to read first block file entry only set to -1 to read last block file entry
91 * only set to greater than zero to skip at most that many entries before
94 int iterationSkips = 0;
97 * The iteration number for the alignment actually parsed from the blc file
99 int iterationCount = 0;
104 public void parse() throws IOException
106 StringBuffer headerLines = new StringBuffer();
107 int numHeaderLines = 0; // number of lines appended.
108 StringBuffer[] seqstrings = null;
113 iterationSkips = Integer.parseInt(suffix);
114 } catch (NumberFormatException e)
116 iterationSkips = 0; // first
124 boolean idsFound = false;
125 boolean newids = false;
126 // search for ID header.
133 if (line.indexOf("*") > -1)
140 int abracket = line.indexOf(">");
145 if (iterationCount > 0 && !newids)
147 // we have a new set of IDs to record.
149 seqs.removeAllElements();
152 line = line.substring(abracket + 1);
154 Sequence seq = parseId(line);
155 seqs.addElement(seq);
159 // header lines - keep them for the alignment comments.
160 headerLines.append(line);
161 headerLines.append(newline);
166 break; // end of file.
167 int starCol = line.indexOf("*");
168 seqstrings = new StringBuffer[seqs.size()];
170 for (int i = 0; i < seqs.size(); i++)
172 if (seqstrings[i] == null)
174 seqstrings[i] = new StringBuffer();
181 while (line != null && line.indexOf("*") == -1)
183 for (int i = 0; i < seqs.size(); i++)
185 if (line.length() > (i + starCol))
187 seqstrings[i].append(line.charAt(i + starCol));
192 } catch (IOException e)
194 if (iterationCount == 0)
196 throw (e); // otherwise we've just run out of iterations.
204 } while (--iterationSkips != -1);
206 for (int i = 0; i < seqs.size(); i++)
208 Sequence newSeq = (Sequence) seqs.elementAt(i);
210 newSeq.setSequence(seqstrings[i].toString());
214 if (headerLines.length() > 1 + numHeaderLines) // could see if buffer is
215 // just whitespace or not.
216 setAlignmentProperty("Comments", headerLines.toString());
217 setAlignmentProperty("iteration", "" + iterationCount);
224 * @return DOCUMENT ME!
226 public String print()
228 return print(getSeqsAsArray());
237 * @return DOCUMENT ME!
239 public String print(SequenceI[] s)
241 StringBuffer out = new StringBuffer();
243 * A general parser for ids. Will look for dbrefs in Uniprot format
244 * source|id And also Jalview /start-end
246 * @String id Id to be parsed
251 while ((i < s.length) && (s[i] != null))
253 out.append(">" + printId(s[i]));
254 if (s[i].getDescription() != null)
256 out.append(" " + s[i].getDescription());
261 if (s[i].getSequence().length > max)
263 max = s[i].getSequence().length;
269 out.append("* iteration 1");
272 for (int j = 0; j < max; j++)
276 while ((i < s.length) && (s[i] != null))
278 if (s[i].getSequence().length > j)
280 out.append(s[i].getSequenceAsString(j, j + 1));
296 return out.toString();