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 QuerySeqPosition = -1;
36 public JPredFile(String inFile, String type)
44 * parse a JPred concise file into a sequence-alignment like object.
50 System.out.println("all read in ");
52 QuerySeqPosition = -1;
54 Vector seq_entries = new Vector();
55 Vector ids = new Vector();
56 Hashtable Symscores = new Hashtable();
57 while ( (line = nextLine()) != null)
59 // Concise format allows no comments or non comma-formatted data
60 StringTokenizer str = new StringTokenizer(line, ":");
62 if (!str.hasMoreTokens())
68 String seqsym = str.nextToken();
69 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
70 // decide if we have more than just alphanumeric symbols
71 int numSymbols = symbols.countTokens();
77 if (seqsym.length() != (2 * numSymbols))
79 // Set of scalars for some property
80 if (Scores.containsKey(id))
83 while (Scores.containsKey(id + "_" + i))
89 Vector scores = new Vector();
90 // Typecheck from first entry
95 // store elements as floats...
96 while (symbols.hasMoreTokens()) {
97 ascore = symbols.nextToken();
98 Float score = new Float(ascore);
99 scores.addElement( (Object) score);
101 Scores.put(id, scores);
105 // or just keep them as strings
107 for (int j = 0; j < i; j++)
110 (Object) ( (Float) scores.get(j)).toString());
112 scores.addElement((Object) ascore);
113 while (symbols.hasMoreTokens()) {
115 ascore = symbols.nextToken();
116 scores.addElement( (Object) ascore);
119 Scores.put(id, scores);
122 else if (id.equals("jnetconf"))
124 System.out.println("here");
125 id = "Prediction Confidence";
126 this.conf = new Vector(numSymbols);
127 for (int i = 0; i < numSymbols; i++)
129 conf.set(i, (Object) symbols.nextToken());
134 // Sequence or a prediction string (rendered as sequence)
136 StringBuffer newseq = new StringBuffer();
138 for (int i = 0; i < numSymbols; i++) {
139 newseq.append(symbols.nextToken());
142 if (id.indexOf(";") > -1) {
143 seq_entries.addElement(newseq);
145 String name = id.substring(id.indexOf(";")+1);
146 while (ids.lastIndexOf(name)>-1) {
147 name = id.substring(id.indexOf(";")+1)+"_"+1;
149 ids.addElement(name);
155 if (id.equals("JNETPRED")) {
156 id = "Predicted Secondary Structure";
158 seq_entries.addElement( newseq.toString() );
160 Symscores.put((Object) id, (Object) new Integer(ids.size()-1));
168 throw new IOException(
169 "JpredFile Parser: No sequence in the prediction!");
171 maxLength = seq_entries.elementAt(0).toString().length();
172 for (int i = 0; i < ids.size(); i++)
174 // Add all sequence like objects
176 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
177 seq_entries.elementAt(i).toString(), 1,
178 seq_entries.elementAt(i).toString().
180 if (!Symscores.containsKey(ids.elementAt(i))
181 && !isValidProteinSequence(newSeq.getSequence()))
183 throw new IOException(
184 "JPredConcise: Not a valid protein sequence - ("
185 + ids.elementAt(i).toString() + ")");
188 if (maxLength != seq_entries.elementAt(i).toString().length())
190 throw new IOException("JPredConcise: Entry (" +
191 ids.elementAt(i).toString()
192 + ") has an unexpected number of columns");
194 if (newSeq.getName().startsWith("QUERY") && QuerySeqPosition==-1) {
195 QuerySeqPosition = seqs.size();
198 seqs.addElement(newSeq);
209 public String print()
211 return "Not Supported";
214 public static void main(String[] args)
218 JPredFile blc = new JPredFile(args[0], "File");
219 for (int i = 0; i < blc.seqs.size(); i++)
221 System.out.println( ( (Sequence) blc.seqs.elementAt(i)).getName()
223 ( (Sequence) blc.seqs.elementAt(i)).getSequence()
227 catch (java.io.IOException e)
229 System.out.println("Exception " + e);
236 StringBuffer out = new StringBuffer();
238 out.append("START PRED\n");
239 for (int i = 0; i < s[0].sequence.length(); i++)
241 out.append(s[0].sequence.substring(i, i + 1) + " ");
242 out.append(s[1].sequence.substring(i, i + 1) + " ");
243 out.append(s[1].score[0].elementAt(i) + " ");
244 out.append(s[1].score[1].elementAt(i) + " ");
245 out.append(s[1].score[2].elementAt(i) + " ");
246 out.append(s[1].score[3].elementAt(i) + " ");
250 out.append("END PRED\n");
251 return out.toString();
254 public static void main(String[] args)
258 BLCFile blc = new BLCFile(args[0], "File");
259 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
260 for (int i = 0; i < blc.seqs.size(); i++)
262 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
264 String out = BLCFile.print(s);
266 AlignFrame af = new AlignFrame(null, s);
269 System.out.println(out);
271 catch (java.io.IOException e)
273 System.out.println("Exception " + e);