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;
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();
52 public JPredFile(String inFile, String type)
60 * parse a JPred concise file into a sequence-alignment like object.
65 // JBPNote log.System.out.println("all read in ");
67 QuerySeqPosition = -1;
69 Vector seq_entries = new Vector();
70 Vector ids = new Vector();
71 Hashtable Symscores = new Hashtable();
72 while ( (line = nextLine()) != null)
74 // Concise format allows no comments or non comma-formatted data
75 StringTokenizer str = new StringTokenizer(line, ":");
77 if (!str.hasMoreTokens())
83 String seqsym = str.nextToken();
84 StringTokenizer symbols = new StringTokenizer(seqsym, ",");
85 // decide if we have more than just alphanumeric symbols
86 int numSymbols = symbols.countTokens();
92 if (seqsym.length() != (2 * numSymbols))
94 // Set of scalars for some property
95 if (Scores.containsKey(id))
98 while (Scores.containsKey(id + "_" + i))
104 Vector scores = new Vector();
105 // Typecheck from first entry
107 String ascore="dead";
110 // store elements as floats...
111 while (symbols.hasMoreTokens()) {
112 ascore = symbols.nextToken();
113 Float score = new Float(ascore);
114 scores.addElement( (Object) score);
116 Scores.put(id, scores);
120 // or just keep them as strings
122 for (int j = 0; j < i; j++)
125 (Object) ( (Float) scores.get(j)).toString());
127 scores.addElement((Object) ascore);
128 while (symbols.hasMoreTokens()) {
130 ascore = symbols.nextToken();
131 scores.addElement( (Object) ascore);
134 Scores.put(id, scores);
137 else if (id.equals("jnetconf"))
139 // log.debug System.out.println("here");
140 id = "Prediction Confidence";
141 this.conf = new Vector(numSymbols);
142 for (int i = 0; i < numSymbols; i++)
144 conf.set(i, (Object) symbols.nextToken());
149 // Sequence or a prediction string (rendered as sequence)
151 StringBuffer newseq = new StringBuffer();
153 for (int i = 0; i < numSymbols; i++) {
154 newseq.append(symbols.nextToken());
157 if (id.indexOf(";") > -1) {
158 seq_entries.addElement(newseq);
160 String name = id.substring(id.indexOf(";")+1);
161 while (ids.lastIndexOf(name)>-1) {
162 name = id.substring(id.indexOf(";")+1)+"_"+1;
164 ids.addElement(name);
170 if (id.equals("JNETPRED")) {
171 id = "Predicted Secondary Structure";
173 seq_entries.addElement( newseq.toString() );
175 Symscores.put((Object) id, (Object) new Integer(ids.size()-1));
183 throw new IOException(
184 "JpredFile Parser: No sequence in the prediction!");
186 maxLength = seq_entries.elementAt(0).toString().length();
187 for (int i = 0; i < ids.size(); i++)
189 // Add all sequence like objects
191 Sequence newSeq = new Sequence(ids.elementAt(i).toString(),
192 seq_entries.elementAt(i).toString(), 1,
193 seq_entries.elementAt(i).toString().
195 if (!Symscores.containsKey(ids.elementAt(i))
196 && !isValidProteinSequence(newSeq.getSequence()))
198 throw new IOException(
199 "JPredConcise: Not a valid protein sequence - ("
200 + ids.elementAt(i).toString() + ")");
203 if (maxLength != seq_entries.elementAt(i).toString().length())
205 throw new IOException("JPredConcise: Entry (" +
206 ids.elementAt(i).toString()
207 + ") has an unexpected number of columns");
209 if (newSeq.getName().startsWith("QUERY") && QuerySeqPosition==-1) {
210 QuerySeqPosition = seqs.size();
213 seqs.addElement(newSeq);
224 public String print()
226 return "Not Supported";
229 public static void main(String[] args)
233 JPredFile blc = new JPredFile(args[0], "File");
234 for (int i = 0; i < blc.seqs.size(); i++)
236 System.out.println( ( (Sequence) blc.seqs.elementAt(i)).getName()
238 ( (Sequence) blc.seqs.elementAt(i)).getSequence()
242 catch (java.io.IOException e)
244 System.err.println("Exception " + e);
251 StringBuffer out = new StringBuffer();
253 out.append("START PRED\n");
254 for (int i = 0; i < s[0].sequence.length(); i++)
256 out.append(s[0].sequence.substring(i, i + 1) + " ");
257 out.append(s[1].sequence.substring(i, i + 1) + " ");
258 out.append(s[1].score[0].elementAt(i) + " ");
259 out.append(s[1].score[1].elementAt(i) + " ");
260 out.append(s[1].score[2].elementAt(i) + " ");
261 out.append(s[1].score[3].elementAt(i) + " ");
265 out.append("END PRED\n");
266 return out.toString();
269 public static void main(String[] args)
273 BLCFile blc = new BLCFile(args[0], "File");
274 DrawableSequence[] s = new DrawableSequence[blc.seqs.size()];
275 for (int i = 0; i < blc.seqs.size(); i++)
277 s[i] = new DrawableSequence( (Sequence) blc.seqs.elementAt(i));
279 String out = BLCFile.print(s);
281 AlignFrame af = new AlignFrame(null, s);
284 System.out.println(out);
286 catch (java.io.IOException e)
288 System.out.println("Exception " + e);