JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / analysis / SequenceIdMatcher.js
1 Clazz.declarePackage ("jalview.analysis");\r
2 Clazz.load (null, "jalview.analysis.SequenceIdMatcher", ["java.util.ArrayList", "$.Arrays", "$.HashMap", "$.Vector"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.names = null;\r
5 if (!Clazz.isClassDefined ("jalview.analysis.SequenceIdMatcher.SeqIdName")) {\r
6 jalview.analysis.SequenceIdMatcher.$SequenceIdMatcher$SeqIdName$ ();\r
7 }\r
8 Clazz.instantialize (this, arguments);\r
9 }, jalview.analysis, "SequenceIdMatcher");\r
10 Clazz.makeConstructor (c$, \r
11 function (seqs) {\r
12 this.names =  new java.util.HashMap ();\r
13 this.addAll (seqs);\r
14 }, "java.util.List");\r
15 Clazz.defineMethod (c$, "addAll", \r
16 function (seqs) {\r
17 for (var seq, $seq = seqs.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {\r
18 this.names.put (Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seq.getDisplayId (true)), seq);\r
19 var dbseq = seq;\r
20 while (dbseq.getDatasetSequence () != null) {\r
21 dbseq = dbseq.getDatasetSequence ();\r
22 }\r
23 if (dbseq.getDBRef () != null) {\r
24 var dbr = dbseq.getDBRef ();\r
25 var sid = null;\r
26 for (var r = 0; r < dbr.length; r++) {\r
27 sid = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, dbr[r].getAccessionId ());\r
28 if (!this.names.containsKey (sid)) {\r
29 this.names.put (sid, seq);\r
30 }}\r
31 }}\r
32 }, "java.util.List");\r
33 Clazz.makeConstructor (c$, \r
34 function (sequences) {\r
35 this.construct (java.util.Arrays.asList (sequences));\r
36 }, "~A");\r
37 Clazz.defineMethod (c$, "pickbestMatch", \r
38 ($fz = function (candName, matches) {\r
39 var st = this.pickbestMatches (candName, matches);\r
40 return st == null || st.size () == 0 ? null : st.get (0);\r
41 }, $fz.isPrivate = true, $fz), "jalview.analysis.SequenceIdMatcher.SeqIdName,java.util.List");\r
42 Clazz.defineMethod (c$, "pickbestMatches", \r
43 ($fz = function (candName, matches) {\r
44 var best =  new java.util.ArrayList ();\r
45 if (candName == null || matches == null || matches.size () == 0) {\r
46 return null;\r
47 }var match = matches.remove (0);\r
48 best.add (match);\r
49 this.names.put (Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, match.getName ()), match);\r
50 var matchlen = match.getName ().length;\r
51 var namlen = candName.id.length;\r
52 while (matches.size () > 0) {\r
53 var cand = matches.remove (0);\r
54 this.names.put (Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, cand.getName ()), cand);\r
55 var q;\r
56 var w;\r
57 var candlen = cand.getName ().length;\r
58 if ((q = Math.abs (matchlen - namlen)) > (w = Math.abs (candlen - namlen)) && candlen > matchlen) {\r
59 best.clear ();\r
60 match = cand;\r
61 matchlen = candlen;\r
62 best.add (match);\r
63 }if (q == w && candlen == matchlen) {\r
64 best.add (cand);\r
65 }}\r
66 if (best.size () == 0) {\r
67 return null;\r
68 };return best;\r
69 }, $fz.isPrivate = true, $fz), "jalview.analysis.SequenceIdMatcher.SeqIdName,java.util.List");\r
70 Clazz.defineMethod (c$, "findIdMatch", \r
71 function (seq) {\r
72 var nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seq.getName ());\r
73 return this.findIdMatch (nam);\r
74 }, "jalview.datamodel.SequenceI");\r
75 Clazz.defineMethod (c$, "findIdMatch", \r
76 function (seqnam) {\r
77 var nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seqnam);\r
78 return this.findIdMatch (nam);\r
79 }, "~S");\r
80 Clazz.defineMethod (c$, "findAllIdMatches", \r
81 function (seqnam) {\r
82 var nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seqnam);\r
83 var m = this.findAllIdMatches (nam);\r
84 if (m != null) {\r
85 return m.toArray ( new Array (m.size ()));\r
86 }return null;\r
87 }, "~S");\r
88 Clazz.defineMethod (c$, "findIdMatch", \r
89 function (seqs) {\r
90 var namedseqs = null;\r
91 var i = 0;\r
92 var nam;\r
93 if (seqs.length > 0) {\r
94 namedseqs =  new Array (seqs.length);\r
95 do {\r
96 nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seqs[i].getName ());\r
97 if (this.names.containsKey (nam)) {\r
98 namedseqs[i] = this.findIdMatch (nam);\r
99 } else {\r
100 namedseqs[i] = null;\r
101 }} while (++i < seqs.length);\r
102 }return namedseqs;\r
103 }, "~A");\r
104 Clazz.defineMethod (c$, "findIdMatch", \r
105 ($fz = function (nam) {\r
106 var matches =  new java.util.Vector ();\r
107 while (this.names.containsKey (nam)) {\r
108 matches.addElement (this.names.remove (nam));\r
109 }\r
110 return this.pickbestMatch (nam, matches);\r
111 }, $fz.isPrivate = true, $fz), "jalview.analysis.SequenceIdMatcher.SeqIdName");\r
112 Clazz.defineMethod (c$, "findAllIdMatches", \r
113 ($fz = function (nam) {\r
114 var matches =  new java.util.ArrayList ();\r
115 while (this.names.containsKey (nam)) {\r
116 matches.add (this.names.remove (nam));\r
117 }\r
118 var r = this.pickbestMatches (nam, matches);\r
119 return r;\r
120 }, $fz.isPrivate = true, $fz), "jalview.analysis.SequenceIdMatcher.SeqIdName");\r
121 c$.$SequenceIdMatcher$SeqIdName$ = function () {\r
122 Clazz.pu$h ();\r
123 c$ = Clazz.decorateAsClass (function () {\r
124 Clazz.prepareCallback (this, arguments);\r
125 this.id = null;\r
126 this.WORD_SEP = "~. |#\\/<>!\"\u00a4$%^*)}[@\',?_";\r
127 Clazz.instantialize (this, arguments);\r
128 }, jalview.analysis.SequenceIdMatcher, "SeqIdName");\r
129 Clazz.makeConstructor (c$, \r
130 function (a) {\r
131 if (a != null) {\r
132 this.id =  String.instantialize (a);\r
133 } else {\r
134 this.id = "";\r
135 }}, "~S");\r
136 Clazz.overrideMethod (c$, "hashCode", \r
137 function () {\r
138 return ((this.id.length >= 4) ? this.id.substring (0, 4).hashCode () : this.id.hashCode ());\r
139 });\r
140 Clazz.defineMethod (c$, "equals", \r
141 function (a) {\r
142 if (a == null) {\r
143 return false;\r
144 }if (Clazz.instanceOf (a, jalview.analysis.SequenceIdMatcher.SeqIdName)) {\r
145 return this.equals (a);\r
146 } else {\r
147 if (Clazz.instanceOf (a, String)) {\r
148 return this.equals (a);\r
149 }}return false;\r
150 }, "~O");\r
151 Clazz.defineMethod (c$, "equals", \r
152 function (a) {\r
153 if (this.id.length > a.id.length) {\r
154 return this.id.startsWith (a.id) ? (this.WORD_SEP.indexOf (this.id.charAt (a.id.length)) > -1) : false;\r
155 } else {\r
156 return a.id.startsWith (this.id) ? (a.id.equals (this.id) ? true : (this.WORD_SEP.indexOf (a.id.charAt (this.id.length)) > -1)) : false;\r
157 }}, "jalview.analysis.SequenceIdMatcher.SeqIdName");\r
158 Clazz.defineMethod (c$, "equals", \r
159 function (a) {\r
160 if (this.id.length > a.length) {\r
161 return this.id.startsWith (a) ? (this.WORD_SEP.indexOf (this.id.charAt (a.length)) > -1) : false;\r
162 } else {\r
163 return a.startsWith (this.id) ? (a.equals (this.id) ? true : (this.WORD_SEP.indexOf (a.charAt (this.id.length)) > -1)) : false;\r
164 }}, "~S");\r
165 c$ = Clazz.p0p ();\r
166 };\r
167 });\r