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