Example GOlr Sessions

From GO Wiki
Jump to: navigation, search

Overview

This page has examples of various kinds things that you can with a BBOP JS session on the GO Solr (GOlr) data store.

More documentation soon...

Usage

The is a standard JS environment that makes use of

More documentation soon...

JS add.

This adds two numbers.

Session:

1 + 2;

Use a pre-defined output div.

Put something into one of the pre-defined output divs.

Session:

empty('div1');
append('div1', 'Hello, World!');

Simple loop (each) use.

An example of how to use the loop (each) iterator.

Session:

us.each(['X', 'Y', 'Z'],
     function(item, i){
       empty('div' + (i +1));
       append('div' + (i +1), 'Hi, ' + item + '!');
     });

Write to the log.

Write an arbitrary something to the REPL console log.

Session:

ll('Hello, World!');

Display the GAF URL (for current filters).

This doesn't do much, but illustrates how to get a link out.

Session:

empty('div3');
append('div3', go.gaf_url());

Add a trivial autocomplete box.

Add in an autocomplete at 'div2', *reusing* our global manager.

Session:

empty('div2');
var in1 = new html.input({'id':'in1', 'style':'border:1px solid black;'});
append('div2', in1.to_string());
go.set_personality('ontology');
var ac = new widgets.autocomplete_simple(go, gserv_download, gconf, 'in1', {});

Add a autocomplete box just for GO terms, with trivial callback

Add in an autocomplete at 'div2' for just GO terms using the somewhat slimmer 'bbop_term_ac' personality. This example also contains the addition of a trivial callback function that is triggered on selection.

Session:

empty('div2');
var in1 = new html.input({'id':'in1', 'style':'border:1px solid black;'});
append('div2', in1.to_string());
function jumper(arg1){ alert(arg1); };
go.set_personality('ontology');
go.add_query_filter('document_category', 'ontology_class');
go.add_query_filter('source', '(biological_process OR molecular_function OR cellular_component)');
var ac = new widgets.autocomplete_simple(go, gserv_download, gconf, 'in1',
  {
    'label_template':
    '{{annotation_class_label}} ({{annotation_class}})',
    'value_template': '{{annotation_class}}',
    'list_select_callback': jumper
  });

PANTHER family annotation count for experimental evidence.

The REPL code for a familiar simple operation.

Session:

var print_panther = function(resp){
   us.each(resp.facet_field('panther_family_label'),
   function(pitem){ ll(pitem[0] + ': ' + pitem[1]); });
};

go.set_personality('annotation')
go.add_query_filter('evidence_type_closure', 'experimental evidence');
go.set_results_count(0);
go.set_facet_limit(-1);
go.register('search', print_panther);
go.search()

Startup code for REPL environment.

The code that is used to initialize the GOlr/BBOP JS REPL environment.

Session:

// Top.
var amigo = window.repl.amigo;
var us = window.repl.us;
var bbop = window.repl.bbop;
var widgets = window.repl.widgets;
var html = window.repl.html;
var amigo = window.repl.amigo;
var golr_conf = window.repl.golr_conf;
var gconf = window.repl.gconf;
var sd = window.repl.sd;
var gserv = window.repl.gserv;
var gserv_download = window.repl.gserv_download;
var defs = window.repl.defs;
var linker = window.repl.linker;
var handler = window.repl.handler;
var jquery_engine = window.repl.jquery_engine;
var golr_manager = window.repl.golr_manager;
var golr_response = window.repl.golr_response;

// Aliases.
var loop = bbop.each;
var dump = bbop.dump;
var what_is = bbop.what_is;

// Define a global logger.
var logger = new bbop.logger();
logger.DEBUG = true;
function ll(str){ return logger.kvetch(str); }

// Support a callback to data for the manager.
var data = null;
function callback(response){ data = response; ll('// Returned value placed in [data].'); }

// Get a global manager.
var engine = new jquery_engine(golr_response);
engine.method('GET');
engine.use_jsonp(true);
var go = new golr_manager(gserv_download, gconf, engine, 'async');
go.register('search', callback);

// Add GO-specific methods to our manager.
golr_manager.prototype.gaf_url = function(){ return this.get_download_url(['source', 'bioentity_internal_id', 'bioentity_label', 'qualifier', 'annotation_class', 'reference', 'evidence_type', 'evidence_with', 'aspect', 'bioentity_name', 'synonym', 'type', 'taxon', 'date', 'assigned_by', 'annotation_extension_class', 'bioentity_isoform']); };
golr_manager.prototype.doc_type = function(t){ return this.add_query_filter('document_type', t); };

// jQuery helpers.
var empty = function(did){ jQuery('#' + did).empty(); };
var append = function(did, str){ jQuery('#' + did).append(str); };

Create a popup search pane.

This creates a dialog box with a set id and , then populates it with a search pane.

Session:

widgets.display.dialog('<br /><div id="pager"></div><div id="popup-search-display" style="font-size: 75%"></div>', {width: '800', title: 'search prototype'});
go.set_personality('annotation');
go.add_query_filter('document_category', 'annotation', ['*']);
var pager = new widgets.live_pager('pager', go, {'results_title': 'Total annotations: '});
var results_opts = {'user_buttons_div_id': pager.button_span_id(), 'user_buttons': [] };
var search = new widgets.live_results('popup-search-display', go, gconf.get_class('annotation'), handler, linker, results_opts);
go.search();