2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
21 import jalview.datamodel.*;
\r
28 public class BLCFile extends AlignFile {
\r
34 public BLCFile(String inStr) {
\r
38 public BLCFile(String inFile, String type) throws IOException {
\r
39 super(inFile, type);
\r
42 public void initData() {
\r
44 titles = new Vector();
\r
47 public void parse() {
\r
48 boolean idsFound = false;
\r
49 Vector ids = new Vector();
\r
50 StringBuffer[] seqstrings;
\r
51 Vector starts = new Vector();
\r
52 Vector ends = new Vector();
\r
61 if (line.indexOf("*") > -1) {
\r
67 int abracket = line.indexOf(">");
\r
69 if (abracket > -1) {
\r
70 if (line.indexOf(" ") > -1) //
\r
72 ///Colur it be this format?
\r
73 //>54402046 0 1 137 137:
\r
75 // 1 >L1H14 30539 343
\r
77 ids.addElement(line.substring(abracket + 1,
\r
78 line.indexOf(" ", abracket + 1)));
\r
81 line = line.substring(abracket + 1);
\r
82 line = line.substring(line.indexOf(" ") + 1);
\r
84 line = line.substring(line.indexOf(" ") + 1);
\r
87 int value = Integer.parseInt(line.substring(0,
\r
88 line.indexOf(" ")));
\r
89 starts.addElement(value + "");
\r
90 line = line.substring(line.indexOf(" ") + 1);
\r
92 value = Integer.parseInt(line.substring(0,
\r
93 line.indexOf(" ")));
\r
94 ends.addElement(value + "");
\r
95 } catch (Exception ex) {
\r
96 System.err.println("Error during blockfile read.");
\r
97 ex.printStackTrace();
\r
98 starts.addElement("0");
\r
99 ends.addElement("0");
\r
102 if(line.indexOf("/")>-1)
\r
104 ids.addElement(line.substring(abracket + 1,
\r
105 line.indexOf("/")));
\r
106 line = line.substring(line.indexOf("/") + 1);
\r
107 starts.addElement(line.substring(0, line.indexOf("-")));
\r
108 ends.addElement(line.substring(line.indexOf("-") + 1));
\r
111 ids.addElement(line.substring(abracket+1));
\r
112 starts.addElement("0");
\r
113 ends.addElement("0");
\r
118 } while (!idsFound);
\r
120 int starCol = line.indexOf("*");
\r
121 seqstrings = new StringBuffer[ids.size()];
\r
123 for (int i = 0; i < ids.size(); i++) {
\r
124 if (seqstrings[i] == null) {
\r
125 seqstrings[i] = new StringBuffer();
\r
129 while ((line = nextLine()).indexOf("*") == -1) {
\r
130 for (int i = 0; i < ids.size(); i++) {
\r
131 if (line.length() > (i + starCol)) {
\r
132 seqstrings[i].append(line.charAt(i + starCol));
\r
137 for (int i = 0; i < ids.size(); i++) {
\r
138 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
\r
139 seqstrings[i].toString(),
\r
140 Integer.parseInt(starts.elementAt(i).toString()),
\r
141 Integer.parseInt(ends.elementAt(i).toString()));
\r
142 seqs.addElement(newSeq);
\r
144 } catch (Exception ex) {
\r
145 ex.printStackTrace();
\r
149 public String print() {
\r
150 return print(getSeqsAsArray());
\r
153 public static String print(SequenceI[] s) {
\r
154 StringBuffer out = new StringBuffer();
\r
159 while ((i < s.length) && (s[i] != null)) {
\r
160 out.append(">" + s[i].getName() + "/" + s[i].getStart() + "-" +
\r
161 s[i].getEnd() + "\n");
\r
163 if (s[i].getSequence().length() > max) {
\r
164 max = s[i].getSequence().length();
\r
170 out.append("* iteration 1\n");
\r
172 for (int j = 0; j < max; j++) {
\r
175 while ((i < s.length) && (s[i] != null)) {
\r
176 if (s[i].getSequence().length() > j) {
\r
177 out.append(s[i].getSequence().substring(j, j + 1));
\r
190 return out.toString();
\r