JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / io / AlignmentProperties.js
1 Clazz.declarePackage ("jalview.io");
2 Clazz.load (null, "jalview.io.AlignmentProperties", ["java.lang.StringBuffer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.alignment = null;
5 Clazz.instantialize (this, arguments);
6 }, jalview.io, "AlignmentProperties");
7 Clazz.makeConstructor (c$, 
8 function (alignment) {
9 this.alignment = alignment;
10 }, "jalview.datamodel.AlignmentI");
11 Clazz.defineMethod (c$, "writeProperties", 
12 function (sb, html) {
13 var nl = html ? "<br>" : System.getProperty ("line.separator");
14 var avg = 0;
15 var min = 2147483647;
16 var max = 0;
17 for (var i = 0; i < this.alignment.getHeight (); i++) {
18 var size = 1 + this.alignment.getSequenceAt (i).getEnd () - this.alignment.getSequenceAt (i).getStart ();
19 avg += size;
20 if (size > max) {
21 max = size;
22 }if (size < min) {
23 min = size;
24 }}
25 avg = avg / this.alignment.getHeight ();
26 sb.append (nl);
27 sb.append ("Sequences: " + this.alignment.getHeight ());
28 sb.append (nl);
29 sb.append ("Minimum Sequence Length: " + min);
30 sb.append (nl);
31 sb.append ("Maximum Sequence Length: " + max);
32 sb.append (nl);
33 sb.append ("Average Length: " + Clazz.floatToInt (avg));
34 if ((this.alignment).alignmentProperties != null) {
35 sb.append (nl);
36 sb.append (nl);
37 if (html) {
38 sb.append ("<table border=\"1\">");
39 }var props = (this.alignment).alignmentProperties;
40 var en = props.keys ();
41 while (en.hasMoreElements ()) {
42 var key = en.nextElement ().toString ();
43 var vals = props.get (key).toString ();
44 if (html) {
45 var val =  new StringBuffer ();
46 var pos = 0;
47 var npos;
48 do {
49 npos = vals.indexOf ("\n", pos);
50 if (npos == -1) {
51 val.append (vals.substring (pos));
52 } else {
53 val.append (vals.substring (pos, npos));
54 val.append ("<br>");
55 }pos = npos + 1;
56 } while (npos != -1);
57 sb.append ("<tr><td>" + key + "</td><td>" + val + "</td></tr>");
58 } else {
59 sb.append (nl + key + "\t" + vals);
60 }}
61 if (html) {
62 sb.append ("</table>");
63 }}}, "StringBuffer,~B");
64 Clazz.defineMethod (c$, "formatAsString", 
65 function () {
66 return this.formatReport (false);
67 });
68 Clazz.defineMethod (c$, "formatReport", 
69 function (html) {
70 var sb =  new StringBuffer ();
71 this.writeProperties (sb, html);
72 return sb;
73 }, "~B");
74 Clazz.defineMethod (c$, "formatAsHtml", 
75 function () {
76 return this.formatReport (true);
77 });
78 });