JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / io / AnnotationFile.js
1 Clazz.declarePackage ("jalview.io");
2 Clazz.load (null, "jalview.io.AnnotationFile", ["jalview.analysis.Conservation", "jalview.datamodel.AlignmentAnnotation", "$.Annotation", "$.ColumnSelection", "$.GraphLine", "$.SequenceGroup", "jalview.io.AppletFormatAdapter", "jalview.jsdev.GenericFileAdapter", "jalview.schemes.ColourSchemeProperty", "$.ResidueProperties", "$.UserColourScheme", "jalview.util.Comparison", "$.Format", "java.awt.Color", "java.io.BufferedReader", "$.InputStreamReader", "$.StringReader", "java.lang.Boolean", "$.Float", "$.StringBuffer", "java.util.ArrayList", "$.BitSet", "$.Date", "$.Hashtable", "$.StringTokenizer", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.newline = null;
5 this.text = null;
6 if (!Clazz.isClassDefined ("jalview.io.AnnotationFile.ViewDef")) {
7 jalview.io.AnnotationFile.$AnnotationFile$ViewDef$ ();
8 }
9 this.refSeq = null;
10 this.refSeqId = null;
11 this.nlinesread = 0;
12 this.lastread = "";
13 Clazz.instantialize (this, arguments);
14 }, jalview.io, "AnnotationFile");
15 Clazz.prepareFields (c$, function () {
16 this.newline = System.getProperty ("line.separator");
17 });
18 Clazz.makeConstructor (c$, 
19 function () {
20 this.init ();
21 });
22 Clazz.defineMethod (c$, "setNewlineString", 
23 function (nl) {
24 this.newline = nl;
25 this.init ();
26 }, "~S");
27 Clazz.defineMethod (c$, "getNewlineString", 
28 function () {
29 return this.newline;
30 });
31 Clazz.defineMethod (c$, "init", 
32 ($fz = function () {
33 this.text =  new StringBuffer ("JALVIEW_ANNOTATION" + this.newline + "# Created: " +  new java.util.Date () + this.newline + this.newline);
34 this.refSeq = null;
35 this.refSeqId = null;
36 }, $fz.isPrivate = true, $fz));
37 Clazz.defineMethod (c$, "printAnnotations", 
38 function (annotations, list, properties) {
39 return this.printAnnotations (annotations, list, properties, null, null, null);
40 }, "~A,java.util.List,java.util.Hashtable");
41 Clazz.defineMethod (c$, "printAnnotations", 
42 function (annotations, list, properties, cs, al, view) {
43 if (view != null) {
44 if (view.viewname != null) {
45 this.text.append ("VIEW_DEF\t" + view.viewname + "\n");
46 }if (list == null) {
47 list = view.visibleGroups;
48 }if (cs == null) {
49 cs = view.hiddencols;
50 }if (al == null) {
51 }}if (al != null && al.hasSeqrep ()) {
52 this.text.append ("VIEW_SETREF\t" + al.getSeqrep ().getName () + "\n");
53 }if (cs != null && cs.hasHiddenColumns ()) {
54 this.text.append ("VIEW_HIDECOLS\t");
55 var hc = cs.getHiddenColumns ();
56 var comma = false;
57 for (var r, $r = hc.iterator (); $r.hasNext () && ((r = $r.next ()) || true);) {
58 if (!comma) {
59 comma = true;
60 } else {
61 this.text.append (",");
62 }this.text.append ("" + r[0]);
63 this.text.append ("-");
64 this.text.append ("" + r[1]);
65 }
66 this.text.append ("\n");
67 }if (annotations != null) {
68 var oneColour = true;
69 var row;
70 var comma;
71 var refSeq = null;
72 var refGroup = null;
73 var colours =  new StringBuffer ();
74 var graphLine =  new StringBuffer ();
75 var rowprops =  new StringBuffer ();
76 var graphGroup =  new java.util.Hashtable ();
77 var graphGroup_refs =  new java.util.Hashtable ();
78 var graphGroupSeen =  new java.util.BitSet ();
79 var color;
80 for (var i = 0; i < annotations.length; i++) {
81 row = annotations[i];
82 if (!row.visible && !row.hasScore () && !(row.graphGroup > -1 && graphGroupSeen.get (row.graphGroup))) {
83 continue;
84 }color = null;
85 oneColour = true;
86 this.writeSequence_Ref (refSeq, row.sequenceRef);
87 refSeq = row.sequenceRef;
88 this.writeGroup_Ref (refGroup, row.groupRef);
89 refGroup = row.groupRef;
90 var hasGlyphs = row.hasIcons;
91 var hasLabels = row.hasText;
92 var hasValues = row.$hasScore;
93 var hasText = false;
94 for (var j = 0; row.annotations != null && j < row.annotations.length && (!hasGlyphs || !hasLabels || !hasValues); j++) {
95 if (row.annotations[j] != null) {
96 hasLabels = new Boolean (hasLabels | (row.annotations[j].displayCharacter != null && row.annotations[j].displayCharacter.length > 0 && !row.annotations[j].displayCharacter.equals (" "))).valueOf ();
97 hasGlyphs = new Boolean (hasGlyphs | ((row.annotations[j].secondaryStructure).charCodeAt (0) != 0 && row.annotations[j].secondaryStructure != ' ')).valueOf ();
98 hasValues = new Boolean (hasValues | (!Float.isNaN (row.annotations[j].value))).valueOf ();
99 hasText = new Boolean (hasText | (row.annotations[j].description != null && row.annotations[j].description.length > 0)).valueOf ();
100 }}
101 if (row.graph == 0) {
102 this.text.append ("NO_GRAPH\t");
103 hasValues = false;
104 } else {
105 if (row.graph == 1) {
106 this.text.append ("BAR_GRAPH\t");
107 hasGlyphs = false;
108 } else if (row.graph == 2) {
109 hasGlyphs = false;
110 this.text.append ("LINE_GRAPH\t");
111 }if (row.getThreshold () != null) {
112 graphLine.append ("GRAPHLINE\t");
113 graphLine.append (row.label);
114 graphLine.append ("\t");
115 graphLine.append (row.getThreshold ().value);
116 graphLine.append ("\t");
117 graphLine.append (row.getThreshold ().label);
118 graphLine.append ("\t");
119 graphLine.append (jalview.util.Format.getHexString (row.getThreshold ().colour));
120 graphLine.append (this.newline);
121 }if (row.graphGroup > -1) {
122 graphGroupSeen.set (row.graphGroup);
123 var key =  new Integer (row.graphGroup);
124 if (graphGroup.containsKey (key)) {
125 graphGroup.put (key, graphGroup.get (key) + "\t" + row.label);
126 } else {
127 graphGroup_refs.put (key,  Clazz.newArray (-1, [refSeq, refGroup]));
128 graphGroup.put (key, row.label);
129 }}}this.text.append (row.label + "\t");
130 if (row.description != null) {
131 this.text.append (row.description + "\t");
132 }for (var j = 0; row.annotations != null && j < row.annotations.length; j++) {
133 if (refSeq != null && jalview.util.Comparison.isGap (refSeq.getCharAt (j))) {
134 continue;
135 }if (row.annotations[j] != null) {
136 comma = "";
137 if (hasGlyphs) {
138 this.text.append (comma);
139 if (row.annotations[j].secondaryStructure != ' ') {
140 this.text.append (row.annotations[j].secondaryStructure);
141 }comma = ",";
142 }if (hasValues) {
143 if (!Float.isNaN (row.annotations[j].value)) {
144 this.text.append (comma + row.annotations[j].value);
145 } else {
146 System.err.println ("Skipping NaN - not valid value.");
147 this.text.append (comma + 0);
148 }comma = ",";
149 }if (hasLabels) {
150 if (row.annotations[j].displayCharacter != null && row.annotations[j].displayCharacter.length > 0 && !row.annotations[j].displayCharacter.equals (" ")) {
151 this.text.append (comma + row.annotations[j].displayCharacter);
152 comma = ",";
153 }}if (hasText) {
154 if (row.annotations[j].description != null && row.annotations[j].description.length > 0 && !row.annotations[j].description.equals (row.annotations[j].displayCharacter)) {
155 this.text.append (comma + row.annotations[j].description);
156 comma = ",";
157 }}if (color != null && !color.equals (row.annotations[j].colour)) {
158 oneColour = false;
159 }color = row.annotations[j].colour;
160 if (row.annotations[j].colour != null && row.annotations[j].colour !== java.awt.Color.black) {
161 this.text.append (comma + "[" + jalview.util.Format.getHexString (row.annotations[j].colour) + "]");
162 comma = ",";
163 }}this.text.append ("|");
164 }
165 if (row.hasScore ()) {
166 this.text.append ("\t" + row.score);
167 }this.text.append (this.newline);
168 if (color != null && color !== java.awt.Color.black && oneColour) {
169 colours.append ("COLOUR\t");
170 colours.append (row.label);
171 colours.append ("\t");
172 colours.append (jalview.util.Format.getHexString (color));
173 colours.append (this.newline);
174 }if (row.scaleColLabel || row.showAllColLabels || row.centreColLabels) {
175 rowprops.append ("ROWPROPERTIES\t");
176 rowprops.append (row.label);
177 rowprops.append ("\tscaletofit=");
178 rowprops.append (row.scaleColLabel);
179 rowprops.append ("\tshowalllabs=");
180 rowprops.append (row.showAllColLabels);
181 rowprops.append ("\tcentrelabs=");
182 rowprops.append (row.centreColLabels);
183 rowprops.append (this.newline);
184 }if (graphLine.length () > 0) {
185 this.text.append (graphLine.toString ());
186 graphLine.setLength (0);
187 }}
188 this.text.append (this.newline);
189 this.text.append (colours.toString ());
190 if (graphGroup.size () > 0) {
191 var oldRefSeq = refSeq;
192 var oldRefGroup = refGroup;
193 for (var combine_statement, $combine_statement = graphGroup.entrySet ().iterator (); $combine_statement.hasNext () && ((combine_statement = $combine_statement.next ()) || true);) {
194 var seqRefAndGroup = graphGroup_refs.get (combine_statement.getKey ());
195 this.writeSequence_Ref (refSeq, seqRefAndGroup[0]);
196 refSeq = seqRefAndGroup[0];
197 this.writeGroup_Ref (refGroup, seqRefAndGroup[1]);
198 refGroup = seqRefAndGroup[1];
199 this.text.append ("COMBINE\t");
200 this.text.append (combine_statement.getValue ());
201 this.text.append (this.newline);
202 }
203 this.writeSequence_Ref (refSeq, oldRefSeq);
204 refSeq = oldRefSeq;
205 this.writeGroup_Ref (refGroup, oldRefGroup);
206 refGroup = oldRefGroup;
207 }this.text.append (rowprops.toString ());
208 }if (list != null) {
209 this.printGroups (list);
210 }if (properties != null) {
211 this.text.append (this.newline);
212 this.text.append (this.newline);
213 this.text.append ("ALIGNMENT");
214 var en = properties.keys ();
215 while (en.hasMoreElements ()) {
216 var key = en.nextElement ().toString ();
217 this.text.append ("\t");
218 this.text.append (key);
219 this.text.append ("=");
220 this.text.append (properties.get (key));
221 }
222 }return this.text.toString ();
223 }, "~A,java.util.List,java.util.Hashtable,jalview.datamodel.ColumnSelection,jalview.datamodel.AlignmentI,jalview.io.AnnotationFile.ViewDef");
224 Clazz.defineMethod (c$, "writeGroup_Ref", 
225 ($fz = function (refGroup, next_refGroup) {
226 if (next_refGroup == null) {
227 if (refGroup != null) {
228 this.text.append (this.newline);
229 this.text.append ("GROUP_REF\t");
230 this.text.append ("ALIGNMENT");
231 this.text.append (this.newline);
232 }return true;
233 } else {
234 if (refGroup == null || refGroup !== next_refGroup) {
235 this.text.append (this.newline);
236 this.text.append ("GROUP_REF\t");
237 this.text.append (next_refGroup.getName ());
238 this.text.append (this.newline);
239 return true;
240 }}return false;
241 }, $fz.isPrivate = true, $fz), "jalview.datamodel.SequenceGroup,jalview.datamodel.SequenceGroup");
242 Clazz.defineMethod (c$, "writeSequence_Ref", 
243 ($fz = function (refSeq, next_refSeq) {
244 if (next_refSeq == null) {
245 if (refSeq != null) {
246 this.text.append (this.newline);
247 this.text.append ("SEQUENCE_REF\t");
248 this.text.append ("ALIGNMENT");
249 this.text.append (this.newline);
250 return true;
251 }} else {
252 if (refSeq == null || refSeq !== next_refSeq) {
253 this.text.append (this.newline);
254 this.text.append ("SEQUENCE_REF\t");
255 this.text.append (next_refSeq.getName ());
256 this.text.append (this.newline);
257 return true;
258 }}return false;
259 }, $fz.isPrivate = true, $fz), "jalview.datamodel.SequenceI,jalview.datamodel.SequenceI");
260 Clazz.defineMethod (c$, "printGroups", 
261 function (list) {
262 var seqrep = null;
263 for (var sg, $sg = list.iterator (); $sg.hasNext () && ((sg = $sg.next ()) || true);) {
264 if (!sg.hasSeqrep ()) {
265 this.text.append ("SEQUENCE_GROUP\t" + sg.getName () + "\t" + (sg.getStartRes () + 1) + "\t" + (sg.getEndRes () + 1) + "\t" + "-1\t");
266 seqrep = null;
267 } else {
268 seqrep = sg.getSeqrep ();
269 this.text.append ("SEQUENCE_REF\t");
270 this.text.append (seqrep.getName ());
271 this.text.append (this.newline);
272 this.text.append ("SEQUENCE_GROUP\t");
273 this.text.append (sg.getName ());
274 this.text.append ("\t");
275 this.text.append ("" + (seqrep.findPosition (sg.getStartRes ())));
276 this.text.append ("\t");
277 this.text.append ((seqrep.findPosition (sg.getEndRes ())));
278 this.text.append ("\t");
279 this.text.append ("-1\t");
280 }for (var s = 0; s < sg.getSize (); s++) {
281 this.text.append (sg.getSequenceAt (s).getName ());
282 this.text.append ("\t");
283 }
284 this.text.append (this.newline);
285 this.text.append ("PROPERTIES\t");
286 this.text.append (sg.getName ());
287 this.text.append ("\t");
288 if (sg.getDescription () != null) {
289 this.text.append ("description=");
290 this.text.append (sg.getDescription ());
291 this.text.append ("\t");
292 }if (sg.cs != null) {
293 this.text.append ("colour=");
294 this.text.append (jalview.schemes.ColourSchemeProperty.getColourName (sg.cs));
295 this.text.append ("\t");
296 if (sg.cs.getThreshold () != 0) {
297 this.text.append ("pidThreshold=");
298 this.text.append (sg.cs.getThreshold ());
299 }if (sg.cs.conservationApplied ()) {
300 this.text.append ("consThreshold=");
301 this.text.append (sg.cs.getConservationInc ());
302 this.text.append ("\t");
303 }}this.text.append ("outlineColour=");
304 this.text.append (jalview.util.Format.getHexString (sg.getOutlineColour ()));
305 this.text.append ("\t");
306 this.text.append ("displayBoxes=");
307 this.text.append (sg.getDisplayBoxes ());
308 this.text.append ("\t");
309 this.text.append ("displayText=");
310 this.text.append (sg.getDisplayText ());
311 this.text.append ("\t");
312 this.text.append ("colourText=");
313 this.text.append (sg.getColourText ());
314 this.text.append ("\t");
315 this.text.append ("showUnconserved=");
316 this.text.append (sg.getShowNonconserved ());
317 this.text.append ("\t");
318 if (sg.textColour !== java.awt.Color.black) {
319 this.text.append ("textCol1=");
320 this.text.append (jalview.util.Format.getHexString (sg.textColour));
321 this.text.append ("\t");
322 }if (sg.textColour2 !== java.awt.Color.white) {
323 this.text.append ("textCol2=");
324 this.text.append (jalview.util.Format.getHexString (sg.textColour2));
325 this.text.append ("\t");
326 }if (sg.thresholdTextColour != 0) {
327 this.text.append ("textColThreshold=");
328 this.text.append (sg.thresholdTextColour);
329 this.text.append ("\t");
330 }if (sg.idColour != null) {
331 this.text.append ("idColour=");
332 this.text.append (jalview.util.Format.getHexString (sg.idColour));
333 this.text.append ("\t");
334 }if (sg.isHidereps ()) {
335 this.text.append ("hide=true\t");
336 }if (sg.isHideCols ()) {
337 this.text.append ("hidecols=true\t");
338 }if (seqrep != null) {
339 this.text.append (this.newline);
340 this.text.append ("SEQUENCE_REF");
341 }this.text.append (this.newline);
342 this.text.append (this.newline);
343 }
344 }, "java.util.List");
345 Clazz.defineMethod (c$, "annotateAlignmentView", 
346 function (viewport, file, protocol) {
347 var colSel = viewport.getColumnSelection ();
348 if (colSel == null) {
349 colSel =  new jalview.datamodel.ColumnSelection ();
350 }var rslt = this.readAnnotationFile (viewport.getAlignment (), colSel, file, protocol);
351 if (rslt && (colSel.hasSelectedColumns () || colSel.hasHiddenColumns ())) {
352 viewport.setColumnSelection (colSel);
353 }return rslt;
354 }, "jalview.api.AlignViewportI,~S,~S");
355 Clazz.defineMethod (c$, "readAnnotationFile", 
356 function (al, file, protocol) {
357 return this.readAnnotationFile (al, null, file, protocol);
358 }, "jalview.datamodel.AlignmentI,~S,~S");
359 Clazz.defineMethod (c$, "readAnnotationFile", 
360 function (al, colSel, file, protocol) {
361 var $in = null;
362 try {
363 if (protocol.equals (jalview.io.AppletFormatAdapter.FILE)) {
364 $in = jalview.jsdev.GenericFileAdapter.getReader (file, false);
365 } else if (protocol.equals (jalview.io.AppletFormatAdapter.URL)) {
366 $in = jalview.jsdev.GenericFileAdapter.getReader (file, true);
367 } else if (protocol.equals (jalview.io.AppletFormatAdapter.PASTE)) {
368 $in =  new java.io.BufferedReader ( new java.io.StringReader (file));
369 } else if (protocol.equals (jalview.io.AppletFormatAdapter.CLASSLOADER)) {
370 var is = this.getClass ().getResourceAsStream ("/" + file);
371 if (is != null) {
372 $in =  new java.io.BufferedReader ( new java.io.InputStreamReader (is));
373 }}if ($in != null) {
374 return this.parseAnnotationFrom (al, colSel, $in);
375 }} catch (ex) {
376 if (Clazz.exceptionOf (ex, Exception)) {
377 ex.printStackTrace ();
378 System.out.println ("Problem reading annotation file: " + ex);
379 if (this.nlinesread > 0) {
380 System.out.println ("Last read line " + this.nlinesread + ": '" + this.lastread + "' (first 80 chars) ...");
381 }return false;
382 } else {
383 throw ex;
384 }
385 }
386 return false;
387 }, "jalview.datamodel.AlignmentI,jalview.datamodel.ColumnSelection,~S,~S");
388 Clazz.defineMethod (c$, "parseAnnotationFrom", 
389 function (al, colSel, $in) {
390 this.nlinesread = 0;
391 var combineAnnotation_calls =  new java.util.ArrayList ();
392 var deferredAnnotation_calls =  new java.util.ArrayList ();
393 var modified = false;
394 var groupRef = null;
395 var groupRefRows =  new java.util.Hashtable ();
396 var autoAnnots =  new java.util.Hashtable ();
397 {
398 var line;
399 var label;
400 var description;
401 var token;
402 var graphStyle;
403 var index;
404 var refSeqIndex = 1;
405 var existingAnnotations = 0;
406 var overrideAutoAnnot = false;
407 if (al.getAlignmentAnnotation () != null) {
408 existingAnnotations = al.getAlignmentAnnotation ().length;
409 if (existingAnnotations > 0) {
410 var aa = al.getAlignmentAnnotation ();
411 for (var aai = 0; aai < aa.length; aai++) {
412 if (aa[aai].autoCalculated) {
413 autoAnnots.put (this.autoAnnotsKey (aa[aai], aa[aai].sequenceRef, (aa[aai].groupRef == null ? null : aa[aai].groupRef.getName ())),  new Integer (1));
414 }}
415 }}var alWidth = al.getWidth ();
416 var st;
417 var annotations;
418 var annotation = null;
419 var jvAnnotationFile = false;
420 while ((line = $in.readLine ()) != null) {
421 this.nlinesread++;
422 this.lastread =  String.instantialize (line);
423 if (line.indexOf ("#") == 0) {
424 continue;
425 }if (line.indexOf ("JALVIEW_ANNOTATION") > -1) {
426 jvAnnotationFile = true;
427 break;
428 }}
429 if (!jvAnnotationFile) {
430 $in.close ();
431 return false;
432 }while ((line = $in.readLine ()) != null) {
433 this.nlinesread++;
434 this.lastread =  String.instantialize (line);
435 if (line.indexOf ("#") == 0 || line.indexOf ("JALVIEW_ANNOTATION") > -1 || line.length == 0) {
436 continue;
437 }st =  new java.util.StringTokenizer (line, "\t");
438 token = st.nextToken ();
439 if (token.equalsIgnoreCase ("COLOUR")) {
440 this.colourAnnotations (al, st.nextToken (), st.nextToken ());
441 modified = true;
442 continue;
443 } else if (token.equalsIgnoreCase (jalview.io.AnnotationFile.COMBINE)) {
444 combineAnnotation_calls.add ( Clazz.newArray (-1, [st, this.refSeq, groupRef]));
445 modified = true;
446 continue;
447 } else if (token.equalsIgnoreCase ("ROWPROPERTIES")) {
448 this.addRowProperties (al, st);
449 modified = true;
450 continue;
451 } else if (token.equalsIgnoreCase (jalview.io.AnnotationFile.GRAPHLINE)) {
452 deferredAnnotation_calls.add ( Clazz.newArray (-1, [jalview.io.AnnotationFile.GRAPHLINE, st, this.refSeq, groupRef]));
453 modified = true;
454 continue;
455 } else if (token.equalsIgnoreCase ("SEQUENCE_REF")) {
456 if (st.hasMoreTokens ()) {
457 this.refSeq = al.findName (this.refSeqId = st.nextToken ());
458 if (this.refSeq == null) {
459 this.refSeqId = null;
460 }try {
461 refSeqIndex = Integer.parseInt (st.nextToken ());
462 if (refSeqIndex < 1) {
463 refSeqIndex = 1;
464 System.out.println ("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile");
465 }} catch (ex) {
466 if (Clazz.exceptionOf (ex, Exception)) {
467 refSeqIndex = 1;
468 } else {
469 throw ex;
470 }
471 }
472 } else {
473 this.refSeq = null;
474 this.refSeqId = null;
475 }continue;
476 } else if (token.equalsIgnoreCase ("GROUP_REF")) {
477 groupRef = null;
478 if (st.hasMoreTokens ()) {
479 groupRef = st.nextToken ();
480 if (groupRef.length < 1) {
481 groupRef = null;
482 } else {
483 if (groupRefRows.get (groupRef) == null) {
484 groupRefRows.put (groupRef,  new java.util.Vector ());
485 }}}continue;
486 } else if (token.equalsIgnoreCase ("SEQUENCE_GROUP")) {
487 this.addGroup (al, st);
488 modified = true;
489 continue;
490 } else if (token.equalsIgnoreCase ("PROPERTIES")) {
491 this.addProperties (al, st);
492 modified = true;
493 continue;
494 } else if (token.equalsIgnoreCase ("BELOW_ALIGNMENT")) {
495 this.setBelowAlignment (al, st);
496 modified = true;
497 continue;
498 } else if (token.equalsIgnoreCase ("ALIGNMENT")) {
499 this.addAlignmentDetails (al, st);
500 modified = true;
501 continue;
502 } else if (token.equalsIgnoreCase ("VIEW_SETREF")) {
503 if (this.refSeq != null) {
504 al.setSeqrep (this.refSeq);
505 }modified = true;
506 continue;
507 } else if (token.equalsIgnoreCase ("VIEW_HIDECOLS")) {
508 if (st.hasMoreTokens ()) {
509 if (colSel == null) {
510 colSel =  new jalview.datamodel.ColumnSelection ();
511 }this.parseHideCols (colSel, st.nextToken ());
512 }modified = true;
513 continue;
514 } else if (token.equalsIgnoreCase ("HIDE_INSERTIONS")) {
515 var sr = this.refSeq == null ? al.getSeqrep () : this.refSeq;
516 if (sr == null) {
517 sr = al.getSequenceAt (0);
518 }if (sr != null) {
519 if (colSel == null) {
520 System.err.println ("Cannot process HIDE_INSERTIONS without an alignment view: Ignoring line: " + line);
521 } else {
522 colSel.hideInsertionsFor (sr);
523 }}modified = true;
524 continue;
525 }graphStyle = jalview.datamodel.AlignmentAnnotation.getGraphValueFromString (token);
526 label = st.nextToken ();
527 index = 0;
528 annotations =  new Array (alWidth);
529 description = null;
530 var score = NaN;
531 if (st.hasMoreTokens ()) {
532 line = st.nextToken ();
533 if (line.indexOf ("|") == -1) {
534 description = line;
535 if (st.hasMoreTokens ()) {
536 line = st.nextToken ();
537 }}if (st.hasMoreTokens ()) {
538 score = Float.$valueOf (st.nextToken ()).floatValue ();
539 }st =  new java.util.StringTokenizer (line, "|", true);
540 var emptyColumn = true;
541 var onlyOneElement = (st.countTokens () == 1);
542 while (st.hasMoreElements () && index < alWidth) {
543 token = st.nextToken ().trim ();
544 if (onlyOneElement) {
545 try {
546 score = Float.$valueOf (token).floatValue ();
547 break;
548 } catch (ex) {
549 if (Clazz.exceptionOf (ex, NumberFormatException)) {
550 } else {
551 throw ex;
552 }
553 }
554 }if (token.equals ("|")) {
555 if (emptyColumn) {
556 index++;
557 }emptyColumn = true;
558 } else {
559 annotations[index++] = this.parseAnnotation (token, graphStyle);
560 emptyColumn = false;
561 }}
562 }annotation =  new jalview.datamodel.AlignmentAnnotation (label, description, (index == 0) ? null : annotations, 0, 0, graphStyle);
563 annotation.score = score;
564 if (!overrideAutoAnnot && autoAnnots.containsKey (this.autoAnnotsKey (annotation, this.refSeq, groupRef))) {
565 continue;
566 }if (this.refSeq != null) {
567 annotation.belowAlignment = false;
568 var referedSeq = this.refSeq;
569 do {
570 var ann =  new jalview.datamodel.AlignmentAnnotation (annotation);
571 annotation.createSequenceMapping (referedSeq, refSeqIndex, false);
572 annotation.adjustForAlignment ();
573 referedSeq.addAlignmentAnnotation (annotation);
574 al.addAnnotation (annotation);
575 al.setAnnotationIndex (annotation, al.getAlignmentAnnotation ().length - existingAnnotations - 1);
576 if (groupRef != null) {
577 (groupRefRows.get (groupRef)).addElement (annotation);
578 }annotation = ann;
579 } while (this.refSeqId != null && (referedSeq = al.findName (referedSeq, this.refSeqId, true)) != null);
580 } else {
581 al.addAnnotation (annotation);
582 al.setAnnotationIndex (annotation, al.getAlignmentAnnotation ().length - existingAnnotations - 1);
583 if (groupRef != null) {
584 (groupRefRows.get (groupRef)).addElement (annotation);
585 }}modified = true;
586 }
587 var groupRefLookup =  new java.util.Hashtable ();
588 var en = groupRefRows.keys ();
589 while (en.hasMoreElements ()) {
590 groupRef = en.nextElement ();
591 var matched = false;
592 for (var theGroup, $theGroup = al.getGroups ().iterator (); $theGroup.hasNext () && ((theGroup = $theGroup.next ()) || true);) {
593 if (theGroup.getName ().equals (groupRef)) {
594 if (matched) {
595 System.err.println ("Ignoring 1:many group reference mappings for group name '" + groupRef + "'");
596 } else {
597 matched = true;
598 var rowset = groupRefRows.get (groupRef);
599 groupRefLookup.put (groupRef, theGroup);
600 if (rowset != null && rowset.size () > 0) {
601 var alan = null;
602 for (var elm = 0, elmSize = rowset.size (); elm < elmSize; elm++) {
603 alan = rowset.elementAt (elm);
604 alan.groupRef = theGroup;
605 }
606 }}}}
607 (groupRefRows.get (groupRef)).removeAllElements ();
608 }
609 for (var _deferred_args, $_deferred_args = deferredAnnotation_calls.iterator (); $_deferred_args.hasNext () && ((_deferred_args = $_deferred_args.next ()) || true);) {
610 if (_deferred_args[0] === jalview.io.AnnotationFile.GRAPHLINE) {
611 this.addLine (al, _deferred_args[1], _deferred_args[2], (_deferred_args[3] == null) ? null : groupRefLookup.get (_deferred_args[3]));
612 }}
613 var combinecount = 0;
614 for (var _combine_args, $_combine_args = combineAnnotation_calls.iterator (); $_combine_args.hasNext () && ((_combine_args = $_combine_args.next ()) || true);) {
615 this.combineAnnotations (al, ++combinecount, _combine_args[0], _combine_args[1], (_combine_args[2] == null) ? null : groupRefLookup.get (_combine_args[2]));
616 }
617 }return modified;
618 }, "jalview.datamodel.AlignmentI,jalview.datamodel.ColumnSelection,java.io.BufferedReader");
619 Clazz.defineMethod (c$, "parseHideCols", 
620 ($fz = function (colSel, nextToken) {
621 var inval =  new java.util.StringTokenizer (nextToken, ",");
622 while (inval.hasMoreTokens ()) {
623 var range = inval.nextToken ().trim ();
624 var from;
625 var to = range.indexOf ("-");
626 if (to == -1) {
627 from = to = Integer.parseInt (range);
628 if (from >= 0) {
629 colSel.hideColumns (from, to);
630 }} else {
631 from = Integer.parseInt (range.substring (0, to));
632 if (to < range.length - 1) {
633 to = Integer.parseInt (range.substring (to + 1));
634 } else {
635 to = from;
636 }if (from > 0 && to >= from) {
637 colSel.hideColumns (from, to);
638 }}}
639 }, $fz.isPrivate = true, $fz), "jalview.datamodel.ColumnSelection,~S");
640 Clazz.defineMethod (c$, "autoAnnotsKey", 
641 ($fz = function (annotation, refSeq, groupRef) {
642 return annotation.graph + "\t" + annotation.label + "\t" + annotation.description + "\t" + (refSeq != null ? refSeq.getDisplayId (true) : "");
643 }, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.SequenceI,~S");
644 Clazz.defineMethod (c$, "parseAnnotation", 
645 function (string, graphStyle) {
646 var hasSymbols = (graphStyle == 0);
647 var desc = null;
648 var displayChar = null;
649 var ss = ' ';
650 var value = 0;
651 var parsedValue = false;
652 var dcset = false;
653 var colour = null;
654 var i = string.indexOf ("[");
655 var j = string.indexOf ("]");
656 if (i > -1 && j > -1) {
657 var ucs =  new jalview.schemes.UserColourScheme ();
658 colour = ucs.getColourFromString (string.substring (i + 1, j));
659 if (i > 0 && string.charAt (i - 1) == ',') {
660 i--;
661 }string = string.substring (0, i) + string.substring (j + 1);
662 }var st =  new java.util.StringTokenizer (string, ",", true);
663 var token;
664 var seenContent = false;
665 var pass = 0;
666 while (st.hasMoreTokens ()) {
667 pass++;
668 token = st.nextToken ().trim ();
669 if (token.equals (",")) {
670 if (!seenContent && parsedValue && !dcset) {
671 dcset = true;
672 displayChar = " ";
673 }seenContent = false;
674 continue;
675 } else {
676 seenContent = true;
677 }if (!parsedValue) {
678 try {
679 displayChar = token;
680 value =  new Float (token).floatValue ();
681 parsedValue = true;
682 continue;
683 } catch (ex) {
684 if (Clazz.exceptionOf (ex, NumberFormatException)) {
685 } else {
686 throw ex;
687 }
688 }
689 } else {
690 if (token.length == 1) {
691 displayChar = token;
692 }}if (hasSymbols && (token.equals ("H") || token.equals ("E") || token.equals ("S") || token.equals (" "))) {
693 ss = token.charAt (0);
694 if (displayChar.equals (token.substring (0, 1))) {
695 displayChar = "";
696 }} else if (desc == null || (parsedValue && pass > 2)) {
697 desc = token;
698 }}
699 if (displayChar != null && desc != null && desc.length == 1) {
700 if (displayChar.length > 1) {
701 var tmp = displayChar;
702 displayChar = desc;
703 desc = tmp;
704 } else {
705 if (displayChar.equals (desc)) {
706 desc = null;
707 }}}var anot =  new jalview.datamodel.Annotation (displayChar, desc, ss, value);
708 anot.colour = colour;
709 return anot;
710 }, "~S,~N");
711 Clazz.defineMethod (c$, "colourAnnotations", 
712 function (al, label, colour) {
713 var ucs =  new jalview.schemes.UserColourScheme (colour);
714 var annotations;
715 for (var i = 0; i < al.getAlignmentAnnotation ().length; i++) {
716 if (al.getAlignmentAnnotation ()[i].label.equalsIgnoreCase (label)) {
717 annotations = al.getAlignmentAnnotation ()[i].annotations;
718 for (var j = 0; j < annotations.length; j++) {
719 if (annotations[j] != null) {
720 annotations[j].colour = ucs.findColour ('A');
721 }}
722 }}
723 }, "jalview.datamodel.AlignmentI,~S,~S");
724 Clazz.defineMethod (c$, "combineAnnotations", 
725 function (al, combineCount, st, seqRef, groupRef) {
726 var group = st.nextToken ();
727 var graphGroup = 0;
728 if (al.getAlignmentAnnotation () != null) {
729 for (var i = 0; i < al.getAlignmentAnnotation ().length; i++) {
730 var aa = al.getAlignmentAnnotation ()[i];
731 if (aa.graphGroup > graphGroup) {
732 graphGroup = aa.graphGroup + 1;
733 }if (aa.sequenceRef === seqRef && aa.groupRef === groupRef && aa.label.equalsIgnoreCase (group)) {
734 if (aa.graphGroup > -1) {
735 graphGroup = aa.graphGroup;
736 } else {
737 if (graphGroup <= combineCount) {
738 graphGroup = combineCount + 1;
739 }aa.graphGroup = graphGroup;
740 }break;
741 }}
742 while (st.hasMoreTokens ()) {
743 group = st.nextToken ();
744 for (var i = 0; i < al.getAlignmentAnnotation ().length; i++) {
745 var aa = al.getAlignmentAnnotation ()[i];
746 if (aa.sequenceRef === seqRef && aa.groupRef === groupRef && aa.label.equalsIgnoreCase (group)) {
747 aa.graphGroup = graphGroup;
748 break;
749 }}
750 }
751 } else {
752 System.err.println ("Couldn't combine annotations. None are added to alignment yet!");
753 }}, "jalview.datamodel.AlignmentI,~N,java.util.StringTokenizer,jalview.datamodel.SequenceI,jalview.datamodel.SequenceGroup");
754 Clazz.defineMethod (c$, "addLine", 
755 function (al, st, seqRef, groupRef) {
756 var group = st.nextToken ();
757 var annotation = null;
758 var alannot = al.getAlignmentAnnotation ();
759 var value =  new Float (st.nextToken ()).floatValue ();
760 var label = st.hasMoreTokens () ? st.nextToken () : null;
761 var colour = null;
762 if (st.hasMoreTokens ()) {
763 var ucs =  new jalview.schemes.UserColourScheme (st.nextToken ());
764 colour = ucs.findColour ('A');
765 }if (alannot != null) {
766 for (var i = 0; i < alannot.length; i++) {
767 if (alannot[i].label.equalsIgnoreCase (group) && (seqRef == null || alannot[i].sequenceRef === seqRef) && (groupRef == null || alannot[i].groupRef === groupRef)) {
768 alannot[i].setThreshold ( new jalview.datamodel.GraphLine (value, label, colour));
769 }}
770 }if (annotation == null) {
771 return;
772 }}, "jalview.datamodel.AlignmentI,java.util.StringTokenizer,jalview.datamodel.SequenceI,jalview.datamodel.SequenceGroup");
773 Clazz.defineMethod (c$, "addGroup", 
774 function (al, st) {
775 var sg =  new jalview.datamodel.SequenceGroup ();
776 sg.setName (st.nextToken ());
777 var rng = "";
778 try {
779 rng = st.nextToken ();
780 if (rng.length > 0 && !rng.startsWith ("*")) {
781 sg.setStartRes (Integer.parseInt (rng) - 1);
782 } else {
783 sg.setStartRes (0);
784 }rng = st.nextToken ();
785 if (rng.length > 0 && !rng.startsWith ("*")) {
786 sg.setEndRes (Integer.parseInt (rng) - 1);
787 } else {
788 sg.setEndRes (al.getWidth () - 1);
789 }} catch (e) {
790 if (Clazz.exceptionOf (e, Exception)) {
791 System.err.println ("Couldn't parse Group Start or End Field as '*' or a valid column or sequence index: '" + rng + "' - assuming alignment width for group.");
792 sg.setStartRes (0);
793 sg.setEndRes (al.getWidth () - 1);
794 } else {
795 throw e;
796 }
797 }
798 var index = st.nextToken ();
799 if (index.equals ("-1")) {
800 while (st.hasMoreElements ()) {
801 sg.addSequence (al.findName (st.nextToken ()), false);
802 }
803 } else {
804 var st2 =  new java.util.StringTokenizer (index, ",");
805 while (st2.hasMoreTokens ()) {
806 var tmp = st2.nextToken ();
807 if (tmp.equals ("*")) {
808 for (var i = 0; i < al.getHeight (); i++) {
809 sg.addSequence (al.getSequenceAt (i), false);
810 }
811 } else if (tmp.indexOf ("-") >= 0) {
812 var st3 =  new java.util.StringTokenizer (tmp, "-");
813 var start = (Integer.parseInt (st3.nextToken ()));
814 var end = (Integer.parseInt (st3.nextToken ()));
815 if (end > start) {
816 for (var i = start; i <= end; i++) {
817 sg.addSequence (al.getSequenceAt (i - 1), false);
818 }
819 }} else {
820 sg.addSequence (al.getSequenceAt (Integer.parseInt (tmp) - 1), false);
821 }}
822 }if (this.refSeq != null) {
823 sg.setStartRes (this.refSeq.findIndex (sg.getStartRes () + 1) - 1);
824 sg.setEndRes (this.refSeq.findIndex (sg.getEndRes () + 1) - 1);
825 sg.setSeqrep (this.refSeq);
826 }if (sg.getSize () > 0) {
827 al.addGroup (sg);
828 }}, "jalview.datamodel.AlignmentI,java.util.StringTokenizer");
829 Clazz.defineMethod (c$, "addRowProperties", 
830 function (al, st) {
831 var label = st.nextToken ();
832 var keyValue;
833 var key;
834 var value;
835 var scaletofit = false;
836 var centerlab = false;
837 var showalllabs = false;
838 while (st.hasMoreTokens ()) {
839 keyValue = st.nextToken ();
840 key = keyValue.substring (0, keyValue.indexOf ("="));
841 value = keyValue.substring (keyValue.indexOf ("=") + 1);
842 if (key.equalsIgnoreCase ("scaletofit")) {
843 scaletofit = Boolean.$valueOf (value).booleanValue ();
844 }if (key.equalsIgnoreCase ("showalllabs")) {
845 showalllabs = Boolean.$valueOf (value).booleanValue ();
846 }if (key.equalsIgnoreCase ("centrelabs")) {
847 centerlab = Boolean.$valueOf (value).booleanValue ();
848 }var alr = al.getAlignmentAnnotation ();
849 if (alr != null) {
850 for (var i = 0; i < alr.length; i++) {
851 if (alr[i].label.equalsIgnoreCase (label)) {
852 alr[i].centreColLabels = centerlab;
853 alr[i].scaleColLabel = scaletofit;
854 alr[i].showAllColLabels = showalllabs;
855 }}
856 }}
857 }, "jalview.datamodel.AlignmentI,java.util.StringTokenizer");
858 Clazz.defineMethod (c$, "addProperties", 
859 function (al, st) {
860 if (al.getGroups () == null) {
861 return;
862 }var name = st.nextToken ();
863 var sg = null;
864 for (var _sg, $_sg = al.getGroups ().iterator (); $_sg.hasNext () && ((_sg = $_sg.next ()) || true);) {
865 if ((sg = _sg).getName ().equals (name)) {
866 break;
867 } else {
868 sg = null;
869 }}
870 if (sg != null) {
871 var keyValue;
872 var key;
873 var value;
874 var def = sg.cs;
875 sg.cs = null;
876 while (st.hasMoreTokens ()) {
877 keyValue = st.nextToken ();
878 key = keyValue.substring (0, keyValue.indexOf ("="));
879 value = keyValue.substring (keyValue.indexOf ("=") + 1);
880 if (key.equalsIgnoreCase ("description")) {
881 sg.setDescription (value);
882 } else if (key.equalsIgnoreCase ("colour")) {
883 sg.cs = jalview.schemes.ColourSchemeProperty.getColour (al, value);
884 } else if (key.equalsIgnoreCase ("pidThreshold")) {
885 sg.cs.setThreshold (Integer.parseInt (value), true);
886 } else if (key.equalsIgnoreCase ("consThreshold")) {
887 sg.cs.setConservationInc (Integer.parseInt (value));
888 var c =  new jalview.analysis.Conservation ("Group", jalview.schemes.ResidueProperties.propHash, 3, sg.getSequences (null), sg.getStartRes (), sg.getEndRes () + 1);
889 c.calculate ();
890 c.verdict (false, 25);
891 sg.cs.setConservation (c);
892 } else if (key.equalsIgnoreCase ("outlineColour")) {
893 sg.setOutlineColour ( new jalview.schemes.UserColourScheme (value).findColour ('A'));
894 } else if (key.equalsIgnoreCase ("displayBoxes")) {
895 sg.setDisplayBoxes (Boolean.$valueOf (value).booleanValue ());
896 } else if (key.equalsIgnoreCase ("showUnconserved")) {
897 sg.setShowNonconserved (Boolean.$valueOf (value).booleanValue ());
898 } else if (key.equalsIgnoreCase ("displayText")) {
899 sg.setDisplayText (Boolean.$valueOf (value).booleanValue ());
900 } else if (key.equalsIgnoreCase ("colourText")) {
901 sg.setColourText (Boolean.$valueOf (value).booleanValue ());
902 } else if (key.equalsIgnoreCase ("textCol1")) {
903 sg.textColour =  new jalview.schemes.UserColourScheme (value).findColour ('A');
904 } else if (key.equalsIgnoreCase ("textCol2")) {
905 sg.textColour2 =  new jalview.schemes.UserColourScheme (value).findColour ('A');
906 } else if (key.equalsIgnoreCase ("textColThreshold")) {
907 sg.thresholdTextColour = Integer.parseInt (value);
908 } else if (key.equalsIgnoreCase ("idColour")) {
909 sg.setIdColour ((def =  new jalview.schemes.UserColourScheme (value)).findColour ('A'));
910 } else if (key.equalsIgnoreCase ("hide")) {
911 sg.setHidereps (true);
912 } else if (key.equalsIgnoreCase ("hidecols")) {
913 sg.setHideCols (true);
914 }sg.recalcConservation ();
915 }
916 if (sg.cs == null) {
917 sg.cs = def;
918 }}}, "jalview.datamodel.AlignmentI,java.util.StringTokenizer");
919 Clazz.defineMethod (c$, "setBelowAlignment", 
920 function (al, st) {
921 var token;
922 var aa;
923 var ala = al.getAlignmentAnnotation ();
924 if (ala == null) {
925 System.err.print ("Warning - no annotation to set below for sequence associated annotation:");
926 }while (st.hasMoreTokens ()) {
927 token = st.nextToken ();
928 if (ala == null) {
929 System.err.print (" " + token);
930 } else {
931 for (var i = 0; i < al.getAlignmentAnnotation ().length; i++) {
932 aa = al.getAlignmentAnnotation ()[i];
933 if (aa.sequenceRef === this.refSeq && aa.label.equals (token)) {
934 aa.belowAlignment = true;
935 }}
936 }}
937 if (ala == null) {
938 System.err.print ("\n");
939 }}, "jalview.datamodel.AlignmentI,java.util.StringTokenizer");
940 Clazz.defineMethod (c$, "addAlignmentDetails", 
941 function (al, st) {
942 var keyValue;
943 var key;
944 var value;
945 while (st.hasMoreTokens ()) {
946 keyValue = st.nextToken ();
947 key = keyValue.substring (0, keyValue.indexOf ("="));
948 value = keyValue.substring (keyValue.indexOf ("=") + 1);
949 al.setProperty (key, value);
950 }
951 }, "jalview.datamodel.AlignmentI,java.util.StringTokenizer");
952 Clazz.defineMethod (c$, "printCSVAnnotations", 
953 function (annotations) {
954 var sp =  new StringBuffer ();
955 for (var i = 0; i < annotations.length; i++) {
956 var atos = annotations[i].toString ();
957 var p = 0;
958 do {
959 var cp = atos.indexOf ("\n", p);
960 sp.append (annotations[i].label);
961 sp.append (",");
962 if (cp > p) {
963 sp.append (atos.substring (p, cp + 1));
964 } else {
965 sp.append (atos.substring (p));
966 sp.append (this.newline);
967 }p = cp + 1;
968 } while (p > 0);
969 }
970 return sp.toString ();
971 }, "~A");
972 Clazz.defineMethod (c$, "printAnnotationsForView", 
973 function (viewport) {
974 return this.printAnnotations (viewport.isShowAnnotation () ? viewport.getAlignment ().getAlignmentAnnotation () : null, viewport.getAlignment ().getGroups (), viewport.getAlignment ().getProperties (), viewport.getColumnSelection (), viewport.getAlignment (), null);
975 }, "jalview.api.AlignViewportI");
976 Clazz.defineMethod (c$, "printAnnotationsForAlignment", 
977 function (al) {
978 return this.printAnnotations (al.getAlignmentAnnotation (), al.getGroups (), al.getProperties (), null, al, null);
979 }, "jalview.datamodel.AlignmentI");
980 c$.$AnnotationFile$ViewDef$ = function () {
981 Clazz.pu$h ();
982 c$ = Clazz.decorateAsClass (function () {
983 Clazz.prepareCallback (this, arguments);
984 this.viewname = null;
985 this.hidseqs = null;
986 this.hiddencols = null;
987 this.visibleGroups = null;
988 this.hiddenRepSeqs = null;
989 Clazz.instantialize (this, arguments);
990 }, jalview.io.AnnotationFile, "ViewDef");
991 Clazz.makeConstructor (c$, 
992 function (a, b, c, d) {
993 this.viewname = a;
994 this.hidseqs = b;
995 this.hiddencols = c;
996 this.hiddenRepSeqs = d;
997 }, "~S,jalview.datamodel.HiddenSequences,jalview.datamodel.ColumnSelection,java.util.Hashtable");
998 c$ = Clazz.p0p ();
999 };
1000 Clazz.defineStatics (c$,
1001 "GRAPHLINE", "GRAPHLINE",
1002 "COMBINE", "COMBINE");
1003 });