1 Clazz.declarePackage ("jalview.io");
2 Clazz.load (["jalview.io.AlignFile"], "jalview.io.JPredFile", ["jalview.datamodel.Alignment", "$.Sequence", "jalview.io.JnetAnnotationMaker", "jalview.util.MessageManager", "java.io.IOException", "java.lang.Float", "$.StringBuffer", "java.util.Hashtable", "$.StringTokenizer", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
8 this.QuerySeqPosition = 0;
10 Clazz.instantialize (this, arguments);
11 }, jalview.io, "JPredFile", jalview.io.AlignFile);
12 Clazz.defineMethod (c$, "setQuerySeqPosition",
13 function (QuerySeqPosition) {
14 this.QuerySeqPosition = QuerySeqPosition;
16 Clazz.defineMethod (c$, "getQuerySeqPosition",
18 return this.QuerySeqPosition;
20 Clazz.defineMethod (c$, "getScores",
24 Clazz.defineMethod (c$, "getSymscores",
26 return this.Symscores;
28 Clazz.defineMethod (c$, "initData",
30 Clazz.superCall (this, jalview.io.JPredFile, "initData", []);
31 this.Scores = new java.util.Hashtable ();
35 Clazz.overrideMethod (c$, "parse",
38 this.QuerySeqPosition = -1;
40 var seq_entries = new java.util.Vector ();
41 var ids = new java.util.Vector ();
42 var Symscores = new java.util.Hashtable ();
43 while ((line = this.nextLine ()) != null) {
44 var str = new java.util.StringTokenizer (line, ":");
46 if (!str.hasMoreTokens ()) {
48 }id = str.nextToken ();
49 var seqsym = str.nextToken ();
50 var symbols = new java.util.StringTokenizer (seqsym, ",");
51 var numSymbols = symbols.countTokens ();
52 if (numSymbols == 0) {
54 }if (seqsym.length != (2 * numSymbols)) {
55 if (this.Scores.containsKey (id)) {
57 while (this.Scores.containsKey (id + "_" + i)) {
61 }var scores = new java.util.Vector ();
65 while (symbols.hasMoreTokens ()) {
66 ascore = symbols.nextToken ();
67 var score = new Float (ascore);
68 scores.addElement (score);
70 this.Scores.put (id, scores);
72 if (Clazz.exceptionOf (e, Exception)) {
74 for (var j = 0; j < i; j++) {
75 scores.setElementAt ((scores.elementAt (j)).toString (), j);
77 scores.addElement (ascore);
78 while (symbols.hasMoreTokens ()) {
79 ascore = symbols.nextToken ();
80 scores.addElement (ascore);
82 this.Scores.put (id, scores);
87 } else if (id.equals ("jnetconf")) {
88 id = "Prediction Confidence";
89 this.conf = new java.util.Vector (numSymbols);
90 for (var i = 0; i < numSymbols; i++) {
91 this.conf.setElementAt (symbols.nextToken (), i);
94 var newseq = new StringBuffer ();
95 for (var i = 0; i < numSymbols; i++) {
96 newseq.append (symbols.nextToken ());
98 if (id.indexOf (";") > -1) {
99 seq_entries.addElement (newseq);
101 var name = id.substring (id.indexOf (";") + 1);
102 while (ids.lastIndexOf (name) > -1) {
103 name = id.substring (id.indexOf (";") + 1) + "_" + ++i;
105 if (this.QuerySeqPosition == -1) this.QuerySeqPosition = ids.size ();
106 ids.addElement (name);
109 if (id.equals ("JNETPRED")) {
110 id = "Predicted Secondary Structure";
111 }seq_entries.addElement (newseq.toString ());
113 Symscores.put (id, new Integer (ids.size () - 1));
115 this.maxLength = seq_entries.elementAt (0).toString ().length;
116 for (var i = 0; i < ids.size (); i++) {
117 var newSeq = new jalview.datamodel.Sequence (ids.elementAt (i).toString (), seq_entries.elementAt (i).toString (), 1, seq_entries.elementAt (i).toString ().length);
118 if (this.maxLength != seq_entries.elementAt (i).toString ().length) {
119 throw new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.jpredconcide_entry_has_unexpected_number_of_columns", Clazz.newArray (-1, [ids.elementAt (i).toString ()])));
120 }if ((newSeq.getName ().startsWith ("QUERY") || newSeq.getName ().startsWith ("align;")) && (this.QuerySeqPosition == -1)) {
121 this.QuerySeqPosition = this.seqs.size ();
122 }this.seqs.addElement (newSeq);
124 if (this.seqs.size () > 0 && this.QuerySeqPosition > -1) {
125 var tal = new jalview.datamodel.Alignment (this.getSeqsAsArray ());
127 jalview.io.JnetAnnotationMaker.add_annotation (this, tal, this.QuerySeqPosition, true);
129 if (Clazz.exceptionOf (e, Exception)) {
131 var ex = new java.io.IOException (jalview.util.MessageManager.formatMessage ("exception.couldnt_parse_concise_annotation_for_prediction", Clazz.newArray (-1, [e.getMessage ()])));
132 e.printStackTrace ();
138 this.annotations = new java.util.Vector ();
139 var aan = tal.getAlignmentAnnotation ();
140 for (var aai = 0; aan != null && aai < aan.length; aai++) {
141 this.annotations.addElement (aan[aai]);
144 Clazz.overrideMethod (c$, "print",
146 return "Not Supported";
148 c$.main = Clazz.defineMethod (c$, "main",
151 var blc = new jalview.io.JPredFile (args[0], "File");
152 for (var i = 0; i < blc.seqs.size (); i++) {
153 System.out.println ((blc.seqs.elementAt (i)).getName () + "\n" + (blc.seqs.elementAt (i)).getSequenceAsString () + "\n");
156 if (Clazz.exceptionOf (e, java.io.IOException)) {
157 System.err.println ("Exception " + e);
163 Clazz.defineMethod (c$, "removeNonSequences",
165 if (this.annotSeqs != null) {
167 }this.annotSeqs = new java.util.Vector ();
168 var newseqs = new java.util.Vector ();
170 var j = this.seqs.size ();
171 for (; i < this.QuerySeqPosition; i++) {
172 this.annotSeqs.addElement (this.seqs.elementAt (i));
175 var sq = this.seqs.elementAt (j - 1);
176 if (sq.getName ().toUpperCase ().startsWith ("JPRED")) {
177 this.annotSeqs.addElement (sq);
178 this.seqs.removeElementAt (--j);
179 }}for (; i < j; i++) {
180 newseqs.addElement (this.seqs.elementAt (i));
182 this.seqs.removeAllElements ();