1 Clazz.declarePackage ("jalview.io");
\r
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 () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
4 this.doGffSource = true;
\r
6 if (!Clazz.isClassDefined ("jalview.io.FeaturesFile.InvalidGFF3FieldException")) {
\r
7 jalview.io.FeaturesFile.$FeaturesFile$InvalidGFF3FieldException$ ();
\r
9 this.lastmatchedAl = null;
\r
10 this.matcher = null;
\r
11 Clazz.instantialize (this, arguments);
\r
12 }, jalview.io, "FeaturesFile", jalview.io.AlignFile);
\r
13 Clazz.makeConstructor (c$,
\r
15 Clazz.superConstructor (this, jalview.io.FeaturesFile, []);
\r
17 Clazz.defineMethod (c$, "parse",
\r
18 function (align, colours, removeHTML) {
\r
19 return this.parse (align, colours, null, removeHTML, false);
\r
20 }, "jalview.datamodel.AlignmentI,java.util.Hashtable,~B");
\r
21 Clazz.defineMethod (c$, "parse",
\r
22 function (align, colours, removeHTML, relaxedIdMatching) {
\r
23 return this.parse (align, colours, null, removeHTML, relaxedIdMatching);
\r
24 }, "jalview.datamodel.AlignmentI,java.util.Map,~B,~B");
\r
25 Clazz.defineMethod (c$, "parse",
\r
26 function (align, colours, featureLink, removeHTML) {
\r
27 return this.parse (align, colours, featureLink, removeHTML, false);
\r
28 }, "jalview.datamodel.AlignmentI,java.util.Map,java.util.Map,~B");
\r
29 Clazz.defineMethod (c$, "parse",
\r
30 function (align, colours, featureLink, removeHTML, relaxedIdmatching) {
\r
34 var newseqs = new java.util.ArrayList ();
\r
44 var featureGroup = null;
\r
45 var groupLink = null;
\r
46 var typeLink = new java.util.Hashtable ();
\r
48 var gffProps = new java.util.HashMap ();
\r
49 while ((line = this.nextLine ()) != null) {
\r
50 if (line.startsWith ("#")) {
\r
51 if (line.startsWith ("##")) {
\r
52 this.processGffPragma (line, gffProps, align, newseqs);
\r
55 }st = new java.util.StringTokenizer (line, "\t");
\r
56 if (st.countTokens () == 1) {
\r
57 if (line.trim ().equalsIgnoreCase ("GFF")) {
\r
60 }}if (st.countTokens () > 1 && st.countTokens () < 4) {
\r
62 type = st.nextToken ();
\r
63 if (type.equalsIgnoreCase ("startgroup")) {
\r
64 featureGroup = st.nextToken ();
\r
65 if (st.hasMoreElements ()) {
\r
66 groupLink = st.nextToken ();
\r
67 featureLink.put (featureGroup, groupLink);
\r
68 }} else if (type.equalsIgnoreCase ("endgroup")) {
\r
70 featureGroup = null;
\r
74 var colscheme = st.nextToken ();
\r
75 if (colscheme.indexOf ("|") > -1 || colscheme.trim ().equalsIgnoreCase ("label")) {
\r
76 var gcol = new java.util.StringTokenizer (colscheme, "|", true);
\r
77 var threshtype = -1;
\r
79 var max = 3.4028235E38;
\r
80 var threshval = NaN;
\r
81 var labelCol = false;
\r
82 var mincol = gcol.nextToken ();
\r
83 if (mincol === "|") {
\r
84 System.err.println ("Expected either 'label' or a colour specification in the line: " + line);
\r
87 if (mincol.toLowerCase ().indexOf ("label") == 0) {
\r
89 mincol = (gcol.hasMoreTokens () ? gcol.nextToken () : null);
\r
90 mincol = (gcol.hasMoreTokens () ? gcol.nextToken () : null);
\r
94 if (mincol != null) {
\r
95 if (mincol.equals ("|")) {
\r
99 }maxcol = gcol.nextToken ();
\r
100 if (maxcol.equals ("|")) {
\r
104 }abso = gcol.nextToken ();
\r
106 if (abso.toLowerCase ().indexOf ("abso") != 0) {
\r
110 minval = gcol.nextToken ();
\r
112 }maxval = gcol.nextToken ();
\r
113 if (gcol.hasMoreTokens ()) {
\r
116 if (minval.length > 0) {
\r
117 min = new Float (minval).floatValue ();
\r
119 if (Clazz.exceptionOf (e, Exception)) {
\r
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 ?");
\r
121 e.printStackTrace ();
\r
127 if (maxval.length > 0) {
\r
128 max = new Float (maxval).floatValue ();
\r
130 if (Clazz.exceptionOf (e, Exception)) {
\r
131 System.err.println ("Couldn't parse the maximum value for graduated colour for type (" + colscheme + ")");
\r
132 e.printStackTrace ();
\r
141 colour = new jalview.schemes.GraduatedColor ( new jalview.schemes.UserColourScheme (mincol).findColour ('A'), new jalview.schemes.UserColourScheme (maxcol).findColour ('A'), min, max);
\r
143 if (Clazz.exceptionOf (e, Exception)) {
\r
144 System.err.println ("Couldn't parse the graduated colour scheme (" + colscheme + ")");
\r
145 e.printStackTrace ();
\r
150 if (colour != null) {
\r
151 (colour).setColourByLabel (labelCol);
\r
152 (colour).setAutoScaled (abso == null);
\r
155 if (gcol.hasMoreTokens ()) {
\r
156 ttype = gcol.nextToken ();
\r
157 if (ttype.toLowerCase ().startsWith ("below")) {
\r
158 (colour).setThreshType (0);
\r
159 } else if (ttype.toLowerCase ().startsWith ("above")) {
\r
160 (colour).setThreshType (1);
\r
162 (colour).setThreshType (-1);
\r
163 if (!ttype.toLowerCase ().startsWith ("no")) {
\r
164 System.err.println ("Ignoring unrecognised threshold type : " + ttype);
\r
165 }}}if ((colour).getThreshType () != -1) {
\r
168 tval = gcol.nextToken ();
\r
169 (colour).setThresh ( new Float (tval).floatValue ());
\r
171 if (Clazz.exceptionOf (e, Exception)) {
\r
172 System.err.println ("Couldn't parse threshold value as a float: (" + tval + ")");
\r
173 e.printStackTrace ();
\r
178 }if (gcol.hasMoreTokens ()) {
\r
179 System.err.println ("Ignoring additional tokens in parameters in graduated colour specification\n");
\r
180 while (gcol.hasMoreTokens ()) {
\r
181 System.err.println ("|" + gcol.nextToken ());
\r
183 System.err.println ("\n");
\r
185 var ucs = new jalview.schemes.UserColourScheme (colscheme);
\r
186 colour = ucs.findColour ('A');
\r
187 }if (colour != null) {
\r
188 colours.put (type, colour);
\r
189 }if (st.hasMoreElements ()) {
\r
190 var link = st.nextToken ();
\r
191 typeLink.put (type, link);
\r
192 if (featureLink == null) {
\r
193 featureLink = new java.util.Hashtable ();
\r
194 }featureLink.put (type, link);
\r
197 while (st.hasMoreElements ()) {
\r
199 seqId = token = st.nextToken ();
\r
200 seq = this.findName (align, seqId, relaxedIdmatching, newseqs);
\r
202 desc = st.nextToken ();
\r
204 if (this.doGffSource && desc.indexOf (' ') == -1) {
\r
205 group = String.instantialize (desc);
\r
206 }type = st.nextToken ();
\r
208 var stt = st.nextToken ();
\r
209 if (stt.length == 0 || stt.equals ("-")) {
\r
212 start = Integer.parseInt (stt);
\r
214 if (Clazz.exceptionOf (ex, NumberFormatException)) {
\r
221 var stt = st.nextToken ();
\r
222 if (stt.length == 0 || stt.equals ("-")) {
\r
225 end = Integer.parseInt (stt);
\r
227 if (Clazz.exceptionOf (ex, NumberFormatException)) {
\r
236 score = new Float (st.nextToken ()).floatValue ();
\r
238 if (Clazz.exceptionOf (ex, NumberFormatException)) {
\r
244 sf = new jalview.datamodel.SequenceFeature (type, desc, start, end, score, group);
\r
246 sf.setValue ("STRAND", st.nextToken ());
\r
247 sf.setValue ("FRAME", st.nextToken ());
\r
249 if (Clazz.exceptionOf (ex, Exception)) {
\r
254 if (st.hasMoreTokens ()) {
\r
255 var attributes = new StringBuffer ();
\r
257 while (st.hasMoreTokens ()) {
\r
258 attributes.append ((sep ? "\t" : "") + st.nextElement ());
\r
261 sf.setValue ("ATTRIBUTES", attributes.toString ());
\r
262 }if (this.processOrAddSeqFeature (align, newseqs, seq, sf, GFFFile, relaxedIdmatching)) {
\r
263 while ((seq = align.findName (seq, seqId, true)) != null) {
\r
264 seq.addSequenceFeature ( new jalview.datamodel.SequenceFeature (sf));
\r
267 }}if (GFFFile && seq == null) {
\r
270 desc = st.nextToken ();
\r
271 }if (!st.hasMoreTokens ()) {
\r
272 System.err.println ("DEBUG: Run out of tokens when trying to identify the destination for the feature.. giving up.");
\r
274 }token = st.nextToken ();
\r
275 if (!token.equals ("ID_NOT_SPECIFIED")) {
\r
276 seq = this.findName (align, seqId = token, relaxedIdmatching, null);
\r
281 index = Integer.parseInt (st.nextToken ());
\r
282 seq = align.getSequenceAt (index);
\r
284 if (Clazz.exceptionOf (ex, NumberFormatException)) {
\r
290 }if (seq == null) {
\r
291 System.out.println ("Sequence not found: " + line);
\r
293 }start = Integer.parseInt (st.nextToken ());
\r
294 end = Integer.parseInt (st.nextToken ());
\r
295 type = st.nextToken ();
\r
296 if (!colours.containsKey (type)) {
\r
297 var ucs = new jalview.schemes.UserColourScheme (type);
\r
298 colours.put (type, ucs.findColour ('A'));
\r
299 }sf = new jalview.datamodel.SequenceFeature (type, desc, "", start, end, featureGroup);
\r
300 if (st.hasMoreTokens ()) {
\r
302 score = new Float (st.nextToken ()).floatValue ();
\r
304 if (Clazz.exceptionOf (ex, NumberFormatException)) {
\r
310 sf.setScore (score);
\r
311 }if (groupLink != null && removeHTML) {
\r
312 sf.addLink (groupLink);
\r
313 sf.description += "%LINK%";
\r
314 }if (typeLink.containsKey (type) && removeHTML) {
\r
315 sf.addLink (typeLink.get (type).toString ());
\r
316 sf.description += "%LINK%";
\r
317 }this.parseDescriptionHTML (sf, removeHTML);
\r
318 seq.addSequenceFeature (sf);
\r
319 while (seqId != null && (seq = align.findName (seq, seqId, false)) != null) {
\r
320 seq.addSequenceFeature ( new jalview.datamodel.SequenceFeature (sf));
\r
325 this.resetMatcher ();
\r
327 if (Clazz.exceptionOf (ex, Exception)) {
\r
328 this.warningMessage = ((this.warningMessage == null) ? "" : this.warningMessage) + "Parsing error at\n" + line;
\r
329 System.out.println ("Error parsing feature file: " + ex + "\n" + line);
\r
330 ex.printStackTrace (System.err);
\r
331 this.resetMatcher ();
\r
338 }, "jalview.datamodel.AlignmentI,java.util.Map,java.util.Map,~B,~B");
\r
339 Clazz.defineMethod (c$, "processGffPragma",
\r
340 ($fz = function (line, gffProps, align, newseqs) {
\r
341 var spacepos = line.indexOf (' ');
\r
342 var pragma = spacepos == -1 ? line.substring (2).trim () : line.substring (2, spacepos);
\r
343 var gffpragma = jalview.io.FeaturesFile.GFFPRAGMA.get (pragma.toLowerCase ());
\r
344 if (gffpragma == null) {
\r
346 }switch (gffpragma) {
\r
347 case jalview.io.FeaturesFile.GffPragmas.gff_version:
\r
349 this.gffversion = Integer.parseInt (line.substring (spacepos + 1));
\r
353 case jalview.io.FeaturesFile.GffPragmas.feature_ontology:
\r
355 case jalview.io.FeaturesFile.GffPragmas.attribute_ontology:
\r
357 case jalview.io.FeaturesFile.GffPragmas.source_ontology:
\r
359 case jalview.io.FeaturesFile.GffPragmas.species_build:
\r
361 case jalview.io.FeaturesFile.GffPragmas.hash:
\r
363 case jalview.io.FeaturesFile.GffPragmas.fasta:
\r
364 this.process_as_fasta (align, newseqs);
\r
367 System.err.println ("Ignoring unknown pragma:\n" + line);
\r
369 }, $fz.isPrivate = true, $fz), "~S,java.util.Map,jalview.datamodel.AlignmentI,java.util.ArrayList");
\r
370 Clazz.defineMethod (c$, "process_as_fasta",
\r
371 ($fz = function (align, newseqs) {
\r
375 if (Clazz.exceptionOf (q, java.io.IOException)) {
\r
380 var parser = jalview.jsdev.GenericFileAdapter.getFile ("FastaFile", []);
\r
381 var includedseqs = parser.getSeqs ();
\r
382 var smatcher = new jalview.analysis.SequenceIdMatcher (newseqs);
\r
383 for (var p = 0, pSize = includedseqs.size (); p < pSize; p++) {
\r
384 var dummyseq = smatcher.findIdMatch (includedseqs.get (p));
\r
385 if (dummyseq != null) {
\r
386 var mseq = includedseqs.get (p);
\r
387 if (Clazz.instanceOf (dummyseq, jalview.datamodel.SequenceDummy)) {
\r
388 (dummyseq).become (mseq);
\r
389 includedseqs.set (p, dummyseq);
\r
391 for (var seq, $seq = includedseqs.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
\r
392 align.addSequence (seq);
\r
394 }, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentI,java.util.List");
\r
395 Clazz.defineMethod (c$, "processOrAddSeqFeature",
\r
396 function (align, newseqs, seq, sf, gFFFile, relaxedIdMatching) {
\r
397 var attr = sf.getValue ("ATTRIBUTES");
\r
399 if (gFFFile && attr != null) {
\r
401 for (var attset, $attset = 0, $$attset = attr.$plit ("\t"); $attset < $$attset.length && ((attset = $$attset[$attset]) || true); $attset++) {
\r
402 if (attset == null || attset.trim ().length == 0) {
\r
405 var set = new java.util.HashMap ();
\r
406 for (var pair, $pair = 0, $$pair = attset.trim ().$plit (";"); $pair < $$pair.length && ((pair = $$pair[$pair]) || true); $pair++) {
\r
407 pair = pair.trim ();
\r
408 if (pair.length == 0) {
\r
410 }var eqpos = pair.indexOf ('=');
\r
411 var sppos = pair.indexOf (' ');
\r
414 if (sppos > -1 && (eqpos == -1 || sppos < eqpos)) {
\r
415 key = pair.substring (0, sppos);
\r
416 value = pair.substring (sppos + 1);
\r
418 if (eqpos > -1 && (sppos == -1 || eqpos < sppos)) {
\r
419 key = pair.substring (0, eqpos);
\r
420 value = pair.substring (eqpos + 1);
\r
423 }}if (key != null) {
\r
424 var vals = set.get (key);
\r
425 if (vals == null) {
\r
426 vals = new java.util.ArrayList ();
\r
427 set.put (key, vals);
\r
428 }if (value != null) {
\r
429 vals.add (value.trim ());
\r
432 add = new Boolean (add & this.processGffKey (set, nattr, seq, sf, align, newseqs, relaxedIdMatching)).valueOf ();
\r
434 if (Clazz.exceptionOf (ivfe, jalview.io.FeaturesFile.InvalidGFF3FieldException)) {
\r
435 System.err.println (ivfe);
\r
442 seq.addSequenceFeature (sf);
\r
444 }, "jalview.datamodel.AlignmentI,java.util.List,jalview.datamodel.SequenceI,jalview.datamodel.SequenceFeature,~B,~B");
\r
445 Clazz.defineMethod (c$, "processGffKey",
\r
446 function (set, nattr, seq, sf, align, newseqs, relaxedIdMatching) {
\r
448 if (sf.getType ().equals ("similarity")) {
\r
449 var strand = sf.getStrand ();
\r
450 var querySeq = this.findNames (align, newseqs, relaxedIdMatching, set.get (attr = "Query"));
\r
451 if (querySeq == null || querySeq.size () != 1) {
\r
452 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Expecting exactly one sequence in Query field (got " + set.get (attr) + ")");
\r
453 }if (set.containsKey (attr = "Align")) {
\r
454 var alco = new jalview.datamodel.AlignedCodonFrame ();
\r
455 var codonmapping = this.constructCodonMappingFromAlign (set, attr, strand);
\r
456 alco.addMap (seq, querySeq.get (0), codonmapping);
\r
457 align.addCodonFrame (alco);
\r
460 }, "java.util.Map,~N,jalview.datamodel.SequenceI,jalview.datamodel.SequenceFeature,jalview.datamodel.AlignmentI,java.util.List,~B");
\r
461 Clazz.defineMethod (c$, "constructCodonMappingFromAlign",
\r
462 ($fz = function (set, attr, strand) {
\r
464 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Invalid strand for a codon mapping (cannot be 0)");
\r
465 }var fromrange = new java.util.ArrayList ();
\r
466 var torange = new java.util.ArrayList ();
\r
468 var lastpframe = 0;
\r
469 for (var range, $range = set.get (attr).iterator (); $range.hasNext () && ((range = $range.next ()) || true);) {
\r
470 var ints = new java.util.ArrayList ();
\r
471 var st = new java.util.StringTokenizer (range, " ");
\r
472 while (st.hasMoreTokens ()) {
\r
473 var num = st.nextToken ();
\r
475 ints.add ( new Integer (num));
\r
477 if (Clazz.exceptionOf (nfe, NumberFormatException)) {
\r
478 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Invalid number in field " + num);
\r
484 if (ints.size () != 3) {
\r
485 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Invalid number of fields for this attribute (" + ints.size () + ")");
\r
486 }fromrange.add ( new Integer (ints.get (0).intValue ()));
\r
487 fromrange.add ( new Integer (ints.get (0).intValue () + strand * ints.get (2).intValue ()));
\r
488 if (ints.get (1).equals (new Integer (lastppos)) && lastpframe > 0) {
\r
489 lastppos += (ints.get (2)).intValue () / 3;
\r
490 lastpframe = (ints.get (2)).intValue () % 3;
\r
491 torange.set (torange.size () - 1, new Integer (lastppos));
\r
493 torange.add (ints.get (1));
\r
494 lastppos = (ints.get (1)).intValue () + (ints.get (2)).intValue () / 3;
\r
495 lastpframe = (ints.get (2)).intValue () % 3;
\r
496 torange.add ( new Integer (lastppos));
\r
498 if (fromrange.size () % 2 == 1) {
\r
499 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Couldn't parse the DNA alignment range correctly");
\r
500 }if (torange.size () % 2 == 1) {
\r
501 throw Clazz.innerTypeInstance (jalview.io.FeaturesFile.InvalidGFF3FieldException, this, null, attr, set, "Couldn't parse the protein alignment range correctly");
\r
502 }var frommap = Clazz.newIntArray (fromrange.size (), 0);
\r
503 var tomap = Clazz.newIntArray (torange.size (), 0);
\r
505 for (var ip, $ip = fromrange.iterator (); $ip.hasNext () && ((ip = $ip.next ()) || true);) {
\r
506 frommap[p++] = ip.intValue ();
\r
509 for (var ip, $ip = torange.iterator (); $ip.hasNext () && ((ip = $ip.next ()) || true);) {
\r
510 tomap[p++] = ip.intValue ();
\r
512 return new jalview.util.MapList (frommap, tomap, 3, 1);
\r
513 }, $fz.isPrivate = true, $fz), "java.util.Map,~S,~N");
\r
514 Clazz.defineMethod (c$, "findNames",
\r
515 ($fz = function (align, newseqs, relaxedIdMatching, list) {
\r
516 var found = new java.util.ArrayList ();
\r
517 for (var seqId, $seqId = list.iterator (); $seqId.hasNext () && ((seqId = $seqId.next ()) || true);) {
\r
518 var seq = this.findName (align, seqId, relaxedIdMatching, newseqs);
\r
523 }, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentI,java.util.List,~B,java.util.List");
\r
524 Clazz.defineMethod (c$, "resetMatcher",
\r
525 ($fz = function () {
\r
526 this.lastmatchedAl = null;
\r
527 this.matcher = null;
\r
528 }, $fz.isPrivate = true, $fz));
\r
529 Clazz.defineMethod (c$, "findName",
\r
530 ($fz = function (align, seqId, relaxedIdMatching, newseqs) {
\r
532 if (relaxedIdMatching) {
\r
533 if (this.lastmatchedAl !== align) {
\r
534 this.matcher = new jalview.analysis.SequenceIdMatcher ((this.lastmatchedAl = align).getSequencesArray ());
\r
535 if (newseqs != null) {
\r
536 this.matcher.addAll (newseqs);
\r
537 }}match = this.matcher.findIdMatch (seqId);
\r
539 match = align.findName (seqId, true);
\r
540 if (match == null && newseqs != null) {
\r
541 for (var m, $m = newseqs.iterator (); $m.hasNext () && ((m = $m.next ()) || true);) {
\r
542 if (seqId.equals (m.getName ())) {
\r
545 }}if (match == null && newseqs != null) {
\r
546 match = new jalview.datamodel.SequenceDummy (seqId);
\r
547 if (relaxedIdMatching) {
\r
548 this.matcher.addAll (java.util.Arrays.asList ( Clazz.newArray (-1, [match])));
\r
549 }newseqs.add (match);
\r
551 }, $fz.isPrivate = true, $fz), "jalview.datamodel.AlignmentI,~S,~B,java.util.List");
\r
552 Clazz.defineMethod (c$, "parseDescriptionHTML",
\r
553 function (sf, removeHTML) {
\r
554 if (sf.getDescription () == null) {
\r
556 }var parsed = new jalview.util.ParseHtmlBodyAndLinks (sf.getDescription (), removeHTML, this.newline);
\r
557 sf.description = (removeHTML) ? parsed.getNonHtmlContent () : sf.description;
\r
558 for (var link, $link = parsed.getLinks ().iterator (); $link.hasNext () && ((link = $link.next ()) || true);) {
\r
561 }, "jalview.datamodel.SequenceFeature,~B");
\r
562 Clazz.defineMethod (c$, "printJalviewFormat",
\r
563 function (seqs, visible) {
\r
564 return this.printJalviewFormat (seqs, visible, true, true);
\r
565 }, "~A,java.util.Map");
\r
566 Clazz.defineMethod (c$, "printJalviewFormat",
\r
567 function (seqs, visible, visOnly, nonpos) {
\r
568 var out = new StringBuffer ();
\r
570 var featuresGen = false;
\r
571 if (visOnly && !nonpos && (visible == null || visible.size () < 1)) {
\r
572 return "No Features Visible";
\r
573 }if (visible != null && visOnly) {
\r
574 var en = visible.keySet ().iterator ();
\r
577 while (en.hasNext ()) {
\r
578 type = en.next ().toString ();
\r
579 if (Clazz.instanceOf (visible.get (type), jalview.schemes.GraduatedColor)) {
\r
580 var gc = visible.get (type);
\r
581 color = (gc.isColourByLabel () ? "label|" : "") + jalview.util.Format.getHexString (gc.getMinColor ()) + "|" + jalview.util.Format.getHexString (gc.getMaxColor ()) + (gc.isAutoScale () ? "|" : "|abso|") + gc.getMin () + "|" + gc.getMax () + "|";
\r
582 if (gc.getThreshType () != -1) {
\r
583 if (gc.getThreshType () == 0) {
\r
586 if (gc.getThreshType () != 1) {
\r
587 System.err.println ("WARNING: Unsupported threshold type (" + gc.getThreshType () + ") : Assuming 'above'");
\r
589 }color += "|" + gc.getThresh ();
\r
592 }} else if (Clazz.instanceOf (visible.get (type), java.awt.Color)) {
\r
593 color = jalview.util.Format.getHexString (visible.get (type));
\r
595 color = jalview.util.Format.getHexString ( new java.awt.Color (Integer.parseInt (visible.get (type).toString ())));
\r
596 }out.append (type);
\r
598 out.append (color);
\r
599 out.append (this.newline);
\r
601 }var groups = new java.util.Vector ();
\r
602 var groupIndex = 0;
\r
603 var isnonpos = false;
\r
604 for (var i = 0; i < seqs.length; i++) {
\r
605 next = seqs[i].getSequenceFeatures ();
\r
606 if (next != null) {
\r
607 for (var j = 0; j < next.length; j++) {
\r
608 isnonpos = next[j].begin == 0 && next[j].end == 0;
\r
609 if ((!nonpos && isnonpos) || (!isnonpos && visOnly && !visible.containsKey (next[j].type))) {
\r
611 }if (next[j].featureGroup != null && !groups.contains (next[j].featureGroup)) {
\r
612 groups.addElement (next[j].featureGroup);
\r
617 if (groups.size () > 0 && groupIndex < groups.size ()) {
\r
618 group = groups.elementAt (groupIndex).toString ();
\r
619 out.append (this.newline);
\r
620 out.append ("STARTGROUP\t");
\r
621 out.append (group);
\r
622 out.append (this.newline);
\r
625 }for (var i = 0; i < seqs.length; i++) {
\r
626 next = seqs[i].getSequenceFeatures ();
\r
627 if (next != null) {
\r
628 for (var j = 0; j < next.length; j++) {
\r
629 isnonpos = next[j].begin == 0 && next[j].end == 0;
\r
630 if ((!nonpos && isnonpos) || (!isnonpos && visOnly && !visible.containsKey (next[j].type))) {
\r
632 }if (group != null && (next[j].featureGroup == null || !next[j].featureGroup.equals (group))) {
\r
634 }if (group == null && next[j].featureGroup != null) {
\r
636 }featuresGen = true;
\r
637 if (next[j].description == null || next[j].description.equals ("")) {
\r
638 out.append (next[j].type + "\t");
\r
640 if (next[j].links != null && next[j].getDescription ().indexOf ("<html>") == -1) {
\r
641 out.append ("<html>");
\r
642 }out.append (next[j].description + " ");
\r
643 if (next[j].links != null) {
\r
644 for (var l = 0; l < next[j].links.size (); l++) {
\r
645 var label = next[j].links.elementAt (l).toString ();
\r
646 var href = label.substring (label.indexOf ("|") + 1);
\r
647 label = label.substring (0, label.indexOf ("|"));
\r
648 if (next[j].description.indexOf (href) == -1) {
\r
649 out.append ("<a href=\"" + href + "\">" + label + "</a>");
\r
651 if (next[j].getDescription ().indexOf ("</html>") == -1) {
\r
652 out.append ("</html>");
\r
653 }}out.append ("\t");
\r
654 }out.append (seqs[i].getName ());
\r
655 out.append ("\t-1\t");
\r
656 out.append (next[j].begin);
\r
658 out.append (next[j].end);
\r
660 out.append (next[j].type);
\r
661 if (!Float.isNaN (next[j].score)) {
\r
663 out.append (next[j].score);
\r
664 }out.append (this.newline);
\r
667 if (group != null) {
\r
668 out.append ("ENDGROUP\t");
\r
669 out.append (group);
\r
670 out.append (this.newline);
\r
674 }} while (groupIndex < groups.size () + 1);
\r
675 if (!featuresGen) {
\r
676 return "No Features Visible";
\r
677 }return out.toString ();
\r
678 }, "~A,java.util.Map,~B,~B");
\r
679 Clazz.defineMethod (c$, "printGFFFormat",
\r
680 function (seqs, visible) {
\r
681 return this.printGFFFormat (seqs, visible, true, true);
\r
682 }, "~A,java.util.Map");
\r
683 Clazz.defineMethod (c$, "printGFFFormat",
\r
684 function (seqs, visible, visOnly, nonpos) {
\r
685 var out = new StringBuffer ();
\r
689 for (var i = 0; i < seqs.length; i++) {
\r
690 if (seqs[i].getSequenceFeatures () != null) {
\r
691 next = seqs[i].getSequenceFeatures ();
\r
692 for (var j = 0; j < next.length; j++) {
\r
693 isnonpos = next[j].begin == 0 && next[j].end == 0;
\r
694 if ((!nonpos && isnonpos) || (!isnonpos && visOnly && !visible.containsKey (next[j].type))) {
\r
696 }source = next[j].featureGroup;
\r
697 if (source == null) {
\r
698 source = next[j].getDescription ();
\r
699 }out.append (seqs[i].getName ());
\r
701 out.append (source);
\r
703 out.append (next[j].type);
\r
705 out.append (next[j].begin);
\r
707 out.append (next[j].end);
\r
709 out.append (next[j].score);
\r
711 if (next[j].getValue ("STRAND") != null) {
\r
712 out.append (next[j].getValue ("STRAND"));
\r
715 out.append (".\t");
\r
716 }if (next[j].getValue ("FRAME") != null) {
\r
717 out.append (next[j].getValue ("FRAME"));
\r
720 }if (next[j].getValue ("ATTRIBUTES") != null) {
\r
721 out.append (next[j].getValue ("ATTRIBUTES"));
\r
722 }out.append (this.newline);
\r
725 return out.toString ();
\r
726 }, "~A,java.util.Map,~B,~B");
\r
727 Clazz.defineMethod (c$, "parse",
\r
730 Clazz.overrideMethod (c$, "print",
\r
732 return "USE printGFFFormat() or printJalviewFormat()";
\r
734 c$.$FeaturesFile$InvalidGFF3FieldException$ = function () {
\r
736 c$ = Clazz.decorateAsClass (function () {
\r
737 Clazz.prepareCallback (this, arguments);
\r
740 Clazz.instantialize (this, arguments);
\r
741 }, jalview.io.FeaturesFile, "InvalidGFF3FieldException", Exception);
\r
742 Clazz.makeConstructor (c$,
\r
743 function (a, b, c) {
\r
744 Clazz.superConstructor (this, jalview.io.FeaturesFile.InvalidGFF3FieldException, [c + " (Field was " + a + " and value was " + b.get (a).toString ()]);
\r
746 this.value = b.get (a).toString ();
\r
747 }, "~S,java.util.Map,~S");
\r
751 c$ = Clazz.declareType (jalview.io.FeaturesFile, "GffPragmas", Enum);
\r
752 Clazz.defineEnumConstant (c$, "gff_version", 0, []);
\r
753 Clazz.defineEnumConstant (c$, "sequence_region", 1, []);
\r
754 Clazz.defineEnumConstant (c$, "feature_ontology", 2, []);
\r
755 Clazz.defineEnumConstant (c$, "attribute_ontology", 3, []);
\r
756 Clazz.defineEnumConstant (c$, "source_ontology", 4, []);
\r
757 Clazz.defineEnumConstant (c$, "species_build", 5, []);
\r
758 Clazz.defineEnumConstant (c$, "fasta", 6, []);
\r
759 Clazz.defineEnumConstant (c$, "hash", 7, []);
\r
761 Clazz.defineStatics (c$,
\r
762 "GFFPRAGMA", null);
\r
764 jalview.io.FeaturesFile.GFFPRAGMA = new java.util.HashMap ();
\r
765 jalview.io.FeaturesFile.GFFPRAGMA.put ("sequence-region", jalview.io.FeaturesFile.GffPragmas.sequence_region);
\r
766 jalview.io.FeaturesFile.GFFPRAGMA.put ("feature-ontology", jalview.io.FeaturesFile.GffPragmas.feature_ontology);
\r
767 jalview.io.FeaturesFile.GFFPRAGMA.put ("#", jalview.io.FeaturesFile.GffPragmas.hash);
\r
768 jalview.io.FeaturesFile.GFFPRAGMA.put ("fasta", jalview.io.FeaturesFile.GffPragmas.fasta);
\r
769 jalview.io.FeaturesFile.GFFPRAGMA.put ("species-build", jalview.io.FeaturesFile.GffPragmas.species_build);
\r
770 jalview.io.FeaturesFile.GFFPRAGMA.put ("source-ontology", jalview.io.FeaturesFile.GffPragmas.source_ontology);
\r
771 jalview.io.FeaturesFile.GFFPRAGMA.put ("attribute-ontology", jalview.io.FeaturesFile.GffPragmas.attribute_ontology);
\r