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());
273 if (!Symscores.containsKey(ids.elementAt(i)) &&
274 !isValidProteinSequence(newSeq.getSequence()))
276 throw new IOException("JPredConcise: "
277 +AppletFormatAdapter.INVALID_CHARACTERS +" : "
278 +ids.elementAt(i).toString() + ")");
281 if (maxLength != seq_entries.elementAt(i).toString().length())
283 throw new IOException("JPredConcise: Entry (" +
284 ids.elementAt(i).toString() +
285 ") has an unexpected number of columns");
288 if (newSeq.getName().startsWith("QUERY") &&
289 (QuerySeqPosition == -1))
291 QuerySeqPosition = seqs.size();
294 seqs.addElement(newSeq);
303 public String print()
305 return "Not Supported";
311 * @param args DOCUMENT ME!
313 public static void main(String[] args)
317 JPredFile blc = new JPredFile(args[0], "File");
319 for (int i = 0; i < blc.seqs.size(); i++)
321 System.out.println(((Sequence) blc.seqs.elementAt(i)).getName() +
322 "\n" + ((Sequence) blc.seqs.elementAt(i)).getSequenceAsString() +
326 catch (java.io.IOException e)
328 System.err.println("Exception " + e);
332 Vector annotSeqs=null;
336 public void removeNonSequences()
340 annotSeqs = new Vector();
341 Vector newseqs = new Vector();
344 for (; i<QuerySeqPosition; i++)
345 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")) {
350 annotSeqs.addElement(sq);
351 seqs.removeElementAt(--j);
355 newseqs.addElement(seqs.elementAt(i));
357 seqs.removeAllElements();
364 StringBuffer out = new StringBuffer();
366 out.append("START PRED\n");
367 for (int i = 0; i < s[0].sequence.length(); i++)
369 out.append(s[0].sequence.substring(i, i + 1) + " ");
370 out.append(s[1].sequence.substring(i, i + 1) + " ");
371 out.append(s[1].score[0].elementAt(i) + " ");
372 out.append(s[1].score[1].elementAt(i) + " ");
373 out.append(s[1].score[2].elementAt(i) + " ");
374 out.append(s[1].score[3].elementAt(i) + " ");
378 out.append("END PRED\n");
379 return out.toString();
382 public static void main(String[] args)
386 BLCFile blc = new BLCFile(args[0], "File");
387 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
388 for (int i = 0; i < blc.seqs.size(); i++)
390 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
392 String out = BLCFile.print(s);
394 AlignFrame af = new AlignFrame(null, s);
397 System.out.println(out);
399 catch (java.io.IOException e)
401 System.out.println("Exception " + e);