2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2005 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
27 import jalview.datamodel.*;
\r
29 import jalview.util.*;
\r
40 * @version $Revision$
\r
42 public class JPredFile extends AlignFile
\r
46 Hashtable Scores; // Hash of names and score vectors
\r
47 Hashtable Symscores; // indexes of symbol annotation properties in sequenceI vector
\r
48 private int QuerySeqPosition;
\r
51 * Creates a new JPredFile object.
\r
53 * @param inStr DOCUMENT ME!
\r
55 public JPredFile(String inStr)
\r
61 * Creates a new JPredFile object.
\r
63 * @param inFile DOCUMENT ME!
\r
64 * @param type DOCUMENT ME!
\r
66 * @throws IOException DOCUMENT ME!
\r
68 public JPredFile(String inFile, String type) throws IOException
\r
70 super(inFile, type);
\r
76 * @param QuerySeqPosition DOCUMENT ME!
\r
78 public void setQuerySeqPosition(int QuerySeqPosition)
\r
80 this.QuerySeqPosition = QuerySeqPosition;
\r
86 * @return DOCUMENT ME!
\r
88 public int getQuerySeqPosition()
\r
90 return QuerySeqPosition;
\r
96 * @return DOCUMENT ME!
\r
98 public Hashtable getScores()
\r
106 * @return DOCUMENT ME!
\r
108 public Hashtable getSymscores()
\r
116 public void initData()
\r
119 Scores = new Hashtable();
\r
125 * parse a JPred concise file into a sequence-alignment like object.
127 public void parse() throws IOException
\r
129 // JBPNote log.System.out.println("all read in ");
\r
131 QuerySeqPosition = -1;
\r
134 Vector seq_entries = new Vector();
\r
135 Vector ids = new Vector();
\r
136 Hashtable Symscores = new Hashtable();
\r
138 while ((line = nextLine()) != null)
\r
140 // Concise format allows no comments or non comma-formatted data
\r
141 StringTokenizer str = new StringTokenizer(line, ":");
\r
144 if (!str.hasMoreTokens())
\r
149 id = str.nextToken();
\r
151 String seqsym = str.nextToken();
\r
152 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
\r
154 // decide if we have more than just alphanumeric symbols
\r
155 int numSymbols = symbols.countTokens();
\r
157 if (numSymbols == 0)
\r
162 if (seqsym.length() != (2 * numSymbols))
\r
164 // Set of scalars for some property
\r
165 if (Scores.containsKey(id))
\r
169 while (Scores.containsKey(id + "_" + i))
\r
177 Vector scores = new Vector();
\r
179 // Typecheck from first entry
\r
181 String ascore = "dead";
\r
185 // store elements as floats...
\r
186 while (symbols.hasMoreTokens())
\r
188 ascore = symbols.nextToken();
\r
190 Float score = new Float(ascore);
\r
191 scores.addElement((Object) score);
\r
194 Scores.put(id, scores);
\r
196 catch (Exception e)
\r
198 // or just keep them as strings
\r
201 for (int j = 0; j < i; j++)
\r
204 (Object) ((Float) scores.get(j)).toString());
\r
207 scores.addElement((Object) ascore);
\r
209 while (symbols.hasMoreTokens())
\r
211 ascore = symbols.nextToken();
\r
212 scores.addElement((Object) ascore);
\r
215 Scores.put(id, scores);
\r
218 else if (id.equals("jnetconf"))
\r
220 // log.debug System.out.println("here");
\r
221 id = "Prediction Confidence";
\r
222 this.conf = new Vector(numSymbols);
\r
224 for (int i = 0; i < numSymbols; i++)
\r
226 conf.set(i, (Object) symbols.nextToken());
\r
231 // Sequence or a prediction string (rendered as sequence)
\r
232 StringBuffer newseq = new StringBuffer();
\r
234 for (int i = 0; i < numSymbols; i++)
\r
236 newseq.append(symbols.nextToken());
\r
239 if (id.indexOf(";") > -1)
\r
241 seq_entries.addElement(newseq);
\r
244 String name = id.substring(id.indexOf(";") + 1);
\r
246 while (ids.lastIndexOf(name) > -1)
\r
248 name = id.substring(id.indexOf(";") + 1) + "_" + 1;
\r
251 ids.addElement(name);
\r
257 if (id.equals("JNETPRED"))
\r
259 id = "Predicted Secondary Structure";
\r
262 seq_entries.addElement(newseq.toString());
\r
263 ids.addElement(id);
\r
264 Symscores.put((Object) id,
\r
265 (Object) new Integer(ids.size() - 1));
\r
272 throw new IOException(
\r
273 "JpredFile Parser: No sequence in the prediction!");
\r
276 maxLength = seq_entries.elementAt(0).toString().length();
\r
278 for (int i = 0; i < ids.size(); i++)
\r
280 // Add all sequence like objects
\r
281 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
\r
282 seq_entries.elementAt(i).toString(), 1,
\r
283 seq_entries.elementAt(i).toString().length());
\r
285 if (!Symscores.containsKey(ids.elementAt(i)) &&
\r
286 !isValidProteinSequence(newSeq.getSequence()))
\r
288 throw new IOException(
\r
289 "JPredConcise: Not a valid protein sequence - (" +
\r
290 ids.elementAt(i).toString() + ")");
\r
293 if (maxLength != seq_entries.elementAt(i).toString().length())
\r
295 throw new IOException("JPredConcise: Entry (" +
\r
296 ids.elementAt(i).toString() +
\r
297 ") has an unexpected number of columns");
\r
300 if (newSeq.getName().startsWith("QUERY") &&
\r
301 (QuerySeqPosition == -1))
\r
303 QuerySeqPosition = seqs.size();
\r
306 seqs.addElement(newSeq);
\r
315 public String print()
\r
317 return "Not Supported";
\r
323 * @param args DOCUMENT ME!
\r
325 public static void main(String[] args)
\r
329 JPredFile blc = new JPredFile(args[0], "File");
\r
331 for (int i = 0; i < blc.seqs.size(); i++)
\r
333 System.out.println(((Sequence) blc.seqs.elementAt(i)).getName() +
\r
334 "\n" + ((Sequence) blc.seqs.elementAt(i)).getSequence() +
\r
338 catch (java.io.IOException e)
\r
340 System.err.println("Exception " + e);
\r
341 e.printStackTrace();
\r
348 StringBuffer out = new StringBuffer();
350 out.append("START PRED\n");
351 for (int i = 0; i < s[0].sequence.length(); i++)
353 out.append(s[0].sequence.substring(i, i + 1) + " ");
354 out.append(s[1].sequence.substring(i, i + 1) + " ");
355 out.append(s[1].score[0].elementAt(i) + " ");
356 out.append(s[1].score[1].elementAt(i) + " ");
357 out.append(s[1].score[2].elementAt(i) + " ");
358 out.append(s[1].score[3].elementAt(i) + " ");
362 out.append("END PRED\n");
363 return out.toString();
366 public static void main(String[] args)
370 BLCFile blc = new BLCFile(args[0], "File");
371 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
372 for (int i = 0; i < blc.seqs.size(); i++)
374 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
376 String out = BLCFile.print(s);
378 AlignFrame af = new AlignFrame(null, s);
381 System.out.println(out);
383 catch (java.io.IOException e)
385 System.out.println("Exception " + e);