// // QUORUM //---------------------------------------------------------------------------// var QUORUM = { // // Supported algorithms. // algorithms: ["blastn", "blastx", "tblastn", "blastp"], // // Poll quorum search results asynchronously and insert them into // the DOM via #blast_template. // pollResults: function(id, interval, algos) { // Set the default poll interval to 5 seconds. interval = interval || 5000; // Algorithms algos = algos || QUORUM.algorithms; _.each(algos, function(a) { $.getJSON( '/quorum/jobs/' + id + '/get_quorum_search_results.json?algo=' + a, function(data) { if (data.length === 0) { setTimeout(function() { QUORUM.pollResults(id, interval, [a]); }, interval); } else { $('#' + a + '-results').empty(); var temp = _.template( $('#blast_template').html(), { data: data, algo: a } ); $('#' + a + '-results').html(temp); return; } } ); }); }, // // Display jQuery UI modal box containing detailed report of all hits // to the same query. After the modal box is inserted into the DOM, // automatically scroll to the highlighted hit. // viewDetailedReport: function(id, focus_id, query, algo) { // Create the modal box. $('#detailed_report_dialog').html( "
" +
"Loading... " +
"
Alignment (Mouse over for positions):
" + "" + seq + ""; }, // // Format Query and Hit Strand. // // If query_frame or hit_frame < 0, print 'reverse'; print 'forward' otherwise. // formatStrand: function(qstrand, hstrand) { var q = ""; var h = ""; qstrand < 0 ? q = "reverse" : q = "forward"; hstrand < 0 ? h = "reverse" : h = "forward"; return q + " / " + h; }, // // Display links to Hsps in the same group. // displayHspLinks: function(focus, group, data) { if (group !== null) { var str = "Related HSPs: "; var ids = _.map(group.split(","), function(i) { return parseInt(i, 10); }); var selected = _(data).chain() .reject(function(d) { return !_.include(ids, d.id); }) .sortBy(function(d) { return d.id; }) .value(); _.each(selected, function(e) { if (e.id !== focus) { str += "" + e.hsp_num + " "; } else { str += e.hsp_num + " "; } }); return str; } }, // // Download Blast hit sequence. // downloadSequence: function(id, algo_id, algo, el) { $(el).html('Fetching sequence...'); $.getJSON( "/quorum/jobs/" + id + "/get_quorum_blast_hit_sequence.json?algo_id=" + algo_id + "&algo=" + algo, function(data) { QUORUM.getSequenceFile(id, data[0].meta_id, el); } ); }, // // Poll application for Blast hit sequence. // getSequenceFile: function(id, meta_id, el) { var url = "/quorum/jobs/" + id + "/send_quorum_blast_hit_sequence?meta_id=" + meta_id; $.get( url, function(data) { if (data.length === 0) { setTimeout(function() { QUORUM.getSequenceFile(id, meta_id, el) }, 2500); } else { if (data.indexOf("error") !== -1) { // Print error message. $(el).addClass('ui-state-error').html(data); } else { // Force browser to download file via iframe. $(el).addClass('ui-state-highlight').html('Sequence Downloaded Successfully'); $('.quorum_sequence_download').remove(); $('body').append(''); $('.quorum_sequence_download').attr('src', url).hide(); } } } ); }, // // Autoscroll to given div id. // autoScroll: function(id, highlight) { $('html, body').animate({ scrollTop: $('#' + id).offset().top }, 1000); if (highlight) { $('#' + id).effect("highlight", {}, 4000); } }, // // Open URL in new window. // openWindow: function(url, name, width, height) { var windowSize = "width=" + width + ",height=" + height + ",scrollbars=yes"; window.open(url, name, windowSize); } };