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
5 if (!Clazz.isClassDefined ("jalview.analysis.SequenceIdMatcher.SeqIdName")) {
\r
6 jalview.analysis.SequenceIdMatcher.$SequenceIdMatcher$SeqIdName$ ();
\r
8 Clazz.instantialize (this, arguments);
\r
9 }, jalview.analysis, "SequenceIdMatcher");
\r
10 Clazz.makeConstructor (c$,
\r
12 this.names = new java.util.HashMap ();
\r
14 }, "java.util.List");
\r
15 Clazz.defineMethod (c$, "addAll",
\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
20 while (dbseq.getDatasetSequence () != null) {
\r
21 dbseq = dbseq.getDatasetSequence ();
\r
23 if (dbseq.getDBRef () != null) {
\r
24 var dbr = dbseq.getDBRef ();
\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
32 }, "java.util.List");
\r
33 Clazz.makeConstructor (c$,
\r
34 function (sequences) {
\r
35 this.construct (java.util.Arrays.asList (sequences));
\r
37 Clazz.defineMethod (c$, "pickbestMatch",
\r
38 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 }, "jalview.analysis.SequenceIdMatcher.SeqIdName,java.util.List");
\r
42 Clazz.defineMethod (c$, "pickbestMatches",
\r
43 function (candName, matches) {
\r
44 var best = new java.util.ArrayList ();
\r
45 if (candName == null || matches == null || matches.size () == 0) {
\r
47 }var match = matches.remove (0);
\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
57 var candlen = cand.getName ().length;
\r
58 if ((q = Math.abs (matchlen - namlen)) > (w = Math.abs (candlen - namlen)) && candlen > matchlen) {
\r
63 }if (q == w && candlen == matchlen) {
\r
66 if (best.size () == 0) {
\r
69 }, "jalview.analysis.SequenceIdMatcher.SeqIdName,java.util.List");
\r
70 Clazz.defineMethod (c$, "findIdMatch",
\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
77 var nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seqnam);
\r
78 return this.findIdMatch (nam);
\r
80 Clazz.defineMethod (c$, "findAllIdMatches",
\r
82 var nam = Clazz.innerTypeInstance (jalview.analysis.SequenceIdMatcher.SeqIdName, this, null, seqnam);
\r
83 var m = this.findAllIdMatches (nam);
\r
85 return m.toArray ( new Array (m.size ()));
\r
88 Clazz.defineMethod (c$, "findIdMatch",
\r
90 var namedseqs = null;
\r
93 if (seqs.length > 0) {
\r
94 namedseqs = new Array (seqs.length);
\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
100 namedseqs[i] = null;
\r
101 }} while (++i < seqs.length);
\r
104 Clazz.defineMethod (c$, "findIdMatch",
\r
106 var matches = new java.util.Vector ();
\r
107 while (this.names.containsKey (nam)) {
\r
108 matches.addElement (this.names.remove (nam));
\r
110 return this.pickbestMatch (nam, matches);
\r
111 }, "jalview.analysis.SequenceIdMatcher.SeqIdName");
\r
112 Clazz.defineMethod (c$, "findAllIdMatches",
\r
114 var matches = new java.util.ArrayList ();
\r
115 while (this.names.containsKey (nam)) {
\r
116 matches.add (this.names.remove (nam));
\r
118 var r = this.pickbestMatches (nam, matches);
\r
120 }, "jalview.analysis.SequenceIdMatcher.SeqIdName");
\r
121 c$.$SequenceIdMatcher$SeqIdName$ = function () {
\r
122 Clazz.pu$h(self.c$);
\r
123 c$ = Clazz.decorateAsClass (function () {
\r
124 Clazz.prepareCallback (this, arguments);
\r
126 this.WORD_SEP = "~. |#\\/<>!\"\u00a4$%^*)}[@\',?_";
\r
127 Clazz.instantialize (this, arguments);
\r
128 }, jalview.analysis.SequenceIdMatcher, "SeqIdName");
\r
129 Clazz.makeConstructor (c$,
\r
132 this.id = String.instantialize (a);
\r
136 Clazz.overrideMethod (c$, "hashCode",
\r
138 return ((this.id.length >= 4) ? this.id.substring (0, 4).hashCode () : this.id.hashCode ());
\r
140 Clazz.defineMethod (c$, "equals",
\r
144 }if (Clazz.instanceOf (a, jalview.analysis.SequenceIdMatcher.SeqIdName)) {
\r
145 return this.equals (a);
\r
147 if (Clazz.instanceOf (a, String)) {
\r
148 return this.equals (a);
\r
151 Clazz.defineMethod (c$, "equals",
\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
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
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
163 return a.startsWith (this.id) ? (a.equals (this.id) ? true : (this.WORD_SEP.indexOf (a.charAt (this.id.length)) > -1)) : false;
\r