JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / io / ModellerDescription.js
1 Clazz.declarePackage ("jalview.io");
2 Clazz.load (["java.util.Hashtable"], "jalview.io.ModellerDescription", ["jalview.datamodel.DBRefSource", "jalview.jsdev.RegExp", "java.util.StringTokenizer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.seqTypes = null;
5 this.Fields = null;
6 this.TYPE = 0;
7 this.LOCALID = 1;
8 this.START = 2;
9 this.START_CHAIN = 3;
10 this.END = 4;
11 this.END_CHAIN = 5;
12 this.DESCRIPTION1 = 6;
13 this.DESCRIPTION2 = 7;
14 this.RESOLUTION = 8;
15 this.TAIL = 9;
16 this.Types = null;
17 this.Padding = null;
18 this.fields = null;
19 if (!Clazz.isClassDefined ("jalview.io.ModellerDescription.resCode")) {
20 jalview.io.ModellerDescription.$ModellerDescription$resCode$ ();
21 }
22 Clazz.instantialize (this, arguments);
23 }, jalview.io, "ModellerDescription");
24 Clazz.prepareFields (c$, function () {
25 this.seqTypes =  Clazz.newArray (-1, ["sequence", "structure", "structureX", "structureN"]);
26 this.Fields =  Clazz.newArray (-1, ["objectType", "objectId", "startField", "startCode", "endField", "endCode", "description1", "description2", "resolutionField", "tailField"]);
27 this.Types =  Clazz.newIntArray (-1, [0, 0, 1, 0, 1, 0, 0, 0, 0, 0]);
28 this.Padding =  Clazz.newCharArray (-1, [' ', ' ', ' ', '.', ' ', '.', '.', '.', '.', '.']);
29 this.fields =  new java.util.Hashtable ();
30 });
31 Clazz.makeConstructor (c$, 
32 function () {
33 this.fields.put (this.Fields[9], "");
34 });
35 Clazz.defineMethod (c$, "validResidueCode", 
36 ($fz = function (field) {
37 var val = null;
38 var r = jalview.jsdev.RegExp.newRegex (["\\s*((([-0-9]+).?)|FIRST|LAST|@)"]);
39 if (!r.search (field)) {
40 return null;
41 }var value = r.stringMatchedI (3);
42 if (value == null) {
43 value = r.stringMatchedI (1);
44 }try {
45 val = Integer.$valueOf (value);
46 return Clazz.innerTypeInstance (jalview.io.ModellerDescription.resCode, this, null, field, val);
47 } catch (e) {
48 if (Clazz.exceptionOf (e, Exception)) {
49 } else {
50 throw e;
51 }
52 }
53 return Clazz.innerTypeInstance (jalview.io.ModellerDescription.resCode, this, null, field, null);
54 }, $fz.isPrivate = true, $fz), "~S");
55 Clazz.defineMethod (c$, "parseDescription", 
56 ($fz = function (desc) {
57 var fields =  new java.util.Hashtable ();
58 var st =  new java.util.StringTokenizer (desc, ":", true);
59 var field;
60 var type = -1;
61 if (st.countTokens () > 0) {
62 var i = 0;
63 field = st.nextToken (":");
64 do {
65 if (this.seqTypes[i].equalsIgnoreCase (field)) {
66 break;
67 }} while (++i < this.seqTypes.length);
68 if (i < this.seqTypes.length) {
69 st.nextToken ();
70 type = i;
71 i = 1;
72 while (i < 9 && st.hasMoreTokens ()) {
73 if ((field = st.nextToken (":")) != null) {
74 if (!field.equals (":")) {
75 if (this.Types[i] == 1) {
76 var val = this.validResidueCode (field);
77 if (val != null) {
78 fields.put ( String.instantialize (this.Fields[i] + "num"), val);
79 } else {
80 type = -1;
81 };}fields.put (this.Fields[i++], field);
82 if (st.hasMoreTokens ()) {
83 st.nextToken ();
84 }} else {
85 i++;
86 }}}
87 if (i == 9) {
88 while (st.hasMoreTokens ()) {
89 var tl = st.nextToken (":");
90 field += tl.equals (":") ? tl : (":" + tl);
91 }
92 fields.put (this.Fields[9], field);
93 }}}if (type == -1) {
94 fields =  new java.util.Hashtable ();
95 fields.put (this.Fields[9],  String.instantialize (desc));
96 } else {
97 fields.put (this.Fields[0], this.seqTypes[type]);
98 }return fields;
99 }, $fz.isPrivate = true, $fz), "~S");
100 Clazz.makeConstructor (c$, 
101 function (desc) {
102 if (desc == null) {
103 desc = "";
104 }this.fields = this.parseDescription (desc);
105 }, "~S");
106 Clazz.defineMethod (c$, "setStartCode", 
107 function (v) {
108 var r;
109 this.fields.put (this.Fields[2] + "num", r = Clazz.innerTypeInstance (jalview.io.ModellerDescription.resCode, this, null, v));
110 this.fields.put (this.Fields[2], r.field);
111 }, "~N");
112 Clazz.defineMethod (c$, "setEndCode", 
113 function (v) {
114 var r;
115 this.fields.put (this.Fields[4] + "num", r = Clazz.innerTypeInstance (jalview.io.ModellerDescription.resCode, this, null, v));
116 this.fields.put (this.Fields[4], r.field);
117 }, "~N");
118 Clazz.makeConstructor (c$, 
119 function (seq) {
120 if (seq.getDescription () != null) {
121 this.fields = this.parseDescription (seq.getDescription ());
122 }if (this.isModellerFieldset ()) {
123 if (this.getStartCode () == null || (this.getStartNum () != seq.getStart () && this.getStartCode ().val != null)) {
124 this.setStartCode (seq.getStart ());
125 }if (this.getEndCode () == null || (this.getEndNum () != seq.getEnd () && this.getStartCode () != null && this.getStartCode ().val != null)) {
126 this.setEndCode (seq.getEnd ());
127 }} else {
128 this.setStartCode (seq.getStart ());
129 this.setEndCode (seq.getEnd ());
130 this.fields.put (this.Fields[1], seq.getName ());
131 var t = 0;
132 if (seq.getDatasetSequence () != null && seq.getDatasetSequence ().getDBRef () != null) {
133 var dbr = seq.getDatasetSequence ().getDBRef ();
134 var i;
135 var j;
136 for (i = 0, j = dbr.length; i < j; i++) {
137 if (dbr[i] != null) {
138 if (dbr[i].getSource ().equals (jalview.datamodel.DBRefSource.PDB)) {
139 this.fields.put (this.Fields[1], dbr[i].getAccessionId ());
140 t = 2;
141 break;
142 }}}
143 }this.fields.put (this.Fields[0], this.seqTypes[t]);
144 }}, "jalview.datamodel.SequenceI");
145 Clazz.defineMethod (c$, "isModellerFieldset", 
146 function () {
147 return (this.fields.containsKey (this.Fields[0]));
148 });
149 Clazz.defineMethod (c$, "getDescriptionLine", 
150 function () {
151 var desc = "";
152 var lastfield = this.Fields.length - 1;
153 if (this.isModellerFieldset ()) {
154 var value;
155 for (; lastfield > 6; lastfield--) {
156 if (this.fields.containsKey (this.Fields[lastfield])) {
157 break;
158 }}
159 for (var i = 0; i < lastfield; i++) {
160 value = this.fields.get (this.Fields[i]);
161 if (value != null && value.length > 0) {
162 desc += (this.fields.get (this.Fields[i])) + ":";
163 } else {
164 desc += this.Padding[i] + ":";
165 }}
166 }if (this.fields.containsKey (this.Fields[lastfield])) {
167 desc += this.fields.get (this.Fields[lastfield]);
168 } else {
169 desc += ".";
170 }return desc;
171 });
172 Clazz.defineMethod (c$, "getStartNum", 
173 function () {
174 var start = 0;
175 var val = this.getStartCode ();
176 if (val != null && val.val != null) {
177 return val.val.intValue ();
178 }return start;
179 });
180 Clazz.defineMethod (c$, "getStartCode", 
181 function () {
182 if (this.isModellerFieldset () && this.fields.containsKey (this.Fields[2] + "num")) {
183 return this.fields.get (this.Fields[2] + "num");
184 }return null;
185 });
186 Clazz.defineMethod (c$, "getEndCode", 
187 function () {
188 if (this.isModellerFieldset () && this.fields.containsKey (this.Fields[4] + "num")) {
189 return this.fields.get (this.Fields[4] + "num");
190 }return null;
191 });
192 Clazz.defineMethod (c$, "getEndNum", 
193 function () {
194 var end = 0;
195 var val = this.getEndCode ();
196 if (val != null && val.val != null) {
197 return val.val.intValue ();
198 }return end;
199 });
200 Clazz.defineMethod (c$, "updateSequenceI", 
201 function (newSeq) {
202 if (this.isModellerFieldset ()) {
203 var rc = this.getStartCode ();
204 if (rc != null && rc.val != null) {
205 newSeq.setStart (this.getStartNum ());
206 } else {
207 newSeq.setStart (1);
208 }rc = this.getEndCode ();
209 if (rc != null && rc.val != null) {
210 newSeq.setEnd (this.getEndNum ());
211 } else {
212 newSeq.setEnd (newSeq.getStart () + newSeq.getLength ());
213 }return true;
214 }return false;
215 }, "jalview.datamodel.SequenceI");
216 c$.$ModellerDescription$resCode$ = function () {
217 Clazz.pu$h ();
218 c$ = Clazz.decorateAsClass (function () {
219 Clazz.prepareCallback (this, arguments);
220 this.val = null;
221 this.field = null;
222 Clazz.instantialize (this, arguments);
223 }, jalview.io.ModellerDescription, "resCode");
224 Clazz.makeConstructor (c$, 
225 function (a, b) {
226 this.val = b;
227 this.field = a;
228 }, "~S,Integer");
229 Clazz.makeConstructor (c$, 
230 function (a) {
231 this.val =  new Integer (a);
232 this.field = this.val.toString ();
233 }, "~N");
234 c$ = Clazz.p0p ();
235 };
236 });