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.
60 public BLCFile(String inFile, String type) throws Exception
65 public BLCFile(FileParse source) throws Exception
73 public void initData()
76 titles = new Vector();
80 * Control the number of block iterations to skip before returning. set to 0
81 * to read first block file entry only set to -1 to read last block file entry
82 * only set to greater than zero to skip at most that many entries before
85 int iterationSkips = 0;
88 * The iteration number for the alignment actually parsed from the blc file
90 int iterationCount = 0;
95 public void parse() throws IOException
97 StringBuffer headerLines = new StringBuffer();
98 int numHeaderLines = 0; // number of lines appended.
99 StringBuffer[] seqstrings = null;
104 iterationSkips = Integer.parseInt(suffix);
105 } catch (NumberFormatException e)
107 iterationSkips = 0; // first
115 boolean idsFound = false;
116 boolean newids = false;
117 // search for ID header.
124 if (line.indexOf("*") > -1)
131 int abracket = line.indexOf(">");
136 if (iterationCount > 0 && !newids)
138 // we have a new set of IDs to record.
140 seqs.removeAllElements();
143 line = line.substring(abracket + 1);
145 Sequence seq = parseId(line);
146 seqs.addElement(seq);
150 // header lines - keep them for the alignment comments.
151 headerLines.append(line);
152 headerLines.append(newline);
157 break; // end of file.
158 int starCol = line.indexOf("*");
159 seqstrings = new StringBuffer[seqs.size()];
161 for (int i = 0; i < seqs.size(); i++)
163 if (seqstrings[i] == null)
165 seqstrings[i] = new StringBuffer();
172 while (line != null && line.indexOf("*") == -1)
174 for (int i = 0; i < seqs.size(); i++)
176 if (line.length() > (i + starCol))
178 seqstrings[i].append(line.charAt(i + starCol));
183 } catch (IOException e)
185 if (iterationCount == 0)
187 throw (e); // otherwise we've just run out of iterations.
195 } while (--iterationSkips != -1);
197 for (int i = 0; i < seqs.size(); i++)
199 Sequence newSeq = (Sequence) seqs.elementAt(i);
201 newSeq.setSequence(seqstrings[i].toString());
205 if (headerLines.length() > 1 + numHeaderLines) // could see if buffer is
206 // just whitespace or not.
207 setAlignmentProperty("Comments", headerLines.toString());
208 setAlignmentProperty("iteration", "" + iterationCount);
215 * @return DOCUMENT ME!
217 public String print()
219 return print(getSeqsAsArray());
228 * @return DOCUMENT ME!
230 public String print(SequenceI[] s)
232 StringBuffer out = new StringBuffer();
234 * A general parser for ids. Will look for dbrefs in Uniprot format
235 * source|id And also Jalview /start-end
237 * @String id Id to be parsed
242 while ((i < s.length) && (s[i] != null))
244 out.append(">" + printId(s[i]));
245 if (s[i].getDescription() != null)
247 out.append(" " + s[i].getDescription());
252 if (s[i].getSequence().length > max)
254 max = s[i].getSequence().length;
260 out.append("* iteration 1");
263 for (int j = 0; j < max; j++)
267 while ((i < s.length) && (s[i] != null))
269 if (s[i].getSequence().length > j)
271 out.append(s[i].getSequenceAsString(j, j + 1));
287 return out.toString();