src/hg/js/autocomplete.js 1.3
1.3 2010/02/16 01:27:05 larrym
add lookupGene
Index: src/hg/js/autocomplete.js
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/js/autocomplete.js,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 4 -r1.2 -r1.3
--- src/hg/js/autocomplete.js 9 Feb 2010 08:51:30 -0000 1.2
+++ src/hg/js/autocomplete.js 16 Feb 2010 01:27:05 -0000 1.3
@@ -47,4 +47,32 @@
if(suggestCache != null)
suggestCache[this.key] = response;
this.cont(eval(response));
}
+
+function lookupGene(db, gene)
+{
+// returns coordinates for gene (requires an exact match).
+// Warning: this function does a synchronous ajax call.
+ // first look in our local cache.
+ if(suggestCache && suggestCache[gene]) {
+ var list = eval(suggestCache[gene]);
+ for(var i=0;i<list.length;i++) {
+ if(list[i].value == gene) {
+ return list[i].id;
+ }
+ }
+ }
+ // synchronously get match from the server
+ var str = $.ajax({
+ url: "../cgi-bin/hgSuggest",
+ data: "exact=1&db=" + db + "&prefix=" + gene,
+ async: false
+ }).responseText;
+ if(str) {
+ var obj = eval(str);
+ if(obj.length == 1) {
+ return obj[0].id;
+ }
+ }
+ return null;
+}