1 /* Jalview - a java multiple alignment editor
\r
2 * Copyright (C) 1998 Michele Clamp
\r
4 * This program is free software; you can redistribute it and/or
\r
5 * modify it under the terms of the GNU General Public License
\r
6 * as published by the Free Software Foundation; either version 2
\r
7 * of the License, or (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with this program; if not, write to the Free Software
\r
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
20 import jalview.datamodel.*;
\r
25 public class BLCFile extends AlignFile {
\r
32 public BLCFile(String inStr) {
\r
36 public void initData() {
\r
38 titles = new Vector();
\r
41 public BLCFile(String inFile, String type) throws IOException {
\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
60 if (line.indexOf("*") > -1)
\r
66 int abracket = line.indexOf(">");
\r
71 if(line.indexOf(" ")>-1)//
\r
73 ///Colur it be this format?
\r
74 //>54402046 0 1 137 137:
\r
76 // 1 >L1H14 30539 343
\r
78 ids.addElement(line.substring(abracket + 1,
\r
79 line.indexOf(" ", abracket + 1)));
\r
83 line = line.substring(abracket + 1);
\r
84 line = line.substring(line.indexOf(" ") + 1);
\r
86 line = line.substring(line.indexOf(" ") + 1);
\r
88 int value = Integer.parseInt(line.substring(0, line.indexOf(" ")));
\r
89 starts.addElement(value+"");
\r
90 line = line.substring(line.indexOf(" ") + 1);
\r
92 value = Integer.parseInt(line.substring(0, line.indexOf(" ")));
\r
93 ends.addElement(value+"");
\r
95 }catch(Exception ex)
\r
97 System.err.println("Error during blockfile read.");
\r
98 ex.printStackTrace();
\r
99 starts.addElement("0");
\r
100 ends.addElement("0");
\r
106 ids.addElement( line.substring(abracket + 1, line.indexOf("/")));
\r
107 line = line.substring(line.indexOf("/") + 1);
\r
108 starts.addElement(line.substring(0, line.indexOf("-")));
\r
109 ends.addElement(line.substring(line.indexOf("-") + 1));
\r
114 int starCol = line.indexOf("*");
\r
115 seqstrings = new StringBuffer[ids.size()];
\r
116 for(int i=0; i<ids.size(); i++)
\r
118 if(seqstrings[i]==null)
\r
119 seqstrings[i] = new StringBuffer();
\r
122 while ((line = nextLine()).indexOf("*")==-1)
\r
124 for(int i=0; i<ids.size(); i++)
\r
126 if(line.length()>i+starCol)
\r
127 seqstrings[i].append(line.charAt(i + starCol));
\r
131 for(int i=0; i<ids.size(); i++)
\r
133 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
\r
134 seqstrings[i].toString(),
\r
135 Integer.parseInt(starts.elementAt(i).toString()),
\r
136 Integer.parseInt(ends.elementAt(i).toString()));
\r
137 seqs.addElement(newSeq);
\r
140 }catch(Exception ex){ex.printStackTrace();}
\r
143 public String print() {
\r
144 return print(getSeqsAsArray());
\r
146 public static String print(SequenceI[] s) {
\r
147 StringBuffer out = new StringBuffer();
\r
151 while (i < s.length && s[i] != null) {
\r
152 out.append(">" + s[i].getName() + "/" + s[i].getStart() + "-" + s[i].getEnd() + "\n");
\r
153 if (s[i].getSequence().length() > max) { max = s[i].getSequence().length();}
\r
157 out.append("* iteration 1\n");
\r
158 for (int j = 0; j < max; j++) {
\r
160 while (i < s.length && s[i] != null) {
\r
161 if(s[i].getSequence().length()>j )
\r
162 out.append(s[i].getSequence().substring(j,j+1));
\r
170 return out.toString();
\r