1 Clazz.declarePackage ("jalview.analysis");
2 Clazz.load (null, "jalview.analysis.SequenceIdMatcher", ["java.util.ArrayList", "$.Arrays", "$.HashMap", "$.Vector"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 if (!Clazz.isClassDefined ("jalview.analysis.SequenceIdMatcher.SeqIdName")) {
6 jalview.analysis.SequenceIdMatcher.$SequenceIdMatcher$SeqIdName$ ();
8 Clazz.instantialize (this, arguments);
9 }, jalview.analysis, "SequenceIdMatcher");
10 Clazz.makeConstructor (c$,
12 this.names = new java.util.HashMap ();
15 Clazz.defineMethod (c$, "addAll",
17 for (var seq, $seq = seqs.iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) {
18 this.names.put (Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seq.getDisplayId (true)), seq);
20 while (dbseq.getDatasetSequence () != null) {
21 dbseq = dbseq.getDatasetSequence ();
23 if (dbseq.getDBRef () != null) {
24 var dbr = dbseq.getDBRef ();
26 for (var r = 0; r < dbr.length; r++) {
27 sid = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, dbr[r].getAccessionId ());
28 if (!this.names.containsKey (sid)) {
29 this.names.put (sid, seq);
33 Clazz.makeConstructor (c$,
34 function (sequences) {
35 this.construct (java.util.Arrays.asList (sequences));
37 Clazz.defineMethod (c$, "pickbestMatch",
38 function (candName, matches) {
39 var st = this.pickbestMatches (candName, matches);
40 return st == null || st.size () == 0 ? null : st.get (0);
41 }, "jalview.analysis.SequenceIdMatcher.SeqIdName,java.util.List");
42 Clazz.defineMethod (c$, "pickbestMatches",
43 function (candName, matches) {
44 var best = new java.util.ArrayList ();
45 if (candName == null || matches == null || matches.size () == 0) {
47 }var match = matches.remove (0);
49 this.names.put (Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, match.getName ()), match);
50 var matchlen = match.getName ().length;
51 var namlen = candName.id.length;
52 while (matches.size () > 0) {
53 var cand = matches.remove (0);
54 this.names.put (Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, cand.getName ()), cand);
57 var candlen = cand.getName ().length;
58 if ((q = Math.abs (matchlen - namlen)) > (w = Math.abs (candlen - namlen)) && candlen > matchlen) {
63 }if (q == w && candlen == matchlen) {
66 if (best.size () == 0) {
69 }, "jalview.analysis.SequenceIdMatcher.SeqIdName,java.util.List");
70 Clazz.defineMethod (c$, "findIdMatch",
72 var nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seq.getName ());
73 return this.findIdMatch (nam);
74 }, "jalview.datamodel.SequenceI");
75 Clazz.defineMethod (c$, "findIdMatch",
77 var nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seqnam);
78 return this.findIdMatch (nam);
80 Clazz.defineMethod (c$, "findAllIdMatches",
82 var nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seqnam);
83 var m = this.findAllIdMatches (nam);
85 return m.toArray ( new Array (m.size ()));
88 Clazz.defineMethod (c$, "findIdMatch",
93 if (seqs.length > 0) {
94 namedseqs = new Array (seqs.length);
96 nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seqs[i].getName ());
97 if (this.names.containsKey (nam)) {
98 namedseqs[i] = this.findIdMatch (nam);
101 }} while (++i < seqs.length);
104 Clazz.defineMethod (c$, "findIdMatch",
106 var matches = new java.util.Vector ();
107 while (this.names.containsKey (nam)) {
108 matches.addElement (this.names.remove (nam));
110 return this.pickbestMatch (nam, matches);
111 }, "jalview.analysis.SequenceIdMatcher.SeqIdName");
112 Clazz.defineMethod (c$, "findAllIdMatches",
114 var matches = new java.util.ArrayList ();
115 while (this.names.containsKey (nam)) {
116 matches.add (this.names.remove (nam));
118 var r = this.pickbestMatches (nam, matches);
120 }, "jalview.analysis.SequenceIdMatcher.SeqIdName");
121 c$.$SequenceIdMatcher$SeqIdName$ = function () {
123 c$ = Clazz.decorateAsClass (function () {
124 Clazz.prepareCallback (this, arguments);
126 this.WORD_SEP = "~. |#\\/<>!\"\u00a4$%^*)}[@\',?_";
127 Clazz.instantialize (this, arguments);
128 }, jalview.analysis.SequenceIdMatcher, "SeqIdName");
129 Clazz.makeConstructor (c$,
132 this.id = String.instantialize (a);
136 Clazz.overrideMethod (c$, "hashCode",
138 return ((this.id.length >= 4) ? this.id.substring (0, 4).hashCode () : this.id.hashCode ());
140 Clazz.defineMethod (c$, "equals",
144 }if (Clazz.instanceOf (a, jalview.analysis.SequenceIdMatcher.SeqIdName)) {
145 return this.equals (a);
147 if (Clazz.instanceOf (a, String)) {
148 return this.equals (a);
151 Clazz.defineMethod (c$, "equals",
153 if (this.id.length > a.id.length) {
154 return this.id.startsWith (a.id) ? (this.WORD_SEP.indexOf (this.id.charAt (a.id.length)) > -1) : false;
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;
157 }}, "jalview.analysis.SequenceIdMatcher.SeqIdName");
158 Clazz.defineMethod (c$, "equals",
160 if (this.id.length > a.length) {
161 return this.id.startsWith (a) ? (this.WORD_SEP.indexOf (this.id.charAt (a.length)) > -1) : false;
163 return a.startsWith (this.id) ? (a.equals (this.id) ? true : (this.WORD_SEP.indexOf (a.charAt (this.id.length)) > -1)) : false;