JAL-1807 test
[jalviewjs.git] / bin / jalview / io / FeaturesFile.js
1 Clazz.declarePackage ("jalview.io");
2 Clazz.load (["jalview.io.AlignFile", "java.lang.Enum", "$.Exception"], "jalview.io.FeaturesFile", ["jalview.analysis.SequenceIdMatcher", "jalview.datamodel.AlignedCodonFrame", "$.SequenceDummy", "$.SequenceFeature", "jalview.jsdev.GenericFileAdapter", "jalview.schemes.GraduatedColor", "$.UserColourScheme", "jalview.util.Format", "$.MapList", "$.ParseHtmlBodyAndLinks", "java.awt.Color", "java.lang.Float", "$.StringBuffer", "java.util.ArrayList", "$.Arrays", "$.HashMap", "$.Hashtable", "$.StringTokenizer", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.doGffSource = true;
5 this.gffversion = 0;
6 if (!Clazz.isClassDefined ("jalview.io.FeaturesFile.InvalidGFF3FieldException")) {
7 jalview.io.FeaturesFile.$FeaturesFile$InvalidGFF3FieldException$ ();
8 }
9 this.lastmatchedAl = null;
10 this.matcher = null;
11 Clazz.instantialize (this, arguments);
12 }, jalview.io, "FeaturesFile", jalview.io.AlignFile);
13 Clazz.makeConstructor (c$, 
14 function () {
15 Clazz.superConstructor (this, jalview.io.FeaturesFile, []);
16 });
17 Clazz.defineMethod (c$, "parse", 
18 function (align, colours, removeHTML) {
19 return this.parse (align, colours, null, removeHTML, false);
20 }, "jalview.datamodel.AlignmentI,java.util.Hashtable,~B");
21 Clazz.defineMethod (c$, "parse", 
22 function (align, colours, removeHTML, relaxedIdMatching) {
23 return this.parse (align, colours, null, removeHTML, relaxedIdMatching);
24 }, "jalview.datamodel.AlignmentI,java.util.Map,~B,~B");
25 Clazz.defineMethod (c$, "parse", 
26 function (align, colours, featureLink, removeHTML) {
27 return this.parse (align, colours, featureLink, removeHTML, false);
28 }, "jalview.datamodel.AlignmentI,java.util.Map,java.util.Map,~B");
29 Clazz.defineMethod (c$, "parse", 
30 function (align, colours, featureLink, removeHTML, relaxedIdmatching) {
31 var line = null;
32 try {
33 var seq = null;
34 var newseqs =  new java.util.ArrayList ();
35 var type;
36 var desc;
37 var token = null;
38 var index;
39 var start;
40 var end;
41 var score;
42 var st;
43 var sf;
44 var featureGroup = null;
45 var groupLink = null;
46 var typeLink =  new java.util.Hashtable ();
47 var GFFFile = true;
48 var gffProps =  new java.util.HashMap ();
49 while ((line = this.nextLine ()) != null) {
50 if (line.startsWith ("#")) {
51 if (line.startsWith ("##")) {
52 this.processGffPragma (line, gffProps, align, newseqs);
53 line = "";
54 }continue;
55 }st =  new java.util.StringTokenizer (line, "\t");
56 if (st.countTokens () == 1) {
57 if (line.trim ().equalsIgnoreCase ("GFF")) {
58 GFFFile = true;
59 continue;
60 }}if (st.countTokens () > 1 && st.countTokens () < 4) {
61 GFFFile = false;
62 type = st.nextToken ();
63 if (type.equalsIgnoreCase ("startgroup")) {
64 featureGroup = st.nextToken ();
65 if (st.hasMoreElements ()) {
66 groupLink = st.nextToken ();
67 featureLink.put (featureGroup, groupLink);
68 }} else if (type.equalsIgnoreCase ("endgroup")) {
69 st.nextToken ();
70 featureGroup = null;
71 groupLink = null;
72 } else {
73 var colour = null;
74 var colscheme = st.nextToken ();
75 if (colscheme.indexOf ("|") > -1 || colscheme.trim ().equalsIgnoreCase ("label")) {
76 var gcol =  new java.util.StringTokenizer (colscheme, "|", true);
77 var threshtype = -1;
78 var min = 1.4E-45;
79 var max = 3.4028235E38;
80 var threshval = NaN;
81 var labelCol = false;
82 var mincol = gcol.nextToken ();
83 if (mincol === "|") {
84 System.err.println ("Expected either 'label' or a colour specification in the line: " + line);
85 continue;
86 }var maxcol = null;
87 if (mincol.toLowerCase ().indexOf ("label") == 0) {
88 labelCol = true;
89 mincol = (gcol.hasMoreTokens () ? gcol.nextToken () : null);
90 mincol = (gcol.hasMoreTokens () ? gcol.nextToken () : null);
91 }var abso = null;
92 var minval;
93 var maxval;
94 if (mincol != null) {
95 if (mincol.equals ("|")) {
96 mincol = "";
97 } else {
98 gcol.nextToken ();
99 }maxcol = gcol.nextToken ();
100 if (maxcol.equals ("|")) {
101 maxcol = "";
102 } else {
103 gcol.nextToken ();
104 }abso = gcol.nextToken ();
105 gcol.nextToken ();
106 if (abso.toLowerCase ().indexOf ("abso") != 0) {
107 minval = abso;
108 abso = null;
109 } else {
110 minval = gcol.nextToken ();
111 gcol.nextToken ();
112 }maxval = gcol.nextToken ();
113 if (gcol.hasMoreTokens ()) {
114 gcol.nextToken ();
115 }try {
116 if (minval.length > 0) {
117 min =  new Float (minval).floatValue ();
118 }} catch (e) {
119 if (Clazz.exceptionOf (e, Exception)) {
120 System.err.println ("Couldn't parse the minimum value for graduated colour for type (" + colscheme + ") - did you misspell 'auto' for the optional automatic colour switch ?");
121 e.printStackTrace ();
122 } else {
123 throw e;
124 }
125 }
126 try {
127 if (maxval.length > 0) {
128 max =  new Float (maxval).floatValue ();
129 }} catch (e) {
130 if (Clazz.exceptionOf (e, Exception)) {
131 System.err.println ("Couldn't parse the maximum value for graduated colour for type (" + colscheme + ")");
132 e.printStackTrace ();
133 } else {
134 throw e;
135 }
136 }
137 } else {
138 mincol = "FFFFFF";
139 maxcol = "000000";
140 }try {
141 colour =  new jalview.schemes.GraduatedColor ( new jalview.schemes.UserColourScheme (mincol).findColour ('A'),  new jalview.schemes.UserColourScheme (maxcol).findColour ('A'), min, max);
142 } catch (e) {
143 if (Clazz.exceptionOf (e, Exception)) {
144 System.err.println ("Couldn't parse the graduated colour scheme (" + colscheme + ")");
145 e.printStackTrace ();
146 } else {
147 throw e;
148 }
149 }
150 if (colour != null) {
151 (colour).setColourByLabel (labelCol);
152 (colour).setAutoScaled (abso == null);
153 var ttype = null;
154 var tval = null;
155 if (gcol.hasMoreTokens ()) {
156 ttype = gcol.nextToken ();
157 if (ttype.toLowerCase ().startsWith ("below")) {
158 (colour).setThreshType (0);
159 } else if (ttype.toLowerCase ().startsWith ("above")) {
160 (colour).setThreshType (1);
161 } else {
162 (colour).setThreshType (-1);
163 if (!ttype.toLowerCase ().startsWith ("no")) {
164 System.err.println ("Ignoring unrecognised threshold type : " + ttype);
165 }}}if ((colour).getThreshType () != -1) {
166 try {
167 gcol.nextToken ();
168 tval = gcol.nextToken ();
169 (colour).setThresh ( new Float (tval).floatValue ());
170 } catch (e) {
171 if (Clazz.exceptionOf (e, Exception)) {
172 System.err.println ("Couldn't parse threshold value as a float: (" + tval + ")");
173 e.printStackTrace ();
174 } else {
175 throw e;
176 }
177 }
178 }if (gcol.hasMoreTokens ()) {
179 System.err.println ("Ignoring additional tokens in parameters in graduated colour specification\n");
180 while (gcol.hasMoreTokens ()) {
181 System.err.println ("|" + gcol.nextToken ());
182 }
183 System.err.println ("\n");
184 }}} else {
185 var ucs =  new jalview.schemes.UserColourScheme (colscheme);
186 colour = ucs.findColour ('A');
187 }if (colour != null) {
188 colours.put (type, colour);
189 }if (st.hasMoreElements ()) {
190 var link = st.nextToken ();
191 typeLink.put (type, link);
192 if (featureLink == null) {
193 featureLink =  new java.util.Hashtable ();
194 }featureLink.put (type, link);
195 }}continue;
196 }var seqId = "";
197 while (st.hasMoreElements ()) {
198 if (GFFFile) {
199 seqId = token = st.nextToken ();
200 seq = this.findName (align, seqId, relaxedIdmatching, newseqs);
201 if (seq != null) {
202 desc = st.nextToken ();
203 var group = null;
204 if (this.doGffSource && desc.indexOf (' ') == -1) {
205 group =  String.instantialize (desc);
206 }type = st.nextToken ();
207 try {
208 var stt = st.nextToken ();
209 if (stt.length == 0 || stt.equals ("-")) {
210 start = 0;
211 } else {
212 start = Integer.parseInt (stt);
213 }} catch (ex) {
214 if (Clazz.exceptionOf (ex, NumberFormatException)) {
215 start = 0;
216 } else {
217 throw ex;
218 }
219 }
220 try {
221 var stt = st.nextToken ();
222 if (stt.length == 0 || stt.equals ("-")) {
223 end = 0;
224 } else {
225 end = Integer.parseInt (stt);
226 }} catch (ex) {
227 if (Clazz.exceptionOf (ex, NumberFormatException)) {
228 end = 0;
229 } else {
230 throw ex;
231 }
232 }
233 if (end == 0) {
234 start = 0;
235 }try {
236 score =  new Float (st.nextToken ()).floatValue ();
237 } catch (ex) {
238 if (Clazz.exceptionOf (ex, NumberFormatException)) {
239 score = 0;
240 } else {
241 throw ex;
242 }
243 }
244 sf =  new jalview.datamodel.SequenceFeature (type, desc, start, end, score, group);
245 try {
246 sf.setValue ("STRAND", st.nextToken ());
247 sf.setValue ("FRAME", st.nextToken ());
248 } catch (ex) {
249 if (Clazz.exceptionOf (ex, Exception)) {
250 } else {
251 throw ex;
252 }
253 }
254 if (st.hasMoreTokens ()) {
255 var attributes =  new StringBuffer ();
256 var sep = false;
257 while (st.hasMoreTokens ()) {
258 attributes.append ((sep ? "\t" : "") + st.nextElement ());
259 sep = true;
260 }
261 sf.setValue ("ATTRIBUTES", attributes.toString ());
262 }if (this.processOrAddSeqFeature (align, newseqs, seq, sf, GFFFile, relaxedIdmatching)) {
263 while ((seq = align.findName (seq, seqId, true)) != null) {
264 seq.addSequenceFeature ( new jalview.datamodel.SequenceFeature (sf));
265 }
266 }break;
267 }}if (GFFFile && seq == null) {
268 desc = token;
269 } else {
270 desc = st.nextToken ();
271 }if (!st.hasMoreTokens ()) {
272 System.err.println ("DEBUG: Run out of tokens when trying to identify the destination for the feature.. giving up.");
273 return false;
274 }token = st.nextToken ();
275 if (!token.equals ("ID_NOT_SPECIFIED")) {
276 seq = this.findName (align, seqId = token, relaxedIdmatching, null);
277 st.nextToken ();
278 } else {
279 seqId = null;
280 try {
281 index = Integer.parseInt (st.nextToken ());
282 seq = align.getSequenceAt (index);
283 } catch (ex) {
284 if (Clazz.exceptionOf (ex, NumberFormatException)) {
285 seq = null;
286 } else {
287 throw ex;
288 }
289 }
290 }if (seq == null) {
291 System.out.println ("Sequence not found: " + line);
292 break;
293 }start = Integer.parseInt (st.nextToken ());
294 end = Integer.parseInt (st.nextToken ());
295 type = st.nextToken ();
296 if (!colours.containsKey (type)) {
297 var ucs =  new jalview.schemes.UserColourScheme (type);
298 colours.put (type, ucs.findColour ('A'));
299 }sf =  new jalview.datamodel.SequenceFeature (type, desc, "", start, end, featureGroup);
300 if (st.hasMoreTokens ()) {
301 try {
302 score =  new Float (st.nextToken ()).floatValue ();
303 } catch (ex) {
304 if (Clazz.exceptionOf (ex, NumberFormatException)) {
305 score = 0;
306 } else {
307 throw ex;
308 }
309 }
310 sf.setScore (score);
311 }if (groupLink != null && removeHTML) {
312 sf.addLink (groupLink);
313 sf.description += "%LINK%";
314 }if (typeLink.containsKey (type) && removeHTML) {
315 sf.addLink (typeLink.get (type).toString ());
316 sf.description += "%LINK%";
317 }this.parseDescriptionHTML (sf, removeHTML);
318 seq.addSequenceFeature (sf);
319 while (seqId != null && (seq = align.findName (seq, seqId, false)) != null) {
320 seq.addSequenceFeature ( new jalview.datamodel.SequenceFeature (sf));
321 }
322 GFFFile = false;
323 }
324 }
325 this.resetMatcher ();
326 } catch (ex) {
327 if (Clazz.exceptionOf (ex, Exception)) {
328 this.warningMessage = ((this.warningMessage == null) ? "" : this.warningMessage) + "Parsing error at\n" + line;
329 System.out.println ("Error parsing feature file: " + ex + "\n" + line);
330 ex.printStackTrace (System.err);
331 this.resetMatcher ();
332 return false;
333 } else {
334 throw ex;
335 }
336 }
337 return true;
338 }, "jalview.datamodel.AlignmentI,java.util.Map,java.util.Map,~B,~B");
339 Clazz.defineMethod (c$, "processGffPragma", 
340 ($fz = function (line, gffProps, align, newseqs) {
341 var spacepos = line.indexOf (' ');
342 var pragma = spacepos == -1 ? line.substring (2).trim () : line.substring (2, spacepos);
343 var gffpragma = jalview.io.FeaturesFile.GFFPRAGMA.get (pragma.toLowerCase ());
344 if (gffpragma == null) {
345 return;
346 }switch (gffpragma) {
347 case jalview.io.FeaturesFile.GffPragmas.gff_version:
348 try {
349 this.gffversion = Integer.parseInt (line.substring (spacepos + 1));
350 } finally {
351 }
352 break;
353 case jalview.io.FeaturesFile.GffPragmas.feature_ontology:
354 break;
355 case jalview.io.FeaturesFile.GffPragmas.attribute_ontology:
356 break;
357 case jalview.io.FeaturesFile.GffPragmas.source_ontology:
358 break;
359 case jalview.io.FeaturesFile.GffPragmas.species_build:
360 break;
361 case jalview.io.FeaturesFile.GffPragmas.hash:
362 break;
363 case jalview.io.FeaturesFile.GffPragmas.fasta:
364 this.process_as_fasta (align, newseqs);
365 break;
366 default:
367 System.err.println ("Ignoring unknown pragma:\n" + line);
368 }
369 }, $fz.isPrivate = true, $fz), "~S,java.util.Map,jalview.datamodel.AlignmentI,java.util.ArrayList");
370 Clazz.defineMethod (c$, "process_as_fasta", 
371 ($fz = function (align, newseqs) {
372 try {
373 this.mark ();
374 } catch (q) {
375 if (Clazz.exceptionOf (q, java.io.IOException)) {
376 } else {
377 throw q;
378 }
379 }
380 var parser = jalview.jsdev.GenericFileAdapter.getFile ("FastaFile", []);
381 var includedseqs = parser.getSeqs ();
382 var smatcher =  new jalview.analysis.SequenceIdMatcher (newseqs);
383 for (var p = 0, pSize = includedseqs.size (); p < pSize; p++) {
384 var dummyseq = smatcher.findIdMatch (includedseqs.get (p));
385 if (dummyseq != null) {
386 var mseq = includedseqs.get (p);
387 if (Clazz.instanceOf (dummyseq, jalview.datamodel.SequenceDummy)) {
388 (dummyseq).become (mseq);
389 includedseqs.set (p, dummyseq);
390 }}}
391 for (var seq, $seq = includedseqs.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
392 align.addSequence (seq);
393 }
394 }, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentI,java.util.List");
395 Clazz.defineMethod (c$, "processOrAddSeqFeature", 
396 function (align, newseqs, seq, sf, gFFFile, relaxedIdMatching) {
397 var attr = sf.getValue ("ATTRIBUTES");
398 var add = true;
399 if (gFFFile && attr != null) {
400 var nattr = 8;
401 for (var attset, $attset = 0, $$attset = attr.$plit ("\t"); $attset < $$attset.length && ((attset = $$attset[$attset]) || true); $attset++) {
402 if (attset == null || attset.trim ().length == 0) {
403 continue;
404 }nattr++;
405 var set =  new java.util.HashMap ();
406 for (var pair, $pair = 0, $$pair = attset.trim ().$plit (";"); $pair < $$pair.length && ((pair = $$pair[$pair]) || true); $pair++) {
407 pair = pair.trim ();
408 if (pair.length == 0) {
409 continue;
410 }var eqpos = pair.indexOf ('=');
411 var sppos = pair.indexOf (' ');
412 var key = null;
413 var value = null;
414 if (sppos > -1 && (eqpos == -1 || sppos < eqpos)) {
415 key = pair.substring (0, sppos);
416 value = pair.substring (sppos + 1);
417 } else {
418 if (eqpos > -1 && (sppos == -1 || eqpos < sppos)) {
419 key = pair.substring (0, eqpos);
420 value = pair.substring (eqpos + 1);
421 } else {
422 key = pair;
423 }}if (key != null) {
424 var vals = set.get (key);
425 if (vals == null) {
426 vals =  new java.util.ArrayList ();
427 set.put (key, vals);
428 }if (value != null) {
429 vals.add (value.trim ());
430 }}}
431 try {
432 add = new Boolean (add & this.processGffKey (set, nattr, seq, sf, align, newseqs, relaxedIdMatching)).valueOf ();
433 } catch (ivfe) {
434 if (Clazz.exceptionOf (ivfe, jalview.io.FeaturesFile.InvalidGFF3FieldException)) {
435 System.err.println (ivfe);
436 } else {
437 throw ivfe;
438 }
439 }
440 }
441 }if (add) {
442 seq.addSequenceFeature (sf);
443 }return add;
444 }, "jalview.datamodel.AlignmentI,java.util.List,jalview.datamodel.SequenceI,jalview.datamodel.SequenceFeature,~B,~B");
445 Clazz.defineMethod (c$, "processGffKey", 
446 function (set, nattr, seq, sf, align, newseqs, relaxedIdMatching) {
447 var attr;
448 if (sf.getType ().equals ("similarity")) {
449 var strand = sf.getStrand ();
450 var querySeq = this.findNames (align, newseqs, relaxedIdMatching, set.get (attr = "Query"));
451 if (querySeq == null || querySeq.size () != 1) {
452 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Expecting exactly one sequence in Query field (got " + set.get (attr) + ")");
453 }if (set.containsKey (attr = "Align")) {
454 var alco =  new jalview.datamodel.AlignedCodonFrame ();
455 var codonmapping = this.constructCodonMappingFromAlign (set, attr, strand);
456 alco.addMap (seq, querySeq.get (0), codonmapping);
457 align.addCodonFrame (alco);
458 return false;
459 }}return true;
460 }, "java.util.Map,~N,jalview.datamodel.SequenceI,jalview.datamodel.SequenceFeature,jalview.datamodel.AlignmentI,java.util.List,~B");
461 Clazz.defineMethod (c$, "constructCodonMappingFromAlign", 
462 ($fz = function (set, attr, strand) {
463 if (strand == 0) {
464 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Invalid strand for a codon mapping (cannot be 0)");
465 }var fromrange =  new java.util.ArrayList ();
466 var torange =  new java.util.ArrayList ();
467 var lastppos = 0;
468 var lastpframe = 0;
469 for (var range, $range = set.get (attr).iterator (); $range.hasNext () && ((range = $range.next ()) || true);) {
470 var ints =  new java.util.ArrayList ();
471 var st =  new java.util.StringTokenizer (range, " ");
472 while (st.hasMoreTokens ()) {
473 var num = st.nextToken ();
474 try {
475 ints.add ( new Integer (num));
476 } catch (nfe) {
477 if (Clazz.exceptionOf (nfe, NumberFormatException)) {
478 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Invalid number in field " + num);
479 } else {
480 throw nfe;
481 }
482 }
483 }
484 if (ints.size () != 3) {
485 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Invalid number of fields for this attribute (" + ints.size () + ")");
486 }fromrange.add ( new Integer (ints.get (0).intValue ()));
487 fromrange.add ( new Integer (ints.get (0).intValue () + strand * ints.get (2).intValue ()));
488 if (ints.get (1).equals (new Integer (lastppos)) && lastpframe > 0) {
489 lastppos += (ints.get (2)).intValue () / 3;
490 lastpframe = (ints.get (2)).intValue () % 3;
491 torange.set (torange.size () - 1,  new Integer (lastppos));
492 } else {
493 torange.add (ints.get (1));
494 lastppos = (ints.get (1)).intValue () + (ints.get (2)).intValue () / 3;
495 lastpframe = (ints.get (2)).intValue () % 3;
496 torange.add ( new Integer (lastppos));
497 }}
498 if (fromrange.size () % 2 == 1) {
499 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Couldn't parse the DNA alignment range correctly");
500 }if (torange.size () % 2 == 1) {
501 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Couldn't parse the protein alignment range correctly");
502 }var frommap =  Clazz.newIntArray (fromrange.size (), 0);
503 var tomap =  Clazz.newIntArray (torange.size (), 0);
504 var p = 0;
505 for (var ip, $ip = fromrange.iterator (); $ip.hasNext () && ((ip = $ip.next ()) || true);) {
506 frommap[p++] = ip.intValue ();
507 }
508 p = 0;
509 for (var ip, $ip = torange.iterator (); $ip.hasNext () && ((ip = $ip.next ()) || true);) {
510 tomap[p++] = ip.intValue ();
511 }
512 return  new jalview.util.MapList (frommap, tomap, 3, 1);
513 }, $fz.isPrivate = true, $fz), "java.util.Map,~S,~N");
514 Clazz.defineMethod (c$, "findNames", 
515 ($fz = function (align, newseqs, relaxedIdMatching, list) {
516 var found =  new java.util.ArrayList ();
517 for (var seqId, $seqId = list.iterator (); $seqId.hasNext () && ((seqId = $seqId.next ()) || true);) {
518 var seq = this.findName (align, seqId, relaxedIdMatching, newseqs);
519 if (seq != null) {
520 found.add (seq);
521 }}
522 return found;
523 }, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentI,java.util.List,~B,java.util.List");
524 Clazz.defineMethod (c$, "resetMatcher", 
525 ($fz = function () {
526 this.lastmatchedAl = null;
527 this.matcher = null;
528 }, $fz.isPrivate = true, $fz));
529 Clazz.defineMethod (c$, "findName", 
530 ($fz = function (align, seqId, relaxedIdMatching, newseqs) {
531 var match = null;
532 if (relaxedIdMatching) {
533 if (this.lastmatchedAl !== align) {
534 this.matcher =  new jalview.analysis.SequenceIdMatcher ((this.lastmatchedAl = align).getSequencesArray ());
535 if (newseqs != null) {
536 this.matcher.addAll (newseqs);
537 }}match = this.matcher.findIdMatch (seqId);
538 } else {
539 match = align.findName (seqId, true);
540 if (match == null && newseqs != null) {
541 for (var m, $m = newseqs.iterator (); $m.hasNext () && ((m = $m.next ()) || true);) {
542 if (seqId.equals (m.getName ())) {
543 return m;
544 }}
545 }}if (match == null && newseqs != null) {
546 match =  new jalview.datamodel.SequenceDummy (seqId);
547 if (relaxedIdMatching) {
548 this.matcher.addAll (java.util.Arrays.asList ( Clazz.newArray (-1, [match])));
549 }newseqs.add (match);
550 }return match;
551 }, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentI,~S,~B,java.util.List");
552 Clazz.defineMethod (c$, "parseDescriptionHTML", 
553 function (sf, removeHTML) {
554 if (sf.getDescription () == null) {
555 return;
556 }var parsed =  new jalview.util.ParseHtmlBodyAndLinks (sf.getDescription (), removeHTML, this.newline);
557 sf.description = (removeHTML) ? parsed.getNonHtmlContent () : sf.description;
558 for (var link, $link = parsed.getLinks ().iterator (); $link.hasNext () && ((link = $link.next ()) || true);) {
559 sf.addLink (link);
560 }
561 }, "jalview.datamodel.SequenceFeature,~B");
562 Clazz.defineMethod (c$, "printJalviewFormat", 
563 function (seqs, visible) {
564 return this.printJalviewFormat (seqs, visible, true, true);
565 }, "~A,java.util.Map");
566 Clazz.defineMethod (c$, "printJalviewFormat", 
567 function (seqs, visible, visOnly, nonpos) {
568 var out =  new StringBuffer ();
569 var next;
570 var featuresGen = false;
571 if (visOnly && !nonpos && (visible == null || visible.size () < 1)) {
572 return "No Features Visible";
573 }if (visible != null && visOnly) {
574 var en = visible.keySet ().iterator ();
575 var type;
576 var color;
577 while (en.hasNext ()) {
578 type = en.next ().toString ();
579 if (Clazz.instanceOf (visible.get (type), jalview.schemes.GraduatedColor)) {
580 var gc = visible.get (type);
581 color = (gc.isColourByLabel () ? "label|" : "") + jalview.util.Format.getHexString (gc.getMinColor ()) + "|" + jalview.util.Format.getHexString (gc.getMaxColor ()) + (gc.isAutoScale () ? "|" : "|abso|") + gc.getMin () + "|" + gc.getMax () + "|";
582 if (gc.getThreshType () != -1) {
583 if (gc.getThreshType () == 0) {
584 color += "below";
585 } else {
586 if (gc.getThreshType () != 1) {
587 System.err.println ("WARNING: Unsupported threshold type (" + gc.getThreshType () + ") : Assuming 'above'");
588 }color += "above";
589 }color += "|" + gc.getThresh ();
590 } else {
591 color += "none";
592 }} else if (Clazz.instanceOf (visible.get (type), java.awt.Color)) {
593 color = jalview.util.Format.getHexString (visible.get (type));
594 } else {
595 color = jalview.util.Format.getHexString ( new java.awt.Color (Integer.parseInt (visible.get (type).toString ())));
596 }out.append (type);
597 out.append ("\t");
598 out.append (color);
599 out.append (this.newline);
600 }
601 }var groups =  new java.util.Vector ();
602 var groupIndex = 0;
603 var isnonpos = false;
604 for (var i = 0; i < seqs.length; i++) {
605 next = seqs[i].getSequenceFeatures ();
606 if (next != null) {
607 for (var j = 0; j < next.length; j++) {
608 isnonpos = next[j].begin == 0 && next[j].end == 0;
609 if ((!nonpos && isnonpos) || (!isnonpos && visOnly && !visible.containsKey (next[j].type))) {
610 continue;
611 }if (next[j].featureGroup != null && !groups.contains (next[j].featureGroup)) {
612 groups.addElement (next[j].featureGroup);
613 }}
614 }}
615 var group = null;
616 do {
617 if (groups.size () > 0 && groupIndex < groups.size ()) {
618 group = groups.elementAt (groupIndex).toString ();
619 out.append (this.newline);
620 out.append ("STARTGROUP\t");
621 out.append (group);
622 out.append (this.newline);
623 } else {
624 group = null;
625 }for (var i = 0; i < seqs.length; i++) {
626 next = seqs[i].getSequenceFeatures ();
627 if (next != null) {
628 for (var j = 0; j < next.length; j++) {
629 isnonpos = next[j].begin == 0 && next[j].end == 0;
630 if ((!nonpos && isnonpos) || (!isnonpos && visOnly && !visible.containsKey (next[j].type))) {
631 continue;
632 }if (group != null && (next[j].featureGroup == null || !next[j].featureGroup.equals (group))) {
633 continue;
634 }if (group == null && next[j].featureGroup != null) {
635 continue;
636 }featuresGen = true;
637 if (next[j].description == null || next[j].description.equals ("")) {
638 out.append (next[j].type + "\t");
639 } else {
640 if (next[j].links != null && next[j].getDescription ().indexOf ("<html>") == -1) {
641 out.append ("<html>");
642 }out.append (next[j].description + " ");
643 if (next[j].links != null) {
644 for (var l = 0; l < next[j].links.size (); l++) {
645 var label = next[j].links.elementAt (l).toString ();
646 var href = label.substring (label.indexOf ("|") + 1);
647 label = label.substring (0, label.indexOf ("|"));
648 if (next[j].description.indexOf (href) == -1) {
649 out.append ("<a href=\"" + href + "\">" + label + "</a>");
650 }}
651 if (next[j].getDescription ().indexOf ("</html>") == -1) {
652 out.append ("</html>");
653 }}out.append ("\t");
654 }out.append (seqs[i].getName ());
655 out.append ("\t-1\t");
656 out.append ("" + next[j].begin);
657 out.append ("\t");
658 out.append ("" + next[j].end);
659 out.append ("\t");
660 out.append (next[j].type);
661 if (!Float.isNaN (next[j].score)) {
662 out.append ("\t");
663 out.append (next[j].score);
664 }out.append (this.newline);
665 }
666 }}
667 if (group != null) {
668 out.append ("ENDGROUP\t");
669 out.append (group);
670 out.append (this.newline);
671 groupIndex++;
672 } else {
673 break;
674 }} while (groupIndex < groups.size () + 1);
675 if (!featuresGen) {
676 return "No Features Visible";
677 }return out.toString ();
678 }, "~A,java.util.Map,~B,~B");
679 Clazz.defineMethod (c$, "printGFFFormat", 
680 function (seqs, visible) {
681 return this.printGFFFormat (seqs, visible, true, true);
682 }, "~A,java.util.Map");
683 Clazz.defineMethod (c$, "printGFFFormat", 
684 function (seqs, visible, visOnly, nonpos) {
685 var out =  new StringBuffer ();
686 var next;
687 var source;
688 var isnonpos;
689 for (var i = 0; i < seqs.length; i++) {
690 if (seqs[i].getSequenceFeatures () != null) {
691 next = seqs[i].getSequenceFeatures ();
692 for (var j = 0; j < next.length; j++) {
693 isnonpos = next[j].begin == 0 && next[j].end == 0;
694 if ((!nonpos && isnonpos) || (!isnonpos && visOnly && !visible.containsKey (next[j].type))) {
695 continue;
696 }source = next[j].featureGroup;
697 if (source == null) {
698 source = next[j].getDescription ();
699 }out.append (seqs[i].getName ());
700 out.append ("\t");
701 out.append (source);
702 out.append ("\t");
703 out.append (next[j].type);
704 out.append ("\t");
705 out.append ("" + next[j].begin);
706 out.append ("\t");
707 out.append ("" + next[j].end);
708 out.append ("\t");
709 out.append (next[j].score);
710 out.append ("\t");
711 if (next[j].getValue ("STRAND") != null) {
712 out.append (next[j].getValue ("STRAND"));
713 out.append ("\t");
714 } else {
715 out.append (".\t");
716 }if (next[j].getValue ("FRAME") != null) {
717 out.append (next[j].getValue ("FRAME"));
718 } else {
719 out.append (".");
720 }if (next[j].getValue ("ATTRIBUTES") != null) {
721 out.append (next[j].getValue ("ATTRIBUTES"));
722 }out.append (this.newline);
723 }
724 }}
725 return out.toString ();
726 }, "~A,java.util.Map,~B,~B");
727 Clazz.defineMethod (c$, "parse", 
728 function () {
729 });
730 Clazz.overrideMethod (c$, "print", 
731 function () {
732 return "USE printGFFFormat() or printJalviewFormat()";
733 });
734 c$.$FeaturesFile$InvalidGFF3FieldException$ = function () {
735 Clazz.pu$h ();
736 c$ = Clazz.decorateAsClass (function () {
737 Clazz.prepareCallback (this, arguments);
738 this.field = null;
739 this.value = null;
740 Clazz.instantialize (this, arguments);
741 }, jalview.io.FeaturesFile, "InvalidGFF3FieldException", Exception);
742 Clazz.makeConstructor (c$, 
743 function (a, b, c) {
744 Clazz.superConstructor (this, jalview.io.FeaturesFile.InvalidGFF3FieldException, [c + " (Field was " + a + " and value was " + b.get (a).toString ()]);
745 this.field = a;
746 this.value = b.get (a).toString ();
747 }, "~S,java.util.Map,~S");
748 c$ = Clazz.p0p ();
749 };
750 Clazz.pu$h ();
751 c$ = Clazz.declareType (jalview.io.FeaturesFile, "GffPragmas", Enum);
752 Clazz.defineEnumConstant (c$, "gff_version", 0, []);
753 Clazz.defineEnumConstant (c$, "sequence_region", 1, []);
754 Clazz.defineEnumConstant (c$, "feature_ontology", 2, []);
755 Clazz.defineEnumConstant (c$, "attribute_ontology", 3, []);
756 Clazz.defineEnumConstant (c$, "source_ontology", 4, []);
757 Clazz.defineEnumConstant (c$, "species_build", 5, []);
758 Clazz.defineEnumConstant (c$, "fasta", 6, []);
759 Clazz.defineEnumConstant (c$, "hash", 7, []);
760 c$ = Clazz.p0p ();
761 Clazz.defineStatics (c$,
762 "GFFPRAGMA", null);
763 {
764 jalview.io.FeaturesFile.GFFPRAGMA =  new java.util.HashMap ();
765 jalview.io.FeaturesFile.GFFPRAGMA.put ("sequence-region", jalview.io.FeaturesFile.GffPragmas.sequence_region);
766 jalview.io.FeaturesFile.GFFPRAGMA.put ("feature-ontology", jalview.io.FeaturesFile.GffPragmas.feature_ontology);
767 jalview.io.FeaturesFile.GFFPRAGMA.put ("#", jalview.io.FeaturesFile.GffPragmas.hash);
768 jalview.io.FeaturesFile.GFFPRAGMA.put ("fasta", jalview.io.FeaturesFile.GffPragmas.fasta);
769 jalview.io.FeaturesFile.GFFPRAGMA.put ("species-build", jalview.io.FeaturesFile.GffPragmas.species_build);
770 jalview.io.FeaturesFile.GFFPRAGMA.put ("source-ontology", jalview.io.FeaturesFile.GffPragmas.source_ontology);
771 jalview.io.FeaturesFile.GFFPRAGMA.put ("attribute-ontology", jalview.io.FeaturesFile.GffPragmas.attribute_ontology);
772 }});