1 Clazz.declarePackage ("jalview.datamodel");
2 Clazz.load (["jalview.datamodel.AnnotatedCollectionI", "java.awt.Color", "java.util.ArrayList"], "jalview.datamodel.SequenceGroup", ["jalview.analysis.AAFrequency", "$.Conservation", "jalview.datamodel.AlignmentAnnotation", "$.Sequence", "jalview.schemes.ResidueProperties", "jalview.util.Comparison", "java.lang.StringBuffer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 this.description = null;
7 this.aaFrequency = null;
8 this.displayBoxes = true;
9 this.displayText = true;
10 this.colourText = false;
11 this.showNonconserved = false;
12 this.sequences = null;
18 this.outlineColour = null;
20 this.thresholdTextColour = 0;
21 this.textColour = null;
22 this.textColour2 = null;
23 this.ignoreGapsInConsensus = true;
24 this.showSequenceLogo = false;
25 this.normaliseSequenceLogo = false;
26 this.consPercGaps = 25;
27 this.consensusData = null;
28 this.hidereps = false;
29 this.hidecols = false;
30 this.consensus = null;
31 this.conservation = null;
32 this.showConsensusHistogram = false;
34 Clazz.instantialize (this, arguments);
35 }, jalview.datamodel, "SequenceGroup", null, jalview.datamodel.AnnotatedCollectionI);
36 Clazz.prepareFields (c$, function () {
37 this.sequences = new java.util.ArrayList ();
38 this.outlineColour = java.awt.Color.black;
39 this.textColour = java.awt.Color.black;
40 this.textColour2 = java.awt.Color.white;
42 Clazz.defineMethod (c$, "isShowSequenceLogo",
44 return this.showSequenceLogo;
46 Clazz.makeConstructor (c$,
48 this.groupName = "JGroup:" + this.hashCode ();
50 Clazz.makeConstructor (c$,
51 function (sequences, groupName, scheme, displayBoxes, displayText, colourText, start, end) {
52 this.sequences = sequences;
53 this.groupName = groupName;
54 this.displayBoxes = displayBoxes;
55 this.displayText = displayText;
56 this.colourText = colourText;
58 this.startRes = start;
60 this.recalcConservation ();
61 }, "java.util.List,~S,jalview.schemes.ColourSchemeI,~B,~B,~B,~N,~N");
62 Clazz.makeConstructor (c$,
65 this.sequences = new java.util.ArrayList ();
66 this.sequences.addAll (seqsel.sequences);
67 if (seqsel.groupName != null) {
68 this.groupName = String.instantialize (seqsel.groupName);
69 }this.displayBoxes = seqsel.displayBoxes;
70 this.displayText = seqsel.displayText;
71 this.colourText = seqsel.colourText;
72 this.startRes = seqsel.startRes;
73 this.endRes = seqsel.endRes;
75 if (seqsel.description != null) {
76 this.description = String.instantialize (seqsel.description);
77 }this.hidecols = seqsel.hidecols;
78 this.hidereps = seqsel.hidereps;
79 this.idColour = seqsel.idColour;
80 this.outlineColour = seqsel.outlineColour;
81 this.seqrep = seqsel.seqrep;
82 this.textColour = seqsel.textColour;
83 this.textColour2 = seqsel.textColour2;
84 this.thresholdTextColour = seqsel.thresholdTextColour;
85 this.width = seqsel.width;
86 this.ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
87 if (seqsel.conserve != null) {
88 this.recalcConservation ();
89 }}}, "jalview.datamodel.SequenceGroup");
90 Clazz.defineMethod (c$, "getSelectionAsNewSequences",
92 var iSize = this.sequences.size ();
93 var seqs = new Array (iSize);
94 var inorder = this.getSequencesInOrder (align);
95 for (var i = 0, ipos = 0; i < inorder.length; i++) {
97 seqs[ipos] = seq.getSubSequence (this.startRes, this.endRes + 1);
98 if (seqs[ipos] != null) {
99 seqs[ipos].setDescription (seq.getDescription ());
100 seqs[ipos].setDBRef (seq.getDBRef ());
101 seqs[ipos].setSequenceFeatures (seq.getSequenceFeatures ());
102 if (seq.getDatasetSequence () != null) {
103 seqs[ipos].setDatasetSequence (seq.getDatasetSequence ());
104 }if (seq.getAnnotation () != null) {
105 var alann = align.getAlignmentAnnotation ();
106 for (var a = 0; a < seq.getAnnotation ().length; a++) {
107 var tocopy = seq.getAnnotation ()[a];
110 for (var pos = 0; pos < alann.length; pos++) {
111 if (alann[pos] === tocopy) {
117 }}var newannot = new jalview.datamodel.AlignmentAnnotation (seq.getAnnotation ()[a]);
118 newannot.restrict (this.startRes, this.endRes);
119 newannot.setSequenceRef (seqs[ipos]);
120 newannot.adjustForAlignment ();
121 seqs[ipos].addAlignmentAnnotation (newannot);
127 if (iSize != inorder.length) {
128 var nseqs = new Array (iSize);
129 System.arraycopy (seqs, 0, nseqs, 0, iSize);
132 }, "jalview.datamodel.AlignmentI");
133 Clazz.defineMethod (c$, "findEndRes",
137 for (var j = 0; j < this.endRes + 1 && j < seq.getLength (); j++) {
138 ch = seq.getCharAt (j);
139 if (!jalview.util.Comparison.isGap ((ch))) {
143 eres += seq.getStart () - 1;
145 }, "jalview.datamodel.SequenceI");
146 Clazz.defineMethod (c$, "getSequences",
148 return this.sequences;
150 Clazz.defineMethod (c$, "getSequences",
151 function (hiddenReps) {
152 if (hiddenReps == null) {
153 return this.sequences;
155 var allSequences = new java.util.ArrayList ();
156 for (var seq, $seq = this.sequences.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
157 allSequences.add (seq);
158 if (hiddenReps.containsKey (seq)) {
159 var hsg = hiddenReps.get (seq);
160 for (var seq2, $seq2 = hsg.getSequences ().iterator (); $seq2.hasNext () && ((seq2 = $seq2.next ()) || true);) {
161 if (seq2 !== seq && !allSequences.contains (seq2)) {
162 allSequences.add (seq2);
166 }}, "java.util.Map");
167 Clazz.defineMethod (c$, "getSequencesAsArray",
169 var tmp = this.getSequences (map);
172 }return tmp.toArray ( new Array (tmp.size ()));
174 Clazz.defineMethod (c$, "adjustForRemoveLeft",
176 if (this.startRes >= col) {
177 this.startRes = this.startRes - col;
178 }if (this.endRes >= col) {
179 this.endRes = this.endRes - col;
180 if (this.startRes > this.endRes) {
186 Clazz.defineMethod (c$, "adjustForRemoveRight",
188 if (this.startRes > col) {
190 }if (this.endRes >= col) {
194 Clazz.defineMethod (c$, "getName",
196 return this.groupName;
198 Clazz.defineMethod (c$, "getDescription",
200 return this.description;
202 Clazz.defineMethod (c$, "setName",
204 this.groupName = name;
206 Clazz.defineMethod (c$, "setDescription",
208 this.description = desc;
210 Clazz.defineMethod (c$, "getConservation",
212 return this.conserve;
214 Clazz.defineMethod (c$, "setConservation",
217 }, "jalview.analysis.Conservation");
218 Clazz.defineMethod (c$, "addSequence",
219 function (s, recalc) {
221 if (s != null && !this.sequences.contains (s)) {
222 this.sequences.add (s);
224 this.recalcConservation ();
225 }}}, "jalview.datamodel.SequenceI,~B");
226 Clazz.defineMethod (c$, "getConsPercGaps",
228 return this.consPercGaps;
230 Clazz.defineMethod (c$, "setConsPercGaps",
231 function (consPercGaps) {
232 this.consPercGaps = consPercGaps;
234 Clazz.defineMethod (c$, "recalcConservation",
236 if (this.cs == null && this.consensus == null && this.conservation == null) {
239 var cnsns = jalview.analysis.AAFrequency.calculate (this.sequences, this.startRes, this.endRes + 1, this.showSequenceLogo);
240 if (this.consensus != null) {
241 this._updateConsensusRow (cnsns, this.sequences.size ());
242 }if (this.cs != null) {
243 this.cs.setConsensus (cnsns);
244 }if ((this.conservation != null) || (this.cs != null && this.cs.conservationApplied ())) {
245 var c = new jalview.analysis.Conservation (this.groupName, jalview.schemes.ResidueProperties.propHash, 3, this.sequences, this.startRes, this.endRes + 1);
247 c.verdict (false, this.consPercGaps);
248 if (this.conservation != null) {
249 this._updateConservationRow (c);
250 }if (this.cs != null) {
251 if (this.cs.conservationApplied ()) {
252 this.cs.setConservation (c);
253 }}}if (this.cs != null) {
254 this.cs.alignmentChanged (this.context != null ? this.context : this, null);
256 if (Clazz.exceptionOf (err, OutOfMemoryError)) {
257 System.out.println ("Out of memory loading groups: " + err);
263 Clazz.defineMethod (c$, "_updateConservationRow",
264 ($fz = function (c) {
265 if (this.conservation == null) {
266 this.getConservation ();
267 }this.conservation.label = "Conservation for " + this.getName ();
268 this.conservation.description = "Conservation for group " + this.getName () + " less than " + this.consPercGaps + "% gaps";
269 var aWidth = (this.conservation.annotations != null) ? (this.endRes < this.conservation.annotations.length ? this.conservation.annotations.length : this.endRes + 1) : this.endRes + 1;
270 this.conservation.annotations = null;
271 this.conservation.annotations = new Array (aWidth);
272 c.completeAnnotations (this.conservation, null, this.startRes, this.endRes + 1);
273 }, $fz.isPrivate = true, $fz), "jalview.analysis.Conservation");
274 Clazz.defineMethod (c$, "_updateConsensusRow",
275 ($fz = function (cnsns, nseq) {
276 if (this.consensus == null) {
277 this.getConsensus ();
278 }this.consensus.label = "Consensus for " + this.getName ();
279 this.consensus.description = "Percent Identity";
280 this.consensusData = cnsns;
281 var aWidth = (this.consensus.annotations != null) ? (this.endRes < this.consensus.annotations.length ? this.consensus.annotations.length : this.endRes + 1) : this.endRes + 1;
282 this.consensus.annotations = null;
283 this.consensus.annotations = new Array (aWidth);
284 jalview.analysis.AAFrequency.completeConsensus (this.consensus, cnsns, this.startRes, this.endRes + 1, this.ignoreGapsInConsensus, this.showSequenceLogo, nseq);
285 }, $fz.isPrivate = true, $fz), "~A,~N");
286 Clazz.defineMethod (c$, "addOrRemove",
287 function (s, recalc) {
289 if (this.sequences.contains (s)) {
290 this.deleteSequence (s, recalc);
292 this.addSequence (s, recalc);
293 }}}, "jalview.datamodel.SequenceI,~B");
294 Clazz.defineMethod (c$, "deleteSequence",
295 function (s, recalc) {
297 this.sequences.remove (s);
299 this.recalcConservation ();
300 }}}, "jalview.datamodel.SequenceI,~B");
301 Clazz.overrideMethod (c$, "getStartRes",
303 return this.startRes;
305 Clazz.overrideMethod (c$, "getEndRes",
309 Clazz.defineMethod (c$, "setStartRes",
313 Clazz.defineMethod (c$, "setEndRes",
317 Clazz.defineMethod (c$, "getSize",
319 return this.sequences.size ();
321 Clazz.defineMethod (c$, "getSequenceAt",
323 return this.sequences.get (i);
325 Clazz.defineMethod (c$, "setColourText",
327 this.colourText = state;
329 Clazz.defineMethod (c$, "getColourText",
331 return this.colourText;
333 Clazz.defineMethod (c$, "setDisplayText",
335 this.displayText = state;
337 Clazz.defineMethod (c$, "getDisplayText",
339 return this.displayText;
341 Clazz.defineMethod (c$, "setDisplayBoxes",
343 this.displayBoxes = state;
345 Clazz.defineMethod (c$, "getDisplayBoxes",
347 return this.displayBoxes;
349 Clazz.overrideMethod (c$, "getWidth",
353 for (var seq, $seq = this.sequences.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
354 if (first || seq.getLength () > this.width) {
355 this.width = seq.getLength ();
360 Clazz.defineMethod (c$, "setOutlineColour",
362 this.outlineColour = c;
363 }, "java.awt.Color");
364 Clazz.defineMethod (c$, "getOutlineColour",
366 return this.outlineColour;
368 Clazz.defineMethod (c$, "getSequencesInOrder",
370 return this.getSequencesInOrder (al, true);
371 }, "jalview.datamodel.AlignmentI");
372 Clazz.defineMethod (c$, "getSequencesInOrder",
373 function (al, trim) {
375 var sSize = this.sequences.size ();
376 var alHeight = al.getHeight ();
377 var seqs = new Array ((trim) ? sSize : alHeight);
379 for (var i = 0; i < alHeight && index < sSize; i++) {
380 if (this.sequences.contains (al.getSequenceAt (i))) {
381 seqs[(trim) ? index : i] = al.getSequenceAt (i);
388 }if (index < seqs.length) {
390 seqs = new Array (index);
391 while (--index >= 0) {
392 seqs[index] = dummy[index];
396 }}, "jalview.datamodel.AlignmentI,~B");
397 Clazz.defineMethod (c$, "getIdColour",
399 return this.idColour;
401 Clazz.defineMethod (c$, "setIdColour",
402 function (idColour) {
403 this.idColour = idColour;
404 }, "java.awt.Color");
405 Clazz.overrideMethod (c$, "getSeqrep",
409 Clazz.overrideMethod (c$, "setSeqrep",
411 this.seqrep = seqrep;
412 }, "jalview.datamodel.SequenceI");
413 Clazz.overrideMethod (c$, "hasSeqrep",
415 return this.seqrep != null;
417 Clazz.defineMethod (c$, "setHidereps",
418 function (visibility) {
419 this.hidereps = visibility;
421 Clazz.defineMethod (c$, "isHidereps",
423 return this.hidereps;
425 Clazz.defineMethod (c$, "setHideCols",
426 function (visibility) {
427 this.hidecols = visibility;
429 Clazz.defineMethod (c$, "isHideCols",
431 return this.hidecols;
433 Clazz.defineMethod (c$, "intersect",
434 function (alignment, map) {
435 var sgroup = new jalview.datamodel.SequenceGroup (this);
436 var insect = this.getSequencesInOrder (alignment);
437 sgroup.sequences = new java.util.ArrayList ();
438 for (var s = 0; insect != null && s < insect.length; s++) {
439 if (map == null || map.containsKey (insect[s])) {
440 sgroup.sequences.add (insect[s]);
443 }, "jalview.datamodel.AlignmentI,java.util.Map");
444 Clazz.defineMethod (c$, "getShowNonconserved",
446 return this.showNonconserved;
448 Clazz.defineMethod (c$, "setShowNonconserved",
449 function (displayNonconserved) {
450 this.showNonconserved = displayNonconserved;
452 Clazz.defineMethod (c$, "setConsensus",
454 if (this.consensus == null) {
455 this.consensus = aan;
456 }}, "jalview.datamodel.AlignmentAnnotation");
457 Clazz.defineMethod (c$, "getConsensus",
459 var aWidth = this.getWidth ();
462 }if (this.consensus == null) {
463 this.consensus = new jalview.datamodel.AlignmentAnnotation ("", "", new Array (1), 0, 100, 1);
464 this.consensus.hasText = true;
465 this.consensus.autoCalculated = true;
466 this.consensus.groupRef = this;
467 this.consensus.label = "Consensus for " + this.getName ();
468 this.consensus.description = "Percent Identity";
469 }return this.consensus;
471 Clazz.defineMethod (c$, "setConservationRow",
473 if (this.conservation == null) {
474 this.conservation = aan;
475 }}, "jalview.datamodel.AlignmentAnnotation");
476 Clazz.defineMethod (c$, "getConservationRow",
478 if (this.conservation == null) {
479 this.conservation = new jalview.datamodel.AlignmentAnnotation ("", "", new Array (1), 0, 11, 1);
480 }this.conservation.hasText = true;
481 this.conservation.autoCalculated = true;
482 this.conservation.groupRef = this;
483 this.conservation.label = "Conservation for " + this.getName ();
484 this.conservation.description = "Conservation for group " + this.getName () + " less than " + this.consPercGaps + "% gaps";
485 return this.conservation;
487 Clazz.defineMethod (c$, "hasAnnotationRows",
489 return this.consensus != null || this.conservation != null;
491 Clazz.defineMethod (c$, "getConsensusSeq",
493 this.getConsensus ();
494 var seqs = new StringBuffer ();
495 for (var i = 0; i < this.consensus.annotations.length; i++) {
496 if (this.consensus.annotations[i] != null) {
497 if (this.consensus.annotations[i].description.charAt (0) == '[') {
498 seqs.append (this.consensus.annotations[i].description.charAt (1));
500 seqs.append (this.consensus.annotations[i].displayCharacter);
502 var sq = new jalview.datamodel.Sequence ("Group" + this.getName () + " Consensus", seqs.toString ());
503 sq.setDescription ("Percentage Identity Consensus " + ((this.ignoreGapsInConsensus) ? " without gaps" : ""));
506 Clazz.defineMethod (c$, "setIgnoreGapsConsensus",
508 if (this.ignoreGapsInConsensus != state && this.consensus != null) {
509 this.ignoreGapsInConsensus = state;
510 this.recalcConservation ();
511 }this.ignoreGapsInConsensus = state;
513 Clazz.defineMethod (c$, "getIgnoreGapsConsensus",
515 return this.ignoreGapsInConsensus;
517 Clazz.defineMethod (c$, "setshowSequenceLogo",
518 function (showSequenceLogo) {
519 if (this.showSequenceLogo != showSequenceLogo && this.consensus != null) {
520 this.showSequenceLogo = showSequenceLogo;
521 this.recalcConservation ();
522 }this.showSequenceLogo = showSequenceLogo;
524 Clazz.defineMethod (c$, "setShowConsensusHistogram",
525 function (showConsHist) {
526 if (this.showConsensusHistogram != showConsHist && this.consensus != null) {
527 this.showConsensusHistogram = showConsHist;
528 this.recalcConservation ();
529 }this.showConsensusHistogram = showConsHist;
531 Clazz.defineMethod (c$, "isShowConsensusHistogram",
533 return this.showConsensusHistogram;
535 Clazz.defineMethod (c$, "setNormaliseSequenceLogo",
537 this.normaliseSequenceLogo = norm;
539 Clazz.defineMethod (c$, "isNormaliseSequenceLogo",
541 return this.normaliseSequenceLogo;
543 Clazz.overrideMethod (c$, "getAlignmentAnnotation",
545 var annot = new java.util.ArrayList ();
547 for (var seq, $seq = this.sequences.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
548 var aa = seq.getAnnotation ();
550 for (var al, $al = 0, $$al = aa; $al < $$al.length && ((al = $$al[$al]) || true); $al++) {
551 if (al.groupRef === this) {
555 if (this.consensus != null) {
556 annot.add (this.consensus);
557 }if (this.conservation != null) {
558 annot.add (this.conservation);
559 }}return annot.toArray ( new Array (0));
561 Clazz.overrideMethod (c$, "findAnnotation",
563 var aa = new java.util.ArrayList ();
564 for (var a, $a = 0, $$a = this.getAlignmentAnnotation (); $a < $$a.length && ((a = $$a[$a]) || true); $a++) {
565 if (a.getCalcId () === calcId) {
570 Clazz.overrideMethod (c$, "findAnnotations",
571 function (seq, calcId, label) {
572 var aa = new java.util.ArrayList ();
573 for (var ann, $ann = 0, $$ann = this.getAlignmentAnnotation (); $ann < $$ann.length && ((ann = $$ann[$ann]) || true); $ann++) {
574 if (ann.getCalcId () != null && ann.getCalcId ().equals (calcId) && ann.sequenceRef != null && ann.sequenceRef === seq && ann.label != null && ann.label.equals (label)) {
578 }, "jalview.datamodel.SequenceI,~S,~S");
579 Clazz.defineMethod (c$, "hasAnnotation",
581 if (calcId != null && !"".equals (calcId)) {
582 for (var a, $a = 0, $$a = this.getAlignmentAnnotation (); $a < $$a.length && ((a = $$a[$a]) || true); $a++) {
583 if (a.getCalcId () === calcId) {
588 Clazz.defineMethod (c$, "clear",
591 this.sequences.clear ();
593 Clazz.defineMethod (c$, "setContext",
595 this.context = context;
596 }, "jalview.datamodel.AnnotatedCollectionI");
597 Clazz.overrideMethod (c$, "getContext",