JAL-1807 test
[jalviewjs.git] / bin / jalview / io / AlignFile.js
1 Clazz.declarePackage ("jalview.io");
2 Clazz.load (["jalview.io.FileParse"], "jalview.io.AlignFile", ["jalview.datamodel.Sequence", "jalview.util.MessageManager", "java.io.IOException", "java.lang.Error", "java.util.ArrayList", "$.Hashtable", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.noSeqs = 0;
5 this.maxLength = 0;
6 this.seqs = null;
7 this.annotations = null;
8 this.seqGroups = null;
9 this.properties = null;
10 this.start = 0;
11 this.end = 0;
12 this.jvSuffix = true;
13 this.parseCalled = false;
14 this.newickStrings = null;
15 Clazz.instantialize (this, arguments);
16 }, jalview.io, "AlignFile", jalview.io.FileParse);
17 Clazz.makeConstructor (c$, 
18 function () {
19 Clazz.superConstructor (this, jalview.io.AlignFile, []);
20 this.initData ();
21 });
22 Clazz.makeConstructor (c$, 
23 function (inFile, type) {
24 this.construct (true, inFile, type);
25 }, "~S,~S");
26 Clazz.makeConstructor (c$, 
27 function (parseImmediately, inFile, type) {
28 Clazz.superConstructor (this, jalview.io.AlignFile, [inFile, type]);
29 this.initData ();
30 if (parseImmediately) {
31 this.doParse ();
32 }}, "~B,~S,~S");
33 Clazz.makeConstructor (c$, 
34 function (source) {
35 this.construct (true, source);
36 }, "jalview.io.FileParse");
37 Clazz.makeConstructor (c$, 
38 function (parseImmediately, source) {
39 Clazz.superConstructor (this, jalview.io.AlignFile, [source]);
40 this.initData ();
41 if (parseImmediately) {
42 this.doParse ();
43 }}, "~B,jalview.io.FileParse");
44 Clazz.defineMethod (c$, "doParse", 
45 function () {
46 if (this.parseCalled) {
47 throw  new java.io.IOException ("Implementation error: Parser called twice for same data.\nNeed to call initData() again before parsing can be reattempted.");
48 }this.parseCalled = true;
49 this.parse ();
50 for (var i = 0, c = this.seqs.size (); i < c; i++) {
51 this.seqs.get (i).setIndex (i);
52 }
53 });
54 Clazz.defineMethod (c$, "getSeqs", 
55 function () {
56 return this.seqs;
57 });
58 Clazz.defineMethod (c$, "getSeqGroups", 
59 function () {
60 return this.seqGroups;
61 });
62 Clazz.defineMethod (c$, "getSeqsAsArray", 
63 function () {
64 var s =  new Array (this.seqs.size ());
65 for (var i = 0; i < this.seqs.size (); i++) {
66 s[i] = this.seqs.elementAt (i);
67 }
68 return s;
69 });
70 Clazz.defineMethod (c$, "addAnnotations", 
71 function (al) {
72 this.addProperties (al);
73 for (var i = 0; i < this.annotations.size (); i++) {
74 var an = this.annotations.elementAt (i);
75 an.validateRangeAndDisplay ();
76 al.addAnnotation (an);
77 }
78 }, "jalview.datamodel.AlignmentI");
79 Clazz.defineMethod (c$, "addSeqGroups", 
80 function (al) {
81 this.seqGroups = al.getGroups ();
82 }, "jalview.datamodel.AlignmentI");
83 Clazz.defineMethod (c$, "addProperties", 
84 function (al) {
85 if (this.properties != null && this.properties.size () > 0) {
86 var keys = this.properties.keys ();
87 var vals = this.properties.elements ();
88 while (keys.hasMoreElements ()) {
89 al.setProperty (keys.nextElement (), vals.nextElement ());
90 }
91 }}, "jalview.datamodel.AlignmentI");
92 Clazz.defineMethod (c$, "setAlignmentProperty", 
93 function (key, value) {
94 if (key == null) {
95 throw  new Error (jalview.util.MessageManager.getString ("error.implementation_error_cannot_have_null_alignment"));
96 }if (value == null) {
97 return;
98 }if (this.properties == null) {
99 this.properties =  new java.util.Hashtable ();
100 }this.properties.put (key, value);
101 }, "~O,~O");
102 Clazz.defineMethod (c$, "getAlignmentProperty", 
103 function (key) {
104 if (this.properties != null && key != null) {
105 return this.properties.get (key);
106 }return null;
107 }, "~O");
108 Clazz.defineMethod (c$, "initData", 
109 function () {
110 this.seqs =  new java.util.Vector ();
111 this.annotations =  new java.util.Vector ();
112 this.seqGroups =  new java.util.ArrayList ();
113 this.parseCalled = false;
114 });
115 Clazz.defineMethod (c$, "setSeqs", 
116 function (s) {
117 this.seqs =  new java.util.Vector ();
118 for (var i = 0; i < s.length; i++) {
119 this.seqs.addElement (s[i]);
120 }
121 }, "~A");
122 Clazz.defineMethod (c$, "addJVSuffix", 
123 function (b) {
124 this.jvSuffix = b;
125 }, "~B");
126 Clazz.defineMethod (c$, "parseId", 
127 function (id) {
128 var seq = null;
129 id = id.trim ();
130 var space = id.indexOf (" ");
131 if (space > -1) {
132 seq =  new jalview.datamodel.Sequence (id.substring (0, space), "");
133 seq.setDescription (id.substring (space + 1));
134 } else {
135 seq =  new jalview.datamodel.Sequence (id, "");
136 }return seq;
137 }, "~S");
138 Clazz.defineMethod (c$, "printId", 
139 function (seq) {
140 return seq.getDisplayId (this.jvSuffix);
141 }, "jalview.datamodel.SequenceI");
142 Clazz.defineMethod (c$, "addNewickTree", 
143 function (treeName, newickString) {
144 if (this.newickStrings == null) {
145 this.newickStrings =  new java.util.Vector ();
146 }this.newickStrings.addElement ( Clazz.newArray (-1, [treeName, newickString]));
147 }, "~S,~S");
148 Clazz.defineMethod (c$, "getTreeCount", 
149 function () {
150 return this.newickStrings == null ? 0 : this.newickStrings.size ();
151 });
152 Clazz.defineMethod (c$, "addGroups", 
153 function (al) {
154 for (var sg, $sg = this.getSeqGroups ().iterator (); $sg.hasNext () && ((sg = $sg.next ()) || true);) {
155 al.addGroup (sg);
156 }
157 }, "jalview.datamodel.AlignmentI");
158 });