3 * JalviewX / Vamsas Project
4 * JPred.seq.concise reader
8 import jalview.datamodel.*;
14 public class JPredFile
19 Hashtable Scores; // Hash of names and score vectors
21 public JPredFile(String inStr)
26 public void initData()
30 Scores = new Hashtable();
33 public JPredFile(String inFile, String type)
41 * parse a JPred concise file into a sequence-alignment like object.
51 Vector seq_entries = new Vector();
52 Vector ids = new Vector();
54 while ( (line = nextLine()) != null)
56 // Concise format allows no comments or non comma-formatted data
57 StringTokenizer str = new StringTokenizer(line, ":");
60 if (str.hasMoreTokens())
63 String seqsym = str.nextToken();
64 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
65 // decide if we have more than just alphanumeric symbols
66 int numSymbols = symbols.countTokens();
67 if (seq.length() != (2 * numSymbols))
69 // Set of scalars for some property
70 if (Scores.containsKey(id))
73 while (Scores.containsKey(id + "_" + i))
79 Vector scores = new Vector(numSymbols);
80 // Typecheck from first entry
82 String ascore = symbols.nextToken();
85 // store elements as floats...
88 Float score = new Float(ascore);
89 scores.set(i, (Object) score);
90 ascore = symbols.nextToken();
92 while (++i < numSymbols);
96 // or just keep them as strings
97 for (int j = 0; j < i; j++)
101 ( (Float) scores.get(j)).toString());
105 scores.set(i, ascore);
106 ascore = symbols.nextToken();
108 while (++i < numSymbols);
110 Scores.put(id, scores);
114 if (id.equals("jnetconf"))
116 id = "Prediction Confidence";
117 this.conf = new Vector(numSymbols);
118 for (int i = 0; i < numSymbols; i++)
120 conf.set(i, (Object) symbols.nextToken());
125 // Sequence or a prediction string (rendered as sequence)
127 StringBuffer newseq = new StringBuffer();
128 for (int i = 0; i < numSymbols; i++)
130 newseq.append(symbols.nextToken());
132 if (id.indexOf(";") > -1)
134 seq_entries.addElement(newseq);
135 ids.addElement(id.substring(id.indexOf(";")));
140 if (id.equals("JNETPRED"))
142 id = "Predicted Secondary Structure";
144 seq_entries.addElement(newseq);
155 throw new IOException("JpredFile Parser: No sequence in the prediction!");
157 maxLength = seq_entries.elementAt(0).toString().length();
158 for (int i = 0; i < ids.size(); i++)
160 // Add all sequence like objects
162 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
163 seq_entries.elementAt(i).toString(), 1,
164 seq_entries.elementAt(i).toString().length());
165 if (!isValidProteinSequence(newSeq.getSequence()))
167 throw new IOException("JPredConcise: Not a valid protein sequence - ("
168 + ids.elementAt(i).toString() + ")");
171 if (maxLength != seq_entries.elementAt(i).toString().length())
173 throw new IOException("JPredConcise: Entry (" +
174 ids.elementAt(i).toString()
175 + ") has an unexpected number of columns");
177 seqs.addElement(newSeq);
188 public String print()
190 return "Not Supported";
194 StringBuffer out = new StringBuffer();
196 out.append("START PRED\n");
197 for (int i = 0; i < s[0].sequence.length(); i++)
199 out.append(s[0].sequence.substring(i, i + 1) + " ");
200 out.append(s[1].sequence.substring(i, i + 1) + " ");
201 out.append(s[1].score[0].elementAt(i) + " ");
202 out.append(s[1].score[1].elementAt(i) + " ");
203 out.append(s[1].score[2].elementAt(i) + " ");
204 out.append(s[1].score[3].elementAt(i) + " ");
208 out.append("END PRED\n");
209 return out.toString();
212 public static void main(String[] args)
216 BLCFile blc = new BLCFile(args[0], "File");
217 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
218 for (int i = 0; i < blc.seqs.size(); i++)
220 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
222 String out = BLCFile.print(s);
224 AlignFrame af = new AlignFrame(null, s);
227 System.out.println(out);
229 catch (java.io.IOException e)
231 System.out.println("Exception " + e);