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