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
20 Hashtable Symscores; // indexes of symbol annotation properties in sequenceI vector
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();
53 Hashtable Symscores = new Hashtable();
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())
66 String seqsym = str.nextToken();
67 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
68 // decide if we have more than just alphanumeric symbols
69 int numSymbols = symbols.countTokens();
75 if (seqsym.length() != (2 * numSymbols))
77 // Set of scalars for some property
78 if (Scores.containsKey(id))
81 while (Scores.containsKey(id + "_" + i))
87 Vector scores = new Vector();
88 // Typecheck from first entry
93 // store elements as floats...
94 while (symbols.hasMoreTokens()) {
95 ascore = symbols.nextToken();
96 Float score = new Float(ascore);
97 scores.addElement( (Object) score);
102 // or just keep them as strings
104 for (int j = 0; j < i; j++)
107 (Object) ( (Float) scores.get(j)).toString());
109 scores.addElement((Object) ascore);
110 while (symbols.hasMoreTokens()) {
112 ascore = symbols.nextToken();
113 scores.addElement( (Object) ascore);
116 Scores.put(id, scores);
119 if (id.equals("jnetconf"))
121 id = "Prediction Confidence";
122 this.conf = new Vector(numSymbols);
123 for (int i = 0; i < numSymbols; i++)
125 conf.set(i, (Object) symbols.nextToken());
130 // Sequence or a prediction string (rendered as sequence)
132 StringBuffer newseq = new StringBuffer();
134 for (int i = 0; i < numSymbols; i++) {
135 newseq.append(symbols.nextToken());
138 if (id.indexOf(";") > -1) {
139 seq_entries.addElement(newseq);
141 String name = id.substring(id.indexOf(";")+1);
142 while (ids.lastIndexOf(name)>-1) {
143 name = id.substring(id.indexOf(";")+1)+"_"+1;
145 ids.addElement(name);
150 if (id.equals("JNETPRED")) {
151 id = "Predicted Secondary Structure";
153 seq_entries.addElement( newseq.toString() );
155 Symscores.put((Object) id, (Object) new Integer(ids.size()-1));
163 throw new IOException(
164 "JpredFile Parser: No sequence in the prediction!");
166 maxLength = seq_entries.elementAt(0).toString().length();
167 for (int i = 0; i < ids.size(); i++)
169 // Add all sequence like objects
171 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
172 seq_entries.elementAt(i).toString(), 1,
173 seq_entries.elementAt(i).toString().
175 if (!Symscores.containsKey(ids.elementAt(i))
176 && !isValidProteinSequence(newSeq.getSequence()))
178 throw new IOException(
179 "JPredConcise: Not a valid protein sequence - ("
180 + ids.elementAt(i).toString() + ")");
183 if (maxLength != seq_entries.elementAt(i).toString().length())
185 throw new IOException("JPredConcise: Entry (" +
186 ids.elementAt(i).toString()
187 + ") has an unexpected number of columns");
189 seqs.addElement(newSeq);
200 public String print()
202 return "Not Supported";
205 public static void main(String[] args)
209 JPredFile blc = new JPredFile(args[0], "File");
210 for (int i = 0; i < blc.seqs.size(); i++)
212 System.out.println( ( (Sequence) blc.seqs.elementAt(i)).getName()
214 ( (Sequence) blc.seqs.elementAt(i)).getSequence()
218 catch (java.io.IOException e)
220 System.out.println("Exception " + e);
227 StringBuffer out = new StringBuffer();
229 out.append("START PRED\n");
230 for (int i = 0; i < s[0].sequence.length(); i++)
232 out.append(s[0].sequence.substring(i, i + 1) + " ");
233 out.append(s[1].sequence.substring(i, i + 1) + " ");
234 out.append(s[1].score[0].elementAt(i) + " ");
235 out.append(s[1].score[1].elementAt(i) + " ");
236 out.append(s[1].score[2].elementAt(i) + " ");
237 out.append(s[1].score[3].elementAt(i) + " ");
241 out.append("END PRED\n");
242 return out.toString();
245 public static void main(String[] args)
249 BLCFile blc = new BLCFile(args[0], "File");
250 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
251 for (int i = 0; i < blc.seqs.size(); i++)
253 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
255 String out = BLCFile.print(s);
257 AlignFrame af = new AlignFrame(null, s);
260 System.out.println(out);
262 catch (java.io.IOException e)
264 System.out.println("Exception " + e);