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.
47 System.out.println("all read in ");
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, ":");
59 if (!str.hasMoreTokens())
65 String seqsym = str.nextToken();
66 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
67 // decide if we have more than just alphanumeric symbols
68 int numSymbols = symbols.countTokens();
74 if (seqsym.length() != (2 * numSymbols))
76 // Set of scalars for some property
77 if (Scores.containsKey(id))
80 while (Scores.containsKey(id + "_" + i))
86 Vector scores = new Vector();
87 // Typecheck from first entry
92 // store elements as floats...
93 while (symbols.hasMoreTokens()) {
94 ascore = symbols.nextToken();
95 Float score = new Float(ascore);
96 scores.addElement( (Object) score);
98 Scores.put(id, scores);
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 else if (id.equals("jnetconf"))
121 System.out.println("here");
122 id = "Prediction Confidence";
123 this.conf = new Vector(numSymbols);
124 for (int i = 0; i < numSymbols; i++)
126 conf.set(i, (Object) symbols.nextToken());
131 // Sequence or a prediction string (rendered as sequence)
133 StringBuffer newseq = new StringBuffer();
135 for (int i = 0; i < numSymbols; i++) {
136 newseq.append(symbols.nextToken());
139 if (id.indexOf(";") > -1) {
140 seq_entries.addElement(newseq);
142 String name = id.substring(id.indexOf(";")+1);
143 while (ids.lastIndexOf(name)>-1) {
144 name = id.substring(id.indexOf(";")+1)+"_"+1;
146 ids.addElement(name);
151 if (id.equals("JNETPRED")) {
152 id = "Predicted Secondary Structure";
154 seq_entries.addElement( newseq.toString() );
156 Symscores.put((Object) id, (Object) new Integer(ids.size()-1));
164 throw new IOException(
165 "JpredFile Parser: No sequence in the prediction!");
167 maxLength = seq_entries.elementAt(0).toString().length();
168 for (int i = 0; i < ids.size(); i++)
170 // Add all sequence like objects
172 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
173 seq_entries.elementAt(i).toString(), 1,
174 seq_entries.elementAt(i).toString().
176 if (!Symscores.containsKey(ids.elementAt(i))
177 && !isValidProteinSequence(newSeq.getSequence()))
179 throw new IOException(
180 "JPredConcise: Not a valid protein sequence - ("
181 + ids.elementAt(i).toString() + ")");
184 if (maxLength != seq_entries.elementAt(i).toString().length())
186 throw new IOException("JPredConcise: Entry (" +
187 ids.elementAt(i).toString()
188 + ") has an unexpected number of columns");
190 seqs.addElement(newSeq);
201 public String print()
203 return "Not Supported";
206 public static void main(String[] args)
210 JPredFile blc = new JPredFile(args[0], "File");
211 for (int i = 0; i < blc.seqs.size(); i++)
213 System.out.println( ( (Sequence) blc.seqs.elementAt(i)).getName()
215 ( (Sequence) blc.seqs.elementAt(i)).getSequence()
219 catch (java.io.IOException e)
221 System.out.println("Exception " + e);
228 StringBuffer out = new StringBuffer();
230 out.append("START PRED\n");
231 for (int i = 0; i < s[0].sequence.length(); i++)
233 out.append(s[0].sequence.substring(i, i + 1) + " ");
234 out.append(s[1].sequence.substring(i, i + 1) + " ");
235 out.append(s[1].score[0].elementAt(i) + " ");
236 out.append(s[1].score[1].elementAt(i) + " ");
237 out.append(s[1].score[2].elementAt(i) + " ");
238 out.append(s[1].score[3].elementAt(i) + " ");
242 out.append("END PRED\n");
243 return out.toString();
246 public static void main(String[] args)
250 BLCFile blc = new BLCFile(args[0], "File");
251 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
252 for (int i = 0; i < blc.seqs.size(); i++)
254 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
256 String out = BLCFile.print(s);
258 AlignFrame af = new AlignFrame(null, s);
261 System.out.println(out);
263 catch (java.io.IOException e)
265 System.out.println("Exception " + e);