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
49 * Creates a new JPredFile object.
\r
51 * @param inFile DOCUMENT ME!
\r
52 * @param type DOCUMENT ME!
\r
54 * @throws IOException DOCUMENT ME!
\r
56 public JPredFile(String inFile, String type) throws IOException
\r
58 super(inFile, type);
\r
64 * @param QuerySeqPosition DOCUMENT ME!
\r
66 public void setQuerySeqPosition(int QuerySeqPosition)
\r
68 this.QuerySeqPosition = QuerySeqPosition;
\r
74 * @return DOCUMENT ME!
\r
76 public int getQuerySeqPosition()
\r
78 return QuerySeqPosition;
\r
84 * @return DOCUMENT ME!
\r
86 public Hashtable getScores()
\r
94 * @return DOCUMENT ME!
\r
96 public Hashtable getSymscores()
\r
104 public void initData()
\r
107 Scores = new Hashtable();
\r
113 * parse a JPred concise file into a sequence-alignment like object.
\r
115 public void parse() throws IOException
\r
117 // JBPNote log.System.out.println("all read in ");
\r
119 QuerySeqPosition = -1;
\r
122 Vector seq_entries = new Vector();
\r
123 Vector ids = new Vector();
\r
124 Hashtable Symscores = new Hashtable();
\r
126 while ((line = nextLine()) != null)
\r
128 // Concise format allows no comments or non comma-formatted data
\r
129 StringTokenizer str = new StringTokenizer(line, ":");
\r
132 if (!str.hasMoreTokens())
\r
137 id = str.nextToken();
\r
139 String seqsym = str.nextToken();
\r
140 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
\r
142 // decide if we have more than just alphanumeric symbols
\r
143 int numSymbols = symbols.countTokens();
\r
145 if (numSymbols == 0)
\r
150 if (seqsym.length() != (2 * numSymbols))
\r
152 // Set of scalars for some property
\r
153 if (Scores.containsKey(id))
\r
157 while (Scores.containsKey(id + "_" + i))
\r
165 Vector scores = new Vector();
\r
167 // Typecheck from first entry
\r
169 String ascore = "dead";
\r
173 // store elements as floats...
\r
174 while (symbols.hasMoreTokens())
\r
176 ascore = symbols.nextToken();
\r
178 Float score = new Float(ascore);
\r
179 scores.addElement((Object) score);
\r
182 Scores.put(id, scores);
\r
184 catch (Exception e)
\r
186 // or just keep them as strings
\r
189 for (int j = 0; j < i; j++)
\r
191 scores.setElementAt(
\r
192 (Object) ((Float) scores.elementAt(j)).toString(), j);
\r
195 scores.addElement((Object) ascore);
\r
197 while (symbols.hasMoreTokens())
\r
199 ascore = symbols.nextToken();
\r
200 scores.addElement((Object) ascore);
\r
203 Scores.put(id, scores);
\r
206 else if (id.equals("jnetconf"))
\r
208 // log.debug System.out.println("here");
\r
209 id = "Prediction Confidence";
\r
210 this.conf = new Vector(numSymbols);
\r
212 for (int i = 0; i < numSymbols; i++)
\r
214 conf.setElementAt( symbols.nextToken(), i);
\r
219 // Sequence or a prediction string (rendered as sequence)
\r
220 StringBuffer newseq = new StringBuffer();
\r
222 for (int i = 0; i < numSymbols; i++)
\r
224 newseq.append(symbols.nextToken());
\r
227 if (id.indexOf(";") > -1)
\r
229 seq_entries.addElement(newseq);
\r
232 String name = id.substring(id.indexOf(";") + 1);
\r
234 while (ids.lastIndexOf(name) > -1)
\r
236 name = id.substring(id.indexOf(";") + 1) + "_" + ++i;
\r
239 ids.addElement(name);
\r
245 if (id.equals("JNETPRED"))
\r
247 id = "Predicted Secondary Structure";
\r
250 seq_entries.addElement(newseq.toString());
\r
251 ids.addElement(id);
\r
252 Symscores.put((Object) id,
\r
253 (Object) new Integer(ids.size() - 1));
\r
257 /* leave it to the parser user to actually check this.
\r
260 throw new IOException(
\r
261 "JpredFile Parser: No sequence in the prediction!");
\r
264 maxLength = seq_entries.elementAt(0).toString().length();
\r
266 for (int i = 0; i < ids.size(); i++)
\r
268 // Add all sequence like objects
\r
269 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
\r
270 seq_entries.elementAt(i).toString(), 1,
\r
271 seq_entries.elementAt(i).toString().length());
\r
273 if (!Symscores.containsKey(ids.elementAt(i)) &&
\r
274 !isValidProteinSequence(newSeq.getSequence()))
\r
276 throw new IOException("JPredConcise: "
\r
277 +AppletFormatAdapter.INVALID_CHARACTERS +" : "
\r
278 +ids.elementAt(i).toString() + ")");
\r
281 if (maxLength != seq_entries.elementAt(i).toString().length())
\r
283 throw new IOException("JPredConcise: Entry (" +
\r
284 ids.elementAt(i).toString() +
\r
285 ") has an unexpected number of columns");
\r
288 if (newSeq.getName().startsWith("QUERY") &&
\r
289 (QuerySeqPosition == -1))
\r
291 QuerySeqPosition = seqs.size();
\r
294 seqs.addElement(newSeq);
\r
303 public String print()
\r
305 return "Not Supported";
\r
311 * @param args DOCUMENT ME!
\r
313 public static void main(String[] args)
\r
317 JPredFile blc = new JPredFile(args[0], "File");
\r
319 for (int i = 0; i < blc.seqs.size(); i++)
\r
321 System.out.println(((Sequence) blc.seqs.elementAt(i)).getName() +
\r
322 "\n" + ((Sequence) blc.seqs.elementAt(i)).getSequence() +
\r
326 catch (java.io.IOException e)
\r
328 System.err.println("Exception " + e);
\r
329 e.printStackTrace();
\r
332 Vector annotSeqs=null;
\r
334 * removeNonSequences
\r
336 public void removeNonSequences()
\r
338 if (annotSeqs!=null)
\r
340 annotSeqs = new Vector();
\r
341 Vector newseqs = new Vector();
\r
344 for (; i<QuerySeqPosition; i++)
\r
345 annotSeqs.addElement(seqs.elementAt(i));
\r
346 // check that no stray annotations have been added at the end.
\r
348 SequenceI sq = (SequenceI) seqs.elementAt(j-1);
\r
349 if (sq.getName().toUpperCase().startsWith("JPRED")) {
\r
350 annotSeqs.addElement(sq);
\r
351 seqs.removeElementAt(--j);
\r
355 newseqs.addElement(seqs.elementAt(i));
\r
357 seqs.removeAllElements();
\r
364 StringBuffer out = new StringBuffer();
\r
366 out.append("START PRED\n");
\r
367 for (int i = 0; i < s[0].sequence.length(); i++)
\r
369 out.append(s[0].sequence.substring(i, i + 1) + " ");
\r
370 out.append(s[1].sequence.substring(i, i + 1) + " ");
\r
371 out.append(s[1].score[0].elementAt(i) + " ");
\r
372 out.append(s[1].score[1].elementAt(i) + " ");
\r
373 out.append(s[1].score[2].elementAt(i) + " ");
\r
374 out.append(s[1].score[3].elementAt(i) + " ");
\r
378 out.append("END PRED\n");
\r
379 return out.toString();
\r
382 public static void main(String[] args)
\r
386 BLCFile blc = new BLCFile(args[0], "File");
\r
387 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
\r
388 for (int i = 0; i < blc.seqs.size(); i++)
\r
390 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
\r
392 String out = BLCFile.print(s);
\r
394 AlignFrame af = new AlignFrame(null, s);
\r
395 af.resize(700, 500);
\r
397 System.out.println(out);
\r
399 catch (java.io.IOException e)
\r
401 System.out.println("Exception " + e);
\r