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
22 * JalviewX / Vamsas Project
\r
23 * JPred.seq.concise reader
\r
30 import jalview.datamodel.*;
\r
37 * @version $Revision$
\r
39 public class JPredFile extends AlignFile
\r
43 Hashtable Scores; // Hash of names and score vectors
\r
44 Hashtable Symscores; // indexes of symbol annotation properties in sequenceI vector
\r
45 private int QuerySeqPosition;
\r
48 * Creates a new JPredFile object.
\r
50 * @param inStr DOCUMENT ME!
\r
52 public JPredFile(String inStr)
\r
58 * Creates a new JPredFile object.
\r
60 * @param inFile DOCUMENT ME!
\r
61 * @param type DOCUMENT ME!
\r
63 * @throws IOException DOCUMENT ME!
\r
65 public JPredFile(String inFile, String type) throws IOException
\r
67 super(inFile, type);
\r
73 * @param QuerySeqPosition DOCUMENT ME!
\r
75 public void setQuerySeqPosition(int QuerySeqPosition)
\r
77 this.QuerySeqPosition = QuerySeqPosition;
\r
83 * @return DOCUMENT ME!
\r
85 public int getQuerySeqPosition()
\r
87 return QuerySeqPosition;
\r
93 * @return DOCUMENT ME!
\r
95 public Hashtable getScores()
\r
103 * @return DOCUMENT ME!
\r
105 public Hashtable getSymscores()
\r
113 public void initData()
\r
116 Scores = new Hashtable();
\r
122 * parse a JPred concise file into a sequence-alignment like object.
\r
124 public void parse() throws IOException
\r
126 // JBPNote log.System.out.println("all read in ");
\r
128 QuerySeqPosition = -1;
\r
131 Vector seq_entries = new Vector();
\r
132 Vector ids = new Vector();
\r
133 Hashtable Symscores = new Hashtable();
\r
135 while ((line = nextLine()) != null)
\r
137 // Concise format allows no comments or non comma-formatted data
\r
138 StringTokenizer str = new StringTokenizer(line, ":");
\r
141 if (!str.hasMoreTokens())
\r
146 id = str.nextToken();
\r
148 String seqsym = str.nextToken();
\r
149 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
\r
151 // decide if we have more than just alphanumeric symbols
\r
152 int numSymbols = symbols.countTokens();
\r
154 if (numSymbols == 0)
\r
159 if (seqsym.length() != (2 * numSymbols))
\r
161 // Set of scalars for some property
\r
162 if (Scores.containsKey(id))
\r
166 while (Scores.containsKey(id + "_" + i))
\r
174 Vector scores = new Vector();
\r
176 // Typecheck from first entry
\r
178 String ascore = "dead";
\r
182 // store elements as floats...
\r
183 while (symbols.hasMoreTokens())
\r
185 ascore = symbols.nextToken();
\r
187 Float score = new Float(ascore);
\r
188 scores.addElement((Object) score);
\r
191 Scores.put(id, scores);
\r
193 catch (Exception e)
\r
195 // or just keep them as strings
\r
198 for (int j = 0; j < i; j++)
\r
200 scores.setElementAt(
\r
201 (Object) ((Float) scores.elementAt(j)).toString(), j);
\r
204 scores.addElement((Object) ascore);
\r
206 while (symbols.hasMoreTokens())
\r
208 ascore = symbols.nextToken();
\r
209 scores.addElement((Object) ascore);
\r
212 Scores.put(id, scores);
\r
215 else if (id.equals("jnetconf"))
\r
217 // log.debug System.out.println("here");
\r
218 id = "Prediction Confidence";
\r
219 this.conf = new Vector(numSymbols);
\r
221 for (int i = 0; i < numSymbols; i++)
\r
223 conf.setElementAt( symbols.nextToken(), i);
\r
228 // Sequence or a prediction string (rendered as sequence)
\r
229 StringBuffer newseq = new StringBuffer();
\r
231 for (int i = 0; i < numSymbols; i++)
\r
233 newseq.append(symbols.nextToken());
\r
236 if (id.indexOf(";") > -1)
\r
238 seq_entries.addElement(newseq);
\r
241 String name = id.substring(id.indexOf(";") + 1);
\r
243 while (ids.lastIndexOf(name) > -1)
\r
245 name = id.substring(id.indexOf(";") + 1) + "_" + ++i;
\r
248 ids.addElement(name);
\r
254 if (id.equals("JNETPRED"))
\r
256 id = "Predicted Secondary Structure";
\r
259 seq_entries.addElement(newseq.toString());
\r
260 ids.addElement(id);
\r
261 Symscores.put((Object) id,
\r
262 (Object) new Integer(ids.size() - 1));
\r
266 /* leave it to the parser user to actually check this.
\r
269 throw new IOException(
\r
270 "JpredFile Parser: No sequence in the prediction!");
\r
273 maxLength = seq_entries.elementAt(0).toString().length();
\r
275 for (int i = 0; i < ids.size(); i++)
\r
277 // Add all sequence like objects
\r
278 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
\r
279 seq_entries.elementAt(i).toString(), 1,
\r
280 seq_entries.elementAt(i).toString().length());
\r
282 if (!Symscores.containsKey(ids.elementAt(i)) &&
\r
283 !isValidProteinSequence(newSeq.getSequence()))
\r
285 throw new IOException("JPredConcise: "
\r
286 +AppletFormatAdapter.INVALID_CHARACTERS +" : "
\r
287 +ids.elementAt(i).toString() + ")");
\r
290 if (maxLength != seq_entries.elementAt(i).toString().length())
\r
292 throw new IOException("JPredConcise: Entry (" +
\r
293 ids.elementAt(i).toString() +
\r
294 ") has an unexpected number of columns");
\r
297 if (newSeq.getName().startsWith("QUERY") &&
\r
298 (QuerySeqPosition == -1))
\r
300 QuerySeqPosition = seqs.size();
\r
303 seqs.addElement(newSeq);
\r
312 public String print()
\r
314 return "Not Supported";
\r
320 * @param args DOCUMENT ME!
\r
322 public static void main(String[] args)
\r
326 JPredFile blc = new JPredFile(args[0], "File");
\r
328 for (int i = 0; i < blc.seqs.size(); i++)
\r
330 System.out.println(((Sequence) blc.seqs.elementAt(i)).getName() +
\r
331 "\n" + ((Sequence) blc.seqs.elementAt(i)).getSequence() +
\r
335 catch (java.io.IOException e)
\r
337 System.err.println("Exception " + e);
\r
338 e.printStackTrace();
\r
341 Vector annotSeqs=null;
\r
343 * removeNonSequences
\r
345 public void removeNonSequences()
\r
347 if (annotSeqs!=null)
\r
349 annotSeqs = new Vector();
\r
350 Vector newseqs = new Vector();
\r
353 for (; i<QuerySeqPosition; i++)
\r
354 annotSeqs.addElement(seqs.elementAt(i));
\r
355 // check that no stray annotations have been added at the end.
\r
357 SequenceI sq = (SequenceI) seqs.elementAt(j-1);
\r
358 if (sq.getName().toUpperCase().startsWith("JPRED")) {
\r
359 annotSeqs.addElement(sq);
\r
360 seqs.removeElementAt(--j);
\r
364 newseqs.addElement(seqs.elementAt(i));
\r
366 seqs.removeAllElements();
\r
373 StringBuffer out = new StringBuffer();
\r
375 out.append("START PRED\n");
\r
376 for (int i = 0; i < s[0].sequence.length(); i++)
\r
378 out.append(s[0].sequence.substring(i, i + 1) + " ");
\r
379 out.append(s[1].sequence.substring(i, i + 1) + " ");
\r
380 out.append(s[1].score[0].elementAt(i) + " ");
\r
381 out.append(s[1].score[1].elementAt(i) + " ");
\r
382 out.append(s[1].score[2].elementAt(i) + " ");
\r
383 out.append(s[1].score[3].elementAt(i) + " ");
\r
387 out.append("END PRED\n");
\r
388 return out.toString();
\r
391 public static void main(String[] args)
\r
395 BLCFile blc = new BLCFile(args[0], "File");
\r
396 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
\r
397 for (int i = 0; i < blc.seqs.size(); i++)
\r
399 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
\r
401 String out = BLCFile.print(s);
\r
403 AlignFrame af = new AlignFrame(null, s);
\r
404 af.resize(700, 500);
\r
406 System.out.println(out);
\r
408 catch (java.io.IOException e)
\r
410 System.out.println("Exception " + e);
\r