2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 import jalview.datamodel.*;
34 public class BLCFile extends AlignFile
39 * Creates a new BLCFile object.
47 * Creates a new BLCFile object.
49 * @param inFile DOCUMENT ME!
50 * @param type DOCUMENT ME!
52 * @throws IOException DOCUMENT ME!
54 public BLCFile(String inFile, String type) throws IOException
62 public void initData()
65 titles = new Vector();
71 public void parse() throws IOException
73 boolean idsFound = false;
74 Vector ids = new Vector();
75 StringBuffer[] seqstrings;
76 Vector starts = new Vector();
77 Vector ends = new Vector();
86 if (line.indexOf("*") > -1)
93 int abracket = line.indexOf(">");
97 if (line.indexOf(" ") > -1) //
99 line = line.substring(abracket + 1,
100 line.indexOf(" ", abracket + 1));
103 line = line.substring(abracket+1);
106 Sequence seq = parseId(line);
107 ids.addElement(seq.getName());
108 starts.addElement(seq.getStart() + "");
109 ends.addElement(seq.getEnd() + "");
114 int starCol = line.indexOf("*");
115 seqstrings = new StringBuffer[ids.size()];
117 for (int i = 0; i < ids.size(); i++)
119 if (seqstrings[i] == null)
121 seqstrings[i] = new StringBuffer();
125 while ((line = nextLine()).indexOf("*") == -1)
127 for (int i = 0; i < ids.size(); i++)
129 if (line.length() > (i + starCol))
131 seqstrings[i].append(line.charAt(i + starCol));
136 for (int i = 0; i < ids.size(); i++)
138 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
139 seqstrings[i].toString(),
140 Integer.parseInt(starts.elementAt(i).
142 Integer.parseInt(ends.elementAt(i).toString()));
144 if (!isValidProteinSequence(newSeq.getSequence()))
146 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS
147 +" : "+ newSeq.getName()
148 +" : "+invalidCharacter);
152 seqs.addElement(newSeq);
160 * @return DOCUMENT ME!
162 public String print()
164 return print(getSeqsAsArray());
170 * @param s DOCUMENT ME!
172 * @return DOCUMENT ME!
174 public String print(SequenceI[] s)
176 StringBuffer out = new StringBuffer();
178 * A general parser for ids. Will look for dbrefs in
179 * Uniprot format source|id
180 * And also Jalview /start-end
182 * @String id Id to be parsed
187 while ((i < s.length) && (s[i] != null))
189 out.append(">" + printId(s[i]) +"\n");
191 if (s[i].getSequence().length() > max)
193 max = s[i].getSequence().length();
199 out.append("* iteration 1\n");
201 for (int j = 0; j < max; j++)
205 while ((i < s.length) && (s[i] != null))
207 if (s[i].getSequence().length() > j)
209 out.append(s[i].getSequence().substring(j, j + 1));
224 return out.toString();