Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / jalview / analysis / AnnotationSorter.js
1 Clazz.declarePackage ("jalview.analysis");
2 Clazz.load (["java.lang.Enum", "java.util.HashMap"], "jalview.analysis.AnnotationSorter", ["jalview.analysis.AlignmentUtils", "java.lang.UnsupportedOperationException", "java.util.Arrays"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.alignment = null;
5 this.showAutocalcAbove = false;
6 this.sequenceIndices = null;
7 this.bySequenceAndLabel = null;
8 this.byLabelAndSequence = null;
9 this.noSort = null;
10 Clazz.instantialize (this, arguments);
11 }, jalview.analysis, "AnnotationSorter");
12 Clazz.prepareFields (c$, function () {
13 this.sequenceIndices =  new java.util.HashMap ();
14 this.bySequenceAndLabel = ((Clazz.isClassDefined ("jalview.analysis.AnnotationSorter$1") ? 0 : jalview.analysis.AnnotationSorter.$AnnotationSorter$1$ ()), Clazz.innerTypeInstance (jalview.analysis.AnnotationSorter$1, this, null));
15 this.byLabelAndSequence = ((Clazz.isClassDefined ("jalview.analysis.AnnotationSorter$2") ? 0 : jalview.analysis.AnnotationSorter.$AnnotationSorter$2$ ()), Clazz.innerTypeInstance (jalview.analysis.AnnotationSorter$2, this, null));
16 this.noSort = ((Clazz.isClassDefined ("jalview.analysis.AnnotationSorter$3") ? 0 : jalview.analysis.AnnotationSorter.$AnnotationSorter$3$ ()), Clazz.innerTypeInstance (jalview.analysis.AnnotationSorter$3, this, null));
17 });
18 Clazz.makeConstructor (c$, 
19 function (alignmentI, showAutocalculatedAbove) {
20 this.alignment = alignmentI;
21 this.showAutocalcAbove = showAutocalculatedAbove;
22 }, "jalview.datamodel.AlignmentI,~B");
23 Clazz.defineMethod (c$, "sort", 
24 function (alignmentAnnotations, order) {
25 if (alignmentAnnotations == null) {
26 return;
27 }this.saveSequenceIndices (alignmentAnnotations);
28 var comparator = this.getComparator (order);
29 if (alignmentAnnotations != null) {
30 {
31 java.util.Arrays.sort (alignmentAnnotations, comparator);
32 }}}, "~A,jalview.analysis.AnnotationSorter.SequenceAnnotationOrder");
33 Clazz.defineMethod (c$, "saveSequenceIndices", 
34  function (alignmentAnnotations) {
35 this.sequenceIndices.clear ();
36 for (var ann, $ann = 0, $$ann = alignmentAnnotations; $ann < $$ann.length && ((ann = $$ann[$ann]) || true); $ann++) {
37 var seq = ann.sequenceRef;
38 if (seq != null) {
39 var index = jalview.analysis.AlignmentUtils.getSequenceIndex (this.alignment, seq);
40 this.sequenceIndices.put (seq, new Integer (index));
41 }}
42 }, "~A");
43 Clazz.defineMethod (c$, "getComparator", 
44  function (order) {
45 if (order == null) {
46 return this.noSort;
47 }switch (order) {
48 case jalview.analysis.AnnotationSorter.SequenceAnnotationOrder.NONE:
49 return this.noSort;
50 case jalview.analysis.AnnotationSorter.SequenceAnnotationOrder.SEQUENCE_AND_LABEL:
51 return this.bySequenceAndLabel;
52 case jalview.analysis.AnnotationSorter.SequenceAnnotationOrder.LABEL_AND_SEQUENCE:
53 return this.byLabelAndSequence;
54 default:
55 throw  new UnsupportedOperationException (order.toString ());
56 }
57 }, "jalview.analysis.AnnotationSorter.SequenceAnnotationOrder");
58 Clazz.defineMethod (c$, "compareLabels", 
59  function (o1, o2) {
60 if (o1 == null || o2 == null) {
61 return 0;
62 }var label1 = o1.label;
63 var label2 = o2.label;
64 if (label1 == null && label2 == null) {
65 return 0;
66 }if (label1 == null) {
67 return -1;
68 }if (label2 == null) {
69 return 1;
70 }return label1.toUpperCase ().compareTo (label2.toUpperCase ());
71 }, "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.AlignmentAnnotation");
72 Clazz.defineMethod (c$, "compareSequences", 
73  function (o1, o2) {
74 var seq1 = o1.sequenceRef;
75 var seq2 = o2.sequenceRef;
76 if (seq1 == null && seq2 == null) {
77 return 0;
78 }if (seq1 == null) {
79 return this.showAutocalcAbove ? -1 : 1;
80 }if (seq2 == null) {
81 return this.showAutocalcAbove ? 1 : -1;
82 }var index1 = (this.sequenceIndices.get (seq1)).intValue ();
83 var index2 = (this.sequenceIndices.get (seq2)).intValue ();
84 if (index1 == index2) {
85 return 0;
86 }if (index1 == -1) {
87 return -1;
88 }if (index2 == -1) {
89 return 1;
90 }return Integer.compare (index1, index2);
91 }, "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.AlignmentAnnotation");
92 c$.$AnnotationSorter$1$ = function () {
93 Clazz.pu$h(self.c$);
94 c$ = Clazz.declareAnonymous (jalview.analysis, "AnnotationSorter$1", null, java.util.Comparator);
95 Clazz.overrideMethod (c$, "compare", 
96 function (o1, o2) {
97 if (o1 == null && o2 == null) {
98 return 0;
99 }if (o1 == null) {
100 return -1;
101 }if (o2 == null) {
102 return 1;
103 }if (o1.sequenceRef == null && o2.sequenceRef == null) {
104 return 0;
105 }var sequenceOrder = this.b$["jalview.analysis.AnnotationSorter"].compareSequences (o1, o2);
106 return sequenceOrder == 0 ? this.b$["jalview.analysis.AnnotationSorter"].compareLabels (o1, o2) : sequenceOrder;
107 }, "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.AlignmentAnnotation");
108 c$ = Clazz.p0p ();
109 };
110 c$.$AnnotationSorter$2$ = function () {
111 Clazz.pu$h(self.c$);
112 c$ = Clazz.declareAnonymous (jalview.analysis, "AnnotationSorter$2", null, java.util.Comparator);
113 Clazz.overrideMethod (c$, "compare", 
114 function (o1, o2) {
115 if (o1 == null && o2 == null) {
116 return 0;
117 }if (o1 == null) {
118 return -1;
119 }if (o2 == null) {
120 return 1;
121 }if (o1.sequenceRef == null && o2.sequenceRef == null) {
122 return 0;
123 }if (o1.sequenceRef == null) {
124 return this.b$["jalview.analysis.AnnotationSorter"].showAutocalcAbove ? -1 : 1;
125 }if (o2.sequenceRef == null) {
126 return this.b$["jalview.analysis.AnnotationSorter"].showAutocalcAbove ? 1 : -1;
127 }var labelOrder = this.b$["jalview.analysis.AnnotationSorter"].compareLabels (o1, o2);
128 return labelOrder == 0 ? this.b$["jalview.analysis.AnnotationSorter"].compareSequences (o1, o2) : labelOrder;
129 }, "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.AlignmentAnnotation");
130 c$ = Clazz.p0p ();
131 };
132 c$.$AnnotationSorter$3$ = function () {
133 Clazz.pu$h(self.c$);
134 c$ = Clazz.declareAnonymous (jalview.analysis, "AnnotationSorter$3", null, java.util.Comparator);
135 Clazz.overrideMethod (c$, "compare", 
136 function (o1, o2) {
137 if (o1 != null && o2 != null) {
138 if (o1.sequenceRef == null && o2.sequenceRef != null) {
139 return this.b$["jalview.analysis.AnnotationSorter"].showAutocalcAbove ? -1 : 1;
140 }if (o1.sequenceRef != null && o2.sequenceRef == null) {
141 return this.b$["jalview.analysis.AnnotationSorter"].showAutocalcAbove ? 1 : -1;
142 }}return 0;
143 }, "jalview.datamodel.AlignmentAnnotation,jalview.datamodel.AlignmentAnnotation");
144 c$ = Clazz.p0p ();
145 };
146 Clazz.pu$h(self.c$);
147 c$ = Clazz.decorateAsClass (function () {
148 this.description = null;
149 Clazz.instantialize (this, arguments);
150 }, jalview.analysis.AnnotationSorter, "SequenceAnnotationOrder", Enum);
151 Clazz.makeConstructor (c$, 
152  function (a) {
153 this.description = a;
154 }, "~S");
155 Clazz.overrideMethod (c$, "toString", 
156 function () {
157 return this.description;
158 });
159 c$.forDescription = Clazz.defineMethod (c$, "forDescription", 
160 function (a) {
161 for (var order, $order = 0, $$order = jalview.analysis.AnnotationSorter.SequenceAnnotationOrder.values (); $order < $$order.length && ((order = $$order[$order]) || true); $order++) {
162 if (order.toString ().equals (a)) {
163 return order;
164 }}
165 return null;
166 }, "~S");
167 Clazz.defineEnumConstant (c$, "SEQUENCE_AND_LABEL", 0, ["Sequence"]);
168 Clazz.defineEnumConstant (c$, "LABEL_AND_SEQUENCE", 1, ["Label"]);
169 Clazz.defineEnumConstant (c$, "NONE", 2, ["No sort"]);
170 c$ = Clazz.p0p ();
171 });