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
28 import jalview.datamodel.*;
29 import jalview.util.*;
34 public class JPredFile
39 Hashtable Scores; // Hash of names and score vectors
40 Hashtable Symscores; // indexes of symbol annotation properties in sequenceI vector
41 private int QuerySeqPosition;
42 public void setQuerySeqPosition(int QuerySeqPosition)
44 this.QuerySeqPosition = QuerySeqPosition;
47 public int getQuerySeqPosition()
49 return QuerySeqPosition;
51 public Hashtable getScores() {
54 public Hashtable getSymscores() {
58 public JPredFile(String inStr)
63 public void initData()
67 Scores = new Hashtable();
72 public JPredFile(String inFile, String type)
80 * parse a JPred concise file into a sequence-alignment like object.
85 // JBPNote log.System.out.println("all read in ");
87 QuerySeqPosition = -1;
89 Vector seq_entries = new Vector();
90 Vector ids = new Vector();
91 Hashtable Symscores = new Hashtable();
92 while ( (line = nextLine()) != null)
94 // Concise format allows no comments or non comma-formatted data
95 StringTokenizer str = new StringTokenizer(line, ":");
97 if (!str.hasMoreTokens())
102 id = str.nextToken();
103 String seqsym = str.nextToken();
104 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
105 // decide if we have more than just alphanumeric symbols
106 int numSymbols = symbols.countTokens();
112 if (seqsym.length() != (2 * numSymbols))
114 // Set of scalars for some property
115 if (Scores.containsKey(id))
118 while (Scores.containsKey(id + "_" + i))
124 Vector scores = new Vector();
125 // Typecheck from first entry
127 String ascore="dead";
130 // store elements as floats...
131 while (symbols.hasMoreTokens()) {
132 ascore = symbols.nextToken();
133 Float score = new Float(ascore);
134 scores.addElement( (Object) score);
136 Scores.put(id, scores);
140 // or just keep them as strings
142 for (int j = 0; j < i; j++)
145 (Object) ( (Float) scores.get(j)).toString());
147 scores.addElement((Object) ascore);
148 while (symbols.hasMoreTokens()) {
150 ascore = symbols.nextToken();
151 scores.addElement( (Object) ascore);
154 Scores.put(id, scores);
157 else if (id.equals("jnetconf"))
159 // log.debug System.out.println("here");
160 id = "Prediction Confidence";
161 this.conf = new Vector(numSymbols);
162 for (int i = 0; i < numSymbols; i++)
164 conf.set(i, (Object) symbols.nextToken());
169 // Sequence or a prediction string (rendered as sequence)
171 StringBuffer newseq = new StringBuffer();
173 for (int i = 0; i < numSymbols; i++) {
174 newseq.append(symbols.nextToken());
177 if (id.indexOf(";") > -1) {
178 seq_entries.addElement(newseq);
180 String name = id.substring(id.indexOf(";")+1);
181 while (ids.lastIndexOf(name)>-1) {
182 name = id.substring(id.indexOf(";")+1)+"_"+1;
184 ids.addElement(name);
190 if (id.equals("JNETPRED")) {
191 id = "Predicted Secondary Structure";
193 seq_entries.addElement( newseq.toString() );
195 Symscores.put((Object) id, (Object) new Integer(ids.size()-1));
203 throw new IOException(
204 "JpredFile Parser: No sequence in the prediction!");
206 maxLength = seq_entries.elementAt(0).toString().length();
207 for (int i = 0; i < ids.size(); i++)
209 // Add all sequence like objects
211 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
212 seq_entries.elementAt(i).toString(), 1,
213 seq_entries.elementAt(i).toString().
215 if (!Symscores.containsKey(ids.elementAt(i))
216 && !isValidProteinSequence(newSeq.getSequence()))
218 throw new IOException(
219 "JPredConcise: Not a valid protein sequence - ("
220 + ids.elementAt(i).toString() + ")");
223 if (maxLength != seq_entries.elementAt(i).toString().length())
225 throw new IOException("JPredConcise: Entry (" +
226 ids.elementAt(i).toString()
227 + ") has an unexpected number of columns");
229 if (newSeq.getName().startsWith("QUERY") && QuerySeqPosition==-1) {
230 QuerySeqPosition = seqs.size();
233 seqs.addElement(newSeq);
244 public String print()
246 return "Not Supported";
249 public static void main(String[] args)
253 JPredFile blc = new JPredFile(args[0], "File");
254 for (int i = 0; i < blc.seqs.size(); i++)
256 System.out.println( ( (Sequence) blc.seqs.elementAt(i)).getName()
258 ( (Sequence) blc.seqs.elementAt(i)).getSequence()
262 catch (java.io.IOException e)
264 System.err.println("Exception " + e);
271 StringBuffer out = new StringBuffer();
273 out.append("START PRED\n");
274 for (int i = 0; i < s[0].sequence.length(); i++)
276 out.append(s[0].sequence.substring(i, i + 1) + " ");
277 out.append(s[1].sequence.substring(i, i + 1) + " ");
278 out.append(s[1].score[0].elementAt(i) + " ");
279 out.append(s[1].score[1].elementAt(i) + " ");
280 out.append(s[1].score[2].elementAt(i) + " ");
281 out.append(s[1].score[3].elementAt(i) + " ");
285 out.append("END PRED\n");
286 return out.toString();
289 public static void main(String[] args)
293 BLCFile blc = new BLCFile(args[0], "File");
294 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
295 for (int i = 0; i < blc.seqs.size(); i++)
297 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
299 String out = BLCFile.print(s);
301 AlignFrame af = new AlignFrame(null, s);
304 System.out.println(out);
306 catch (java.io.IOException e)
308 System.out.println("Exception " + e);