2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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.*;
38 public class JPredFile
43 Hashtable Scores; // Hash of names and score vectors
44 Hashtable Symscores; // indexes of symbol annotation properties in sequenceI vector
45 private int QuerySeqPosition;
48 * Creates a new JPredFile object.
50 * @param inFile DOCUMENT ME!
51 * @param type DOCUMENT ME!
53 * @throws IOException DOCUMENT ME!
55 public JPredFile(String inFile, String type)
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.
118 // JBPNote log.System.out.println("all read in ");
120 QuerySeqPosition = -1;
123 Vector seq_entries = new Vector();
124 Vector ids = new Vector();
125 Hashtable Symscores = new Hashtable();
127 while ( (line = nextLine()) != null)
129 // Concise format allows no comments or non comma-formatted data
130 StringTokenizer str = new StringTokenizer(line, ":");
133 if (!str.hasMoreTokens())
138 id = str.nextToken();
140 String seqsym = str.nextToken();
141 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
143 // decide if we have more than just alphanumeric symbols
144 int numSymbols = symbols.countTokens();
151 if (seqsym.length() != (2 * numSymbols))
153 // Set of scalars for some property
154 if (Scores.containsKey(id))
158 while (Scores.containsKey(id + "_" + i))
166 Vector scores = new Vector();
168 // Typecheck from first entry
170 String ascore = "dead";
174 // store elements as floats...
175 while (symbols.hasMoreTokens())
177 ascore = symbols.nextToken();
179 Float score = new Float(ascore);
180 scores.addElement( (Object) score);
183 Scores.put(id, scores);
187 // or just keep them as strings
190 for (int j = 0; j < i; j++)
193 (Object) ( (Float) scores.elementAt(j)).toString(), j);
196 scores.addElement( (Object) ascore);
198 while (symbols.hasMoreTokens())
200 ascore = symbols.nextToken();
201 scores.addElement( (Object) ascore);
204 Scores.put(id, scores);
207 else if (id.equals("jnetconf"))
209 // log.debug System.out.println("here");
210 id = "Prediction Confidence";
211 this.conf = new Vector(numSymbols);
213 for (int i = 0; i < numSymbols; i++)
215 conf.setElementAt(symbols.nextToken(), i);
220 // Sequence or a prediction string (rendered as sequence)
221 StringBuffer newseq = new StringBuffer();
223 for (int i = 0; i < numSymbols; i++)
225 newseq.append(symbols.nextToken());
228 if (id.indexOf(";") > -1)
230 seq_entries.addElement(newseq);
233 String name = id.substring(id.indexOf(";") + 1);
235 while (ids.lastIndexOf(name) > -1)
237 name = id.substring(id.indexOf(";") + 1) + "_" + ++i;
240 if (QuerySeqPosition==-1)
241 QuerySeqPosition = ids.size();
242 ids.addElement(name);
247 if (id.equals("JNETPRED"))
249 id = "Predicted Secondary Structure";
252 seq_entries.addElement(newseq.toString());
254 Symscores.put( (Object) id,
255 (Object)new Integer(ids.size() - 1));
259 /* leave it to the parser user to actually check this.
262 throw new IOException(
263 "JpredFile Parser: No sequence in the prediction!");
266 maxLength = seq_entries.elementAt(0).toString().length();
268 for (int i = 0; i < ids.size(); i++)
270 // Add all sequence like objects
271 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
272 seq_entries.elementAt(i).toString(), 1,
273 seq_entries.elementAt(i).toString().length());
275 if (maxLength != seq_entries.elementAt(i).toString().length())
277 throw new IOException("JPredConcise: Entry (" +
278 ids.elementAt(i).toString() +
279 ") has an unexpected number of columns");
282 if ((newSeq.getName().startsWith("QUERY") || newSeq.getName().startsWith("align;"))&&
283 (QuerySeqPosition == -1))
285 QuerySeqPosition = seqs.size();
288 seqs.addElement(newSeq);
297 public String print()
299 return "Not Supported";
305 * @param args DOCUMENT ME!
307 public static void main(String[] args)
311 JPredFile blc = new JPredFile(args[0], "File");
313 for (int i = 0; i < blc.seqs.size(); i++)
315 System.out.println( ( (Sequence) blc.seqs.elementAt(i)).getName() +
317 ( (Sequence) blc.seqs.elementAt(i)).getSequenceAsString() +
321 catch (java.io.IOException e)
323 System.err.println("Exception " + e);
328 Vector annotSeqs = null;
332 public void removeNonSequences()
334 if (annotSeqs != null)
338 annotSeqs = new Vector();
339 Vector newseqs = new Vector();
342 for (; i < QuerySeqPosition; i++)
344 annotSeqs.addElement(seqs.elementAt(i));
346 // check that no stray annotations have been added at the end.
348 SequenceI sq = (SequenceI) seqs.elementAt(j - 1);
349 if (sq.getName().toUpperCase().startsWith("JPRED"))
351 annotSeqs.addElement(sq);
352 seqs.removeElementAt(--j);
357 newseqs.addElement(seqs.elementAt(i));
360 seqs.removeAllElements();
366 StringBuffer out = new StringBuffer();
368 out.append("START PRED\n");
369 for (int i = 0; i < s[0].sequence.length(); i++)
371 out.append(s[0].sequence.substring(i, i + 1) + " ");
372 out.append(s[1].sequence.substring(i, i + 1) + " ");
373 out.append(s[1].score[0].elementAt(i) + " ");
374 out.append(s[1].score[1].elementAt(i) + " ");
375 out.append(s[1].score[2].elementAt(i) + " ");
376 out.append(s[1].score[3].elementAt(i) + " ");
380 out.append("END PRED\n");
381 return out.toString();
384 public static void main(String[] args)
388 BLCFile blc = new BLCFile(args[0], "File");
389 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
390 for (int i = 0; i < blc.seqs.size(); i++)
392 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
394 String out = BLCFile.print(s);
396 AlignFrame af = new AlignFrame(null, s);
399 System.out.println(out);
401 catch (java.io.IOException e)
403 System.out.println("Exception " + e);