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
22 * JalviewX / Vamsas Project
23 * JPred.seq.concise reader
30 import jalview.datamodel.*;
39 public class JPredFile extends AlignFile
43 Hashtable Scores; // Hash of names and score vectors
44 Hashtable Symscores; // indexes of symbol annotation properties in sequenceI vector
45 private int QuerySeqPosition;
49 * Creates a new JPredFile object.
51 * @param inFile DOCUMENT ME!
52 * @param type DOCUMENT ME!
54 * @throws IOException DOCUMENT ME!
56 public JPredFile(String inFile, String type) throws IOException
64 * @param QuerySeqPosition DOCUMENT ME!
66 public void setQuerySeqPosition(int QuerySeqPosition)
68 this.QuerySeqPosition = QuerySeqPosition;
74 * @return DOCUMENT ME!
76 public int getQuerySeqPosition()
78 return QuerySeqPosition;
84 * @return DOCUMENT ME!
86 public Hashtable getScores()
94 * @return DOCUMENT ME!
96 public Hashtable getSymscores()
104 public void initData()
107 Scores = new Hashtable();
113 * parse a JPred concise file into a sequence-alignment like object.
115 public void parse() throws IOException
117 // JBPNote log.System.out.println("all read in ");
119 QuerySeqPosition = -1;
122 Vector seq_entries = new Vector();
123 Vector ids = new Vector();
124 Hashtable Symscores = new Hashtable();
126 while ((line = nextLine()) != null)
128 // Concise format allows no comments or non comma-formatted data
129 StringTokenizer str = new StringTokenizer(line, ":");
132 if (!str.hasMoreTokens())
137 id = str.nextToken();
139 String seqsym = str.nextToken();
140 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
142 // decide if we have more than just alphanumeric symbols
143 int numSymbols = symbols.countTokens();
150 if (seqsym.length() != (2 * numSymbols))
152 // Set of scalars for some property
153 if (Scores.containsKey(id))
157 while (Scores.containsKey(id + "_" + i))
165 Vector scores = new Vector();
167 // Typecheck from first entry
169 String ascore = "dead";
173 // store elements as floats...
174 while (symbols.hasMoreTokens())
176 ascore = symbols.nextToken();
178 Float score = new Float(ascore);
179 scores.addElement((Object) score);
182 Scores.put(id, scores);
186 // or just keep them as strings
189 for (int j = 0; j < i; j++)
192 (Object) ((Float) scores.elementAt(j)).toString(), j);
195 scores.addElement((Object) ascore);
197 while (symbols.hasMoreTokens())
199 ascore = symbols.nextToken();
200 scores.addElement((Object) ascore);
203 Scores.put(id, scores);
206 else if (id.equals("jnetconf"))
208 // log.debug System.out.println("here");
209 id = "Prediction Confidence";
210 this.conf = new Vector(numSymbols);
212 for (int i = 0; i < numSymbols; i++)
214 conf.setElementAt( symbols.nextToken(), i);
219 // Sequence or a prediction string (rendered as sequence)
220 StringBuffer newseq = new StringBuffer();
222 for (int i = 0; i < numSymbols; i++)
224 newseq.append(symbols.nextToken());
227 if (id.indexOf(";") > -1)
229 seq_entries.addElement(newseq);
232 String name = id.substring(id.indexOf(";") + 1);
234 while (ids.lastIndexOf(name) > -1)
236 name = id.substring(id.indexOf(";") + 1) + "_" + ++i;
239 ids.addElement(name);
245 if (id.equals("JNETPRED"))
247 id = "Predicted Secondary Structure";
250 seq_entries.addElement(newseq.toString());
252 Symscores.put((Object) id,
253 (Object) new Integer(ids.size() - 1));
257 /* leave it to the parser user to actually check this.
260 throw new IOException(
261 "JpredFile Parser: No sequence in the prediction!");
264 maxLength = seq_entries.elementAt(0).toString().length();
266 for (int i = 0; i < ids.size(); i++)
268 // Add all sequence like objects
269 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
270 seq_entries.elementAt(i).toString(), 1,
271 seq_entries.elementAt(i).toString().length());
274 if (maxLength != seq_entries.elementAt(i).toString().length())
276 throw new IOException("JPredConcise: Entry (" +
277 ids.elementAt(i).toString() +
278 ") has an unexpected number of columns");
281 if (newSeq.getName().startsWith("QUERY") &&
282 (QuerySeqPosition == -1))
284 QuerySeqPosition = seqs.size();
287 seqs.addElement(newSeq);
296 public String print()
298 return "Not Supported";
304 * @param args DOCUMENT ME!
306 public static void main(String[] args)
310 JPredFile blc = new JPredFile(args[0], "File");
312 for (int i = 0; i < blc.seqs.size(); i++)
314 System.out.println(((Sequence) blc.seqs.elementAt(i)).getName() +
315 "\n" + ((Sequence) blc.seqs.elementAt(i)).getSequenceAsString() +
319 catch (java.io.IOException e)
321 System.err.println("Exception " + e);
325 Vector annotSeqs=null;
329 public void removeNonSequences()
333 annotSeqs = new Vector();
334 Vector newseqs = new Vector();
337 for (; i<QuerySeqPosition; i++)
338 annotSeqs.addElement(seqs.elementAt(i));
339 // check that no stray annotations have been added at the end.
341 SequenceI sq = (SequenceI) seqs.elementAt(j-1);
342 if (sq.getName().toUpperCase().startsWith("JPRED")) {
343 annotSeqs.addElement(sq);
344 seqs.removeElementAt(--j);
348 newseqs.addElement(seqs.elementAt(i));
350 seqs.removeAllElements();
357 StringBuffer out = new StringBuffer();
359 out.append("START PRED\n");
360 for (int i = 0; i < s[0].sequence.length(); i++)
362 out.append(s[0].sequence.substring(i, i + 1) + " ");
363 out.append(s[1].sequence.substring(i, i + 1) + " ");
364 out.append(s[1].score[0].elementAt(i) + " ");
365 out.append(s[1].score[1].elementAt(i) + " ");
366 out.append(s[1].score[2].elementAt(i) + " ");
367 out.append(s[1].score[3].elementAt(i) + " ");
371 out.append("END PRED\n");
372 return out.toString();
375 public static void main(String[] args)
379 BLCFile blc = new BLCFile(args[0], "File");
380 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
381 for (int i = 0; i < blc.seqs.size(); i++)
383 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
385 String out = BLCFile.print(s);
387 AlignFrame af = new AlignFrame(null, s);
390 System.out.println(out);
392 catch (java.io.IOException e)
394 System.out.println("Exception " + e);