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