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 private int QuerySeqPosition = -1;
22 public void setQuerySeqPosition(int QuerySeqPosition)
24 this.QuerySeqPosition = QuerySeqPosition;
27 public int getQuerySeqPosition()
29 return QuerySeqPosition;
31 public Hashtable getScores() {
34 public Hashtable getSymscores() {
38 public JPredFile(String inStr)
43 public void initData()
47 Scores = new Hashtable();
50 QuerySeqPosition = -1;
53 public JPredFile(String inFile, String type)
61 * parse a JPred concise file into a sequence-alignment like object.
66 System.out.println("all read in ");
68 QuerySeqPosition = -1;
70 Vector seq_entries = new Vector();
71 Vector ids = new Vector();
72 Hashtable Symscores = new Hashtable();
73 while ( (line = nextLine()) != null)
75 // Concise format allows no comments or non comma-formatted data
76 StringTokenizer str = new StringTokenizer(line, ":");
78 if (!str.hasMoreTokens())
84 String seqsym = str.nextToken();
85 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
86 // decide if we have more than just alphanumeric symbols
87 int numSymbols = symbols.countTokens();
93 if (seqsym.length() != (2 * numSymbols))
95 // Set of scalars for some property
96 if (Scores.containsKey(id))
99 while (Scores.containsKey(id + "_" + i))
105 Vector scores = new Vector();
106 // Typecheck from first entry
108 String ascore="dead";
111 // store elements as floats...
112 while (symbols.hasMoreTokens()) {
113 ascore = symbols.nextToken();
114 Float score = new Float(ascore);
115 scores.addElement( (Object) score);
117 Scores.put(id, scores);
121 // or just keep them as strings
123 for (int j = 0; j < i; j++)
126 (Object) ( (Float) scores.get(j)).toString());
128 scores.addElement((Object) ascore);
129 while (symbols.hasMoreTokens()) {
131 ascore = symbols.nextToken();
132 scores.addElement( (Object) ascore);
135 Scores.put(id, scores);
138 else if (id.equals("jnetconf"))
140 System.out.println("here");
141 id = "Prediction Confidence";
142 this.conf = new Vector(numSymbols);
143 for (int i = 0; i < numSymbols; i++)
145 conf.set(i, (Object) symbols.nextToken());
150 // Sequence or a prediction string (rendered as sequence)
152 StringBuffer newseq = new StringBuffer();
154 for (int i = 0; i < numSymbols; i++) {
155 newseq.append(symbols.nextToken());
158 if (id.indexOf(";") > -1) {
159 seq_entries.addElement(newseq);
161 String name = id.substring(id.indexOf(";")+1);
162 while (ids.lastIndexOf(name)>-1) {
163 name = id.substring(id.indexOf(";")+1)+"_"+1;
165 ids.addElement(name);
171 if (id.equals("JNETPRED")) {
172 id = "Predicted Secondary Structure";
174 seq_entries.addElement( newseq.toString() );
176 Symscores.put((Object) id, (Object) new Integer(ids.size()-1));
184 throw new IOException(
185 "JpredFile Parser: No sequence in the prediction!");
187 maxLength = seq_entries.elementAt(0).toString().length();
188 for (int i = 0; i < ids.size(); i++)
190 // Add all sequence like objects
192 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
193 seq_entries.elementAt(i).toString(), 1,
194 seq_entries.elementAt(i).toString().
196 if (!Symscores.containsKey(ids.elementAt(i))
197 && !isValidProteinSequence(newSeq.getSequence()))
199 throw new IOException(
200 "JPredConcise: Not a valid protein sequence - ("
201 + ids.elementAt(i).toString() + ")");
204 if (maxLength != seq_entries.elementAt(i).toString().length())
206 throw new IOException("JPredConcise: Entry (" +
207 ids.elementAt(i).toString()
208 + ") has an unexpected number of columns");
210 if (newSeq.getName().startsWith("QUERY") && QuerySeqPosition==-1) {
211 QuerySeqPosition = seqs.size();
214 seqs.addElement(newSeq);
225 public String print()
227 return "Not Supported";
230 public static void main(String[] args)
234 JPredFile blc = new JPredFile(args[0], "File");
235 for (int i = 0; i < blc.seqs.size(); i++)
237 System.out.println( ( (Sequence) blc.seqs.elementAt(i)).getName()
239 ( (Sequence) blc.seqs.elementAt(i)).getSequence()
243 catch (java.io.IOException e)
245 System.out.println("Exception " + e);
252 StringBuffer out = new StringBuffer();
254 out.append("START PRED\n");
255 for (int i = 0; i < s[0].sequence.length(); i++)
257 out.append(s[0].sequence.substring(i, i + 1) + " ");
258 out.append(s[1].sequence.substring(i, i + 1) + " ");
259 out.append(s[1].score[0].elementAt(i) + " ");
260 out.append(s[1].score[1].elementAt(i) + " ");
261 out.append(s[1].score[2].elementAt(i) + " ");
262 out.append(s[1].score[3].elementAt(i) + " ");
266 out.append("END PRED\n");
267 return out.toString();
270 public static void main(String[] args)
274 BLCFile blc = new BLCFile(args[0], "File");
275 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
276 for (int i = 0; i < blc.seqs.size(); i++)
278 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
280 String out = BLCFile.print(s);
282 AlignFrame af = new AlignFrame(null, s);
285 System.out.println(out);
287 catch (java.io.IOException e)
289 System.out.println("Exception " + e);